LCOV - code coverage report
Current view: top level - plugins/srv6-mobile - gtp6_e.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 46 55 83.6 %
Date: 2023-10-26 01:39:38 Functions: 10 12 83.3 %

          Line data    Source code
       1             : /*
       2             :  * srv6_end_m_gtp6_e.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_t srv6_end_main_v6;
      25             : 
      26             : static void
      27           6 : clb_dpo_lock_srv6_end_m_gtp6_e (dpo_id_t * dpo)
      28             : {
      29           6 : }
      30             : 
      31             : static void
      32           3 : clb_dpo_unlock_srv6_end_m_gtp6_e (dpo_id_t * dpo)
      33             : {
      34           3 : }
      35             : 
      36             : static u8 *
      37           0 : clb_dpo_format_srv6_end_m_gtp6_e (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_e,
      47             :   .dv_unlock = clb_dpo_unlock_srv6_end_m_gtp6_e,
      48             :   .dv_format = clb_dpo_format_srv6_end_m_gtp6_e,
      49             : };
      50             : 
      51             : const static char *const srv6_end_m_gtp6_e_nodes[] = {
      52             :   "srv6-end-m-gtp6-e",
      53             :   NULL,
      54             : };
      55             : 
      56             : const static char *const *const dpo_nodes[DPO_PROTO_NUM] = {
      57             :   [DPO_PROTO_IP6] = srv6_end_m_gtp6_e_nodes,
      58             : };
      59             : 
      60             : static u8 fn_name[] = "SRv6-End.M.GTP6.E-plugin";
      61             : static u8 keyword_str[] = "end.m.gtp6.e";
      62             : static u8 def_str[] =
      63             :   "Endpoint function with encapsulation for IPv6/GTP tunnel";
      64             : static u8 param_str[] = "";
      65             : 
      66             : static u8 *
      67           1 : clb_format_srv6_end_m_gtp6_e (u8 * s, va_list * args)
      68             : {
      69           1 :   srv6_end_gtp6_e_param_t *ls_mem = va_arg (*args, void *);
      70             :   ;
      71             : 
      72           1 :   s = format (s, "SRv6 End.M.GTP6.E function.");
      73             : 
      74           1 :   s = format (s, "\tFib Table %d\n", ls_mem->fib_table);
      75             : 
      76           1 :   return s;
      77             : }
      78             : 
      79             : static uword
      80           2 : clb_unformat_srv6_end_m_gtp6_e (unformat_input_t * input, va_list * args)
      81             : {
      82           2 :   void **plugin_mem_p = va_arg (*args, void **);
      83             :   srv6_end_gtp6_e_param_t *ls_mem;
      84             :   u32 fib_table;
      85             : 
      86           2 :   if (!unformat (input, "end.m.gtp6.e fib-table %d", &fib_table))
      87           1 :     return 0;
      88             : 
      89           1 :   ls_mem = clib_mem_alloc (sizeof *ls_mem);
      90           1 :   clib_memset (ls_mem, 0, sizeof *ls_mem);
      91           1 :   *plugin_mem_p = ls_mem;
      92             : 
      93           1 :   ls_mem->fib_table = fib_table;
      94           1 :   ls_mem->fib4_index = ip4_fib_index_from_table_id (fib_table);
      95           1 :   ls_mem->fib6_index = ip6_fib_index_from_table_id (fib_table);
      96             : 
      97           1 :   return 1;
      98             : }
      99             : 
     100             : static int
     101           1 : clb_creation_srv6_end_m_gtp6_e (ip6_sr_localsid_t * localsid)
     102             : {
     103           1 :   return 0;
     104             : }
     105             : 
     106             : static int
     107           0 : clb_removal_srv6_end_m_gtp6_e (ip6_sr_localsid_t * localsid)
     108             : {
     109             :   srv6_end_gtp6_e_param_t *ls_mem;
     110             : 
     111           0 :   ls_mem = localsid->plugin_mem;
     112             : 
     113           0 :   clib_mem_free (ls_mem);
     114             : 
     115           0 :   return 0;
     116             : }
     117             : 
     118             : static clib_error_t *
     119         575 : srv6_end_m_gtp6_e_init (vlib_main_t * vm)
     120             : {
     121         575 :   srv6_end_main_v6_t *sm = &srv6_end_main_v6;
     122         575 :   ip6_header_t *ip6 = &sm->cache_hdr.ip6;
     123         575 :   udp_header_t *udp = &sm->cache_hdr.udp;
     124         575 :   gtpu_header_t *gtpu = &sm->cache_hdr.gtpu;
     125             :   dpo_type_t dpo_type;
     126             :   vlib_node_t *node;
     127             :   int rc;
     128             : 
     129         575 :   sm->vlib_main = vm;
     130         575 :   sm->vnet_main = vnet_get_main ();
     131             : 
     132         575 :   node = vlib_get_node_by_name (vm, (u8 *) "srv6-end-m-gtp6-e");
     133         575 :   sm->end_m_gtp6_e_node_index = node->index;
     134             : 
     135         575 :   node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
     136         575 :   sm->error_node_index = node->index;
     137             : 
     138             :   // clear the pre cached packet
     139         575 :   clib_memset_u8 (ip6, 0, sizeof (ip6_gtpu_header_t));
     140             : 
     141             :   // set defaults
     142         575 :   ip6->ip_version_traffic_class_and_flow_label = 0x60;
     143         575 :   ip6->protocol = IP_PROTOCOL_UDP;
     144         575 :   ip6->hop_limit = 64;
     145             : 
     146         575 :   udp->dst_port = clib_host_to_net_u16 (SRV6_GTP_UDP_DST_PORT);
     147             : 
     148         575 :   gtpu->ver_flags = GTPU_V1_VER | GTPU_PT_GTP;
     149         575 :   gtpu->type = GTPU_TYPE_GTPU;
     150             : 
     151         575 :   dpo_type = dpo_register_new_type (&dpo_vft, dpo_nodes);
     152             : 
     153         575 :   rc = sr_localsid_register_function (vm, fn_name, keyword_str, def_str, param_str, 128,        //prefix len
     154             :                                       &dpo_type,
     155             :                                       clb_format_srv6_end_m_gtp6_e,
     156             :                                       clb_unformat_srv6_end_m_gtp6_e,
     157             :                                       clb_creation_srv6_end_m_gtp6_e,
     158             :                                       clb_removal_srv6_end_m_gtp6_e);
     159         575 :   if (rc < 0)
     160           0 :     clib_error_return (0, "SRv6 Endpoint GTP6.E LocalSID function"
     161             :                        "couldn't be registered");
     162         575 :   return 0;
     163             : }
     164             : 
     165             : /* *INDENT-OFF* */
     166       14399 : VNET_FEATURE_INIT (srv6_end_m_gtp6_e, static) =
     167             : {
     168             :   .arc_name = "ip6-unicast",
     169             :   .node_name = "srv6-end-m-gtp6-e",
     170             :   .runs_before = 0,
     171             : };
     172             : 
     173        2303 : VLIB_INIT_FUNCTION (srv6_end_m_gtp6_e_init);
     174             : /* *INDENT-ON* */
     175             : 
     176             : /*
     177             :  * fd.io coding-style-patch-verification: ON
     178             :  *
     179             :  * Local Variables:
     180             :  * eval: (c-set-style "gnu")
     181             :  * End:
     182             :  */

Generated by: LCOV version 1.14