From a6e6a6d825f98ecd3c074dfa473aec2d5da4cdb1 Mon Sep 17 00:00:00 2001 From: Stephen Worley Date: Mon, 22 Apr 2019 15:42:10 -0400 Subject: [PATCH] zebra: Fix nhg ifindex setting and checking We were only setting and checking the ifindex if the nexthop had an *_IFINDEX type. However, when nexthop active checking is done, the non-*_IFINDEX types can also obtain a nexthop with an ifindex and are thus valid too. Signed-off-by: Stephen Worley --- zebra/rt_netlink.c | 8 +++++--- zebra/zebra_nhg.c | 19 +++++-------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index 419e8ffb6e..83e3fd558b 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -1962,10 +1962,12 @@ static int netlink_nexthop(int cmd, struct zebra_dplane_ctx *ctx) req.nhm.nh_family = AF_INET6; switch (nh->type) { + case NEXTHOP_TYPE_IPV4: case NEXTHOP_TYPE_IPV4_IFINDEX: addattr_l(&req.n, sizeof(req), NHA_GATEWAY, &nh->gate.ipv4, IPV4_MAX_BYTELEN); break; + case NEXTHOP_TYPE_IPV6: case NEXTHOP_TYPE_IPV6_IFINDEX: addattr_l(&req.n, sizeof(req), NHA_GATEWAY, &nh->gate.ipv6, IPV6_MAX_BYTELEN); @@ -1978,13 +1980,13 @@ static int netlink_nexthop(int cmd, struct zebra_dplane_ctx *ctx) case NEXTHOP_TYPE_IFINDEX: /* Don't need anymore info for this */ break; - case NEXTHOP_TYPE_IPV4: - case NEXTHOP_TYPE_IPV6: + } + + if (!nh->ifindex) { flog_err( EC_ZEBRA_NHG_FIB_UPDATE, "Context received for kernel nexthop update without an interface"); return -1; - break; } addattr32(&req.n, sizeof(req), NHA_OIF, nh->ifindex); diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c index 67f72d1e82..94d41ba246 100644 --- a/zebra/zebra_nhg.c +++ b/zebra/zebra_nhg.c @@ -312,22 +312,13 @@ static void *zebra_nhg_alloc(void *arg) } /* Add the ifp now if its not a group or recursive and has ifindex */ - if (zebra_nhg_depends_is_empty(nhe) && nhe->nhg->nexthop) { + if (zebra_nhg_depends_is_empty(nhe) && nhe->nhg->nexthop + && nhe->nhg->nexthop->ifindex) { struct interface *ifp = NULL; - switch (nhe->nhg->nexthop->type) { - case NEXTHOP_TYPE_IPV4_IFINDEX: - case NEXTHOP_TYPE_IPV6_IFINDEX: - case NEXTHOP_TYPE_IFINDEX: - ifp = if_lookup_by_index(nhe->nhg->nexthop->ifindex, - nhe->vrf_id); - zebra_nhg_set_if(nhe, ifp); - break; - case NEXTHOP_TYPE_BLACKHOLE: - case NEXTHOP_TYPE_IPV4: - case NEXTHOP_TYPE_IPV6: - break; - } + ifp = if_lookup_by_index(nhe->nhg->nexthop->ifindex, + nhe->vrf_id); + zebra_nhg_set_if(nhe, ifp); } /* Add to id table as well */