FD.io VPP  v18.07-34-g55fbdb9
Vector Packet Processing
pot_api.c
Go to the documentation of this file.
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 */
31 
32 /* define message structures */
33 #define vl_typedefs
35 #undef vl_typedefs
36 
37 /* define generated endian-swappers */
38 #define vl_endianfun
40 #undef vl_endianfun
41 
42 /* instantiate all the print functions we know about */
43 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
44 #define vl_printfun
46 #undef vl_printfun
47 
48 /* Get the API version number */
49 #define vl_api_version(n,v) static u32 api_version=(v);
51 #undef vl_api_version
52 
53 #define REPLY_MSG_ID_BASE sm->msg_id_base
55 
56 /* List of message types that this plugin understands */
57 #define foreach_pot_plugin_api_msg \
58 _(POT_PROFILE_ADD, pot_profile_add) \
59 _(POT_PROFILE_ACTIVATE, pot_profile_activate) \
60 _(POT_PROFILE_DEL, pot_profile_del) \
61 _(POT_PROFILE_SHOW_CONFIG_DUMP, pot_profile_show_config_dump) \
62 
65 {
66  pot_main_t * sm = &pot_main;
67  int rv = 0;
68  vl_api_pot_profile_add_reply_t * rmp;
69  u8 id;
70  pot_profile *profile = NULL;
71  u8 *name = 0;
72 
73  if (mp->list_name_len)
74  name = format(0, "%s", mp->list_name);
75 
77  id = mp->id;
78  profile = pot_profile_find(id);
79  if (profile) {
80  rv = pot_profile_create(profile,
81  clib_net_to_host_u64(mp->prime),
82  clib_net_to_host_u64(mp->polynomial_public),
83  clib_net_to_host_u64(mp->lpc),
84  clib_net_to_host_u64(mp->secret_share));
85  if (rv != 0)
86  goto ERROROUT;
87  if (1 == mp->validator)
88  (void)pot_set_validator(profile, clib_net_to_host_u64(mp->secret_key));
89  (void)pot_profile_set_bit_mask(profile, mp->max_bits);
90  } else {
91  rv = -3;
92  }
93  ERROROUT:
94  vec_free(name);
95  REPLY_MACRO(VL_API_POT_PROFILE_ADD_REPLY);
96 }
97 
99 {
101  pot_main_t * sm = &pot_main;
102  pot_profile *profile = pot_profile_find(id);
103  int rv = 0;
104  if(profile){
105  REPLY_MACRO2(VL_API_POT_PROFILE_SHOW_CONFIG_DETAILS,
106  rmp->id=id;
107  rmp->validator=profile->validator;
108  rmp->secret_key=clib_host_to_net_u64(profile->secret_key);
109  rmp->secret_share=clib_host_to_net_u64(profile->secret_share);
110  rmp->prime=clib_host_to_net_u64(profile->prime);
111  rmp->bit_mask=clib_host_to_net_u64(profile->bit_mask);
112  rmp->lpc=clib_host_to_net_u64(profile->lpc);
113  rmp->polynomial_public=clib_host_to_net_u64(profile->poly_pre_eval);
114  );
115  }
116  else{
117  REPLY_MACRO2(VL_API_POT_PROFILE_SHOW_CONFIG_DETAILS,
118  rmp->id=id;
119  rmp->validator=0;
120  rmp->secret_key=0;
121  rmp->secret_share=0;
122  rmp->prime=0;
123  rmp->bit_mask=0;
124  rmp->lpc=0;
125  rmp->polynomial_public=0;
126  );
127  }
128 }
129 
132 {
133  u8 id = mp->id;
134  u8 dump_call_id = ~0;
135  if(dump_call_id==id){
136  for(id=0;id<MAX_POT_PROFILES;id++)
138  }
139  else
141 }
142 
145 {
146  pot_main_t * sm = &pot_main;
147  int rv = 0;
148  vl_api_pot_profile_add_reply_t * rmp;
149  u8 id;
150  u8 *name = NULL;
151 
152  if (mp->list_name_len)
153  name = format(0, "%s", mp->list_name);
154  if (!pot_profile_list_is_enabled(name)) {
155  rv = -1;
156  } else {
157  id = mp->id;
158  rv = pot_profile_set_active(id);
159  }
160 
161  vec_free(name);
162  REPLY_MACRO(VL_API_POT_PROFILE_ACTIVATE_REPLY);
163 }
164 
165 
168 {
169  pot_main_t * sm = &pot_main;
170  int rv = 0;
171  vl_api_pot_profile_del_reply_t * rmp;
172 
174 
175  REPLY_MACRO(VL_API_POT_PROFILE_DEL_REPLY);
176 }
177 
178 /* Set up the API message handling tables */
179 static clib_error_t *
181 {
182  pot_main_t * sm = &pot_main;
183 #define _(N,n) \
184  vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
185  #n, \
186  vl_api_##n##_t_handler, \
187  vl_noop_handler, \
188  vl_api_##n##_t_endian, \
189  vl_api_##n##_t_print, \
190  sizeof(vl_api_##n##_t), 1);
192 #undef _
193 
194  return 0;
195 }
196 
197 #define vl_msg_name_crc_list
199 #undef vl_msg_name_crc_list
200 
201 static void
203 {
204 #define _(id,n,crc) \
205  vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base);
206  foreach_vl_msg_name_crc_pot;
207 #undef _
208 }
209 
211 {
212  pot_main_t * sm = &pot_main;
213  clib_error_t * error = 0;
214  u8 * name;
215 
216  bzero(sm, sizeof(pot_main));
217  (void)pot_util_init();
218 
219  sm->vlib_main = vm;
220  sm->vnet_main = vnet_get_main();
221 
222  name = format (0, "ioam_pot_%08x%c", api_version, 0);
223 
224  /* Ask for a correctly-sized block of API message decode slots */
226  ((char *) name, VL_MSG_FIRST_AVAILABLE);
227 
228  error = pot_plugin_api_hookup (vm);
229 
230  /* Add our API messages to the global name_crc hash table */
232 
233  vec_free(name);
234 
235  return error;
236 }
237 
pot_main_t pot_main
Definition: pot_util.c:23
void clear_pot_profiles()
Definition: pot_util.c:264
static clib_error_t * pot_plugin_api_hookup(vlib_main_t *vm)
Definition: pot_api.c:180
pot_profile * pot_profile_find(u8 id)
Definition: pot_util.c:58
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
int pot_profile_create(pot_profile *profile, u64 prime, u64 poly2, u64 lpc, u64 secret_share)
Definition: pot_util.c:117
Proof of Transit(POT): Set POT profile.
Definition: pot.api:31
#define REPLY_MACRO2(t, body)
#define NULL
Definition: clib.h:55
static clib_error_t * pot_init(vlib_main_t *vm)
Definition: pot_api.c:210
vnet_main_t * vnet_main
Definition: pot_util.h:84
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
u8 list_name[list_name_len]
Definition: pot.api:43
u64 secret_share
Definition: pot_util.h:62
unsigned char u8
Definition: types.h:56
static int pot_profile_set_active(u8 id)
Definition: pot_util.h:148
#define MAX_POT_PROFILES
Definition: pot_util.h:28
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:156
u64 poly_pre_eval
Definition: pot_util.h:65
Show POT profile reply.
Definition: pot.api:95
#define REPLY_MACRO(t)
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:201
static void vl_api_pot_profile_del_t_handler(vl_api_pot_profile_del_t *mp)
Definition: pot_api.c:167
vlib_main_t * vlib_main
Definition: pot_util.h:83
vlib_main_t * vm
Definition: buffer.c:294
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:339
Usage:
Definition: pot_util.h:54
static void vl_api_pot_profile_show_config_dump_t_handler(vl_api_pot_profile_show_config_dump_t *mp)
Definition: pot_api.c:131
u8 list_name[list_name_len]
Definition: pot.api:56
#define foreach_pot_plugin_api_msg
Definition: pot_api.c:57
u64 secret_key
Definition: pot_util.h:61
int pot_set_validator(pot_profile *profile, u64 key)
Definition: pot_util.c:136
int pot_util_init(void)
Definition: pot_util.c:42
u16 msg_id_base
Definition: pot_util.h:80
Delete POT Profile.
Definition: pot.api:65
u8 validator
Definition: pot_util.h:60
static void vl_api_pot_profile_activate_t_handler(vl_api_pot_profile_activate_t *mp)
Definition: pot_api.c:144
void pot_profile_list_init(u8 *profile_list_name)
Definition: pot_util.c:85
int pot_profile_list_is_enabled(u8 *name)
Definition: pot_util.c:79
Proof of Transit(POT): Activate POT profile in the list.
Definition: pot.api:51
static void setup_message_id_table(pot_main_t *sm, api_main_t *am)
Definition: pot_api.c:202
static void send_pot_profile_details(vl_api_pot_profile_show_config_dump_t *mp, u8 id)
Definition: pot_api.c:98
u64 bit_mask
Definition: pot_util.h:66
api_main_t api_main
Definition: api_shared.c:35
u16 vl_msg_api_get_msg_ids(const char *name, int n)
Definition: api_shared.c:872
int pot_profile_set_bit_mask(pot_profile *profile, u16 bits)
Definition: pot_util.c:240
static void vl_api_pot_profile_add_t_handler(vl_api_pot_profile_add_t *mp)
Definition: pot_api.c:64