LCOV - code coverage report
Current view: top level - plugins/srv6-mobile - gtp6_dt.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 14 61 23.0 %
Date: 2023-10-26 01:39:38 Functions: 5 12 41.7 %

          Line data    Source code
       1             : /*
       2             :  * srv6_end_m_gtp6_dt.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/fib/fib_table.h>
      21             : #include <vnet/plugin/plugin.h>
      22             : #include <vpp/app/version.h>
      23             : #include <srv6-mobile/mobile.h>
      24             : 
      25             : srv6_end_main_v6_dt_t srv6_end_main_v6_dt;
      26             : 
      27             : static void
      28           0 : clb_dpo_lock_srv6_end_m_gtp6_dt (dpo_id_t * dpo)
      29             : {
      30           0 : }
      31             : 
      32             : static void
      33           0 : clb_dpo_unlock_srv6_end_m_gtp6_dt (dpo_id_t * dpo)
      34             : {
      35           0 : }
      36             : 
      37             : static u8 *
      38           0 : clb_dpo_format_srv6_end_m_gtp6_dt (u8 * s, va_list * args)
      39             : {
      40           0 :   index_t index = va_arg (*args, index_t);
      41           0 :   CLIB_UNUSED (u32 indent) = va_arg (*args, u32);
      42             : 
      43           0 :   return (format (s, "SR: dynamic_proxy_index:[%u]", index));
      44             : }
      45             : 
      46             : const static dpo_vft_t dpo_vft = {
      47             :   .dv_lock = clb_dpo_lock_srv6_end_m_gtp6_dt,
      48             :   .dv_unlock = clb_dpo_unlock_srv6_end_m_gtp6_dt,
      49             :   .dv_format = clb_dpo_format_srv6_end_m_gtp6_dt,
      50             : };
      51             : 
      52             : const static char *const srv6_end_m_gtp6_dt_nodes[] = {
      53             :   "srv6-end-m-gtp6-dt",
      54             :   NULL,
      55             : };
      56             : 
      57             : const static char *const *const dpo_nodes[DPO_PROTO_NUM] = {
      58             :   [DPO_PROTO_IP6] = srv6_end_m_gtp6_dt_nodes,
      59             : };
      60             : 
      61             : static u8 fn_name[] = "SRv6-End.M.GTP6.DT-plugin";
      62             : static u8 keyword_str[] = "end.m.gtp6.dt";
      63             : static u8 def_str[] = "Endpoint function with DT for IPv6/GTP tunnel";
      64             : static u8 param_str[] = "fib-index <index> [local-fib-table <index>]";
      65             : 
      66             : static u8 *
      67           0 : clb_format_srv6_end_m_gtp6_dt (u8 * s, va_list * args)
      68             : {
      69           0 :   srv6_end_gtp6_dt_param_t *ls_mem = va_arg (*args, void *);
      70             : 
      71           0 :   s = format (s, "SRv6 End gtp6.dt\n\t");
      72             : 
      73           0 :   if (ls_mem->type == SRV6_GTP6_DT4)
      74           0 :     s = format (s, " Type GTP6.DT4 fib-table %u\n", ls_mem->fib4_index);
      75           0 :   else if (ls_mem->type == SRV6_GTP6_DT6)
      76           0 :     s = format (s, " Type GTP6.DT6, fib-table %u, local-fib-table %u\n",
      77             :                 ls_mem->fib6_index, ls_mem->local_fib_index);
      78           0 :   else if (ls_mem->type == SRV6_GTP6_DT46)
      79           0 :     s = format (s, " Type GTP6.DT46, fib-table %u, local-fib-table %u\n",
      80             :                 ls_mem->fib6_index, ls_mem->local_fib_index);
      81             :   else
      82           0 :     s = format (s, "\n");
      83             : 
      84           0 :   return s;
      85             : }
      86             : 
      87             : static uword
      88           0 : clb_unformat_srv6_end_m_gtp6_dt (unformat_input_t * input, va_list * args)
      89             : {
      90           0 :   void **plugin_mem_p = va_arg (*args, void **);
      91             :   srv6_end_gtp6_dt_param_t *ls_mem;
      92           0 :   u32 fib_index = 0;
      93           0 :   u32 local_fib_index = 0;
      94             :   u32 type;
      95             : 
      96           0 :   if (unformat (input, "end.m.gtp6.dt4 fib-table %u", &fib_index))
      97             :     {
      98           0 :       type = SRV6_GTP6_DT4;
      99             :     }
     100           0 :   else if (unformat (input, "end.m.gtp6.dt6 fib-table %u local-fib-table %u",
     101             :                      &fib_index, &local_fib_index))
     102             :     {
     103           0 :       type = SRV6_GTP6_DT6;
     104             :     }
     105           0 :   else if (unformat (input, "end.m.gtp6.dt46 fib-table %u local-fib-table %u",
     106             :                      &fib_index, &local_fib_index))
     107             :     {
     108           0 :       type = SRV6_GTP6_DT46;
     109             :     }
     110             :   else
     111             :     {
     112           0 :       return 0;
     113             :     }
     114             : 
     115           0 :   ls_mem = clib_mem_alloc (sizeof *ls_mem);
     116           0 :   clib_memset (ls_mem, 0, sizeof *ls_mem);
     117           0 :   *plugin_mem_p = ls_mem;
     118             : 
     119           0 :   ls_mem->fib4_index = fib_table_find (FIB_PROTOCOL_IP4, fib_index);
     120           0 :   ls_mem->fib6_index = fib_table_find (FIB_PROTOCOL_IP6, fib_index);
     121             : 
     122           0 :   if (type == SRV6_GTP6_DT6 || type == SRV6_GTP6_DT46)
     123             :     {
     124           0 :       ls_mem->local_fib_index =
     125           0 :         fib_table_find (FIB_PROTOCOL_IP6, local_fib_index);
     126             :     }
     127             : 
     128           0 :   ls_mem->type = type;
     129             : 
     130           0 :   return 1;
     131             : }
     132             : 
     133             : static int
     134           0 : clb_creation_srv6_end_m_gtp6_dt (ip6_sr_localsid_t * localsid)
     135             : {
     136           0 :   return 0;
     137             : }
     138             : 
     139             : static int
     140           0 : clb_removal_srv6_end_m_gtp6_dt (ip6_sr_localsid_t * localsid)
     141             : {
     142             :   srv6_end_gtp6_dt_param_t *ls_mem;
     143             : 
     144           0 :   ls_mem = localsid->plugin_mem;
     145             : 
     146           0 :   clib_mem_free (ls_mem);
     147             : 
     148           0 :   return 0;
     149             : }
     150             : 
     151             : static clib_error_t *
     152         575 : srv6_end_m_gtp6_dt_init (vlib_main_t * vm)
     153             : {
     154         575 :   srv6_end_main_v6_dt_t *sm = &srv6_end_main_v6_dt;
     155             :   dpo_type_t dpo_type;
     156             :   vlib_node_t *node;
     157             :   int rc;
     158             : 
     159         575 :   sm->vlib_main = vm;
     160         575 :   sm->vnet_main = vnet_get_main ();
     161             : 
     162         575 :   node = vlib_get_node_by_name (vm, (u8 *) "srv6-end-m-gtp6-dt");
     163         575 :   sm->end_m_gtp6_dt_node_index = node->index;
     164             : 
     165         575 :   node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
     166         575 :   sm->error_node_index = node->index;
     167             : 
     168         575 :   dpo_type = dpo_register_new_type (&dpo_vft, dpo_nodes);
     169             : 
     170         575 :   rc = sr_localsid_register_function (vm, fn_name, keyword_str, def_str, param_str, 128,        //prefix len
     171             :                                       &dpo_type,
     172             :                                       clb_format_srv6_end_m_gtp6_dt,
     173             :                                       clb_unformat_srv6_end_m_gtp6_dt,
     174             :                                       clb_creation_srv6_end_m_gtp6_dt,
     175             :                                       clb_removal_srv6_end_m_gtp6_dt);
     176         575 :   if (rc < 0)
     177           0 :     clib_error_return (0, "SRv6 Endpoint GTP6.DT LocalSID function"
     178             :                        "couldn't be registered");
     179         575 :   return 0;
     180             : }
     181             : 
     182             : /* *INDENT-OFF* */
     183       14399 : VNET_FEATURE_INIT (srv6_end_m_gtp6_dt, static) =
     184             : {
     185             :   .arc_name = "ip6-unicast",
     186             :   .node_name = "srv6-end-m-gtp6-dt",
     187             :   .runs_before = 0,
     188             : };
     189             : 
     190        4031 : VLIB_INIT_FUNCTION (srv6_end_m_gtp6_dt_init);
     191             : /* *INDENT-ON* */
     192             : 
     193             : /*
     194             :  * fd.io coding-style-patch-verification: ON
     195             :  *
     196             :  * Local Variables:
     197             :  * eval: (c-set-style "gnu")
     198             :  * End:
     199             :  */

Generated by: LCOV version 1.14