srv6-mobile: Update GTP4/6.D function
[vpp.git] / src / plugins / srv6-mobile / gtp4_d.c
index 7bafa56..bf5dcd2 100644 (file)
@@ -68,12 +68,13 @@ static u8 keyword_str[] = "t.m.gtp4.d";
 static u8 def_str[] =
   "Transit function with decapsulation for IPv4/GTP tunnel";
 static u8 param_str[] =
-  "<sr-prefix>/<sr-prefixlen> v6src_prefix <v6src_prefix>/<prefixlen> [nhtype <nhtype>]";
+  "<sr-prefix>/<sr-prefixlen> v6src_prefix <v6src_prefix>/<prefixlen> [nhtype "
+  "<nhtype>] fib-table <id>";
 
 static u8 *
 clb_format_srv6_t_m_gtp4_d (u8 * s, va_list * args)
 {
-  srv6_end_gtp4_param_t *ls_mem = va_arg (*args, void *);
+  srv6_end_gtp4_d_param_t *ls_mem = va_arg (*args, void *);
 
   s = format (s, "SRv6 T.M.GTP4.D\n\t");
 
@@ -88,16 +89,18 @@ clb_format_srv6_t_m_gtp4_d (u8 * s, va_list * args)
   if (ls_mem->nhtype != SRV6_NHTYPE_NONE)
     {
       if (ls_mem->nhtype == SRV6_NHTYPE_IPV4)
-       s = format (s, ", NHType IPv4\n");
+       s = format (s, ", NHType IPv4");
       else if (ls_mem->nhtype == SRV6_NHTYPE_IPV6)
-       s = format (s, ", NHType IPv6\n");
+       s = format (s, ", NHType IPv6");
       else if (ls_mem->nhtype == SRV6_NHTYPE_NON_IP)
-       s = format (s, ", NHType Non-IP\n");
+       s = format (s, ", NHType Non-IP");
       else
-       s = format (s, ", NHType Unknow(%d)\n", ls_mem->nhtype);
+       s = format (s, ", NHType Unknow(%d)", ls_mem->nhtype);
     }
-  else
-    s = format (s, "\n");
+
+  s = format (s, ", FIB table %d", ls_mem->fib_table);
+
+  s = format (s, ", Drop In %d\n", ls_mem->drop_in);
 
   return s;
 }
@@ -106,42 +109,65 @@ static uword
 clb_unformat_srv6_t_m_gtp4_d (unformat_input_t * input, va_list * args)
 {
   void **plugin_mem_p = va_arg (*args, void **);
-  srv6_end_gtp4_param_t *ls_mem;
+  srv6_end_gtp4_d_param_t *ls_mem;
   ip6_address_t sr_prefix;
   u32 sr_prefixlen;
   ip6_address_t v6src_prefix;
   u32 v6src_prefixlen;
-  u8 nhtype;
+  u32 fib_table = 0;
+  bool drop_in = false;
+  u8 nhtype = SRV6_NHTYPE_NONE;
+  bool config = false;
 
-  if (unformat (input, "t.m.gtp4.d %U/%d v6src_prefix %U/%d nhtype ipv4",
-               unformat_ip6_address, &sr_prefix, &sr_prefixlen,
-               unformat_ip6_address, &v6src_prefix, &v6src_prefixlen))
-    {
-      nhtype = SRV6_NHTYPE_IPV4;
-    }
-  else
-    if (unformat
-       (input, "t.m.gtp4.d %U/%d v6src_prefix %U/%d nhtype ipv6",
-        unformat_ip6_address, &sr_prefix, &sr_prefixlen,
-        unformat_ip6_address, &v6src_prefix, &v6src_prefixlen))
-    {
-      nhtype = SRV6_NHTYPE_IPV6;
-    }
-  else
-    if (unformat
-       (input, "t.m.gtp4.d %U/%d v6src_prefix %U/%d nhtype non-ip",
-        unformat_ip6_address, &sr_prefix, &sr_prefixlen,
-        unformat_ip6_address, &v6src_prefix, &v6src_prefixlen))
+  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
     {
-      nhtype = SRV6_NHTYPE_NON_IP;
-    }
-  else if (unformat (input, "t.m.gtp4.d %U/%d v6src_prefix %U/%d",
-                    unformat_ip6_address, &sr_prefix, &sr_prefixlen,
-                    unformat_ip6_address, &v6src_prefix, &v6src_prefixlen))
-    {
-      nhtype = SRV6_NHTYPE_NONE;
+      if (unformat (
+           input,
+           "t.m.gtp4.d %U/%d v6src_prefix %U/%d nhtype ipv4 fib-table %d",
+           unformat_ip6_address, &sr_prefix, &sr_prefixlen,
+           unformat_ip6_address, &v6src_prefix, &v6src_prefixlen, &fib_table))
+       {
+         config = true;
+         nhtype = SRV6_NHTYPE_IPV4;
+       }
+      else if (unformat (input,
+                        "t.m.gtp4.d %U/%d v6src_prefix %U/%d nhtype ipv6 "
+                        "fib-table %d",
+                        unformat_ip6_address, &sr_prefix, &sr_prefixlen,
+                        unformat_ip6_address, &v6src_prefix, &v6src_prefixlen,
+                        &fib_table))
+       {
+         config = true;
+         nhtype = SRV6_NHTYPE_IPV6;
+       }
+      else if (unformat (
+                input, "t.m.gtp4.d %U/%d v6src_prefix %U/%d nhtype non-ip",
+                unformat_ip6_address, &sr_prefix, &sr_prefixlen,
+                unformat_ip6_address, &v6src_prefix, &v6src_prefixlen))
+       {
+         config = true;
+         nhtype = SRV6_NHTYPE_NON_IP;
+       }
+      else if (unformat (input,
+                        "t.m.gtp4.d %U/%d v6src_prefix %U/%d fib-table %d",
+                        unformat_ip6_address, &sr_prefix, &sr_prefixlen,
+                        unformat_ip6_address, &v6src_prefix, &v6src_prefixlen,
+                        &fib_table))
+       {
+         config = true;
+         nhtype = SRV6_NHTYPE_NONE;
+       }
+      else if (unformat (input, "drop-in"))
+       {
+         drop_in = true;
+       }
+      else
+       {
+         return 0;
+       }
     }
-  else
+
+  if (!config)
     {
       return 0;
     }
@@ -158,6 +184,12 @@ clb_unformat_srv6_t_m_gtp4_d (unformat_input_t * input, va_list * args)
 
   ls_mem->nhtype = nhtype;
 
+  ls_mem->drop_in = drop_in;
+
+  ls_mem->fib_table = fib_table;
+  ls_mem->fib4_index = ip4_fib_index_from_table_id (fib_table);
+  ls_mem->fib6_index = ip6_fib_index_from_table_id (fib_table);
+
   return 1;
 }
 
@@ -170,9 +202,9 @@ clb_creation_srv6_t_m_gtp4_d (ip6_sr_policy_t * sr_policy)
 static int
 clb_removal_srv6_t_m_gtp4_d (ip6_sr_policy_t * sr_policy)
 {
-  srv6_end_gtp4_param_t *ls_mem;
+  srv6_end_gtp4_d_param_t *ls_mem;
 
-  ls_mem = (srv6_end_gtp4_param_t *) sr_policy->plugin_mem;
+  ls_mem = (srv6_end_gtp4_d_param_t *) sr_policy->plugin_mem;
 
   clib_mem_free (ls_mem);