LCOV - code coverage report
Current view: top level - plugins/srv6-mobile - gtp6_d.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 62 93 66.7 %
Date: 2023-07-05 22:20:52 Functions: 10 14 71.4 %

          Line data    Source code
       1             : /*
       2             :  * srv6_end_m_gtp6_d.c
       3             :  *
       4             :  * Copyright (c) 2019 Arrcus Inc and/or its affiliates.
       5             :  * Licensed under the Apache License, Version 2.0 (the "License");
       6             :  * you may not use this file except in compliance with the License.
       7             :  * You may obtain a copy of the License at:
       8             :  *
       9             :  *     http://www.apache.org/licenses/LICENSE-2.0
      10             :  *
      11             :  * Unless required by applicable law or agreed to in writing, software
      12             :  * distributed under the License is distributed on an "AS IS" BASIS,
      13             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      14             :  * See the License for the specific language governing permissions and
      15             :  * limitations under the License.
      16             :  */
      17             : 
      18             : #include <vnet/vnet.h>
      19             : #include <vnet/adj/adj.h>
      20             : #include <vnet/plugin/plugin.h>
      21             : #include <vpp/app/version.h>
      22             : #include <srv6-mobile/mobile.h>
      23             : 
      24             : srv6_end_main_v6_decap_t srv6_end_main_v6_decap;
      25             : 
      26             : static void
      27           6 : clb_dpo_lock_srv6_end_m_gtp6_d (dpo_id_t * dpo)
      28             : {
      29           6 : }
      30             : 
      31             : static void
      32           3 : clb_dpo_unlock_srv6_end_m_gtp6_d (dpo_id_t * dpo)
      33             : {
      34           3 : }
      35             : 
      36             : static u8 *
      37           0 : clb_dpo_format_srv6_end_m_gtp6_d (u8 * s, va_list * args)
      38             : {
      39           0 :   index_t index = va_arg (*args, index_t);
      40           0 :   CLIB_UNUSED (u32 indent) = va_arg (*args, u32);
      41             : 
      42           0 :   return (format (s, "SR: dynamic_proxy_index:[%u]", index));
      43             : }
      44             : 
      45             : const static dpo_vft_t dpo_vft = {
      46             :   .dv_lock = clb_dpo_lock_srv6_end_m_gtp6_d,
      47             :   .dv_unlock = clb_dpo_unlock_srv6_end_m_gtp6_d,
      48             :   .dv_format = clb_dpo_format_srv6_end_m_gtp6_d,
      49             : };
      50             : 
      51             : const static char *const srv6_end_m_gtp6_d_nodes[] = {
      52             :   "srv6-end-m-gtp6-d",
      53             :   NULL,
      54             : };
      55             : 
      56             : const static char *const *const dpo_nodes[DPO_PROTO_NUM] = {
      57             :   [DPO_PROTO_IP6] = srv6_end_m_gtp6_d_nodes,
      58             : };
      59             : 
      60             : static u8 fn_name[] = "SRv6-End.M.GTP6.D-plugin";
      61             : static u8 keyword_str[] = "end.m.gtp6.d";
      62             : static u8 def_str[] =
      63             :   "Endpoint function with dencapsulation for IPv6/GTP tunnel";
      64             : static u8 param_str[] =
      65             :   "<sr-prefix>/<sr-prefixlen> [nhtype <nhtype>] fib-table <id>";
      66             : 
      67             : static u8 *
      68           1 : clb_format_srv6_end_m_gtp6_d (u8 * s, va_list * args)
      69             : {
      70           1 :   srv6_end_gtp6_d_param_t *ls_mem = va_arg (*args, void *);
      71             : 
      72           1 :   s = format (s, "SRv6 End gtp6.d\n\t");
      73             : 
      74             :   s =
      75           1 :     format (s, "SR Prefix: %U/%d", format_ip6_address, &ls_mem->sr_prefix,
      76             :             ls_mem->sr_prefixlen);
      77             : 
      78           1 :   if (ls_mem->nhtype != SRV6_NHTYPE_NONE)
      79             :     {
      80           0 :       if (ls_mem->nhtype == SRV6_NHTYPE_IPV4)
      81           0 :         s = format (s, ", NHType IPv4");
      82           0 :       else if (ls_mem->nhtype == SRV6_NHTYPE_IPV6)
      83           0 :         s = format (s, ", NHType IPv6");
      84           0 :       else if (ls_mem->nhtype == SRV6_NHTYPE_NON_IP)
      85           0 :         s = format (s, ", NHType Non-IP");
      86             :       else
      87           0 :         s = format (s, ", NHType Unknow(%d)", ls_mem->nhtype);
      88             :     }
      89             : 
      90           1 :   s = format (s, " FIB table %d", ls_mem->fib_table);
      91             : 
      92           1 :   s = format (s, " Drop In %d", ls_mem->drop_in);
      93             : 
      94           1 :   return s;
      95             : }
      96             : 
      97             : static uword
      98           1 : clb_unformat_srv6_end_m_gtp6_d (unformat_input_t * input, va_list * args)
      99             : {
     100           1 :   void **plugin_mem_p = va_arg (*args, void **);
     101             :   srv6_end_gtp6_d_param_t *ls_mem;
     102             :   ip6_address_t sr_prefix;
     103             :   u32 sr_prefixlen;
     104           1 :   u8 nhtype = SRV6_NHTYPE_NONE;
     105           1 :   bool drop_in = false;
     106           1 :   bool config = false;
     107           1 :   u32 fib_table = 0;
     108             : 
     109           3 :   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
     110             :     {
     111           2 :       if (unformat (input, "end.m.gtp6.d %U/%d nh-type ipv4 fib-table %d",
     112             :                     unformat_ip6_address, &sr_prefix, &sr_prefixlen,
     113             :                     &fib_table))
     114             :         {
     115           0 :           config = true;
     116           0 :           nhtype = SRV6_NHTYPE_IPV4;
     117             :         }
     118           2 :       else if (unformat (input, "end.m.gtp6.d %U/%d nh-type ipv6 fib-table %d",
     119             :                          unformat_ip6_address, &sr_prefix, &sr_prefixlen,
     120             :                          &fib_table))
     121             :         {
     122           0 :           config = true;
     123           0 :           nhtype = SRV6_NHTYPE_IPV6;
     124             :         }
     125           2 :       else if (unformat (input, "end.m.gtp6.d %U/%d nh-type none",
     126             :                          unformat_ip6_address, &sr_prefix, &sr_prefixlen))
     127             :         {
     128           0 :           config = true;
     129           0 :           nhtype = SRV6_NHTYPE_NON_IP;
     130             :         }
     131           2 :       else if (unformat (input, "end.m.gtp6.d %U/%d fib-table %d",
     132             :                          unformat_ip6_address, &sr_prefix, &sr_prefixlen,
     133             :                          &fib_table))
     134             :         {
     135           1 :           config = true;
     136           1 :           nhtype = SRV6_NHTYPE_NONE;
     137             :         }
     138           1 :       else if (unformat (input, "drop-in"))
     139             :         {
     140           1 :           drop_in = true;
     141             :         }
     142             :       else
     143             :         {
     144           0 :           return 0;
     145             :         }
     146             :     }
     147             : 
     148           1 :   if (!config)
     149             :     {
     150           0 :       return 0;
     151             :     }
     152             : 
     153           1 :   ls_mem = clib_mem_alloc (sizeof *ls_mem);
     154           1 :   clib_memset (ls_mem, 0, sizeof *ls_mem);
     155           1 :   *plugin_mem_p = ls_mem;
     156             : 
     157           1 :   ls_mem->sr_prefix = sr_prefix;
     158           1 :   ls_mem->sr_prefixlen = sr_prefixlen;
     159             : 
     160           1 :   ls_mem->nhtype = nhtype;
     161             : 
     162           1 :   ls_mem->drop_in = drop_in;
     163             : 
     164           1 :   ls_mem->fib_table = fib_table;
     165           1 :   ls_mem->fib4_index = ip4_fib_index_from_table_id (fib_table);
     166           1 :   ls_mem->fib6_index = ip6_fib_index_from_table_id (fib_table);
     167             : 
     168           1 :   return 1;
     169             : }
     170             : 
     171             : static int
     172           1 : clb_creation_srv6_end_m_gtp6_d (ip6_sr_localsid_t * localsid)
     173             : {
     174           1 :   return 0;
     175             : }
     176             : 
     177             : static int
     178           0 : clb_creation_srv6_end_m_gtp6_d_2 (ip6_sr_policy_t *sr_policy)
     179             : {
     180           0 :   return 0;
     181             : }
     182             : 
     183             : static int
     184           0 : clb_removal_srv6_end_m_gtp6_d (ip6_sr_localsid_t * localsid)
     185             : {
     186             :   srv6_end_gtp6_d_param_t *ls_mem;
     187             : 
     188           0 :   ls_mem = localsid->plugin_mem;
     189             : 
     190           0 :   clib_mem_free (ls_mem);
     191             : 
     192           0 :   return 0;
     193             : }
     194             : 
     195             : static int
     196           0 : clb_removal_srv6_end_m_gtp6_d_2 (ip6_sr_policy_t *sr_policy)
     197             : {
     198             :   srv6_end_gtp6_d_param_t *ls_mem;
     199             : 
     200           0 :   ls_mem = sr_policy->plugin_mem;
     201             : 
     202           0 :   clib_mem_free (ls_mem);
     203             : 
     204           0 :   return 0;
     205             : }
     206             : 
     207             : static clib_error_t *
     208         559 : srv6_end_m_gtp6_d_init (vlib_main_t * vm)
     209             : {
     210         559 :   srv6_end_main_v6_decap_t *sm = &srv6_end_main_v6_decap;
     211             :   ip6_header_t *ip6;
     212             :   dpo_type_t dpo_type;
     213             :   vlib_node_t *node;
     214             :   int rc;
     215             : 
     216         559 :   sm->vlib_main = vm;
     217         559 :   sm->vnet_main = vnet_get_main ();
     218             : 
     219         559 :   node = vlib_get_node_by_name (vm, (u8 *) "srv6-end-m-gtp6-d");
     220         559 :   sm->end_m_gtp6_d_node_index = node->index;
     221             : 
     222         559 :   node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
     223         559 :   sm->error_node_index = node->index;
     224             : 
     225         559 :   ip6 = &sm->cache_hdr;
     226             : 
     227         559 :   clib_memset_u8 (ip6, 0, sizeof (ip6_header_t));
     228             : 
     229             :   // IPv6 header (default)
     230         559 :   ip6->ip_version_traffic_class_and_flow_label = 0x60;
     231         559 :   ip6->hop_limit = 64;
     232         559 :   ip6->protocol = IP_PROTOCOL_IPV6;
     233             : 
     234         559 :   dpo_type = dpo_register_new_type (&dpo_vft, dpo_nodes);
     235             : 
     236         559 :   rc = sr_localsid_register_function (vm, fn_name, keyword_str, def_str, param_str, 128,        //prefix len
     237             :                                       &dpo_type,
     238             :                                       clb_format_srv6_end_m_gtp6_d,
     239             :                                       clb_unformat_srv6_end_m_gtp6_d,
     240             :                                       clb_creation_srv6_end_m_gtp6_d,
     241             :                                       clb_removal_srv6_end_m_gtp6_d);
     242         559 :   if (rc < 0)
     243           0 :     clib_error_return (0, "SRv6 Endpoint GTP6.D LocalSID function"
     244             :                        "couldn't be registered");
     245             : 
     246         559 :   rc = sr_policy_register_function (
     247             :     vm, fn_name, keyword_str, def_str, param_str, 128, // prefix len
     248             :     &dpo_type, clb_format_srv6_end_m_gtp6_d, clb_unformat_srv6_end_m_gtp6_d,
     249             :     clb_creation_srv6_end_m_gtp6_d_2, clb_removal_srv6_end_m_gtp6_d_2);
     250         559 :   if (rc < 0)
     251           0 :     clib_error_return (0, "SRv6 GTP6.D Steering function"
     252             :                           "couldn't be registered");
     253             : 
     254         559 :   return 0;
     255             : }
     256             : 
     257             : /* *INDENT-OFF* */
     258       11759 : VNET_FEATURE_INIT (srv6_end_m_gtp6_d, static) =
     259             : {
     260             :   .arc_name = "ip6-unicast",
     261             :   .node_name = "srv6-end-m-gtp6-d",
     262             :   .runs_before = 0,
     263             : };
     264             : 
     265        2799 : VLIB_INIT_FUNCTION (srv6_end_m_gtp6_d_init);
     266             : /* *INDENT-ON* */
     267             : 
     268             : /*
     269             :  * fd.io coding-style-patch-verification: ON
     270             :  *
     271             :  * Local Variables:
     272             :  * eval: (c-set-style "gnu")
     273             :  * End:
     274             :  */

Generated by: LCOV version 1.14