summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2017-08-08 10:50:43 +0200
committerDavid Lamparter <equinox@opensourcerouting.org>2017-08-15 13:25:44 +0200
commitce19a04aea80f45ca1da80e28bf3a1253138c691 (patch)
treec77a0afabe9f9ac0e469c65b41da391032ceb8e8
parentdoc: sample code-doc in .rst+sphinx (diff)
downloadfrr-ce19a04aea80f45ca1da80e28bf3a1253138c691.tar.xz
frr-ce19a04aea80f45ca1da80e28bf3a1253138c691.zip
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>
-rw-r--r--babeld/babel_interface.c4
-rw-r--r--bgpd/bgp_main.c3
-rw-r--r--eigrpd/eigrp_interface.c4
-rw-r--r--isisd/isis_circuit.c4
-rw-r--r--lib/if.c35
-rw-r--r--lib/if.h17
-rw-r--r--nhrpd/nhrp_interface.c4
-rw-r--r--ospfd/ospf_interface.c4
-rw-r--r--ripd/rip_interface.c4
-rw-r--r--ripngd/ripng_interface.c4
-rw-r--r--zebra/interface.c4
11 files changed, 33 insertions, 54 deletions
diff --git a/babeld/babel_interface.c b/babeld/babel_interface.c
index 1ae33b3a2..9fa32ee6f 100644
--- a/babeld/babel_interface.c
+++ b/babeld/babel_interface.c
@@ -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);
diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c
index a80dff271..d1359402d 100644
--- a/bgpd/bgp_main.c
+++ b/bgpd/bgp_main.c
@@ -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);
diff --git a/eigrpd/eigrp_interface.c b/eigrpd/eigrp_interface.c
index 7f05e1470..22b6fa394 100644
--- a/eigrpd/eigrp_interface.c
+++ b/eigrpd/eigrp_interface.c
@@ -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)
diff --git a/isisd/isis_circuit.c b/isisd/isis_circuit.c
index 9622dcdbc..a1aa87e39 100644
--- a/isisd/isis_circuit.c
+++ b/isisd/isis_circuit.c
@@ -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);
diff --git a/lib/if.c b/lib/if.c
index 4e4534851..43c382bea 100644
--- a/lib/if.c
+++ b/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)
{
diff --git a/lib/if.h b/lib/if.h
index f80ac1917..a592e0ff8 100644
--- a/lib/if.h
+++ b/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 **);
diff --git a/nhrpd/nhrp_interface.c b/nhrpd/nhrp_interface.c
index 58ad16754..a46962c91 100644
--- a/nhrpd/nhrp_interface.c
+++ b/nhrpd/nhrp_interface.c
@@ -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)
diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c
index 4ea8ec26f..54639afd6 100644
--- a/ospfd/ospf_interface.c
+++ b/ospfd/ospf_interface.c
@@ -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);
}
diff --git a/ripd/rip_interface.c b/ripd/rip_interface.c
index a17047112..00b6d1cad 100644
--- a/ripd/rip_interface.c
+++ b/ripd/rip_interface.c
@@ -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);
diff --git a/ripngd/ripng_interface.c b/ripngd/ripng_interface.c
index c762d8ace..02fab6825 100644
--- a/ripngd/ripng_interface.c
+++ b/ripngd/ripng_interface.c
@@ -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();
diff --git a/zebra/interface.c b/zebra/interface.c
index c4d036399..48158c82c 100644
--- a/zebra/interface.c
+++ b/zebra/interface.c
@@ -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);