From 2f9123e06920a96797a9e139ee3af0dab52f6639 Mon Sep 17 00:00:00 2001 From: Don Slice Date: Mon, 9 Oct 2017 15:22:52 +0000 Subject: [PATCH] bgpd: check for bgp instance before processing interfaces Problem reported with the log displaying error messages if bgpd was enabled in /etc/frr/daemons but bgp wasn't actually configured. The problem was due to operating on interfaces before if_create had been called (which happens at "router bgp" not at frr starting. Moved the checks for the bgp instance before operating on interfaces. Manual testing successful and bgp-smoke completed with no new issues. Ticket: CM-13504 Signed-off-by: Don Slice Reviewed-by: CCR-6738 --- bgpd/bgp_zebra.c | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index c90257d659..f979457244 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -224,6 +224,10 @@ static int bgp_interface_delete(int command, struct zclient *zclient, struct interface *ifp; struct bgp *bgp; + bgp = bgp_lookup_by_vrf_id(vrf_id); + if (!bgp) + return 0; + s = zclient->ibuf; ifp = zebra_interface_state_read(s, vrf_id); if (!ifp) /* This may happen if we've just unregistered for a VRF. */ @@ -232,10 +236,6 @@ static int bgp_interface_delete(int command, struct zclient *zclient, if (BGP_DEBUG(zebra, ZEBRA)) zlog_debug("Rx Intf del VRF %u IF %s", vrf_id, ifp->name); - bgp = bgp_lookup_by_vrf_id(vrf_id); - if (!bgp) - return 0; - bgp_update_interface_nbrs(bgp, ifp, NULL); ifp->ifindex = IFINDEX_DELETED; @@ -252,6 +252,10 @@ static int bgp_interface_up(int command, struct zclient *zclient, struct listnode *node, *nnode; struct bgp *bgp; + bgp = bgp_lookup_by_vrf_id(vrf_id); + if (!bgp) + return 0; + s = zclient->ibuf; ifp = zebra_interface_state_read(s, vrf_id); @@ -261,10 +265,6 @@ static int bgp_interface_up(int command, struct zclient *zclient, if (BGP_DEBUG(zebra, ZEBRA)) zlog_debug("Rx Intf up VRF %u IF %s", vrf_id, ifp->name); - bgp = bgp_lookup_by_vrf_id(vrf_id); - if (!bgp) - return 0; - for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, c)) bgp_connected_add(bgp, c); @@ -284,6 +284,10 @@ static int bgp_interface_down(int command, struct zclient *zclient, struct listnode *node, *nnode; struct bgp *bgp; + bgp = bgp_lookup_by_vrf_id(vrf_id); + if (!bgp) + return 0; + s = zclient->ibuf; ifp = zebra_interface_state_read(s, vrf_id); if (!ifp) @@ -292,10 +296,6 @@ static int bgp_interface_down(int command, struct zclient *zclient, if (BGP_DEBUG(zebra, ZEBRA)) zlog_debug("Rx Intf down VRF %u IF %s", vrf_id, ifp->name); - bgp = bgp_lookup_by_vrf_id(vrf_id); - if (!bgp) - return 0; - for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, c)) bgp_connected_delete(bgp, c); @@ -338,6 +338,11 @@ static int bgp_interface_address_add(int command, struct zclient *zclient, zebra_size_t length, vrf_id_t vrf_id) { struct connected *ifc; + struct bgp *bgp; + + bgp = bgp_lookup_by_vrf_id(vrf_id); + if (!bgp) + return 0; ifc = zebra_interface_address_read(command, zclient->ibuf, vrf_id); @@ -352,13 +357,8 @@ static int bgp_interface_address_add(int command, struct zclient *zclient, } if (if_is_operative(ifc->ifp)) { - struct bgp *bgp; - - bgp = bgp_lookup_by_vrf_id(vrf_id); - if (!bgp) - return 0; - bgp_connected_add(bgp, ifc); + /* If we have learnt of any neighbors on this interface, * check to kick off any BGP interface-based neighbors, * but only if this is a link-local address. @@ -377,6 +377,10 @@ static int bgp_interface_address_delete(int command, struct zclient *zclient, struct connected *ifc; struct bgp *bgp; + bgp = bgp_lookup_by_vrf_id(vrf_id); + if (!bgp) + return 0; + ifc = zebra_interface_address_read(command, zclient->ibuf, vrf_id); if (ifc == NULL) @@ -390,9 +394,7 @@ static int bgp_interface_address_delete(int command, struct zclient *zclient, } if (if_is_operative(ifc->ifp)) { - bgp = bgp_lookup_by_vrf_id(vrf_id); - if (bgp) - bgp_connected_delete(bgp, ifc); + bgp_connected_delete(bgp, ifc); } connected_free(ifc); -- 2.39.5