2 *------------------------------------------------------------------
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:
10 * http://www.apache.org/licenses/LICENSE-2.0
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 *------------------------------------------------------------------
20 #include <vnet/vnet.h>
21 #include <vlibmemory/api.h>
23 #include <vnet/interface.h>
24 #include <vnet/api_errno.h>
26 #include <vnet/vnet_msg_enum.h>
28 #define vl_typedefs /* define message structures */
29 #include <vnet/vnet_all_api_h.h>
32 #define vl_endianfun /* define message structures */
33 #include <vnet/vnet_all_api_h.h>
36 /* instantiate all the print functions we know about */
37 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
39 #include <vnet/vnet_all_api_h.h>
42 #include <vlibapi/api_helper_macros.h>
44 #define foreach_vpe_api_msg \
45 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
46 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable)
55 } cop_whitelist_enable_disable_args_t;
58 * This API will be deprecated in vpp 20.12.
60 * Continue to support it for the moment if the "adl" plugin
63 static int default_interface_enable_disable_callback
64 (u32 sw_if_index, int enable_disable)
66 return VNET_API_ERROR_UNIMPLEMENTED;
69 static int (*interface_enable_disable_callback) (u32, int) =
70 default_interface_enable_disable_callback;
73 register_vl_api_cop_interface_enable_disable_callback (void *cb)
75 interface_enable_disable_callback = cb;
78 static void vl_api_cop_interface_enable_disable_t_handler
79 (vl_api_cop_interface_enable_disable_t * mp)
81 vl_api_cop_interface_enable_disable_reply_t *rmp;
83 u32 sw_if_index = ntohl (mp->sw_if_index);
86 VALIDATE_SW_IF_INDEX (mp);
88 enable_disable = (int) mp->enable_disable;
90 rv = (*interface_enable_disable_callback) (sw_if_index, enable_disable);
92 BAD_SW_IF_INDEX_LABEL;
94 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
98 * This API will be deprecated in vpp 20.12.
100 * Continue to support it for the moment if the "adl" plugin
104 static int default_whitelist_enable_disable_callback
105 (cop_whitelist_enable_disable_args_t * a)
107 return VNET_API_ERROR_UNIMPLEMENTED;
110 static int (*whitelist_enable_disable_callback)
111 (cop_whitelist_enable_disable_args_t * a) =
112 default_whitelist_enable_disable_callback;
115 register_vl_api_cop_whitelist_enable_disable_callback (void *cb)
117 whitelist_enable_disable_callback = cb;
120 static void vl_api_cop_whitelist_enable_disable_t_handler
121 (vl_api_cop_whitelist_enable_disable_t * mp)
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);
128 VALIDATE_SW_IF_INDEX (mp);
130 a->sw_if_index = sw_if_index;
133 a->default_cop = mp->default_cop;
134 a->fib_id = ntohl (mp->fib_id);
136 rv = (*whitelist_enable_disable_callback) (a);
138 BAD_SW_IF_INDEX_LABEL;
140 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
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()
150 #define vl_msg_name_crc_list
151 #include <vnet/vnet_all_api_h.h>
152 #undef vl_msg_name_crc_list
155 setup_message_id_table (api_main_t * am)
157 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
158 foreach_vl_msg_name_crc_cop;
162 static clib_error_t *
163 cop_api_hookup (vlib_main_t * vm)
165 api_main_t *am = vlibapi_get_main ();
168 vl_msg_api_set_handlers(VL_API_##N, #n, \
169 vl_api_##n##_t_handler, \
171 vl_api_##n##_t_endian, \
172 vl_api_##n##_t_print, \
173 sizeof(vl_api_##n##_t), 1);
178 * Set up the (msg_name, crc, message-id) table
180 setup_message_id_table (am);
185 VLIB_API_INIT_FUNCTION (cop_api_hookup);
188 * fd.io coding-style-patch-verification: ON
191 * eval: (c-set-style "gnu")