vppinfra: bihash walk cb typedef and continue/stop controls 23/23823/2
authorNeale Ranns <nranns@cisco.com>
Fri, 6 Dec 2019 05:53:17 +0000 (05:53 +0000)
committerDave Barach <openvpp@barachs.net>
Mon, 16 Dec 2019 23:29:21 +0000 (23:29 +0000)
Type: feature

Change-Id: I28f7a658be3f3beec9ea32635b60d1d3a10d9b06
Signed-off-by: Neale Ranns <nranns@cisco.com>
20 files changed:
src/plugins/gbp/gbp_endpoint.c
src/plugins/pppoe/pppoe.c
src/plugins/unittest/bihash_test.c
src/vnet/adj/adj_nbr.c
src/vnet/fib/ip6_fib.c
src/vnet/ip/ip6_ll_table.c
src/vnet/ip/reass/ip4_full_reass.c
src/vnet/ip/reass/ip4_sv_reass.c
src/vnet/ip/reass/ip6_full_reass.c
src/vnet/ip/reass/ip6_sv_reass.c
src/vnet/l2/l2_fib.c
src/vnet/lisp-cp/control.c
src/vnet/lisp-cp/gid_dictionary.c
src/vnet/lisp-cp/gid_dictionary.h
src/vnet/mfib/ip6_mfib.c
src/vnet/session/session_table.c
src/vnet/session/session_table.h
src/vppinfra/bihash_doc.h
src/vppinfra/bihash_template.c
src/vppinfra/bihash_template.h

index bef6777..c6cab3f 100644 (file)
@@ -1268,8 +1268,8 @@ gbp_endpoint_show_one (index_t gei, void *ctx)
   return (WALK_CONTINUE);
 }
 
-static void
-gbp_endpoint_walk_ip_itf (const clib_bihash_kv_24_8_t * kvp, void *arg)
+static int
+gbp_endpoint_walk_ip_itf (clib_bihash_kv_24_8_t * kvp, void *arg)
 {
   ip46_address_t ip;
   vlib_main_t *vm;
@@ -1283,10 +1283,11 @@ gbp_endpoint_walk_ip_itf (const clib_bihash_kv_24_8_t * kvp, void *arg)
                   format_ip46_address, &ip, IP46_TYPE_ANY,
                   format_vnet_sw_if_index_name, vnet_get_main (),
                   sw_if_index, kvp->value);
+  return (BIHASH_WALK_CONTINUE);
 }
 
-static void
-gbp_endpoint_walk_mac_itf (const clib_bihash_kv_16_8_t * kvp, void *arg)
+static int
+gbp_endpoint_walk_mac_itf (clib_bihash_kv_16_8_t * kvp, void *arg)
 {
   mac_address_t mac;
   vlib_main_t *vm;
@@ -1300,6 +1301,7 @@ gbp_endpoint_walk_mac_itf (const clib_bihash_kv_16_8_t * kvp, void *arg)
                   format_mac_address_t, &mac,
                   format_vnet_sw_if_index_name, vnet_get_main (),
                   sw_if_index, kvp->value);
+  return (BIHASH_WALK_CONTINUE);
 }
 
 static clib_error_t *
index 1f8a728..46faa1f 100644 (file)
@@ -628,7 +628,7 @@ typedef struct pppoe_show_walk_ctx_t_
   u32 total_entries;
 } pppoe_show_walk_ctx_t;
 
-static void
+static int
 pppoe_show_walk_cb (BVT (clib_bihash_kv) * kvp, void *arg)
 {
   pppoe_show_walk_ctx_t *ctx = arg;
@@ -656,6 +656,8 @@ pppoe_show_walk_cb (BVT (clib_bihash_kv) * kvp, void *arg)
                   result.fields.session_index == ~0
                   ? -1 : result.fields.session_index);
   ctx->total_entries++;
+
+  return (BIHASH_WALK_CONTINUE);
 }
 
 /** Display the contents of the PPPoE Fib. */
