From e8b0e4201e8a5793b103c2944d19f7761932a521 Mon Sep 17 00:00:00 2001 From: Stephen Worley Date: Wed, 20 Mar 2019 13:03:22 -0400 Subject: [PATCH] zebra: Add afi value for all nexthops sent/received Since nexthops are always going to need to be address family specific unless they are only a group, we have to address this when we receive and send them. Signed-off-by: Stephen Worley --- zebra/rt_netlink.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index 52c3b706e0..c8d392b4bb 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -1910,30 +1910,30 @@ static int netlink_nexthop(int cmd, struct zebra_dplane_ctx *ctx) // TODO: IF not a group const struct nexthop_group nhg = nhe->nhg; const struct nexthop *nh = nhg.nexthop; - const struct prefix *dest_p; - unsigned char family = 0; + + if (nhe->afi == AFI_IP) + req.nhm.nh_family = AF_INET; + else if (nhe->afi == AFI_IP6) + req.nhm.nh_family = AF_INET6; switch (nh->type) { // TODO: Need AF for just index also // just use dest? - case NEXTHOP_TYPE_IFINDEX: - dest_p = dplane_ctx_get_dest(ctx); - family = PREFIX_FAMILY(dest_p); - break; case NEXTHOP_TYPE_IPV4_IFINDEX: - family = AF_INET; addattr_l(&req.n, sizeof(req), NHA_GATEWAY, &nh->gate.ipv4, IPV4_MAX_BYTELEN); break; case NEXTHOP_TYPE_IPV6_IFINDEX: - family = AF_INET6; addattr_l(&req.n, sizeof(req), NHA_GATEWAY, &nh->gate.ipv6, IPV6_MAX_BYTELEN); break; case NEXTHOP_TYPE_BLACKHOLE: - family = AF_UNSPEC; + // TODO: Handle this addattr_l(&req.n, sizeof(req), NHA_BLACKHOLE, NULL, 0); break; + case NEXTHOP_TYPE_IFINDEX: + /* Don't need anymore info for this */ + break; case NEXTHOP_TYPE_IPV4: case NEXTHOP_TYPE_IPV6: flog_err( @@ -1943,7 +1943,6 @@ static int netlink_nexthop(int cmd, struct zebra_dplane_ctx *ctx) break; } - req.nhm.nh_family = family; req.nhm.nh_protocol = zebra2proto(dplane_ctx_get_type(ctx)); addattr32(&req.n, sizeof(req), NHA_OIF, nh->ifindex); @@ -2224,6 +2223,7 @@ int netlink_nexthop_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) /* nexthop group id */ uint32_t id; unsigned char family; + afi_t afi = AFI_UNSPEC; struct interface *ifp = NULL; struct nhmsg *nhm = NULL; /* struct for nexthop group abstraction */ @@ -2262,13 +2262,15 @@ int netlink_nexthop_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) /* We use the ID key'd nhg table for kernel updates */ id = *((uint32_t *)RTA_DATA(tb[NHA_ID])); - family = nhm->nh_family; if (IS_ZEBRA_DEBUG_KERNEL) { zlog_debug("Nexthop ID (%u) update from the kernel", id); } - /* Lookup via the id */ + family = nhm->nh_family; + + afi = family2afi(family); + nhe = zebra_nhg_lookup_id(id); if (h->nlmsg_type == RTM_NEWNEXTHOP) { @@ -2310,7 +2312,7 @@ int netlink_nexthop_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) nexthop_group_copy(&nhe->nhg, &nhg); } else { /* This is a new nexthop group */ - nhe = zebra_nhg_find(&nhg, nh.vrf_id, id); + nhe = zebra_nhg_find(&nhg, nh.vrf_id, afi, id); if (nhe) { nhe->is_kernel_nh = true; } else {