tunnel: add cli support for encap_decap flags 14/30214/5
authorMohammed Hawari <mohammed@hawari.fr>
Tue, 1 Dec 2020 10:30:57 +0000 (11:30 +0100)
committerNeale Ranns <nranns@cisco.com>
Tue, 8 Dec 2020 16:38:01 +0000 (16:38 +0000)
Change-Id: I2bf6ba325975309183dba1e14e9519c944710752
Signed-off-by: Mohammed Hawari <mohammed@hawari.fr>
Type: improvement

src/vnet/gre/interface.c
src/vnet/ipip/ipip_cli.c
src/vnet/tunnel/tunnel.c
src/vnet/tunnel/tunnel.h

index ad0efde..5e8ad46 100644 (file)
@@ -593,6 +593,7 @@ create_gre_tunnel_command_fn (vlib_main_t * vm,
   u32 outer_table_id = 0;
   gre_tunnel_type_t t_type = GRE_TUNNEL_TYPE_L3;
   tunnel_mode_t t_mode = TUNNEL_MODE_P2P;
+  tunnel_encap_decap_flags_t flags = TUNNEL_ENCAP_DECAP_FLAG_NONE;
   u32 session_id = 0;
   int rv;
   u8 is_add = 1;
@@ -621,6 +622,11 @@ create_gre_tunnel_command_fn (vlib_main_t * vm,
        t_type = GRE_TUNNEL_TYPE_TEB;
       else if (unformat (line_input, "erspan %d", &session_id))
        t_type = GRE_TUNNEL_TYPE_ERSPAN;
+      else
+       if (unformat
+           (line_input, "flags %U", unformat_tunnel_encap_decap_flags,
+            &flags))
+       ;
       else
        {
          error = clib_error_return (0, "unknown input `%U'",
@@ -662,6 +668,7 @@ create_gre_tunnel_command_fn (vlib_main_t * vm,
   a->session_id = session_id;
   a->is_ipv6 = !ip46_address_is_ip4 (&src);
   a->instance = instance;
+  a->flags = flags;
   clib_memcpy (&a->src, &src, sizeof (a->src));
   clib_memcpy (&a->dst, &dst, sizeof (a->dst));
 
index 5e049af..872fb33 100644 (file)
@@ -35,6 +35,7 @@ create_ipip_tunnel_command_fn (vlib_main_t * vm,
   clib_error_t *error = NULL;
   bool ip4_set = false, ip6_set = false;
   tunnel_mode_t mode = TUNNEL_MODE_P2P;
+  tunnel_encap_decap_flags_t flags = TUNNEL_ENCAP_DECAP_FLAG_NONE;
 
   /* Get a line of input. */
   if (!unformat_user (input, unformat_line_input, line_input))
@@ -74,6 +75,11 @@ create_ipip_tunnel_command_fn (vlib_main_t * vm,
        }
       else if (unformat (line_input, "outer-table-id %d", &table_id))
        ;
+      else
+       if (unformat
+           (line_input, "flags %U", unformat_tunnel_encap_decap_flags,
+            &flags))
+       ;
       else
        {
          error =
@@ -109,8 +115,7 @@ create_ipip_tunnel_command_fn (vlib_main_t * vm,
                            &src,
                            &dst,
                            fib_index,
-                           TUNNEL_ENCAP_DECAP_FLAG_NONE,
-                           IP_DSCP_CS0, mode, &sw_if_index);
+                           flags, IP_DSCP_CS0, mode, &sw_if_index);
     }
 
   switch (rv)
index 96d7fd1..38bde34 100644 (file)
@@ -62,6 +62,20 @@ format_tunnel_encap_decap_flags (u8 * s, va_list * args)
     return (s);
 }
 
+uword
+unformat_tunnel_encap_decap_flags (unformat_input_t * input, va_list * args)
+{
+  tunnel_encap_decap_flags_t *f =
+    va_arg (*args, tunnel_encap_decap_flags_t *);
+#define _(a,b,c) if (unformat(input, b)) {\
+  *f |= TUNNEL_ENCAP_DECAP_FLAG_##a;\
+  return 1;\
+  }
+  forech_tunnel_encap_decap_flag;
+#undef _
+  return 0;
+}
+
 
 /*
  * fd.io coding-style-patch-verification: ON
index f23a3d4..6c97fc1 100644 (file)
@@ -55,9 +55,9 @@ typedef enum tunnel_encap_decap_flags_t_
 #define TUNNEL_FLAG_MASK (0x1f)
 
 extern u8 *format_tunnel_encap_decap_flags (u8 * s, va_list * args);
-
+extern uword
+unformat_tunnel_encap_decap_flags (unformat_input_t * input, va_list * args);
 #endif
-
 /*
  * fd.io coding-style-patch-verification: ON
  *