bpf_trace_filter: plugin for BPF Trace Filtering
[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 #include <pcap.h>
25
26 static clib_error_t *
27 set_bpf_trace_filter_command_fn (vlib_main_t *vm, unformat_input_t *input,
28                                  vlib_cli_command_t *cmd)
29 {
30   unformat_input_t _line_input, *line_input = &_line_input;
31   u8 *bpf_expr = 0;
32   u8 is_del = 0;
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, "%s", &bpf_expr))
44         ;
45       else
46         return clib_error_return (0, "unknown input `%U'",
47                                   format_unformat_error, input);
48     }
49
50   err = bpf_trace_filter_set_unset ((char *) bpf_expr, is_del);
51   unformat_free (line_input);
52
53   return err;
54 }
55
56 VLIB_CLI_COMMAND (set_bpf_trace_filter, static) = {
57   .path = "set bpf trace filter",
58   .short_help = "set bpf trace filter {<pcap string>}",
59   .function = set_bpf_trace_filter_command_fn,
60 };
61
62 /*
63  * fd.io coding-style-patch-verification: ON
64  *
65  * Local Variables:
66  * eval: (c-set-style "gnu")
67  * End:
68  */