Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 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> |
Damjan Marion | 96b41f7 | 2016-11-10 18:01:42 +0100 | [diff] [blame] | 20 | #include <vnet/api_errno.h> |
Damjan Marion | 35af9e5 | 2017-03-06 12:02:50 +0100 | [diff] [blame] | 21 | #include <vnet/devices/devices.h> |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 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; |
Dave Barach | a25def7 | 2018-11-26 11:04:45 -0500 | [diff] [blame] | 33 | /** End of the arc (optional, for consistency-checking) */ |
| 34 | char *last_in_arc; |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 35 | /* Feature arc index, assigned by init function */ |
Damjan Marion | 87cd119 | 2016-11-04 11:00:27 +0100 | [diff] [blame] | 36 | u8 feature_arc_index; |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 37 | u8 *arc_index_ptr; |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 38 | } vnet_feature_arc_registration_t; |
| 39 | |
Pavel Kotucek | 7490a75 | 2016-11-15 09:19:11 +0100 | [diff] [blame] | 40 | /* Enable feature callback. */ |
| 41 | typedef clib_error_t *(vnet_feature_enable_disable_function_t) |
| 42 | (u32 sw_if_index, int enable_disable); |
| 43 | |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 44 | /** feature registration object */ |
| 45 | typedef struct _vnet_feature_registration |
| 46 | { |
| 47 | /** next registration in list of all registrations*/ |
Damjan Marion | 13adc3d | 2018-04-09 20:59:53 +0200 | [diff] [blame] | 48 | struct _vnet_feature_registration *next, *next_in_arc; |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 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 */ |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 54 | u32 *feature_index_ptr; |
| 55 | u32 feature_index; |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 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; |
Pavel Kotucek | 7490a75 | 2016-11-15 09:19:11 +0100 | [diff] [blame] | 60 | |
| 61 | /** Function to enable/disable feature **/ |
| 62 | vnet_feature_enable_disable_function_t *enable_disable_cb; |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 63 | } vnet_feature_registration_t; |
| 64 | |
Dave Barach | 2dd192b | 2018-11-19 09:31:48 -0500 | [diff] [blame] | 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; |
| 78 | } vnet_feature_constraint_registration_t; |
| 79 | |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 80 | typedef struct vnet_feature_config_main_t_ |
| 81 | { |
| 82 | vnet_config_main_t config_main; |
| 83 | u32 *config_index_by_sw_if_index; |
| 84 | } vnet_feature_config_main_t; |
| 85 | |
| 86 | typedef struct |
| 87 | { |
| 88 | /** feature arc configuration list */ |
| 89 | vnet_feature_arc_registration_t *next_arc; |
| 90 | uword **arc_index_by_name; |
| 91 | |
| 92 | /** feature path configuration lists */ |
| 93 | vnet_feature_registration_t *next_feature; |
| 94 | vnet_feature_registration_t **next_feature_by_arc; |
Dave Barach | 2dd192b | 2018-11-19 09:31:48 -0500 | [diff] [blame] | 95 | vnet_feature_constraint_registration_t *next_constraint; |
| 96 | vnet_feature_constraint_registration_t **next_constraint_by_arc; |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 97 | uword **next_feature_by_name; |
| 98 | |
| 99 | /** feature config main objects */ |
| 100 | vnet_feature_config_main_t *feature_config_mains; |
| 101 | |
| 102 | /** Save partial order results for show command */ |
| 103 | char ***feature_nodes; |
| 104 | |
| 105 | /** bitmap of interfaces which have driver rx features configured */ |
| 106 | uword **sw_if_index_has_features; |
| 107 | |
| 108 | /** feature reference counts by interface */ |
| 109 | i16 **feature_count_by_sw_if_index; |
| 110 | |
Damjan Marion | 87cd119 | 2016-11-04 11:00:27 +0100 | [diff] [blame] | 111 | /** Feature arc index for device-input */ |
| 112 | u8 device_input_feature_arc_index; |
| 113 | |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 114 | /** convenience */ |
| 115 | vlib_main_t *vlib_main; |
| 116 | vnet_main_t *vnet_main; |
| 117 | } vnet_feature_main_t; |
| 118 | |
| 119 | extern vnet_feature_main_t feature_main; |
| 120 | |
Damjan Marion | 6e36351 | 2018-08-10 22:39:11 +0200 | [diff] [blame] | 121 | #ifndef CLIB_MARCH_VARIANT |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 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 | } \ |
Damjan Marion | 72d2c4f | 2018-04-05 21:32:29 +0200 | [diff] [blame] | 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 | } \ |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 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 | } \ |
Damjan Marion | 72d2c4f | 2018-04-05 21:32:29 +0200 | [diff] [blame] | 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 | } \ |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 160 | __VA_ARGS__ vnet_feature_registration_t vnet_feat_##x |
Dave Barach | 2dd192b | 2018-11-19 09:31:48 -0500 | [diff] [blame] | 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 | |
Damjan Marion | 6e36351 | 2018-08-10 22:39:11 +0200 | [diff] [blame] | 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 |
Dave Barach | 2dd192b | 2018-11-19 09:31:48 -0500 | [diff] [blame] | 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 | |
Damjan Marion | 6e36351 | 2018-08-10 22:39:11 +0200 | [diff] [blame] | 198 | #endif |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 199 | |
| 200 | void |
Damjan Marion | 87cd119 | 2016-11-04 11:00:27 +0100 | [diff] [blame] | 201 | vnet_config_update_feature_count (vnet_feature_main_t * fm, u8 arc, |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 202 | u32 sw_if_index, int is_add); |
| 203 | |
Damjan Marion | 87cd119 | 2016-11-04 11:00:27 +0100 | [diff] [blame] | 204 | u32 vnet_get_feature_index (u8 arc, const char *s); |
| 205 | u8 vnet_get_feature_arc_index (const char *s); |
Pavel Kotucek | 7490a75 | 2016-11-15 09:19:11 +0100 | [diff] [blame] | 206 | vnet_feature_registration_t *vnet_get_feature_reg (const char *arc_name, |
| 207 | const char *node_name); |
| 208 | |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 209 | |
Damjan Marion | 96b41f7 | 2016-11-10 18:01:42 +0100 | [diff] [blame] | 210 | int |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 211 | vnet_feature_enable_disable_with_index (u8 arc_index, u32 feature_index, |
| 212 | u32 sw_if_index, int enable_disable, |
| 213 | void *feature_config, |
| 214 | u32 n_feature_config_bytes); |
| 215 | |
| 216 | int |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 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 | |
Neale Ranns | 5d0136f | 2020-05-12 08:51:02 +0000 | [diff] [blame] | 222 | u32 |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 223 | vnet_feature_modify_end_node (u8 arc_index, u32 sw_if_index, u32 node_index); |
| 224 | |
Steven Luong | 71e5b47 | 2019-10-10 11:36:41 -0700 | [diff] [blame] | 225 | static_always_inline u32 |
| 226 | vnet_get_feature_count (u8 arc, u32 sw_if_index) |
| 227 | { |
| 228 | vnet_feature_main_t *fm = &feature_main; |
| 229 | return (fm->feature_count_by_sw_if_index[arc][sw_if_index]); |
| 230 | } |
| 231 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 232 | static inline vnet_feature_config_main_t * |
| 233 | vnet_get_feature_arc_config_main (u8 arc_index) |
| 234 | { |
| 235 | vnet_feature_main_t *fm = &feature_main; |
| 236 | |
| 237 | if (arc_index == (u8) ~ 0) |
| 238 | return 0; |
| 239 | |
| 240 | return &fm->feature_config_mains[arc_index]; |
| 241 | } |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 242 | |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 243 | static_always_inline vnet_feature_config_main_t * |
| 244 | vnet_feature_get_config_main (u16 arc) |
| 245 | { |
| 246 | vnet_feature_main_t *fm = &feature_main; |
| 247 | return &fm->feature_config_mains[arc]; |
| 248 | } |
| 249 | |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 250 | static_always_inline int |
Damjan Marion | 87cd119 | 2016-11-04 11:00:27 +0100 | [diff] [blame] | 251 | vnet_have_features (u8 arc, u32 sw_if_index) |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 252 | { |
| 253 | vnet_feature_main_t *fm = &feature_main; |
| 254 | return clib_bitmap_get (fm->sw_if_index_has_features[arc], sw_if_index); |
| 255 | } |
| 256 | |
| 257 | static_always_inline u32 |
Damjan Marion | 87cd119 | 2016-11-04 11:00:27 +0100 | [diff] [blame] | 258 | vnet_get_feature_config_index (u8 arc, u32 sw_if_index) |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 259 | { |
| 260 | vnet_feature_main_t *fm = &feature_main; |
| 261 | vnet_feature_config_main_t *cm = &fm->feature_config_mains[arc]; |
| 262 | return vec_elt (cm->config_index_by_sw_if_index, sw_if_index); |
| 263 | } |
| 264 | |
Damjan Marion | 87cd119 | 2016-11-04 11:00:27 +0100 | [diff] [blame] | 265 | static_always_inline void * |
| 266 | vnet_feature_arc_start_with_data (u8 arc, u32 sw_if_index, u32 * next, |
| 267 | vlib_buffer_t * b, u32 n_data_bytes) |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 268 | { |
| 269 | vnet_feature_main_t *fm = &feature_main; |
Damjan Marion | 87cd119 | 2016-11-04 11:00:27 +0100 | [diff] [blame] | 270 | vnet_feature_config_main_t *cm; |
| 271 | cm = &fm->feature_config_mains[arc]; |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 272 | |
| 273 | if (PREDICT_FALSE (vnet_have_features (arc, sw_if_index))) |
| 274 | { |
Damjan Marion | aa682a3 | 2018-04-26 22:45:40 +0200 | [diff] [blame] | 275 | vnet_buffer (b)->feature_arc_index = arc; |
Damjan Marion | 87cd119 | 2016-11-04 11:00:27 +0100 | [diff] [blame] | 276 | b->current_config_index = |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 277 | vec_elt (cm->config_index_by_sw_if_index, sw_if_index); |
Damjan Marion | 87cd119 | 2016-11-04 11:00:27 +0100 | [diff] [blame] | 278 | return vnet_get_config_data (&cm->config_main, &b->current_config_index, |
| 279 | next, n_data_bytes); |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 280 | } |
Damjan Marion | 05bb1dd | 2016-11-08 21:28:22 +0100 | [diff] [blame] | 281 | return 0; |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 282 | } |
| 283 | |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 284 | static_always_inline void * |
| 285 | vnet_feature_arc_start_w_cfg_index (u8 arc, |
| 286 | u32 sw_if_index, |
| 287 | u32 * next, |
| 288 | vlib_buffer_t * b, u32 cfg_index) |
| 289 | { |
| 290 | vnet_feature_main_t *fm = &feature_main; |
| 291 | vnet_feature_config_main_t *cm; |
| 292 | cm = &fm->feature_config_mains[arc]; |
| 293 | |
| 294 | vnet_buffer (b)->feature_arc_index = arc; |
| 295 | b->current_config_index = cfg_index; |
| 296 | |
| 297 | return vnet_get_config_data (&cm->config_main, &b->current_config_index, |
| 298 | next, 0); |
| 299 | } |
| 300 | |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 301 | static_always_inline void |
Damjan Marion | 87cd119 | 2016-11-04 11:00:27 +0100 | [diff] [blame] | 302 | vnet_feature_arc_start (u8 arc, u32 sw_if_index, u32 * next0, |
| 303 | vlib_buffer_t * b0) |
| 304 | { |
| 305 | vnet_feature_arc_start_with_data (arc, sw_if_index, next0, b0, 0); |
| 306 | } |
| 307 | |
| 308 | static_always_inline void * |
Damjan Marion | 7d98a12 | 2018-07-19 20:42:08 +0200 | [diff] [blame] | 309 | vnet_feature_next_with_data (u32 * next0, vlib_buffer_t * b0, |
| 310 | u32 n_data_bytes) |
Damjan Marion | 87cd119 | 2016-11-04 11:00:27 +0100 | [diff] [blame] | 311 | { |
| 312 | vnet_feature_main_t *fm = &feature_main; |
Damjan Marion | aa682a3 | 2018-04-26 22:45:40 +0200 | [diff] [blame] | 313 | u8 arc = vnet_buffer (b0)->feature_arc_index; |
Damjan Marion | 87cd119 | 2016-11-04 11:00:27 +0100 | [diff] [blame] | 314 | vnet_feature_config_main_t *cm = &fm->feature_config_mains[arc]; |
| 315 | |
| 316 | return vnet_get_config_data (&cm->config_main, |
| 317 | &b0->current_config_index, next0, |
| 318 | n_data_bytes); |
| 319 | } |
| 320 | |
| 321 | static_always_inline void |
Damjan Marion | 7d98a12 | 2018-07-19 20:42:08 +0200 | [diff] [blame] | 322 | vnet_feature_next (u32 * next0, vlib_buffer_t * b0) |
Damjan Marion | 87cd119 | 2016-11-04 11:00:27 +0100 | [diff] [blame] | 323 | { |
Damjan Marion | 7d98a12 | 2018-07-19 20:42:08 +0200 | [diff] [blame] | 324 | vnet_feature_next_with_data (next0, b0, 0); |
Damjan Marion | 87cd119 | 2016-11-04 11:00:27 +0100 | [diff] [blame] | 325 | } |
| 326 | |
Neale Ranns | 5cd31ec | 2020-02-24 12:54:31 +0000 | [diff] [blame] | 327 | static_always_inline void |
| 328 | vnet_feature_next_u16 (u16 * next0, vlib_buffer_t * b0) |
| 329 | { |
| 330 | u32 next32; |
| 331 | vnet_feature_next_with_data (&next32, b0, 0); |
| 332 | *next0 = next32; |
| 333 | } |
| 334 | |
Damjan Marion | dc09133 | 2018-02-25 22:52:07 +0100 | [diff] [blame] | 335 | static_always_inline int |
| 336 | vnet_device_input_have_features (u32 sw_if_index) |
| 337 | { |
| 338 | vnet_feature_main_t *fm = &feature_main; |
| 339 | return vnet_have_features (fm->device_input_feature_arc_index, sw_if_index); |
| 340 | } |
| 341 | |
Damjan Marion | 87cd119 | 2016-11-04 11:00:27 +0100 | [diff] [blame] | 342 | static_always_inline void |
| 343 | vnet_feature_start_device_input_x1 (u32 sw_if_index, u32 * next0, |
Damjan Marion | 35af9e5 | 2017-03-06 12:02:50 +0100 | [diff] [blame] | 344 | vlib_buffer_t * b0) |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 345 | { |
| 346 | vnet_feature_main_t *fm = &feature_main; |
| 347 | vnet_feature_config_main_t *cm; |
Damjan Marion | 87cd119 | 2016-11-04 11:00:27 +0100 | [diff] [blame] | 348 | u8 feature_arc_index = fm->device_input_feature_arc_index; |
| 349 | cm = &fm->feature_config_mains[feature_arc_index]; |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 350 | |
| 351 | if (PREDICT_FALSE |
| 352 | (clib_bitmap_get |
Damjan Marion | 87cd119 | 2016-11-04 11:00:27 +0100 | [diff] [blame] | 353 | (fm->sw_if_index_has_features[feature_arc_index], sw_if_index))) |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 354 | { |
| 355 | /* |
| 356 | * Save next0 so that the last feature in the chain |
| 357 | * can skip ethernet-input if indicated... |
| 358 | */ |
Damjan Marion | 35af9e5 | 2017-03-06 12:02:50 +0100 | [diff] [blame] | 359 | u16 adv; |
| 360 | |
Damjan Marion | 35af9e5 | 2017-03-06 12:02:50 +0100 | [diff] [blame] | 361 | adv = device_input_next_node_advance[*next0]; |
Damjan Marion | 35af9e5 | 2017-03-06 12:02:50 +0100 | [diff] [blame] | 362 | vlib_buffer_advance (b0, -adv); |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 363 | |
Damjan Marion | aa682a3 | 2018-04-26 22:45:40 +0200 | [diff] [blame] | 364 | vnet_buffer (b0)->feature_arc_index = feature_arc_index; |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 365 | b0->current_config_index = |
| 366 | vec_elt (cm->config_index_by_sw_if_index, sw_if_index); |
| 367 | vnet_get_config_data (&cm->config_main, &b0->current_config_index, |
| 368 | next0, /* # bytes of config data */ 0); |
| 369 | } |
| 370 | } |
| 371 | |
Damjan Marion | 87cd119 | 2016-11-04 11:00:27 +0100 | [diff] [blame] | 372 | static_always_inline void |
| 373 | vnet_feature_start_device_input_x2 (u32 sw_if_index, |
| 374 | u32 * next0, |
| 375 | u32 * next1, |
Damjan Marion | 35af9e5 | 2017-03-06 12:02:50 +0100 | [diff] [blame] | 376 | vlib_buffer_t * b0, vlib_buffer_t * b1) |
Damjan Marion | 87cd119 | 2016-11-04 11:00:27 +0100 | [diff] [blame] | 377 | { |
| 378 | vnet_feature_main_t *fm = &feature_main; |
| 379 | vnet_feature_config_main_t *cm; |
| 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 |
| 384 | (clib_bitmap_get |
| 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 | */ |
Damjan Marion | 35af9e5 | 2017-03-06 12:02:50 +0100 | [diff] [blame] | 391 | u16 adv; |
| 392 | |
Damjan Marion | 35af9e5 | 2017-03-06 12:02:50 +0100 | [diff] [blame] | 393 | adv = device_input_next_node_advance[*next0]; |
Damjan Marion | 35af9e5 | 2017-03-06 12:02:50 +0100 | [diff] [blame] | 394 | vlib_buffer_advance (b0, -adv); |
| 395 | |
Damjan Marion | 35af9e5 | 2017-03-06 12:02:50 +0100 | [diff] [blame] | 396 | adv = device_input_next_node_advance[*next1]; |
Damjan Marion | 35af9e5 | 2017-03-06 12:02:50 +0100 | [diff] [blame] | 397 | vlib_buffer_advance (b1, -adv); |
Damjan Marion | 87cd119 | 2016-11-04 11:00:27 +0100 | [diff] [blame] | 398 | |
Damjan Marion | aa682a3 | 2018-04-26 22:45:40 +0200 | [diff] [blame] | 399 | vnet_buffer (b0)->feature_arc_index = feature_arc_index; |
| 400 | vnet_buffer (b1)->feature_arc_index = feature_arc_index; |
Damjan Marion | 87cd119 | 2016-11-04 11:00:27 +0100 | [diff] [blame] | 401 | b0->current_config_index = |
| 402 | vec_elt (cm->config_index_by_sw_if_index, sw_if_index); |
| 403 | b1->current_config_index = b0->current_config_index; |
| 404 | vnet_get_config_data (&cm->config_main, &b0->current_config_index, |
| 405 | next0, /* # bytes of config data */ 0); |
| 406 | vnet_get_config_data (&cm->config_main, &b1->current_config_index, |
| 407 | next1, /* # bytes of config data */ 0); |
| 408 | } |
| 409 | } |
| 410 | |
Damjan Marion | 7dc4146 | 2016-11-15 19:47:58 +0100 | [diff] [blame] | 411 | static_always_inline void |
| 412 | vnet_feature_start_device_input_x4 (u32 sw_if_index, |
| 413 | u32 * next0, |
| 414 | u32 * next1, |
| 415 | u32 * next2, |
| 416 | u32 * next3, |
| 417 | vlib_buffer_t * b0, |
| 418 | vlib_buffer_t * b1, |
Damjan Marion | 35af9e5 | 2017-03-06 12:02:50 +0100 | [diff] [blame] | 419 | vlib_buffer_t * b2, vlib_buffer_t * b3) |
Damjan Marion | 7dc4146 | 2016-11-15 19:47:58 +0100 | [diff] [blame] | 420 | { |
| 421 | vnet_feature_main_t *fm = &feature_main; |
| 422 | vnet_feature_config_main_t *cm; |
| 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 |
| 427 | (clib_bitmap_get |
| 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 | */ |
Damjan Marion | 35af9e5 | 2017-03-06 12:02:50 +0100 | [diff] [blame] | 434 | u16 adv; |
| 435 | |
Damjan Marion | 35af9e5 | 2017-03-06 12:02:50 +0100 | [diff] [blame] | 436 | adv = device_input_next_node_advance[*next0]; |
Damjan Marion | 35af9e5 | 2017-03-06 12:02:50 +0100 | [diff] [blame] | 437 | vlib_buffer_advance (b0, -adv); |
| 438 | |
Damjan Marion | 35af9e5 | 2017-03-06 12:02:50 +0100 | [diff] [blame] | 439 | adv = device_input_next_node_advance[*next1]; |
Damjan Marion | 35af9e5 | 2017-03-06 12:02:50 +0100 | [diff] [blame] | 440 | vlib_buffer_advance (b1, -adv); |
| 441 | |
Damjan Marion | 35af9e5 | 2017-03-06 12:02:50 +0100 | [diff] [blame] | 442 | adv = device_input_next_node_advance[*next2]; |
Damjan Marion | 35af9e5 | 2017-03-06 12:02:50 +0100 | [diff] [blame] | 443 | vlib_buffer_advance (b2, -adv); |
| 444 | |
Damjan Marion | 35af9e5 | 2017-03-06 12:02:50 +0100 | [diff] [blame] | 445 | adv = device_input_next_node_advance[*next3]; |
Damjan Marion | 35af9e5 | 2017-03-06 12:02:50 +0100 | [diff] [blame] | 446 | vlib_buffer_advance (b3, -adv); |
Damjan Marion | 7dc4146 | 2016-11-15 19:47:58 +0100 | [diff] [blame] | 447 | |
Damjan Marion | aa682a3 | 2018-04-26 22:45:40 +0200 | [diff] [blame] | 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; |
Damjan Marion | 7dc4146 | 2016-11-15 19:47:58 +0100 | [diff] [blame] | 452 | |
| 453 | b0->current_config_index = |
| 454 | vec_elt (cm->config_index_by_sw_if_index, sw_if_index); |
| 455 | b1->current_config_index = b0->current_config_index; |
| 456 | b2->current_config_index = b0->current_config_index; |
| 457 | b3->current_config_index = b0->current_config_index; |
| 458 | |
| 459 | vnet_get_config_data (&cm->config_main, &b0->current_config_index, |
| 460 | next0, /* # bytes of config data */ 0); |
| 461 | vnet_get_config_data (&cm->config_main, &b1->current_config_index, |
| 462 | next1, /* # bytes of config data */ 0); |
| 463 | vnet_get_config_data (&cm->config_main, &b2->current_config_index, |
| 464 | next2, /* # bytes of config data */ 0); |
| 465 | vnet_get_config_data (&cm->config_main, &b3->current_config_index, |
| 466 | next3, /* # bytes of config data */ 0); |
| 467 | } |
| 468 | } |
Damjan Marion | 87cd119 | 2016-11-04 11:00:27 +0100 | [diff] [blame] | 469 | |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 470 | #define VNET_FEATURES(...) (char*[]) { __VA_ARGS__, 0} |
| 471 | |
Dave Barach | 2dd192b | 2018-11-19 09:31:48 -0500 | [diff] [blame] | 472 | clib_error_t *vnet_feature_arc_init |
| 473 | (vlib_main_t * vm, |
| 474 | vnet_config_main_t * vcm, |
| 475 | char **feature_start_nodes, |
| 476 | int num_feature_start_nodes, |
Dave Barach | 5f9f3c8 | 2019-11-22 17:42:58 -0500 | [diff] [blame] | 477 | char *last_in_arc, |
Dave Barach | 2dd192b | 2018-11-19 09:31:48 -0500 | [diff] [blame] | 478 | vnet_feature_registration_t * first_reg, |
| 479 | vnet_feature_constraint_registration_t * first_const_set, |
| 480 | char ***in_feature_nodes); |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 481 | |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 482 | void vnet_interface_features_show (vlib_main_t * vm, u32 sw_if_index, |
| 483 | int verbose); |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 484 | |
Neale Ranns | c8972fe | 2019-12-02 23:10:08 +0000 | [diff] [blame] | 485 | typedef void (*vnet_feature_update_cb_t) (u32 sw_if_index, |
| 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 | |
Dave Barach | caebbcf | 2020-07-29 18:07:02 -0400 | [diff] [blame] | 491 | int |
| 492 | vnet_feature_is_enabled (const char *arc_name, const char *feature_node_name, |
| 493 | u32 sw_if_index); |
| 494 | |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 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 | */ |