index 2dbc6b1..0352403 100644 (file)
@@ -244,11 +244,12 @@ test_bihash_threads (bihash_test_main_t * tm)
 /*
  * Callback to blow up spectacularly if anything remains in the table
  */
-static void
+static int
 count_items (BVT (clib_bihash_kv) * kvp, void *notused)
 {
   _clib_error (CLIB_ERROR_ABORT, 0, 0,
               "bihash test FAILED, items left in table!");
+  return (BIHASH_WALK_CONTINUE);
 }
 
 static clib_error_t *
index 2e0888b..4fb6d92 100644 (file)
@@ -521,12 +521,13 @@ typedef struct adj_db_count_ctx_t_ {
     u64 count;
 } adj_db_count_ctx_t;
 
-static void
+static int
 adj_db_count (BVT(clib_bihash_kv) * kvp,
              void *arg)
 {
     adj_db_count_ctx_t * ctx = arg;
     ctx->count++;
+    return (BIHASH_WALK_CONTINUE);
 }
 
 u32
@@ -563,14 +564,16 @@ typedef struct adj_walk_ctx_t_
     void *awc_ctx;
 } adj_walk_ctx_t;
 
-static void
+static int
 adj_nbr_walk_cb (BVT(clib_bihash_kv) * kvp,
                 void *arg)
 {
     adj_walk_ctx_t *ctx = arg;
 
     // FIXME: can't stop early...
-    ctx->awc_cb(kvp->value, ctx->awc_ctx);
+    if (ADJ_WALK_RC_STOP == ctx->awc_cb(kvp->value, ctx->awc_ctx))
+        return (BIHASH_WALK_STOP);
+    return (BIHASH_WALK_CONTINUE);
 }
 
 void
index 6d0eca4..06160c5 100644 (file)
@@ -589,7 +589,7 @@ typedef struct {
   u64 count_by_prefix_length[129];
 } count_routes_in_fib_at_prefix_length_arg_t;
 
-static void
+static int
 count_routes_in_fib_at_prefix_length (clib_bihash_kv_24_8_t * kvp,
                                       void *arg)
 {
@@ -597,11 +597,13 @@ count_routes_in_fib_at_prefix_length (clib_bihash_kv_24_8_t * kvp,
   int mask_width;
 
   if ((kvp->key[2]>>32) != ap->fib_index)
-    return;
+      return (BIHASH_WALK_CONTINUE);
 
   mask_width = kvp->key[2] & 0xFF;
 
   ap->count_by_prefix_length[mask_width]++;
+
+  return (BIHASH_WALK_CONTINUE);
 }
 
 static clib_error_t *
index 3672b63..243b94a 100644 (file)
@@ -210,18 +210,20 @@ typedef struct
   u64 count_by_prefix_length[129];
 } count_routes_in_fib_at_prefix_length_arg_t;
 
-static void
-count_routes_in_fib_at_prefix_length (BVT (clib_bihash_kv) * kvp, void *arg)
+static int
+count_routes_in_fib_at_prefix_length (clib_bihash_kv_24_8_t * kvp, void *arg)
 {
   count_routes_in_fib_at_prefix_length_arg_t *ap = arg;
   int mask_width;
 
   if ((kvp->key[2] >> 32) != ap->fib_index)
-    return;
+    return (BIHASH_WALK_CONTINUE);
 
   mask_width = kvp->key[2] & 0xFF;
 
   ap->count_by_prefix_length[mask_width]++;
+
+  return (BIHASH_WALK_CONTINUE);
 }
 
 static clib_error_t *
index f6c0546..d492e5e 100644 (file)
@@ -1365,7 +1365,7 @@ typedef struct
 } ip4_rehash_cb_ctx;
 
 #ifndef CLIB_MARCH_VARIANT
-static void
+static int
 ip4_rehash_cb (clib_bihash_kv_16_8_t * kv, void *_ctx)
 {
   ip4_rehash_cb_ctx *ctx = _ctx;
@@ -1373,6 +1373,7 @@ ip4_rehash_cb (clib_bihash_kv_16_8_t * kv, void *_ctx)
     {
       ctx->failure = 1;
     }
+  return (BIHASH_WALK_CONTINUE);
 }
 
 static void
