blob: 4a5127db6ac07d04b20715691ac361877c789e02 [file] [log] [blame]
Damjan Marion22311502016-10-28 20:30:15 +02001/*
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#include <vnet/feature/feature.h>
Neale Rannsc8972fe2019-12-02 23:10:08 +000017
Damjan Marion22311502016-10-28 20:30:15 +020018
19vnet_feature_main_t feature_main;
20
Neale Rannsc8972fe2019-12-02 23:10:08 +000021typedef struct vnet_feature_upd_registration_t_
22{
23 vnet_feature_update_cb_t cb;
24 void *data;
25} vnet_feature_upd_registration_t;
26
27static vnet_feature_upd_registration_t *regs;
28
29void
30vnet_feature_register (vnet_feature_update_cb_t cb, void *data)
31{
32 vnet_feature_upd_registration_t *reg;
33
34 vec_add2 (regs, reg, 1);
35
36 reg->cb = cb;
37 reg->data = data;
38}
39
40static void
41vent_feature_reg_invoke (u32 sw_if_index, u8 arc_index, u8 is_enable)
42{
43 vnet_feature_upd_registration_t *reg;
44
45 vec_foreach (reg, regs)
46 reg->cb (sw_if_index, arc_index, is_enable, reg->data);
47}
48
49
Damjan Marion22311502016-10-28 20:30:15 +020050static clib_error_t *
51vnet_feature_init (vlib_main_t * vm)
52{
53 vnet_feature_main_t *fm = &feature_main;
54 vnet_feature_registration_t *freg;
55 vnet_feature_arc_registration_t *areg;
Dave Barach2dd192b2018-11-19 09:31:48 -050056 vnet_feature_constraint_registration_t *creg;
Damjan Marion22311502016-10-28 20:30:15 +020057 u32 arc_index = 0;
58
59 fm->arc_index_by_name = hash_create_string (0, sizeof (uword));
60 areg = fm->next_arc;
61
62 /* process feature arc registrations */
63 while (areg)
64 {
65 char *s;
66 int i = 0;
67 areg->feature_arc_index = arc_index;
Damjan Marion8b3191e2016-11-09 19:54:20 +010068 if (areg->arc_index_ptr)
69 *areg->arc_index_ptr = arc_index;
Damjan Marion22311502016-10-28 20:30:15 +020070 hash_set_mem (fm->arc_index_by_name, areg->arc_name,
71 pointer_to_uword (areg));
72
73 /* process start nodes */
74 while ((s = areg->start_nodes[i]))
75 {
Damjan Marion22311502016-10-28 20:30:15 +020076 i++;
77 }
78 areg->n_start_nodes = i;
79
80 /* next */
81 areg = areg->next;
82 arc_index++;
83 }
84
85 vec_validate (fm->next_feature_by_arc, arc_index - 1);
86 vec_validate (fm->feature_nodes, arc_index - 1);
87 vec_validate (fm->feature_config_mains, arc_index - 1);
88 vec_validate (fm->next_feature_by_name, arc_index - 1);
89 vec_validate (fm->sw_if_index_has_features, arc_index - 1);
90 vec_validate (fm->feature_count_by_sw_if_index, arc_index - 1);
Dave Barach2dd192b2018-11-19 09:31:48 -050091 vec_validate (fm->next_constraint_by_arc, arc_index - 1);
Damjan Marion22311502016-10-28 20:30:15 +020092
93 freg = fm->next_feature;
94 while (freg)
95 {
Damjan Marion96b41f72016-11-10 18:01:42 +010096 vnet_feature_registration_t *next;
Damjan Marion22311502016-10-28 20:30:15 +020097 uword *p = hash_get_mem (fm->arc_index_by_name, freg->arc_name);
98 if (p == 0)
Florin Coras3d2a9142017-08-16 21:23:44 -070099 {
100 /* Don't start vpp with broken features arcs */
101 clib_warning ("Unknown feature arc '%s'", freg->arc_name);
102 os_exit (1);
103 }
Damjan Marion22311502016-10-28 20:30:15 +0200104
105 areg = uword_to_pointer (p[0], vnet_feature_arc_registration_t *);
106 arc_index = areg->feature_arc_index;
107
Damjan Marion96b41f72016-11-10 18:01:42 +0100108 next = freg->next;
Damjan Marion13adc3d2018-04-09 20:59:53 +0200109 freg->next_in_arc = fm->next_feature_by_arc[arc_index];
Damjan Marion96b41f72016-11-10 18:01:42 +0100110 fm->next_feature_by_arc[arc_index] = freg;
Damjan Marion22311502016-10-28 20:30:15 +0200111
112 /* next */
Damjan Marion96b41f72016-11-10 18:01:42 +0100113 freg = next;
Damjan Marion22311502016-10-28 20:30:15 +0200114 }
115
Dave Barach2dd192b2018-11-19 09:31:48 -0500116 /* Move bulk constraints to the constraint by arc lists */
117 creg = fm->next_constraint;
118 while (creg)
119 {
120 vnet_feature_constraint_registration_t *next;
121 uword *p = hash_get_mem (fm->arc_index_by_name, creg->arc_name);
122 if (p == 0)
123 {
124 /* Don't start vpp with broken features arcs */
125 clib_warning ("Unknown feature arc '%s'", creg->arc_name);
126 os_exit (1);
127 }
128
129 areg = uword_to_pointer (p[0], vnet_feature_arc_registration_t *);
130 arc_index = areg->feature_arc_index;
131
132 next = creg->next;
133 creg->next_in_arc = fm->next_constraint_by_arc[arc_index];
134 fm->next_constraint_by_arc[arc_index] = creg;
135
136 /* next */
137 creg = next;
138 }
139
140
Damjan Marion96b41f72016-11-10 18:01:42 +0100141 areg = fm->next_arc;
Damjan Marion22311502016-10-28 20:30:15 +0200142 while (areg)
143 {
144 clib_error_t *error;
145 vnet_feature_config_main_t *cm;
146 vnet_config_main_t *vcm;
Dave Baracha25def72018-11-26 11:04:45 -0500147 char **features_in_order, *last_feature;
Damjan Marion22311502016-10-28 20:30:15 +0200148
149 arc_index = areg->feature_arc_index;
150 cm = &fm->feature_config_mains[arc_index];
151 vcm = &cm->config_main;
Dave Barach2dd192b2018-11-19 09:31:48 -0500152 if ((error = vnet_feature_arc_init
153 (vm, vcm, areg->start_nodes, areg->n_start_nodes,
Dave Barach5f9f3c82019-11-22 17:42:58 -0500154 areg->last_in_arc,
Dave Barach2dd192b2018-11-19 09:31:48 -0500155 fm->next_feature_by_arc[arc_index],
156 fm->next_constraint_by_arc[arc_index],
157 &fm->feature_nodes[arc_index])))
Damjan Marion22311502016-10-28 20:30:15 +0200158 {
Florin Coras3d2a9142017-08-16 21:23:44 -0700159 clib_error_report (error);
160 os_exit (1);
Damjan Marion22311502016-10-28 20:30:15 +0200161 }
162
Dave Baracha25def72018-11-26 11:04:45 -0500163 features_in_order = fm->feature_nodes[arc_index];
164
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700165 /* If specified, verify that the last node in the arc is actually last */
Dave Baracha25def72018-11-26 11:04:45 -0500166 if (areg->last_in_arc && vec_len (features_in_order) > 0)
167 {
168 last_feature = features_in_order[vec_len (features_in_order) - 1];
169 if (strncmp (areg->last_in_arc, last_feature,
170 strlen (areg->last_in_arc)))
171 clib_warning
172 ("WARNING: %s arc: last node is %s, but expected %s!",
173 areg->arc_name, last_feature, areg->last_in_arc);
174 }
175
Damjan Marion22311502016-10-28 20:30:15 +0200176 fm->next_feature_by_name[arc_index] =
177 hash_create_string (0, sizeof (uword));
178 freg = fm->next_feature_by_arc[arc_index];
179
180 while (freg)
181 {
182 hash_set_mem (fm->next_feature_by_name[arc_index],
183 freg->node_name, pointer_to_uword (freg));
Damjan Marion13adc3d2018-04-09 20:59:53 +0200184 freg = freg->next_in_arc;
Damjan Marion22311502016-10-28 20:30:15 +0200185 }
186
187 /* next */
188 areg = areg->next;
189 arc_index++;
190 }
191
192 return 0;
193}
194
195VLIB_INIT_FUNCTION (vnet_feature_init);
196
Damjan Marion87cd1192016-11-04 11:00:27 +0100197u8
198vnet_get_feature_arc_index (const char *s)
Damjan Marion22311502016-10-28 20:30:15 +0200199{
200 vnet_feature_main_t *fm = &feature_main;
201 vnet_feature_arc_registration_t *reg;
202 uword *p;
203
204 p = hash_get_mem (fm->arc_index_by_name, s);
205 if (p == 0)
206 return ~0;
207
208 reg = uword_to_pointer (p[0], vnet_feature_arc_registration_t *);
209 return reg->feature_arc_index;
210}
211
Pavel Kotucek7490a752016-11-15 09:19:11 +0100212vnet_feature_registration_t *
213vnet_get_feature_reg (const char *arc_name, const char *node_name)
214{
215 u8 arc_index;
216
217 arc_index = vnet_get_feature_arc_index (arc_name);
218 if (arc_index == (u8) ~ 0)
219 return 0;
220
221 vnet_feature_main_t *fm = &feature_main;
222 vnet_feature_registration_t *reg;
223 uword *p;
224
225 p = hash_get_mem (fm->next_feature_by_name[arc_index], node_name);
226 if (p == 0)
227 return 0;
228
229 reg = uword_to_pointer (p[0], vnet_feature_registration_t *);
230 return reg;
231}
232
Damjan Marion22311502016-10-28 20:30:15 +0200233u32
Damjan Marion87cd1192016-11-04 11:00:27 +0100234vnet_get_feature_index (u8 arc, const char *s)
Damjan Marion22311502016-10-28 20:30:15 +0200235{
236 vnet_feature_main_t *fm = &feature_main;
237 vnet_feature_registration_t *reg;
238 uword *p;
239
Damjan Marion21da6ce2016-11-28 18:21:59 +0100240 if (s == 0)
241 return ~0;
242
Damjan Marion22311502016-10-28 20:30:15 +0200243 p = hash_get_mem (fm->next_feature_by_name[arc], s);
244 if (p == 0)
245 return ~0;
246
247 reg = uword_to_pointer (p[0], vnet_feature_registration_t *);
Damjan Marion8b3191e2016-11-09 19:54:20 +0100248 return reg->feature_index;
Damjan Marion22311502016-10-28 20:30:15 +0200249}
250
Damjan Marion96b41f72016-11-10 18:01:42 +0100251int
Damjan Marion8b3191e2016-11-09 19:54:20 +0100252vnet_feature_enable_disable_with_index (u8 arc_index, u32 feature_index,
253 u32 sw_if_index, int enable_disable,
254 void *feature_config,
255 u32 n_feature_config_bytes)
Damjan Marion22311502016-10-28 20:30:15 +0200256{
257 vnet_feature_main_t *fm = &feature_main;
258 vnet_feature_config_main_t *cm;
Damjan Marion21da6ce2016-11-28 18:21:59 +0100259 i16 feature_count;
Matthew Smithc3267ed2018-05-15 15:51:30 -0500260 u32 ci;
Damjan Marion22311502016-10-28 20:30:15 +0200261
Damjan Marion05bb1dd2016-11-08 21:28:22 +0100262 if (arc_index == (u8) ~ 0)
Damjan Marion96b41f72016-11-10 18:01:42 +0100263 return VNET_API_ERROR_INVALID_VALUE;
Damjan Marion22311502016-10-28 20:30:15 +0200264
Damjan Marion22311502016-10-28 20:30:15 +0200265 if (feature_index == ~0)
Damjan Marion96b41f72016-11-10 18:01:42 +0100266 return VNET_API_ERROR_INVALID_VALUE_2;
Damjan Marion8b3191e2016-11-09 19:54:20 +0100267
268 cm = &fm->feature_config_mains[arc_index];
269 vec_validate_init_empty (cm->config_index_by_sw_if_index, sw_if_index, ~0);
Matthew Smithc3267ed2018-05-15 15:51:30 -0500270 ci = cm->config_index_by_sw_if_index[sw_if_index];
Damjan Marion22311502016-10-28 20:30:15 +0200271
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100272 vec_validate (fm->feature_count_by_sw_if_index[arc_index], sw_if_index);
Damjan Marion21da6ce2016-11-28 18:21:59 +0100273 feature_count = fm->feature_count_by_sw_if_index[arc_index][sw_if_index];
274
275 if (!enable_disable && feature_count < 1)
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100276 return 0;
277
Damjan Marion22311502016-10-28 20:30:15 +0200278 ci = (enable_disable
279 ? vnet_config_add_feature
280 : vnet_config_del_feature)
281 (vlib_get_main (), &cm->config_main, ci, feature_index, feature_config,
282 n_feature_config_bytes);
Matthew Smithc3267ed2018-05-15 15:51:30 -0500283 if (ci == ~0)
Klement Sekera3ecc2212018-03-27 10:34:43 +0200284 {
285 return 0;
286 }
Damjan Marion22311502016-10-28 20:30:15 +0200287 cm->config_index_by_sw_if_index[sw_if_index] = ci;
288
Damjan Marion21da6ce2016-11-28 18:21:59 +0100289 /* update feature count */
290 enable_disable = (enable_disable > 0);
291 feature_count += enable_disable ? 1 : -1;
Damjan Marion21da6ce2016-11-28 18:21:59 +0100292 ASSERT (feature_count >= 0);
Damjan Marion22311502016-10-28 20:30:15 +0200293
Damjan Marion21da6ce2016-11-28 18:21:59 +0100294 fm->sw_if_index_has_features[arc_index] =
295 clib_bitmap_set (fm->sw_if_index_has_features[arc_index], sw_if_index,
296 (feature_count > 0));
Neale Rannsc8972fe2019-12-02 23:10:08 +0000297 vent_feature_reg_invoke (sw_if_index, arc_index, (feature_count > 0));
Damjan Marion21da6ce2016-11-28 18:21:59 +0100298
299 fm->feature_count_by_sw_if_index[arc_index][sw_if_index] = feature_count;
Damjan Marion96b41f72016-11-10 18:01:42 +0100300 return 0;
Damjan Marion22311502016-10-28 20:30:15 +0200301}
302
Damjan Marion8b3191e2016-11-09 19:54:20 +0100303int
304vnet_feature_enable_disable (const char *arc_name, const char *node_name,
305 u32 sw_if_index, int enable_disable,
306 void *feature_config, u32 n_feature_config_bytes)
307{
308 u32 feature_index;
309 u8 arc_index;
310
311 arc_index = vnet_get_feature_arc_index (arc_name);
312
313 if (arc_index == (u8) ~ 0)
314 return VNET_API_ERROR_INVALID_VALUE;
315
316 feature_index = vnet_get_feature_index (arc_index, node_name);
317
318 return vnet_feature_enable_disable_with_index (arc_index, feature_index,
319 sw_if_index, enable_disable,
320 feature_config,
321 n_feature_config_bytes);
322}
323
Neale Ranns4ec36c52020-03-31 09:21:29 -0400324int
325vnet_feature_modify_end_node (u8 arc_index,
326 u32 sw_if_index, u32 end_node_index)
327{
328 vnet_feature_main_t *fm = &feature_main;
329 vnet_feature_config_main_t *cm;
330 u32 ci;
331
332 if (arc_index == (u8) ~ 0)
333 return VNET_API_ERROR_INVALID_VALUE;
334
335 if (end_node_index == ~0)
336 return VNET_API_ERROR_INVALID_VALUE_2;
337
338 cm = &fm->feature_config_mains[arc_index];
339 vec_validate_init_empty (cm->config_index_by_sw_if_index, sw_if_index, ~0);
340 ci = cm->config_index_by_sw_if_index[sw_if_index];
341
342 ci = vnet_config_modify_end_node (vlib_get_main (), &cm->config_main,
343 ci, end_node_index);
344
345 if (ci == ~0)
346 return 0;
347
348 cm->config_index_by_sw_if_index[sw_if_index] = ci;
349
350 return 0;
351}
352
Dave Barach525c9d02018-05-26 10:48:55 -0400353static int
354feature_cmp (void *a1, void *a2)
355{
356 vnet_feature_registration_t *reg1 = a1;
357 vnet_feature_registration_t *reg2 = a2;
358
359 return (int) reg1->feature_index - reg2->feature_index;
360}
Damjan Marion22311502016-10-28 20:30:15 +0200361
362/** Display the set of available driver features.
363 Useful for verifying that expected features are present
364*/
365
366static clib_error_t *
367show_features_command_fn (vlib_main_t * vm,
368 unformat_input_t * input, vlib_cli_command_t * cmd)
369{
370 vnet_feature_main_t *fm = &feature_main;
371 vnet_feature_arc_registration_t *areg;
372 vnet_feature_registration_t *freg;
Dave Barach525c9d02018-05-26 10:48:55 -0400373 vnet_feature_registration_t *feature_regs = 0;
374 int verbose = 0;
375
376 if (unformat (input, "verbose"))
377 verbose = 1;
Damjan Marion22311502016-10-28 20:30:15 +0200378
379 vlib_cli_output (vm, "Available feature paths");
380
381 areg = fm->next_arc;
382 while (areg)
383 {
Dave Barach525c9d02018-05-26 10:48:55 -0400384 if (verbose)
385 vlib_cli_output (vm, "[%2d] %s:", areg->feature_arc_index,
386 areg->arc_name);
387 else
388 vlib_cli_output (vm, "%s:", areg->arc_name);
389
Damjan Marion96b41f72016-11-10 18:01:42 +0100390 freg = fm->next_feature_by_arc[areg->feature_arc_index];
391 while (freg)
392 {
Dave Barach525c9d02018-05-26 10:48:55 -0400393 vec_add1 (feature_regs, freg[0]);
Damjan Marion13adc3d2018-04-09 20:59:53 +0200394 freg = freg->next_in_arc;
Damjan Marion96b41f72016-11-10 18:01:42 +0100395 }
Damjan Marion22311502016-10-28 20:30:15 +0200396
Dave Barach525c9d02018-05-26 10:48:55 -0400397 vec_sort_with_function (feature_regs, feature_cmp);
Damjan Marion22311502016-10-28 20:30:15 +0200398
Dave Barach525c9d02018-05-26 10:48:55 -0400399 vec_foreach (freg, feature_regs)
400 {
401 if (verbose)
402 vlib_cli_output (vm, " [%2d]: %s\n", freg->feature_index,
403 freg->node_name);
404 else
405 vlib_cli_output (vm, " %s\n", freg->node_name);
406 }
407 vec_reset_length (feature_regs);
Damjan Marion22311502016-10-28 20:30:15 +0200408 /* next */
409 areg = areg->next;
410 }
Dave Barach525c9d02018-05-26 10:48:55 -0400411 vec_free (feature_regs);
Damjan Marion22311502016-10-28 20:30:15 +0200412
413 return 0;
414}
415
416/*?
417 * Display the set of available driver features
418 *
419 * @cliexpar
420 * Example:
Dave Barach525c9d02018-05-26 10:48:55 -0400421 * @cliexcmd{show features [verbose]}
Damjan Marion22311502016-10-28 20:30:15 +0200422 * @cliexend
423 * @endparblock
424?*/
425/* *INDENT-OFF* */
426VLIB_CLI_COMMAND (show_features_command, static) = {
427 .path = "show features",
Paul Vinciguerrabaa17102019-11-06 15:41:45 -0500428 .short_help = "show features [verbose]",
Damjan Marion22311502016-10-28 20:30:15 +0200429 .function = show_features_command_fn,
430};
431/* *INDENT-ON* */
432
433/** Display the set of driver features configured on a specific interface
434 * Called by "show interface" handler
435 */
436
437void
Dave Barach525c9d02018-05-26 10:48:55 -0400438vnet_interface_features_show (vlib_main_t * vm, u32 sw_if_index, int verbose)
Damjan Marion22311502016-10-28 20:30:15 +0200439{
440 vnet_feature_main_t *fm = &feature_main;
441 u32 node_index, current_config_index;
442 u16 feature_arc;
443 vnet_feature_config_main_t *cm = fm->feature_config_mains;
444 vnet_feature_arc_registration_t *areg;
445 vnet_config_main_t *vcm;
446 vnet_config_t *cfg;
447 u32 cfg_index;
448 vnet_config_feature_t *feat;
449 vlib_node_t *n;
450 int i;
451
Dave Barach525c9d02018-05-26 10:48:55 -0400452 vlib_cli_output (vm, "Feature paths configured on %U...",
Damjan Marion22311502016-10-28 20:30:15 +0200453 format_vnet_sw_if_index_name,
454 vnet_get_main (), sw_if_index);
455
456 areg = fm->next_arc;
457 while (areg)
458 {
459 feature_arc = areg->feature_arc_index;
460 vcm = &(cm[feature_arc].config_main);
461
462 vlib_cli_output (vm, "\n%s:", areg->arc_name);
463 areg = areg->next;
464
465 if (NULL == cm[feature_arc].config_index_by_sw_if_index ||
Damjan Marion87cd1192016-11-04 11:00:27 +0100466 vec_len (cm[feature_arc].config_index_by_sw_if_index) <=
467 sw_if_index)
Damjan Marion22311502016-10-28 20:30:15 +0200468 {
469 vlib_cli_output (vm, " none configured");
470 continue;
471 }
472
473 current_config_index =
474 vec_elt (cm[feature_arc].config_index_by_sw_if_index, sw_if_index);
475
476 if (current_config_index == ~0)
477 {
478 vlib_cli_output (vm, " none configured");
479 continue;
480 }
481
482 ASSERT (current_config_index
483 < vec_len (vcm->config_pool_index_by_user_index));
484
485 cfg_index = vcm->config_pool_index_by_user_index[current_config_index];
486 cfg = pool_elt_at_index (vcm->config_pool, cfg_index);
487
488 for (i = 0; i < vec_len (cfg->features); i++)
489 {
490 feat = cfg->features + i;
491 node_index = feat->node_index;
492 n = vlib_get_node (vm, node_index);
Dave Barach525c9d02018-05-26 10:48:55 -0400493 if (verbose)
494 vlib_cli_output (vm, " [%2d] %v", feat->feature_index, n->name);
495 else
496 vlib_cli_output (vm, " %v", n->name);
Damjan Marion22311502016-10-28 20:30:15 +0200497 }
498 }
499}
500
Pavel Kotucek7490a752016-11-15 09:19:11 +0100501static clib_error_t *
502set_interface_features_command_fn (vlib_main_t * vm,
503 unformat_input_t * input,
504 vlib_cli_command_t * cmd)
505{
506 vnet_main_t *vnm = vnet_get_main ();
507 unformat_input_t _line_input, *line_input = &_line_input;
508 clib_error_t *error = 0;
509
510 u8 *arc_name = 0;
511 u8 *feature_name = 0;
512 u32 sw_if_index = ~0;
513 u8 enable = 1;
514
515 /* Get a line of input. */
516 if (!unformat_user (input, unformat_line_input, line_input))
Paul Vinciguerra3b4a6a12018-10-02 19:02:16 -0700517 return 0;
Pavel Kotucek7490a752016-11-15 09:19:11 +0100518
519 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
520 {
521 if (unformat
Paul Vinciguerraa4e2e7c2019-11-06 13:25:17 -0500522 (line_input, "%U %s arc %s", unformat_vnet_sw_interface, vnm,
523 &sw_if_index, &feature_name, &arc_name))
Pavel Kotucek7490a752016-11-15 09:19:11 +0100524 ;
525 else if (unformat (line_input, "disable"))
526 enable = 0;
527 else
528 {
529 error = unformat_parse_error (line_input);
530 goto done;
531 }
532 }
Paul Vinciguerraa4e2e7c2019-11-06 13:25:17 -0500533 if (!feature_name || !arc_name)
534 {
535 error = clib_error_return (0, "Both feature name and arc required...");
536 goto done;
537 }
Pavel Kotucek7490a752016-11-15 09:19:11 +0100538
539 if (sw_if_index == ~0)
540 {
541 error = clib_error_return (0, "Interface not specified...");
542 goto done;
543 }
544
545 vec_add1 (arc_name, 0);
546 vec_add1 (feature_name, 0);
547
Paul Vinciguerraa4e2e7c2019-11-06 13:25:17 -0500548 u8 arc_index;
549
550 arc_index = vnet_get_feature_arc_index ((const char *) arc_name);
551
552 if (arc_index == (u8) ~ 0)
553 {
554 error =
555 clib_error_return (0, "Unknown arc name (%s)... ",
556 (const char *) arc_name);
557 goto done;
558 }
559
Pavel Kotucek7490a752016-11-15 09:19:11 +0100560 vnet_feature_registration_t *reg;
561 reg =
562 vnet_get_feature_reg ((const char *) arc_name,
563 (const char *) feature_name);
564 if (reg == 0)
565 {
Paul Vinciguerraa4e2e7c2019-11-06 13:25:17 -0500566 error =
567 clib_error_return (0,
568 "Feature (%s) not registered to arc (%s)... See 'show features verbose' for valid feature/arc combinations. ",
569 feature_name, arc_name);
Pavel Kotucek7490a752016-11-15 09:19:11 +0100570 goto done;
571 }
572 if (reg->enable_disable_cb)
573 error = reg->enable_disable_cb (sw_if_index, enable);
574 if (!error)
575 vnet_feature_enable_disable ((const char *) arc_name,
576 (const char *) feature_name, sw_if_index,
577 enable, 0, 0);
578
579done:
580 vec_free (feature_name);
581 vec_free (arc_name);
Billy McFall614c1312017-03-01 17:01:06 -0500582 unformat_free (line_input);
Pavel Kotucek7490a752016-11-15 09:19:11 +0100583 return error;
584}
585
586/*?
587 * Set feature for given interface
588 *
589 * @cliexpar
590 * Example:
591 * @cliexcmd{set interface feature GigabitEthernet2/0/0 ip4_flow_classify arc ip4_unicast}
592 * @cliexend
593 * @endparblock
594?*/
595/* *INDENT-OFF* */
596VLIB_CLI_COMMAND (set_interface_feature_command, static) = {
597 .path = "set interface feature",
Pierre Pfister1bfd3722017-09-18 11:40:32 +0200598 .short_help = "set interface feature <intfc> <feature_name> arc <arc_name> "
599 "[disable]",
Pavel Kotucek7490a752016-11-15 09:19:11 +0100600 .function = set_interface_features_command_fn,
601};
602/* *INDENT-ON* */
603
Damjan Marion22311502016-10-28 20:30:15 +0200604/*
605 * fd.io coding-style-patch-verification: ON
606 *
607 * Local Variables:
608 * eval: (c-set-style "gnu")
609 * End:
610 */