Skip to content

Commit

Permalink
*: Add infrastructure to support zapi interface callbacks
Browse files Browse the repository at this point in the history
Start the conversion to allow zapi interface callbacks to be
controlled like vrf creation/destruction/change callbacks.

This will allow us to consolidate control into the interface.c
instead of having each daemon read the stream and react accordingly.
This will hopefully reduce a bunch of cut-n-paste stuff

Create 4 new callback functions that will be controlled by
lib/if.c

create -> A upper level protocol receives an interface creation event
The ifp is brand spanking newly created in the system.
up -> A upper level protocol receives a interface up event
This means the interface is up and ready to go.
down -> A upper level protocol receives a interface down
destroy -> A upper level protocol receives a destroy event
This means to delete the pointers associated with it.

At this point this is just boilerplate setup for future commits.
There is no new functionality.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
  • Loading branch information
donaldsharp committed Sep 18, 2019
1 parent c9d4e5f commit c4ff9fa
Show file tree
Hide file tree
Showing 27 changed files with 315 additions and 14 deletions.
23 changes: 22 additions & 1 deletion babeld/babel_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,26 @@ DEFUN (show_babel_parameters,
return CMD_SUCCESS;
}

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

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

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

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

void
babel_if_init(void)
{
Expand All @@ -1271,7 +1291,8 @@ babel_if_init(void)

/* install interface node and commands */
install_node (&babel_interface_node, interface_config_write);
if_cmd_init();
if_cmd_init(babel_ifp_create, babel_ifp_up,
babel_ifp_down, babel_ifp_destroy);

install_element(BABEL_NODE, &babel_network_cmd);
install_element(BABEL_NODE, &no_babel_network_cmd);
Expand Down
23 changes: 22 additions & 1 deletion eigrpd/eigrp_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,26 @@ static int eigrp_write_interface(struct vty *vty)
return written;
}

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

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

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

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

void
eigrp_cli_init(void)
{
Expand All @@ -907,7 +927,8 @@ eigrp_cli_init(void)
install_element(EIGRP_NODE, &eigrp_redistribute_source_metric_cmd);

install_node(&eigrp_interface_node, eigrp_write_interface);
if_cmd_init();
if_cmd_init(eigrp_ifp_create, eigrp_ifp_up,
eigrp_ifp_down, eigrp_ifp_destroy);

install_element(INTERFACE_NODE, &eigrp_if_delay_cmd);
install_element(INTERFACE_NODE, &no_eigrp_if_delay_cmd);
Expand Down
20 changes: 20 additions & 0 deletions eigrpd/eigrp_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,23 @@ uint32_t eigrp_scaled_to_delay(uint32_t scaled)
{
return scaled / 256;
}

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

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

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

int eigrp_ifp_destroy(struct interface *ifp)
{
return 0;
}
4 changes: 4 additions & 0 deletions eigrpd/eigrp_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,9 @@ extern uint32_t eigrp_scaled_to_bandwidth(uint32_t);
extern uint32_t eigrp_delay_to_scaled(uint32_t);
extern uint32_t eigrp_scaled_to_delay(uint32_t);

extern int eigrp_ifp_create(struct interface *ifp);
extern int eigrp_ifp_up(struct interface *ifp);
extern int eigrp_ifp_down(struct interface *ifp);
extern int eigrp_ifp_destroy(struct interface *ifp);

#endif /* ZEBRA_EIGRP_INTERFACE_H_ */
23 changes: 22 additions & 1 deletion isisd/isis_circuit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,26 @@ int isis_if_delete_hook(struct interface *ifp)
return 0;
}

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

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

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

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

void isis_circuit_init(void)
{
/* Initialize Zebra interface data structure */
Expand All @@ -1397,5 +1417,6 @@ void isis_circuit_init(void)

/* Install interface node */
install_node(&interface_node, isis_interface_config_write);
if_cmd_init();
if_cmd_init(isis_ifp_create, isis_ifp_up,
isis_ifp_down, isis_ifp_destroy);
}
17 changes: 16 additions & 1 deletion lib/if.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ DEFINE_QOBJ_TYPE(interface)
DEFINE_HOOK(if_add, (struct interface * ifp), (ifp))
DEFINE_KOOH(if_del, (struct interface * ifp), (ifp))

