LCOV - code coverage report
Current view: top level - plugins/ioam/lib-pot - pot_api.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 9 60 15.0 %
Date: 2023-07-05 22:20:52 Functions: 3 8 37.5 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2016 Cisco and/or its affiliates.
       3             :  * Licensed under the Apache License, Version 2.0 (the "License");
       4             :  * you may not use this file except in compliance with the License.
       5             :  * You may obtain a copy of the License at:
       6             :  *
       7             :  *     http://www.apache.org/licenses/LICENSE-2.0
       8             :  *
       9             :  * Unless required by applicable law or agreed to in writing, software
      10             :  * distributed under the License is distributed on an "AS IS" BASIS,
      11             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             :  * See the License for the specific language governing permissions and
      13             :  * limitations under the License.
      14             :  */
      15             : /*
      16             :  *------------------------------------------------------------------
      17             :  * pot_api.c - Proof of Transit related APIs to create
      18             :  *             and maintain profiles
      19             :  *------------------------------------------------------------------
      20             :  */
      21             : 
      22             : #include <vnet/vnet.h>
      23             : #include <vnet/plugin/plugin.h>
      24             : #include <ioam/lib-pot/pot_util.h>
      25             : 
      26             : #include <vlibapi/api.h>
      27             : #include <vlibmemory/api.h>
      28             : 
      29             : /* define message IDs */
      30             : #include <ioam/lib-pot/pot.api_enum.h>
      31             : #include <ioam/lib-pot/pot.api_types.h>
      32             : 
      33             : #define REPLY_MSG_ID_BASE sm->msg_id_base
      34             : #include <vlibapi/api_helper_macros.h>
      35             : 
      36           0 : static void vl_api_pot_profile_add_t_handler
      37             : (vl_api_pot_profile_add_t *mp)
      38             : {
      39           0 :     pot_main_t * sm = &pot_main;
      40           0 :     int rv = 0;
      41             :     vl_api_pot_profile_add_reply_t * rmp;
      42             :     u8 id;
      43           0 :     pot_profile *profile = NULL;
      44           0 :     u8 *name = 0;
      45             : 
      46           0 :     name = vl_api_from_api_to_new_vec(mp, &mp->list_name);
      47             : 
      48           0 :     pot_profile_list_init(name);
      49           0 :     id = mp->id;
      50           0 :     profile = pot_profile_find(id);
      51           0 :     if (profile) {
      52           0 :         rv = pot_profile_create(profile,
      53             :                                 clib_net_to_host_u64(mp->prime),
      54             :                                 clib_net_to_host_u64(mp->polynomial_public),
      55             :                                 clib_net_to_host_u64(mp->lpc),
      56             :                                 clib_net_to_host_u64(mp->secret_share));
      57           0 :         if (rv != 0)
      58           0 :             goto ERROROUT;
      59           0 :         if (1 == mp->validator)
      60           0 :           (void)pot_set_validator(profile, clib_net_to_host_u64(mp->secret_key));
      61           0 :         (void)pot_profile_set_bit_mask(profile, mp->max_bits);
      62             :     } else {
      63           0 :         rv = -3;
      64             :     }
      65           0 :  ERROROUT:
      66           0 :     vec_free(name);
      67           0 :     REPLY_MACRO(VL_API_POT_PROFILE_ADD_REPLY);
      68             : }
      69             : 
      70           0 : static void send_pot_profile_details(vl_api_pot_profile_show_config_dump_t *mp, u8 id)
      71             : {
      72             :     vl_api_pot_profile_show_config_details_t * rmp;
      73           0 :     pot_main_t * sm = &pot_main;
      74           0 :     pot_profile *profile = pot_profile_find(id);
      75           0 :     int rv = 0;
      76           0 :     if(profile){
      77           0 :         REPLY_MACRO2(VL_API_POT_PROFILE_SHOW_CONFIG_DETAILS,
      78             :                         rmp->id=id;
      79             :                         rmp->validator=profile->validator;
      80             :                         rmp->secret_key=clib_host_to_net_u64(profile->secret_key);
      81             :                         rmp->secret_share=clib_host_to_net_u64(profile->secret_share);
      82             :                         rmp->prime=clib_host_to_net_u64(profile->prime);
      83             :                         rmp->bit_mask=clib_host_to_net_u64(profile->bit_mask);
      84             :                         rmp->lpc=clib_host_to_net_u64(profile->lpc);
      85             :                         rmp->polynomial_public=clib_host_to_net_u64(profile->poly_pre_eval);
      86             :                         );
      87             :     }
      88             :     else{
      89           0 :         REPLY_MACRO2(VL_API_POT_PROFILE_SHOW_CONFIG_DETAILS,
      90             :                         rmp->id=id;
      91             :                         rmp->validator=0;
      92             :                         rmp->secret_key=0;
      93             :                         rmp->secret_share=0;
      94             :                         rmp->prime=0;
      95             :                         rmp->bit_mask=0;
      96             :                         rmp->lpc=0;
      97             :                         rmp->polynomial_public=0;
      98             :                         );
      99             :     }
     100             : }
     101             : 
     102           0 : static void vl_api_pot_profile_show_config_dump_t_handler
     103             : (vl_api_pot_profile_show_config_dump_t *mp)
     104             : {
     105           0 :     u8 id = mp->id;
     106           0 :     u8 dump_call_id = ~0;
     107           0 :     if(dump_call_id==id){
     108           0 :         for(id=0;id<MAX_POT_PROFILES;id++)
     109           0 :             send_pot_profile_details(mp,id);
     110             :     }
     111             :     else
     112           0 :         send_pot_profile_details(mp,id);
     113           0 : }
     114             : 
     115           0 : static void vl_api_pot_profile_activate_t_handler
     116             : (vl_api_pot_profile_activate_t *mp)
     117             : {
     118           0 :     pot_main_t * sm = &pot_main;
     119           0 :     int rv = 0;
     120             :     vl_api_pot_profile_add_reply_t * rmp;
     121             :     u8 id;
     122           0 :     u8 *name = NULL;
     123             : 
     124           0 :     name = vl_api_from_api_to_new_vec(mp, &mp->list_name);
     125           0 :     if (!pot_profile_list_is_enabled(name)) {
     126           0 :         rv = -1;
     127             :     } else {
     128           0 :         id = mp->id;
     129           0 :         rv = pot_profile_set_active(id);
     130             :     }
     131             : 
     132           0 :     vec_free(name);
     133           0 :     REPLY_MACRO(VL_API_POT_PROFILE_ACTIVATE_REPLY);
     134             : }
     135             : 
     136             : 
     137           0 : static void vl_api_pot_profile_del_t_handler
     138             : (vl_api_pot_profile_del_t *mp)
     139             : {
     140           0 :     pot_main_t * sm = &pot_main;
     141           0 :     int rv = 0;
     142             :     vl_api_pot_profile_del_reply_t * rmp;
     143             : 
     144           0 :     clear_pot_profiles();
     145             : 
     146           0 :     REPLY_MACRO(VL_API_POT_PROFILE_DEL_REPLY);
     147             : }
     148             : 
     149             : #include <ioam/lib-pot/pot.api.c>
     150         559 : static clib_error_t * pot_init (vlib_main_t * vm)
     151             : {
     152         559 :   pot_main_t * sm = &pot_main;
     153             : 
     154         559 :   bzero(sm, sizeof(pot_main));
     155         559 :   (void)pot_util_init();
     156             : 
     157         559 :   sm->vlib_main = vm;
     158         559 :   sm->vnet_main = vnet_get_main();
     159             : 
     160             :   /* Ask for a correctly-sized block of API message decode slots */
     161         559 :   sm->msg_id_base = setup_message_id_table ();
     162             : 
     163         559 :   return 0;
     164             : }
     165             : 
     166        1119 : VLIB_INIT_FUNCTION (pot_init);

Generated by: LCOV version 1.14