vrrp: fix vrrp_garp_or_na_send()'s memory leak
[vpp.git] / src / plugins / bpf_trace_filter / api.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
18 #include <vlib/vlib.h>
19 #include <bpf_trace_filter/bpf_trace_filter.h>
20 #include <vlibapi/api.h>
21 #include <vlibmemory/api.h>
22
23 /* define message IDs */
24 #include <bpf_trace_filter/bpf_trace_filter.api_enum.h>
25 #include <bpf_trace_filter/bpf_trace_filter.api_types.h>
26
27 #define REPLY_MSG_ID_BASE (bm->msg_id_base)
28 #include <vlibapi/api_helper_macros.h>
29
30 static void
31 vl_api_bpf_trace_filter_set_t_handler (vl_api_bpf_trace_filter_set_t *mp)
32 {
33   bpf_trace_filter_main_t *bm = &bpf_trace_filter_main;
34   vl_api_bpf_trace_filter_set_reply_t *rmp;
35   clib_error_t *err = 0;
36   int rv = 0;
37   u8 is_del = !mp->is_add;
38   char *bpf_expr;
39
40   bpf_expr = vl_api_from_api_to_new_c_string (&mp->filter);
41   err = bpf_trace_filter_set_unset (bpf_expr, is_del, 0);
42
43   if (err)
44     {
45       rv = -1;
46       clib_error_report (err);
47     }
48   vec_free (bpf_expr);
49
50   REPLY_MACRO (VL_API_BPF_TRACE_FILTER_SET_REPLY);
51 }
52
53 static void
54 vl_api_bpf_trace_filter_set_v2_t_handler (vl_api_bpf_trace_filter_set_v2_t *mp)
55 {
56   bpf_trace_filter_main_t *bm = &bpf_trace_filter_main;
57   vl_api_bpf_trace_filter_set_v2_reply_t *rmp;
58   clib_error_t *err = 0;
59   int rv = 0;
60   u8 is_del = !mp->is_add;
61   u8 optimize = !!mp->optimize;
62   char *bpf_expr;
63
64   bpf_expr = vl_api_from_api_to_new_c_string (&mp->filter);
65   err = bpf_trace_filter_set_unset (bpf_expr, is_del, optimize);
66
67   if (err)
68     {
69       rv = -1;
70       clib_error_report (err);
71     }
72   vec_free (bpf_expr);
73
74   REPLY_MACRO (VL_API_BPF_TRACE_FILTER_SET_V2_REPLY);
75 }
76
77 #include <bpf_trace_filter/bpf_trace_filter.api.c>
78
79 static clib_error_t *
80 bpf_trace_filter_plugin_api_hookup (vlib_main_t *vm)
81 {
82   bpf_trace_filter_main_t *bm = &bpf_trace_filter_main;
83
84   /* ask for a correctly-sized block of API message decode slots */
85   bm->msg_id_base = setup_message_id_table ();
86   return 0;
87 }
88
89 VLIB_API_INIT_FUNCTION (bpf_trace_filter_plugin_api_hookup);
90
91 /*
92  * fd.io coding-style-patch-verification: ON
93  *
94  * Local Variables:
95  * eval: (c-set-style "gnu")
96  * End:
97  */