diff options
Diffstat (limited to 'zebra/if_netlink.c')
| -rw-r--r-- | zebra/if_netlink.c | 132 |
1 files changed, 37 insertions, 95 deletions
diff --git a/zebra/if_netlink.c b/zebra/if_netlink.c index 0dcf5082a2..47a101e619 100644 --- a/zebra/if_netlink.c +++ b/zebra/if_netlink.c @@ -67,6 +67,7 @@ #include "zebra/zebra_mpls.h" #include "zebra/kernel_netlink.h" #include "zebra/if_netlink.h" +#include "zebra/zebra_errors.h" extern struct zebra_privs_t zserv_privs; @@ -81,7 +82,7 @@ static void set_ifindex(struct interface *ifp, ifindex_t ifi_index, && (oifp != ifp)) { if (ifi_index == IFINDEX_INTERNAL) flog_err( - LIB_ERR_INTERFACE, + EC_LIB_INTERFACE, "Netlink is setting interface %s ifindex to reserved internal value %u", ifp->name, ifi_index); else { @@ -91,7 +92,7 @@ static void set_ifindex(struct interface *ifp, ifindex_t ifi_index, ifi_index, oifp->name, ifp->name); if (if_is_up(oifp)) flog_err( - LIB_ERR_INTERFACE, + EC_LIB_INTERFACE, "interface rename detected on up interface: index %d was renamed from %s to %s, results are uncertain!", ifi_index, oifp->name, ifp->name); if_delete_update(oifp); @@ -112,8 +113,8 @@ static void netlink_interface_update_hw_addr(struct rtattr **tb, hw_addr_len = RTA_PAYLOAD(tb[IFLA_ADDRESS]); if (hw_addr_len > INTERFACE_HWADDR_MAX) - zlog_warn("Hardware address is too large: %d", - hw_addr_len); + zlog_debug("Hardware address is too large: %d", + hw_addr_len); else { ifp->hw_addr_len = hw_addr_len; memcpy(ifp->hw_addr, RTA_DATA(tb[IFLA_ADDRESS]), @@ -312,8 +313,8 @@ static void netlink_vrf_change(struct nlmsghdr *h, struct rtattr *tb, vrf = vrf_get((vrf_id_t)ifi->ifi_index, name); // It would create vrf if (!vrf) { - flog_err(LIB_ERR_INTERFACE, "VRF %s id %u not created", - name, ifi->ifi_index); + flog_err(EC_LIB_INTERFACE, "VRF %s id %u not created", + name, ifi->ifi_index); return; } @@ -334,9 +335,9 @@ static void netlink_vrf_change(struct nlmsghdr *h, struct rtattr *tb, /* Enable the created VRF. */ if (!vrf_enable(vrf)) { - flog_err(LIB_ERR_INTERFACE, - "Failed to enable VRF %s id %u", name, - ifi->ifi_index); + flog_err(EC_LIB_INTERFACE, + "Failed to enable VRF %s id %u", name, + ifi->ifi_index); return; } @@ -349,7 +350,8 @@ static void netlink_vrf_change(struct nlmsghdr *h, struct rtattr *tb, vrf = vrf_lookup_by_id((vrf_id_t)ifi->ifi_index); if (!vrf) { - zlog_warn("%s: vrf not found", __func__); + flog_warn(EC_ZEBRA_VRF_NOT_FOUND, "%s: vrf not found", + __func__); return; } @@ -531,7 +533,8 @@ static int netlink_bridge_interface(struct nlmsghdr *h, int len, ns_id_t ns_id, /* The interface should already be known, if not discard. */ ifp = if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id), ifi->ifi_index); if (!ifp) { - zlog_warn("Cannot find bridge IF %s(%u)", name, ifi->ifi_index); + zlog_debug("Cannot find bridge IF %s(%u)", name, + ifi->ifi_index); return 0; } if (!IS_ZEBRA_IF_VXLAN(ifp)) @@ -896,9 +899,10 @@ int netlink_interface_addr(struct nlmsghdr *h, ns_id_t ns_id, int startup) ifa = NLMSG_DATA(h); if (ifa->ifa_family != AF_INET && ifa->ifa_family != AF_INET6) { - zlog_warn( - "Invalid address family: %u received from kernel interface addr change: %u", - ifa->ifa_family, h->nlmsg_type); + flog_warn( + EC_ZEBRA_UNKNOWN_FAMILY, + "Invalid address family: %u received from kernel interface addr change: %s", + ifa->ifa_family, nl_msg_type_to_str(h->nlmsg_type)); return 0; } @@ -920,7 +924,7 @@ int netlink_interface_addr(struct nlmsghdr *h, ns_id_t ns_id, int startup) ifp = if_lookup_by_index_per_ns(zns, ifa->ifa_index); if (ifp == NULL) { flog_err( - LIB_ERR_INTERFACE, + EC_LIB_INTERFACE, "netlink_interface_addr can't find interface by index %d", ifa->ifa_index); return -1; @@ -1002,8 +1006,9 @@ int netlink_interface_addr(struct nlmsghdr *h, ns_id_t ns_id, int startup) if (ifa->ifa_family == AF_INET) { if (ifa->ifa_prefixlen > IPV4_MAX_BITLEN) { zlog_err( - "Invalid prefix length: %u received from kernel interface addr change: %u", - ifa->ifa_prefixlen, h->nlmsg_type); + "Invalid prefix length: %u received from kernel interface addr change: %s", + ifa->ifa_prefixlen, + nl_msg_type_to_str(h->nlmsg_type)); return -1; } if (h->nlmsg_type == RTM_NEWADDR) @@ -1018,8 +1023,9 @@ int netlink_interface_addr(struct nlmsghdr *h, ns_id_t ns_id, int startup) if (ifa->ifa_family == AF_INET6) { if (ifa->ifa_prefixlen > IPV6_MAX_BITLEN) { zlog_err( - "Invalid prefix length: %u received from kernel interface addr change: %u", - ifa->ifa_prefixlen, h->nlmsg_type); + "Invalid prefix length: %u received from kernel interface addr change: %s", + ifa->ifa_prefixlen, + nl_msg_type_to_str(h->nlmsg_type)); return -1; } if (h->nlmsg_type == RTM_NEWADDR) { @@ -1044,67 +1050,6 @@ int netlink_interface_addr(struct nlmsghdr *h, ns_id_t ns_id, int startup) return 0; } -/* helper function called by if_netlink_change - * to delete interfaces in case the interface moved - * to an other netns - */ -static void if_netlink_check_ifp_instance_consistency(uint16_t cmd, - struct interface *ifp, - ns_id_t ns_id) -{ - struct interface *other_ifp; - - /* - * look if interface name is also found on other netns - * - only if vrf backend is netns - * - do not concern lo interface - * - then remove previous one - * - for new link case, check found interface is not active - */ - if (!vrf_is_backend_netns() || - !strcmp(ifp->name, "lo")) - return; - other_ifp = if_lookup_by_name_not_ns(ns_id, ifp->name); - if (!other_ifp) - return; - /* because previous interface may be inactive, - * interface is moved back to default vrf - * then one may find the same pointer; ignore - */ - if (other_ifp == ifp) - return; - if ((cmd == RTM_NEWLINK) - && (CHECK_FLAG(other_ifp->status, ZEBRA_INTERFACE_ACTIVE))) - return; - if (IS_ZEBRA_DEBUG_KERNEL && cmd == RTM_NEWLINK) { - zlog_debug("RTM_NEWLINK %s(%u, VRF %u) replaces %s(%u, VRF %u)\n", - ifp->name, - ifp->ifindex, - ifp->vrf_id, - other_ifp->name, - other_ifp->ifindex, - other_ifp->vrf_id); - } else if (IS_ZEBRA_DEBUG_KERNEL && cmd == RTM_DELLINK) { - zlog_debug("RTM_DELLINK %s(%u, VRF %u) is replaced by %s(%u, VRF %u)\n", - ifp->name, - ifp->ifindex, - ifp->vrf_id, - other_ifp->name, - other_ifp->ifindex, - other_ifp->vrf_id); - } - /* the found interface replaces the current one - * remove it - */ - if (cmd == RTM_DELLINK) - if_delete(ifp); - else - if_delete(other_ifp); - /* the found interface is replaced by the current one - * suppress it - */ -} - int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) { int len; @@ -1130,16 +1075,17 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) /* assume if not default zns, then new VRF */ if (!(h->nlmsg_type == RTM_NEWLINK || h->nlmsg_type == RTM_DELLINK)) { /* If this is not link add/delete message so print warning. */ - zlog_warn("netlink_link_change: wrong kernel message %d", - h->nlmsg_type); + zlog_debug("netlink_link_change: wrong kernel message %s", + nl_msg_type_to_str(h->nlmsg_type)); return 0; } if (!(ifi->ifi_family == AF_UNSPEC || ifi->ifi_family == AF_BRIDGE || ifi->ifi_family == AF_INET6)) { - zlog_warn( - "Invalid address family: %u received from kernel link change: %u", - ifi->ifi_family, h->nlmsg_type); + flog_warn( + EC_ZEBRA_UNKNOWN_FAMILY, + "Invalid address family: %u received from kernel link change: %s", + ifi->ifi_family, nl_msg_type_to_str(h->nlmsg_type)); return 0; } @@ -1248,7 +1194,7 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) set_ifindex(ifp, ifi->ifi_index, zns); ifp->flags = ifi->ifi_flags & 0x0000fffff; if (!tb[IFLA_MTU]) { - zlog_warn( + zlog_debug( "RTM_NEWLINK for interface %s(%u) without MTU set", name, ifi->ifi_index); return 0; @@ -1278,8 +1224,6 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp)) zebra_l2if_update_bridge_slave(ifp, bridge_ifindex); - if_netlink_check_ifp_instance_consistency(RTM_NEWLINK, - ifp, ns_id); } else if (ifp->vrf_id != vrf_id) { /* VRF change for an interface. */ if (IS_ZEBRA_DEBUG_KERNEL) @@ -1303,7 +1247,7 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) set_ifindex(ifp, ifi->ifi_index, zns); if (!tb[IFLA_MTU]) { - zlog_warn( + zlog_debug( "RTM_NEWLINK for interface %s(%u) without MTU set", name, ifi->ifi_index); return 0; @@ -1353,14 +1297,14 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp) || was_bridge_slave) zebra_l2if_update_bridge_slave(ifp, bridge_ifindex); - if_netlink_check_ifp_instance_consistency(RTM_NEWLINK, - ifp, ns_id); } } else { /* Delete interface notification from kernel */ if (ifp == NULL) { - zlog_warn("RTM_DELLINK for unknown interface %s(%u)", - name, ifi->ifi_index); + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug( + "RTM_DELLINK for unknown interface %s(%u)", + name, ifi->ifi_index); return 0; } @@ -1378,8 +1322,6 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) if (!IS_ZEBRA_IF_VRF(ifp)) if_delete_update(ifp); - if_netlink_check_ifp_instance_consistency(RTM_DELLINK, - ifp, ns_id); } return 0; |
