Skip to content

Commit

Permalink
*: Convert zapi->interface_delete to ifp callback
Browse files Browse the repository at this point in the history
Convert the callback of the interface_delete to the new
ifp callback.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
  • Loading branch information
donaldsharp committed Sep 19, 2019
1 parent 69b30c8 commit de2c8df
Show file tree
Hide file tree
Showing 31 changed files with 105 additions and 362 deletions.
22 changes: 2 additions & 20 deletions babeld/babel_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,31 +103,18 @@ int babel_ifp_create (struct interface *ifp)
debugf(BABEL_DEBUG_IF, "receive a 'interface add'");

interface_recalculate(ifp);

return 0;
}

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 @@ -1250,11 +1237,6 @@ int babel_ifp_up(struct interface *ifp)
return 0;
}

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

void
babel_if_init(void)
{
Expand Down
1 change: 0 additions & 1 deletion babeld/babel_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ void babelz_zebra_init(void)
zclient_init(zclient, ZEBRA_ROUTE_BABEL, 0, &babeld_privs);

zclient->zebra_connected = babel_zebra_connected;
zclient->interface_delete = babel_interface_delete;
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
19 changes: 1 addition & 18 deletions bfdd/ptm_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,19 +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;

/* 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 @@ -749,11 +740,6 @@ static int bfd_ifp_create(struct interface *ifp)
return 0;
}

static int bfd_ifp_destroy(struct 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);
Expand All @@ -771,9 +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_delete = bfdd_interface_update;

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

Expand Down
20 changes: 3 additions & 17 deletions bgpd/bgp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,28 +202,20 @@ static void bgp_nbr_connected_delete(struct bgp *bgp, struct nbr_connected *ifc,
}
}

static int bgp_interface_delete(ZAPI_CALLBACK_ARGS)
static int bgp_ifp_destroy(struct interface *ifp)
{
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;
}

Expand Down Expand Up @@ -2700,11 +2692,6 @@ static int bgp_ifp_create(struct interface *ifp)
return 0;
}

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

void bgp_zebra_init(struct thread_master *master, unsigned short instance)
{
zclient_num_connects = 0;
Expand All @@ -2717,7 +2704,6 @@ void bgp_zebra_init(struct thread_master *master, unsigned short instance)
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_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 Down
13 changes: 13 additions & 0 deletions eigrpd/eigrp_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,19 @@ static int eigrp_ifp_down(struct interface *ifp)

static int eigrp_ifp_destroy(struct interface *ifp)
{
if (if_is_up(ifp))
zlog_warn("Zebra: got delete of %s, but interface is still up",
ifp->name);

if (IS_DEBUG_EIGRP(zebra, ZEBRA_INTERFACE))
zlog_debug(
"Zebra: interface delete %s index %d flags %llx metric %d mtu %d",
ifp->name, ifp->ifindex, (unsigned long long)ifp->flags,
ifp->metric, ifp->mtu);

if (ifp->info)
eigrp_if_free(ifp->info, INTERFACE_DOWN_BY_ZEBRA);

return 0;
}

Expand Down
32 changes: 0 additions & 32 deletions eigrpd/eigrp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
#include "eigrpd/eigrp_topology.h"
#include "eigrpd/eigrp_fsm.h"

static int eigrp_interface_delete(ZAPI_CALLBACK_ARGS);
static int eigrp_interface_address_add(ZAPI_CALLBACK_ARGS);
static int eigrp_interface_address_delete(ZAPI_CALLBACK_ARGS);

Expand Down Expand Up @@ -109,7 +108,6 @@ void eigrp_zebra_init(void)
zclient_init(zclient, ZEBRA_ROUTE_EIGRP, 0, &eigrpd_privs);
zclient->zebra_connected = eigrp_zebra_connected;
zclient->router_id_update = eigrp_router_id_update_zebra;
zclient->interface_delete = eigrp_interface_delete;
zclient->interface_address_add = eigrp_interface_address_add;
zclient->interface_address_delete = eigrp_interface_address_delete;
zclient->redistribute_route_add = eigrp_zebra_read_route;
Expand Down Expand Up @@ -143,36 +141,6 @@ static int eigrp_zebra_read_route(ZAPI_CALLBACK_ARGS)
return 0;
}

static int eigrp_interface_delete(ZAPI_CALLBACK_ARGS)
{
struct interface *ifp;
struct stream *s;

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

if (ifp == NULL)
return 0;

if (if_is_up(ifp))
zlog_warn("Zebra: got delete of %s, but interface is still up",
ifp->name);

if (IS_DEBUG_EIGRP(zebra, ZEBRA_INTERFACE))
zlog_debug(
"Zebra: interface delete %s index %d flags %llx metric %d mtu %d",
ifp->name, ifp->ifindex, (unsigned long long)ifp->flags,
ifp->metric, ifp->mtu);

if (ifp->info)
eigrp_if_free(ifp->info, INTERFACE_DOWN_BY_ZEBRA);

if_set_index(ifp, IFINDEX_INTERNAL);
return 0;
}

static int eigrp_interface_address_add(ZAPI_CALLBACK_ARGS)
{
struct connected *c;
Expand Down
10 changes: 10 additions & 0 deletions isisd/isis_circuit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,16 @@ static int isis_ifp_down(struct interface *ifp)

static int isis_ifp_destroy(struct interface *ifp)
{
if (if_is_operative(ifp))
zlog_warn("Zebra: got delete of %s, but interface is still up",
ifp->name);

isis_csm_state_change(IF_DOWN_FROM_Z, circuit_scan_by_ifp(ifp), ifp);

/* Cannot call if_delete because we should retain the pseudo interface
in case there is configuration info attached to it. */
if_delete_retain(ifp);

return 0;
}

