blob: 2cf79f3875d09f72796437a50b9e42900aee22c0 [file] [log] [blame]
Pavel Kotucekd2c97d92017-01-24 10:58:12 +01001/*
2 *------------------------------------------------------------------
3 * classify_api.c - classify api
4 *
5 * Copyright (c) 2016 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/classify/vnet_classify.h>
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010027#include <vnet/classify/in_out_acl.h>
Pavel Kotucekd2c97d92017-01-24 10:58:12 +010028#include <vnet/classify/policer_classify.h>
29#include <vnet/classify/flow_classify.h>
Neale Rannsb8d44812017-11-10 06:53:54 -080030#include <vnet/l2/l2_classify.h>
Pavel Kotucekd2c97d92017-01-24 10:58:12 +010031
32#include <vnet/vnet_msg_enum.h>
33
34#define vl_typedefs /* define message structures */
35#include <vnet/vnet_all_api_h.h>
36#undef vl_typedefs
37
38#define vl_endianfun /* define message structures */
39#include <vnet/vnet_all_api_h.h>
40#undef vl_endianfun
41
42/* instantiate all the print functions we know about */
43#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
44#define vl_printfun
45#include <vnet/vnet_all_api_h.h>
46#undef vl_printfun
47
48#include <vlibapi/api_helper_macros.h>
49
50#define foreach_vpe_api_msg \
51_(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
52_(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
53_(CLASSIFY_TABLE_IDS,classify_table_ids) \
54_(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
55_(CLASSIFY_TABLE_INFO,classify_table_info) \
56_(CLASSIFY_SESSION_DUMP,classify_session_dump) \
Pavel Kotucekd2c97d92017-01-24 10:58:12 +010057_(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface) \
58_(POLICER_CLASSIFY_DUMP, policer_classify_dump) \
59_(FLOW_CLASSIFY_SET_INTERFACE, flow_classify_set_interface) \
Neale Rannsb8d44812017-11-10 06:53:54 -080060_(FLOW_CLASSIFY_DUMP, flow_classify_dump) \
61_(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
62_(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010063_(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
64_(OUTPUT_ACL_SET_INTERFACE, output_acl_set_interface)
Pavel Kotucekd2c97d92017-01-24 10:58:12 +010065
66#define foreach_classify_add_del_table_field \
67_(table_index) \
68_(nbuckets) \
69_(memory_size) \
70_(skip_n_vectors) \
71_(match_n_vectors) \
72_(next_table_index) \
73_(miss_next_index) \
74_(current_data_flag) \
75_(current_data_offset)
76
77static void vl_api_classify_add_del_table_t_handler
78 (vl_api_classify_add_del_table_t * mp)
79{
80 vl_api_classify_add_del_table_reply_t *rmp;
81 vnet_classify_main_t *cm = &vnet_classify_main;
82 vnet_classify_table_t *t;
83 int rv;
84
85#define _(a) u32 a;
86 foreach_classify_add_del_table_field;
87#undef _
88
89#define _(a) a = ntohl(mp->a);
90 foreach_classify_add_del_table_field;
91#undef _
92
93 /* The underlying API fails silently, on purpose, so check here */
94 if (mp->is_add == 0) /* delete */
95 {
96 if (pool_is_free_index (cm->tables, table_index))
97 {
98 rv = VNET_API_ERROR_NO_SUCH_TABLE;
99 goto out;
100 }
101 }
102 else /* add or update */
103 {
104 if (table_index != ~0 && pool_is_free_index (cm->tables, table_index))
105 table_index = ~0;
106 }
107
108 rv = vnet_classify_add_del_table
109 (cm, mp->mask, nbuckets, memory_size,
110 skip_n_vectors, match_n_vectors,
111 next_table_index, miss_next_index, &table_index,
112 current_data_flag, current_data_offset, mp->is_add, mp->del_chain);
113
114out:
115 /* *INDENT-OFF* */
116 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
117 ({
118 if (rv == 0 && mp->is_add)
119 {
120 t = pool_elt_at_index (cm->tables, table_index);
121 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
122 rmp->match_n_vectors = ntohl(t->match_n_vectors);
123 rmp->new_table_index = ntohl(table_index);
124 }
125 else
126 {
127 rmp->skip_n_vectors = ~0;
128 rmp->match_n_vectors = ~0;
129 rmp->new_table_index = ~0;
130 }
131 }));
132 /* *INDENT-ON* */
133}
134
135static void vl_api_classify_add_del_session_t_handler
136 (vl_api_classify_add_del_session_t * mp)
137{
138 vnet_classify_main_t *cm = &vnet_classify_main;
139 vl_api_classify_add_del_session_reply_t *rmp;
140 int rv;
141 u32 table_index, hit_next_index, opaque_index, metadata;
142 i32 advance;
143 u8 action;
144
145 table_index = ntohl (mp->table_index);
146 hit_next_index = ntohl (mp->hit_next_index);
147 opaque_index = ntohl (mp->opaque_index);
148 advance = ntohl (mp->advance);
149 action = mp->action;
150 metadata = ntohl (mp->metadata);
151
152 rv = vnet_classify_add_del_session
153 (cm, table_index, mp->match, hit_next_index, opaque_index,
154 advance, action, metadata, mp->is_add);
155
156 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
157}
158
159static void
160 vl_api_policer_classify_set_interface_t_handler
161 (vl_api_policer_classify_set_interface_t * mp)
162{
163 vlib_main_t *vm = vlib_get_main ();
164 vl_api_policer_classify_set_interface_reply_t *rmp;
165 int rv;
166 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
167
168 ip4_table_index = ntohl (mp->ip4_table_index);
169 ip6_table_index = ntohl (mp->ip6_table_index);
170 l2_table_index = ntohl (mp->l2_table_index);
171 sw_if_index = ntohl (mp->sw_if_index);
172
173 VALIDATE_SW_IF_INDEX (mp);
174
175 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
176 ip6_table_index, l2_table_index,
177 mp->is_add);
178
179 BAD_SW_IF_INDEX_LABEL;
180
181 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
182}
183
184static void
185send_policer_classify_details (u32 sw_if_index,
Florin Coras6c4dae22018-01-09 06:39:23 -0800186 u32 table_index, vl_api_registration_t * reg,
187 u32 context)
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100188{
189 vl_api_policer_classify_details_t *mp;
190
191 mp = vl_msg_api_alloc (sizeof (*mp));
192 memset (mp, 0, sizeof (*mp));
193 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
194 mp->context = context;
195 mp->sw_if_index = htonl (sw_if_index);
196 mp->table_index = htonl (table_index);
197
Florin Coras6c4dae22018-01-09 06:39:23 -0800198 vl_api_send_msg (reg, (u8 *) mp);
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100199}
200
201static void
202vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
203{
Florin Coras6c4dae22018-01-09 06:39:23 -0800204 vl_api_registration_t *reg;
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100205 policer_classify_main_t *pcm = &policer_classify_main;
206 u32 *vec_tbl;
207 int i;
208
Florin Coras6c4dae22018-01-09 06:39:23 -0800209 reg = vl_api_client_index_to_registration (mp->client_index);
210 if (!reg)
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100211 return;
212
213 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
214
215 if (vec_len (vec_tbl))
216 {
217 for (i = 0; i < vec_len (vec_tbl); i++)
218 {
219 if (vec_elt (vec_tbl, i) == ~0)
220 continue;
221
Florin Coras6c4dae22018-01-09 06:39:23 -0800222 send_policer_classify_details (i, vec_elt (vec_tbl, i), reg,
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100223 mp->context);
224 }
225 }
226}
227
228static void
229vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
230{
Florin Coras6c4dae22018-01-09 06:39:23 -0800231 vl_api_registration_t *reg;
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100232
Florin Coras6c4dae22018-01-09 06:39:23 -0800233 reg = vl_api_client_index_to_registration (mp->client_index);
234 if (!reg)
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100235 return;
236
237 vnet_classify_main_t *cm = &vnet_classify_main;
238 vnet_classify_table_t *t;
239 u32 *table_ids = 0;
240 u32 count;
241
242 /* *INDENT-OFF* */
243 pool_foreach (t, cm->tables,
244 ({
245 vec_add1 (table_ids, ntohl(t - cm->tables));
246 }));
247 /* *INDENT-ON* */
248 count = vec_len (table_ids);
249
250 vl_api_classify_table_ids_reply_t *rmp;
251 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
252 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
253 rmp->context = mp->context;
254 rmp->count = ntohl (count);
255 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
256 rmp->retval = 0;
257
Florin Coras6c4dae22018-01-09 06:39:23 -0800258 vl_api_send_msg (reg, (u8 *) rmp);
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100259
260 vec_free (table_ids);
261}
262
263static void
264 vl_api_classify_table_by_interface_t_handler
265 (vl_api_classify_table_by_interface_t * mp)
266{
267 vl_api_classify_table_by_interface_reply_t *rmp;
268 int rv = 0;
269
270 u32 sw_if_index = ntohl (mp->sw_if_index);
271 u32 *acl = 0;
272
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100273 vec_validate (acl, IN_OUT_ACL_N_TABLES - 1);
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100274 vec_set (acl, ~0);
275
276 VALIDATE_SW_IF_INDEX (mp);
277
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100278 in_out_acl_main_t *am = &in_out_acl_main;
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100279
280 int if_idx;
281 u32 type;
282
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100283 for (type = 0; type < IN_OUT_ACL_N_TABLES; type++)
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100284 {
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100285 u32 *vec_tbl =
286 am->classify_table_index_by_sw_if_index[IN_OUT_ACL_INPUT_TABLE_GROUP]
287 [type];
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100288 if (vec_len (vec_tbl))
289 {
290 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
291 {
292 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
293 {
294 continue;
295 }
296 acl[type] = vec_elt (vec_tbl, if_idx);
297 }
298 }
299 }
300
301 BAD_SW_IF_INDEX_LABEL;
302
303 /* *INDENT-OFF* */
304 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
305 ({
306 rmp->sw_if_index = ntohl(sw_if_index);
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100307 rmp->l2_table_id = ntohl(acl[IN_OUT_ACL_TABLE_L2]);
308 rmp->ip4_table_id = ntohl(acl[IN_OUT_ACL_TABLE_IP4]);
309 rmp->ip6_table_id = ntohl(acl[IN_OUT_ACL_TABLE_IP6]);
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100310 }));
311 /* *INDENT-ON* */
312 vec_free (acl);
313}
314
315static void
316vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
317{
Florin Coras6c4dae22018-01-09 06:39:23 -0800318 vl_api_registration_t *reg;
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100319
Florin Coras6c4dae22018-01-09 06:39:23 -0800320 reg = vl_api_client_index_to_registration (mp->client_index);
321 if (!reg)
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100322 return;
323
324 vl_api_classify_table_info_reply_t *rmp = 0;
325
326 vnet_classify_main_t *cm = &vnet_classify_main;
327 u32 table_id = ntohl (mp->table_id);
328 vnet_classify_table_t *t;
329
330 /* *INDENT-OFF* */
331 pool_foreach (t, cm->tables,
332 ({
333 if (table_id == t - cm->tables)
334 {
335 rmp = vl_msg_api_alloc_as_if_client
336 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
337 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
338 rmp->context = mp->context;
339 rmp->table_id = ntohl(table_id);
340 rmp->nbuckets = ntohl(t->nbuckets);
341 rmp->match_n_vectors = ntohl(t->match_n_vectors);
342 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
343 rmp->active_sessions = ntohl(t->active_elements);
344 rmp->next_table_index = ntohl(t->next_table_index);
345 rmp->miss_next_index = ntohl(t->miss_next_index);
346 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
347 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
348 rmp->retval = 0;
349 break;
350 }
351 }));
352 /* *INDENT-ON* */
353
354 if (rmp == 0)
355 {
356 rmp = vl_msg_api_alloc (sizeof (*rmp));
357 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
358 rmp->context = mp->context;
359 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
360 }
361
Florin Coras6c4dae22018-01-09 06:39:23 -0800362 vl_api_send_msg (reg, (u8 *) rmp);
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100363}
364
365static void
Florin Coras6c4dae22018-01-09 06:39:23 -0800366send_classify_session_details (vl_api_registration_t * reg,
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100367 u32 table_id,
368 u32 match_length,
369 vnet_classify_entry_t * e, u32 context)
370{
371 vl_api_classify_session_details_t *rmp;
372
373 rmp = vl_msg_api_alloc (sizeof (*rmp));
374 memset (rmp, 0, sizeof (*rmp));
375 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
376 rmp->context = context;
377 rmp->table_id = ntohl (table_id);
378 rmp->hit_next_index = ntohl (e->next_index);
379 rmp->advance = ntohl (e->advance);
380 rmp->opaque_index = ntohl (e->opaque_index);
381 rmp->match_length = ntohl (match_length);
382 clib_memcpy (rmp->match, e->key, match_length);
383
Florin Coras6c4dae22018-01-09 06:39:23 -0800384 vl_api_send_msg (reg, (u8 *) rmp);
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100385}
386
387static void
388vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
389{
390 vnet_classify_main_t *cm = &vnet_classify_main;
Florin Coras6c4dae22018-01-09 06:39:23 -0800391 vl_api_registration_t *reg;
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100392
393 u32 table_id = ntohl (mp->table_id);
394 vnet_classify_table_t *t;
395
Florin Coras6c4dae22018-01-09 06:39:23 -0800396 reg = vl_api_client_index_to_registration (mp->client_index);
397 if (!reg)
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100398 return;
399
400 /* *INDENT-OFF* */
401 pool_foreach (t, cm->tables,
402 ({
403 if (table_id == t - cm->tables)
404 {
405 vnet_classify_bucket_t * b;
406 vnet_classify_entry_t * v, * save_v;
407 int i, j, k;
408
409 for (i = 0; i < t->nbuckets; i++)
410 {
411 b = &t->buckets [i];
412 if (b->offset == 0)
413 continue;
414
415 save_v = vnet_classify_get_entry (t, b->offset);
416 for (j = 0; j < (1<<b->log2_pages); j++)
417 {
418 for (k = 0; k < t->entries_per_page; k++)
419 {
420 v = vnet_classify_entry_at_index
421 (t, save_v, j*t->entries_per_page + k);
422 if (vnet_classify_entry_is_free (v))
423 continue;
424
425 send_classify_session_details
Florin Coras6c4dae22018-01-09 06:39:23 -0800426 (reg, table_id, t->match_n_vectors * sizeof (u32x4),
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100427 v, mp->context);
428 }
429 }
430 }
431 break;
432 }
433 }));
434 /* *INDENT-ON* */
435}
436
437static void
438 vl_api_flow_classify_set_interface_t_handler
439 (vl_api_flow_classify_set_interface_t * mp)
440{
441 vlib_main_t *vm = vlib_get_main ();
442 vl_api_flow_classify_set_interface_reply_t *rmp;
443 int rv;
444 u32 sw_if_index, ip4_table_index, ip6_table_index;
445
446 ip4_table_index = ntohl (mp->ip4_table_index);
447 ip6_table_index = ntohl (mp->ip6_table_index);
448 sw_if_index = ntohl (mp->sw_if_index);
449
450 VALIDATE_SW_IF_INDEX (mp);
451
452 rv = vnet_set_flow_classify_intfc (vm, sw_if_index, ip4_table_index,
453 ip6_table_index, mp->is_add);
454
455 BAD_SW_IF_INDEX_LABEL;
456
457 REPLY_MACRO (VL_API_FLOW_CLASSIFY_SET_INTERFACE_REPLY);
458}
459
460static void
461send_flow_classify_details (u32 sw_if_index,
Florin Coras6c4dae22018-01-09 06:39:23 -0800462 u32 table_index, vl_api_registration_t * reg,
463 u32 context)
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100464{
465 vl_api_flow_classify_details_t *mp;
466
467 mp = vl_msg_api_alloc (sizeof (*mp));
468 memset (mp, 0, sizeof (*mp));
469 mp->_vl_msg_id = ntohs (VL_API_FLOW_CLASSIFY_DETAILS);
470 mp->context = context;
471 mp->sw_if_index = htonl (sw_if_index);
472 mp->table_index = htonl (table_index);
473
Florin Coras6c4dae22018-01-09 06:39:23 -0800474 vl_api_send_msg (reg, (u8 *) mp);
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100475}
476
477static void
478vl_api_flow_classify_dump_t_handler (vl_api_flow_classify_dump_t * mp)
479{
Florin Coras6c4dae22018-01-09 06:39:23 -0800480 vl_api_registration_t *reg;
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100481 flow_classify_main_t *pcm = &flow_classify_main;
482 u32 *vec_tbl;
483 int i;
484
Florin Coras6c4dae22018-01-09 06:39:23 -0800485 reg = vl_api_client_index_to_registration (mp->client_index);
486 if (!reg)
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100487 return;
488
489 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
490
491 if (vec_len (vec_tbl))
492 {
493 for (i = 0; i < vec_len (vec_tbl); i++)
494 {
495 if (vec_elt (vec_tbl, i) == ~0)
496 continue;
497
Florin Coras6c4dae22018-01-09 06:39:23 -0800498 send_flow_classify_details (i, vec_elt (vec_tbl, i), reg,
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100499 mp->context);
500 }
501 }
502}
503
Neale Rannsb8d44812017-11-10 06:53:54 -0800504static void vl_api_classify_set_interface_ip_table_t_handler
505 (vl_api_classify_set_interface_ip_table_t * mp)
506{
507 vlib_main_t *vm = vlib_get_main ();
508 vl_api_classify_set_interface_ip_table_reply_t *rmp;
509 int rv;
510
511 VALIDATE_SW_IF_INDEX (mp);
512
513 u32 table_index = ntohl (mp->table_index);
514 u32 sw_if_index = ntohl (mp->sw_if_index);
515
516 if (mp->is_ipv6)
517 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
518 else
519 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
520
521 BAD_SW_IF_INDEX_LABEL;
522
523 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
524}
525
526static void vl_api_classify_set_interface_l2_tables_t_handler
527 (vl_api_classify_set_interface_l2_tables_t * mp)
528{
529 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
530 int rv;
531 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
532 int enable;
533
534 ip4_table_index = ntohl (mp->ip4_table_index);
535 ip6_table_index = ntohl (mp->ip6_table_index);
536 other_table_index = ntohl (mp->other_table_index);
537 sw_if_index = ntohl (mp->sw_if_index);
538
539 VALIDATE_SW_IF_INDEX (mp);
540
541 if (mp->is_input)
542 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
543 ip6_table_index,
544 other_table_index);
545 else
546 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
547 ip6_table_index,
548 other_table_index);
549
550 if (rv == 0)
551 {
552 if (ip4_table_index != ~0 || ip6_table_index != ~0
553 || other_table_index != ~0)
554 enable = 1;
555 else
556 enable = 0;
557
558 if (mp->is_input)
559 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
560 else
561 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
562 }
563
564 BAD_SW_IF_INDEX_LABEL;
565
566 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
567}
568
569static void vl_api_input_acl_set_interface_t_handler
570 (vl_api_input_acl_set_interface_t * mp)
571{
572 vlib_main_t *vm = vlib_get_main ();
573 vl_api_input_acl_set_interface_reply_t *rmp;
574 int rv;
575
576 VALIDATE_SW_IF_INDEX (mp);
577
578 u32 ip4_table_index = ntohl (mp->ip4_table_index);
579 u32 ip6_table_index = ntohl (mp->ip6_table_index);
580 u32 l2_table_index = ntohl (mp->l2_table_index);
581 u32 sw_if_index = ntohl (mp->sw_if_index);
582
583 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
584 ip6_table_index, l2_table_index, mp->is_add);
585
586 BAD_SW_IF_INDEX_LABEL;
587
588 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
589}
590
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100591static void vl_api_output_acl_set_interface_t_handler
592 (vl_api_output_acl_set_interface_t * mp)
593{
594 vlib_main_t *vm = vlib_get_main ();
595 vl_api_output_acl_set_interface_reply_t *rmp;
596 int rv;
597
598 VALIDATE_SW_IF_INDEX (mp);
599
600 u32 ip4_table_index = ntohl (mp->ip4_table_index);
601 u32 ip6_table_index = ntohl (mp->ip6_table_index);
602 u32 l2_table_index = ntohl (mp->l2_table_index);
603 u32 sw_if_index = ntohl (mp->sw_if_index);
604
605 rv = vnet_set_output_acl_intfc (vm, sw_if_index, ip4_table_index,
606 ip6_table_index, l2_table_index,
607 mp->is_add);
608
609 BAD_SW_IF_INDEX_LABEL;
610
611 REPLY_MACRO (VL_API_OUTPUT_ACL_SET_INTERFACE_REPLY);
612}
613
Pavel Kotucekd2c97d92017-01-24 10:58:12 +0100614/*
615 * classify_api_hookup
616 * Add vpe's API message handlers to the table.
617 * vlib has alread mapped shared memory and
618 * added the client registration handlers.
619 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
620 */
621#define vl_msg_name_crc_list
622#include <vnet/vnet_all_api_h.h>
623#undef vl_msg_name_crc_list
624
625static void
626setup_message_id_table (api_main_t * am)
627{
628#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
629 foreach_vl_msg_name_crc_classify;
630#undef _
631}
632
633static clib_error_t *
634classify_api_hookup (vlib_main_t * vm)
635{
636 api_main_t *am = &api_main;
637
638#define _(N,n) \
639 vl_msg_api_set_handlers(VL_API_##N, #n, \
640 vl_api_##n##_t_handler, \
641 vl_noop_handler, \
642 vl_api_##n##_t_endian, \
643 vl_api_##n##_t_print, \
644 sizeof(vl_api_##n##_t), 1);
645 foreach_vpe_api_msg;
646#undef _
647
648 /*
649 * Set up the (msg_name, crc, message-id) table
650 */
651 setup_message_id_table (am);
652
653 return 0;
654}
655
656VLIB_API_INIT_FUNCTION (classify_api_hookup);
657
658/*
659 * fd.io coding-style-patch-verification: ON
660 *
661 * Local Variables:
662 * eval: (c-set-style "gnu")
663 * End:
664 */