From c4ff9fa9be7736f1ac7f6dec4d8820cae9cea004 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 18 Sep 2019 16:20:04 -0400 Subject: [PATCH] *: Add infrastructure to support zapi interface callbacks 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 --- babeld/babel_interface.c | 23 ++++++++++++++++++++++- eigrpd/eigrp_cli.c | 23 ++++++++++++++++++++++- eigrpd/eigrp_interface.c | 20 ++++++++++++++++++++ eigrpd/eigrp_interface.h | 4 ++++ isisd/isis_circuit.c | 23 ++++++++++++++++++++++- lib/if.c | 17 ++++++++++++++++- lib/if.h | 6 +++++- nhrpd/nhrp_interface.c | 20 ++++++++++++++++++++ nhrpd/nhrp_interface.h | 0 nhrpd/nhrp_vty.c | 3 ++- nhrpd/nhrpd.h | 4 ++++ ospf6d/ospf6_interface.c | 23 ++++++++++++++++++++++- ospfd/ospf_interface.c | 20 ++++++++++++++++++++ ospfd/ospf_interface.h | 5 +++++ ospfd/ospf_vty.c | 3 ++- pbrd/pbr_vty.c | 3 ++- pbrd/pbr_zebra.c | 20 ++++++++++++++++++++ pbrd/pbr_zebra.h | 6 ++++++ pimd/pim_cmd.c | 3 ++- pimd/pim_iface.c | 20 ++++++++++++++++++++ pimd/pim_iface.h | 6 ++++++ ripd/rip_interface.c | 23 ++++++++++++++++++++++- ripngd/ripng_interface.c | 23 ++++++++++++++++++++++- vrrpd/vrrp_vty.c | 4 +++- vrrpd/vrrp_zebra.c | 20 ++++++++++++++++++++ vrrpd/vrrp_zebra.h | 5 +++++ zebra/interface.c | 2 +- 27 files changed, 315 insertions(+), 14 deletions(-) create mode 100644 nhrpd/nhrp_interface.h diff --git a/babeld/babel_interface.c b/babeld/babel_interface.c index 0eeb9b2bbbfa..a62b80c7493b 100644 --- a/babeld/babel_interface.c +++ b/babeld/babel_interface.c @@ -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) { @@ -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); diff --git a/eigrpd/eigrp_cli.c b/eigrpd/eigrp_cli.c index a93d4c828070..176eb19a3227 100644 --- a/eigrpd/eigrp_cli.c +++ b/eigrpd/eigrp_cli.c @@ -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) { @@ -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); diff --git a/eigrpd/eigrp_interface.c b/eigrpd/eigrp_interface.c index fd1d3f5cb9e0..f232a6642bd0 100644 --- a/eigrpd/eigrp_interface.c +++ b/eigrpd/eigrp_interface.c @@ -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; +} diff --git a/eigrpd/eigrp_interface.h b/eigrpd/eigrp_interface.h index a18b0b7015d0..13e7c835810f 100644 --- a/eigrpd/eigrp_interface.h +++ b/eigrpd/eigrp_interface.h @@ -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_ */ diff --git a/isisd/isis_circuit.c b/isisd/isis_circuit.c index 5da8e6ee9e2e..a65ba92f7274 100644 --- a/isisd/isis_circuit.c +++ b/isisd/isis_circuit.c @@ -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 */ @@ -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); } diff --git a/lib/if.c b/lib/if.c index e47669f438c8..9076c2feb389 100644 --- a/lib/if.c +++ b/lib/if.c @@ -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 @@ -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); @@ -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 ------- */ diff --git a/lib/if.h b/lib/if.h index ee99fad2e16b..8085273b3f9d 100644 --- a/lib/if.h +++ b/lib/if.h @@ -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 diff --git a/nhrpd/nhrp_interface.c b/nhrpd/nhrp_interface.c index 8f1ba14fe4f2..31e19eda3ed3 100644 --- a/nhrpd/nhrp_interface.c +++ b/nhrpd/nhrp_interface.c @@ -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; +} diff --git a/nhrpd/nhrp_interface.h b/nhrpd/nhrp_interface.h new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/nhrpd/nhrp_vty.c b/nhrpd/nhrp_vty.c index cfedc1c6b927..2bef67fe0238 100644 --- a/nhrpd/nhrp_vty.c +++ b/nhrpd/nhrp_vty.c @@ -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); diff --git a/nhrpd/nhrpd.h b/nhrpd/nhrpd.h index 670c9f4f18c6..50746d9ad5c0 100644 --- a/nhrpd/nhrpd.h +++ b/nhrpd/nhrpd.h @@ -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); diff --git a/ospf6d/ospf6_interface.c b/ospf6d/ospf6_interface.c index 692c84ad08e7..1abcadc36acb 100644 --- a/ospf6d/ospf6_interface.c +++ b/ospf6d/ospf6_interface.c @@ -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); diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c index 387770870811..d8b541589536 100644 --- a/ospfd/ospf_interface.c +++ b/ospfd/ospf_interface.c @@ -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; +} diff --git a/ospfd/ospf_interface.h b/ospfd/ospf_interface.h index 0c903954d321..b8268a3afa69 100644 --- a/ospfd/ospf_interface.h +++ b/ospfd/ospf_interface.h @@ -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 *); diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 8fa91f500c31..92c6751d9b41 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -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); diff --git a/pbrd/pbr_vty.c b/pbrd/pbr_vty.c index 5e7addc9d2b0..83686f42e0b8 100644 --- a/pbrd/pbr_vty.c +++ b/pbrd/pbr_vty.c @@ -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); diff --git a/pbrd/pbr_zebra.c b/pbrd/pbr_zebra.c index d74d0fcd23d3..b8df7fc5ae94 100644 --- a/pbrd/pbr_zebra.c +++ b/pbrd/pbr_zebra.c @@ -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; +} diff --git a/pbrd/pbr_zebra.h b/pbrd/pbr_zebra.h index 4cbefe263635..d5d938021ae7 100644 --- a/pbrd/pbr_zebra.h +++ b/pbrd/pbr_zebra.h @@ -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 diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 28b4af9457f7..75d63ef5eb23 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -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); diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index bdeda2d76b71..d20713b9c520 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -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; +} diff --git a/pimd/pim_iface.h b/pimd/pim_iface.h index 1c11e8570518..1b76b5230595 100644 --- a/pimd/pim_iface.h +++ b/pimd/pim_iface.h @@ -227,4 +227,10 @@ int pim_update_source_set(struct interface *ifp, struct in_addr source); bool pim_if_is_vrf_device(struct interface *ifp); int pim_if_ifchannel_count(struct pim_interface *pim_ifp); + +extern int pim_ifp_create(struct interface *ifp); +extern int pim_ifp_up(struct interface *ifp); +extern int pim_ifp_down(struct interface *ifp); +extern int pim_ifp_destroy(struct interface *ifp); + #endif /* PIM_IFACE_H */ diff --git a/ripd/rip_interface.c b/ripd/rip_interface.c index 80561f350ba2..74a87996b4b0 100644 --- a/ripd/rip_interface.c +++ b/ripd/rip_interface.c @@ -1253,6 +1253,26 @@ static int rip_interface_delete_hook(struct interface *ifp) return 0; } +static int rip_ifp_create(struct interface *ifp) +{ + return 0; +} + +static int rip_ifp_up(struct interface *ifp) +{ + return 0; +} + +static int rip_ifp_down(struct interface *ifp) +{ + return 0; +} + +static int rip_ifp_destroy(struct interface *ifp) +{ + return 0; +} + /* Allocate and initialize interface vector. */ void rip_if_init(void) { @@ -1262,5 +1282,6 @@ void rip_if_init(void) /* Install interface node. */ install_node(&interface_node, rip_interface_config_write); - if_cmd_init(); + if_cmd_init(rip_ifp_create, rip_ifp_up, + rip_ifp_down, rip_ifp_destroy); } diff --git a/ripngd/ripng_interface.c b/ripngd/ripng_interface.c index 9ed9dc28feb2..ab2449b8a512 100644 --- a/ripngd/ripng_interface.c +++ b/ripngd/ripng_interface.c @@ -989,6 +989,26 @@ static struct cmd_node interface_node = { INTERFACE_NODE, "%s(config-if)# ", 1 /* VTYSH */ }; +static int ripng_ifp_create(struct interface *ifp) +{ + return 0; +} + +static int ripng_ifp_up(struct interface *ifp) +{ + return 0; +} + +static int ripng_ifp_down(struct interface *ifp) +{ + return 0; +} + +static int ripng_ifp_destroy(struct interface *ifp) +{ + return 0; +} + /* Initialization of interface. */ void ripng_if_init(void) { @@ -998,5 +1018,6 @@ void ripng_if_init(void) /* Install interface node. */ install_node(&interface_node, interface_config_write); - if_cmd_init(); + if_cmd_init(ripng_ifp_create, ripng_ifp_up, + ripng_ifp_down, ripng_ifp_destroy); } diff --git a/vrrpd/vrrp_vty.c b/vrrpd/vrrp_vty.c index 2dc3d3f8a393..334b3e255671 100644 --- a/vrrpd/vrrp_vty.c +++ b/vrrpd/vrrp_vty.c @@ -30,6 +30,7 @@ #include "vrrp.h" #include "vrrp_debug.h" #include "vrrp_vty.h" +#include "vrrp_zebra.h" #ifndef VTYSH_EXTRACT_PL #include "vrrpd/vrrp_vty_clippy.c" #endif @@ -731,7 +732,8 @@ void vrrp_vty_init(void) install_node(&debug_node, vrrp_config_write_debug); install_node(&interface_node, vrrp_config_write_interface); install_node(&vrrp_node, vrrp_config_write_global); - if_cmd_init(); + if_cmd_init(vrrp_ifp_create, vrrp_ifp_up, + vrrp_ifp_down, vrrp_ifp_destroy); install_element(VIEW_NODE, &vrrp_vrid_show_cmd); install_element(VIEW_NODE, &vrrp_vrid_show_summary_cmd); diff --git a/vrrpd/vrrp_zebra.c b/vrrpd/vrrp_zebra.c index 72b77c131369..976072d51f6f 100644 --- a/vrrpd/vrrp_zebra.c +++ b/vrrpd/vrrp_zebra.c @@ -254,3 +254,23 @@ void vrrp_zebra_init(void) zlog_notice("%s: zclient socket initialized", __PRETTY_FUNCTION__); } + +int vrrp_ifp_create(struct interface *ifp) +{ + return 0; +} + +int vrrp_ifp_up(struct interface *ifp) +{ + return 0; +} + +int vrrp_ifp_down(struct interface *ifp) +{ + return 0; +} + +int vrrp_ifp_destroy(struct interface *ifp) +{ + return 0; +} diff --git a/vrrpd/vrrp_zebra.h b/vrrpd/vrrp_zebra.h index 84bcba23c19a..02d7055b8600 100644 --- a/vrrpd/vrrp_zebra.h +++ b/vrrpd/vrrp_zebra.h @@ -29,4 +29,9 @@ extern void vrrp_zebra_radv_set(struct vrrp_router *r, bool enable); extern int vrrp_zclient_send_interface_protodown(struct interface *ifp, bool down); +extern int vrrp_ifp_create(struct interface *ifp); +extern int vrrp_ifp_up(struct interface *ifp); +extern int vrrp_ifp_down(struct interface *ifp); +extern int vrrp_ifp_destroy(struct interface *ifp); + #endif /* __VRRP_ZEBRA_H__ */ diff --git a/zebra/interface.c b/zebra/interface.c index d21ab25fed45..820808024dc8 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -3201,7 +3201,7 @@ void zebra_if_init(void) /* Install configuration write function. */ install_node(&interface_node, if_config_write); install_node(&link_params_node, NULL); - if_cmd_init(); + if_cmd_init(NULL, NULL, NULL, NULL); install_element(VIEW_NODE, &show_interface_cmd); install_element(VIEW_NODE, &show_interface_vrf_all_cmd);