blob: 6ebcebcbf86a7d561dc42ab63e8c69c2f09f01a1 [file] [log] [blame]
Pavel Kotucek884cf262017-01-25 08:27:15 +01001/*
2 *------------------------------------------------------------------
3 * cop_api.c - cop api
4 *
Dave Barachac0326f2020-07-14 18:30:05 -04005 * Copyright (c) 2016,2020 Cisco and/or its affiliates.
Pavel Kotucek884cf262017-01-25 08:27:15 +01006 * 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>
Pavel Kotucek884cf262017-01-25 08:27:15 +010025
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
Dave Barachac0326f2020-07-14 18:30:05 -040048typedef 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 */
63static int default_interface_enable_disable_callback
64 (u32 sw_if_index, int enable_disable)
65{
66 return VNET_API_ERROR_UNIMPLEMENTED;
67}
68
69static int (*interface_enable_disable_callback) (u32, int) =
70 default_interface_enable_disable_callback;
71
72void
73register_vl_api_cop_interface_enable_disable_callback (void *cb)
74{
75 interface_enable_disable_callback = cb;
76}
77
Pavel Kotucek884cf262017-01-25 08:27:15 +010078static 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
Dave Barachac0326f2020-07-14 18:30:05 -040090 rv = (*interface_enable_disable_callback) (sw_if_index, enable_disable);
Pavel Kotucek884cf262017-01-25 08:27:15 +010091
92 BAD_SW_IF_INDEX_LABEL;
93
94 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
95}
96
Dave Barachac0326f2020-07-14 18:30:05 -040097/*
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
104static int default_whitelist_enable_disable_callback
105 (cop_whitelist_enable_disable_args_t * a)
106{
107 return VNET_API_ERROR_UNIMPLEMENTED;
108}
109
110static int (*whitelist_enable_disable_callback)
111 (cop_whitelist_enable_disable_args_t * a) =
112 default_whitelist_enable_disable_callback;
113
114void
115register_vl_api_cop_whitelist_enable_disable_callback (void *cb)
116{
117 whitelist_enable_disable_callback = cb;
118}
119
Pavel Kotucek884cf262017-01-25 08:27:15 +0100120static 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
Dave Barachac0326f2020-07-14 18:30:05 -0400136 rv = (*whitelist_enable_disable_callback) (a);
Pavel Kotucek884cf262017-01-25 08:27:15 +0100137
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.
Jim Thompsonf324dec2019-04-08 03:22:21 -0500146 * vlib has already mapped shared memory and
Pavel Kotucek884cf262017-01-25 08:27:15 +0100147 * 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
154static void
155setup_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
162static clib_error_t *
163cop_api_hookup (vlib_main_t * vm)
164{
Dave Barach39d69112019-11-27 11:42:13 -0500165 api_main_t *am = vlibapi_get_main ();
Pavel Kotucek884cf262017-01-25 08:27:15 +0100166
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
185VLIB_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 */