mirror of
https://git.proxmox.com/git/mirror_frr
synced 2026-01-24 16:26:43 +00:00
lib: replace if_add_hook with hook_* logic
This allows modules to register their own additional hooks on interface creation/deletion. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
This commit is contained in:
parent
2a6a7a656d
commit
ce19a04aea
@ -1256,8 +1256,8 @@ void
|
||||
babel_if_init ()
|
||||
{
|
||||
/* initialize interface list */
|
||||
if_add_hook (IF_NEW_HOOK, babel_if_new_hook);
|
||||
if_add_hook (IF_DELETE_HOOK, babel_if_delete_hook);
|
||||
hook_register_prio(if_add, 0, babel_if_new_hook);
|
||||
hook_register_prio(if_del, 0, babel_if_delete_hook);
|
||||
|
||||
babel_enable_if = vector_init (1);
|
||||
|
||||
|
||||
@ -178,9 +178,6 @@ static __attribute__((__noreturn__)) void bgp_exit(int status)
|
||||
|
||||
bgp_close();
|
||||
|
||||
if (retain_mode)
|
||||
if_add_hook(IF_DELETE_HOOK, NULL);
|
||||
|
||||
/* reverse bgp_master_init */
|
||||
for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
|
||||
bgp_delete(bgp);
|
||||
|
||||
@ -150,8 +150,8 @@ struct list *eigrp_iflist;
|
||||
void eigrp_if_init()
|
||||
{
|
||||
/* Initialize Zebra interface data structure. */
|
||||
if_add_hook(IF_NEW_HOOK, eigrp_if_new_hook);
|
||||
if_add_hook(IF_DELETE_HOOK, eigrp_if_delete_hook);
|
||||
hook_register_prio(if_add, 0, eigrp_if_new_hook);
|
||||
hook_register_prio(if_del, 0, eigrp_if_delete_hook);
|
||||
}
|
||||
|
||||
int eigrp_if_new_hook(struct interface *ifp)
|
||||
|
||||
@ -1336,8 +1336,8 @@ int isis_if_delete_hook(struct interface *ifp)
|
||||
void isis_circuit_init()
|
||||
{
|
||||
/* Initialize Zebra interface data structure */
|
||||
if_add_hook(IF_NEW_HOOK, isis_if_new_hook);
|
||||
if_add_hook(IF_DELETE_HOOK, isis_if_delete_hook);
|
||||
hook_register_prio(if_add, 0, isis_if_new_hook);
|
||||
hook_register_prio(if_del, 0, isis_if_delete_hook);
|
||||
|
||||
/* Install interface node */
|
||||
install_node(&interface_node, isis_interface_config_write);
|
||||
|
||||
35
lib/if.c
35
lib/if.c
@ -42,17 +42,12 @@ DEFINE_MTYPE_STATIC(LIB, IF_LINK_PARAMS, "Informational Link Parameters")
|
||||
|
||||
DEFINE_QOBJ_TYPE(interface)
|
||||
|
||||
DEFINE_HOOK(if_add, (struct interface *ifp), (ifp))
|
||||
DEFINE_KOOH(if_del, (struct interface *ifp), (ifp))
|
||||
|
||||
/* List of interfaces in only the default VRF */
|
||||
int ptm_enable = 0;
|
||||
|
||||
/* One for each program. This structure is needed to store hooks. */
|
||||
struct if_master {
|
||||
int (*if_new_hook)(struct interface *);
|
||||
int (*if_delete_hook)(struct interface *);
|
||||
} if_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
|
||||
@ -150,10 +145,7 @@ struct interface *if_create(const char *name, int namelen, vrf_id_t vrf_id)
|
||||
SET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION);
|
||||
|
||||
QOBJ_REG(ifp, interface);
|
||||
|
||||
if (if_master.if_new_hook)
|
||||
(*if_master.if_new_hook)(ifp);
|
||||
|
||||
hook_call(if_add, ifp);
|
||||
return ifp;
|
||||
}
|
||||
|
||||
@ -182,9 +174,7 @@ void if_update_to_new_vrf(struct interface *ifp, vrf_id_t vrf_id)
|
||||
/* Delete interface structure. */
|
||||
void if_delete_retain(struct interface *ifp)
|
||||
{
|
||||
if (if_master.if_delete_hook)
|
||||
(*if_master.if_delete_hook)(ifp);
|
||||
|
||||
hook_call(if_del, ifp);
|
||||
QOBJ_UNREG(ifp);
|
||||
|
||||
/* Free connected address list */
|
||||
@ -209,21 +199,6 @@ void if_delete(struct interface *ifp)
|
||||
XFREE(MTYPE_IF, ifp);
|
||||
}
|
||||
|
||||
/* Add hook to interface master. */
|
||||
void if_add_hook(int type, int (*func)(struct interface *ifp))
|
||||
{
|
||||
switch (type) {
|
||||
case IF_NEW_HOOK:
|
||||
if_master.if_new_hook = func;
|
||||
break;
|
||||
case IF_DELETE_HOOK:
|
||||
if_master.if_delete_hook = func;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Interface existance check by index. */
|
||||
struct interface *if_lookup_by_index(ifindex_t ifindex, vrf_id_t vrf_id)
|
||||
{
|
||||
|
||||
17
lib/if.h
17
lib/if.h
@ -25,6 +25,7 @@
|
||||
#include "linklist.h"
|
||||
#include "memory.h"
|
||||
#include "qobj.h"
|
||||
#include "hook.h"
|
||||
|
||||
DECLARE_MTYPE(IF)
|
||||
DECLARE_MTYPE(CONNECTED_LABEL)
|
||||
@ -283,6 +284,17 @@ struct interface {
|
||||
};
|
||||
DECLARE_QOBJ_TYPE(interface)
|
||||
|
||||
/* called from the library code whenever interfaces are created/deleted
|
||||
* note: interfaces may not be fully realized at that point; also they
|
||||
* may not exist in the system (ifindex = IFINDEX_INTERNAL)
|
||||
*
|
||||
* priority values are important here, daemons should be at 0 while modules
|
||||
* can use 1000+ so they run after the daemon has initialised daemon-specific
|
||||
* interface data
|
||||
*/
|
||||
DECLARE_HOOK(if_add, (struct interface *ifp), (ifp))
|
||||
DECLARE_KOOH(if_del, (struct interface *ifp), (ifp))
|
||||
|
||||
/* Connected address structure. */
|
||||
struct connected {
|
||||
/* Attached interface. */
|
||||
@ -355,10 +367,6 @@ struct nbr_connected {
|
||||
? (C)->destination \
|
||||
: (C)->address)
|
||||
|
||||
/* Interface hook sort. */
|
||||
#define IF_NEW_HOOK 0
|
||||
#define IF_DELETE_HOOK 1
|
||||
|
||||
/* There are some interface flags which are only supported by some
|
||||
operating system. */
|
||||
|
||||
@ -442,7 +450,6 @@ extern int if_is_loopback(struct interface *);
|
||||
extern int if_is_broadcast(struct interface *);
|
||||
extern int if_is_pointopoint(struct interface *);
|
||||
extern int if_is_multicast(struct interface *);
|
||||
extern void if_add_hook(int, int (*)(struct interface *));
|
||||
extern void if_init(struct list **);
|
||||
extern void if_cmd_init(void);
|
||||
extern void if_terminate(struct list **);
|
||||
|
||||
@ -48,8 +48,8 @@ static int nhrp_if_delete_hook(struct interface *ifp)
|
||||
|
||||
void nhrp_interface_init(void)
|
||||
{
|
||||
if_add_hook(IF_NEW_HOOK, nhrp_if_new_hook);
|
||||
if_add_hook(IF_DELETE_HOOK, nhrp_if_delete_hook);
|
||||
hook_register_prio(if_add, 0, nhrp_if_new_hook);
|
||||
hook_register_prio(if_del, 0, nhrp_if_delete_hook);
|
||||
}
|
||||
|
||||
void nhrp_interface_update_mtu(struct interface *ifp, afi_t afi)
|
||||
|
||||
@ -1163,6 +1163,6 @@ void ospf_if_init()
|
||||
{
|
||||
/* Initialize Zebra interface data structure. */
|
||||
om->iflist = vrf_iflist(VRF_DEFAULT);
|
||||
if_add_hook(IF_NEW_HOOK, ospf_if_new_hook);
|
||||
if_add_hook(IF_DELETE_HOOK, ospf_if_delete_hook);
|
||||
hook_register_prio(if_add, 0, ospf_if_new_hook);
|
||||
hook_register_prio(if_del, 0, ospf_if_delete_hook);
|
||||
}
|
||||
|
||||
@ -1877,8 +1877,8 @@ static int rip_interface_delete_hook(struct interface *ifp)
|
||||
void rip_if_init(void)
|
||||
{
|
||||
/* Default initial size of interface vector. */
|
||||
if_add_hook(IF_NEW_HOOK, rip_interface_new_hook);
|
||||
if_add_hook(IF_DELETE_HOOK, rip_interface_delete_hook);
|
||||
hook_register_prio(if_add, 0, rip_interface_new_hook);
|
||||
hook_register_prio(if_del, 0, rip_interface_delete_hook);
|
||||
|
||||
/* RIP network init. */
|
||||
rip_enable_interface = vector_init(1);
|
||||
|
||||
@ -1121,8 +1121,8 @@ static struct cmd_node interface_node = {
|
||||
void ripng_if_init()
|
||||
{
|
||||
/* Interface initialize. */
|
||||
if_add_hook(IF_NEW_HOOK, ripng_if_new_hook);
|
||||
if_add_hook(IF_DELETE_HOOK, ripng_if_delete_hook);
|
||||
hook_register_prio(if_add, 0, ripng_if_new_hook);
|
||||
hook_register_prio(if_del, 0, ripng_if_delete_hook);
|
||||
|
||||
/* RIPng enable network init. */
|
||||
ripng_enable_network = route_table_init();
|
||||
|
||||
@ -2930,8 +2930,8 @@ static int if_config_write(struct vty *vty)
|
||||
void zebra_if_init(void)
|
||||
{
|
||||
/* Initialize interface and new hook. */
|
||||
if_add_hook(IF_NEW_HOOK, if_zebra_new_hook);
|
||||
if_add_hook(IF_DELETE_HOOK, if_zebra_delete_hook);
|
||||
hook_register_prio(if_add, 0, if_zebra_new_hook);
|
||||
hook_register_prio(if_del, 0, if_zebra_delete_hook);
|
||||
|
||||
/* Install configuration write function. */
|
||||
install_node(&interface_node, if_config_write);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user