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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 *------------------------------------------------------------------
17 * pot_api.c - Proof of Transit related APIs to create
18 * and maintain profiles
19 *------------------------------------------------------------------
22 #include <vnet/vnet.h>
23 #include <vnet/plugin/plugin.h>
24 #include <ioam/lib-pot/pot_util.h>
26 #include <vlibapi/api.h>
27 #include <vlibmemory/api.h>
29 /* define message IDs */
30 #include <ioam/lib-pot/pot.api_enum.h>
31 #include <ioam/lib-pot/pot.api_types.h>
33 #define REPLY_MSG_ID_BASE sm->msg_id_base
34 #include <vlibapi/api_helper_macros.h>
36 static void vl_api_pot_profile_add_t_handler
37 (vl_api_pot_profile_add_t *mp)
39 pot_main_t * sm = &pot_main;
41 vl_api_pot_profile_add_reply_t * rmp;
43 pot_profile *profile = NULL;
46 if (mp->list_name_len)
47 name = format(0, "%s", mp->list_name);
49 pot_profile_list_init(name);
51 profile = pot_profile_find(id);
53 rv = pot_profile_create(profile,
54 clib_net_to_host_u64(mp->prime),
55 clib_net_to_host_u64(mp->polynomial_public),
56 clib_net_to_host_u64(mp->lpc),
57 clib_net_to_host_u64(mp->secret_share));
60 if (1 == mp->validator)
61 (void)pot_set_validator(profile, clib_net_to_host_u64(mp->secret_key));
62 (void)pot_profile_set_bit_mask(profile, mp->max_bits);
68 REPLY_MACRO(VL_API_POT_PROFILE_ADD_REPLY);
71 static void send_pot_profile_details(vl_api_pot_profile_show_config_dump_t *mp, u8 id)
73 vl_api_pot_profile_show_config_details_t * rmp;
74 pot_main_t * sm = &pot_main;
75 pot_profile *profile = pot_profile_find(id);
78 REPLY_MACRO2(VL_API_POT_PROFILE_SHOW_CONFIG_DETAILS,
80 rmp->validator=profile->validator;
81 rmp->secret_key=clib_host_to_net_u64(profile->secret_key);
82 rmp->secret_share=clib_host_to_net_u64(profile->secret_share);
83 rmp->prime=clib_host_to_net_u64(profile->prime);
84 rmp->bit_mask=clib_host_to_net_u64(profile->bit_mask);
85 rmp->lpc=clib_host_to_net_u64(profile->lpc);
86 rmp->polynomial_public=clib_host_to_net_u64(profile->poly_pre_eval);
90 REPLY_MACRO2(VL_API_POT_PROFILE_SHOW_CONFIG_DETAILS,
98 rmp->polynomial_public=0;
103 static void vl_api_pot_profile_show_config_dump_t_handler
104 (vl_api_pot_profile_show_config_dump_t *mp)
107 u8 dump_call_id = ~0;
108 if(dump_call_id==id){
109 for(id=0;id<MAX_POT_PROFILES;id++)
110 send_pot_profile_details(mp,id);
113 send_pot_profile_details(mp,id);
116 static void vl_api_pot_profile_activate_t_handler
117 (vl_api_pot_profile_activate_t *mp)
119 pot_main_t * sm = &pot_main;
121 vl_api_pot_profile_add_reply_t * rmp;
125 if (mp->list_name_len)
126 name = format(0, "%s", mp->list_name);
127 if (!pot_profile_list_is_enabled(name)) {
131 rv = pot_profile_set_active(id);
135 REPLY_MACRO(VL_API_POT_PROFILE_ACTIVATE_REPLY);
139 static void vl_api_pot_profile_del_t_handler
140 (vl_api_pot_profile_del_t *mp)
142 pot_main_t * sm = &pot_main;
144 vl_api_pot_profile_del_reply_t * rmp;
146 clear_pot_profiles();
148 REPLY_MACRO(VL_API_POT_PROFILE_DEL_REPLY);
151 #include <ioam/lib-pot/pot.api.c>
152 static clib_error_t * pot_init (vlib_main_t * vm)
154 pot_main_t * sm = &pot_main;
156 bzero(sm, sizeof(pot_main));
157 (void)pot_util_init();
160 sm->vnet_main = vnet_get_main();
162 /* Ask for a correctly-sized block of API message decode slots */
163 sm->msg_id_base = setup_message_id_table ();
168 VLIB_INIT_FUNCTION (pot_init);