X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fnhrp%2Fnhrp.c;h=11d2c2be027f78520d5542483e48fe6db3f7616e;hb=14053c9dbd75182f5302f7388d17508f3930f7ce;hp=a89f6cd94591ab860d00a06a3aa1406deb2f1225;hpb=e11dce20c99775884877ad6dcf879e8995c78ebf;p=vpp.git diff --git a/src/vnet/nhrp/nhrp.c b/src/vnet/nhrp/nhrp.c index a89f6cd9459..11d2c2be027 100644 --- a/src/vnet/nhrp/nhrp.c +++ b/src/vnet/nhrp/nhrp.c @@ -20,29 +20,60 @@ #include #include +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 * @@ -110,9 +141,7 @@ nhrp_entry_add (u32 sw_if_index, 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); @@ -131,9 +160,7 @@ nhrp_entry_del (u32 sw_if_index, const ip46_address_t * peer) { 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); @@ -178,6 +205,26 @@ nhrp_walk (nhrp_walk_cb_t fn, void *ctx) /* *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) {