struct interface_master{
int (*create_hook)(struct interface *ifp);
int (*up_hook)(struct interface *ifp);
int (*down_hook)(struct interface *ifp);
int (*destroy_hook)(struct interface *ifp);
} ifp_master = { 0, };

/* Compare interface names, returning an integer greater than, equal to, or
* less than 0, (following the strcmp convention), according to the
* relationship between ifp1 and ifp2. Interface names consist of an
Expand Down Expand Up @@ -1358,7 +1365,10 @@ static const struct cmd_variable_handler if_var_handlers[] = {
{.tokenname = "INTERFACE", .completions = if_autocomplete},
{.completions = NULL}};

void if_cmd_init(void)
void if_cmd_init(int (*create)(struct interface *ifp),
int (*up)(struct interface *ifp),
int (*down)(struct interface *ifp),
int (*destroy)(struct interface *ifp))
{
cmd_variable_handler_register(if_var_handlers);

Expand All @@ -1368,6 +1378,11 @@ void if_cmd_init(void)
install_default(INTERFACE_NODE);
install_element(INTERFACE_NODE, &interface_desc_cmd);
install_element(INTERFACE_NODE, &no_interface_desc_cmd);

ifp_master.create_hook = create;
ifp_master.up_hook = up;
ifp_master.down_hook = down;
ifp_master.destroy_hook = destroy;
}

/* ------- Northbound callbacks ------- */
Expand Down
6 changes: 5 additions & 1 deletion lib/if.h
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,11 @@ struct if_link_params *if_link_params_get(struct interface *);
void if_link_params_free(struct interface *);

/* Northbound. */
extern void if_cmd_init(void);
extern void if_cmd_init(int (*create)(struct interface *ifp),
int (*up)(struct interface *ifp),
int (*down)(struct interface *ifp),
int (*destroy)(struct interface *ifp));

extern const struct frr_yang_module_info frr_interface_info;

#ifdef __cplusplus
Expand Down
20 changes: 20 additions & 0 deletions nhrpd/nhrp_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,23 @@ void nhrp_interface_set_source(struct interface *ifp, const char *ifname)

nhrp_interface_update_nbma(ifp);
}

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

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

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

int nhrp_ifp_destroy(struct interface *ifp)
{
return 0;
}
Empty file added nhrpd/nhrp_interface.h
Empty file.
3 changes: 2 additions & 1 deletion nhrpd/nhrp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,8 @@ void nhrp_config_init(void)
/* interface specific commands */
install_node(&nhrp_interface_node, interface_config_write);

if_cmd_init();
if_cmd_init(nhrp_ifp_create, nhrp_ifp_up,
nhrp_ifp_down, nhrp_ifp_destroy);
install_element(INTERFACE_NODE, &tunnel_protection_cmd);
install_element(INTERFACE_NODE, &no_tunnel_protection_cmd);
install_element(INTERFACE_NODE, &tunnel_source_cmd);
Expand Down
4 changes: 4 additions & 0 deletions nhrpd/nhrpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ void nhrp_interface_notify_del(struct interface *ifp, struct notifier_block *n);
void nhrp_interface_set_protection(struct interface *ifp, const char *profile,
const char *fallback_profile);
void nhrp_interface_set_source(struct interface *ifp, const char *ifname);
extern int nhrp_ifp_create(struct interface *ifp);
extern int nhrp_ifp_up(struct interface *ifp);
extern int nhrp_ifp_down(struct interface *ifp);
extern int nhrp_ifp_destroy(struct interface *ifp);

int nhrp_nhs_add(struct interface *ifp, afi_t afi, union sockunion *proto_addr,
const char *nbma_fqdn);
Expand Down
23 changes: 22 additions & 1 deletion ospf6d/ospf6_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -1935,11 +1935,32 @@ static struct cmd_node interface_node = {
INTERFACE_NODE, "%s(config-if)# ", 1 /* VTYSH */
};

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

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

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

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

