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);
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);
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)
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);
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
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;
}
/* 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 */
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)
{
#include "linklist.h"
#include "memory.h"
#include "qobj.h"
+#include "hook.h"
DECLARE_MTYPE(IF)
DECLARE_MTYPE(CONNECTED_LABEL)
};
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. */
? (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. */
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 **);
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)
{
/* 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);
}
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);
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();
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);