diff options
Diffstat (limited to 'src/plugins/srv6-mobile/gtp6_d.c')
-rw-r--r-- | src/plugins/srv6-mobile/gtp6_d.c | 142 |
1 files changed, 102 insertions, 40 deletions
diff --git a/src/plugins/srv6-mobile/gtp6_d.c b/src/plugins/srv6-mobile/gtp6_d.c index c62320b33fd..ef831ba750c 100644 --- a/src/plugins/srv6-mobile/gtp6_d.c +++ b/src/plugins/srv6-mobile/gtp6_d.c @@ -61,12 +61,13 @@ static u8 fn_name[] = "SRv6-End.M.GTP6.D-plugin"; static u8 keyword_str[] = "end.m.gtp6.d"; static u8 def_str[] = "Endpoint function with dencapsulation for IPv6/GTP tunnel"; -static u8 param_str[] = "<sr-prefix>/<sr-prefixlen> [nhtype <nhtype>]"; +static u8 param_str[] = + "<sr-prefix>/<sr-prefixlen> [nhtype <nhtype>] fib-table <id>"; static u8 * clb_format_srv6_end_m_gtp6_d (u8 * s, va_list * args) { - srv6_end_gtp6_param_t *ls_mem = va_arg (*args, void *); + srv6_end_gtp6_d_param_t *ls_mem = va_arg (*args, void *); s = format (s, "SRv6 End gtp6.d\n\t"); @@ -77,62 +78,98 @@ clb_format_srv6_end_m_gtp6_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", ls_mem->drop_in); return s; } +void +alloc_param_srv6_end_m_gtp6_d (void **plugin_mem_p, const void *sr_prefix, + const u32 sr_prefixlen, const u8 nhtype, + const bool drop_in, const u32 fib_table) +{ + srv6_end_gtp6_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->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_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); +} + static uword clb_unformat_srv6_end_m_gtp6_d (unformat_input_t * input, va_list * args) { void **plugin_mem_p = va_arg (*args, void **); - srv6_end_gtp6_param_t *ls_mem; ip6_address_t sr_prefix; u32 sr_prefixlen; - u8 nhtype; + u8 nhtype = SRV6_NHTYPE_NONE; + bool drop_in = false; + bool config = false; + u32 fib_table = 0; - if (unformat (input, "end.m.gtp6.d %U/%d nh-type ipv4", - unformat_ip6_address, &sr_prefix, &sr_prefixlen)) + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { - nhtype = SRV6_NHTYPE_IPV4; - } - else if (unformat (input, "end.m.gtp6.d %U/%d nh-type ipv6", - unformat_ip6_address, &sr_prefix, &sr_prefixlen)) - { - nhtype = SRV6_NHTYPE_IPV6; - } - else if (unformat (input, "end.m.gtp6.d %U/%d nh-type none", - unformat_ip6_address, &sr_prefix, &sr_prefixlen)) - { - nhtype = SRV6_NHTYPE_NON_IP; - } - else if (unformat (input, "end.m.gtp6.d %U/%d", - unformat_ip6_address, &sr_prefix, &sr_prefixlen)) - { - nhtype = SRV6_NHTYPE_NONE; + if (unformat (input, "end.m.gtp6.d %U/%d nh-type ipv4 fib-table %d", + unformat_ip6_address, &sr_prefix, &sr_prefixlen, + &fib_table)) + { + config = true; + nhtype = SRV6_NHTYPE_IPV4; + } + else if (unformat (input, "end.m.gtp6.d %U/%d nh-type ipv6 fib-table %d", + unformat_ip6_address, &sr_prefix, &sr_prefixlen, + &fib_table)) + { + config = true; + nhtype = SRV6_NHTYPE_IPV6; + } + else if (unformat (input, "end.m.gtp6.d %U/%d nh-type none", + unformat_ip6_address, &sr_prefix, &sr_prefixlen)) + { + config = true; + nhtype = SRV6_NHTYPE_NON_IP; + } + else if (unformat (input, "end.m.gtp6.d %U/%d fib-table %d", + unformat_ip6_address, &sr_prefix, &sr_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->nhtype = nhtype; + alloc_param_srv6_end_m_gtp6_d (plugin_mem_p, &sr_prefix, sr_prefixlen, + nhtype, drop_in, fib_table); return 1; } @@ -144,9 +181,15 @@ clb_creation_srv6_end_m_gtp6_d (ip6_sr_localsid_t * localsid) } static int +clb_creation_srv6_end_m_gtp6_d_2 (ip6_sr_policy_t *sr_policy) +{ + return 0; +} + +static int clb_removal_srv6_end_m_gtp6_d (ip6_sr_localsid_t * localsid) { - srv6_end_gtp6_param_t *ls_mem; + srv6_end_gtp6_d_param_t *ls_mem; ls_mem = localsid->plugin_mem; @@ -155,6 +198,18 @@ clb_removal_srv6_end_m_gtp6_d (ip6_sr_localsid_t * localsid) return 0; } +static int +clb_removal_srv6_end_m_gtp6_d_2 (ip6_sr_policy_t *sr_policy) +{ + srv6_end_gtp6_d_param_t *ls_mem; + + ls_mem = sr_policy->plugin_mem; + + clib_mem_free (ls_mem); + + return 0; +} + static clib_error_t * srv6_end_m_gtp6_d_init (vlib_main_t * vm) { @@ -193,10 +248,18 @@ srv6_end_m_gtp6_d_init (vlib_main_t * vm) if (rc < 0) clib_error_return (0, "SRv6 Endpoint GTP6.D LocalSID function" "couldn't be registered"); + + rc = sr_policy_register_function ( + vm, fn_name, keyword_str, def_str, param_str, 128, // prefix len + &dpo_type, clb_format_srv6_end_m_gtp6_d, clb_unformat_srv6_end_m_gtp6_d, + clb_creation_srv6_end_m_gtp6_d_2, clb_removal_srv6_end_m_gtp6_d_2); + if (rc < 0) + clib_error_return (0, "SRv6 GTP6.D Steering function" + "couldn't be registered"); + return 0; } -/* *INDENT-OFF* */ VNET_FEATURE_INIT (srv6_end_m_gtp6_d, static) = { .arc_name = "ip6-unicast", @@ -205,7 +268,6 @@ VNET_FEATURE_INIT (srv6_end_m_gtp6_d, static) = }; VLIB_INIT_FUNCTION (srv6_end_m_gtp6_d_init); -/* *INDENT-ON* */ /* * fd.io coding-style-patch-verification: ON |