FD.io VPP  v16.12-rc0-308-g931be3a
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 
21 /** feature registration object */
22 typedef struct _vnet_feature_arc_registration
23 {
24  /** next registration in list of all registrations*/
25  struct _vnet_feature_arc_registration *next;
26  /** Feature Arc name */
27  char *arc_name;
28  /** Start nodes */
29  char **start_nodes;
30  int n_start_nodes;
31  /* Feature arc index, assigned by init function */
32  u16 feature_arc_index;
34 
35 /** feature registration object */
36 typedef struct _vnet_feature_registration
37 {
38  /** next registration in list of all registrations*/
39  struct _vnet_feature_registration *next;
40  /** Feature arc name */
41  char *arc_name;
42  /** Graph node name */
43  char *node_name;
44  /** Pointer to this feature index, filled in by vnet_feature_arc_init */
45  u32 *feature_index;
46  u32 feature_index_u32;
47  /** Constraints of the form "this feature runs before X" */
48  char **runs_before;
49  /** Constraints of the form "this feature runs after Y" */
50  char **runs_after;
52 
54 {
58 
59 typedef struct
60 {
61  /** feature arc configuration list */
64 
65  /** feature path configuration lists */
69 
70  /** feature config main objects */
72 
73  /** Save partial order results for show command */
74  char ***feature_nodes;
75 
76  /** bitmap of interfaces which have driver rx features configured */
78 
79  /** feature reference counts by interface */
81 
82  /** convenience */
86 
88 
89 #define VNET_FEATURE_ARC_INIT(x,...) \
90  __VA_ARGS__ vnet_feature_arc_registration_t vnet_feat_arc_##x;\
91 static void __vnet_add_feature_arc_registration_##x (void) \
92  __attribute__((__constructor__)) ; \
93 static void __vnet_add_feature_arc_registration_##x (void) \
94 { \
95  vnet_feature_main_t * fm = &feature_main; \
96  vnet_feat_arc_##x.next = fm->next_arc; \
97  fm->next_arc = & vnet_feat_arc_##x; \
98 } \
99 __VA_ARGS__ vnet_feature_arc_registration_t vnet_feat_arc_##x
100 
101 #define VNET_FEATURE_INIT(x,...) \
102  __VA_ARGS__ vnet_feature_registration_t vnet_feat_##x; \
103 static void __vnet_add_feature_registration_##x (void) \
104  __attribute__((__constructor__)) ; \
105 static void __vnet_add_feature_registration_##x (void) \
106 { \
107  vnet_feature_main_t * fm = &feature_main; \
108  vnet_feat_##x.next = fm->next_feature; \
109  fm->next_feature = & vnet_feat_##x; \
110 } \
111 __VA_ARGS__ vnet_feature_registration_t vnet_feat_##x
112 
113 void
115  u32 sw_if_index, int is_add);
116 
118 
119 void
120 vnet_feature_enable_disable (const char *arc_name, const char *node_name,
121  u32 sw_if_index, int enable_disable,
122  void *feature_config,
123  u32 n_feature_config_bytes);
124 
125 
127 vnet_have_features (u32 arc, u32 sw_if_index)
128 {
130  return clib_bitmap_get (fm->sw_if_index_has_features[arc], sw_if_index);
131 }
132 
135 {
138  return vec_elt (cm->config_index_by_sw_if_index, sw_if_index);
139 }
140 
142 vnet_feature_redirect (u16 arc, u32 sw_if_index, u32 * next0,
143  vlib_buffer_t * b0)
144 {
147 
148  if (PREDICT_FALSE (vnet_have_features (arc, sw_if_index)))
149  {
151  vec_elt (cm->config_index_by_sw_if_index, sw_if_index);
153  next0, /* # bytes of config data */ 0);
154  }
155 }
156 
159  u32 sw_if_index, u32 * next0,
160  vlib_buffer_t * b0,
161  u16 buffer_advanced0)
162 {
165 
166  ASSERT (node->feature_arc_index != ~(u16) 0);
167  cm = &fm->feature_config_mains[node->feature_arc_index];
168 
169  if (PREDICT_FALSE
171  (fm->sw_if_index_has_features[node->feature_arc_index], sw_if_index)))
172  {
173  /*
174  * Save next0 so that the last feature in the chain
175  * can skip ethernet-input if indicated...
176  */
177  vnet_buffer (b0)->device_input_feat.saved_next_index = *next0;
178  vnet_buffer (b0)->device_input_feat.buffer_advance = buffer_advanced0;
179  vlib_buffer_advance (b0, -buffer_advanced0);
180 
182  vec_elt (cm->config_index_by_sw_if_index, sw_if_index);
184  next0, /* # bytes of config data */ 0);
185  }
186 }
187 
188 #define ORDER_CONSTRAINTS (char*[])
189 #define VNET_FEATURES(...) (char*[]) { __VA_ARGS__, 0}
190 
192  vnet_config_main_t * vcm,
193  char **feature_start_nodes,
194  int num_feature_start_nodes,
196  first_reg, char ***feature_nodes);
197 
198 void vnet_interface_features_show (vlib_main_t * vm, u32 sw_if_index);
199 
200 #endif /* included_feature_h */
201 
202 /*
203  * fd.io coding-style-patch-verification: ON
204  *
205  * Local Variables:
206  * eval: (c-set-style "gnu")
207  * End:
208  */
vnet_config_main_t config_main
Definition: feature.h:55
struct vnet_feature_config_main_t_ vnet_feature_config_main_t
static char * feature_start_nodes[]
Definition: init.c:64
u32 current_config_index
Used by feature subgraph arcs to visit enabled feature nodes.
Definition: buffer.h:124
bad routing header type(not 4)") sr_error (NO_MORE_SEGMENTS
void vnet_config_update_feature_count(vnet_feature_main_t *fm, u16 arc, u32 sw_if_index, int is_add)
Definition: feature.c:136
char *** feature_nodes
Save partial order results for show command.
Definition: feature.h:74
vnet_feature_registration_t * next_feature
feature path configuration lists
Definition: feature.h:66
vnet_main_t * vnet_main
Definition: feature.h:84
#define static_always_inline
Definition: clib.h:85
static_always_inline void vnet_feature_device_input_redirect_x1(vlib_node_runtime_t *node, u32 sw_if_index, u32 *next0, vlib_buffer_t *b0, u16 buffer_advanced0)
Definition: feature.h:158
vlib_main_t * vlib_main
convenience
Definition: feature.h:83
vnet_feature_main_t feature_main
Definition: feature.c:18
u32 vnet_feature_index_from_node_name(u16 type, const char *s)
Definition: feature.c:170
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:127
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_redirect(u16 arc, u32 sw_if_index, u32 *next0, vlib_buffer_t *b0)
Definition: feature.h:142
static_always_inline u32 vnet_feature_get_config_index(u16 arc, u32 sw_if_index)
Definition: feature.h:134
uword ** next_feature_by_name
Definition: feature.h:68
void 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:185
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:203
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:63
i16 ** feature_count_by_sw_if_index
feature reference counts by interface
Definition: feature.h:80
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
#define vnet_buffer(b)
Definition: buffer.h:333
vnet_feature_registration_t ** next_feature_by_arc
Definition: feature.h:67
u64 uword
Definition: types.h:112
#define vec_elt(v, i)
Get vector value at index i.
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:272
static_always_inline int vnet_have_features(u32 arc, u32 sw_if_index)
Definition: feature.h:127
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:62
uword ** sw_if_index_has_features
bitmap of interfaces which have driver rx features configured
Definition: feature.h:77
vnet_feature_config_main_t * feature_config_mains
feature config main objects
Definition: feature.h:71
u16 feature_arc_index
Definition: node.h:469
struct _vnet_feature_registration vnet_feature_registration_t
feature registration object