index a926f2a..d713062 100644 (file)
@@ -711,7 +711,7 @@ typedef struct
 } ip4_rehash_cb_ctx;
 
 #ifndef CLIB_MARCH_VARIANT
-static void
+static int
 ip4_rehash_cb (clib_bihash_kv_16_8_t * kv, void *_ctx)
 {
   ip4_rehash_cb_ctx *ctx = _ctx;
@@ -719,6 +719,7 @@ ip4_rehash_cb (clib_bihash_kv_16_8_t * kv, void *_ctx)
     {
       ctx->failure = 1;
     }
+  return (BIHASH_WALK_CONTINUE);
 }
 
 static void
index 7f56d2c..7bcfdfc 100644 (file)
@@ -1349,7 +1349,7 @@ typedef struct
   clib_bihash_48_8_t *new_hash;
 } ip6_rehash_cb_ctx;
 
-static void
+static int
 ip6_rehash_cb (clib_bihash_kv_48_8_t * kv, void *_ctx)
 {
   ip6_rehash_cb_ctx *ctx = _ctx;
@@ -1357,6 +1357,7 @@ ip6_rehash_cb (clib_bihash_kv_48_8_t * kv, void *_ctx)
     {
       ctx->failure = 1;
     }
+  return (BIHASH_WALK_CONTINUE);
 }
 
 static void
index 5531d0b..0837f06 100644 (file)
@@ -818,7 +818,7 @@ typedef struct
   clib_bihash_48_8_t *new_hash;
 } ip6_rehash_cb_ctx;
 
-static void
+static int
 ip6_rehash_cb (clib_bihash_kv_48_8_t * kv, void *_ctx)
 {
   ip6_rehash_cb_ctx *ctx = _ctx;
@@ -826,6 +826,7 @@ ip6_rehash_cb (clib_bihash_kv_48_8_t * kv, void *_ctx)
     {
       ctx->failure = 1;
     }
+  return (BIHASH_WALK_CONTINUE);
 }
 
 static void
index 600d0c9..3e71f77 100644 (file)
@@ -111,7 +111,7 @@ typedef struct l2fib_dump_walk_ctx_t_
   l2fib_entry_result_t *l2fe_res;
 } l2fib_dump_walk_ctx_t;
 
-static void
+static int
 l2fib_dump_walk_cb (BVT (clib_bihash_kv) * kvp, void *arg)
 {
   l2fib_dump_walk_ctx_t *ctx = arg;
@@ -126,6 +126,8 @@ l2fib_dump_walk_cb (BVT (clib_bihash_kv) * kvp, void *arg)
       vec_add1 (ctx->l2fe_key, key);
       vec_add1 (ctx->l2fe_res, result);
     }
+
+  return (BIHASH_WALK_CONTINUE);
 }
 
 void
@@ -158,7 +160,7 @@ typedef struct l2fib_show_walk_ctx_t_
   u8 now;
 } l2fib_show_walk_ctx_t;
 
-static void
+static int
 l2fib_show_walk_cb (BVT (clib_bihash_kv) * kvp, void *arg)
 {
   l2fib_show_walk_ctx_t *ctx = arg;
@@ -186,10 +188,10 @@ l2fib_show_walk_cb (BVT (clib_bihash_kv) * kvp, void *arg)
       u8 *s = NULL;
 
       if (ctx->learn && l2fib_entry_result_is_set_AGE_NOT (&result))
-       return;                 /* skip provisioned macs */
+       return (BIHASH_WALK_CONTINUE);  /* skip provisioned macs */
 
       if (ctx->add && !l2fib_entry_result_is_set_AGE_NOT (&result))
-       return;                 /* skip learned macs */
+       return (BIHASH_WALK_CONTINUE);  /* skip learned macs */
 
       bd_config = vec_elt_at_index (l2input_main.bd_configs,
                                    key.fields.bd_index);
@@ -219,6 +221,8 @@ l2fib_show_walk_cb (BVT (clib_bihash_kv) * kvp, void *arg)
                       ctx->vnm, result.fields.sw_if_index);
       vec_free (s);
     }
