ip: Add unformat for flow_hash_config 54/35754/2
authorNathan Skrzypczak <nathan.skrzypczak@gmail.com>
Wed, 23 Mar 2022 17:08:53 +0000 (18:08 +0100)
committerDamjan Marion <dmarion@me.com>
Wed, 23 Mar 2022 18:29:08 +0000 (18:29 +0000)
Type: improvement

This also makes the is_white_space function
public

Change-Id: Ifc1c0d4509f3ecae14f09bb5fa7a2eea33c49b09
Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
src/vnet/ip/lookup.c
src/vnet/ip/lookup.h
src/vppinfra/format.h
src/vppinfra/unformat.c

index c2c4bae..92310e4 100644 (file)
@@ -128,6 +128,42 @@ format_ip_flow_hash_config (u8 * s, va_list * args)
   return s;
 }
 
+uword
+unformat_ip_flow_hash_config (unformat_input_t *input, va_list *args)
+{
+  flow_hash_config_t *flow_hash_config = va_arg (*args, flow_hash_config_t *);
+  uword start_index = unformat_check_input (input);
+  int matched_once = 0;
+
+  if (unformat (input, "default"))
+    {
+      *flow_hash_config = IP_FLOW_HASH_DEFAULT;
+      return 1;
+    }
+  while (!unformat_is_eof (input) &&
+        !is_white_space (unformat_peek_input (input)))
+    {
+      if (unformat (input, "%_,"))
+       ;
+#define _(a, b)                                                               \
+  else if (unformat (input, "%_" #a))                                         \
+  {                                                                           \
+    *flow_hash_config |= b;                                                   \
+    matched_once = 1;                                                         \
+  }
+      foreach_flow_hash_bit_v1
+#undef _
+       else
+      {
+       /* Roll back to our start */
+       input->index = start_index;
+       return 0;
+      }
+    }
+
+  return matched_once;
+}
+
 u8 *
 format_ip_adjacency_packet_data (u8 * s, va_list * args)
 {
index 48ba468..aa99827 100644 (file)
@@ -162,7 +162,7 @@ typedef struct ip_lookup_main_t
 } ip_lookup_main_t;
 
 u8 *format_ip_flow_hash_config (u8 * s, va_list * args);
-
+uword unformat_ip_flow_hash_config (unformat_input_t *input, va_list *args);
 
 always_inline void
 ip_lookup_set_buffer_fib_index (u32 * fib_index_by_sw_if_index,
index ee47a20..2cd636d 100644 (file)
@@ -200,6 +200,22 @@ unformat_put_input (unformat_input_t * input)
   input->index -= 1;
 }
 
+always_inline uword
+is_white_space (uword c)
+{
+  switch (c)
+    {
+    case ' ':
+    case '\t':
+    case '\n':
+    case '\r':
+      return 1;
+
+    default:
+      return 0;
+    }
+}
+
 /* Peek current input character without advancing. */
 always_inline uword
 unformat_peek_input (unformat_input_t * input)
index 0f6da4f..3904b45 100644 (file)
@@ -70,22 +70,6 @@ _unformat_fill_input (unformat_input_t * i)
   return i->index;
 }
 
-always_inline uword
-is_white_space (uword c)
-{
-  switch (c)
-    {
-    case ' ':
-    case '\t':
-    case '\n':
-    case '\r':
-      return 1;
-
-    default:
-      return 0;
-    }
-}
-
 /* Format function for dumping input stream. */
 __clib_export u8 *
 format_unformat_error (u8 * s, va_list * va)