summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/srv6-mobile/CMakeLists.txt1
-rwxr-xr-xsrc/plugins/srv6-mobile/extra/runner.py53
-rw-r--r--src/plugins/srv6-mobile/gtp4_d.c240
-rw-r--r--src/plugins/srv6-mobile/mobile.h13
-rw-r--r--src/plugins/srv6-mobile/node.c476
-rw-r--r--src/plugins/srv6-mobile/test/test_srv6_end.py5
6 files changed, 739 insertions, 49 deletions
diff --git a/src/plugins/srv6-mobile/CMakeLists.txt b/src/plugins/srv6-mobile/CMakeLists.txt
index 612d626df91..ebd03f7fbf4 100644
--- a/src/plugins/srv6-mobile/CMakeLists.txt
+++ b/src/plugins/srv6-mobile/CMakeLists.txt
@@ -14,6 +14,7 @@
add_vpp_plugin(srv6mobile
SOURCES
gtp4_e.c
+ gtp4_d.c
gtp6_e.c
gtp6_d.c
gtp6_d_di.c
diff --git a/src/plugins/srv6-mobile/extra/runner.py b/src/plugins/srv6-mobile/extra/runner.py
index 710252d5ce1..9fffe419029 100755
--- a/src/plugins/srv6-mobile/extra/runner.py
+++ b/src/plugins/srv6-mobile/extra/runner.py
@@ -527,6 +527,7 @@ class Program(object):
for p in c4.pg_read_packets():
p.show2()
+ ''' T.Map is obsolete
def test_tmap(self):
# TESTS:
# trace add af-packet-input 10
@@ -809,6 +810,7 @@ class Program(object):
print("Receiving packet on {}:".format(c4.name))
for p in c4.pg_read_packets():
p.show2()
+ '''
def test_gtp4(self):
# TESTS:
@@ -836,9 +838,8 @@ class Program(object):
c1.vppctl_exec("set sr encaps source addr A1::1")
c1.vppctl_exec("sr policy add bsid D4:: next D2:: next D3::")
- c1.vppctl_exec(
- "sr localsid prefix 172.20.0.1/32 "
- "behavior end.m.gtp4.d D4::/32 v6src_prefix C1::/64 nhtype ipv4")
+ c1.vppctl_exec("sr policy add bsid D5:: behavior t.m.gtp4.d D4::/32 v6src_prefix C1::/64 nhtype ipv4")
+ c1.vppctl_exec("sr steer l3 172.20.0.1/32 via bsid D5::")
c2.vppctl_exec("sr localsid address D2:: behavior end")
@@ -906,10 +907,8 @@ class Program(object):
c1.vppctl_exec("set sr encaps source addr A1::1")
c1.vppctl_exec("sr policy add bsid D4:: next D2:: next D3::")
- c1.vppctl_exec(
- "sr localsid prefix ::ffff:ac14:0001/128 "
- "behavior end.m.gtp4.d D4::/32 v6src_prefix C1::/64 "
- "nhtype ipv4")
+ c1.vppctl_exec("sr policy add bsid D5:: behavior t.m.gtp4.d D4::/32 v6src_prefix C1::/64 nhtype ipv4")
+ c1.vppctl_exec("sr steer l3 172.20.0.1/32 via bsid D5::")
c2.vppctl_exec("sr localsid address D2:: behavior end")
@@ -978,10 +977,8 @@ class Program(object):
c1.vppctl_exec("set sr encaps source addr A1::1")
c1.vppctl_exec("sr policy add bsid D4:: next D2:: next D3::")
- c1.vppctl_exec(
- "sr localsid prefix 172.20.0.1/32 "
- "behavior end.m.gtp4.d D4::/32 v6src_prefix C1::/64 "
- "nhtype ipv4")
+ c1.vppctl_exec("sr policy add bsid D5:: behavior t.m.gtp4.d D4::/32 v6src_prefix C1::/64 nhtype ipv4")
+ c1.vppctl_exec("sr steer l3 172.20.0.1/32 via bsid D5::")
c2.vppctl_exec("sr localsid address D2:: behavior end")
@@ -1047,9 +1044,8 @@ class Program(object):
c1.vppctl_exec("set sr encaps source addr A1::1")
c1.vppctl_exec("sr policy add bsid D4:: next D2:: next D3::")
- c1.vppctl_exec(
- "sr localsid prefix ::ffff:ac14:0001/128 "
- "behavior end.m.gtp4.d D4::/32 v6src_prefix C1::/64")
+ c1.vppctl_exec("sr policy add bsid D5:: behavior t.m.gtp4.d D4::/32 v6src_prefix C1::/64")
+ c1.vppctl_exec("sr steer l3 172.20.0.1/32 via bsid D5::")
c2.vppctl_exec("sr localsid address D2:: behavior end")
@@ -1117,9 +1113,8 @@ class Program(object):
c1.vppctl_exec("set sr encaps source addr A1::1")
c1.vppctl_exec("sr policy add bsid D4:: next D2:: next D3::")
- c1.vppctl_exec(
- "sr localsid prefix ::ffff:ac14:0001/128 "
- "behavior end.m.gtp4.d D4::/32 v6src_prefix C1::/64")
+ c1.vppctl_exec("sr policy add bsid D5:: behavior t.m.gtp4.d D4::/32 v6src_prefix C1::/64")
+ c1.vppctl_exec("sr steer l3 172.20.0.1/32 via bsid D5::")
c2.vppctl_exec("sr localsid address D2:: behavior end")
@@ -1935,10 +1930,10 @@ def get_args():
choices=[
"ping",
"srv6",
- "tmap",
- "tmap_5g",
- "tmap_ipv6",
- "tmap_ipv6_5g",
+ # "tmap",
+ # "tmap_5g",
+ # "tmap_ipv6",
+ # "tmap_ipv6_5g",
"gtp4",
"gtp4_5g",
"gtp4_echo",
@@ -1996,14 +1991,14 @@ def main(op=None, prefix=None, verbose=None,
program.test_ping()
elif op == 'srv6':
program.test_srv6()
- elif op == 'tmap':
- program.test_tmap()
- elif op == 'tmap_5g':
- program.test_tmap_5g()
- elif op == 'tmap_ipv6':
- program.test_tmap_ipv6()
- elif op == 'tmap_ipv6_5g':
- program.test_tmap_ipv6_5g()
+ # elif op == 'tmap':
+ # program.test_tmap()
+ # elif op == 'tmap_5g':
+ # program.test_tmap_5g()
+ # elif op == 'tmap_ipv6':
+ # program.test_tmap_ipv6()
+ # elif op == 'tmap_ipv6_5g':
+ # program.test_tmap_ipv6_5g()
elif op == 'gtp4':
program.test_gtp4()
elif op == 'gtp4_5g':
diff --git a/src/plugins/srv6-mobile/gtp4_d.c b/src/plugins/srv6-mobile/gtp4_d.c
new file mode 100644
index 00000000000..2160a90260f
--- /dev/null
+++ b/src/plugins/srv6-mobile/gtp4_d.c
@@ -0,0 +1,240 @@
+/*
+ * srv6_t_m_gtp4_d.c
+ *
+ * Copyright (c) 2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <vnet/vnet.h>
+#include <vnet/adj/adj.h>
+#include <vnet/plugin/plugin.h>
+#include <vpp/app/version.h>
+#include <srv6-mobile/mobile.h>
+
+srv6_t_main_v4_decap_t srv6_t_main_v4_decap;
+
+static void
+clb_dpo_lock_srv6_t_m_gtp4_d (dpo_id_t * dpo)
+{
+}
+
+static void
+clb_dpo_unlock_srv6_t_m_gtp4_d (dpo_id_t * dpo)
+{
+}
+
+static u8 *
+clb_dpo_format_srv6_t_m_gtp4_d (u8 * s, va_list * args)
+{
+ index_t index = va_arg (*args, index_t);
+ CLIB_UNUSED (u32 indent) = va_arg (*args, u32);
+
+ return (format (s, "SR: dynamic_proxy_index:[%u]", index));
+}
+
+const static dpo_vft_t dpo_vft = {
+ .dv_lock = clb_dpo_lock_srv6_t_m_gtp4_d,
+ .dv_unlock = clb_dpo_unlock_srv6_t_m_gtp4_d,
+ .dv_format = clb_dpo_format_srv6_t_m_gtp4_d,
+};
+
+const static char *const srv6_t_m_gtp4_d_nodes[] = {
+ "srv6-t-m-gtp4-d",
+ NULL,
+};
+
+const static char *const srv6_t_m_gtp4_d_v6_nodes[] = {
+ "error-drop",
+ NULL,
+};
+
+const static char *const *const dpo_nodes[DPO_PROTO_NUM] = {
+ [DPO_PROTO_IP6] = srv6_t_m_gtp4_d_v6_nodes,
+ [DPO_PROTO_IP4] = srv6_t_m_gtp4_d_nodes,
+};
+
+static u8 fn_name[] = "SRv6-T.M.GTP4.D-plugin";
+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>]";
+
+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 *);
+
+ s = format (s, "SRv6 T.M.GTP4.D\n\t");
+
+ s =
+ format (s, "SR Prefix: %U/%d, ", format_ip6_address, &ls_mem->sr_prefix,
+ ls_mem->sr_prefixlen);
+
+ s =
+ format (s, "v6src Prefix: %U/%d", format_ip6_address,
+ &ls_mem->v6src_prefix, ls_mem->v6src_prefixlen);
+
+ if (ls_mem->nhtype != SRV6_NHTYPE_NONE)
+ {
+ if (ls_mem->nhtype == SRV6_NHTYPE_IPV4)
+ s = format (s, ", NHType IPv4\n");
+ else if (ls_mem->nhtype == SRV6_NHTYPE_IPV6)
+ s = format (s, ", NHType IPv6\n");
+ else if (ls_mem->nhtype == SRV6_NHTYPE_NON_IP)
+ s = format (s, ", NHType Non-IP\n");
+ else
+ s = format (s, ", NHType Unknow(%d)\n", ls_mem->nhtype);
+ }
+ else
+ s = format (s, "\n");
+
+ return s;
+}
+
+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;
+ ip6_address_t sr_prefix;
+ u32 sr_prefixlen;
+ ip6_address_t v6src_prefix;
+ u32 v6src_prefixlen;
+ u8 nhtype;
+
+ 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))
+ {
+ 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;
+ }
+ else
+ {
+ return 0;
+ }
+
+ ls_mem = clib_mem_alloc_aligned_at_offset (sizeof *ls_mem, 0, 0, 1);
+ clib_memset (ls_mem, 0, sizeof *ls_mem);
+ *plugin_mem_p = ls_mem;
+
+ ls_mem->sr_prefix = sr_prefix;
+ ls_mem->sr_prefixlen = sr_prefixlen;
+
+ ls_mem->v6src_prefix = v6src_prefix;
+ ls_mem->v6src_prefixlen = v6src_prefixlen;
+
+ ls_mem->nhtype = nhtype;
+
+ return 1;
+}
+
+static int
+clb_creation_srv6_t_m_gtp4_d (ip6_sr_policy_t * sr_policy)
+{
+ return 0;
+}
+
+static int
+clb_removal_srv6_t_m_gtp4_d (ip6_sr_policy_t * sr_policy)
+{
+ srv6_end_gtp4_param_t *ls_mem;
+
+ ls_mem = (srv6_end_gtp4_param_t *) sr_policy->plugin_mem;
+
+ clib_mem_free (ls_mem);
+
+ return 0;
+}
+
+static clib_error_t *
+srv6_t_m_gtp4_d_init (vlib_main_t * vm)
+{
+ srv6_t_main_v4_decap_t *sm = &srv6_t_main_v4_decap;
+ ip6_header_t *ip6;
+ dpo_type_t dpo_type;
+ vlib_node_t *node;
+ u32 rc;
+
+ sm->vlib_main = vm;
+ sm->vnet_main = vnet_get_main ();
+
+ node = vlib_get_node_by_name (vm, (u8 *) "srv6-t-m-gtp4-d");
+ sm->t_m_gtp4_d_node_index = node->index;
+
+ node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
+ sm->error_node_index = node->index;
+
+ ip6 = &sm->cache_hdr;
+
+ clib_memset_u8 (ip6, 0, sizeof (ip6_header_t));
+
+ // IPv6 header (default)
+ ip6->ip_version_traffic_class_and_flow_label = 0x60;
+ ip6->hop_limit = 64;
+ ip6->protocol = IP_PROTOCOL_IPV6;
+
+ dpo_type = dpo_register_new_type (&dpo_vft, dpo_nodes);
+
+ rc = sr_policy_register_function (vm, fn_name, keyword_str, def_str, param_str, 128, //prefix len
+ &dpo_type,
+ clb_format_srv6_t_m_gtp4_d,
+ clb_unformat_srv6_t_m_gtp4_d,
+ clb_creation_srv6_t_m_gtp4_d,
+ clb_removal_srv6_t_m_gtp4_d);
+ if (rc < 0)
+ clib_error_return (0, "SRv6 Transit GTP4.D Policy function"
+ "couldn't be registered");
+ return 0;
+}
+
+/* *INDENT-OFF* */
+VNET_FEATURE_INIT (srv6_t_m_gtp4_d, static) =
+{
+ .arc_name = "ip4-unicast",
+ .node_name = "srv6-t-m-gtp4-d",
+ .runs_before = 0,
+};
+
+VLIB_INIT_FUNCTION (srv6_t_m_gtp4_d_init);
+/* *INDENT-ON* */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/plugins/srv6-mobile/mobile.h b/src/plugins/srv6-mobile/mobile.h
index 8be9dc2b944..f1de99a306e 100644
--- a/src/plugins/srv6-mobile/mobile.h
+++ b/src/plugins/srv6-mobile/mobile.h
@@ -37,6 +37,11 @@
#define IP_PROTOCOL_NONE 59
#endif
+#define SRV6_GTP6_UNKNOW 0
+#define SRV6_GTP6_DT4 1
+#define SRV6_GTP6_DT6 2
+#define SRV6_GTP6_DT46 3
+
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define BITALIGN2(A,B) A; B
#define BITALIGN3(A,B,C) A; B; C
@@ -175,19 +180,19 @@ typedef struct srv6_end_main_v4_s
} srv6_end_main_v4_t;
-typedef struct srv6_end_main_v4_decap_s
+typedef struct srv6_t_main_v4_decap_s
{
vlib_main_t *vlib_main;
vnet_main_t *vnet_main;
- u32 end_m_gtp4_d_node_index;
+ u32 t_m_gtp4_d_node_index;
u32 error_node_index;
ip6_header_t cache_hdr;
-} srv6_end_main_v4_decap_t;
+} srv6_t_main_v4_decap_t;
extern srv6_end_main_v4_t srv6_end_main_v4;
-extern srv6_end_main_v4_decap_t srv6_end_main_v4_decap;
+extern srv6_t_main_v4_decap_t srv6_t_main_v4_decap;
extern vlib_node_registration_t srv6_end_m_gtp4_e;
typedef struct srv6_end_main_v6_s
diff --git a/src/plugins/srv6-mobile/node.c b/src/plugins/srv6-mobile/node.c
index 0c2c04e612e..eb9a20e3c53 100644
--- a/src/plugins/srv6-mobile/node.c
+++ b/src/plugins/srv6-mobile/node.c
@@ -113,9 +113,9 @@ format_srv6_end_rewrite_trace6 (u8 * s, va_list * args)
_(M_GTP4_E_PACKETS, "srv6 End.M.GTP4.E packets") \
_(M_GTP4_E_BAD_PACKETS, "srv6 End.M.GTP4.E bad packets")
-#define foreach_srv6_end_v4_d_error \
- _(M_GTP4_D_PACKETS, "srv6 End.M.GTP4.D packets") \
- _(M_GTP4_D_BAD_PACKETS, "srv6 End.M.GTP4.D bad packets")
+#define foreach_srv6_t_v4_d_error \
+ _(M_GTP4_D_PACKETS, "srv6 T.M.GTP4.D packets") \
+ _(M_GTP4_D_BAD_PACKETS, "srv6 T.M.GTP4.D bad packets")
#define foreach_srv6_end_v6_e_error \
_(M_GTP6_E_PACKETS, "srv6 End.M.GTP6.E packets") \
@@ -129,6 +129,10 @@ format_srv6_end_rewrite_trace6 (u8 * s, va_list * args)
_(M_GTP6_D_DI_PACKETS, "srv6 End.M.GTP6.D.DI packets") \
_(M_GTP6_D_DI_BAD_PACKETS, "srv6 End.M.GTP6.D.DI bad packets")
+#define foreach_srv6_end_v6_dt_error \
+ _(M_GTP6_DT_PACKETS, "srv6 End.M.GTP6.DT packets") \
+ _(M_GTP6_DT_BAD_PACKETS, "srv6 End.M.GTP6.DT bad packets")
+
typedef enum
{
#define _(sym,str) SRV6_END_ERROR_##sym,
@@ -139,11 +143,11 @@ typedef enum
typedef enum
{
-#define _(sym,str) SRV6_END_ERROR_##sym,
- foreach_srv6_end_v4_d_error
+#define _(sym,str) SRV6_T_ERROR_##sym,
+ foreach_srv6_t_v4_d_error
#undef _
- SRV6_END_N_V4_D_ERROR,
-} srv6_end_error_v4_d_t;
+ SRV6_T_N_V4_D_ERROR,
+} srv6_t_error_v4_d_t;
typedef enum
{
@@ -169,12 +173,26 @@ typedef enum
SRV6_END_N_V6_D_DI_ERROR,
} srv6_end_error_v6_d_di_t;
+typedef enum
+{
+#define _(sym,str) SRV6_END_ERROR_##sym,
+ foreach_srv6_end_v6_dt_error
+#undef _
+ SRV6_END_N_V6_DT_ERROR,
+} srv6_end_error_v6_dt_t;
+
static char *srv6_end_error_v4_strings[] = {
#define _(sym,string) string,
foreach_srv6_end_v4_error
#undef _
};
+static char *srv6_t_error_v4_d_strings[] = {
+#define _(sym,string) string,
+ foreach_srv6_t_v4_d_error
+#undef _
+};
+
static char *srv6_end_error_v6_e_strings[] = {
#define _(sym,string) string,
foreach_srv6_end_v6_e_error
@@ -202,6 +220,13 @@ typedef enum
typedef enum
{
+ SRV6_T_M_GTP4_D_NEXT_DROP,
+ SRV6_T_M_GTP4_D_NEXT_LOOKUP,
+ SRV6_T_M_GTP4_D_N_NEXT,
+} srv6_T_m_gtp4_d_next_t;
+
+typedef enum
+{
SRV6_END_M_GTP6_E_NEXT_DROP,
SRV6_END_M_GTP6_E_NEXT_LOOKUP,
SRV6_END_M_GTP6_E_N_NEXT,
@@ -514,6 +539,419 @@ VLIB_NODE_FN (srv6_end_m_gtp4_e) (vlib_main_t * vm,
return frame->n_vectors;
}
+// Function for SRv6 GTP4.D function.
+VLIB_NODE_FN (srv6_t_m_gtp4_d) (vlib_main_t * vm,
+ vlib_node_runtime_t * node,
+ vlib_frame_t * frame)
+{
+ srv6_t_main_v4_decap_t *sm = &srv6_t_main_v4_decap;
+ ip6_sr_main_t *sm2 = &sr_main;
+ u32 n_left_from, next_index, *from, *to_next;
+
+ u32 good_n = 0, bad_n = 0;
+
+ from = vlib_frame_vector_args (frame);
+ n_left_from = frame->n_vectors;
+ next_index = node->cached_next_index;
+
+ while (n_left_from > 0)
+ {
+ u32 n_left_to_next;
+
+ vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
+
+ while (n_left_from > 0 && n_left_to_next > 0)
+ {
+ u32 bi0;
+ vlib_buffer_t *b0;
+ ip6_sr_sl_t *sl0;
+ srv6_end_gtp4_param_t *ls_param;
+ ip4_header_t *ip4;
+
+ uword len0;
+
+ u32 next0 = SRV6_T_M_GTP4_D_NEXT_LOOKUP;
+
+ // defaults
+ bi0 = from[0];
+ to_next[0] = bi0;
+ from += 1;
+ to_next += 1;
+ n_left_from -= 1;
+ n_left_to_next -= 1;
+
+ b0 = vlib_get_buffer (vm, bi0);
+
+ sl0 =
+ pool_elt_at_index (sm2->sid_lists,
+ vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
+
+ ls_param = (srv6_end_gtp4_param_t *) sl0->plugin_mem;
+
+ len0 = vlib_buffer_length_in_chain (vm, b0);
+
+ ip4 = vlib_buffer_get_current (b0);
+
+ if (ip4->protocol != IP_PROTOCOL_UDP
+ || len0 < sizeof (ip4_gtpu_header_t))
+ {
+ next0 = SRV6_T_M_GTP4_D_NEXT_DROP;
+
+ bad_n++;
+ }
+ else
+ {
+ uword *p;
+ ip6_sr_policy_t *sr_policy = NULL;
+ ip6_sr_sl_t *sl = NULL;
+ u32 *sl_index;
+ u32 hdr_len;
+
+ ip4_gtpu_header_t *hdr;
+ ip4_address_t src, dst;
+ u8 *srcp, *dstp;
+ ip6_header_t *encap = NULL;
+ ip6_address_t seg;
+ ip6_address_t src6;
+ u8 gtpu_type;
+ u32 teid;
+ u8 *teidp;
+ u8 qfi = 0;
+ u8 *qfip = NULL;
+ u32 offset, shift, index;
+ ip6srv_combo_header_t *ip6srv;
+ gtpu_pdu_session_t *sess = NULL;
+
+ // Decap from GTP-U.
+ hdr = (ip4_gtpu_header_t *) ip4;
+
+ hdr_len = sizeof (ip4_gtpu_header_t);
+
+ teid = hdr->gtpu.teid;
+ teidp = (u8 *) & teid;
+
+ gtpu_type = hdr->gtpu.type;
+
+ if (hdr->gtpu.ver_flags & GTPU_EXTHDR_FLAG)
+ {
+ // Extention header.
+ hdr_len += sizeof (gtpu_exthdr_t);
+ if (hdr->gtpu.ext->nextexthdr == GTPU_EXTHDR_PDU_SESSION)
+ {
+ // PDU Session Container.
+ sess =
+ (gtpu_pdu_session_t *) (((char *) hdr) + hdr_len);
+ qfi = sess->u.val & ~GTPU_PDU_SESSION_P_BIT_MASK;
+ qfip = (u8 *) & qfi;
+
+ hdr_len += sizeof (gtpu_pdu_session_t);
+
+ if (sess->u.val & GTPU_PDU_SESSION_P_BIT_MASK)
+ {
+ hdr_len += sizeof (gtpu_paging_policy_t);
+ }
+ }
+ }
+
+ src = hdr->ip4.src_address;
+ srcp = (u8 *) & src;
+
+ dst = hdr->ip4.dst_address;
+ dstp = (u8 *) & dst;
+
+ seg = ls_param->sr_prefix;
+
+ offset = ls_param->sr_prefixlen / 8;
+ shift = ls_param->sr_prefixlen % 8;
+
+ if (PREDICT_TRUE (shift == 0))
+ {
+ clib_memcpy_fast (&seg.as_u8[offset], dstp, 4);
+
+ if (qfip)
+ {
+ qfi =
+ ((qfi & GTPU_PDU_SESSION_QFI_MASK) << 2) |
+ ((qfi & GTPU_PDU_SESSION_R_BIT_MASK) >> 5);
+
+ if (sess->type)
+ {
+ qfi |= SRV6_PDU_SESSION_U_BIT_MASK;
+ }
+
+ seg.as_u8[offset + 4] = qfi;
+ }
+
+ clib_memcpy_fast (&seg.as_u8[offset + 5], teidp, 4);
+ }
+ else
+ {
+ for (index = 0; index < 4; index++)
+ {
+ seg.as_u8[offset + index] |= dstp[index] >> shift;
+ seg.as_u8[offset + index + 1] |=
+ dstp[index] << (8 - shift);
+
+ seg.as_u8[offset + index + 5] |= teidp[index] >> shift;
+ seg.as_u8[offset + index + 6] |=
+ teidp[index] << (8 - shift);
+ }
+
+ if (qfip)
+ {
+ qfi =
+ ((qfi & GTPU_PDU_SESSION_QFI_MASK) << 2) |
+ ((qfi & GTPU_PDU_SESSION_R_BIT_MASK) >> 5);
+
+ if (sess->type)
+ {
+ qfi |= SRV6_PDU_SESSION_U_BIT_MASK;
+ }
+
+ seg.as_u8[offset + 4] |= qfi >> shift;
+ seg.as_u8[offset + 5] |= qfi << (8 - shift);
+ }
+ }
+
+ src6 = ls_param->v6src_prefix;
+
+ offset = ls_param->v6src_prefixlen / 8;
+ shift = ls_param->v6src_prefixlen % 8;
+
+ if (PREDICT_TRUE (shift == 0))
+ {
+ clib_memcpy_fast (&src6.as_u8[offset], srcp, 4);
+ }
+ else
+ {
+ for (index = 0; index < 4; index++)
+ {
+ src6.as_u8[offset + index] |= srcp[offset] >> shift;
+ src6.as_u8[offset + index + 1] |=
+ srcp[offset] << (8 - shift);
+ }
+ }
+
+ vlib_buffer_advance (b0, (word) hdr_len);
+
+ // Encap to SRv6.
+ if (PREDICT_TRUE (gtpu_type == GTPU_TYPE_GTPU))
+ {
+ encap = vlib_buffer_get_current (b0);
+ }
+
+ len0 = vlib_buffer_length_in_chain (vm, b0);
+
+ p =
+ mhash_get (&sm2->sr_policies_index_hash,
+ &ls_param->sr_prefix);
+ if (p)
+ {
+ sr_policy = pool_elt_at_index (sm2->sr_policies, p[0]);
+ }
+
+ if (sr_policy)
+ {
+ vec_foreach (sl_index, sr_policy->segments_lists)
+ {
+ sl = pool_elt_at_index (sm2->sid_lists, *sl_index);
+ if (sl != NULL)
+ break;
+ }
+ }
+
+ if (sl)
+ {
+ hdr_len = sizeof (ip6srv_combo_header_t);
+ hdr_len += vec_len (sl->segments) * sizeof (ip6_address_t);
+ hdr_len += sizeof (ip6_address_t);
+ }
+ else
+ {
+ hdr_len = sizeof (ip6_header_t);
+
+ if (PREDICT_FALSE (gtpu_type != GTPU_TYPE_GTPU))
+ {
+ hdr_len += sizeof (ip6_sr_header_t);
+ hdr_len += sizeof (ip6_address_t);
+ }
+ }
+
+ vlib_buffer_advance (b0, -(word) hdr_len);
+ ip6srv = vlib_buffer_get_current (b0);
+
+ if (sl)
+ {
+ clib_memcpy_fast (ip6srv, sl->rewrite,
+ vec_len (sl->rewrite));
+
+ ip6srv->ip.protocol = IP_PROTOCOL_IPV6_ROUTE;
+
+ ip6srv->sr.tag =
+ clib_host_to_net_u16 (srh_tagfield[gtpu_type]);
+
+ ip6srv->sr.segments_left += 1;
+ ip6srv->sr.last_entry += 1;
+
+ ip6srv->sr.length += sizeof (ip6_address_t) / 8;
+ ip6srv->sr.segments[0] = seg;
+
+ if (PREDICT_TRUE (encap != NULL))
+ {
+ if (ls_param->nhtype == SRV6_NHTYPE_NONE)
+ {
+ if ((clib_net_to_host_u32
+ (encap->ip_version_traffic_class_and_flow_label)
+ >> 28) == 6)
+ ip6srv->sr.protocol = IP_PROTOCOL_IPV6;
+ else
+ ip6srv->sr.protocol = IP_PROTOCOL_IP_IN_IP;
+ }
+ else if (ls_param->nhtype == SRV6_NHTYPE_IPV4)
+ {
+ ip6srv->sr.protocol = IP_PROTOCOL_IP_IN_IP;
+ if ((clib_net_to_host_u32
+ (encap->ip_version_traffic_class_and_flow_label)
+ >> 28) != 4)
+ {
+ // Bad encap packet.
+ next0 = SRV6_T_M_GTP4_D_NEXT_DROP;
+ bad_n++;
+ goto DONE;
+ }
+ }
+ else if (ls_param->nhtype == SRV6_NHTYPE_IPV6)
+ {
+ ip6srv->sr.protocol = IP_PROTOCOL_IPV6;
+ if ((clib_net_to_host_u32
+ (encap->ip_version_traffic_class_and_flow_label)
+ >> 28) != 6)
+ {
+ // Bad encap packet.
+ next0 = SRV6_T_M_GTP4_D_NEXT_DROP;
+ bad_n++;
+ goto DONE;
+ }
+ }
+ else if (ls_param->nhtype == SRV6_NHTYPE_NON_IP)
+ {
+ ip6srv->sr.protocol = IP_PROTOCOL_NONE;
+ }
+ }
+ else
+ {
+ ip6srv->sr.protocol = IP_PROTOCOL_NONE;
+ }
+
+ clib_memcpy_fast (&ip6srv->sr.segments[1],
+ (u8 *) (sl->rewrite +
+ sizeof (ip6_header_t) +
+ sizeof (ip6_sr_header_t)),
+ vec_len (sl->segments) *
+ sizeof (ip6_address_t));
+ }
+ else
+ {
+ clib_memcpy_fast (ip6srv, &sm->cache_hdr,
+ sizeof (ip6_header_t));
+
+ ip6srv->ip.dst_address = seg;
+
+ if (PREDICT_FALSE (gtpu_type != GTPU_TYPE_GTPU))
+ {
+ ip6srv->ip.protocol = IP_PROTOCOL_IPV6_ROUTE;
+
+ ip6srv->sr.protocol = IP_PROTOCOL_NONE;
+
+ ip6srv->sr.tag =
+ clib_host_to_net_u16 (srh_tagfield[gtpu_type]);
+
+ ip6srv->sr.segments_left = 0;
+ ip6srv->sr.last_entry = 0;
+
+ ip6srv->sr.length = sizeof (ip6_address_t) / 8;
+ ip6srv->sr.segments[0] = seg;
+ }
+ else
+ {
+ if (ls_param->nhtype == SRV6_NHTYPE_NONE)
+ {
+ if ((clib_net_to_host_u32
+ (encap->ip_version_traffic_class_and_flow_label)
+ >> 28) == 6)
+ ip6srv->ip.protocol = IP_PROTOCOL_IPV6;
+ else
+ ip6srv->ip.protocol = IP_PROTOCOL_IP_IN_IP;
+ }
+ else if (ls_param->nhtype == SRV6_NHTYPE_IPV4)
+ {
+ ip6srv->ip.protocol = IP_PROTOCOL_IP_IN_IP;
+ if ((clib_net_to_host_u32
+ (encap->ip_version_traffic_class_and_flow_label)
+ >> 28) != 4)
+ {
+ // Bad encap packet.
+ next0 = SRV6_T_M_GTP4_D_NEXT_DROP;
+ bad_n++;
+ goto DONE;
+ }
+ }
+ else if (ls_param->nhtype == SRV6_NHTYPE_IPV6)
+ {
+ ip6srv->ip.protocol = IP_PROTOCOL_IPV6;
+ if ((clib_net_to_host_u32
+ (encap->ip_version_traffic_class_and_flow_label)
+ >> 28) != 6)
+ {
+ // Bad encap packet.
+ next0 = SRV6_T_M_GTP4_D_NEXT_DROP;
+ bad_n++;
+ goto DONE;
+ }
+ }
+ else if (ls_param->nhtype == SRV6_NHTYPE_NON_IP)
+ {
+ ip6srv->ip.protocol = IP_PROTOCOL_NONE;
+ }
+ }
+ }
+
+ ip6srv->ip.src_address = src6;
+
+ ip6srv->ip.payload_length =
+ clib_host_to_net_u16 (len0 + hdr_len - sizeof (ip6_header_t));
+
+ good_n++;
+
+ if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE) &&
+ PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ srv6_end_rewrite_trace_t *tr =
+ vlib_add_trace (vm, node, b0, sizeof (*tr));
+ clib_memcpy (tr->src.as_u8, ip6srv->ip.src_address.as_u8,
+ sizeof (tr->src.as_u8));
+ clib_memcpy (tr->dst.as_u8, ip6srv->ip.dst_address.as_u8,
+ sizeof (tr->dst.as_u8));
+ }
+ }
+
+ DONE:
+ vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
+ n_left_to_next, bi0, next0);
+ }
+
+ vlib_put_next_frame (vm, node, next_index, n_left_to_next);
+ }
+
+ vlib_node_increment_counter (vm, sm->t_m_gtp4_d_node_index,
+ SRV6_T_ERROR_M_GTP4_D_BAD_PACKETS, bad_n);
+
+ vlib_node_increment_counter (vm, sm->t_m_gtp4_d_node_index,
+ SRV6_T_ERROR_M_GTP4_D_PACKETS, good_n);
+
+ return frame->n_vectors;
+}
+
VLIB_REGISTER_NODE (srv6_end_m_gtp4_e) =
{
.name = "srv6-end-m-gtp4-e",.vector_size = sizeof (u32),.format_trace =
@@ -522,8 +960,20 @@ VLIB_REGISTER_NODE (srv6_end_m_gtp4_e) =
srv6_end_error_v4_strings,.n_next_nodes =
SRV6_END_M_GTP4_E_N_NEXT,.next_nodes =
{
- [SRV6_END_M_GTP4_E_NEXT_DROP] =
- "error-drop",[SRV6_END_M_GTP4_E_NEXT_LOOKUP] = "ip4-lookup",}
+ [SRV6_END_M_GTP4_E_NEXT_DROP] = "error-drop",
+ [SRV6_END_M_GTP4_E_NEXT_LOOKUP] = "ip4-lookup",}
+,};
+
+VLIB_REGISTER_NODE (srv6_t_m_gtp4_d) =
+{
+ .name = "srv6-t-m-gtp4-d",.vector_size = sizeof (u32),.format_trace =
+ format_srv6_end_rewrite_trace,.type = VLIB_NODE_TYPE_INTERNAL,.n_errors =
+ ARRAY_LEN (srv6_t_error_v4_d_strings),.error_strings =
+ srv6_t_error_v4_d_strings,.n_next_nodes =
+ SRV6_T_M_GTP4_D_N_NEXT,.next_nodes =
+ {
+ [SRV6_T_M_GTP4_D_NEXT_DROP] = "error-drop",
+ [SRV6_T_M_GTP4_D_NEXT_LOOKUP] = "ip6-lookup",}
,};
// Function for SRv6 GTP6.E function
@@ -1496,8 +1946,8 @@ VLIB_REGISTER_NODE (srv6_end_m_gtp6_e) =
srv6_end_error_v6_e_strings,.n_next_nodes =
SRV6_END_M_GTP6_E_N_NEXT,.next_nodes =
{
- [SRV6_END_M_GTP6_E_NEXT_DROP] =
- "error-drop",[SRV6_END_M_GTP6_E_NEXT_LOOKUP] = "ip6-lookup",}
+ [SRV6_END_M_GTP6_E_NEXT_DROP] = "error-drop",
+ [SRV6_END_M_GTP6_E_NEXT_LOOKUP] = "ip6-lookup",}
,};
VLIB_REGISTER_NODE (srv6_end_m_gtp6_d) =
@@ -1508,8 +1958,8 @@ VLIB_REGISTER_NODE (srv6_end_m_gtp6_d) =
srv6_end_error_v6_d_strings,.n_next_nodes =
SRV6_END_M_GTP6_D_N_NEXT,.next_nodes =
{
- [SRV6_END_M_GTP6_D_NEXT_DROP] =
- "error-drop",[SRV6_END_M_GTP6_D_NEXT_LOOKUP] = "ip6-lookup",}
+ [SRV6_END_M_GTP6_D_NEXT_DROP] = "error-drop",
+ [SRV6_END_M_GTP6_D_NEXT_LOOKUP] = "ip6-lookup",}
,};
VLIB_REGISTER_NODE (srv6_end_m_gtp6_d_di) =
diff --git a/src/plugins/srv6-mobile/test/test_srv6_end.py b/src/plugins/srv6-mobile/test/test_srv6_end.py
index 4e2a5765bab..9eb62c9ce33 100644
--- a/src/plugins/srv6-mobile/test/test_srv6_end.py
+++ b/src/plugins/srv6-mobile/test/test_srv6_end.py
@@ -59,8 +59,7 @@ class TestSRv6EndMGTP4E(VppTestCase):
IPv6ExtHdrSegmentRouting() /
IPv6(dst=d, src=s) /
UDP(sport=1000, dport=23))
-
- self.logger.info(pkt.show2())
+ self.logger.info(pkt.show2(dump=True))
pkts.append(pkt)
return pkts
@@ -86,7 +85,7 @@ class TestSRv6EndMGTP4E(VppTestCase):
capture = self.pg1.get_capture(len(pkts))
for pkt in capture:
- self.logger.info(pkt.show2())
+ self.logger.info(pkt.show2(dump=True))
self.assertEqual(pkt[IP].dst, self.ip4_dst)
self.assertEqual(pkt[IP].src, self.ip4_src)
self.assertEqual(pkt[GTP_U_Header].teid, 0xbbbbbbbb)