FD.io VPP  v21.10.1-2-g0a485f517
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 */
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
35 
38 {
39  pot_main_t * sm = &pot_main;
40  int rv = 0;
41  vl_api_pot_profile_add_reply_t * rmp;
42  u8 id;
43  pot_profile *profile = NULL;
44  u8 *name = 0;
45 
47 
49  id = mp->id;
50  profile = pot_profile_find(id);
51  if (profile) {
52  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  if (rv != 0)
58  goto ERROROUT;
59  if (1 == mp->validator)
60  (void)pot_set_validator(profile, clib_net_to_host_u64(mp->secret_key));
61  (void)pot_profile_set_bit_mask(profile, mp->max_bits);
62  } else {
63  rv = -3;
64  }
65  ERROROUT:
66  vec_free(name);
67  REPLY_MACRO(VL_API_POT_PROFILE_ADD_REPLY);
68 }
69 
71 {
73  pot_main_t * sm = &pot_main;
74  pot_profile *profile = pot_profile_find(id);
75  int rv = 0;
76  if(profile){
77  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  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 
104 {
105  u8 id = mp->id;
106  u8 dump_call_id = ~0;
107  if(dump_call_id==id){
108  for(id=0;id<MAX_POT_PROFILES;id++)
110  }
111  else
113 }
114 
117 {
118  pot_main_t * sm = &pot_main;
119  int rv = 0;
120  vl_api_pot_profile_add_reply_t * rmp;
121  u8 id;
122  u8 *name = NULL;
123 
126  rv = -1;
127  } else {
128  id = mp->id;
130  }
131 
132  vec_free(name);
133  REPLY_MACRO(VL_API_POT_PROFILE_ACTIVATE_REPLY);
134 }
135 
136 
139 {
140  pot_main_t * sm = &pot_main;
141  int rv = 0;
142  vl_api_pot_profile_del_reply_t * rmp;
143 
145 
146  REPLY_MACRO(VL_API_POT_PROFILE_DEL_REPLY);
147 }
148 
149 #include <ioam/lib-pot/pot.api.c>
151 {
152  pot_main_t * sm = &pot_main;
153 
154  bzero(sm, sizeof(pot_main));
155  (void)pot_util_init();
156 
157  sm->vlib_main = vm;
158  sm->vnet_main = vnet_get_main();
159 
160  /* Ask for a correctly-sized block of API message decode slots */
162 
163  return 0;
164 }
165 
pot_profile_list_is_enabled
int pot_profile_list_is_enabled(u8 *name)
Definition: pot_util.c:79
api.h
REPLY_MACRO2
#define REPLY_MACRO2(t, body)
Definition: api_helper_macros.h:65
vl_api_pot_profile_add_t::secret_key
u64 secret_key
Definition: pot.api:35
vl_api_pot_profile_del_t
Delete POT Profile.
Definition: pot.api:60
name
string name[64]
Definition: fib.api:25
vl_api_pot_profile_show_config_details_t::id
u8 id
Definition: pot.api:92
pot_util.h
pot_profile_find
pot_profile * pot_profile_find(u8 id)
Definition: pot_util.c:58
vl_api_pot_profile_add_t::prime
u64 prime
Definition: pot.api:37
send_pot_profile_details
static void send_pot_profile_details(vl_api_pot_profile_show_config_dump_t *mp, u8 id)
Definition: pot_api.c:70
vl_api_pot_profile_add_t::list_name
string list_name[]
Definition: pot.api:41
pot_main
pot_main_t pot_main
Definition: pot_util.c:23
vl_api_pot_profile_activate_t::list_name
string list_name[]
Definition: pot.api:52
vl_api_pot_profile_show_config_dump_t::id
u8 id
Definition: pot.api:74
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
api.h
vl_api_pot_profile_show_config_details_t::prime
u64 prime
Definition: pot.api:96
vl_api_pot_profile_show_config_details_t::polynomial_public
u64 polynomial_public
Definition: pot.api:99
pot_profile_::lpc
u64 lpc
Definition: pot_util.h:64
vl_api_pot_profile_add_t::validator
u8 validator
Definition: pot.api:34
pot_profile_::prime
u64 prime
Definition: pot_util.h:63
pot_profile_::poly_pre_eval
u64 poly_pre_eval
Definition: pot_util.h:65
MAX_POT_PROFILES
#define MAX_POT_PROFILES
Definition: pot_util.h:28
vl_api_pot_profile_activate_t
Proof of Transit(POT): Activate POT profile in the list.
Definition: pot.api:48
vl_api_pot_profile_del_t_handler
static void vl_api_pot_profile_del_t_handler(vl_api_pot_profile_del_t *mp)
Definition: pot_api.c:138
vl_api_pot_profile_show_config_details_t::secret_key
u64 secret_key
Definition: pot.api:94
vl_api_pot_profile_show_config_details_t::bit_mask
u64 bit_mask
Definition: pot.api:97
pot_main_t::vnet_main
vnet_main_t * vnet_main
Definition: pot_util.h:84
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
vl_api_pot_profile_add_t::max_bits
u8 max_bits
Definition: pot.api:38
vl_api_pot_profile_add_t::lpc
u64 lpc
Definition: pot.api:39
vl_api_pot_profile_show_config_dump_t_handler
static void vl_api_pot_profile_show_config_dump_t_handler(vl_api_pot_profile_show_config_dump_t *mp)
Definition: pot_api.c:103
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: sr_mpls_api.c:174
pot_main_t::msg_id_base
u16 msg_id_base
Definition: pot_util.h:80
vl_api_pot_profile_show_config_details_t::lpc
u64 lpc
Definition: pot.api:98
vl_api_pot_profile_add_t::secret_share
u64 secret_share
Definition: pot.api:36
vl_api_pot_profile_show_config_details_t::secret_share
u64 secret_share
Definition: pot.api:95
vl_api_pot_profile_add_t_handler
static void vl_api_pot_profile_add_t_handler(vl_api_pot_profile_add_t *mp)
Definition: pot_api.c:37
vl_api_pot_profile_activate_t::id
u8 id
Definition: pot.api:51
pot_profile_::validator
u8 validator
Definition: pot_util.h:60
pot_main_t::vlib_main
vlib_main_t * vlib_main
Definition: pot_util.h:83
vl_api_pot_profile_add_t::polynomial_public
u64 polynomial_public
Definition: pot.api:40
pot_profile_
Usage:
Definition: pot_util.h:54
plugin.h
pot_init
static clib_error_t * pot_init(vlib_main_t *vm)
Definition: pot_api.c:150
id
u8 id[64]
Definition: dhcp.api:160
vl_api_pot_profile_add_t::id
u8 id
Definition: pot.api:33
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
vl_api_pot_profile_add_t
Proof of Transit(POT): Set POT profile.
Definition: pot.api:30
pot_profile_list_init
void pot_profile_list_init(u8 *profile_list_name)
Definition: pot_util.c:85
vl_api_pot_profile_activate_t_handler
static void vl_api_pot_profile_activate_t_handler(vl_api_pot_profile_activate_t *mp)
Definition: pot_api.c:116
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
pot_profile_::secret_share
u64 secret_share
Definition: pot_util.h:62
api_helper_macros.h
pot_util_init
int pot_util_init(void)
Definition: pot_util.c:42
vl_api_pot_profile_show_config_details_t
Show POT profile reply.
Definition: pot.api:89
vl_api_from_api_to_new_vec
u8 * vl_api_from_api_to_new_vec(void *mp, vl_api_string_t *astr)
Definition: api_shared.c:1202
vlib_main_t
Definition: main.h:102
pot_set_validator
int pot_set_validator(pot_profile *profile, u64 key)
Definition: pot_util.c:136
pot_main_t
Definition: pot_util.h:72
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
pot_profile_::secret_key
u64 secret_key
Definition: pot_util.h:61
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
rv
int __clib_unused rv
Definition: application.c:491
pot_profile_::bit_mask
u64 bit_mask
Definition: pot_util.h:66
vnet.h
vl_api_pot_profile_show_config_dump_t
Show POT Profiles.
Definition: pot.api:71
pot_profile_set_active
static int pot_profile_set_active(u8 id)
Definition: pot_util.h:148
pot_profile_create
int pot_profile_create(pot_profile *profile, u64 prime, u64 poly2, u64 lpc, u64 secret_share)
Definition: pot_util.c:117
pot_profile_set_bit_mask
int pot_profile_set_bit_mask(pot_profile *profile, u16 bits)
Definition: pot_util.c:240
clear_pot_profiles
void clear_pot_profiles()
Definition: pot_util.c:264
vl_api_pot_profile_show_config_details_t::validator
u8 validator
Definition: pot.api:93