diff options
Diffstat (limited to 'zebra/rt_netlink.c')
-rw-r--r-- | zebra/rt_netlink.c | 48 |
1 files changed, 19 insertions, 29 deletions
diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index f9f90224..e9ddd737 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -41,7 +41,6 @@ #include "zebra/redistribute.h" #include "zebra/interface.h" #include "zebra/debug.h" -#include <stddef.h> /* Socket interface to kernel */ struct nlsock @@ -66,7 +65,7 @@ static const struct message nlmsg_str[] = { {0, NULL} }; -static const char *nexthop_types_desc[] = +static const char *nexthop_types_desc[] = { "none", "Directly connected", @@ -80,7 +79,6 @@ static const char *nexthop_types_desc[] = "Null0 nexthop", }; - extern struct zebra_t zebrad; extern struct zebra_privs_t zserv_privs; @@ -150,7 +148,6 @@ netlink_socket (struct nlsock *nl, unsigned long groups) return -1; } - memset (&snl, 0, sizeof snl); snl.nl_family = AF_NETLINK; snl.nl_groups = groups; @@ -262,7 +259,6 @@ netlink_parse_info (int (*filter) (struct sockaddr_nl *, struct nlmsghdr *), while (1) { - //increased from 4096 to 32768 as recvmsg overrun error char buf[32768]; struct iovec iov = { buf, sizeof buf }; struct sockaddr_nl snl; @@ -276,7 +272,6 @@ netlink_parse_info (int (*filter) (struct sockaddr_nl *, struct nlmsghdr *), continue; if (errno == EWOULDBLOCK || errno == EAGAIN) break; - zlog (NULL, LOG_ERR, "%s recvmsg overrun: %s", nl->name, safe_strerror(errno)); continue; @@ -295,13 +290,6 @@ netlink_parse_info (int (*filter) (struct sockaddr_nl *, struct nlmsghdr *), return -1; } - /* JF: Ignore messages that aren't from the kernel */ - if ( snl.nl_pid != 0 ) - { - zlog_debug ("Ignoring message from pid %u", snl.nl_pid ); - continue; - } - for (h = (struct nlmsghdr *) buf; NLMSG_OK (h, (unsigned int) status); h = NLMSG_NEXT (h, status)) { @@ -544,6 +532,9 @@ netlink_interface_addr (struct sockaddr_nl *snl, struct nlmsghdr *h) ifp = if_lookup_by_index (ifa->ifa_index); if (ifp == NULL) { + if (h->nlmsg_type == RTM_DELADDR) + return 0; + zlog_err ("netlink_interface_addr can't find interface by index %d", ifa->ifa_index); return -1; @@ -703,6 +694,7 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h) return 0; if (rtm->rtm_protocol == RTPROT_REDIRECT) return 0; + if (rtm->rtm_protocol == RTPROT_KERNEL) return 0; @@ -745,7 +737,7 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h) p.prefixlen = rtm->rtm_dst_len; rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, flags, &p, gate, src, index, - table, metric, 0, rtm->rtm_scope); + table, metric, 0, rtm->rtm_scope, rtm->rtm_protocol); } #ifdef HAVE_IPV6 if (rtm->rtm_family == AF_INET6) @@ -884,7 +876,7 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h) if (h->nlmsg_type == RTM_NEWROUTE) rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, &p, gate, src, index, table, 0, - 0, rtm->rtm_scope); + 0, rtm->rtm_scope, rtm->rtm_protocol); else rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, 0, &p, gate, index, table); } @@ -972,7 +964,6 @@ netlink_link_change (struct sockaddr_nl *snl, struct nlmsghdr *h) unsigned int mtu = *(uint32_t *) RTA_DATA (tb[IFLA_MTU]); ifp = if_lookup_by_index (ifi->ifi_index); - /* New interface */ if (ifp == NULL || !CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) { if (ifp == NULL) @@ -989,11 +980,12 @@ netlink_link_change (struct sockaddr_nl *snl, struct nlmsghdr *h) zlog_info ("interface %s index %d %s added.", name, ifi->ifi_index, if_flag_dump(new_flags)); + ifp->flags = new_flags; ifp->mtu6 = ifp->mtu = mtu; - /* If new link is added. */ - if_add_update (ifp); + /* If new link is added. */ + if_add_update (ifp); } /* Interface status change. */ else if (new_flags != ifp->flags) @@ -1025,15 +1017,14 @@ netlink_link_change (struct sockaddr_nl *snl, struct nlmsghdr *h) ifp->mtu = ifp->mtu6 = mtu; zlog_info("interface index %d was renamed from %s to %s", ifi->ifi_index, ifp->name, name); - - strncpy(ifp->name, name, INTERFACE_NAMSIZ); - rib_update(); + + if_rename (ifp, name); } /* Interface mtu change */ else if (mtu != ifp->mtu) { - zlog_info("interface index %d mtu changed from %u to %u", - ifp->mtu, mtu); + zlog_info("interface %s mtu changed from %u to %u", + ifp->name, ifp->mtu, mtu); ifp->mtu = ifp->mtu6 = mtu; if (if_is_operative (ifp)) zebra_interface_up_update (ifp); @@ -1054,8 +1045,8 @@ netlink_link_change (struct sockaddr_nl *snl, struct nlmsghdr *h) name, ifi->ifi_index); if_delete_update (ifp); - if_delete (ifp); } + return 0; } @@ -1290,9 +1281,10 @@ netlink_delroute (int family, void *dest, int length, void *gate, req.n.nlmsg_flags = NLM_F_REQUEST; req.n.nlmsg_type = RTM_DELROUTE; req.r.rtm_family = family; + req.r.rtm_dst_len = length; req.r.rtm_scope = RT_SCOPE_NOWHERE; + req.r.rtm_protocol = RTPROT_UNSPEC; req.r.rtm_table = table; - req.r.rtm_dst_len = length; if (dest) addattr_l (&req.n, sizeof req, RTA_DST, dest, bytelen); @@ -1335,6 +1327,7 @@ netlink_route_multipath (int cmd, struct prefix *p, struct rib *rib, req.r.rtm_family = family; req.r.rtm_table = rib->table; req.r.rtm_dst_len = p->prefixlen; + req.r.rtm_scope = rib->scope; if ((rib->flags & ZEBRA_FLAG_BLACKHOLE) || (rib->flags & ZEBRA_FLAG_REJECT)) discard = 1; @@ -1343,8 +1336,7 @@ netlink_route_multipath (int cmd, struct prefix *p, struct rib *rib, switch (rib->type) { case ZEBRA_ROUTE_KERNEL: - /* FIXME: should remember original protocol from RTM_NEWLINK */ - req.r.rtm_protocol = RTPROT_BOOT; + req.r.rtm_protocol = rib->protocol; break; case ZEBRA_ROUTE_CONNECT: req.r.rtm_protocol = RTPROT_KERNEL; @@ -1353,8 +1345,6 @@ netlink_route_multipath (int cmd, struct prefix *p, struct rib *rib, req.r.rtm_protocol = RTPROT_ZEBRA; } - req.r.rtm_scope = rib->scope; - if (cmd == RTM_NEWROUTE) { if (discard) |