FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
cop_api.c
Go to the documentation of this file.
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 
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 {
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  */
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) =
71 
72 void
73 register_vl_api_cop_interface_enable_disable_callback (void *cb)
74 {
76 }
77 
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 
87 
88  enable_disable = (int) mp->enable_disable;
89 
90  rv = (*interface_enable_disable_callback) (sw_if_index, enable_disable);
91 
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 
106 {
107  return VNET_API_ERROR_UNIMPLEMENTED;
108 }
109 
113 
114 void
116 {
118 }
119 
122 {
123  vl_api_cop_whitelist_enable_disable_reply_t *rmp;
125  u32 sw_if_index = ntohl (mp->sw_if_index);
126  int rv;
127 
129 
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 
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
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 *
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);
175 #undef _
176 
177  /*
178  * Set up the (msg_name, crc, message-id) table
179  */
181 
182  return 0;
183 }
184 
186 
187 /*
188  * fd.io coding-style-patch-verification: ON
189  *
190  * Local Variables:
191  * eval: (c-set-style "gnu")
192  * End:
193  */
VLIB_API_INIT_FUNCTION(cop_api_hookup)
cop: enable/disable whitelist filtration features on an interface Note: the supplied fib_id must matc...
Definition: cop.api:48
static void vl_api_cop_whitelist_enable_disable_t_handler(vl_api_cop_whitelist_enable_disable_t *mp)
Definition: cop_api.c:121
a
Definition: bitmap.h:538
static clib_error_t * cop_api_hookup(vlib_main_t *vm)
Definition: cop_api.c:163
vlib_main_t * vm
Definition: in2out_ed.c:1582
unsigned char u8
Definition: types.h:56
vl_api_interface_index_t sw_if_index
Definition: cop.api:32
unsigned int u32
Definition: types.h:88
void register_vl_api_cop_whitelist_enable_disable_callback(void *cb)
Definition: cop_api.c:115
#define REPLY_MACRO(t)
static void setup_message_id_table(api_main_t *am)
Definition: cop_api.c:155
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:227
#define BAD_SW_IF_INDEX_LABEL
cop: enable/disable junk filtration features on an interface
Definition: cop.api:27
static void vl_api_cop_interface_enable_disable_t_handler(vl_api_cop_interface_enable_disable_t *mp)
Definition: cop_api.c:79
static int default_interface_enable_disable_callback(u32 sw_if_index, int enable_disable)
Definition: cop_api.c:64
static int(* interface_enable_disable_callback)(u32, int)
Definition: cop_api.c:69
#define foreach_vpe_api_msg
Definition: cop_api.c:44
static int(* whitelist_enable_disable_callback)(cop_whitelist_enable_disable_args_t *a)=default_whitelist_enable_disable_callback
Definition: cop_api.c:111
static int default_whitelist_enable_disable_callback(cop_whitelist_enable_disable_args_t *a)
Definition: cop_api.c:105
static api_main_t * vlibapi_get_main(void)
Definition: api_common.h:389
vl_api_interface_index_t sw_if_index
Definition: cop.api:53
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:33
#define VALIDATE_SW_IF_INDEX(mp)