FD.io VPP  v17.01.1-3-gc6833f8
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 
22 /** feature registration object */
23 typedef struct _vnet_feature_arc_registration
24 {
25  /** next registration in list of all registrations*/
26  struct _vnet_feature_arc_registration *next;
27  /** Feature Arc name */
28  char *arc_name;
29  /** Start nodes */
30  char **start_nodes;
31  int n_start_nodes;
32  /** End node */
33  char *end_node;
34  /* Feature arc index, assigned by init function */
35  u8 feature_arc_index;
36  u8 *arc_index_ptr;
38 
39 /* Enable feature callback. */
41  (u32 sw_if_index, int enable_disable);
42 
43 /** feature registration object */
44 typedef struct _vnet_feature_registration
45 {
46  /** next registration in list of all registrations*/
47  struct _vnet_feature_registration *next;
48  /** Feature arc name */
49  char *arc_name;
50  /** Graph node name */
51  char *node_name;
52  /** Pointer to this feature index, filled in by vnet_feature_arc_init */
53  u32 *feature_index_ptr;
54  u32 feature_index;
55  /** Constraints of the form "this feature runs before X" */
56  char **runs_before;
57  /** Constraints of the form "this feature runs after Y" */
58  char **runs_after;
59 
60  /** Function to enable/disable feature **/
61  vnet_feature_enable_disable_function_t *enable_disable_cb;
63 
65 {
70 
71 typedef struct
72 {
73  /** feature arc configuration list */
76 
77  /** feature path configuration lists */
81 
82  /** feature config main objects */
84 
85  /** Save partial order results for show command */
86  char ***feature_nodes;
87 
88  /** bitmap of interfaces which have driver rx features configured */
90 
91  /** feature reference counts by interface */
93 
94  /** Feature arc index for device-input */
96 
97  /** convenience */
101 
103 
104 #define VNET_FEATURE_ARC_INIT(x,...) \
105  __VA_ARGS__ vnet_feature_arc_registration_t vnet_feat_arc_##x;\
106 static void __vnet_add_feature_arc_registration_##x (void) \
107  __attribute__((__constructor__)) ; \
108 static void __vnet_add_feature_arc_registration_##x (void) \
109 { \
110  vnet_feature_main_t * fm = &feature_main; \
111  vnet_feat_arc_##x.next = fm->next_arc; \
112  fm->next_arc = & vnet_feat_arc_##x; \
113 } \
114 __VA_ARGS__ vnet_feature_arc_registration_t vnet_feat_arc_##x
115 
116 #define VNET_FEATURE_INIT(x,...) \
117  __VA_ARGS__ vnet_feature_registration_t vnet_feat_##x; \
118 static void __vnet_add_feature_registration_##x (void) \
119  __attribute__((__constructor__)) ; \
120 static void __vnet_add_feature_registration_##x (void) \
121 { \
122  vnet_feature_main_t * fm = &feature_main; \
123  vnet_feat_##x.next = fm->next_feature; \
124  fm->next_feature = & vnet_feat_##x; \
125 } \
126 __VA_ARGS__ vnet_feature_registration_t vnet_feat_##x
127 
128 void
130  u32 sw_if_index, int is_add);
131 
132 u32 vnet_get_feature_index (u8 arc, const char *s);
133 u8 vnet_get_feature_arc_index (const char *s);
135  const char *node_name);
136 
137 
138 int
139 vnet_feature_enable_disable_with_index (u8 arc_index, u32 feature_index,
140  u32 sw_if_index, int enable_disable,
141  void *feature_config,
142  u32 n_feature_config_bytes);
143 
144 int
145 vnet_feature_enable_disable (const char *arc_name, const char *node_name,
146  u32 sw_if_index, int enable_disable,
147  void *feature_config,
148  u32 n_feature_config_bytes);
149 
150 static inline vnet_feature_config_main_t *
152 {
154 
155  if (arc_index == (u8) ~ 0)
156  return 0;
157 
158  return &fm->feature_config_mains[arc_index];
159 }
160 
163 {
165  return &fm->feature_config_mains[arc];
166 }
167 
169 vnet_have_features (u8 arc, u32 sw_if_index)
170 {
172  return clib_bitmap_get (fm->sw_if_index_has_features[arc], sw_if_index);
173 }
174 
177 {
180  return vec_elt (cm->config_index_by_sw_if_index, sw_if_index);
181 }
182 
184 vnet_feature_arc_start_with_data (u8 arc, u32 sw_if_index, u32 * next,
185  vlib_buffer_t * b, u32 n_data_bytes)
186 {
189  cm = &fm->feature_config_mains[arc];
190 
191  if (PREDICT_FALSE (vnet_have_features (arc, sw_if_index)))
192  {
193  b->feature_arc_index = arc;
195  vec_elt (cm->config_index_by_sw_if_index, sw_if_index);
197  next, n_data_bytes);
198  }
199  return 0;
200 }
201 
203 vnet_feature_arc_start (u8 arc, u32 sw_if_index, u32 * next0,
204  vlib_buffer_t * b0)
205 {
206  vnet_feature_arc_start_with_data (arc, sw_if_index, next0, b0, 0);
207 }
208 
210 vnet_feature_next_with_data (u32 sw_if_index, u32 * next0,
211  vlib_buffer_t * b0, u32 n_data_bytes)
212 {
214  u8 arc = b0->feature_arc_index;
216 
217  return vnet_get_config_data (&cm->config_main,
218  &b0->current_config_index, next0,
219  n_data_bytes);
220 }
221 
223 vnet_feature_next (u32 sw_if_index, u32 * next0, vlib_buffer_t * b0)
224 {
225  vnet_feature_next_with_data (sw_if_index, next0, b0, 0);
226 }
227 
230  vlib_buffer_t * b0, u16 buffer_advanced0)
231 {
234  u8 feature_arc_index = fm->device_input_feature_arc_index;
235  cm = &fm->feature_config_mains[feature_arc_index];
236 
237  if (PREDICT_FALSE
239  (fm->sw_if_index_has_features[feature_arc_index], sw_if_index)))
240  {
241  /*
242  * Save next0 so that the last feature in the chain
243  * can skip ethernet-input if indicated...
244  */
245  vnet_buffer (b0)->device_input_feat.saved_next_index = *next0;
246  vnet_buffer (b0)->device_input_feat.buffer_advance = buffer_advanced0;
247  vlib_buffer_advance (b0, -buffer_advanced0);
248 
249  b0->feature_arc_index = feature_arc_index;
251  vec_elt (cm->config_index_by_sw_if_index, sw_if_index);
253  next0, /* # bytes of config data */ 0);
254  }
255 }
256 
259  u32 * next0,
260  u32 * next1,
261  vlib_buffer_t * b0,
262  vlib_buffer_t * b1,
263  u16 buffer_advanced0,
264  u16 buffer_advanced1)
265 {
268  u8 feature_arc_index = fm->device_input_feature_arc_index;
269  cm = &fm->feature_config_mains[feature_arc_index];
270 
271  if (PREDICT_FALSE
273  (fm->sw_if_index_has_features[feature_arc_index], sw_if_index)))
274  {
275  /*
276  * Save next0 so that the last feature in the chain
277  * can skip ethernet-input if indicated...
278  */
279  vnet_buffer (b0)->device_input_feat.saved_next_index = *next0;
280  vnet_buffer (b1)->device_input_feat.saved_next_index = *next1;
281  vnet_buffer (b0)->device_input_feat.buffer_advance = buffer_advanced0;
282  vnet_buffer (b1)->device_input_feat.buffer_advance = buffer_advanced1;
283  vlib_buffer_advance (b0, -buffer_advanced0);
284  vlib_buffer_advance (b1, -buffer_advanced1);
285 
286  b0->feature_arc_index = feature_arc_index;
287  b1->feature_arc_index = feature_arc_index;
289  vec_elt (cm->config_index_by_sw_if_index, sw_if_index);
292  next0, /* # bytes of config data */ 0);
294  next1, /* # bytes of config data */ 0);
295  }
296 }
297 
300  u32 * next0,
301  u32 * next1,
302  u32 * next2,
303  u32 * next3,
304  vlib_buffer_t * b0,
305  vlib_buffer_t * b1,
306  vlib_buffer_t * b2,
307  vlib_buffer_t * b3,
308  u16 buffer_advanced0,
309  u16 buffer_advanced1,
310  u16 buffer_advanced2,
311  u16 buffer_advanced3)
312 {
315  u8 feature_arc_index = fm->device_input_feature_arc_index;
316  cm = &fm->feature_config_mains[feature_arc_index];
317 
318  if (PREDICT_FALSE
320  (fm->sw_if_index_has_features[feature_arc_index], sw_if_index)))
321  {
322  /*
323  * Save next0 so that the last feature in the chain
324  * can skip ethernet-input if indicated...
325  */
326  vnet_buffer (b0)->device_input_feat.saved_next_index = *next0;
327  vnet_buffer (b1)->device_input_feat.saved_next_index = *next1;
328  vnet_buffer (b2)->device_input_feat.saved_next_index = *next2;
329  vnet_buffer (b3)->device_input_feat.saved_next_index = *next3;
330 
331  vnet_buffer (b0)->device_input_feat.buffer_advance = buffer_advanced0;
332  vnet_buffer (b1)->device_input_feat.buffer_advance = buffer_advanced1;
333  vnet_buffer (b2)->device_input_feat.buffer_advance = buffer_advanced2;
334  vnet_buffer (b3)->device_input_feat.buffer_advance = buffer_advanced3;
335 
336  vlib_buffer_advance (b0, -buffer_advanced0);
337  vlib_buffer_advance (b1, -buffer_advanced1);
338  vlib_buffer_advance (b2, -buffer_advanced2);
339  vlib_buffer_advance (b3, -buffer_advanced3);
340 
341  b0->feature_arc_index = feature_arc_index;
342  b1->feature_arc_index = feature_arc_index;
343  b2->feature_arc_index = feature_arc_index;
344  b3->feature_arc_index = feature_arc_index;
345 
347  vec_elt (cm->config_index_by_sw_if_index, sw_if_index);
351 
353  next0, /* # bytes of config data */ 0);
355  next1, /* # bytes of config data */ 0);
357  next2, /* # bytes of config data */ 0);
359  next3, /* # bytes of config data */ 0);
360  }
361 }
362 
363 #define VNET_FEATURES(...) (char*[]) { __VA_ARGS__, 0}
364 
366  vnet_config_main_t * vcm,
367  char **feature_start_nodes,
368  int num_feature_start_nodes,
370  first_reg, char ***feature_nodes);
371 
372 void vnet_interface_features_show (vlib_main_t * vm, u32 sw_if_index);
373 
374 #endif /* included_feature_h */
375 
376 /*
377  * fd.io coding-style-patch-verification: ON
378  *
379  * Local Variables:
380  * eval: (c-set-style "gnu")
381  * End:
382  */
vnet_config_main_t config_main
Definition: feature.h:66
struct vnet_feature_config_main_t_ vnet_feature_config_main_t
u32 current_config_index
Used by feature subgraph arcs to visit enabled feature nodes.
Definition: buffer.h:124
char *** feature_nodes
Save partial order results for show command.
Definition: feature.h:86
vnet_feature_registration_t * next_feature
feature path configuration lists
Definition: feature.h:78
static_always_inline void vnet_feature_start_device_input_x1(u32 sw_if_index, u32 *next0, vlib_buffer_t *b0, u16 buffer_advanced0)
Definition: feature.h:229
static_always_inline int vnet_have_features(u8 arc, u32 sw_if_index)
Definition: feature.h:169
void vnet_config_update_feature_count(vnet_feature_main_t *fm, u8 arc, u32 sw_if_index, int is_add)
vnet_main_t * vnet_main
Definition: feature.h:99
#define static_always_inline
Definition: clib.h:85
u8 vnet_get_feature_arc_index(const char *s)
Definition: feature.c:125
vlib_main_t * vlib_main
convenience
Definition: feature.h:98
u8 feature_arc_index
Used to identify feature arcs by intermediate feature node.
Definition: buffer.h:128
vnet_feature_main_t feature_main
Definition: feature.c:18
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, vnet_feature_registration_t *first_reg, char ***feature_nodes)
Initialize a feature graph arc.
Definition: registration.c:118
static void * vnet_get_config_data(vnet_config_main_t *cm, u32 *config_index, u32 *next_index, u32 n_data_bytes)
Definition: config.h:122
#define PREDICT_FALSE(x)
Definition: clib.h:97
static_always_inline void vnet_feature_next(u32 sw_if_index, u32 *next0, vlib_buffer_t *b0)
Definition: feature.h:223
uword ** next_feature_by_name
Definition: feature.h:80
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:179
u32 vnet_get_feature_index(u8 arc, const char *s)
Definition: feature.c:161
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:207
static uword clib_bitmap_get(uword *ai, uword i)
Gets the ith bit value from a bitmap.
Definition: bitmap.h:197
uword ** arc_index_by_name
Definition: feature.h:75
i16 ** feature_count_by_sw_if_index
feature reference counts by interface
Definition: feature.h:92
unsigned int u32
Definition: types.h:88
#define vnet_buffer(b)
Definition: buffer.h:361
vnet_feature_registration_t ** next_feature_by_arc
Definition: feature.h:79
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: feature.c:238
clib_error_t *( vnet_feature_enable_disable_function_t)(u32 sw_if_index, int enable_disable)
Definition: feature.h:41
u64 uword
Definition: types.h:112
#define vec_elt(v, i)
Get vector value at index i.
u8 device_input_feature_arc_index
Feature arc index for device-input.
Definition: feature.h:95
unsigned short u16
Definition: types.h:57
void vnet_interface_features_show(vlib_main_t *vm, u32 sw_if_index)
Display the set of driver features configured on a specific interface Called by "show interface" hand...
Definition: feature.c:314
unsigned char u8
Definition: types.h:56
static_always_inline u32 vnet_get_feature_config_index(u8 arc, u32 sw_if_index)
Definition: feature.h:176
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:184
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, u16 buffer_advanced0, u16 buffer_advanced1, u16 buffer_advanced2, u16 buffer_advanced3)
Definition: feature.h:299
static vnet_feature_config_main_t * vnet_get_feature_arc_config_main(u8 arc_index)
Definition: feature.h:151
static_always_inline void * vnet_feature_next_with_data(u32 sw_if_index, u32 *next0, vlib_buffer_t *b0, u32 n_data_bytes)
Definition: feature.h:210
struct _vnet_feature_arc_registration vnet_feature_arc_registration_t
feature registration object
short i16
Definition: types.h:46
vnet_feature_arc_registration_t * next_arc
feature arc configuration list
Definition: feature.h:74
uword ** sw_if_index_has_features
bitmap of interfaces which have driver rx features configured
Definition: feature.h:89
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, u16 buffer_advanced0, u16 buffer_advanced1)
Definition: feature.h:258
vnet_feature_registration_t * vnet_get_feature_reg(const char *arc_name, const char *node_name)
Definition: feature.c:140
vnet_feature_config_main_t * feature_config_mains
feature config main objects
Definition: feature.h:83
static_always_inline vnet_feature_config_main_t * vnet_feature_get_config_main(u16 arc)
Definition: feature.h:162
struct _vnet_feature_registration vnet_feature_registration_t
feature registration object
static_always_inline void vnet_feature_arc_start(u8 arc, u32 sw_if_index, u32 *next0, vlib_buffer_t *b0)
Definition: feature.h:203