diff options
author | Donald Sharp <sharpd@cumulusnetworks.com> | 2019-09-19 04:26:55 +0200 |
---|---|---|
committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2019-09-19 19:34:06 +0200 |
commit | ef7bd2a3d5ecab37018f4035391f99c25ddadeab (patch) | |
tree | e5fb8c3b974e01a2f1ad848b6337583b49efe374 | |
parent | *: Add infrastructure to support zapi interface callbacks (diff) | |
download | frr-ef7bd2a3d5ecab37018f4035391f99c25ddadeab.tar.xz frr-ef7bd2a3d5ecab37018f4035391f99c25ddadeab.zip |
*: Switch all zclient->interface_add to interface create callback
Switch the zclient->interface_add functionality to have everyone
use the interface create callback in lib/if.c
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
34 files changed, 155 insertions, 347 deletions
diff --git a/babeld/babel_interface.c b/babeld/babel_interface.c index 898848f84..a0df6d9e1 100644 --- a/babeld/babel_interface.c +++ b/babeld/babel_interface.c @@ -104,23 +104,14 @@ 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; + } int babel_interface_delete (ZAPI_CALLBACK_ARGS) @@ -1260,11 +1251,6 @@ DEFUN (show_babel_parameters, return CMD_SUCCESS; } -int babel_ifp_create(struct interface *ifp) -{ - return 0; -} - int babel_ifp_up(struct interface *ifp) { return 0; diff --git a/babeld/babel_zebra.c b/babeld/babel_zebra.c index d70823544..3b58db7f2 100644 --- a/babeld/babel_zebra.c +++ b/babeld/babel_zebra.c @@ -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_add = babel_interface_add; zclient->interface_delete = babel_interface_delete; zclient->interface_up = babel_interface_up; zclient->interface_down = babel_interface_down; diff --git a/bfdd/ptm_adapter.c b/bfdd/ptm_adapter.c index 2d1b17ce4..dc90b4d6e 100644 --- a/bfdd/ptm_adapter.c +++ b/bfdd/ptm_adapter.c @@ -677,20 +677,6 @@ static int bfdd_interface_update(ZAPI_CALLBACK_ARGS) { 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) @@ -758,6 +744,8 @@ static int bfdd_interface_address_update(ZAPI_CALLBACK_ARGS) static int bfd_ifp_create(struct interface *ifp) { + bfdd_sessions_enable_interface(ifp); + return 0; } @@ -784,7 +772,6 @@ void bfdd_zclient_init(struct zebra_privs_t *bfdd_priv) 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. */ diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index ee523e51c..3477b9491 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -202,29 +202,6 @@ 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) -{ - 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; @@ -2723,6 +2700,18 @@ 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; } @@ -2753,7 +2742,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_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; diff --git a/eigrpd/eigrp_interface.c b/eigrpd/eigrp_interface.c index 76e101b01..f2faf22e8 100644 --- a/eigrpd/eigrp_interface.c +++ b/eigrpd/eigrp_interface.c @@ -124,6 +124,15 @@ int eigrp_if_delete_hook(struct interface *ifp) static int eigrp_ifp_create(struct interface *ifp) { + struct eigrp_interface *ei = ifp->info; + + if (!ei) + return 0; + + ei->params.type = eigrp_default_iftype(ifp); + + eigrp_if_update(ifp); + return 0; } diff --git a/eigrpd/eigrp_zebra.c b/eigrpd/eigrp_zebra.c index 63cbe84ef..8c8f73b5b 100644 --- a/eigrpd/eigrp_zebra.c +++ b/eigrpd/eigrp_zebra.c @@ -53,7 +53,6 @@ #include "eigrpd/eigrp_topology.h" #include "eigrpd/eigrp_fsm.h" -static int eigrp_interface_add(ZAPI_CALLBACK_ARGS); 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); @@ -114,7 +113,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_add = eigrp_interface_add; zclient->interface_delete = eigrp_interface_delete; zclient->interface_up = eigrp_interface_state_up; zclient->interface_down = eigrp_interface_state_down; @@ -151,26 +149,6 @@ static int eigrp_zebra_read_route(ZAPI_CALLBACK_ARGS) return 0; } -/* Inteface addition message from zebra. */ -static int eigrp_interface_add(ZAPI_CALLBACK_ARGS) -{ - struct interface *ifp; - struct eigrp_interface *ei; - - ifp = zebra_interface_add_read(zclient->ibuf, vrf_id); - - if (!ifp->info) - return 0; - - ei = ifp->info; - - ei->params.type = eigrp_default_iftype(ifp); - - eigrp_if_update(ifp); - - return 0; -} - static int eigrp_interface_delete(ZAPI_CALLBACK_ARGS) { struct interface *ifp; diff --git a/isisd/isis_circuit.c b/isisd/isis_circuit.c index 64ec04705..c78554e5e 100644 --- a/isisd/isis_circuit.c +++ b/isisd/isis_circuit.c @@ -61,6 +61,8 @@ DEFINE_QOBJ_TYPE(isis_circuit) +DEFINE_HOOK(isis_if_new_hook, (struct interface *ifp), (ifp)) + /* * Prototypes. */ @@ -1391,6 +1393,12 @@ int isis_if_delete_hook(struct interface *ifp) static int isis_ifp_create(struct interface *ifp) { + if (if_is_operative(ifp)) + isis_csm_state_change(IF_UP_FROM_Z, circuit_scan_by_ifp(ifp), + ifp); + + hook_call(isis_if_new_hook, ifp); + return 0; } diff --git a/isisd/isis_circuit.h b/isisd/isis_circuit.h index e3541644a..e834e3160 100644 --- a/isisd/isis_circuit.h +++ b/isisd/isis_circuit.h @@ -32,6 +32,8 @@ #include "isis_constants.h" #include "isis_common.h" +DECLARE_HOOK(isis_if_new_hook, (struct interface *ifp), (ifp)); + struct isis_lsp; struct password { diff --git a/isisd/isis_zebra.c b/isisd/isis_zebra.c index 39a2f6ef3..ea4622db3 100644 --- a/isisd/isis_zebra.c +++ b/isisd/isis_zebra.c @@ -53,8 +53,6 @@ struct zclient *zclient = NULL; -DEFINE_HOOK(isis_if_new_hook, (struct interface *ifp), (ifp)) - /* Router-id update message from zebra. */ static int isis_router_id_update_zebra(ZAPI_CALLBACK_ARGS) { @@ -74,21 +72,6 @@ static int isis_router_id_update_zebra(ZAPI_CALLBACK_ARGS) return 0; } -static int isis_zebra_if_add(ZAPI_CALLBACK_ARGS) -{ - struct interface *ifp; - - ifp = zebra_interface_add_read(zclient->ibuf, vrf_id); - - if (if_is_operative(ifp)) - isis_csm_state_change(IF_UP_FROM_Z, circuit_scan_by_ifp(ifp), - ifp); - - hook_call(isis_if_new_hook, ifp); - - return 0; -} - static int isis_zebra_if_del(ZAPI_CALLBACK_ARGS) { struct interface *ifp; @@ -388,7 +371,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_add = isis_zebra_if_add; zclient->interface_delete = isis_zebra_if_del; zclient->interface_up = isis_zebra_if_state_up; zclient->interface_down = isis_zebra_if_state_down; diff --git a/isisd/isis_zebra.h b/isisd/isis_zebra.h index 83a32108e..d00f348c8 100644 --- a/isisd/isis_zebra.h +++ b/isisd/isis_zebra.h @@ -24,8 +24,6 @@ extern struct zclient *zclient; -DECLARE_HOOK(isis_if_new_hook, (struct interface *ifp), (ifp)); - void isis_zebra_init(struct thread_master *); void isis_zebra_stop(void); diff --git a/ldpd/ldp_zebra.c b/ldpd/ldp_zebra.c index 251df7388..d24079f41 100644 --- a/ldpd/ldp_zebra.c +++ b/ldpd/ldp_zebra.c @@ -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_add(ZAPI_CALLBACK_ARGS); static int ldp_interface_delete(ZAPI_CALLBACK_ARGS); static int ldp_interface_status_change(ZAPI_CALLBACK_ARGS); static int ldp_interface_address_add(ZAPI_CALLBACK_ARGS); @@ -264,19 +263,17 @@ ldp_router_id_update(ZAPI_CALLBACK_ARGS) } static int -ldp_interface_add(ZAPI_CALLBACK_ARGS) +ldp_ifp_create(struct interface *ifp) { - struct interface *ifp; struct kif kif; - ifp = zebra_interface_add_read(zclient->ibuf, vrf_id); debug_zebra_in("interface add %s index %d mtu %d", ifp->name, ifp->ifindex, ifp->mtu); ifp2kif(ifp, &kif); main_imsg_compose_both(IMSG_IFSTATUS, &kif, sizeof(kif)); - return (0); + return 0; } static int @@ -532,11 +529,6 @@ ldp_zebra_connected(struct zclient *zclient) extern struct zebra_privs_t ldpd_privs; -static int ldp_ifp_create(struct interface *ifp) -{ - return 0; -} - static int ldp_ifp_up(struct interface *ifp) { return 0; @@ -565,7 +557,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_add = ldp_interface_add; zclient->interface_delete = ldp_interface_delete; zclient->interface_up = ldp_interface_status_change; zclient->interface_down = ldp_interface_status_change; @@ -175,6 +175,12 @@ static struct interface *if_create_backend(const char *name, ifindex_t ifindex, return ifp; } +void if_new_via_zapi(struct interface *ifp) +{ + if (ifp_master.create_hook) + (*ifp_master.create_hook)(ifp); +} + struct interface *if_create(const char *name, vrf_id_t vrf_id) { return if_create_backend(name, IFINDEX_INTERNAL, vrf_id); @@ -563,6 +563,8 @@ extern void if_zapi_callbacks(int (*create)(struct interface *ifp), int (*down)(struct interface *ifp), int (*destroy)(struct interface *ifp)); +extern void if_new_via_zapi(struct interface *ifp); + extern const struct frr_yang_module_info frr_interface_info; #ifdef __cplusplus diff --git a/lib/zclient.c b/lib/zclient.c index 92a495ac6..ea151be53 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -1547,10 +1547,11 @@ static void zclient_vrf_delete(struct zclient *zclient, vrf_id_t vrf_id) vrf_delete(vrf); } -struct interface *zebra_interface_add_read(struct stream *s, vrf_id_t vrf_id) +static void zclient_interface_add(struct zclient *zclient, vrf_id_t vrf_id) { struct interface *ifp; char ifname_tmp[INTERFACE_NAMSIZ]; + struct stream *s = zclient->ibuf; /* Read interface name. */ stream_get(ifname_tmp, s, INTERFACE_NAMSIZ); @@ -1560,15 +1561,14 @@ struct interface *zebra_interface_add_read(struct stream *s, vrf_id_t vrf_id) zebra_interface_if_set_value(s, ifp); - return ifp; + if_new_via_zapi(ifp); } /* * Read interface up/down msg (ZEBRA_INTERFACE_UP/ZEBRA_INTERFACE_DOWN) * from zebra server. The format of this message is the same as - * that sent for ZEBRA_INTERFACE_ADD/ZEBRA_INTERFACE_DELETE (see - * comments for zebra_interface_add_read), except that no sockaddr_dl - * is sent at the tail of the message. + * that sent for ZEBRA_INTERFACE_ADD/ZEBRA_INTERFACE_DELETE, + * except that no sockaddr_dl is sent at the tail of the message. */ struct interface *zebra_interface_state_read(struct stream *s, vrf_id_t vrf_id) { @@ -2789,9 +2789,7 @@ static int zclient_read(struct thread *thread) zclient_vrf_delete(zclient, vrf_id); break; case ZEBRA_INTERFACE_ADD: - if (zclient->interface_add) - (*zclient->interface_add)(command, zclient, length, - vrf_id); + zclient_interface_add(zclient, vrf_id); break; case ZEBRA_INTERFACE_DELETE: if (zclient->interface_delete) diff --git a/lib/zclient.h b/lib/zclient.h index eb3c97b11..9361b56c3 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -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_add)(ZAPI_CALLBACK_ARGS); int (*interface_delete)(ZAPI_CALLBACK_ARGS); int (*interface_up)(ZAPI_CALLBACK_ARGS); int (*interface_down)(ZAPI_CALLBACK_ARGS); @@ -617,7 +616,6 @@ extern bool zapi_parse_header(struct stream *zmsg, struct zmsghdr *hdr); extern void zclient_interface_set_master(struct zclient *client, struct interface *master, struct interface *slave); -extern struct interface *zebra_interface_add_read(struct stream *, vrf_id_t); extern struct interface *zebra_interface_state_read(struct stream *s, vrf_id_t); extern struct connected *zebra_interface_address_read(int, struct stream *, vrf_id_t); diff --git a/nhrpd/nhrp_interface.c b/nhrpd/nhrp_interface.c index 31e19eda3..5d47d0ae8 100644 --- a/nhrpd/nhrp_interface.c +++ b/nhrpd/nhrp_interface.c @@ -296,15 +296,8 @@ void nhrp_interface_update(struct interface *ifp) } } -int nhrp_interface_add(ZAPI_CALLBACK_ARGS) +int nhrp_ifp_create(struct interface *ifp) { - struct interface *ifp; - - /* read and add the interface in the iflist. */ - ifp = zebra_interface_add_read(zclient->ibuf, vrf_id); - if (ifp == NULL) - return 0; - debugf(NHRP_DEBUG_IF, "if-add: %s, ifindex: %u, hw_type: %d %s", ifp->name, ifp->ifindex, ifp->ll_type, if_link_type_str(ifp->ll_type)); @@ -437,11 +430,6 @@ 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; diff --git a/nhrpd/nhrp_route.c b/nhrpd/nhrp_route.c index a788eb2ef..3d0bd7804 100644 --- a/nhrpd/nhrp_route.c +++ b/nhrpd/nhrp_route.c @@ -345,7 +345,6 @@ void nhrp_zebra_init(void) zclient = zclient_new(master, &zclient_options_default); zclient->zebra_connected = nhrp_zebra_connected; - zclient->interface_add = nhrp_interface_add; zclient->interface_delete = nhrp_interface_delete; zclient->interface_up = nhrp_interface_up; zclient->interface_down = nhrp_interface_down; diff --git a/ospf6d/ospf6_interface.c b/ospf6d/ospf6_interface.c index 50e9f80cc..ca0e94518 100644 --- a/ospf6d/ospf6_interface.c +++ b/ospf6d/ospf6_interface.c @@ -42,6 +42,7 @@ #include "ospf6_spf.h" #include "ospf6d.h" #include "ospf6_bfd.h" +#include "ospf6_zebra.h" DEFINE_MTYPE_STATIC(OSPF6D, CFG_PLIST_NAME, "configured prefix list names") DEFINE_QOBJ_TYPE(ospf6_interface) @@ -1937,6 +1938,11 @@ static struct cmd_node interface_node = { static int ospf6_ifp_create(struct interface *ifp) { + if (IS_OSPF6_DEBUG_ZEBRA(RECV)) + zlog_debug("Zebra Interface add: %s index %d mtu %d", ifp->name, + ifp->ifindex, ifp->mtu6); + ospf6_interface_if_add(ifp); + return 0; } diff --git a/ospf6d/ospf6_zebra.c b/ospf6d/ospf6_zebra.c index 8454016b2..d809cff6c 100644 --- a/ospf6d/ospf6_zebra.c +++ b/ospf6d/ospf6_zebra.c @@ -97,19 +97,6 @@ void ospf6_zebra_no_redistribute(int type) AFI_IP6, type, 0, VRF_DEFAULT); } -/* Inteface addition message from zebra. */ -static int ospf6_zebra_if_add(ZAPI_CALLBACK_ARGS) -{ - struct interface *ifp; - - ifp = zebra_interface_add_read(zclient->ibuf, vrf_id); - if (IS_OSPF6_DEBUG_ZEBRA(RECV)) - zlog_debug("Zebra Interface add: %s index %d mtu %d", ifp->name, - ifp->ifindex, ifp->mtu6); - ospf6_interface_if_add(ifp); - return 0; -} - static int ospf6_zebra_if_del(ZAPI_CALLBACK_ARGS) { struct interface *ifp; @@ -583,7 +570,6 @@ void ospf6_zebra_init(struct thread_master *master) zclient_init(zclient, ZEBRA_ROUTE_OSPF6, 0, &ospf6d_privs); zclient->zebra_connected = ospf6_zebra_connected; zclient->router_id_update = ospf6_router_id_update_zebra; - zclient->interface_add = ospf6_zebra_if_add; zclient->interface_delete = ospf6_zebra_if_del; zclient->interface_up = ospf6_zebra_if_state_update; zclient->interface_down = ospf6_zebra_if_state_update; diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c index 3324740d5..c132a3447 100644 --- a/ospfd/ospf_interface.c +++ b/ospfd/ospf_interface.c @@ -50,6 +50,7 @@ DEFINE_QOBJ_TYPE(ospf_interface) DEFINE_HOOK(ospf_vl_add, (struct ospf_vl_data * vd), (vd)) DEFINE_HOOK(ospf_vl_delete, (struct ospf_vl_data * vd), (vd)) +DEFINE_HOOK(ospf_if_update, (struct interface * ifp), (ifp)) int ospf_interface_neighbor_count(struct ospf_interface *oi) { @@ -1218,8 +1219,41 @@ uint8_t ospf_default_iftype(struct interface *ifp) return OSPF_IFTYPE_BROADCAST; } +void ospf_if_interface(struct interface *ifp) +{ + hook_call(ospf_if_update, ifp); +} + static int ospf_ifp_create(struct interface *ifp) { + struct ospf *ospf = NULL; + + if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE)) + zlog_debug( + "Zebra: interface add %s vrf %s[%u] index %d flags %llx metric %d mtu %d speed %u", + ifp->name, ospf_vrf_id_to_name(ifp->vrf_id), + ifp->vrf_id, ifp->ifindex, + (unsigned long long)ifp->flags, ifp->metric, ifp->mtu, + ifp->speed); + + assert(ifp->info); + + if (IF_DEF_PARAMS(ifp) + && !OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), type)) { + SET_IF_PARAM(IF_DEF_PARAMS(ifp), type); + IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp); + } + + ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); + if (!ospf) + return 0; + + ospf_if_recalculate_output_cost(ifp); + + ospf_if_update(ospf, ifp); + + hook_call(ospf_if_update, ifp); + return 0; } diff --git a/ospfd/ospf_interface.h b/ospfd/ospf_interface.h index 0c903954d..f8350c48d 100644 --- a/ospfd/ospf_interface.h +++ b/ospfd/ospf_interface.h @@ -321,7 +321,10 @@ extern int ospf_interface_neighbor_count(struct ospf_interface *oi); state of the interface. */ extern void ospf_if_set_multicast(struct ospf_interface *); +extern void ospf_if_interface(struct interface *ifp); + DECLARE_HOOK(ospf_vl_add, (struct ospf_vl_data * vd), (vd)) DECLARE_HOOK(ospf_vl_delete, (struct ospf_vl_data * vd), (vd)) +DECLARE_HOOK(ospf_if_update, (struct interface * ifp), (ifp)) #endif /* _ZEBRA_OSPF_INTERFACE_H */ diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c index b478832d8..62c7cdd44 100644 --- a/ospfd/ospf_zebra.c +++ b/ospfd/ospf_zebra.c @@ -55,7 +55,6 @@ DEFINE_MTYPE_STATIC(OSPFD, OSPF_EXTERNAL, "OSPF External route table") DEFINE_MTYPE_STATIC(OSPFD, OSPF_REDISTRIBUTE, "OSPF Redistriute") DEFINE_MTYPE_STATIC(OSPFD, OSPF_DIST_ARGS, "OSPF Distribute arguments") -DEFINE_HOOK(ospf_if_update, (struct interface * ifp), (ifp)) DEFINE_HOOK(ospf_if_delete, (struct interface * ifp), (ifp)) /* Zebra structure to hold current status. */ @@ -97,45 +96,6 @@ static int ospf_router_id_update_zebra(ZAPI_CALLBACK_ARGS) return 0; } -/* Inteface addition message from zebra. */ -static int ospf_interface_add(ZAPI_CALLBACK_ARGS) -{ - struct interface *ifp = NULL; - struct ospf *ospf = NULL; - - ifp = zebra_interface_add_read(zclient->ibuf, vrf_id); - if (ifp == NULL) - return 0; - - if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE)) - zlog_debug( - "Zebra: interface add %s vrf %s[%u] index %d flags %llx metric %d mtu %d speed %u", - ifp->name, ospf_vrf_id_to_name(ifp->vrf_id), - ifp->vrf_id, ifp->ifindex, - (unsigned long long)ifp->flags, ifp->metric, ifp->mtu, - ifp->speed); - - assert(ifp->info); - - if (IF_DEF_PARAMS(ifp) - && !OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), type)) { - SET_IF_PARAM(IF_DEF_PARAMS(ifp), type); - IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp); - } - - ospf = ospf_lookup_by_vrf_id(vrf_id); - if (!ospf) - return 0; - - ospf_if_recalculate_output_cost(ifp); - - ospf_if_update(ospf, ifp); - - hook_call(ospf_if_update, ifp); - - return 0; -} - static int ospf_interface_delete(ZAPI_CALLBACK_ARGS) { struct interface *ifp; @@ -283,7 +243,7 @@ static int ospf_interface_address_add(ZAPI_CALLBACK_ARGS) ospf_if_update(ospf, c->ifp); - hook_call(ospf_if_update, c->ifp); + ospf_if_interface(c->ifp); return 0; } @@ -325,7 +285,7 @@ static int ospf_interface_address_delete(ZAPI_CALLBACK_ARGS) /* Call interface hook functions to clean up */ ospf_if_free(oi); - hook_call(ospf_if_update, c->ifp); + ospf_if_interface(c->ifp); connected_free(c); @@ -1524,7 +1484,6 @@ void ospf_zebra_init(struct thread_master *master, unsigned short instance) zclient_init(zclient, ZEBRA_ROUTE_OSPF, instance, &ospfd_privs); zclient->zebra_connected = ospf_zebra_connected; zclient->router_id_update = ospf_router_id_update_zebra; - zclient->interface_add = ospf_interface_add; zclient->interface_delete = ospf_interface_delete; zclient->interface_up = ospf_interface_state_up; zclient->interface_down = ospf_interface_state_down; diff --git a/ospfd/ospf_zebra.h b/ospfd/ospf_zebra.h index 673730653..3622d91e0 100644 --- a/ospfd/ospf_zebra.h +++ b/ospfd/ospf_zebra.h @@ -87,7 +87,6 @@ extern void ospf_zebra_init(struct thread_master *, unsigned short); extern void ospf_zebra_vrf_register(struct ospf *ospf); extern void ospf_zebra_vrf_deregister(struct ospf *ospf); -DECLARE_HOOK(ospf_if_update, (struct interface * ifp), (ifp)) DECLARE_HOOK(ospf_if_delete, (struct interface * ifp), (ifp)) #endif /* _ZEBRA_OSPF_ZEBRA_H */ diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index f4de25587..b12fa6372 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -1339,6 +1339,7 @@ void ospf_if_update(struct ospf *ospf, struct interface *ifp) /* Update connected redistribute. */ update_redistributed(ospf, 1); + } void ospf_remove_vls_through_area(struct ospf *ospf, struct ospf_area *area) diff --git a/pbrd/pbr_zebra.c b/pbrd/pbr_zebra.c index b8df7fc5a..af4b1e832 100644 --- a/pbrd/pbr_zebra.c +++ b/pbrd/pbr_zebra.c @@ -59,15 +59,8 @@ struct pbr_interface *pbr_if_new(struct interface *ifp) } /* Inteface addition message from zebra. */ -static int interface_add(ZAPI_CALLBACK_ARGS) +int pbr_ifp_create(struct interface *ifp) { - struct interface *ifp; - - ifp = zebra_interface_add_read(zclient->ibuf, vrf_id); - - if (!ifp) - return 0; - DEBUGD(&pbr_dbg_zebra, "%s: %s", __PRETTY_FUNCTION__, ifp->name); @@ -447,7 +440,6 @@ void pbr_zebra_init(void) zclient_init(zclient, ZEBRA_ROUTE_PBR, 0, &pbr_privs); zclient->zebra_connected = zebra_connected; - zclient->interface_add = interface_add; zclient->interface_delete = interface_delete; zclient->interface_up = interface_state_up; zclient->interface_down = interface_state_down; @@ -580,11 +572,6 @@ 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; diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index d20713b9c..94b92a7b0 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -1529,6 +1529,53 @@ int pim_if_ifchannel_count(struct pim_interface *pim_ifp) int pim_ifp_create(struct interface *ifp) { + struct pim_instance *pim; + + pim = pim_get_pim_instance(ifp->vrf_id); + if (PIM_DEBUG_ZEBRA) { + zlog_debug( + "%s: %s index %d(%u) flags %ld metric %d mtu %d operative %d", + __PRETTY_FUNCTION__, ifp->name, ifp->ifindex, + ifp->vrf_id, (long)ifp->flags, ifp->metric, ifp->mtu, + if_is_operative(ifp)); + } + + if (if_is_operative(ifp)) { + struct pim_interface *pim_ifp; + + pim_ifp = ifp->info; + /* + * If we have a pim_ifp already and this is an if_add + * that means that we probably have a vrf move event + * If that is the case, set the proper vrfness. + */ + if (pim_ifp) + pim_ifp->pim = pim; + pim_if_addr_add_all(ifp); + } + + /* + * If we are a vrf device that is up, open up the pim_socket for + * listening + * to incoming pim messages irrelevant if the user has configured us + * for pim or not. + */ + if (pim_if_is_vrf_device(ifp)) { + struct pim_interface *pim_ifp; + + if (!ifp->info) { + pim_ifp = pim_if_new(ifp, false, false, false, + false /*vxlan_term*/); + ifp->info = pim_ifp; + } + + pim_sock_add(ifp); + } + + if (!strncmp(ifp->name, PIM_VXLAN_TERM_DEV_NAME, + sizeof(PIM_VXLAN_TERM_DEV_NAME))) + pim_vxlan_add_term_dev(pim, ifp); + return 0; } diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c index b0db23f54..a2b356759 100644 --- a/pimd/pim_zebra.c +++ b/pimd/pim_zebra.c @@ -63,82 +63,11 @@ static int pim_router_id_update_zebra(ZAPI_CALLBACK_ARGS) return 0; } -static int pim_zebra_if_add(ZAPI_CALLBACK_ARGS) -{ - struct interface *ifp; - struct pim_instance *pim; - - /* - zebra api adds/dels interfaces using the same call - interface_add_read below, see comments in lib/zclient.c - */ - ifp = zebra_interface_add_read(zclient->ibuf, vrf_id); - if (!ifp) - return 0; - - pim = pim_get_pim_instance(vrf_id); - if (PIM_DEBUG_ZEBRA) { - zlog_debug( - "%s: %s index %d(%u) flags %ld metric %d mtu %d operative %d", - __PRETTY_FUNCTION__, ifp->name, ifp->ifindex, vrf_id, - (long)ifp->flags, ifp->metric, ifp->mtu, - if_is_operative(ifp)); - } - - if (if_is_operative(ifp)) { - struct pim_interface *pim_ifp; - - pim_ifp = ifp->info; - /* - * If we have a pim_ifp already and this is an if_add - * that means that we probably have a vrf move event - * If that is the case, set the proper vrfness. - */ - if (pim_ifp) - pim_ifp->pim = pim; - pim_if_addr_add_all(ifp); - } - - /* - * If we are a vrf device that is up, open up the pim_socket for - * listening - * to incoming pim messages irrelevant if the user has configured us - * for pim or not. - */ - if (pim_if_is_vrf_device(ifp)) { - struct pim_interface *pim_ifp; - - if (!ifp->info) { - pim_ifp = pim_if_new(ifp, false, false, false, - false /*vxlan_term*/); - ifp->info = pim_ifp; - } - - pim_sock_add(ifp); - } - - if (!strncmp(ifp->name, PIM_VXLAN_TERM_DEV_NAME, - sizeof(PIM_VXLAN_TERM_DEV_NAME))) - pim_vxlan_add_term_dev(pim, ifp); - - return 0; -} - static int pim_zebra_if_del(ZAPI_CALLBACK_ARGS) { struct interface *ifp; struct pim_instance *pim; - /* - zebra api adds/dels interfaces using the same call - interface_add_read below, see comments in lib/zclient.c - - comments in lib/zclient.c seem to indicate that calling - zebra_interface_add_read is the correct call, but that - results in an attemted out of bounds read which causes - pimd to assert. Other clients use zebra_interface_state_read - and it appears to work just fine. - */ ifp = zebra_interface_state_read(zclient->ibuf, vrf_id); if (!ifp) return 0; @@ -793,7 +722,6 @@ void pim_zebra_init(void) zclient->zebra_capabilities = pim_zebra_capabilities; zclient->zebra_connected = pim_zebra_connected; zclient->router_id_update = pim_router_id_update_zebra; - zclient->interface_add = pim_zebra_if_add; zclient->interface_delete = pim_zebra_if_del; zclient->interface_up = pim_zebra_if_state_up; zclient->interface_down = pim_zebra_if_state_down; diff --git a/ripd/rip_interface.c b/ripd/rip_interface.c index f20058a17..11657536b 100644 --- a/ripd/rip_interface.c +++ b/ripd/rip_interface.c @@ -405,11 +405,8 @@ int rip_interface_up(ZAPI_CALLBACK_ARGS) } /* Inteface addition message from zebra. */ -int rip_interface_add(ZAPI_CALLBACK_ARGS) +static int rip_ifp_create(struct interface *ifp) { - struct interface *ifp; - - ifp = zebra_interface_add_read(zclient->ibuf, vrf_id); rip_interface_sync(ifp); if (IS_RIP_DEBUG_ZEBRA) @@ -1253,11 +1250,6 @@ 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; diff --git a/ripd/rip_zebra.c b/ripd/rip_zebra.c index 0c88cb202..92d37bdca 100644 --- a/ripd/rip_zebra.c +++ b/ripd/rip_zebra.c @@ -238,7 +238,6 @@ void rip_zclient_init(struct thread_master *master) zclient = zclient_new(master, &zclient_options_default); zclient_init(zclient, ZEBRA_ROUTE_RIP, 0, &ripd_privs); zclient->zebra_connected = rip_zebra_connected; - zclient->interface_add = rip_interface_add; zclient->interface_delete = rip_interface_delete; zclient->interface_address_add = rip_interface_address_add; zclient->interface_address_delete = rip_interface_address_delete; diff --git a/ripngd/ripng_interface.c b/ripngd/ripng_interface.c index 02c35e04c..7b0ebd42c 100644 --- a/ripngd/ripng_interface.c +++ b/ripngd/ripng_interface.c @@ -256,11 +256,8 @@ int ripng_interface_down(ZAPI_CALLBACK_ARGS) } /* Inteface addition message from zebra. */ -int ripng_interface_add(ZAPI_CALLBACK_ARGS) +static int ripng_ifp_create(struct interface *ifp) { - struct interface *ifp; - - ifp = zebra_interface_add_read(zclient->ibuf, vrf_id); ripng_interface_sync(ifp); if (IS_RIPNG_DEBUG_ZEBRA) @@ -989,11 +986,6 @@ 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; diff --git a/ripngd/ripng_zebra.c b/ripngd/ripng_zebra.c index a557a90c8..a0e096bc6 100644 --- a/ripngd/ripng_zebra.c +++ b/ripngd/ripng_zebra.c @@ -244,7 +244,6 @@ void zebra_init(struct thread_master *master) zclient->zebra_connected = ripng_zebra_connected; zclient->interface_up = ripng_interface_up; zclient->interface_down = ripng_interface_down; - zclient->interface_add = ripng_interface_add; zclient->interface_delete = ripng_interface_delete; zclient->interface_address_add = ripng_interface_address_add; zclient->interface_address_delete = ripng_interface_address_delete; diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c index 6e3478555..343ac67d0 100644 --- a/sharpd/sharp_zebra.c +++ b/sharpd/sharp_zebra.c @@ -58,15 +58,8 @@ static struct interface *zebra_interface_if_lookup(struct stream *s) } /* Inteface addition message from zebra. */ -static int interface_add(ZAPI_CALLBACK_ARGS) +static int sharp_ifp_create(struct interface *ifp) { - struct interface *ifp; - - ifp = zebra_interface_add_read(zclient->ibuf, vrf_id); - - if (!ifp->info) - return 0; - return 0; } @@ -392,11 +385,6 @@ static int sharp_nexthop_update(ZAPI_CALLBACK_ARGS) return 0; } -static int sharp_ifp_create(struct interface *ifp) -{ - return 0; -} - static int sharp_ifp_up(struct interface *ifp) { return 0; @@ -425,7 +413,6 @@ void sharp_zebra_init(void) zclient_init(zclient, ZEBRA_ROUTE_SHARP, 0, &sharp_privs); zclient->zebra_connected = zebra_connected; - zclient->interface_add = interface_add; zclient->interface_delete = interface_delete; zclient->interface_up = interface_state_up; zclient->interface_down = interface_state_down; diff --git a/staticd/static_zebra.c b/staticd/static_zebra.c index c18cbed6b..2a6bfbd60 100644 --- a/staticd/static_zebra.c +++ b/staticd/static_zebra.c @@ -61,16 +61,10 @@ static struct interface *zebra_interface_if_lookup(struct stream *s) } /* Inteface addition message from zebra. */ -static int interface_add(ZAPI_CALLBACK_ARGS) +static int static_ifp_create(struct interface *ifp) { - struct interface *ifp; - - ifp = zebra_interface_add_read(zclient->ibuf, vrf_id); - - if (!ifp) - return 0; - static_ifindex_update(ifp, true); + return 0; } @@ -505,11 +499,6 @@ extern void static_zebra_route_add(struct route_node *rn, zclient, &api); } -static int static_ifp_create(struct interface *ifp) -{ - return 0; -} - static int static_ifp_up(struct interface *ifp) { return 0; @@ -537,7 +526,6 @@ void static_zebra_init(void) zclient_init(zclient, ZEBRA_ROUTE_STATIC, 0, &static_privs); zclient->zebra_capabilities = static_zebra_capabilities; zclient->zebra_connected = zebra_connected; - zclient->interface_add = interface_add; zclient->interface_delete = interface_delete; zclient->interface_up = interface_state_up; zclient->interface_down = interface_state_down; diff --git a/vrrpd/vrrp_zebra.c b/vrrpd/vrrp_zebra.c index 0844b9026..b4fcc3c36 100644 --- a/vrrpd/vrrp_zebra.c +++ b/vrrpd/vrrp_zebra.c @@ -80,21 +80,9 @@ static int vrrp_router_id_update_zebra(int command, struct zclient *zclient, return 0; } -static int vrrp_zebra_if_add(int command, struct zclient *zclient, - zebra_size_t length, vrf_id_t vrf_id) +int vrrp_ifp_create(struct interface *ifp) { - struct interface *ifp; - - /* - * zebra api adds/dels interfaces using the same call - * interface_add_read below, see comments in lib/zclient.c - */ - ifp = zebra_interface_add_read(zclient->ibuf, vrf_id); - - if (!ifp) - return 0; - - vrrp_zebra_debug_if_state(ifp, vrf_id, __func__); + vrrp_zebra_debug_if_state(ifp, ifp->vrf_id, __func__); vrrp_if_add(ifp); @@ -236,11 +224,6 @@ int vrrp_zclient_send_interface_protodown(struct interface *ifp, bool down) down); } -int vrrp_ifp_create(struct interface *ifp) -{ - return 0; -} - int vrrp_ifp_up(struct interface *ifp) { return 0; @@ -266,7 +249,6 @@ void vrrp_zebra_init(void) zclient->zebra_connected = vrrp_zebra_connected; zclient->router_id_update = vrrp_router_id_update_zebra; - zclient->interface_add = vrrp_zebra_if_add; zclient->interface_delete = vrrp_zebra_if_del; zclient->interface_up = vrrp_zebra_if_state_up; zclient->interface_down = vrrp_zebra_if_state_down; |