Skip to content

Commit

Permalink
*: Convert from ->interface_up to the interface callback
Browse files Browse the repository at this point in the history
For all the places we have a zclient->interface_up convert
them to use the interface ifp_up callback instead.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
  • Loading branch information
donaldsharp committed Sep 19, 2019
1 parent ef7bd2a commit ddbf3e6
Show file tree
Hide file tree
Showing 28 changed files with 212 additions and 393 deletions.
1 change: 0 additions & 1 deletion babeld/babel_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ void babelz_zebra_init(void)

zclient->zebra_connected = babel_zebra_connected;
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;
Expand Down
20 changes: 3 additions & 17 deletions bgpd/bgp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,27 +227,19 @@ static int bgp_interface_delete(ZAPI_CALLBACK_ARGS)
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 Down Expand Up @@ -2715,11 +2707,6 @@ static int bgp_ifp_create(struct interface *ifp)
return 0;
}

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

static int bgp_ifp_down(struct interface *ifp)
{
return 0;
Expand Down Expand Up @@ -2751,7 +2738,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;
Expand Down
41 changes: 41 additions & 0 deletions eigrpd/eigrp_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "eigrpd/eigrp_topology.h"
#include "eigrpd/eigrp_memory.h"
#include "eigrpd/eigrp_fsm.h"
#include "eigrpd/eigrp_dump.h"

struct eigrp_interface *eigrp_if_new(struct eigrp *eigrp, struct interface *ifp,
struct prefix *p)
Expand Down Expand Up @@ -138,6 +139,46 @@ static int eigrp_ifp_create(struct interface *ifp)

static int eigrp_ifp_up(struct interface *ifp)
{
/* Interface is already up. */
if (if_is_operative(ifp)) {
/* Temporarily keep ifp values. */
struct interface if_tmp;
memcpy(&if_tmp, ifp, sizeof(struct interface));

if (IS_DEBUG_EIGRP(zebra, ZEBRA_INTERFACE))
zlog_debug("Zebra: Interface[%s] state update.",
ifp->name);

if (if_tmp.bandwidth != ifp->bandwidth) {
if (IS_DEBUG_EIGRP(zebra, ZEBRA_INTERFACE))
zlog_debug(
"Zebra: Interface[%s] bandwidth change %d -> %d.",
ifp->name, if_tmp.bandwidth,
ifp->bandwidth);

// eigrp_if_recalculate_output_cost (ifp);
}

if (if_tmp.mtu != ifp->mtu) {
if (IS_DEBUG_EIGRP(zebra, ZEBRA_INTERFACE))
zlog_debug(
"Zebra: Interface[%s] MTU change %u -> %u.",
ifp->name, if_tmp.mtu, ifp->mtu);

/* Must reset the interface (simulate down/up) when MTU
* changes. */
eigrp_if_reset(ifp);
}
return 0;
}

if (IS_DEBUG_EIGRP(zebra, ZEBRA_INTERFACE))
zlog_debug("Zebra: Interface[%s] state change to up.",
ifp->name);

if (ifp->info)
eigrp_if_up(ifp->info);

return 0;
}

Expand Down
72 changes: 0 additions & 72 deletions eigrpd/eigrp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@
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);
static int eigrp_interface_state_up(ZAPI_CALLBACK_ARGS);
static int eigrp_interface_state_down(ZAPI_CALLBACK_ARGS);
static struct interface *zebra_interface_if_lookup(struct stream *,
vrf_id_t vrf_id);

static int eigrp_zebra_read_route(ZAPI_CALLBACK_ARGS);

Expand Down Expand Up @@ -114,7 +111,6 @@ void eigrp_zebra_init(void)
zclient->zebra_connected = eigrp_zebra_connected;
zclient->router_id_update = eigrp_router_id_update_zebra;
zclient->interface_delete = eigrp_interface_delete;
zclient->interface_up = eigrp_interface_state_up;
zclient->interface_down = eigrp_interface_state_down;
zclient->interface_address_add = eigrp_interface_address_add;
zclient->interface_address_delete = eigrp_interface_address_delete;
Expand Down Expand Up @@ -232,62 +228,6 @@ static int eigrp_interface_address_delete(ZAPI_CALLBACK_ARGS)
return 0;
}

