From 69bf31242abcc016fbfb431f0cf62f1b7de02538 Mon Sep 17 00:00:00 2001 From: Yaroslav Kholod Date: Wed, 18 Dec 2024 15:30:48 +0200 Subject: [PATCH] zebra: update kernel routes with interface check Zebra NH check is wrong -- it does not update missing interface routes Steps to reproduce: ``` ip link set dev eth0 up ip -4 addr add 192.168.0.2/24 dev eth0 ip -4 route add default via 192.168.0.1 ip -4 addr flush dev eth0 ``` Before ``` K>* 0.0.0.0/0 [0/0] via 192.168.0.1, eth0, 00:00:07 ``` After Route is removed from zebra --- zebra/zebra_nhg.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c index 1519246c179e..005d5d3d2a09 100644 --- a/zebra/zebra_nhg.c +++ b/zebra/zebra_nhg.c @@ -2645,10 +2645,12 @@ static unsigned nexthop_active_check(struct route_node *rn, */ if (re->type == ZEBRA_ROUTE_KERNEL || re->type == ZEBRA_ROUTE_SYSTEM) { struct interface *ifp; + int connected_if_count = 0; ifp = if_lookup_by_index(nexthop->ifindex, nexthop->vrf_id); + connected_if_count = connected_count_by_family(ifp->connected, AF_INET) + connected_count_by_family(ifp->connected, AF_INET6); - if (ifp && ifp->vrf->vrf_id == vrf_id && if_is_up(ifp)) { + if (ifp && ifp->vrf->vrf_id == vrf_id && if_is_up(ifp) && connected_if_count) { SET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE); goto skip_check; }