Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib, zebra: Allow for interface deletion when kernel event happens #5009

Merged
merged 8 commits into from
Sep 30, 2019
45 changes: 11 additions & 34 deletions babeld/babel_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,10 @@ babel_interface_up (ZAPI_CALLBACK_ARGS)
}

int
babel_interface_down (ZAPI_CALLBACK_ARGS)
babel_ifp_down(struct interface *ifp)
{
struct stream *s = NULL;
struct interface *ifp = NULL;

debugf(BABEL_DEBUG_IF, "receive a 'interface down'");

s = zclient->ibuf;
ifp = zebra_interface_state_read(s, vrf_id); /* it updates iflist */

if (ifp == NULL) {
return 0;
}
Expand All @@ -104,45 +98,23 @@ babel_interface_down (ZAPI_CALLBACK_ARGS)
return 0;
}

int
babel_interface_add (ZAPI_CALLBACK_ARGS)
int babel_ifp_create (struct interface *ifp)
{
struct interface *ifp = NULL;

debugf(BABEL_DEBUG_IF, "receive a 'interface add'");

/* read and add the interface in the iflist. */
ifp = zebra_interface_add_read (zclient->ibuf, vrf_id);

if (ifp == NULL) {
return 0;
}

interface_recalculate(ifp);
return 0;
}

return 0;
donaldsharp marked this conversation as resolved.
Show resolved Hide resolved
}

int
babel_interface_delete (ZAPI_CALLBACK_ARGS)
babel_ifp_destroy(struct interface *ifp)
{
struct interface *ifp;
struct stream *s;

debugf(BABEL_DEBUG_IF, "receive a 'interface delete'");

s = zclient->ibuf;
ifp = zebra_interface_state_read(s, vrf_id); /* it updates iflist */

if (ifp == NULL)
return 0;

if (IS_ENABLE(ifp))
interface_reset(ifp);

/* To support pseudo interface do not free interface structure. */
/* if_delete(ifp); */
if_set_index(ifp, IFINDEX_INTERNAL);

return 0;
}

Expand Down Expand Up @@ -1260,6 +1232,11 @@ DEFUN (show_babel_parameters,
return CMD_SUCCESS;
}

int babel_ifp_up(struct interface *ifp)
{
return 0;
}

void
babel_if_init(void)
{
Expand Down
5 changes: 5 additions & 0 deletions babeld/babel_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ int babel_interface_delete (int, struct zclient *, zebra_size_t, vrf_id_t);
int babel_interface_address_add (int, struct zclient *, zebra_size_t, vrf_id_t);
int babel_interface_address_delete (int, struct zclient *, zebra_size_t, vrf_id_t);

int babel_ifp_create(struct interface *ifp);
int babel_ifp_up(struct interface *ifp);
int babel_ifp_down(struct interface *ifp);
int babel_ifp_destroy(struct interface *ifp);

unsigned jitter(babel_interface_nfo *, int);
unsigned update_jitter(babel_interface_nfo *babel_ifp, int urgent);
/* return "true" if "address" is one of our ipv6 addresses */
Expand Down
2 changes: 2 additions & 0 deletions babeld/babel_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ main(int argc, char **argv)
babel_replace_by_null(STDIN_FILENO);

/* init some quagga's dependencies, and babeld's commands */
if_zapi_callbacks(babel_ifp_create, babel_ifp_up,
babel_ifp_down, babel_ifp_destroy);
babeld_quagga_init();
/* init zebra client's structure and it's commands */
/* this replace kernel_setup && kernel_setup_socket */
Expand Down
4 changes: 0 additions & 4 deletions babeld/babel_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,6 @@ void babelz_zebra_init(void)
zclient_init(zclient, ZEBRA_ROUTE_BABEL, 0, &babeld_privs);

zclient->zebra_connected = babel_zebra_connected;
zclient->interface_add = babel_interface_add;
zclient->interface_delete = babel_interface_delete;
zclient->interface_up = babel_interface_up;
zclient->interface_down = babel_interface_down;
zclient->interface_address_add = babel_interface_address_add;
zclient->interface_address_delete = babel_interface_address_delete;
zclient->redistribute_route_add = babel_zebra_read_route;
Expand Down
37 changes: 9 additions & 28 deletions bfdd/ptm_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,33 +673,10 @@ void bfdd_sessions_disable_vrf(struct vrf *vrf)
}
}

static int bfdd_interface_update(ZAPI_CALLBACK_ARGS)
static int bfd_ifp_destroy(struct interface *ifp)
{
struct interface *ifp;

/*
* `zebra_interface_add_read` will handle the interface creation
* on `lib/if.c`. We'll use that data structure instead of
* rolling our own.
*/
if (cmd == ZEBRA_INTERFACE_ADD) {
ifp = zebra_interface_add_read(zclient->ibuf, vrf_id);
if (ifp == NULL)
return 0;

bfdd_sessions_enable_interface(ifp);
return 0;
}

/* Update interface information. */
ifp = zebra_interface_state_read(zclient->ibuf, vrf_id);
if (ifp == NULL)
return 0;

bfdd_sessions_disable_interface(ifp);

if_set_index(ifp, IFINDEX_INTERNAL);

return 0;
}

Expand Down Expand Up @@ -756,8 +733,16 @@ static int bfdd_interface_address_update(ZAPI_CALLBACK_ARGS)
return 0;
}

static int bfd_ifp_create(struct interface *ifp)
{
bfdd_sessions_enable_interface(ifp);

return 0;
}

void bfdd_zclient_init(struct zebra_privs_t *bfdd_priv)
{
if_zapi_callbacks(bfd_ifp_create, NULL, NULL, bfd_ifp_destroy);
zclient = zclient_new(master, &zclient_options_default);
assert(zclient != NULL);
zclient_init(zclient, ZEBRA_ROUTE_BFD, 0, bfdd_priv);
Expand All @@ -772,10 +757,6 @@ void bfdd_zclient_init(struct zebra_privs_t *bfdd_priv)
/* Send replay request on zebra connect. */
zclient->zebra_connected = bfdd_zebra_connected;

/* Learn interfaces from zebra instead of the OS. */
zclient->interface_add = bfdd_interface_update;
zclient->interface_delete = bfdd_interface_update;

/* Learn about interface VRF. */
zclient->interface_vrf_update = bfdd_interface_vrf_update;

Expand Down
88 changes: 29 additions & 59 deletions bgpd/bgp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -2721,17 +2675,35 @@ static void bgp_zebra_process_label_chunk(ZAPI_CALLBACK_ARGS)

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;
Expand All @@ -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;
Expand Down
Loading