vlib: clean up r2 plugin registration relocator
[vpp.git] / src / plugins / bpf_trace_filter / cli.c
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2023 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17 #include <stdint.h>
18 #include <net/if.h>
19 #include <sys/ioctl.h>
20 #include <inttypes.h>
21
22 #include <vlib/vlib.h>
23 #include <bpf_trace_filter/bpf_trace_filter.h>
24
25 static clib_error_t *
26 set_bpf_trace_filter_command_fn (vlib_main_t *vm, unformat_input_t *input,
27                                  vlib_cli_command_t *cmd)
28 {
29   unformat_input_t _line_input, *line_input = &_line_input;
30   u8 *bpf_expr = 0;
31   u8 is_del = 0;
32   u8 optimize = 1;
33   clib_error_t *err = 0;
34
35   /* Get a line of input. */
36   if (!unformat_user (input, unformat_line_input, line_input))
37     return 0;
38
39   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
40     {
41       if (unformat (line_input, "del"))
42         is_del = 1;
43       else if (unformat (line_input, "no-optimize"))
44         optimize = 0;
45       else if (unformat (line_input, "%s", &bpf_expr))
46         ;
47       else
48         {
49           err = clib_error_return (0, "unknown input `%U'",
50                                    format_unformat_error, input);
51           break;
52         }
53     }
54   unformat_free (line_input);
55
56   if (err != 0)
57     return err;
58
59   err = bpf_trace_filter_set_unset ((char *) bpf_expr, is_del, optimize);
60
61   return err;
62 }
63
64 VLIB_CLI_COMMAND (set_bpf_trace_filter, static) = {
65   .path = "set bpf trace filter",
66   .short_help = "set bpf trace filter [del] [no-optimize] {<pcap string>}",
67   .function = set_bpf_trace_filter_command_fn,
68 };
69
70 static clib_error_t *
71 show_bpf_trace_filter_command_fn (vlib_main_t *vm, unformat_input_t *input,
72                                   vlib_cli_command_t *cmd)
73 {
74   bpf_trace_filter_main_t *btm = &bpf_trace_filter_main;
75
76   if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
77     {
78       return (clib_error_return (0, "unknown input '%U'",
79                                  format_unformat_error, input));
80     }
81
82   vlib_cli_output (vm, "%U", format_bpf_trace_filter, btm);
83
84   return 0;
85 }
86
87 VLIB_CLI_COMMAND (show_bpf_trace_filter, static) = {
88   .path = "show bpf trace filter",
89   .short_help = "show bpf trace filter",
90   .function = show_bpf_trace_filter_command_fn,
91 };
92
93 /*
94  * fd.io coding-style-patch-verification: ON
95  *
96  * Local Variables:
97  * eval: (c-set-style "gnu")
98  * End:
99  */