static int eigrp_interface_state_up(ZAPI_CALLBACK_ARGS)
{
struct interface *ifp;

ifp = zebra_interface_if_lookup(zclient->ibuf, vrf_id);

if (ifp == NULL)
return 0;

/* Interface is already up. */
if (if_is_operative(ifp)) {
/* Temporarily keep ifp values. */
struct interface if_tmp;
memcpy(&if_tmp, ifp, sizeof(struct interface));

zebra_interface_if_set_value(zclient->ibuf, ifp);

if (IS_DEBUG_EIGRP(zebra, ZEBRA_INTERFACE))
zlog_debug("Zebra: Interface[%s] state update.",
ifp->name);

if (if_tmp.bandwidth != ifp->bandwidth) {
if (IS_DEBUG_EIGRP(zebra, ZEBRA_INTERFACE))
zlog_debug(
"Zebra: Interface[%s] bandwidth change %d -> %d.",
ifp->name, if_tmp.bandwidth,
ifp->bandwidth);

// eigrp_if_recalculate_output_cost (ifp);
}

if (if_tmp.mtu != ifp->mtu) {
if (IS_DEBUG_EIGRP(zebra, ZEBRA_INTERFACE))
zlog_debug(
"Zebra: Interface[%s] MTU change %u -> %u.",
ifp->name, if_tmp.mtu, ifp->mtu);

/* Must reset the interface (simulate down/up) when MTU
* changes. */
eigrp_if_reset(ifp);
}
return 0;
}

zebra_interface_if_set_value(zclient->ibuf, ifp);

if (IS_DEBUG_EIGRP(zebra, ZEBRA_INTERFACE))
zlog_debug("Zebra: Interface[%s] state change to up.",
ifp->name);

if (ifp->info)
eigrp_if_up(ifp->info);

return 0;
}

static int eigrp_interface_state_down(ZAPI_CALLBACK_ARGS)
{
struct interface *ifp;
Expand All @@ -307,18 +247,6 @@ static int eigrp_interface_state_down(ZAPI_CALLBACK_ARGS)
return 0;
}

static struct interface *zebra_interface_if_lookup(struct stream *s,
vrf_id_t vrf_id)
{
char ifname_tmp[INTERFACE_NAMSIZ];

/* Read interface name. */
stream_get(ifname_tmp, s, INTERFACE_NAMSIZ);

/* And look it up. */
return if_lookup_by_name(ifname_tmp, vrf_id);
}

