From 85751d1d332eef13fe9d382682184bd7c3037a4a Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 25 Sep 2018 15:25:51 -0400 Subject: [PATCH] bgpd: Don't necessarily ignore interface callbacks In bgp if we have not configured bgp we were ignoring interface based callbacks. Leading to states where we may not be processing interface information. Leading to states where we do not actually keep ifp data. As an example: Suppose vrf A and vrf B. A has interface swp1. At the same time we only have a `router bgp 9 vrf B` When we received the callback for moving swp1 from vrf A to vrf B we were not processing the move at all and BGP would not consider the interface part of vrf B at all. This commit makes bgp pay attention to interface events irrelevant if bgp is using that vrf. This is now consistent with how the lib/if* expects to work and the rest of the daemons in FRR. Signed-off-by: Donald Sharp --- bgpd/bgp_zebra.c | 52 +++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 3b762a362b..5ab727111c 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -229,8 +229,6 @@ static int bgp_interface_delete(int command, struct zclient *zclient, 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); @@ -240,7 +238,8 @@ 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_update_interface_nbrs(bgp, ifp, NULL); + if (bgp) + bgp_update_interface_nbrs(bgp, ifp, NULL); if_set_index(ifp, IFINDEX_INTERNAL); return 0; @@ -257,8 +256,6 @@ static int bgp_interface_up(int command, struct zclient *zclient, 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); @@ -269,6 +266,9 @@ 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); + if (!bgp) + return 0; + for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, c)) bgp_connected_add(bgp, c); @@ -290,8 +290,6 @@ static int bgp_interface_down(int command, struct zclient *zclient, struct peer *peer; bgp = bgp_lookup_by_vrf_id(vrf_id); - if (!bgp) - return 0; s = zclient->ibuf; ifp = zebra_interface_state_read(s, vrf_id); @@ -301,6 +299,9 @@ 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); + if (!bgp) + return 0; + for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, c)) bgp_connected_delete(bgp, c); @@ -342,8 +343,6 @@ static int bgp_interface_address_add(int command, struct zclient *zclient, 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); @@ -357,6 +356,9 @@ static int bgp_interface_address_add(int command, struct zclient *zclient, ifc->ifp->name, buf); } + if (!bgp) + return 0; + if (if_is_operative(ifc->ifp)) { bgp_connected_add(bgp, ifc); @@ -379,8 +381,6 @@ static int bgp_interface_address_delete(int command, struct zclient *zclient, 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); @@ -394,7 +394,7 @@ static int bgp_interface_address_delete(int command, struct zclient *zclient, ifc->ifp->name, buf); } - if (if_is_operative(ifc->ifp)) { + if (bgp && if_is_operative(ifc->ifp)) { bgp_connected_delete(bgp, ifc); } @@ -483,23 +483,23 @@ static int bgp_interface_vrf_update(int command, struct zclient *zclient, ifp->name, new_vrf_id); 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); + if (bgp) { + for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, c)) + bgp_connected_delete(bgp, c); - for (ALL_LIST_ELEMENTS(ifp->nbr_connected, node, nnode, nc)) - bgp_nbr_connected_delete(bgp, nc, 1); + for (ALL_LIST_ELEMENTS(ifp->nbr_connected, node, nnode, nc)) + bgp_nbr_connected_delete(bgp, nc, 1); - /* Fast external-failover */ - if (!CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER)) { - for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { - if ((peer->ttl != 1) && (peer->gtsm_hops != 1)) - continue; + /* Fast external-failover */ + if (!CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER)) { + for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { + if ((peer->ttl != 1) && (peer->gtsm_hops != 1)) + continue; - if (ifp == peer->nexthop.ifp) - BGP_EVENT_ADD(peer, BGP_Stop); + if (ifp == peer->nexthop.ifp) + BGP_EVENT_ADD(peer, BGP_Stop); + } } } @@ -2191,8 +2191,6 @@ static void bgp_encode_pbr_ipset_match(struct stream *s, stream_put(s, pbim->ipset_name, ZEBRA_IPSET_NAME_SIZE); - - } static void bgp_encode_pbr_ipset_entry_match(struct stream *s, -- 2.39.5