#include <vnet/fib/fib_table.h>
#include <vnet/adj/adj_midchain.h>
+typedef struct nhrp_key_t_
+{
+ ip46_address_t nk_peer;
+ u32 nk_sw_if_index;
+} nhrp_key_t;
+
+struct nhrp_entry_t_
+{
+ nhrp_key_t *ne_key;
+ fib_prefix_t ne_nh;
+ u32 ne_fib_index;
+};
+
static uword *nhrp_db;
static nhrp_entry_t *nhrp_pool;
+static nhrp_vft_t *nhrp_vfts;
+
+#define NHRP_NOTIFY(_ne, _fn) { \
+ nhrp_vft_t *_vft; \
+ vec_foreach(_vft, nhrp_vfts) { \
+ if (_vft->_fn) { \
+ _vft->_fn(_ne); \
+ } \
+ } \
+}
-void
-nhrp_entry_adj_stack (const nhrp_entry_t * ne, adj_index_t ai)
+u32
+nhrp_entry_get_sw_if_index (const nhrp_entry_t * ne)
{
- adj_midchain_delegate_stack (ai, ne->ne_fib_index, &ne->ne_nh);
+ return (ne->ne_key->nk_sw_if_index);
}
-static adj_walk_rc_t
-nhrp_entry_add_adj_walk (adj_index_t ai, void *ctx)
+u32
+nhrp_entry_get_fib_index (const nhrp_entry_t * ne)
{
- nhrp_entry_adj_stack (ctx, ai);
+ return (ne->ne_fib_index);
+}
- return (ADJ_WALK_RC_CONTINUE);
+const ip46_address_t *
+nhrp_entry_get_peer (const nhrp_entry_t * ne)
+{
+ return (&ne->ne_key->nk_peer);
}
-static adj_walk_rc_t
-nhrp_entry_del_adj_walk (adj_index_t ai, void *ctx)
+const fib_prefix_t *
+nhrp_entry_get_nh (const nhrp_entry_t * ne)
{
- adj_midchain_delegate_unstack (ai);
+ return (&ne->ne_nh);
+}
- return (ADJ_WALK_RC_CONTINUE);
+void
+nhrp_entry_adj_stack (const nhrp_entry_t * ne, adj_index_t ai)
+{
+ adj_midchain_delegate_stack (ai, ne->ne_fib_index, &ne->ne_nh);
}
nhrp_entry_t *
hash_set_mem (nhrp_db, ne->ne_key, nei);
- adj_nbr_walk_nh (sw_if_index,
- ne->ne_nh.fp_proto,
- &ne->ne_key->nk_peer, nhrp_entry_add_adj_walk, ne);
+ NHRP_NOTIFY (ne, nv_added);
}
else
return (VNET_API_ERROR_ENTRY_ALREADY_EXISTS);
{
hash_unset_mem (nhrp_db, ne->ne_key);
- adj_nbr_walk_nh (sw_if_index,
- ne->ne_nh.fp_proto,
- &ne->ne_key->nk_peer, nhrp_entry_del_adj_walk, ne);
+ NHRP_NOTIFY (ne, nv_deleted);
clib_mem_free (ne->ne_key);
pool_put (nhrp_pool, ne);
/* *INDENT-ON* */
}
+void
+nhrp_walk_itf (u32 sw_if_index, nhrp_walk_cb_t fn, void *ctx)
+{
+ index_t nei;
+
+ /* *INDENT-OFF* */
+ pool_foreach_index(nei, nhrp_pool,
+ ({
+ if (sw_if_index == nhrp_entry_get_sw_if_index(nhrp_entry_get(nei)))
+ fn(nei, ctx);
+ }));
+ /* *INDENT-ON* */
+}
+
+void
+nhrp_register (const nhrp_vft_t * vft)
+{
+ vec_add1 (nhrp_vfts, *vft);
+}
+
static clib_error_t *
nhrp_init (vlib_main_t * vm)
{