void ospf6_interface_init(void)
{
/* Install interface node. */
install_node(&interface_node, config_write_ospf6_interface);
if_cmd_init();
if_cmd_init(ospf6_ifp_create, ospf6_ifp_up,
ospf6_ifp_down, ospf6_ifp_destroy);

install_element(VIEW_NODE, &show_ipv6_ospf6_interface_prefix_cmd);
install_element(VIEW_NODE, &show_ipv6_ospf6_interface_ifname_cmd);
Expand Down
20 changes: 20 additions & 0 deletions ospfd/ospf_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -1224,3 +1224,23 @@ void ospf_if_init(void)
hook_register_prio(if_add, 0, ospf_if_new_hook);
hook_register_prio(if_del, 0, ospf_if_delete_hook);
}

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

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

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

int ospf_ifp_destroy(struct interface *ifp)
{
return 0;
}
5 changes: 5 additions & 0 deletions ospfd/ospf_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ extern int ospf_crypt_key_delete(struct list *, uint8_t);
extern uint8_t ospf_default_iftype(struct interface *ifp);
extern int ospf_interface_neighbor_count(struct ospf_interface *oi);

extern int ospf_ifp_create(struct interface *ifp);
extern int ospf_ifp_up(struct interface *ifp);
extern int ospf_ifp_down(struct interface *ifp);
extern int ospf_ifp_destroy(struct interface *ifp);

/* Set all multicast memberships appropriately based on the type and
state of the interface. */
extern void ospf_if_set_multicast(struct ospf_interface *);
Expand Down
3 changes: 2 additions & 1 deletion ospfd/ospf_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -10541,7 +10541,8 @@ static void ospf_vty_if_init(void)
{
/* Install interface node. */
install_node(&interface_node, config_write_interface);
if_cmd_init();
if_cmd_init(ospf_ifp_create, ospf_ifp_up,
ospf_ifp_down, ospf_ifp_destroy);

/* "ip ospf authentication" commands. */
install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd);
Expand Down
3 changes: 2 additions & 1 deletion pbrd/pbr_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,8 @@ void pbr_vty_init(void)

install_node(&interface_node,
pbr_interface_config_write);
if_cmd_init();
if_cmd_init(pbr_ifp_create, pbr_ifp_up,
pbr_ifp_down, pbr_ifp_destroy);

install_node(&pbr_map_node,
pbr_vty_map_config_write);
Expand Down
20 changes: 20 additions & 0 deletions pbrd/pbr_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,3 +579,23 @@ void pbr_send_pbr_map(struct pbr_map_sequence *pbrms,

zclient_send_message(zclient);
}

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

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

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

int pbr_ifp_destroy(struct interface *ifp)
{
return 0;
}
6 changes: 6 additions & 0 deletions pbrd/pbr_zebra.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ extern void pbr_send_pbr_map(struct pbr_map_sequence *pbrms,
struct pbr_map_interface *pmi, bool install);

extern struct pbr_interface *pbr_if_new(struct interface *ifp);

extern int pbr_ifp_create(struct interface *ifp);
extern int pbr_ifp_up(struct interface *ifp);
extern int pbr_ifp_down(struct interface *ifp);
extern int pbr_ifp_destroy(struct interface *ifp);

#endif
3 changes: 2 additions & 1 deletion pimd/pim_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -10194,7 +10194,8 @@ void pim_cmd_init(void)
{
install_node(&interface_node,
pim_interface_config_write); /* INTERFACE_NODE */
if_cmd_init();
if_cmd_init(pim_ifp_create, pim_ifp_up,
pim_ifp_down, pim_ifp_destroy);

install_node(&debug_node, pim_debug_config_write);

Expand Down
20 changes: 20 additions & 0 deletions pimd/pim_iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -1526,3 +1526,23 @@ int pim_if_ifchannel_count(struct pim_interface *pim_ifp)

return count;
}

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

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

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

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

0 comments on commit c4ff9fa

Please sign in to comment.