diff options
Diffstat (limited to 'src/plugins/srv6-mobile/gtp4_d.c')
-rw-r--r-- | src/plugins/srv6-mobile/gtp4_d.c | 142 |
1 files changed, 90 insertions, 52 deletions
diff --git a/src/plugins/srv6-mobile/gtp4_d.c b/src/plugins/srv6-mobile/gtp4_d.c index 7bafa560810..f519b4840cc 100644 --- a/src/plugins/srv6-mobile/gtp4_d.c +++ b/src/plugins/srv6-mobile/gtp4_d.c @@ -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,75 +89,114 @@ 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; } +void +alloc_param_srv6_t_m_gtp4_d (void **plugin_mem_p, const void *v6src_prefix, + const u32 v6src_prefixlen, const void *sr_prefix, + const u32 sr_prefixlen, const u32 fib_index, + const u8 nhtype, const bool drop_in) +{ + srv6_end_gtp4_d_param_t *ls_mem; + ls_mem = clib_mem_alloc (sizeof *ls_mem); + clib_memset (ls_mem, 0, sizeof *ls_mem); + *plugin_mem_p = ls_mem; + + ls_mem->v6src_prefixlen = v6src_prefixlen; + memcpy (&ls_mem->v6src_prefix, v6src_prefix, sizeof (ip6_address_t)); + ls_mem->sr_prefixlen = sr_prefixlen; + memcpy (&ls_mem->sr_prefix, sr_prefix, sizeof (ip6_address_t)); + + ls_mem->nhtype = nhtype; + ls_mem->drop_in = drop_in; + ls_mem->fib_table = fib_index; + ls_mem->fib4_index = ip4_fib_index_from_table_id (fib_index); + ls_mem->fib6_index = ip6_fib_index_from_table_id (fib_index); +} + 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; + 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)) + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { - 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; + 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; } - 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; + alloc_param_srv6_t_m_gtp4_d (plugin_mem_p, &v6src_prefix, v6src_prefixlen, + &sr_prefix, sr_prefixlen, fib_table, nhtype, + drop_in); return 1; } @@ -170,9 +210,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); @@ -220,7 +260,6 @@ srv6_t_m_gtp4_d_init (vlib_main_t * vm) return 0; } -/* *INDENT-OFF* */ VNET_FEATURE_INIT (srv6_t_m_gtp4_d, static) = { .arc_name = "ip4-unicast", @@ -229,7 +268,6 @@ VNET_FEATURE_INIT (srv6_t_m_gtp4_d, static) = }; VLIB_INIT_FUNCTION (srv6_t_m_gtp4_d_init); -/* *INDENT-ON* */ /* * fd.io coding-style-patch-verification: ON |