void eigrp_zebra_route_add(struct eigrp *eigrp, struct prefix *p,
struct list *successors, uint32_t distance)
{
Expand Down
2 changes: 2 additions & 0 deletions isisd/isis_circuit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,8 @@ static int isis_ifp_create(struct interface *ifp)

static int isis_ifp_up(struct interface *ifp)
{
isis_csm_state_change(IF_UP_FROM_Z, circuit_scan_by_ifp(ifp), ifp);

return 0;
}

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

static int isis_zebra_if_state_up(ZAPI_CALLBACK_ARGS)
{
struct interface *ifp;

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

if (ifp == NULL)
return 0;

isis_csm_state_change(IF_UP_FROM_Z, circuit_scan_by_ifp(ifp), ifp);

return 0;
}

static int isis_zebra_if_state_down(ZAPI_CALLBACK_ARGS)
{
struct interface *ifp;
Expand Down Expand Up @@ -372,7 +358,6 @@ void isis_zebra_init(struct thread_master *master)
zclient->zebra_connected = isis_zebra_connected;
zclient->router_id_update = isis_router_id_update_zebra;
zclient->interface_delete = isis_zebra_if_del;
zclient->interface_up = isis_zebra_if_state_up;
zclient->interface_down = isis_zebra_if_state_down;
zclient->interface_address_add = isis_zebra_if_address_add;
zclient->interface_address_delete = isis_zebra_if_address_del;
Expand Down
29 changes: 17 additions & 12 deletions ldpd/ldp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,22 +301,13 @@ ldp_interface_delete(ZAPI_CALLBACK_ARGS)
}

static int
ldp_interface_status_change(ZAPI_CALLBACK_ARGS)
ldp_interface_status_change_helper(struct interface *ifp)
{
struct interface *ifp;
struct listnode *node;
struct connected *ifc;
struct kif kif;
struct kaddr ka;

/*
* 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 %s state update", ifp->name);

ifp2kif(ifp, &kif);
Expand All @@ -338,6 +329,21 @@ ldp_interface_status_change(ZAPI_CALLBACK_ARGS)

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

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

return ldp_interface_status_change_helper(ifp);
}

static int
ldp_interface_address_add(ZAPI_CALLBACK_ARGS)
Expand Down Expand Up @@ -531,7 +537,7 @@ extern struct zebra_privs_t ldpd_privs;

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

static int ldp_ifp_down(struct interface *ifp)
Expand All @@ -558,7 +564,6 @@ ldp_zebra_init(struct thread_master *master)
zclient->zebra_connected = ldp_zebra_connected;
zclient->router_id_update = ldp_router_id_update;
zclient->interface_delete = ldp_interface_delete;
zclient->interface_up = ldp_interface_status_change;
zclient->interface_down = ldp_interface_status_change;
zclient->interface_address_add = ldp_interface_address_add;
zclient->interface_address_delete = ldp_interface_address_delete;
Expand Down
6 changes: 6 additions & 0 deletions lib/if.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ void if_new_via_zapi(struct interface *ifp)
(*ifp_master.create_hook)(ifp);
}

void if_up_via_zapi(struct interface *ifp)
{
if (ifp_master.up_hook)
(*ifp_master.up_hook)(ifp);
}

struct interface *if_create(const char *name, vrf_id_t vrf_id)
{
return if_create_backend(name, IFINDEX_INTERNAL, vrf_id);
Expand Down
1 change: 1 addition & 0 deletions lib/if.h
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ extern void if_zapi_callbacks(int (*create)(struct interface *ifp),
int (*destroy)(struct interface *ifp));

extern void if_new_via_zapi(struct interface *ifp);
extern void if_up_via_zapi(struct interface *ifp);

extern const struct frr_yang_module_info frr_interface_info;

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

static void zclient_interface_up(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)
return;

if_up_via_zapi(ifp);
}

static void link_params_set_value(struct stream *s, struct if_link_params *iflp)
{

Expand Down Expand Up @@ -2822,9 +2835,7 @@ static int zclient_read(struct thread *thread)
command, zclient, length, vrf_id);
break;
case ZEBRA_INTERFACE_UP:
if (zclient->interface_up)
(*zclient->interface_up)(command, zclient, length,
vrf_id);
zclient_interface_up(zclient, vrf_id);
break;
case ZEBRA_INTERFACE_DOWN:
if (zclient->interface_down)
Expand Down
1 change: 0 additions & 1 deletion lib/zclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ struct zclient {
void (*zebra_capabilities)(struct zclient_capabilities *cap);
int (*router_id_update)(ZAPI_CALLBACK_ARGS);
int (*interface_delete)(ZAPI_CALLBACK_ARGS);
int (*interface_up)(ZAPI_CALLBACK_ARGS);
int (*interface_down)(ZAPI_CALLBACK_ARGS);
int (*interface_address_add)(ZAPI_CALLBACK_ARGS);
int (*interface_address_delete)(ZAPI_CALLBACK_ARGS);
Expand Down
Loading

0 comments on commit ddbf3e6

Please sign in to comment.