Expand Down
27 changes: 0 additions & 27 deletions isisd/isis_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,32 +72,6 @@ static int isis_router_id_update_zebra(ZAPI_CALLBACK_ARGS)
return 0;
}

static int isis_zebra_if_del(ZAPI_CALLBACK_ARGS)
{
struct interface *ifp;
struct stream *s;

s = zclient->ibuf;
ifp = zebra_interface_state_read(s, vrf_id);

if (!ifp)
return 0;

if (if_is_operative(ifp))
zlog_warn("Zebra: got delete of %s, but interface is still up",
ifp->name);

isis_csm_state_change(IF_DOWN_FROM_Z, circuit_scan_by_ifp(ifp), ifp);

/* Cannot call if_delete because we should retain the pseudo interface
in case there is configuration info attached to it. */
if_delete_retain(ifp);

if_set_index(ifp, IFINDEX_INTERNAL);

return 0;
}

static int isis_zebra_if_address_add(ZAPI_CALLBACK_ARGS)
{
struct connected *c;
Expand Down Expand Up @@ -339,7 +313,6 @@ void isis_zebra_init(struct thread_master *master)
zclient_init(zclient, PROTO_TYPE, 0, &isisd_privs);
zclient->zebra_connected = isis_zebra_connected;
zclient->router_id_update = isis_router_id_update_zebra;
zclient->interface_delete = isis_zebra_if_del;
zclient->interface_address_add = isis_zebra_if_address_add;
zclient->interface_address_delete = isis_zebra_if_address_del;
zclient->interface_link_params = isis_zebra_link_params;
Expand Down
19 changes: 1 addition & 18 deletions ldpd/ldp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ static void ifc2kaddr(struct interface *, struct connected *,
struct kaddr *);
static int ldp_zebra_send_mpls_labels(int, struct kroute *);
static int ldp_router_id_update(ZAPI_CALLBACK_ARGS);
static int ldp_interface_delete(ZAPI_CALLBACK_ARGS);
static int ldp_interface_address_add(ZAPI_CALLBACK_ARGS);
static int ldp_interface_address_delete(ZAPI_CALLBACK_ARGS);
static int ldp_zebra_read_route(ZAPI_CALLBACK_ARGS);
Expand Down Expand Up @@ -276,23 +275,13 @@ ldp_ifp_create(struct interface *ifp)
}