+
+  return (BIHASH_WALK_CONTINUE);
 }
 
 /** Display the contents of the l2fib. */
index 420a6db..78750b9 100644 (file)
@@ -899,16 +899,17 @@ vnet_lisp_add_del_local_mapping (vnet_lisp_add_del_mapping_args_t * a,
   return vnet_lisp_map_cache_add_del (a, map_index_result);
 }
 
-static void
+static int
 add_l2_arp_bd (BVT (clib_bihash_kv) * kvp, void *arg)
 {
   u32 **ht = arg;
   u32 version = (u32) kvp->key[0];
   if (AF_IP6 == version)
-    return;
+    return (BIHASH_WALK_CONTINUE);
 
   u32 bd = (u32) (kvp->key[0] >> 32);
   hash_set (ht[0], bd, 0);
+  return (BIHASH_WALK_CONTINUE);
 }
 
 u32 *
@@ -922,16 +923,17 @@ vnet_lisp_l2_arp_bds_get (void)
   return bds;
 }
 
-static void
+static int
 add_ndp_bd (BVT (clib_bihash_kv) * kvp, void *arg)
 {
   u32 **ht = arg;
   u32 version = (u32) kvp->key[0];
   if (AF_IP4 == version)
-    return;
+    return (BIHASH_WALK_CONTINUE);
 
   u32 bd = (u32) (kvp->key[0] >> 32);
   hash_set (ht[0], bd, 0);
+  return (BIHASH_WALK_CONTINUE);
 }
 
 u32 *
@@ -951,7 +953,7 @@ typedef struct
   u32 bd;
 } lisp_add_l2_arp_ndp_args_t;
 
-static void
+static int
 add_l2_arp_entry (BVT (clib_bihash_kv) * kvp, void *arg)
 {
   lisp_add_l2_arp_ndp_args_t *a = arg;
@@ -959,7 +961,7 @@ add_l2_arp_entry (BVT (clib_bihash_kv) * kvp, void *arg)
 
   u32 version = (u32) kvp->key[0];
   if (AF_IP6 == version)
-    return;
+    return (BIHASH_WALK_CONTINUE);
 
   u32 bd = (u32) (kvp->key[0] >> 32);
 
@@ -969,6 +971,7 @@ add_l2_arp_entry (BVT (clib_bihash_kv) * kvp, void *arg)
       e.ip4 = (u32) kvp->key[1];
       vec_add1 (vector[0], e);
     }
+  return (BIHASH_WALK_CONTINUE);
 }
 
 lisp_api_l2_arp_entry_t *
@@ -986,7 +989,7 @@ vnet_lisp_l2_arp_entries_get_by_bd (u32 bd)
   return entries;
 }
 
-static void
+static int
 add_ndp_entry (BVT (clib_bihash_kv) * kvp, void *arg)
 {
   lisp_add_l2_arp_ndp_args_t *a = arg;
@@ -994,7 +997,7 @@ add_ndp_entry (BVT (clib_bihash_kv) * kvp, void *arg)
 
   u32 version = (u32) kvp->key[0];
   if (AF_IP4 == version)
-    return;
+    return (BIHASH_WALK_CONTINUE);
 
   u32 bd = (u32) (kvp->key[0] >> 32);
 
@@ -1004,6 +1007,7 @@ add_ndp_entry (BVT (clib_bihash_kv) * kvp, void *arg)
       clib_memcpy (e.ip6, &kvp->key[1], 16);
       vec_add1 (vector[0], e);
     }
+  return (BIHASH_WALK_CONTINUE);
 }
 
 lisp_api_ndp_entry_t *
index 3fd98c7..c1b4ada 100644 (file)
@@ -31,7 +31,7 @@ static u32 ip4_lookup (gid_ip4_table_t * db, u32 vni, ip_prefix_t * key);
 
 static u32 ip6_lookup (gid_ip6_table_t * db, u32 vni, ip_prefix_t * key);
 
