adl: move allow/deny list function to plugin
[vpp.git] / src / vnet / cop / cop_api.c
1 /*
2  *------------------------------------------------------------------
3  * cop_api.c - cop api
4  *
5  * Copyright (c) 2016,2020 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19
20 #include <vnet/vnet.h>
21 #include <vlibmemory/api.h>
22
23 #include <vnet/interface.h>
24 #include <vnet/api_errno.h>
25
26 #include <vnet/vnet_msg_enum.h>
27
28 #define vl_typedefs             /* define message structures */
29 #include <vnet/vnet_all_api_h.h>
30 #undef vl_typedefs
31
32 #define vl_endianfun            /* define message structures */
33 #include <vnet/vnet_all_api_h.h>
34 #undef vl_endianfun
35
36 /* instantiate all the print functions we know about */
37 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
38 #define vl_printfun
39 #include <vnet/vnet_all_api_h.h>
40 #undef vl_printfun
41
42 #include <vlibapi/api_helper_macros.h>
43
44 #define foreach_vpe_api_msg                                     \
45 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable)   \
46 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable)
47
48 typedef struct
49 {
50   u32 sw_if_index;
51   u8 ip4;
52   u8 ip6;
53   u8 default_cop;
54   u32 fib_id;
55 } cop_whitelist_enable_disable_args_t;
56
57 /*
58  * This API will be deprecated in vpp 20.12.
59  *
60  * Continue to support it for the moment if the "adl" plugin
61  * is loaded...
62  */
63 static int default_interface_enable_disable_callback
64   (u32 sw_if_index, int enable_disable)
65 {
66   return VNET_API_ERROR_UNIMPLEMENTED;
67 }
68
69 static int (*interface_enable_disable_callback) (u32, int) =
70   default_interface_enable_disable_callback;
71
72 void
73 register_vl_api_cop_interface_enable_disable_callback (void *cb)
74 {
75   interface_enable_disable_callback = cb;
76 }
77
78 static void vl_api_cop_interface_enable_disable_t_handler
79   (vl_api_cop_interface_enable_disable_t * mp)
80 {
81   vl_api_cop_interface_enable_disable_reply_t *rmp;
82   int rv;
83   u32 sw_if_index = ntohl (mp->sw_if_index);
84   int enable_disable;
85
86   VALIDATE_SW_IF_INDEX (mp);
87
88   enable_disable = (int) mp->enable_disable;
89
90   rv = (*interface_enable_disable_callback) (sw_if_index, enable_disable);
91
92   BAD_SW_IF_INDEX_LABEL;
93
94   REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
95 }
96
97 /*
98  * This API will be deprecated in vpp 20.12.
99  *
100  * Continue to support it for the moment if the "adl" plugin
101  * is loaded...
102  */
103
104 static int default_whitelist_enable_disable_callback
105   (cop_whitelist_enable_disable_args_t * a)
106 {
107   return VNET_API_ERROR_UNIMPLEMENTED;
108 }
109
110 static int (*whitelist_enable_disable_callback)
111   (cop_whitelist_enable_disable_args_t * a) =
112   default_whitelist_enable_disable_callback;
113
114 void
115 register_vl_api_cop_whitelist_enable_disable_callback (void *cb)
116 {
117   whitelist_enable_disable_callback = cb;
118 }
119
120 static void vl_api_cop_whitelist_enable_disable_t_handler
121   (vl_api_cop_whitelist_enable_disable_t * mp)
122 {
123   vl_api_cop_whitelist_enable_disable_reply_t *rmp;
124   cop_whitelist_enable_disable_args_t _a, *a = &_a;
125   u32 sw_if_index = ntohl (mp->sw_if_index);
126   int rv;
127
128   VALIDATE_SW_IF_INDEX (mp);
129
130   a->sw_if_index = sw_if_index;
131   a->ip4 = mp->ip4;
132   a->ip6 = mp->ip6;
133   a->default_cop = mp->default_cop;
134   a->fib_id = ntohl (mp->fib_id);
135
136   rv = (*whitelist_enable_disable_callback) (a);
137
138   BAD_SW_IF_INDEX_LABEL;
139
140   REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
141 }
142
143 /*
144  * cop_api_hookup
145  * Add vpe's API message handlers to the table.
146  * vlib has already mapped shared memory and
147  * added the client registration handlers.
148  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
149  */
150 #define vl_msg_name_crc_list
151 #include <vnet/vnet_all_api_h.h>
152 #undef vl_msg_name_crc_list
153
154 static void
155 setup_message_id_table (api_main_t * am)
156 {
157 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
158   foreach_vl_msg_name_crc_cop;
159 #undef _
160 }
161
162 static clib_error_t *
163 cop_api_hookup (vlib_main_t * vm)
164 {
165   api_main_t *am = vlibapi_get_main ();
166
167 #define _(N,n)                                                  \
168     vl_msg_api_set_handlers(VL_API_##N, #n,                     \
169                            vl_api_##n##_t_handler,              \
170                            vl_noop_handler,                     \
171                            vl_api_##n##_t_endian,               \
172                            vl_api_##n##_t_print,                \
173                            sizeof(vl_api_##n##_t), 1);
174   foreach_vpe_api_msg;
175 #undef _
176
177   /*
178    * Set up the (msg_name, crc, message-id) table
179    */
180   setup_message_id_table (am);
181
182   return 0;
183 }
184
185 VLIB_API_INIT_FUNCTION (cop_api_hookup);
186
187 /*
188  * fd.io coding-style-patch-verification: ON
189  *
190  * Local Variables:
191  * eval: (c-set-style "gnu")
192  * End:
193  */