diff options
| author | Russ White <russ@riw.us> | 2019-09-30 07:46:19 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-09-30 07:46:19 -0400 |
| commit | 9898a2fb3441e7382dba4190233f466b8271deae (patch) | |
| tree | 9629a5ce665db95addf0d0bc0f46864ef71b5a49 /bgpd/bgp_zebra.c | |
| parent | 5c256b572ca09b5d15b67ba0236c8a2678dda19c (diff) | |
| parent | 26f8f6fe7fb90208d4a5eb285fdf0dca83bde508 (diff) | |
Merge pull request #5009 from donaldsharp/interface_deletion
lib, zebra: Allow for interface deletion when kernel event happens
Diffstat (limited to 'bgpd/bgp_zebra.c')
| -rw-r--r-- | bgpd/bgp_zebra.c | 88 |
1 files changed, 29 insertions, 59 deletions
diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 71f7f6d0e3..de39e295ff 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -202,75 +202,36 @@ static void bgp_nbr_connected_delete(struct bgp *bgp, struct nbr_connected *ifc, } } -/* Inteface addition message from zebra. */ -static int bgp_interface_add(ZAPI_CALLBACK_ARGS) +static int bgp_ifp_destroy(struct interface *ifp) { - struct interface *ifp; struct bgp *bgp; - ifp = zebra_interface_add_read(zclient->ibuf, vrf_id); - if (!ifp) // unexpected - return 0; - - if (BGP_DEBUG(zebra, ZEBRA) && ifp) - zlog_debug("Rx Intf add VRF %u IF %s", vrf_id, ifp->name); - - bgp = bgp_lookup_by_vrf_id(vrf_id); - if (!bgp) - return 0; - - bgp_mac_add_mac_entry(ifp); - - bgp_update_interface_nbrs(bgp, ifp, ifp); - return 0; -} - -static int bgp_interface_delete(ZAPI_CALLBACK_ARGS) -{ - struct stream *s; - struct interface *ifp; - struct bgp *bgp; - - bgp = bgp_lookup_by_vrf_id(vrf_id); - - s = zclient->ibuf; - ifp = zebra_interface_state_read(s, vrf_id); - if (!ifp) /* This may happen if we've just unregistered for a VRF. */ - return 0; + bgp = bgp_lookup_by_vrf_id(ifp->vrf_id); if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("Rx Intf del VRF %u IF %s", vrf_id, ifp->name); + zlog_debug("Rx Intf del VRF %u IF %s", bgp->vrf_id, ifp->name); if (bgp) bgp_update_interface_nbrs(bgp, ifp, NULL); bgp_mac_del_mac_entry(ifp); - if_set_index(ifp, IFINDEX_INTERNAL); return 0; } -static int bgp_interface_up(ZAPI_CALLBACK_ARGS) +static int bgp_ifp_up(struct interface *ifp) { - struct stream *s; - struct interface *ifp; struct connected *c; struct nbr_connected *nc; struct listnode *node, *nnode; struct bgp *bgp; - bgp = bgp_lookup_by_vrf_id(vrf_id); - - s = zclient->ibuf; - ifp = zebra_interface_state_read(s, vrf_id); - - if (!ifp) - return 0; + bgp = bgp_lookup_by_vrf_id(ifp->vrf_id); bgp_mac_add_mac_entry(ifp); if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("Rx Intf up VRF %u IF %s", vrf_id, ifp->name); + zlog_debug("Rx Intf up VRF %u IF %s", ifp->vrf_id, ifp->name); if (!bgp) return 0; @@ -284,27 +245,20 @@ static int bgp_interface_up(ZAPI_CALLBACK_ARGS) return 0; } -static int bgp_interface_down(ZAPI_CALLBACK_ARGS) +static int bgp_ifp_down(struct interface *ifp) { - struct stream *s; - struct interface *ifp; struct connected *c; struct nbr_connected *nc; struct listnode *node, *nnode; struct bgp *bgp; struct peer *peer; - bgp = bgp_lookup_by_vrf_id(vrf_id); - - s = zclient->ibuf; - ifp = zebra_interface_state_read(s, vrf_id); - if (!ifp) - return 0; + bgp = bgp_lookup_by_vrf_id(ifp->vrf_id); bgp_mac_del_mac_entry(ifp); if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("Rx Intf down VRF %u IF %s", vrf_id, ifp->name); + zlog_debug("Rx Intf down VRF %u IF %s", ifp->vrf_id, ifp->name); if (!bgp) return 0; @@ -2721,17 +2675,35 @@ stream_failure: /* for STREAM_GETX */ extern struct zebra_privs_t bgpd_privs; +static int bgp_ifp_create(struct interface *ifp) +{ + struct bgp *bgp; + + if (BGP_DEBUG(zebra, ZEBRA)) + zlog_debug("Rx Intf add VRF %u IF %s", ifp->vrf_id, ifp->name); + + bgp = bgp_lookup_by_vrf_id(ifp->vrf_id); + if (!bgp) + return 0; + + bgp_mac_add_mac_entry(ifp); + + bgp_update_interface_nbrs(bgp, ifp, ifp); + return 0; +} + void bgp_zebra_init(struct thread_master *master, unsigned short instance) { zclient_num_connects = 0; + if_zapi_callbacks(bgp_ifp_create, bgp_ifp_up, + bgp_ifp_down, bgp_ifp_destroy); + /* Set default values. */ zclient = zclient_new(master, &zclient_options_default); zclient_init(zclient, ZEBRA_ROUTE_BGP, 0, &bgpd_privs); zclient->zebra_connected = bgp_zebra_connected; zclient->router_id_update = bgp_router_id_update; - zclient->interface_add = bgp_interface_add; - zclient->interface_delete = bgp_interface_delete; zclient->interface_address_add = bgp_interface_address_add; zclient->interface_address_delete = bgp_interface_address_delete; zclient->interface_nbr_address_add = bgp_interface_nbr_address_add; @@ -2740,8 +2712,6 @@ void bgp_zebra_init(struct thread_master *master, unsigned short instance) zclient->interface_vrf_update = bgp_interface_vrf_update; zclient->redistribute_route_add = zebra_read_route; zclient->redistribute_route_del = zebra_read_route; - zclient->interface_up = bgp_interface_up; - zclient->interface_down = bgp_interface_down; zclient->nexthop_update = bgp_read_nexthop_update; zclient->import_check_update = bgp_read_import_check_update; zclient->fec_update = bgp_read_fec_update; |
