FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
feature.h
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 #ifndef included_features_h
17 #define included_features_h
18 
19 #include <vnet/vnet.h>
20 #include <vnet/api_errno.h>
21 #include <vnet/devices/devices.h>
22 
23 /** feature registration object */
24 typedef struct _vnet_feature_arc_registration
25 {
26  /** next registration in list of all registrations*/
27  struct _vnet_feature_arc_registration *next;
28  /** Feature Arc name */
29  char *arc_name;
30  /** Start nodes */
31  char **start_nodes;
32  int n_start_nodes;
33  /** End of the arc (optional, for consistency-checking) */
34  char *last_in_arc;
35  /* Feature arc index, assigned by init function */
36  u8 feature_arc_index;
37  u8 *arc_index_ptr;
39 
40 /* Enable feature callback. */
42  (u32 sw_if_index, int enable_disable);
43 
44 /** feature registration object */
45 typedef struct _vnet_feature_registration
46 {
47  /** next registration in list of all registrations*/
48  struct _vnet_feature_registration *next, *next_in_arc;
49  /** Feature arc name */
50  char *arc_name;
51  /** Graph node name */
52  char *node_name;
53  /** Pointer to this feature index, filled in by vnet_feature_arc_init */
54  u32 *feature_index_ptr;
55  u32 feature_index;
56  /** Constraints of the form "this feature runs before X" */
57  char **runs_before;
58  /** Constraints of the form "this feature runs after Y" */
59  char **runs_after;
60 
61  /** Function to enable/disable feature **/
62  vnet_feature_enable_disable_function_t *enable_disable_cb;
64 
65 /** constraint registration object */
66 typedef struct _vnet_feature_constraint_registration
67 {
68  /** next constraint set in list of all registrations*/
69  struct _vnet_feature_constraint_registration *next, *next_in_arc;
70  /** Feature arc name */
71  char *arc_name;
72 
73  /** Feature arc index, assigned by init function */
74  u8 feature_arc_index;
75 
76  /** Node names, to run in the specified order */
77  char **node_names;
79 
81 {
85 
86 typedef struct
87 {
88  /** feature arc configuration list */
91 
92  /** feature path configuration lists */
98 
99  /** feature config main objects */
101 
102  /** Save partial order results for show command */
103  char ***feature_nodes;
104 
105  /** bitmap of interfaces which have driver rx features configured */
107 
108  /** feature reference counts by interface */
110 
111  /** Feature arc index for device-input */
113 
114  /** convenience */
118 
120 
121 #ifndef CLIB_MARCH_VARIANT
122 #define VNET_FEATURE_ARC_INIT(x,...) \
123  __VA_ARGS__ vnet_feature_arc_registration_t vnet_feat_arc_##x;\
124 static void __vnet_add_feature_arc_registration_##x (void) \
125  __attribute__((__constructor__)) ; \
126 static void __vnet_add_feature_arc_registration_##x (void) \
127 { \
128  vnet_feature_main_t * fm = &feature_main; \
129  vnet_feat_arc_##x.next = fm->next_arc; \
130  fm->next_arc = & vnet_feat_arc_##x; \
131 } \
132 static void __vnet_rm_feature_arc_registration_##x (void) \
133  __attribute__((__destructor__)) ; \
134 static void __vnet_rm_feature_arc_registration_##x (void) \
135 { \
136  vnet_feature_main_t * fm = &feature_main; \
137  vnet_feature_arc_registration_t *r = &vnet_feat_arc_##x; \
138  VLIB_REMOVE_FROM_LINKED_LIST (fm->next_arc, r, next); \
139 } \
140 __VA_ARGS__ vnet_feature_arc_registration_t vnet_feat_arc_##x
141 
142 #define VNET_FEATURE_INIT(x,...) \
143  __VA_ARGS__ vnet_feature_registration_t vnet_feat_##x; \
144 static void __vnet_add_feature_registration_##x (void) \
145  __attribute__((__constructor__)) ; \
146 static void __vnet_add_feature_registration_##x (void) \
147 { \
148  vnet_feature_main_t * fm = &feature_main; \
149  vnet_feat_##x.next = fm->next_feature; \
150  fm->next_feature = & vnet_feat_##x; \
151 } \
152 static void __vnet_rm_feature_registration_##x (void) \
153  __attribute__((__destructor__)) ; \
154 static void __vnet_rm_feature_registration_##x (void) \
155 { \
156  vnet_feature_main_t * fm = &feature_main; \
157  vnet_feature_registration_t *r = &vnet_feat_##x; \
158  VLIB_REMOVE_FROM_LINKED_LIST (fm->next_feature, r, next); \
159 } \
160 __VA_ARGS__ vnet_feature_registration_t vnet_feat_##x
161 
162 #define VNET_FEATURE_ARC_ORDER(x,...) \
163  __VA_ARGS__ vnet_feature_constraint_registration_t \
164 vnet_feature_constraint_##x; \
165 static void __vnet_add_constraint_registration_##x (void) \
166  __attribute__((__constructor__)) ; \
167 static void __vnet_add_constraint_registration_##x (void) \
168 { \
169  vnet_feature_main_t * fm = &feature_main; \
170  vnet_feature_constraint_##x.next = fm->next_constraint; \
171  fm->next_constraint = & vnet_feature_constraint_##x; \
172 } \
173 static void __vnet_rm_constraint_registration_##x (void) \
174  __attribute__((__destructor__)) ; \
175 static void __vnet_rm_constraint_registration_##x (void) \
176 { \
177  vnet_feature_main_t * fm = &feature_main; \
178  vnet_feature_constraint_registration_t *r = &vnet_feature_constraint_##x; \
179  VLIB_REMOVE_FROM_LINKED_LIST (fm->next_constraint, r, next); \
180 } \
181 __VA_ARGS__ vnet_feature_constraint_registration_t vnet_feature_constraint_##x
182 
183 #else
184 #define VNET_FEATURE_ARC_INIT(x,...) \
185 extern vnet_feature_arc_registration_t __clib_unused vnet_feat_arc_##x; \
186 static vnet_feature_arc_registration_t __clib_unused __clib_unused_vnet_feat_arc_##x
187 #define VNET_FEATURE_INIT(x,...) \
188 extern vnet_feature_registration_t __clib_unused vnet_feat_##x; \
189 static vnet_feature_registration_t __clib_unused __clib_unused_vnet_feat_##x
190 
191 #define VNET_FEATURE_ARC_ORDER(x,...) \
192 extern vnet_feature_constraint_registration_t \
193 __clib_unused vnet_feature_constraint_##x; \
194 static vnet_feature_constraint_registration_t __clib_unused \
195 __clib_unused_vnet_feature_constraint_##x
196 
197 
198 #endif
199 
200 void
202  u32 sw_if_index, int is_add);
203 
204 u32 vnet_get_feature_index (u8 arc, const char *s);
205 u8 vnet_get_feature_arc_index (const char *s);
207  const char *node_name);
208 
209 
210 int
212  u32 sw_if_index, int enable_disable,
213  void *feature_config,
214  u32 n_feature_config_bytes);
215 
216 int
217 vnet_feature_enable_disable (const char *arc_name, const char *node_name,
218  u32 sw_if_index, int enable_disable,
219  void *feature_config,
220  u32 n_feature_config_bytes);
221 
222 u32
224 
227 {
230 }
231 
232 static inline vnet_feature_config_main_t *
234 {
236 
237  if (arc_index == (u8) ~ 0)
238  return 0;
239 
241 }
242 
245 {
247  return &fm->feature_config_mains[arc];
248 }
249 
252 {
255 }
256 
259 {
263 }
264 
267  vlib_buffer_t * b, u32 n_data_bytes)
268 {
272 
274  {
275  vnet_buffer (b)->feature_arc_index = arc;
279  next, n_data_bytes);
280  }
281  return 0;
282 }
283 
287  u32 * next,
288  vlib_buffer_t * b, u32 cfg_index)
289 {
293 
294  vnet_buffer (b)->feature_arc_index = arc;
295  b->current_config_index = cfg_index;
296 
298  next, 0);
299 }
300 
303  vlib_buffer_t * b0)
304 {
306 }
307 
310  u32 n_data_bytes)
311 {
313  u8 arc = vnet_buffer (b0)->feature_arc_index;
315 
317  &b0->current_config_index, next0,
318  n_data_bytes);
319 }
320 
323 {
324  vnet_feature_next_with_data (next0, b0, 0);
325 }
326 
329 {
330  u32 next32;
331  vnet_feature_next_with_data (&next32, b0, 0);
332  *next0 = next32;
333 }
334 
337 {
340 }
341 
344  vlib_buffer_t * b0)
345 {
348  u8 feature_arc_index = fm->device_input_feature_arc_index;
349  cm = &fm->feature_config_mains[feature_arc_index];
350 
351  if (PREDICT_FALSE
353  (fm->sw_if_index_has_features[feature_arc_index], sw_if_index)))
354  {
355  /*
356  * Save next0 so that the last feature in the chain
357  * can skip ethernet-input if indicated...
358  */
359  u16 adv;
360 
361  adv = device_input_next_node_advance[*next0];
362  vlib_buffer_advance (b0, -adv);
363 
364  vnet_buffer (b0)->feature_arc_index = feature_arc_index;
368  next0, /* # bytes of config data */ 0);
369  }
370 }
371 
374  u32 * next0,
375  u32 * next1,
376  vlib_buffer_t * b0, vlib_buffer_t * b1)
377 {
380  u8 feature_arc_index = fm->device_input_feature_arc_index;
381  cm = &fm->feature_config_mains[feature_arc_index];
382 
383  if (PREDICT_FALSE
385  (fm->sw_if_index_has_features[feature_arc_index], sw_if_index)))
386  {
387  /*
388  * Save next0 so that the last feature in the chain
389  * can skip ethernet-input if indicated...
390  */
391  u16 adv;
392 
393  adv = device_input_next_node_advance[*next0];
394  vlib_buffer_advance (b0, -adv);
395 
396  adv = device_input_next_node_advance[*next1];
397  vlib_buffer_advance (b1, -adv);
398 
399  vnet_buffer (b0)->feature_arc_index = feature_arc_index;
400  vnet_buffer (b1)->feature_arc_index = feature_arc_index;
405  next0, /* # bytes of config data */ 0);
407  next1, /* # bytes of config data */ 0);
408  }
409 }
410 
413  u32 * next0,
414  u32 * next1,
415  u32 * next2,
416  u32 * next3,
417  vlib_buffer_t * b0,
418  vlib_buffer_t * b1,
419  vlib_buffer_t * b2, vlib_buffer_t * b3)
420 {
423  u8 feature_arc_index = fm->device_input_feature_arc_index;
424  cm = &fm->feature_config_mains[feature_arc_index];
425 
426  if (PREDICT_FALSE
428  (fm->sw_if_index_has_features[feature_arc_index], sw_if_index)))
429  {
430  /*
431  * Save next0 so that the last feature in the chain
432  * can skip ethernet-input if indicated...
433  */
434  u16 adv;
435 
436  adv = device_input_next_node_advance[*next0];
437  vlib_buffer_advance (b0, -adv);
438 
439  adv = device_input_next_node_advance[*next1];
440  vlib_buffer_advance (b1, -adv);
441 
442  adv = device_input_next_node_advance[*next2];
443  vlib_buffer_advance (b2, -adv);
444 
445  adv = device_input_next_node_advance[*next3];
446  vlib_buffer_advance (b3, -adv);
447 
448  vnet_buffer (b0)->feature_arc_index = feature_arc_index;
449  vnet_buffer (b1)->feature_arc_index = feature_arc_index;
450  vnet_buffer (b2)->feature_arc_index = feature_arc_index;
451  vnet_buffer (b3)->feature_arc_index = feature_arc_index;
452 
458 
460  next0, /* # bytes of config data */ 0);
462  next1, /* # bytes of config data */ 0);
464  next2, /* # bytes of config data */ 0);
466  next3, /* # bytes of config data */ 0);
467  }
468 }
469 
470 #define VNET_FEATURES(...) (char*[]) { __VA_ARGS__, 0}
471 
473  (vlib_main_t * vm,
474  vnet_config_main_t * vcm,
475  char **feature_start_nodes,
476  int num_feature_start_nodes,
477  char *last_in_arc,
478  vnet_feature_registration_t * first_reg,
479  vnet_feature_constraint_registration_t * first_const_set,
480  char ***in_feature_nodes);
481 
483  int verbose);
484 
486  u8 arc_index,
487  u8 is_enable, void *cb);
488 
489 extern void vnet_feature_register (vnet_feature_update_cb_t cb, void *data);
490 
491 int
492 vnet_feature_is_enabled (const char *arc_name, const char *feature_node_name,
493  u32 sw_if_index);
494 
495 #endif /* included_feature_h */
496 
497 /*
498  * fd.io coding-style-patch-verification: ON
499  *
500  * Local Variables:
501  * eval: (c-set-style "gnu")
502  * End:
503  */
vnet_feature_config_main_t_
Definition: feature.h:80
device_input_next_node_advance
const u32 device_input_next_node_advance[((VNET_DEVICE_INPUT_N_NEXT_NODES/CLIB_CACHE_LINE_BYTES)+1) *CLIB_CACHE_LINE_BYTES]
Definition: devices.c:47
vnet_feature_main_t::sw_if_index_has_features
uword ** sw_if_index_has_features
bitmap of interfaces which have driver rx features configured
Definition: feature.h:106
vnet_feature_config_main_t_::config_main
vnet_config_main_t config_main
Definition: feature.h:82
vnet_have_features
static_always_inline int vnet_have_features(u8 arc, u32 sw_if_index)
Definition: feature.h:251
vnet_feature_config_main_t
struct vnet_feature_config_main_t_ vnet_feature_config_main_t
vnet_feature_arc_init
clib_error_t * vnet_feature_arc_init(vlib_main_t *vm, vnet_config_main_t *vcm, char **feature_start_nodes, int num_feature_start_nodes, char *last_in_arc, vnet_feature_registration_t *first_reg, vnet_feature_constraint_registration_t *first_const_set, char ***in_feature_nodes)
Initialize a feature graph arc.
Definition: registration.c:121
vnet_feature_modify_end_node
u32 vnet_feature_modify_end_node(u8 arc_index, u32 sw_if_index, u32 node_index)
Definition: feature.c:380
vnet_get_feature_arc_index
u8 vnet_get_feature_arc_index(const char *s)
Definition: feature.c:197
next
u16 * next
Definition: nat44_ei_out2in.c:718
vnet_device_input_have_features
static_always_inline int vnet_device_input_have_features(u32 sw_if_index)
Definition: feature.h:336
vnet_config_update_feature_count
void vnet_config_update_feature_count(vnet_feature_main_t *fm, u8 arc, u32 sw_if_index, int is_add)
u16
unsigned short u16
Definition: types.h:57
vnet_feature_config_main_t_::config_index_by_sw_if_index
u32 * config_index_by_sw_if_index
Definition: feature.h:83
vnet_feature_enable_disable_function_t
clib_error_t *() vnet_feature_enable_disable_function_t(u32 sw_if_index, int enable_disable)
Definition: feature.h:42
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
vnet_feature_registration_t
struct _vnet_feature_registration vnet_feature_registration_t
feature registration object
fm
vnet_feature_main_t * fm
Definition: nat44_ei_hairpinning.c:589
node_index
node node_index
Definition: interface_output.c:420
vnet_feature_is_enabled
int vnet_feature_is_enabled(const char *arc_name, const char *feature_node_name, u32 sw_if_index)
Definition: feature.c:324
vnet_feature_next_with_data
static_always_inline void * vnet_feature_next_with_data(u32 *next0, vlib_buffer_t *b0, u32 n_data_bytes)
Definition: feature.h:309
vnet_feature_main_t::next_feature
vnet_feature_registration_t * next_feature
feature path configuration lists
Definition: feature.h:93
vnet_feature_main_t::feature_nodes
char *** feature_nodes
Save partial order results for show command.
Definition: feature.h:103
vnet_feature_main_t::vlib_main
vlib_main_t * vlib_main
convenience
Definition: feature.h:115
vnet_feature_arc_start_w_cfg_index
static_always_inline void * vnet_feature_arc_start_w_cfg_index(u8 arc, u32 sw_if_index, u32 *next, vlib_buffer_t *b, u32 cfg_index)
Definition: feature.h:285
vnet_feature_main_t::next_constraint
vnet_feature_constraint_registration_t * next_constraint
Definition: feature.h:95
vnet_feature_main_t::vnet_main
vnet_main_t * vnet_main
Definition: feature.h:116
vec_elt
#define vec_elt(v, i)
Get vector value at index i.
Definition: vec_bootstrap.h:210
i16
signed short i16
Definition: types.h:46
vnet_get_feature_count
static_always_inline u32 vnet_get_feature_count(u8 arc, u32 sw_if_index)
Definition: feature.h:226
vlib_buffer_advance
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:276
vnet_feature_start_device_input_x2
static_always_inline void vnet_feature_start_device_input_x2(u32 sw_if_index, u32 *next0, u32 *next1, vlib_buffer_t *b0, vlib_buffer_t *b1)
Definition: feature.h:373
clib_bitmap_get
static uword clib_bitmap_get(uword *ai, uword i)
Gets the ith bit value from a bitmap.
Definition: bitmap.h:197
vnet_interface_features_show
void vnet_interface_features_show(vlib_main_t *vm, u32 sw_if_index, int verbose)
Display the set of driver features configured on a specific interface Called by "show interface" hand...
Definition: feature.c:491
vnet_feature_enable_disable_with_index
int vnet_feature_enable_disable_with_index(u8 arc_index, u32 feature_index, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
Definition: feature.c:251
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:437
feature_main
vnet_feature_main_t feature_main
Definition: pnat_test_stubs.h:27
vnet_feature_next_u16
static_always_inline void vnet_feature_next_u16(u16 *next0, vlib_buffer_t *b0)
Definition: feature.h:328
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
vnet_feature_next
static_always_inline void vnet_feature_next(u32 *next0, vlib_buffer_t *b0)
Definition: feature.h:322
static_always_inline
#define static_always_inline
Definition: clib.h:112
uword
u64 uword
Definition: types.h:112
arc_index
u8 arc_index
Definition: nat44_ei_hairpinning.c:590
vnet_feature_register
void vnet_feature_register(vnet_feature_update_cb_t cb, void *data)
Definition: feature.c:29
vnet_feature_main_t::next_feature_by_name
uword ** next_feature_by_name
Definition: feature.h:97
cm
vnet_feature_config_main_t * cm
Definition: nat44_ei_hairpinning.c:591
data
u8 data[128]
Definition: ipsec_types.api:92
vlib_buffer_t::current_config_index
u32 current_config_index
Used by feature subgraph arcs to visit enabled feature nodes.
Definition: buffer.h:156
arc
u8 arc
Definition: interface_output.c:406
vnet_main_t
Definition: vnet.h:76
vnet_config_main_t
Definition: config.h:86
vnet_feature_update_cb_t
void(* vnet_feature_update_cb_t)(u32 sw_if_index, u8 arc_index, u8 is_enable, void *cb)
Definition: feature.h:485
vnet_feature_main_t::feature_count_by_sw_if_index
i16 ** feature_count_by_sw_if_index
feature reference counts by interface
Definition: feature.h:109
u32
unsigned int u32
Definition: types.h:88
vnet_feature_main_t::next_constraint_by_arc
vnet_feature_constraint_registration_t ** next_constraint_by_arc
Definition: feature.h:96
vnet_feature_main_t::next_arc
vnet_feature_arc_registration_t * next_arc
feature arc configuration list
Definition: feature.h:89
vnet_get_feature_config_index
static_always_inline u32 vnet_get_feature_config_index(u8 arc, u32 sw_if_index)
Definition: feature.h:258
vnet_get_feature_index
u32 vnet_get_feature_index(u8 arc, const char *s)
Definition: feature.c:233
vnet_get_feature_reg
vnet_feature_registration_t * vnet_get_feature_reg(const char *arc_name, const char *node_name)
Definition: feature.c:212
vnet_feature_main_t::next_feature_by_arc
vnet_feature_registration_t ** next_feature_by_arc
Definition: feature.h:94
vnet_feature_main_t::arc_index_by_name
uword ** arc_index_by_name
Definition: feature.h:90
vnet_get_feature_arc_config_main
static vnet_feature_config_main_t * vnet_get_feature_arc_config_main(u8 arc_index)
Definition: feature.h:233
vlib_main_t
Definition: main.h:102
vnet_feature_get_config_main
static_always_inline vnet_feature_config_main_t * vnet_feature_get_config_main(u16 arc)
Definition: feature.h:244
vnet_feature_constraint_registration_t
struct _vnet_feature_constraint_registration vnet_feature_constraint_registration_t
constraint registration object
vnet_feature_enable_disable
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
Definition: pnat_test_stubs.h:50
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vnet_get_config_data
static void * vnet_get_config_data(vnet_config_main_t *cm, u32 *config_index, u32 *next_index, u32 n_data_bytes)
Definition: config.h:123
vnet_feature_start_device_input_x1
static_always_inline void vnet_feature_start_device_input_x1(u32 sw_if_index, u32 *next0, vlib_buffer_t *b0)
Definition: feature.h:343
vnet_feature_arc_start
static_always_inline void vnet_feature_arc_start(u8 arc, u32 sw_if_index, u32 *next0, vlib_buffer_t *b0)
Definition: feature.h:302
devices.h
vnet_feature_main_t::feature_config_mains
vnet_feature_config_main_t * feature_config_mains
feature config main objects
Definition: feature.h:100
vnet.h
api_errno.h
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
vnet_feature_main_t::device_input_feature_arc_index
u8 device_input_feature_arc_index
Feature arc index for device-input.
Definition: feature.h:112
vnet_feature_arc_registration_t
struct _vnet_feature_arc_registration vnet_feature_arc_registration_t
feature registration object
vnet_feature_start_device_input_x4
static_always_inline void vnet_feature_start_device_input_x4(u32 sw_if_index, u32 *next0, u32 *next1, u32 *next2, u32 *next3, vlib_buffer_t *b0, vlib_buffer_t *b1, vlib_buffer_t *b2, vlib_buffer_t *b3)
Definition: feature.h:412
vnet_feature_arc_start_with_data
static_always_inline void * vnet_feature_arc_start_with_data(u8 arc, u32 sw_if_index, u32 *next, vlib_buffer_t *b, u32 n_data_bytes)
Definition: feature.h:266
vnet_feature_main_t
Definition: feature.h:86
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111