summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/vnet/adj/adj.c4
-rw-r--r--src/vnet/adj/adj_bfd.c19
-rw-r--r--src/vnet/adj/adj_delegate.c66
-rw-r--r--src/vnet/adj/adj_delegate.h13
-rw-r--r--src/vnet/adj/adj_internal.h1
5 files changed, 74 insertions, 29 deletions
diff --git a/src/vnet/adj/adj.c b/src/vnet/adj/adj.c
index d28d5195330..e1d7821fd39 100644
--- a/src/vnet/adj/adj.c
+++ b/src/vnet/adj/adj.c
@@ -139,7 +139,7 @@ format_ip_adjacency (u8 * s, va_list * args)
s = format(s, "\n delegates:\n ");
FOR_EACH_ADJ_DELEGATE(adj, adt, aed,
{
- s = format(s, " %U\n", format_adj_deletegate, aed);
+ s = format(s, " %U\n", format_adj_delegate, aed);
});
s = format(s, "\n children:\n ");
@@ -162,6 +162,8 @@ adj_last_lock_gone (ip_adjacency_t *adj)
ASSERT(0 == fib_node_list_get_size(adj->ia_node.fn_children));
ADJ_DBG(adj, "last-lock-gone");
+ adj_delegate_vft_lock_gone(adj);
+
vlib_worker_thread_barrier_sync (vm);
switch (adj->lookup_next_index)
diff --git a/src/vnet/adj/adj_bfd.c b/src/vnet/adj/adj_bfd.c
index 3d294c4646e..2d845ffcfd8 100644
--- a/src/vnet/adj/adj_bfd.c
+++ b/src/vnet/adj/adj_bfd.c
@@ -168,6 +168,23 @@ adj_bfd_notify (bfd_listen_event_e event,
adj_unlock(ai);
}
+/**
+ * Print a delegate that represents BFD tracking
+ */
+static u8 *
+adj_delegate_fmt_bfd (const adj_delegate_t *aed, u8 *s)
+{
+ s = format(s, "BFD:[state:%d index:%d]",
+ aed->ad_bfd_state,
+ aed->ad_bfd_index);
+
+ return (s);
+}
+
+const static adj_delegate_vft_t adj_delegate_vft = {
+ .adv_format = adj_delegate_fmt_bfd,
+};
+
static clib_error_t *
adj_bfd_main_init (vlib_main_t * vm)
{
@@ -178,6 +195,8 @@ adj_bfd_main_init (vlib_main_t * vm)
bfd_register_listener(adj_bfd_notify);
+ adj_delegate_register_type (ADJ_DELEGATE_BFD, &adj_delegate_vft);
+
return (error);
}
diff --git a/src/vnet/adj/adj_delegate.c b/src/vnet/adj/adj_delegate.c
index 701b36e2fd9..c65cc8be64e 100644
--- a/src/vnet/adj/adj_delegate.c
+++ b/src/vnet/adj/adj_delegate.c
@@ -17,6 +17,11 @@
#include <vnet/adj/adj.h>
#include <vnet/adj/adj_internal.h>
+/*
+ * The per-type vector of virtual function tables
+ */
+static adj_delegate_vft_t *ad_vfts;
+
static adj_delegate_t *
adj_delegate_find_i (const ip_adjacency_t *adj,
adj_delegate_type_t type,
@@ -105,40 +110,47 @@ adj_delegate_find_or_add (ip_adjacency_t *adj,
return (adj_delegate_get(adj, adt));
}
-/**
- * typedef for printing a delegate
- */
-typedef u8 * (*adj_delegate_format_t)(const adj_delegate_t *aed,
- u8 *s);
-
-/**
- * Print a delegate that represents BFD tracking
- */
-static u8 *
-adj_delegate_fmt_bfd (const adj_delegate_t *aed,
- u8 *s)
+void adj_delegate_vft_lock_gone (ip_adjacency_t *adj)
{
- s = format(s, "BFD:[state:%d index:%d]",
- aed->ad_bfd_state,
- aed->ad_bfd_index);
-
- return (s);
+ adj_delegate_t *delegate;
+ vec_foreach(delegate, adj->ia_delegates) {
+ if (ad_vfts[delegate->ad_type].adv_last_lock)
+ ad_vfts[delegate->ad_type].adv_last_lock(adj, delegate);
+ }
}
-/**
- * A delegate type to formatter map
- */
-static adj_delegate_format_t aed_formatters[] =
-{
- [ADJ_DELEGATE_BFD] = adj_delegate_fmt_bfd,
-};
-
u8 *
-format_adj_deletegate (u8 * s, va_list * args)
+format_adj_delegate (u8 * s, va_list * args)
{
adj_delegate_t *aed;
aed = va_arg (*args, adj_delegate_t *);
+ if (ad_vfts[aed->ad_type].adv_format)
+ return ad_vfts[aed->ad_type].adv_format(aed, s);
+ return format(s, "unknown delegate");
+}
- return (aed_formatters[aed->ad_type](aed, s));
+/**
+ * adj_delegate_register_type
+ *
+ * Register the function table for a given type
+ */
+
+void
+adj_delegate_register_type (adj_delegate_type_t type,
+ const adj_delegate_vft_t *vft)
+{
+ /*
+ * assert that one only registration is made per-node type
+ */
+ if (vec_len(ad_vfts) > type)
+ ASSERT(NULL == ad_vfts[type].adv_last_lock);
+
+ /*
+ * Assert that we are getting each of the required functions
+ */
+ ASSERT(NULL != vft->adv_last_lock);
+
+ vec_validate(ad_vfts, type);
+ ad_vfts[type] = *vft;
}
diff --git a/src/vnet/adj/adj_delegate.h b/src/vnet/adj/adj_delegate.h
index 176512039d6..9f7d8c64afc 100644
--- a/src/vnet/adj/adj_delegate.h
+++ b/src/vnet/adj/adj_delegate.h
@@ -91,6 +91,16 @@ typedef struct adj_delegate_t_
};
} adj_delegate_t;
+/**
+ * An ADJ delegate virtual function table
+ */
+typedef void (*adj_delegate_last_lock_gone_t)(ip_adjacency_t *adj, adj_delegate_t *aed);
+typedef u8 * (*adj_delegate_format_t)(const adj_delegate_t *aed, u8 *s);
+typedef struct adj_delegate_vft_t_ {
+ adj_delegate_format_t adv_format;
+ adj_delegate_last_lock_gone_t adv_last_lock;
+} adj_delegate_vft_t;
+
extern void adj_delegate_remove(ip_adjacency_t *adj,
adj_delegate_type_t type);
@@ -99,6 +109,7 @@ extern adj_delegate_t *adj_delegate_find_or_add(ip_adjacency_t *adj,
extern adj_delegate_t *adj_delegate_get(const ip_adjacency_t *adj,
adj_delegate_type_t type);
-extern u8 *format_adj_deletegate(u8 * s, va_list * args);
+extern u8 *format_adj_delegate(u8 * s, va_list * args);
+extern void adj_delegate_register_type(adj_delegate_type_t type, const adj_delegate_vft_t *vft);
#endif
diff --git a/src/vnet/adj/adj_internal.h b/src/vnet/adj/adj_internal.h
index 3b7ddb2f10c..55afe55fa79 100644
--- a/src/vnet/adj/adj_internal.h
+++ b/src/vnet/adj/adj_internal.h
@@ -126,5 +126,6 @@ extern void adj_mcast_remove(fib_protocol_t proto,
u32 sw_if_index);
extern u32 adj_dpo_get_urpf(const dpo_id_t *dpo);
+extern void adj_delegate_vft_lock_gone(ip_adjacency_t *adj);
#endif