FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
pot_util.h
Go to the documentation of this file.
1 /*
2  * pot_util.h -- Proof Of Transit Utility Header
3  *
4  * Copyright (c) 2016 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef include_vnet_pot_util_h
19 #define include_vnet_pot_util_h
20 
21 #include <vnet/ip/ip6_hop_by_hop.h>
22 #define debug_ioam debug_ioam_fn
23 /* Dont change this size 256. This is there across multiple components */
24 #define PATH_NAME_SIZE 256
25 
26 /* Ring size. this should be same as the one in ODL. Do not change this
27  without change in ODL. */
28 #define MAX_POT_PROFILES 2
29 
30 /**
31  * Usage:
32  *
33  * On any node that participates in Proof of Transit:
34  *
35  * Step 1: Initialize this library by calling pot_init()
36  * Step 2: Setup a proof of transit profile that contains all the parameters needed to compute cumulative:
37  * Call these functions:
38  * pot_profile_find
39  * pot_profile_create
40  * pot_profile_set_bit_mask - To setup how large we want the numbers used in the computation and random number <= 64 bits
41  * Step 2a: For validator do this:
42  * pot_set_validator
43  * Step 2b: On initial node enable the profile to be used:
44  * pot_profile_set_active / pot_profile_get_active will return the profile
45  * Step 3a: At the initial node to generate Random number that will be read by all other nodes:
46  * pot_generate_random
47  * Step 3b: At all nodes including initial and verifier call this to compute cumulative:
48  * pot_update_cumulative
49  * Step 4: At the verifier:
50  * pot_validate
51  *
52  */
53 
54 typedef struct pot_profile_
55 {
56  u8 id : 1;
57  u8 valid : 1;
58  u8 in_use : 1;
68  double primeinv;
70 } pot_profile;
71 
72 typedef struct {
73  /* Name of the default profile list in use*/
76  /* number of profiles in the list */
78 
79  /* API message ID base */
81 
82  /* convenience */
85 } pot_main_t;
86 
87 extern pot_main_t pot_main;
88 
89 /*
90  * Initialize proof of transit
91  */
92 int pot_util_init(void);
94 
95 
96 /*
97  * Find a pot profile by ID
98  */
100 
101 static inline u16 pot_profile_get_id(pot_profile * profile)
102 {
103  if (profile)
104  {
105  return (profile->id);
106  }
107  return (0);
108 }
109 
110 /* setup and clean up profile */
111 int pot_profile_create(pot_profile * profile, u64 prime,
112  u64 poly2, u64 lpc, u64 secret_share);
113 /*
114  * Setup profile as a validator
115  */
116 int pot_set_validator(pot_profile * profile, u64 key);
117 
118 /*
119  * Setup max bits to be used for random number generation
120  */
121 #define MAX_BITS 64
122 int pot_profile_set_bit_mask(pot_profile * profile, u16 bits);
123 
124 /*
125  * Given a random and cumulative compute the new cumulative for a given profile
126  */
127 u64 pot_update_cumulative(pot_profile * profile, u64 cumulative, u64 random);
128 
129 /*
130  * return True if the cumulative matches secret from a profile
131  */
132 u8 pot_validate(pot_profile * profile, u64 cumulative, u64 random);
133 
134 /*
135  * Utility function to get random number per pack
136  */
138 
139 
140 extern void clear_pot_profiles();
141 extern int pot_profile_list_is_enabled(u8 *name);
142 
143 static inline u8 pot_is_decap(pot_profile * p)
144 {
145  return (p->validator == 1);
146 }
147 
148 static inline int pot_profile_set_active (u8 id)
149 {
150  pot_main_t *sm = &pot_main;
151  pot_profile *profile = NULL;
152  pot_profile *current_active_prof = NULL;
153 
154  current_active_prof = pot_profile_find(sm->active_profile_id);
155  profile = pot_profile_find(id);
156  if (profile && profile->valid) {
157  sm->active_profile_id = id;
158  current_active_prof->in_use = 0;
159  profile->in_use = 1;
160  return(0);
161  }
162  return(-1);
163 }
164 static inline u8 pot_profile_get_active_id (void)
165 {
166  pot_main_t *sm = &pot_main;
167  return (sm->active_profile_id);
168 }
169 
170 static inline pot_profile * pot_profile_get_active (void)
171 {
172  pot_main_t *sm = &pot_main;
173  pot_profile *profile = NULL;
174  profile = pot_profile_find(sm->active_profile_id);
175  if (profile && profile->in_use)
176  return(profile);
177  return (NULL);
178 }
179 
181 {
182  if (pow) {
184  }
185 }
186 
187 static inline void pot_profile_incr_usage_stats (pot_profile *pow)
188 {
189  if (pow) {
191  }
192 }
193 
194 
195 #endif
static pot_profile * pot_profile_get_active(void)
Definition: pot_util.h:170
static u8 pot_profile_get_active_id(void)
Definition: pot_util.h:164
unsigned long u64
Definition: types.h:89
#define NULL
Definition: clib.h:58
int pot_util_init(void)
Definition: pot_util.c:42
vnet_main_t * vnet_main
Definition: pot_util.h:84
u64 secret_share
Definition: pot_util.h:62
int pot_profile_set_bit_mask(pot_profile *profile, u16 bits)
Definition: pot_util.c:240
void clear_pot_profiles()
Definition: pot_util.c:264
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
u8 pot_validate(pot_profile *profile, u64 cumulative, u64 random)
Definition: pot_util.c:197
pot_profile * pot_profile_find(u8 id)
Definition: pot_util.c:58
struct pot_profile_ pot_profile
Usage:
int pot_profile_create(pot_profile *profile, u64 prime, u64 poly2, u64 lpc, u64 secret_share)
Definition: pot_util.c:117
double primeinv
Definition: pot_util.h:68
u64 poly_pre_eval
Definition: pot_util.h:65
int pot_profile_list_is_enabled(u8 *name)
Definition: pot_util.c:79
unsigned short u16
Definition: types.h:57
u8 active_profile_id
Definition: pot_util.h:77
u8 name[64]
Definition: memclnt.api:152
void pot_profile_list_init(u8 *name)
Definition: pot_util.c:85
vlib_main_t * vlib_main
Definition: pot_util.h:83
static void pot_profile_reset_usage_stats(pot_profile *pow)
Definition: pot_util.h:180
u64 total_pkts_using_this_profile
Definition: pot_util.h:69
pot_main_t pot_main
Definition: pot_util.c:23
Usage:
Definition: pot_util.h:54
u64 pot_update_cumulative(pot_profile *profile, u64 cumulative, u64 random)
Definition: pot_util.c:169
static void pot_profile_incr_usage_stats(pot_profile *pow)
Definition: pot_util.h:187
u64 secret_key
Definition: pot_util.h:61
u8 * profile_list_name
Definition: pot_util.h:74
u16 msg_id_base
Definition: pot_util.h:80
static u16 pot_profile_get_id(pot_profile *profile)
Definition: pot_util.h:101
u64 pot_generate_random(pot_profile *profile)
Definition: pot_util.c:210
typedef key
Definition: ipsec.api:244
u8 validator
Definition: pot_util.h:60
static u8 pot_is_decap(pot_profile *p)
Definition: pot_util.h:143
u64 random
Definition: pot_util.h:59
u64 bit_mask
Definition: pot_util.h:66
int pot_set_validator(pot_profile *profile, u64 key)
Definition: pot_util.c:136