FD.io VPP  v17.07.01-10-g3be13f0
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;
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 #define VNET_FEATURE_ARC_INIT(x,...) \
103  __VA_ARGS__ vnet_feature_arc_registration_t vnet_feat_arc_##x;\
104 static void __vnet_add_feature_arc_registration_##x (void) \
105  __attribute__((__constructor__)) ; \
106 static void __vnet_add_feature_arc_registration_##x (void) \
107 { \
108  vnet_feature_main_t * fm = &feature_main; \
109  vnet_feat_arc_##x.next = fm->next_arc; \
110  fm->next_arc = & vnet_feat_arc_##x; \
111 } \
112 __VA_ARGS__ vnet_feature_arc_registration_t vnet_feat_arc_##x
113 
114 #define VNET_FEATURE_INIT(x,...) \
115  __VA_ARGS__ vnet_feature_registration_t vnet_feat_##x; \
116 static void __vnet_add_feature_registration_##x (void) \
117  __attribute__((__constructor__)) ; \
118 static void __vnet_add_feature_registration_##x (void) \
119 { \
120  vnet_feature_main_t * fm = &feature_main; \
121  vnet_feat_##x.next = fm->next_feature; \
122  fm->next_feature = & vnet_feat_##x; \
123 } \
124 __VA_ARGS__ vnet_feature_registration_t vnet_feat_##x
125 
126 void
128  u32 sw_if_index, int is_add);
129 
130 u32 vnet_get_feature_index (u8 arc, const char *s);
131 u8 vnet_get_feature_arc_index (const char *s);
133  const char *node_name);
134 
135 
136 int
137 vnet_feature_enable_disable_with_index (u8 arc_index, u32 feature_index,
138  u32 sw_if_index, int enable_disable,
139  void *feature_config,
140  u32 n_feature_config_bytes);
141 
142 int
143 vnet_feature_enable_disable (const char *arc_name, const char *node_name,
144  u32 sw_if_index, int enable_disable,
145  void *feature_config,
146  u32 n_feature_config_bytes);
147 
148 static inline vnet_feature_config_main_t *
150 {
152 
153  if (arc_index == (u8) ~ 0)
154  return 0;
155 
156  return &fm->feature_config_mains[arc_index];
157 }
158 
161 {
163  return &fm->feature_config_mains[arc];
164 }
165 
167 vnet_have_features (u8 arc, u32 sw_if_index)
168 {
170  return clib_bitmap_get (fm->sw_if_index_has_features[arc], sw_if_index);
171 }
172 
175 {
178  return vec_elt (cm->config_index_by_sw_if_index, sw_if_index);
179 }
180 
182 vnet_feature_arc_start_with_data (u8 arc, u32 sw_if_index, u32 * next,
183  vlib_buffer_t * b, u32 n_data_bytes)
184 {
187  cm = &fm->feature_config_mains[arc];
188 
189  if (PREDICT_FALSE (vnet_have_features (arc, sw_if_index)))
190  {
191  b->feature_arc_index = arc;
193  vec_elt (cm->config_index_by_sw_if_index, sw_if_index);
195  next, n_data_bytes);
196  }
197  return 0;
198 }
199 
201 vnet_feature_arc_start (u8 arc, u32 sw_if_index, u32 * next0,
202  vlib_buffer_t * b0)
203 {
204  vnet_feature_arc_start_with_data (arc, sw_if_index, next0, b0, 0);
205 }
206 
208 vnet_feature_next_with_data (u32 sw_if_index, u32 * next0,
209  vlib_buffer_t * b0, u32 n_data_bytes)
210 {
212  u8 arc = b0->feature_arc_index;
214 
215  return vnet_get_config_data (&cm->config_main,
216  &b0->current_config_index, next0,
217  n_data_bytes);
218 }
219 
221 vnet_feature_next (u32 sw_if_index, u32 * next0, vlib_buffer_t * b0)
222 {
223  vnet_feature_next_with_data (sw_if_index, next0, b0, 0);
224 }
225 
228  vlib_buffer_t * b0)
229 {
232  u8 feature_arc_index = fm->device_input_feature_arc_index;
233  cm = &fm->feature_config_mains[feature_arc_index];
234 
235  if (PREDICT_FALSE
237  (fm->sw_if_index_has_features[feature_arc_index], sw_if_index)))
238  {
239  /*
240  * Save next0 so that the last feature in the chain
241  * can skip ethernet-input if indicated...
242  */
243  u16 adv;
244 
245  vnet_buffer (b0)->device_input_feat.saved_next_index = *next0;
246  adv = device_input_next_node_advance[*next0];
247  vnet_buffer (b0)->device_input_feat.buffer_advance = adv;
248  vlib_buffer_advance (b0, -adv);
249 
250  b0->feature_arc_index = feature_arc_index;
252  vec_elt (cm->config_index_by_sw_if_index, sw_if_index);
254  next0, /* # bytes of config data */ 0);
255  }
256 }
257 
260  u32 * next0,
261  u32 * next1,
262  vlib_buffer_t * b0, vlib_buffer_t * b1)
263 {
266  u8 feature_arc_index = fm->device_input_feature_arc_index;
267  cm = &fm->feature_config_mains[feature_arc_index];
268 
269  if (PREDICT_FALSE
271  (fm->sw_if_index_has_features[feature_arc_index], sw_if_index)))
272  {
273  /*
274  * Save next0 so that the last feature in the chain
275  * can skip ethernet-input if indicated...
276  */
277  u16 adv;
278 
279  vnet_buffer (b0)->device_input_feat.saved_next_index = *next0;
280  adv = device_input_next_node_advance[*next0];
281  vnet_buffer (b0)->device_input_feat.buffer_advance = adv;
282  vlib_buffer_advance (b0, -adv);
283 
284  vnet_buffer (b1)->device_input_feat.saved_next_index = *next1;
285  adv = device_input_next_node_advance[*next1];
286  vnet_buffer (b1)->device_input_feat.buffer_advance = adv;
287  vlib_buffer_advance (b1, -adv);
288 
289  b0->feature_arc_index = feature_arc_index;
290  b1->feature_arc_index = feature_arc_index;
292  vec_elt (cm->config_index_by_sw_if_index, sw_if_index);
295  next0, /* # bytes of config data */ 0);
297  next1, /* # bytes of config data */ 0);
298  }
299 }
300 
303  u32 * next0,
304  u32 * next1,
305  u32 * next2,
306  u32 * next3,
307  vlib_buffer_t * b0,
308  vlib_buffer_t * b1,
309  vlib_buffer_t * b2, vlib_buffer_t * b3)
310 {
313  u8 feature_arc_index = fm->device_input_feature_arc_index;
314  cm = &fm->feature_config_mains[feature_arc_index];
315 
316  if (PREDICT_FALSE
318  (fm->sw_if_index_has_features[feature_arc_index], sw_if_index)))
319  {
320  /*
321  * Save next0 so that the last feature in the chain
322  * can skip ethernet-input if indicated...
323  */
324  u16 adv;
325 
326  vnet_buffer (b0)->device_input_feat.saved_next_index = *next0;
327  adv = device_input_next_node_advance[*next0];
328  vnet_buffer (b0)->device_input_feat.buffer_advance = adv;
329  vlib_buffer_advance (b0, -adv);
330 
331  vnet_buffer (b1)->device_input_feat.saved_next_index = *next1;
332  adv = device_input_next_node_advance[*next1];
333  vnet_buffer (b1)->device_input_feat.buffer_advance = adv;
334  vlib_buffer_advance (b1, -adv);
335 
336  vnet_buffer (b2)->device_input_feat.saved_next_index = *next2;
337  adv = device_input_next_node_advance[*next2];
338  vnet_buffer (b2)->device_input_feat.buffer_advance = adv;
339  vlib_buffer_advance (b2, -adv);
340 
341  vnet_buffer (b3)->device_input_feat.saved_next_index = *next3;
342  adv = device_input_next_node_advance[*next3];
343  vnet_buffer (b3)->device_input_feat.buffer_advance = adv;
344  vlib_buffer_advance (b3, -adv);
345 
346  b0->feature_arc_index = feature_arc_index;
347  b1->feature_arc_index = feature_arc_index;
348  b2->feature_arc_index = feature_arc_index;
349  b3->feature_arc_index = feature_arc_index;
350 
352  vec_elt (cm->config_index_by_sw_if_index, sw_if_index);
356 
358  next0, /* # bytes of config data */ 0);
360  next1, /* # bytes of config data */ 0);
362  next2, /* # bytes of config data */ 0);
364  next3, /* # bytes of config data */ 0);
365  }
366 }
367 
368 #define VNET_FEATURES(...) (char*[]) { __VA_ARGS__, 0}
369 
371  vnet_config_main_t * vcm,
372  char **feature_start_nodes,
373  int num_feature_start_nodes,
375  first_reg, char ***feature_nodes);
376 
377 void vnet_interface_features_show (vlib_main_t * vm, u32 sw_if_index);
378 
379 #endif /* included_feature_h */
380 
381 /*
382  * fd.io coding-style-patch-verification: ON
383  *
384  * Local Variables:
385  * eval: (c-set-style "gnu")
386  * End:
387  */
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:116
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:302
static_always_inline int vnet_have_features(u8 arc, u32 sw_if_index)
Definition: feature.h:167
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:97
#define static_always_inline
Definition: clib.h:85
u8 vnet_get_feature_arc_index(const char *s)
Definition: feature.c:123
vlib_main_t * vlib_main
convenience
Definition: feature.h:96
u8 feature_arc_index
Used to identify feature arcs by intermediate feature node.
Definition: buffer.h:120
vnet_feature_main_t feature_main
Definition: feature.c:19
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
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:221
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:259
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:177
u32 vnet_get_feature_index(u8 arc, const char *s)
Definition: feature.c:159
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
unsigned int u32
Definition: types.h:88
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:201
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:225
clib_error_t *( vnet_feature_enable_disable_function_t)(u32 sw_if_index, int enable_disable)
Definition: feature.h:40
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:93
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:301
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:174
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:182
static vnet_feature_config_main_t * vnet_get_feature_arc_config_main(u8 arc_index)
Definition: feature.h:149
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:208
struct _vnet_feature_arc_registration vnet_feature_arc_registration_t
feature registration object
short i16
Definition: types.h:46
#define vnet_buffer(b)
Definition: buffer.h:304
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:227
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:138
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:160
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:201