static int
ldp_interface_delete(ZAPI_CALLBACK_ARGS)
ldp_ifp_destroy(struct interface *ifp)
{
struct interface *ifp;
struct kif kif;

/* zebra_interface_state_read() updates interface structure in iflist */
ifp = zebra_interface_state_read(zclient->ibuf, vrf_id);
if (ifp == NULL)
return (0);

debug_zebra_in("interface delete %s index %d mtu %d", ifp->name,
ifp->ifindex, ifp->mtu);

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

ifp2kif(ifp, &kif);
main_imsg_compose_both(IMSG_IFSTATUS, &kif, sizeof(kif));

Expand Down Expand Up @@ -529,11 +518,6 @@ ldp_zebra_connected(struct zclient *zclient)

extern struct zebra_privs_t ldpd_privs;

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

void
ldp_zebra_init(struct thread_master *master)
{
Expand All @@ -547,7 +531,6 @@ ldp_zebra_init(struct thread_master *master)
/* set callbacks */
zclient->zebra_connected = ldp_zebra_connected;
zclient->router_id_update = ldp_router_id_update;
zclient->interface_delete = ldp_interface_delete;
zclient->interface_address_add = ldp_interface_address_add;
zclient->interface_address_delete = ldp_interface_address_delete;
zclient->redistribute_route_add = ldp_zebra_read_route;
Expand Down
8 changes: 8 additions & 0 deletions lib/if.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ void if_new_via_zapi(struct interface *ifp)
(*ifp_master.create_hook)(ifp);
}

void if_destroy_via_zapi(struct interface *ifp)
{
if (ifp_master.destroy_hook)
(*ifp_master.destroy_hook)(ifp);

if_set_index(ifp, IFINDEX_INTERNAL);
}

void if_up_via_zapi(struct interface *ifp)
{
if (ifp_master.up_hook)
Expand Down
1 change: 1 addition & 0 deletions lib/if.h
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ extern void if_zapi_callbacks(int (*create)(struct interface *ifp),
extern void if_new_via_zapi(struct interface *ifp);
extern void if_up_via_zapi(struct interface *ifp);
extern void if_down_via_zapi(struct interface *ifp);
extern void if_destroy_via_zapi(struct interface *ifp);

extern const struct frr_yang_module_info frr_interface_info;

Expand Down
18 changes: 15 additions & 3 deletions lib/zclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,20 @@ struct interface *zebra_interface_state_read(struct stream *s, vrf_id_t vrf_id)
return ifp;
}

static void zclient_interface_delete(struct zclient *zclient, vrf_id_t vrf_id)
{
struct interface *ifp;
struct stream *s = zclient->ibuf;

ifp = zebra_interface_state_read(s, vrf_id);

if (ifp == NULL)
return;

if_destroy_via_zapi(ifp);
return;
}

static void zclient_interface_up(struct zclient *zclient, vrf_id_t vrf_id)
{
struct interface *ifp;
Expand Down Expand Up @@ -2818,9 +2832,7 @@ static int zclient_read(struct thread *thread)
zclient_interface_add(zclient, vrf_id);
break;
case ZEBRA_INTERFACE_DELETE:
if (zclient->interface_delete)
(*zclient->interface_delete)(command, zclient, length,
vrf_id);
zclient_interface_delete(zclient, vrf_id);
break;
case ZEBRA_INTERFACE_ADDRESS_ADD:
if (zclient->interface_address_add)
Expand Down
1 change: 0 additions & 1 deletion lib/zclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ struct zclient {
void (*zebra_connected)(struct zclient *);
void (*zebra_capabilities)(struct zclient_capabilities *cap);
int (*router_id_update)(ZAPI_CALLBACK_ARGS);
int (*interface_delete)(ZAPI_CALLBACK_ARGS);
int (*interface_address_add)(ZAPI_CALLBACK_ARGS);
int (*interface_address_delete)(ZAPI_CALLBACK_ARGS);
int (*interface_link_params)(ZAPI_CALLBACK_ARGS);
Expand Down
Loading

0 comments on commit de2c8df

Please sign in to comment.