ikev2: support responder hostname
[vpp.git] / src / vppinfra / bitmap.h
index d6dfe86..5c56068 100644 (file)
@@ -314,7 +314,7 @@ clib_bitmap_set_multiple (uword * bitmap, uword i, uword value, uword n_bits)
 }
 
 always_inline uword *
-clfib_bitmap_set_region (uword * bitmap, uword i, uword value, uword n_bits)
+clib_bitmap_set_region (uword * bitmap, uword i, uword value, uword n_bits)
 {
   uword a0, a1, b0;
   uword i_end, mask;
@@ -358,7 +358,13 @@ clfib_bitmap_set_region (uword * bitmap, uword i, uword value, uword n_bits)
     @param ai - the bitmap
     @param body - the expression to evaluate for each set bit
 */
-#define clib_bitmap_foreach(i,ai,body)                                 \
+#define clib_bitmap_foreach(i,ai)                                      \
+  if (ai)                                                              \
+    for (i = clib_bitmap_first_set (ai);                               \
+        i != ~0;                                                       \
+        i = clib_bitmap_next_set (ai, i + 1))
+
+#define clib_bitmap_foreach_old(i,ai,body)                             \
 do {                                                                   \
   uword __bitmap_i, __bitmap_ai, __bitmap_len, __bitmap_first_set;     \
   __bitmap_len = vec_len ((ai));                                       \
@@ -728,10 +734,49 @@ clib_bitmap_next_clear (uword * ai, uword i)
          if (t)
            return log2_first_set (t) + i0 * BITS (ai[0]);
        }
+
+      /* no clear bit left in bitmap, return bit just beyond bitmap */
+      return (i0 * BITS (ai[0])) + 1;
     }
   return i;
 }
 
+/** unformat an any sized hexadecimal bitmask into a bitmap
+
+    uword * bitmap;
+    rv = unformat ("%U", unformat_bitmap_mask, &bitmap);
+
+    Standard unformat_function_t arguments
+
+    @param input - pointer an unformat_input_t
+    @param va - varargs list comprising a single uword **
+    @returns 1 on success, 0 on failure
+*/
+static inline uword
+unformat_bitmap_mask (unformat_input_t * input, va_list * va)
+{
+  u8 *v = 0;                   /* hexadecimal vector */
+  uword **bitmap_return = va_arg (*va, uword **);
+  uword *bitmap = 0;
+
+  if (unformat (input, "%U", unformat_hex_string, &v))
+    {
+      int i, s = vec_len (v) - 1;      /* 's' for significance or shift */
+
+      /* v[0] holds the most significant byte */
+      for (i = 0; s >= 0; i++, s--)
+       bitmap = clib_bitmap_set_multiple (bitmap,
+                                          s * BITS (v[i]), v[i],
+                                          BITS (v[i]));
+
+      vec_free (v);
+      *bitmap_return = bitmap;
+      return 1;
+    }
+
+  return 0;
+}
+
 /** unformat a list of bit ranges into a bitmap (eg "0-3,5-7,11" )
 
     uword * bitmap;