LCOV - code coverage report
Current view: top level - plugins/srv6-mobile - gtp4_d.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 54 87 62.1 %
Date: 2023-10-26 01:39:38 Functions: 9 12 75.0 %

          Line data    Source code
       1             : /*
       2             :  * srv6_t_m_gtp4_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_t_main_v4_decap_t srv6_t_main_v4_decap;
      25             : 
      26             : static void
      27           9 : clb_dpo_lock_srv6_t_m_gtp4_d (dpo_id_t * dpo)
      28             : {
      29           9 : }
      30             : 
      31             : static void
      32           6 : clb_dpo_unlock_srv6_t_m_gtp4_d (dpo_id_t * dpo)
      33             : {
      34           6 : }
      35             : 
      36             : static u8 *
      37           0 : clb_dpo_format_srv6_t_m_gtp4_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_t_m_gtp4_d,
      47             :   .dv_unlock = clb_dpo_unlock_srv6_t_m_gtp4_d,
      48             :   .dv_format = clb_dpo_format_srv6_t_m_gtp4_d,
      49             : };
      50             : 
      51             : const static char *const srv6_t_m_gtp4_d_nodes[] = {
      52             :   "srv6-t-m-gtp4-d",
      53             :   NULL,
      54             : };
      55             : 
      56             : const static char *const srv6_t_m_gtp4_d_v6_nodes[] = {
      57             :   "error-drop",
      58             :   NULL,
      59             : };
      60             : 
      61             : const static char *const *const dpo_nodes[DPO_PROTO_NUM] = {
      62             :   [DPO_PROTO_IP6] = srv6_t_m_gtp4_d_v6_nodes,
      63             :   [DPO_PROTO_IP4] = srv6_t_m_gtp4_d_nodes,
      64             : };
      65             : 
      66             : static u8 fn_name[] = "SRv6-T.M.GTP4.D-plugin";
      67             : static u8 keyword_str[] = "t.m.gtp4.d";
      68             : static u8 def_str[] =
      69             :   "Transit function with decapsulation for IPv4/GTP tunnel";
      70             : static u8 param_str[] =
      71             :   "<sr-prefix>/<sr-prefixlen> v6src_prefix <v6src_prefix>/<prefixlen> [nhtype "
      72             :   "<nhtype>] fib-table <id>";
      73             : 
      74             : static u8 *
      75           0 : clb_format_srv6_t_m_gtp4_d (u8 * s, va_list * args)
      76             : {
      77           0 :   srv6_end_gtp4_d_param_t *ls_mem = va_arg (*args, void *);
      78             : 
      79           0 :   s = format (s, "SRv6 T.M.GTP4.D\n\t");
      80             : 
      81             :   s =
      82           0 :     format (s, "SR Prefix: %U/%d, ", format_ip6_address, &ls_mem->sr_prefix,
      83             :             ls_mem->sr_prefixlen);
      84             : 
      85             :   s =
      86           0 :     format (s, "v6src Prefix: %U/%d", format_ip6_address,
      87             :             &ls_mem->v6src_prefix, ls_mem->v6src_prefixlen);
      88             : 
      89           0 :   if (ls_mem->nhtype != SRV6_NHTYPE_NONE)
      90             :     {
      91           0 :       if (ls_mem->nhtype == SRV6_NHTYPE_IPV4)
      92           0 :         s = format (s, ", NHType IPv4");
      93           0 :       else if (ls_mem->nhtype == SRV6_NHTYPE_IPV6)
      94           0 :         s = format (s, ", NHType IPv6");
      95           0 :       else if (ls_mem->nhtype == SRV6_NHTYPE_NON_IP)
      96           0 :         s = format (s, ", NHType Non-IP");
      97             :       else
      98           0 :         s = format (s, ", NHType Unknow(%d)", ls_mem->nhtype);
      99             :     }
     100             : 
     101           0 :   s = format (s, ", FIB table %d", ls_mem->fib_table);
     102             : 
     103           0 :   s = format (s, ", Drop In %d\n", ls_mem->drop_in);
     104             : 
     105           0 :   return s;
     106             : }
     107             : 
     108             : static uword
     109           1 : clb_unformat_srv6_t_m_gtp4_d (unformat_input_t * input, va_list * args)
     110             : {
     111           1 :   void **plugin_mem_p = va_arg (*args, void **);
     112             :   srv6_end_gtp4_d_param_t *ls_mem;
     113             :   ip6_address_t sr_prefix;
     114             :   u32 sr_prefixlen;
     115             :   ip6_address_t v6src_prefix;
     116             :   u32 v6src_prefixlen;
     117           1 :   u32 fib_table = 0;
     118           1 :   bool drop_in = false;
     119           1 :   u8 nhtype = SRV6_NHTYPE_NONE;
     120           1 :   bool config = false;
     121             : 
     122           3 :   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
     123             :     {
     124           2 :       if (unformat (
     125             :             input,
     126             :             "t.m.gtp4.d %U/%d v6src_prefix %U/%d nhtype ipv4 fib-table %d",
     127             :             unformat_ip6_address, &sr_prefix, &sr_prefixlen,
     128             :             unformat_ip6_address, &v6src_prefix, &v6src_prefixlen, &fib_table))
     129             :         {
     130           0 :           config = true;
     131           0 :           nhtype = SRV6_NHTYPE_IPV4;
     132             :         }
     133           2 :       else if (unformat (input,
     134             :                          "t.m.gtp4.d %U/%d v6src_prefix %U/%d nhtype ipv6 "
     135             :                          "fib-table %d",
     136             :                          unformat_ip6_address, &sr_prefix, &sr_prefixlen,
     137             :                          unformat_ip6_address, &v6src_prefix, &v6src_prefixlen,
     138             :                          &fib_table))
     139             :         {
     140           1 :           config = true;
     141           1 :           nhtype = SRV6_NHTYPE_IPV6;
     142             :         }
     143           1 :       else if (unformat (
     144             :                  input, "t.m.gtp4.d %U/%d v6src_prefix %U/%d nhtype non-ip",
     145             :                  unformat_ip6_address, &sr_prefix, &sr_prefixlen,
     146             :                  unformat_ip6_address, &v6src_prefix, &v6src_prefixlen))
     147             :         {
     148           0 :           config = true;
     149           0 :           nhtype = SRV6_NHTYPE_NON_IP;
     150             :         }
     151           1 :       else if (unformat (input,
     152             :                          "t.m.gtp4.d %U/%d v6src_prefix %U/%d fib-table %d",
     153             :                          unformat_ip6_address, &sr_prefix, &sr_prefixlen,
     154             :                          unformat_ip6_address, &v6src_prefix, &v6src_prefixlen,
     155             :                          &fib_table))
     156             :         {
     157           0 :           config = true;
     158           0 :           nhtype = SRV6_NHTYPE_NONE;
     159             :         }
     160           1 :       else if (unformat (input, "drop-in"))
     161             :         {
     162           1 :           drop_in = true;
     163             :         }
     164             :       else
     165             :         {
     166           0 :           return 0;
     167             :         }
     168             :     }
     169             : 
     170           1 :   if (!config)
     171             :     {
     172           0 :       return 0;
     173             :     }
     174             : 
     175           1 :   ls_mem = clib_mem_alloc (sizeof *ls_mem);
     176           1 :   clib_memset (ls_mem, 0, sizeof *ls_mem);
     177           1 :   *plugin_mem_p = ls_mem;
     178             : 
     179           1 :   ls_mem->sr_prefix = sr_prefix;
     180           1 :   ls_mem->sr_prefixlen = sr_prefixlen;
     181             : 
     182           1 :   ls_mem->v6src_prefix = v6src_prefix;
     183           1 :   ls_mem->v6src_prefixlen = v6src_prefixlen;
     184             : 
     185           1 :   ls_mem->nhtype = nhtype;
     186             : 
     187           1 :   ls_mem->drop_in = drop_in;
     188             : 
     189           1 :   ls_mem->fib_table = fib_table;
     190           1 :   ls_mem->fib4_index = ip4_fib_index_from_table_id (fib_table);
     191           1 :   ls_mem->fib6_index = ip6_fib_index_from_table_id (fib_table);
     192             : 
     193           1 :   return 1;
     194             : }
     195             : 
     196             : static int
     197           1 : clb_creation_srv6_t_m_gtp4_d (ip6_sr_policy_t * sr_policy)
     198             : {
     199           1 :   return 0;
     200             : }
     201             : 
     202             : static int
     203           0 : clb_removal_srv6_t_m_gtp4_d (ip6_sr_policy_t * sr_policy)
     204             : {
     205             :   srv6_end_gtp4_d_param_t *ls_mem;
     206             : 
     207           0 :   ls_mem = (srv6_end_gtp4_d_param_t *) sr_policy->plugin_mem;
     208             : 
     209           0 :   clib_mem_free (ls_mem);
     210             : 
     211           0 :   return 0;
     212             : }
     213             : 
     214             : static clib_error_t *
     215         575 : srv6_t_m_gtp4_d_init (vlib_main_t * vm)
     216             : {
     217         575 :   srv6_t_main_v4_decap_t *sm = &srv6_t_main_v4_decap;
     218             :   ip6_header_t *ip6;
     219             :   dpo_type_t dpo_type;
     220             :   vlib_node_t *node;
     221             :   int rc;
     222             : 
     223         575 :   sm->vlib_main = vm;
     224         575 :   sm->vnet_main = vnet_get_main ();
     225             : 
     226         575 :   node = vlib_get_node_by_name (vm, (u8 *) "srv6-t-m-gtp4-d");
     227         575 :   sm->t_m_gtp4_d_node_index = node->index;
     228             : 
     229         575 :   node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
     230         575 :   sm->error_node_index = node->index;
     231             : 
     232         575 :   ip6 = &sm->cache_hdr;
     233             : 
     234         575 :   clib_memset_u8 (ip6, 0, sizeof (ip6_header_t));
     235             : 
     236             :   // IPv6 header (default)
     237         575 :   ip6->ip_version_traffic_class_and_flow_label = 0x60;
     238         575 :   ip6->hop_limit = 64;
     239         575 :   ip6->protocol = IP_PROTOCOL_IPV6;
     240             : 
     241         575 :   dpo_type = dpo_register_new_type (&dpo_vft, dpo_nodes);
     242             : 
     243         575 :   rc = sr_policy_register_function (vm, fn_name, keyword_str, def_str, param_str, 128,  //prefix len
     244             :                                     &dpo_type,
     245             :                                     clb_format_srv6_t_m_gtp4_d,
     246             :                                     clb_unformat_srv6_t_m_gtp4_d,
     247             :                                     clb_creation_srv6_t_m_gtp4_d,
     248             :                                     clb_removal_srv6_t_m_gtp4_d);
     249         575 :   if (rc < 0)
     250           0 :     clib_error_return (0, "SRv6 Transit GTP4.D Policy function"
     251             :                        "couldn't be registered");
     252         575 :   return 0;
     253             : }
     254             : 
     255             : /* *INDENT-OFF* */
     256       14399 : VNET_FEATURE_INIT (srv6_t_m_gtp4_d, static) =
     257             : {
     258             :   .arc_name = "ip4-unicast",
     259             :   .node_name = "srv6-t-m-gtp4-d",
     260             :   .runs_before = 0,
     261             : };
     262             : 
     263        1151 : VLIB_INIT_FUNCTION (srv6_t_m_gtp4_d_init);
     264             : /* *INDENT-ON* */
     265             : 
     266             : /*
     267             :  * fd.io coding-style-patch-verification: ON
     268             :  *
     269             :  * Local Variables:
     270             :  * eval: (c-set-style "gnu")
     271             :  * End:
     272             :  */

Generated by: LCOV version 1.14