tracenode: filtering feature
[vpp.git] / src / plugins / tracenode / tracenode.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 #include <vlib/vlib.h>
16 #include <tracenode/tracenode.h>
17
18 tracenode_main_t tracenode_main;
19
20 int
21 tracenode_feature_enable_disable (u32 sw_if_index, bool is_pcap, bool enable)
22 {
23   tracenode_main_t *tnm = &tracenode_main;
24   char *node_name = is_pcap ? "pcap-filtering" : "trace-filtering";
25   int rv = 0;
26
27   if (pool_is_free_index (tnm->vnet_main->interface_main.sw_interfaces,
28                           sw_if_index))
29     return VNET_API_ERROR_INVALID_SW_IF_INDEX;
30
31   if (clib_bitmap_get (tnm->feature_enabled_by_sw_if, sw_if_index) == enable)
32     return 0;
33
34   if ((rv = vnet_feature_enable_disable ("ip4-unicast", node_name, sw_if_index,
35                                          enable, 0, 0)) != 0)
36     return rv;
37
38   if ((rv = vnet_feature_enable_disable ("ip6-unicast", node_name, sw_if_index,
39                                          enable, 0, 0)) != 0)
40     return rv;
41
42   tnm->feature_enabled_by_sw_if =
43     clib_bitmap_set (tnm->feature_enabled_by_sw_if, sw_if_index, enable);
44
45   return 0;
46 }
47
48 static clib_error_t *
49 tracenode_init (vlib_main_t *vm)
50 {
51   tracenode_main_t *tnm = &tracenode_main;
52   clib_error_t *error = 0;
53
54   memset (tnm, 0, sizeof (*tnm));
55
56   tnm->vnet_main = vnet_get_main ();
57
58   error = tracenode_plugin_api_hookup (vm);
59
60   return error;
61 }
62
63 VLIB_INIT_FUNCTION (tracenode_init);
64
65 /*
66  * fd.io coding-style-patch-verification: ON
67  *
68  * Local Variables:
69  * eval: (c-set-style "gnu")
70  * End:
71  */