-/*
- * ip4_fib_table_lookup_exact_match
- *
- * Exact match prefix lookup
- */
-fib_node_index_t
-ip4_fib_table_lookup_exact_match (const ip4_fib_t *fib,
- const ip4_address_t *addr,
- u32 len)
-{
- uword * hash, * result;
- u32 key;
-
- hash = fib->fib_entry_by_dst_address[len];
- key = (addr->data_u32 & ip4_main.fib_masks[len]);
-
- result = hash_get(hash, key);
-
- if (NULL != result) {
- return (result[0]);
- }
- return (FIB_NODE_INDEX_INVALID);
-}
-
-/*
- * ip4_fib_table_lookup_adj
- *
- * Longest prefix match
- */
-index_t
-ip4_fib_table_lookup_lb (ip4_fib_t *fib,
- const ip4_address_t *addr)
-{
- fib_node_index_t fei;
-
- fei = ip4_fib_table_lookup(fib, addr, 32);
-
- if (FIB_NODE_INDEX_INVALID != fei)
- {
- const dpo_id_t *dpo;
-
- dpo = fib_entry_contribute_ip_forwarding(fei);
-
- return (dpo->dpoi_index);
- }
- return (INDEX_INVALID);
-}
-
-/*
- * ip4_fib_table_lookup
- *
- * Longest prefix match
- */
-fib_node_index_t
-ip4_fib_table_lookup (const ip4_fib_t *fib,
- const ip4_address_t *addr,
- u32 len)
-{
- uword * hash, * result;
- i32 mask_len;
- u32 key;
-
- for (mask_len = len; mask_len >= 0; mask_len--)
- {
- hash = fib->fib_entry_by_dst_address[mask_len];
- key = (addr->data_u32 & ip4_main.fib_masks[mask_len]);
-
- result = hash_get (hash, key);
-
- if (NULL != result) {
- return (result[0]);
- }
- }
- return (FIB_NODE_INDEX_INVALID);
-}
-
-void
-ip4_fib_table_entry_insert (ip4_fib_t *fib,
- const ip4_address_t *addr,
- u32 len,
- fib_node_index_t fib_entry_index)
-{
- uword * hash, * result;
- u32 key;
-
- key = (addr->data_u32 & ip4_main.fib_masks[len]);
- hash = fib->fib_entry_by_dst_address[len];
- result = hash_get (hash, key);
-
- if (NULL == result) {
- /*
- * adding a new entry
- */
- uword *old_heap;
- old_heap = clib_mem_set_heap (ip4_main.mtrie_mheap);
-
- if (NULL == hash) {
- hash = hash_create (32 /* elts */, sizeof (uword));
- hash_set_flags (hash, HASH_FLAG_NO_AUTO_SHRINK);
-
- }
- hash = hash_set(hash, key, fib_entry_index);
- fib->fib_entry_by_dst_address[len] = hash;
- clib_mem_set_heap (old_heap);
- }
- else
- {
- ASSERT(0);
- }
-}
-
-void
-ip4_fib_table_entry_remove (ip4_fib_t *fib,
- const ip4_address_t *addr,
- u32 len)
-{
- uword * hash, * result;
- u32 key;
-
- key = (addr->data_u32 & ip4_main.fib_masks[len]);
- hash = fib->fib_entry_by_dst_address[len];
- result = hash_get (hash, key);
-
- if (NULL == result)
- {
- /*
- * removing a non-existant entry. i'll allow it.
- */
- }
- else
- {
- uword *old_heap;
-
- old_heap = clib_mem_set_heap (ip4_main.mtrie_mheap);
- hash_unset(hash, key);
- clib_mem_set_heap (old_heap);
- }
-
- fib->fib_entry_by_dst_address[len] = hash;
-}
-
-void
-ip4_fib_table_fwding_dpo_update (ip4_fib_t *fib,
- const ip4_address_t *addr,
- u32 len,
- const dpo_id_t *dpo)
-{
- ip4_fib_mtrie_route_add(&fib->mtrie, addr, len, dpo->dpoi_index);
-}
-
-void
-ip4_fib_table_fwding_dpo_remove (ip4_fib_t *fib,
- const ip4_address_t *addr,
- u32 len,
- const dpo_id_t *dpo,
- u32 cover_index)
-{
- fib_prefix_t cover_prefix = {
- .fp_len = 0,
- };
- const dpo_id_t *cover_dpo;
-
- /*
- * We need to pass the MTRIE the LB index and address length of the
- * covering prefix, so it can fill the plys with the correct replacement
- * for the entry being removed
- */
- fib_entry_get_prefix(cover_index, &cover_prefix);
- cover_dpo = fib_entry_contribute_ip_forwarding(cover_index);
-
- ip4_fib_mtrie_route_del(&fib->mtrie,
- addr, len, dpo->dpoi_index,
- cover_prefix.fp_len,
- cover_dpo->dpoi_index);
-}
-
-void
-ip4_fib_table_walk (ip4_fib_t *fib,
- fib_table_walk_fn_t fn,
- void *ctx)
-{
- int i;
-
- for (i = 0; i < ARRAY_LEN (fib->fib_entry_by_dst_address); i++)
- {
- uword * hash = fib->fib_entry_by_dst_address[i];
-
- if (NULL != hash)
- {
- hash_pair_t * p;
-
- hash_foreach_pair (p, hash,
- ({
- fn(p->value[0], ctx);
- }));
- }
- }
-}