-static void
+static int
 foreach_sfib4_subprefix (BVT (clib_bihash_kv) * kvp, void *arg)
 {
   sfib_entry_arg_t *a = arg;
@@ -51,6 +51,7 @@ foreach_sfib4_subprefix (BVT (clib_bihash_kv) * kvp, void *arg)
       /* found sub-prefix of src prefix */
       (a->cb) (kvp->value, a->arg);
     }
+  return (BIHASH_WALK_CONTINUE);
 }
 
 static void
@@ -77,7 +78,7 @@ gid_dict_foreach_ip4_subprefix (gid_dictionary_t * db, u32 vni,
                                           foreach_sfib4_subprefix, &a);
 }
 
-static void
+static int
 foreach_sfib6_subprefix (BVT (clib_bihash_kv) * kvp, void *arg)
 {
   sfib_entry_arg_t *a = arg;
@@ -94,6 +95,7 @@ foreach_sfib6_subprefix (BVT (clib_bihash_kv) * kvp, void *arg)
       /* found sub-prefix of src prefix */
       (a->cb) (kvp->value, a->arg);
     }
+  return (BIHASH_WALK_CONTINUE);
 }
 
 static void
@@ -139,9 +141,9 @@ gid_dict_foreach_subprefix (gid_dictionary_t * db, gid_address_t * eid,
 }
 
 void
