tracenode: filtering feature
[vpp.git] / src / plugins / tracenode / cli.c
1 /*
2  * Copyright (c) 2023 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 <vlib/vlib.h>
17 #include <tracenode/tracenode.h>
18
19 static clib_error_t *
20 tracenode_feature_cmd_fn (vlib_main_t *vm, unformat_input_t *input,
21                           vlib_cli_command_t *cmd)
22 {
23   unformat_input_t _line_input, *line_input = &_line_input;
24   u32 sw_if_index = ~0;
25   int enable = 1, is_pcap = 0;
26   int rv;
27
28   /* Get a line of input. */
29   if (!unformat_user (input, unformat_line_input, line_input))
30     return 0;
31
32   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
33     {
34       if (unformat (line_input, "disable"))
35         enable = 0;
36       else if (unformat (line_input, "pcap"))
37         is_pcap = 1;
38       else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
39                          vnet_get_main (), &sw_if_index))
40         {
41           if (sw_if_index == 0)
42             return clib_error_return (0, "Local interface not supported...");
43         }
44
45       else
46         break;
47     }
48
49   if (sw_if_index == ~0)
50     return clib_error_return (0, "Software interface required");
51
52   if ((rv = tracenode_feature_enable_disable (sw_if_index, is_pcap, enable)) !=
53       0)
54     return clib_error_return (
55       0, "vnet_enable_disable_tracenode_feature returned %d", rv);
56
57   return 0;
58 }
59
60 VLIB_CLI_COMMAND (tracenode_feature, static) = {
61   .path = "tracenode feature",
62   .short_help = "tracenode feature <intfc> [disable] [pcap]",
63   .function = tracenode_feature_cmd_fn,
64 };
65
66 /*
67  * fd.io coding-style-patch-verification: ON
68  *
69  * Local Variables:
70  * eval: (c-set-style "gnu")
71  * End:
72  */