FD.io VPP  v18.10-34-gcce845e
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  /* Feature arc index, assigned by init function */
34  u8 feature_arc_index;
35  u8 *arc_index_ptr;
37 
38 /* Enable feature callback. */
40  (u32 sw_if_index, int enable_disable);
41 
42 /** feature registration object */
43 typedef struct _vnet_feature_registration
44 {
45  /** next registration in list of all registrations*/
46  struct _vnet_feature_registration *next, *next_in_arc;
47  /** Feature arc name */
48  char *arc_name;
49  /** Graph node name */
50  char *node_name;
51  /** Pointer to this feature index, filled in by vnet_feature_arc_init */
52  u32 *feature_index_ptr;
53  u32 feature_index;
54  /** Constraints of the form "this feature runs before X" */
55  char **runs_before;
56  /** Constraints of the form "this feature runs after Y" */
57  char **runs_after;
58 
59  /** Function to enable/disable feature **/
60  vnet_feature_enable_disable_function_t *enable_disable_cb;
62 
64 {
68 
69 typedef struct
70 {
71  /** feature arc configuration list */
74 
75  /** feature path configuration lists */
79 
80  /** feature config main objects */
82 
83  /** Save partial order results for show command */
84  char ***feature_nodes;
85 
86  /** bitmap of interfaces which have driver rx features configured */
88 
89  /** feature reference counts by interface */
91 
92  /** Feature arc index for device-input */
94 
95  /** convenience */
99 
101 
102 #ifndef CLIB_MARCH_VARIANT
103 #define VNET_FEATURE_ARC_INIT(x,...) \
104  __VA_ARGS__ vnet_feature_arc_registration_t vnet_feat_arc_##x;\
105 static void __vnet_add_feature_arc_registration_##x (void) \
106  __attribute__((__constructor__)) ; \
107 static void __vnet_add_feature_arc_registration_##x (void) \
108 { \
109  vnet_feature_main_t * fm = &feature_main; \
110  vnet_feat_arc_##x.next = fm->next_arc; \
111  fm->next_arc = & vnet_feat_arc_##x; \
112 } \
113 static void __vnet_rm_feature_arc_registration_##x (void) \
114  __attribute__((__destructor__)) ; \
115 static void __vnet_rm_feature_arc_registration_##x (void) \
116 { \
117  vnet_feature_main_t * fm = &feature_main; \
118  vnet_feature_arc_registration_t *r = &vnet_feat_arc_##x; \
119  VLIB_REMOVE_FROM_LINKED_LIST (fm->next_arc, r, next); \
120 } \
121 __VA_ARGS__ vnet_feature_arc_registration_t vnet_feat_arc_##x
122 
123 #define VNET_FEATURE_INIT(x,...) \
124  __VA_ARGS__ vnet_feature_registration_t vnet_feat_##x; \
125 static void __vnet_add_feature_registration_##x (void) \
126  __attribute__((__constructor__)) ; \
127 static void __vnet_add_feature_registration_##x (void) \
128 { \
129  vnet_feature_main_t * fm = &feature_main; \
130  vnet_feat_##x.next = fm->next_feature; \
131  fm->next_feature = & vnet_feat_##x; \
132 } \
133 static void __vnet_rm_feature_registration_##x (void) \
134  __attribute__((__destructor__)) ; \
135 static void __vnet_rm_feature_registration_##x (void) \
136 { \
137  vnet_feature_main_t * fm = &feature_main; \
138  vnet_feature_registration_t *r = &vnet_feat_##x; \
139  VLIB_REMOVE_FROM_LINKED_LIST (fm->next_feature, r, next); \
140 } \
141 __VA_ARGS__ vnet_feature_registration_t vnet_feat_##x
142 #else
143 #define VNET_FEATURE_ARC_INIT(x,...) \
144 extern vnet_feature_arc_registration_t __clib_unused vnet_feat_arc_##x; \
145 static vnet_feature_arc_registration_t __clib_unused __clib_unused_vnet_feat_arc_##x
146 #define VNET_FEATURE_INIT(x,...) \
147 extern vnet_feature_registration_t __clib_unused vnet_feat_##x; \
148 static vnet_feature_registration_t __clib_unused __clib_unused_vnet_feat_##x
149 #endif
150 
151 void
153  u32 sw_if_index, int is_add);
154 
155 u32 vnet_get_feature_index (u8 arc, const char *s);
156 u8 vnet_get_feature_arc_index (const char *s);
158  const char *node_name);
159 
160 
161 int
162 vnet_feature_enable_disable_with_index (u8 arc_index, u32 feature_index,
163  u32 sw_if_index, int enable_disable,
164  void *feature_config,
165  u32 n_feature_config_bytes);
166 
167 int
168 vnet_feature_enable_disable (const char *arc_name, const char *node_name,
169  u32 sw_if_index, int enable_disable,
170  void *feature_config,
171  u32 n_feature_config_bytes);
172 
173 static inline vnet_feature_config_main_t *
175 {
177 
178  if (arc_index == (u8) ~ 0)
179  return 0;
180 
181  return &fm->feature_config_mains[arc_index];
182 }
183 
186 {
188  return &fm->feature_config_mains[arc];
189 }
190 
192 vnet_have_features (u8 arc, u32 sw_if_index)
193 {
195  return clib_bitmap_get (fm->sw_if_index_has_features[arc], sw_if_index);
196 }
197 
200 {
203  return vec_elt (cm->config_index_by_sw_if_index, sw_if_index);
204 }
205 
207 vnet_feature_arc_start_with_data (u8 arc, u32 sw_if_index, u32 * next,
208  vlib_buffer_t * b, u32 n_data_bytes)
209 {
212  cm = &fm->feature_config_mains[arc];
213 
214  if (PREDICT_FALSE (vnet_have_features (arc, sw_if_index)))
215  {
216  vnet_buffer (b)->feature_arc_index = arc;
218  vec_elt (cm->config_index_by_sw_if_index, sw_if_index);
220  next, n_data_bytes);
221  }
222  return 0;
223 }
224 
226 vnet_feature_arc_start (u8 arc, u32 sw_if_index, u32 * next0,
227  vlib_buffer_t * b0)
228 {
229  vnet_feature_arc_start_with_data (arc, sw_if_index, next0, b0, 0);
230 }
231 
234  u32 n_data_bytes)
235 {
237  u8 arc = vnet_buffer (b0)->feature_arc_index;
239 
240  return vnet_get_config_data (&cm->config_main,
241  &b0->current_config_index, next0,
242  n_data_bytes);
243 }
244 
247 {
248  vnet_feature_next_with_data (next0, b0, 0);
249 }
250 
253 {
255  return vnet_have_features (fm->device_input_feature_arc_index, sw_if_index);
256 }
257 
260  vlib_buffer_t * b0)
261 {
264  u8 feature_arc_index = fm->device_input_feature_arc_index;
265  cm = &fm->feature_config_mains[feature_arc_index];
266 
267  if (PREDICT_FALSE
269  (fm->sw_if_index_has_features[feature_arc_index], sw_if_index)))
270  {
271  /*
272  * Save next0 so that the last feature in the chain
273  * can skip ethernet-input if indicated...
274  */
275  u16 adv;
276 
277  adv = device_input_next_node_advance[*next0];
278  vlib_buffer_advance (b0, -adv);
279 
280  vnet_buffer (b0)->feature_arc_index = feature_arc_index;
282  vec_elt (cm->config_index_by_sw_if_index, sw_if_index);
284  next0, /* # bytes of config data */ 0);
285  }
286 }
287 
290  u32 * next0,
291  u32 * next1,
292  vlib_buffer_t * b0, vlib_buffer_t * b1)
293 {
296  u8 feature_arc_index = fm->device_input_feature_arc_index;
297  cm = &fm->feature_config_mains[feature_arc_index];
298 
299  if (PREDICT_FALSE
301  (fm->sw_if_index_has_features[feature_arc_index], sw_if_index)))
302  {
303  /*
304  * Save next0 so that the last feature in the chain
305  * can skip ethernet-input if indicated...
306  */
307  u16 adv;
308 
309  adv = device_input_next_node_advance[*next0];
310  vlib_buffer_advance (b0, -adv);
311 
312  adv = device_input_next_node_advance[*next1];
313  vlib_buffer_advance (b1, -adv);
314 
315  vnet_buffer (b0)->feature_arc_index = feature_arc_index;
316  vnet_buffer (b1)->feature_arc_index = feature_arc_index;
318  vec_elt (cm->config_index_by_sw_if_index, sw_if_index);
321  next0, /* # bytes of config data */ 0);
323  next1, /* # bytes of config data */ 0);
324  }
325 }
326 
329  u32 * next0,
330  u32 * next1,
331  u32 * next2,
332  u32 * next3,
333  vlib_buffer_t * b0,
334  vlib_buffer_t * b1,
335  vlib_buffer_t * b2, vlib_buffer_t * b3)
336 {
339  u8 feature_arc_index = fm->device_input_feature_arc_index;
340  cm = &fm->feature_config_mains[feature_arc_index];
341 
342  if (PREDICT_FALSE
344  (fm->sw_if_index_has_features[feature_arc_index], sw_if_index)))
345  {
346  /*
347  * Save next0 so that the last feature in the chain
348  * can skip ethernet-input if indicated...
349  */
350  u16 adv;
351 
352  adv = device_input_next_node_advance[*next0];
353  vlib_buffer_advance (b0, -adv);
354 
355  adv = device_input_next_node_advance[*next1];
356  vlib_buffer_advance (b1, -adv);
357 
358  adv = device_input_next_node_advance[*next2];
359  vlib_buffer_advance (b2, -adv);
360 
361  adv = device_input_next_node_advance[*next3];
362  vlib_buffer_advance (b3, -adv);
363 
364  vnet_buffer (b0)->feature_arc_index = feature_arc_index;
365  vnet_buffer (b1)->feature_arc_index = feature_arc_index;
366  vnet_buffer (b2)->feature_arc_index = feature_arc_index;
367  vnet_buffer (b3)->feature_arc_index = feature_arc_index;
368 
370  vec_elt (cm->config_index_by_sw_if_index, sw_if_index);
374 
376  next0, /* # bytes of config data */ 0);
378  next1, /* # bytes of config data */ 0);
380  next2, /* # bytes of config data */ 0);
382  next3, /* # bytes of config data */ 0);
383  }
384 }
385 
386 #define VNET_FEATURES(...) (char*[]) { __VA_ARGS__, 0}
387 
389  vnet_config_main_t * vcm,
390  char **feature_start_nodes,
391  int num_feature_start_nodes,
393  first_reg, char ***feature_nodes);
394 
395 void vnet_interface_features_show (vlib_main_t * vm, u32 sw_if_index,
396  int verbose);
397 
398 #endif /* included_feature_h */
399 
400 /*
401  * fd.io coding-style-patch-verification: ON
402  *
403  * Local Variables:
404  * eval: (c-set-style "gnu")
405  * End:
406  */
vnet_config_main_t config_main
Definition: feature.h:65
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:135
char *** feature_nodes
Save partial order results for show command.
Definition: feature.h:84
vnet_feature_registration_t * next_feature
feature path configuration lists
Definition: feature.h:76
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:328
static_always_inline int vnet_have_features(u8 arc, u32 sw_if_index)
Definition: feature.h:192
void vnet_config_update_feature_count(vnet_feature_main_t *fm, u8 arc, u32 sw_if_index, int is_add)
unsigned char u8
Definition: types.h:56
vnet_main_t * vnet_main
Definition: feature.h:97
#define fm
#define static_always_inline
Definition: clib.h:95
u8 vnet_get_feature_arc_index(const char *s)
Definition: feature.c:127
vlib_main_t * vlib_main
convenience
Definition: feature.h:96
static_always_inline int vnet_device_input_have_features(u32 sw_if_index)
Definition: feature.h:252
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:338
vnet_feature_main_t feature_main
Definition: feature.c:19
unsigned int u32
Definition: types.h:88
static_always_inline void * vnet_feature_next_with_data(u32 *next0, vlib_buffer_t *b0, u32 n_data_bytes)
Definition: feature.h:233
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
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
unsigned short u16
Definition: types.h:57
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:107
uword ** next_feature_by_name
Definition: feature.h:78
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:289
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:181
vlib_main_t * vm
Definition: buffer.c:294
static_always_inline void vnet_feature_next(u32 *next0, vlib_buffer_t *b0)
Definition: feature.h:246
u32 vnet_get_feature_index(u8 arc, const char *s)
Definition: feature.c:163
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:73
i16 ** feature_count_by_sw_if_index
feature reference counts by interface
Definition: feature.h:90
vnet_feature_registration_t ** next_feature_by_arc
Definition: feature.h:77
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:218
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:233
clib_error_t *( vnet_feature_enable_disable_function_t)(u32 sw_if_index, int enable_disable)
Definition: feature.h:40
#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:93
static_always_inline u32 vnet_get_feature_config_index(u8 arc, u32 sw_if_index)
Definition: feature.h:199
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:207
u64 uword
Definition: types.h:112
static vnet_feature_config_main_t * vnet_get_feature_arc_config_main(u8 arc_index)
Definition: feature.h:174
struct _vnet_feature_arc_registration vnet_feature_arc_registration_t
feature registration object
#define vnet_buffer(b)
Definition: buffer.h:344
vnet_feature_arc_registration_t * next_arc
feature arc configuration list
Definition: feature.h:72
static_always_inline void vnet_feature_start_device_input_x1(u32 sw_if_index, u32 *next0, vlib_buffer_t *b0)
Definition: feature.h:259
uword ** sw_if_index_has_features
bitmap of interfaces which have driver rx features configured
Definition: feature.h:87
vnet_feature_registration_t * vnet_get_feature_reg(const char *arc_name, const char *node_name)
Definition: feature.c:142
vnet_feature_config_main_t * feature_config_mains
feature config main objects
Definition: feature.h:81
static_always_inline vnet_feature_config_main_t * vnet_feature_get_config_main(u16 arc)
Definition: feature.h:185
struct _vnet_feature_registration vnet_feature_registration_t
feature registration object
signed short i16
Definition: types.h:46
static_always_inline void vnet_feature_arc_start(u8 arc, u32 sw_if_index, u32 *next0, vlib_buffer_t *b0)
Definition: feature.h:226