-gid_dict_foreach_l2_arp_ndp_entry (gid_dictionary_t * db, void (*cb)
-                                  (BVT (clib_bihash_kv) * kvp, void *arg),
-                                  void *ht)
+gid_dict_foreach_l2_arp_ndp_entry (gid_dictionary_t * db,
+                                  BV (clib_bihash_foreach_key_value_pair_cb)
+                                  cb, void *ht)
 {
   gid_l2_arp_ndp_table_t *tab = &db->arp_ndp_table;
   BV (clib_bihash_foreach_key_value_pair) (&tab->arp_ndp_lookup_table, cb,
index 3f8500e..5154b3a 100644 (file)
@@ -146,9 +146,9 @@ gid_dict_foreach_subprefix (gid_dictionary_t * db, gid_address_t * eid,
                            foreach_subprefix_match_cb_t cb, void *arg);
 
 void
-gid_dict_foreach_l2_arp_ndp_entry (gid_dictionary_t * db, void (*cb)
-                                  (BVT (clib_bihash_kv) * kvp, void *arg),
-                                  void *ht);
+gid_dict_foreach_l2_arp_ndp_entry (gid_dictionary_t * db,
+                                  BV (clib_bihash_foreach_key_value_pair_cb)
+                                  cb, void *ht);
 
 #endif /* VNET_LISP_GPE_GID_DICTIONARY_H_ */
 
index 690f4ed..6b3b8d9 100644 (file)
@@ -609,7 +609,7 @@ typedef struct ip6_mfib_walk_ctx_t_
     void *i6w_ctx;
 } ip6_mfib_walk_ctx_t;
 
-static void
+static int
 ip6_mfib_walk_cb (clib_bihash_kv_40_8_t * kvp,
                  void *arg)
 {
@@ -619,6 +619,7 @@ ip6_mfib_walk_cb (clib_bihash_kv_40_8_t * kvp,
     {
         ctx->i6w_fn(kvp->value, ctx->i6w_ctx);
     }
+    return (BIHASH_WALK_CONTINUE);
 }
 
 void
index 1f586f8..d619fa5 100644 (file)
@@ -139,11 +139,12 @@ typedef struct _ip4_session_table_walk_ctx_t
   void *ctx;
 } ip4_session_table_walk_ctx_t;
 
-void
+static int
 ip4_session_table_walk_cb (clib_bihash_kv_16_8_t * kvp, void *arg)
 {
   ip4_session_table_walk_ctx_t *ctx = arg;
   ctx->fn (kvp, ctx->ctx);
+  return (BIHASH_WALK_CONTINUE);
 }
 
 void
index 4aaa900..d3af566 100644 (file)
@@ -60,7 +60,6 @@ typedef struct _session_lookup_table
 typedef int (*ip4_session_table_walk_fn_t) (clib_bihash_kv_16_8_t * kvp,
                                            void *ctx);
 
-void ip4_session_table_walk_cb (clib_bihash_kv_16_8_t * kvp, void *arg);
 void ip4_session_table_walk (clib_bihash_16_8_t * hash,
                             ip4_session_table_walk_fn_t fn, void *arg);
 
index a7e70e9..da8c832 100644 (file)
@@ -165,17 +165,25 @@ void clib_bihash_prefetch_data (clib_bihash * h, u64 hash);
 int clib_bihash_search_inline_2
   (clib_bihash * h, clib_bihash_kv * search_key, clib_bihash_kv * valuep);
 
+/* Calback function for walking a bihash table
+ *
+ * @param kv - KV pair visited
+ * @param ctx - Context passed to the walk
+ * @return BIHASH_WALK_CONTINUE to continue BIHASH_WALK_STOP to stop
+ */
+typedef int (*clib_bihash_foreach_key_value_pair_cb) (clib_bihash_kv * kv,
+                                                     void *ctx);
+
 /** Visit active (key,value) pairs in a bi-hash table
 
     @param h - the bi-hash table to search
     @param callback - function to call with each active (key,value) pair
     @param arg - arbitrary second argument passed to the callback function
     First argument is the (key,value) pair to visit
-    @note Trying to supply a proper function prototype for the
-    callback function appears to be a fool's errand.
 */
 void clib_bihash_foreach_key_value_pair (clib_bihash * h,
-                                        void *callback, void *arg);
+                                        clib_bihash_foreach_key_value_pair_cb
+                                        * callback, void *arg);
 
 /*
  * fd.io coding-style-patch-verification: ON
index 97c4cd0..b090041 100644 (file)
@@ -906,12 +906,12 @@ u8 *BV (format_bihash) (u8 * s, va_list * args)
 }
 
 void BV (clib_bihash_foreach_key_value_pair)
-  (BVT (clib_bihash) * h, void *callback, void *arg)
+  (BVT (clib_bihash) * h,
+   BV (clib_bihash_foreach_key_value_pair_cb) cb, void *arg)
 {
   int i, j, k;
   BVT (clib_bihash_bucket) * b;
   BVT (clib_bihash_value) * v;
-  void (*fp) (BVT (clib_bihash_kv) *, void *) = callback;
 
   if (PREDICT_FALSE (alloc_arena (h) == 0))
     return;
@@ -930,7 +930,8 @@ void BV (clib_bihash_foreach_key_value_pair)
              if (BV (clib_bihash_is_free) (&v->kvp[k]))
                continue;
 
-             (*fp) (&v->kvp[k], arg);
+             if (BIHASH_WALK_STOP == cb (&v->kvp[k], arg))
+               return;
              /*
               * In case the callback deletes the last entry in the bucket...
               */
index ebd70c0..f11e6d5 100644 (file)
@@ -328,8 +328,16 @@ int BV (clib_bihash_search) (BVT (clib_bihash) * h,
                             BVT (clib_bihash_kv) * search_v,
                             BVT (clib_bihash_kv) * return_v);
 
+#define BIHASH_WALK_STOP 0
+#define BIHASH_WALK_CONTINUE 1
+
+typedef
+  int (*BV (clib_bihash_foreach_key_value_pair_cb)) (BVT (clib_bihash_kv) *,
+                                                    void *);
 void BV (clib_bihash_foreach_key_value_pair) (BVT (clib_bihash) * h,
-                                             void *callback, void *arg);
+                                             BV
+                                             (clib_bihash_foreach_key_value_pair_cb)
+                                             cb, void *arg);
 void *clib_all_bihash_set_heap (void);
 void clib_bihash_copied (void *dst, void *src);