LCOV - code coverage report
Current view: top level - vnet/srv6 - sr_api.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 45 277 16.2 %
Date: 2023-07-05 22:20:52 Functions: 7 24 29.2 %

          Line data    Source code
       1             : /*
       2             :  *------------------------------------------------------------------
       3             :  * sr_api.c - ipv6 segment routing api
       4             :  *
       5             :  * Copyright (c) 2016 Cisco and/or its affiliates.
       6             :  * Licensed under the Apache License, Version 2.0 (the "License");
       7             :  * you may not use this file except in compliance with the License.
       8             :  * You may obtain a copy of the License at:
       9             :  *
      10             :  *     http://www.apache.org/licenses/LICENSE-2.0
      11             :  *
      12             :  * Unless required by applicable law or agreed to in writing, software
      13             :  * distributed under the License is distributed on an "AS IS" BASIS,
      14             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      15             :  * See the License for the specific language governing permissions and
      16             :  * limitations under the License.
      17             :  *------------------------------------------------------------------
      18             :  */
      19             : 
      20             : #include <vnet/vnet.h>
      21             : #include <vnet/srv6/sr.h>
      22             : #include <vlibmemory/api.h>
      23             : 
      24             : #include <vnet/interface.h>
      25             : #include <vnet/api_errno.h>
      26             : #include <vnet/feature/feature.h>
      27             : #include <vnet/fib/fib_table.h>
      28             : #include <vnet/ip/ip_types_api.h>
      29             : 
      30             : #include <vnet/format_fns.h>
      31             : #include <vnet/srv6/sr.api_enum.h>
      32             : #include <vnet/srv6/sr.api_types.h>
      33             : 
      34             : #define REPLY_MSG_ID_BASE sr_main.msg_id_base
      35             : #include <vlibapi/api_helper_macros.h>
      36             : 
      37          18 : static void vl_api_sr_localsid_add_del_t_handler
      38             :   (vl_api_sr_localsid_add_del_t * mp)
      39             : {
      40             :   vl_api_sr_localsid_add_del_reply_t *rmp;
      41          18 :   int rv = 0;
      42             :   ip46_address_t prefix;
      43             :   ip6_address_t localsid;
      44             : /*
      45             :  * int sr_cli_localsid (char is_del, ip6_address_t *localsid_addr,
      46             :  *  char end_psp, u8 behavior, u32 sw_if_index, u32 vlan_index, u32 fib_table,
      47             :  *  ip46_address_t *nh_addr, void *ls_plugin_mem)
      48             :  */
      49          18 :   if (mp->behavior == SR_BEHAVIOR_X ||
      50          14 :       mp->behavior == SR_BEHAVIOR_DX6 ||
      51          12 :       mp->behavior == SR_BEHAVIOR_DX4 || mp->behavior == SR_BEHAVIOR_DX2)
      52          10 :     VALIDATE_SW_IF_INDEX (mp);
      53             : 
      54          18 :   ip6_address_decode (mp->localsid, &localsid);
      55          18 :   ip_address_decode (&mp->nh_addr, &prefix);
      56             : 
      57          18 :   rv = sr_cli_localsid (mp->is_del,
      58             :                         &localsid, 128,
      59          18 :                         mp->end_psp,
      60          18 :                         mp->behavior,
      61             :                         ntohl (mp->sw_if_index),
      62             :                         ntohl (mp->vlan_index),
      63             :                         ntohl (mp->fib_table), &prefix, 0, NULL);
      64             : 
      65          18 :   BAD_SW_IF_INDEX_LABEL;
      66          18 :   REPLY_MACRO (VL_API_SR_LOCALSID_ADD_DEL_REPLY);
      67             : }
      68             : 
      69             : static void
      70           0 : vl_api_sr_policy_add_t_handler (vl_api_sr_policy_add_t * mp)
      71             : {
      72             :   vl_api_sr_policy_add_reply_t *rmp;
      73           0 :   ip6_address_t *segments = 0, *seg;
      74             :   ip6_address_t bsid_addr;
      75             : 
      76             :   int i;
      77           0 :   for (i = 0; i < mp->sids.num_sids; i++)
      78             :     {
      79           0 :       vec_add2 (segments, seg, 1);
      80           0 :       ip6_address_decode (mp->sids.sids[i], seg);
      81             :     }
      82             : 
      83           0 :   ip6_address_decode (mp->bsid_addr, &bsid_addr);
      84             : 
      85             :   /*
      86             :    * sr_policy_add (ip6_address_t *bsid, ip6_address_t *segments,
      87             :    *                ip6_address_t *encap_src,
      88             :    *                u32 weight, u8 behavior, u32 fib_table, u8 is_encap,
      89             :    *                u16 behavior, void *plugin_mem)
      90             :    */
      91           0 :   int rv = 0;
      92             :   rv =
      93           0 :     sr_policy_add (&bsid_addr, segments, NULL, ntohl (mp->sids.weight),
      94           0 :                    mp->is_spray, ntohl (mp->fib_table), mp->is_encap, 0, NULL);
      95           0 :   vec_free (segments);
      96             : 
      97           0 :   REPLY_MACRO (VL_API_SR_POLICY_ADD_REPLY);
      98             : }
      99             : 
     100             : static void
     101           0 : vl_api_sr_policy_mod_t_handler (vl_api_sr_policy_mod_t * mp)
     102             : {
     103             :   vl_api_sr_policy_mod_reply_t *rmp;
     104           0 :   ip6_address_t *segments = 0, *seg;
     105             :   ip6_address_t bsid_addr;
     106             : 
     107             :   int i;
     108           0 :   for (i = 0; i < mp->sids.num_sids; i++)
     109             :     {
     110           0 :       vec_add2 (segments, seg, 1);
     111           0 :       ip6_address_decode (mp->sids.sids[i], seg);
     112             :     }
     113             : 
     114           0 :   ip6_address_decode (mp->bsid_addr, &bsid_addr);
     115             : 
     116           0 :   int rv = 0;
     117             :   /*
     118             :    * int
     119             :    * sr_policy_mod(ip6_address_t *bsid, u32 index, u32 fib_table,
     120             :    *               u8 operation, ip6_address_t *segments,
     121             :    *               ip6_address_t *encap_src, u32 sl_index,
     122             :    *               u32 weight, u8 is_encap)
     123             :    */
     124           0 :   rv = sr_policy_mod (&bsid_addr, ntohl (mp->sr_policy_index),
     125           0 :                       ntohl (mp->fib_table), mp->operation, segments, NULL,
     126             :                       ntohl (mp->sl_index), ntohl (mp->sids.weight));
     127           0 :   vec_free (segments);
     128             : 
     129           0 :   REPLY_MACRO (VL_API_SR_POLICY_MOD_REPLY);
     130             : }
     131             : 
     132             : static void
     133           1 : vl_api_sr_policy_add_v2_t_handler (vl_api_sr_policy_add_v2_t *mp)
     134             : {
     135             :   vl_api_sr_policy_add_v2_reply_t *rmp;
     136           1 :   ip6_address_t *segments = 0, *seg;
     137             :   ip6_address_t bsid_addr;
     138             :   ip6_address_t encap_src;
     139             : 
     140             :   int i;
     141           4 :   for (i = 0; i < mp->sids.num_sids; i++)
     142             :     {
     143           3 :       vec_add2 (segments, seg, 1);
     144           3 :       ip6_address_decode (mp->sids.sids[i], seg);
     145             :     }
     146             : 
     147           1 :   ip6_address_decode (mp->bsid_addr, &bsid_addr);
     148           1 :   ip6_address_decode (mp->encap_src, &encap_src);
     149             : 
     150           1 :   if (ip6_address_is_zero (&encap_src))
     151             :     {
     152           0 :       encap_src = *sr_get_encaps_source ();
     153             :     }
     154             :   /*
     155             :    * sr_policy_add (ip6_address_t *bsid, ip6_address_t *segments,
     156             :    *                ip6_address_t *encap_src,
     157             :    *                u32 weight, u8 behavior, u32 fib_table, u8 is_encap,
     158             :    *                u16 behavior, void *plugin_mem)
     159             :    */
     160           1 :   int rv = 0;
     161             :   rv =
     162           1 :     sr_policy_add (&bsid_addr, segments, &encap_src, ntohl (mp->sids.weight),
     163           1 :                    mp->type, ntohl (mp->fib_table), mp->is_encap, 0, NULL);
     164           1 :   vec_free (segments);
     165             : 
     166           1 :   REPLY_MACRO (VL_API_SR_POLICY_ADD_REPLY);
     167             : }
     168             : 
     169             : static void
     170           0 : vl_api_sr_policy_mod_v2_t_handler (vl_api_sr_policy_mod_v2_t *mp)
     171             : {
     172             :   vl_api_sr_policy_mod_v2_reply_t *rmp;
     173           0 :   ip6_address_t *segments = 0, *seg;
     174             :   ip6_address_t bsid_addr;
     175             :   ip6_address_t encap_src;
     176             : 
     177             :   int i;
     178           0 :   for (i = 0; i < mp->sids.num_sids; i++)
     179             :     {
     180           0 :       vec_add2 (segments, seg, 1);
     181           0 :       ip6_address_decode (mp->sids.sids[i], seg);
     182             :     }
     183             : 
     184           0 :   ip6_address_decode (mp->bsid_addr, &bsid_addr);
     185           0 :   ip6_address_decode (mp->encap_src, &encap_src);
     186             : 
     187           0 :   if (ip6_address_is_zero (&encap_src))
     188             :     {
     189           0 :       encap_src = *sr_get_encaps_source ();
     190             :     }
     191             : 
     192           0 :   int rv = 0;
     193             :   /*
     194             :    * int
     195             :    * sr_policy_mod(ip6_address_t *bsid, u32 index, u32 fib_table,
     196             :    *               u8 operation, ip6_address_t *segments,
     197             :    *               ip6_address_t *encap_src, u32 sl_index,
     198             :    *               u32 weight, u8 is_encap)
     199             :    */
     200             :   rv =
     201           0 :     sr_policy_mod (&bsid_addr, ntohl (mp->sr_policy_index),
     202           0 :                    ntohl (mp->fib_table), mp->operation, segments, &encap_src,
     203             :                    ntohl (mp->sl_index), ntohl (mp->sids.weight));
     204           0 :   vec_free (segments);
     205             : 
     206           0 :   REPLY_MACRO (VL_API_SR_POLICY_MOD_REPLY);
     207             : }
     208             : 
     209             : static void
     210           1 : vl_api_sr_policy_del_t_handler (vl_api_sr_policy_del_t * mp)
     211             : {
     212             :   vl_api_sr_policy_del_reply_t *rmp;
     213           1 :   int rv = 0;
     214             :   ip6_address_t bsid_addr;
     215             : /*
     216             :  * int
     217             :  * sr_policy_del (ip6_address_t *bsid, u32 index)
     218             :  */
     219           1 :   ip6_address_decode (mp->bsid_addr, &bsid_addr);
     220           1 :   rv = sr_policy_del (&bsid_addr, ntohl (mp->sr_policy_index));
     221             : 
     222           1 :   REPLY_MACRO (VL_API_SR_POLICY_DEL_REPLY);
     223             : }
     224             : 
     225             : static void
     226           0 : vl_api_sr_set_encap_source_t_handler (vl_api_sr_set_encap_source_t * mp)
     227             : {
     228             :   vl_api_sr_set_encap_source_reply_t *rmp;
     229           0 :   int rv = 0;
     230             :   ip6_address_t encaps_source;
     231             : 
     232           0 :   ip6_address_decode (mp->encaps_source, &encaps_source);
     233           0 :   sr_set_source (&encaps_source);
     234             : 
     235           0 :   REPLY_MACRO (VL_API_SR_SET_ENCAP_SOURCE_REPLY);
     236             : }
     237             : 
     238             : static void
     239           0 : vl_api_sr_set_encap_hop_limit_t_handler (vl_api_sr_set_encap_hop_limit_t * mp)
     240             : {
     241             :   vl_api_sr_set_encap_hop_limit_reply_t *rmp;
     242           0 :   int rv = 0;
     243             : 
     244           0 :   if (mp->hop_limit == 0)
     245           0 :     rv = VNET_API_ERROR_INVALID_VALUE;
     246             :   else
     247           0 :     sr_set_hop_limit (mp->hop_limit);
     248             : 
     249           0 :   REPLY_MACRO (VL_API_SR_SET_ENCAP_HOP_LIMIT_REPLY);
     250             : }
     251             : 
     252           2 : static void vl_api_sr_steering_add_del_t_handler
     253             :   (vl_api_sr_steering_add_del_t * mp)
     254             : {
     255             :   vl_api_sr_steering_add_del_reply_t *rmp;
     256           2 :   int rv = 0;
     257             :   ip6_address_t bsid_addr;
     258             :   ip46_address_t prefix_addr;
     259             : /*
     260             :  * int
     261             :  * sr_steering_policy(int is_del, ip6_address_t *bsid, u32 sr_policy_index,
     262             :  *  u32 table_id, ip46_address_t *prefix, u32 mask_width, u32 sw_if_index,
     263             :  *  u8 traffic_type)
     264             :  */
     265             : 
     266           2 :   ip6_address_decode (mp->bsid_addr, &bsid_addr);
     267           2 :   ip_address_decode (&mp->prefix.address, &prefix_addr);
     268             : 
     269           2 :   if (mp->traffic_type == SR_STEER_L2)
     270           0 :     VALIDATE_SW_IF_INDEX (mp);
     271             : 
     272           2 :   rv = sr_steering_policy (mp->is_del,
     273             :                            &bsid_addr,
     274             :                            ntohl (mp->sr_policy_index),
     275             :                            ntohl (mp->table_id),
     276             :                            &prefix_addr,
     277           2 :                            mp->prefix.len,
     278           2 :                            ntohl (mp->sw_if_index), mp->traffic_type);
     279             : 
     280           2 :   BAD_SW_IF_INDEX_LABEL;
     281           2 :   REPLY_MACRO (VL_API_SR_STEERING_ADD_DEL_REPLY);
     282             : }
     283             : 
     284           0 : static void send_sr_localsid_details
     285             :   (ip6_sr_localsid_t * t, vl_api_registration_t * reg, u32 context)
     286             : {
     287             :   vl_api_sr_localsids_details_t *rmp;
     288             : 
     289           0 :   rmp = vl_msg_api_alloc (sizeof (*rmp));
     290           0 :   clib_memset (rmp, 0, sizeof (*rmp));
     291           0 :   rmp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_SR_LOCALSIDS_DETAILS);
     292           0 :   ip6_address_encode (&t->localsid, rmp->addr);
     293           0 :   rmp->end_psp = t->end_psp;
     294           0 :   rmp->behavior = t->behavior;
     295           0 :   rmp->fib_table = htonl (t->fib_table);
     296           0 :   rmp->vlan_index = htonl (t->vlan_index);
     297           0 :   ip_address_encode (&t->next_hop, IP46_TYPE_ANY, &rmp->xconnect_nh_addr);
     298             : 
     299           0 :   if (t->behavior == SR_BEHAVIOR_T || t->behavior == SR_BEHAVIOR_DT6)
     300           0 :     rmp->xconnect_iface_or_vrf_table =
     301           0 :       htonl (fib_table_get_table_id (t->sw_if_index, FIB_PROTOCOL_IP6));
     302           0 :   else if (t->behavior == SR_BEHAVIOR_DT4)
     303           0 :     rmp->xconnect_iface_or_vrf_table =
     304           0 :       htonl (fib_table_get_table_id (t->sw_if_index, FIB_PROTOCOL_IP4));
     305             :   else
     306           0 :     rmp->xconnect_iface_or_vrf_table = htonl (t->sw_if_index);
     307             : 
     308           0 :   rmp->context = context;
     309             : 
     310           0 :   vl_api_send_msg (reg, (u8 *) rmp);
     311           0 : }
     312             : 
     313           0 : static void vl_api_sr_localsids_dump_t_handler
     314             :   (vl_api_sr_localsids_dump_t * mp)
     315             : {
     316             :   vl_api_registration_t *reg;
     317           0 :   ip6_sr_main_t *sm = &sr_main;
     318             :   ip6_sr_localsid_t *t;
     319             : 
     320           0 :   reg = vl_api_client_index_to_registration (mp->client_index);
     321           0 :   if (!reg)
     322           0 :     return;
     323             : 
     324             :   /* *INDENT-OFF* */
     325           0 :   pool_foreach (t, sm->localsids)
     326             :    {
     327           0 :     send_sr_localsid_details(t, reg, mp->context);
     328             :   }
     329             :   /* *INDENT-ON* */
     330             : }
     331             : 
     332             : static void
     333           0 : send_sr_localsid_with_packet_stats_details (int local_sid_index,
     334             :                                             ip6_sr_localsid_t *t,
     335             :                                             vl_api_registration_t *reg,
     336             :                                             u32 context)
     337             : {
     338             :   vl_api_sr_localsids_with_packet_stats_details_t *rmp;
     339             :   vlib_counter_t good_traffic, bad_traffic;
     340           0 :   ip6_sr_main_t *sm = &sr_main;
     341             : 
     342           0 :   rmp = vl_msg_api_alloc (sizeof (*rmp));
     343           0 :   clib_memset (rmp, 0, sizeof (*rmp));
     344           0 :   rmp->_vl_msg_id =
     345           0 :     ntohs (REPLY_MSG_ID_BASE + VL_API_SR_LOCALSIDS_WITH_PACKET_STATS_DETAILS);
     346           0 :   ip6_address_encode (&t->localsid, rmp->addr);
     347           0 :   rmp->end_psp = t->end_psp;
     348           0 :   rmp->behavior = t->behavior;
     349           0 :   rmp->fib_table = htonl (t->fib_table);
     350           0 :   rmp->vlan_index = htonl (t->vlan_index);
     351           0 :   ip_address_encode (&t->next_hop, IP46_TYPE_ANY, &rmp->xconnect_nh_addr);
     352             : 
     353           0 :   if (t->behavior == SR_BEHAVIOR_T || t->behavior == SR_BEHAVIOR_DT6)
     354           0 :     rmp->xconnect_iface_or_vrf_table =
     355           0 :       htonl (fib_table_get_table_id (t->sw_if_index, FIB_PROTOCOL_IP6));
     356           0 :   else if (t->behavior == SR_BEHAVIOR_DT4)
     357           0 :     rmp->xconnect_iface_or_vrf_table =
     358           0 :       htonl (fib_table_get_table_id (t->sw_if_index, FIB_PROTOCOL_IP4));
     359             :   else
     360           0 :     rmp->xconnect_iface_or_vrf_table = htonl (t->sw_if_index);
     361             : 
     362           0 :   rmp->context = context;
     363           0 :   vlib_get_combined_counter (&(sm->sr_ls_valid_counters), local_sid_index,
     364             :                              &good_traffic);
     365           0 :   vlib_get_combined_counter (&(sm->sr_ls_invalid_counters), local_sid_index,
     366             :                              &bad_traffic);
     367           0 :   rmp->good_traffic_bytes = clib_host_to_net_u64 (good_traffic.bytes);
     368           0 :   rmp->good_traffic_pkt_count = clib_host_to_net_u64 (good_traffic.packets);
     369           0 :   rmp->bad_traffic_bytes = clib_host_to_net_u64 (bad_traffic.bytes);
     370           0 :   rmp->bad_traffic_pkt_count = clib_host_to_net_u64 (bad_traffic.packets);
     371           0 :   vl_api_send_msg (reg, (u8 *) rmp);
     372           0 : }
     373             : 
     374             : static void
     375           0 : vl_api_sr_localsids_with_packet_stats_dump_t_handler (
     376             :   vl_api_sr_localsids_with_packet_stats_dump_t *mp)
     377             : {
     378             :   vl_api_registration_t *reg;
     379           0 :   ip6_sr_main_t *sm = &sr_main;
     380           0 :   ip6_sr_localsid_t **localsid_list = 0;
     381             :   ip6_sr_localsid_t *t;
     382             :   int i;
     383             : 
     384           0 :   reg = vl_api_client_index_to_registration (mp->client_index);
     385           0 :   if (!reg)
     386           0 :     return;
     387             : 
     388           0 :   pool_foreach (t, sm->localsids)
     389             :     {
     390           0 :       vec_add1 (localsid_list, t);
     391             :     }
     392           0 :   for (i = 0; i < vec_len (localsid_list); i++)
     393             :     {
     394           0 :       t = localsid_list[i];
     395           0 :       send_sr_localsid_with_packet_stats_details (i, t, reg, mp->context);
     396             :     }
     397             : }
     398             : 
     399           0 : static void send_sr_policies_details
     400             :   (ip6_sr_policy_t * t, vl_api_registration_t * reg, u32 context)
     401             : {
     402             :   vl_api_sr_policies_details_t *rmp;
     403           0 :   ip6_sr_main_t *sm = &sr_main;
     404             : 
     405           0 :   u32 *sl_index, slidx = 0;
     406           0 :   ip6_sr_sl_t *segment_list = 0;
     407             :   ip6_address_t *segment;
     408             :   vl_api_srv6_sid_list_t *api_sid_list;
     409             : 
     410           0 :   rmp = vl_msg_api_alloc (sizeof (*rmp) +
     411           0 :                           vec_len (t->segments_lists) *
     412             :                           sizeof (vl_api_srv6_sid_list_t));
     413           0 :   clib_memset (rmp, 0,
     414             :                (sizeof (*rmp) +
     415             :                 vec_len (t->segments_lists) *
     416             :                 sizeof (vl_api_srv6_sid_list_t)));
     417             : 
     418           0 :   rmp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_SR_POLICIES_DETAILS);
     419           0 :   ip6_address_encode (&t->bsid, rmp->bsid);
     420           0 :   rmp->is_encap = t->is_encap;
     421           0 :   rmp->is_spray = t->type;
     422           0 :   rmp->fib_table = htonl (t->fib_table);
     423           0 :   rmp->num_sid_lists = vec_len (t->segments_lists);
     424             : 
     425             :   /* Fill in all the segments lists */
     426           0 :   vec_foreach (sl_index, t->segments_lists)
     427             :   {
     428           0 :     segment_list = pool_elt_at_index (sm->sid_lists, *sl_index);
     429             : 
     430           0 :     api_sid_list = &rmp->sid_lists[sl_index - t->segments_lists];
     431             : 
     432           0 :     api_sid_list->num_sids = vec_len (segment_list->segments);
     433           0 :     api_sid_list->weight = htonl (segment_list->weight);
     434           0 :     slidx = 0;
     435           0 :     vec_foreach (segment, segment_list->segments)
     436             :     {
     437           0 :       ip6_address_encode (segment, api_sid_list->sids[slidx++]);
     438             :     }
     439             :   }
     440             : 
     441           0 :   rmp->context = context;
     442           0 :   vl_api_send_msg (reg, (u8 *) rmp);
     443           0 : }
     444             : 
     445             : static void
     446           0 : vl_api_sr_policies_dump_t_handler (vl_api_sr_policies_dump_t * mp)
     447             : {
     448             :   vl_api_registration_t *reg;
     449           0 :   ip6_sr_main_t *sm = &sr_main;
     450             :   ip6_sr_policy_t *t;
     451             : 
     452           0 :   reg = vl_api_client_index_to_registration (mp->client_index);
     453           0 :   if (!reg)
     454           0 :     return;
     455             : 
     456             :   /* *INDENT-OFF* */
     457           0 :   pool_foreach (t, sm->sr_policies)
     458             :    {
     459           0 :     send_sr_policies_details(t, reg, mp->context);
     460             :   }
     461             :   /* *INDENT-ON* */
     462             : }
     463             : 
     464             : static void
     465           0 : send_sr_policies_v2_details (ip6_sr_policy_t *t, vl_api_registration_t *reg,
     466             :                              u32 context)
     467             : {
     468             :   vl_api_sr_policies_v2_details_t *rmp;
     469           0 :   ip6_sr_main_t *sm = &sr_main;
     470             : 
     471           0 :   u32 *sl_index, slidx = 0;
     472           0 :   ip6_sr_sl_t *segment_list = 0;
     473             :   ip6_address_t *segment;
     474             :   vl_api_srv6_sid_list_t *api_sid_list;
     475             : 
     476           0 :   rmp = vl_msg_api_alloc (sizeof (*rmp) + vec_len (t->segments_lists) *
     477             :                                             sizeof (vl_api_srv6_sid_list_t));
     478           0 :   clib_memset (rmp, 0,
     479             :                (sizeof (*rmp) + vec_len (t->segments_lists) *
     480             :                                   sizeof (vl_api_srv6_sid_list_t)));
     481             : 
     482           0 :   rmp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_SR_POLICIES_V2_DETAILS);
     483           0 :   ip6_address_encode (&t->bsid, rmp->bsid);
     484           0 :   ip6_address_encode (&t->encap_src, rmp->encap_src);
     485           0 :   rmp->is_encap = t->is_encap;
     486           0 :   rmp->type = t->type;
     487           0 :   rmp->fib_table = htonl (t->fib_table);
     488           0 :   rmp->num_sid_lists = vec_len (t->segments_lists);
     489             : 
     490             :   /* Fill in all the segments lists */
     491           0 :   vec_foreach (sl_index, t->segments_lists)
     492             :     {
     493           0 :       segment_list = pool_elt_at_index (sm->sid_lists, *sl_index);
     494             : 
     495           0 :       api_sid_list = &rmp->sid_lists[sl_index - t->segments_lists];
     496             : 
     497           0 :       api_sid_list->num_sids = vec_len (segment_list->segments);
     498           0 :       api_sid_list->weight = htonl (segment_list->weight);
     499           0 :       slidx = 0;
     500           0 :       vec_foreach (segment, segment_list->segments)
     501             :         {
     502           0 :           ip6_address_encode (segment, api_sid_list->sids[slidx++]);
     503             :         }
     504             :     }
     505             : 
     506           0 :   rmp->context = context;
     507           0 :   vl_api_send_msg (reg, (u8 *) rmp);
     508           0 : }
     509             : 
     510             : static void
     511           0 : vl_api_sr_policies_v2_dump_t_handler (vl_api_sr_policies_v2_dump_t *mp)
     512             : {
     513             :   vl_api_registration_t *reg;
     514           0 :   ip6_sr_main_t *sm = &sr_main;
     515             :   ip6_sr_policy_t *t;
     516             : 
     517           0 :   reg = vl_api_client_index_to_registration (mp->client_index);
     518           0 :   if (!reg)
     519           0 :     return;
     520             : 
     521           0 :   pool_foreach (t, sm->sr_policies)
     522             :     {
     523           0 :       send_sr_policies_v2_details (t, reg, mp->context);
     524             :     }
     525             : }
     526             : 
     527           0 : static void send_sr_policies_details_with_sl_index
     528             :   (ip6_sr_policy_t * t, vl_api_registration_t * reg, u32 context)
     529             : {
     530             :   vl_api_sr_policies_with_sl_index_details_t *rmp;
     531           0 :   ip6_sr_main_t *sm = &sr_main;
     532             : 
     533           0 :   u32 *sl_index, slidx = 0;
     534           0 :   ip6_sr_sl_t *segment_list = 0;
     535             :   ip6_address_t *segment;
     536             :   vl_api_srv6_sid_list_with_sl_index_t *api_sid_list;
     537             : 
     538           0 :   rmp = vl_msg_api_alloc (sizeof (*rmp) +
     539           0 :                           vec_len (t->segments_lists) *
     540             :                           sizeof (vl_api_srv6_sid_list_with_sl_index_t));
     541           0 :   clib_memset (rmp, 0,
     542             :                (sizeof (*rmp) +
     543             :                 vec_len (t->segments_lists) *
     544             :                 sizeof (vl_api_srv6_sid_list_with_sl_index_t)));
     545             : 
     546           0 :   rmp->_vl_msg_id =
     547           0 :     ntohs (REPLY_MSG_ID_BASE + VL_API_SR_POLICIES_WITH_SL_INDEX_DETAILS);
     548           0 :   ip6_address_encode (&t->bsid, rmp->bsid);
     549           0 :   rmp->is_encap = t->is_encap;
     550           0 :   rmp->is_spray = t->type;
     551           0 :   rmp->fib_table = htonl (t->fib_table);
     552           0 :   rmp->num_sid_lists = vec_len (t->segments_lists);
     553             : 
     554             :   /* Fill in all the segments lists */
     555           0 :   vec_foreach (sl_index, t->segments_lists)
     556             :   {
     557           0 :     segment_list = pool_elt_at_index (sm->sid_lists, *sl_index);
     558             : 
     559           0 :     api_sid_list = &rmp->sid_lists[sl_index - t->segments_lists];
     560           0 :     api_sid_list->sl_index = htonl (*sl_index);
     561           0 :     api_sid_list->num_sids = vec_len (segment_list->segments);
     562           0 :     api_sid_list->weight = htonl (segment_list->weight);
     563           0 :     slidx = 0;
     564           0 :     vec_foreach (segment, segment_list->segments)
     565             :     {
     566           0 :       ip6_address_encode (segment, api_sid_list->sids[slidx++]);
     567             :     }
     568             :   }
     569             : 
     570           0 :   rmp->context = context;
     571           0 :   vl_api_send_msg (reg, (u8 *) rmp);
     572           0 : }
     573             : 
     574             : static void
     575           0 :   vl_api_sr_policies_with_sl_index_dump_t_handler
     576             :   (vl_api_sr_policies_with_sl_index_dump_t * mp)
     577             : {
     578             :   vl_api_registration_t *reg;
     579           0 :   ip6_sr_main_t *sm = &sr_main;
     580             :   ip6_sr_policy_t *t;
     581             : 
     582           0 :   reg = vl_api_client_index_to_registration (mp->client_index);
     583           0 :   if (!reg)
     584           0 :     return;
     585             : 
     586             :   /* *INDENT-OFF* */
     587           0 :   pool_foreach (t, sm->sr_policies)
     588             :    {
     589           0 :     send_sr_policies_details_with_sl_index(t, reg, mp->context);
     590             :   }
     591             :   /* *INDENT-ON* */
     592             : }
     593             : 
     594           0 : static void send_sr_steering_pol_details
     595             :   (ip6_sr_steering_policy_t * t, vl_api_registration_t * reg, u32 context)
     596             : {
     597             :   vl_api_sr_steering_pol_details_t *rmp;
     598           0 :   ip6_sr_main_t *sm = &sr_main;
     599             : 
     600           0 :   rmp = vl_msg_api_alloc (sizeof (*rmp));
     601           0 :   clib_memset (rmp, 0, sizeof (*rmp));
     602           0 :   rmp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_SR_STEERING_POL_DETAILS);
     603             : 
     604             :   //Get the SR policy BSID
     605             :   ip6_sr_policy_t *p;
     606           0 :   p = pool_elt_at_index (sm->sr_policies, t->sr_policy);
     607           0 :   ip6_address_encode (&p->bsid, rmp->bsid);
     608             : 
     609             :   //Get the steering
     610           0 :   rmp->traffic_type = t->classify.traffic_type;
     611           0 :   rmp->fib_table = htonl (t->classify.l3.fib_table);
     612           0 :   ip_address_encode (&t->classify.l3.prefix, IP46_TYPE_ANY,
     613             :                      &rmp->prefix.address);
     614           0 :   rmp->prefix.len = t->classify.l3.mask_width;
     615             : 
     616           0 :   rmp->sw_if_index = htonl (t->classify.l2.sw_if_index);
     617             : 
     618           0 :   rmp->context = context;
     619           0 :   vl_api_send_msg (reg, (u8 *) rmp);
     620           0 : }
     621             : 
     622           0 : static void vl_api_sr_steering_pol_dump_t_handler
     623             :   (vl_api_sr_policies_dump_t * mp)
     624             : {
     625             :   vl_api_registration_t *reg;
     626           0 :   ip6_sr_main_t *sm = &sr_main;
     627             :   ip6_sr_steering_policy_t *t;
     628             : 
     629           0 :   reg = vl_api_client_index_to_registration (mp->client_index);
     630           0 :   if (!reg)
     631           0 :     return;
     632             : 
     633             :   /* *INDENT-OFF* */
     634           0 :   pool_foreach (t, sm->steer_policies)
     635             :    {
     636           0 :     send_sr_steering_pol_details(t, reg, mp->context);
     637             :   }
     638             :   /* *INDENT-ON* */
     639             : }
     640             : 
     641             : #include <vnet/srv6/sr.api.c>
     642             : static clib_error_t *
     643         559 : sr_api_hookup (vlib_main_t * vm)
     644             : {
     645             :   /*
     646             :    * Set up the (msg_name, crc, message-id) table
     647             :    */
     648         559 :   REPLY_MSG_ID_BASE = setup_message_id_table ();
     649             : 
     650         559 :   return 0;
     651             : }
     652             : 
     653       11199 : VLIB_API_INIT_FUNCTION (sr_api_hookup);
     654             : 
     655             : /*
     656             :  * fd.io coding-style-patch-verification: ON
     657             :  *
     658             :  * Local Variables:
     659             :  * eval: (c-set-style "gnu")
     660             :  * End:
     661             :  */

Generated by: LCOV version 1.14