2 *------------------------------------------------------------------
3 * classify_api.c - classify api
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:
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/classify/vnet_classify.h>
27 #include <vnet/classify/in_out_acl.h>
28 #include <vnet/classify/policer_classify.h>
29 #include <vnet/classify/flow_classify.h>
30 #include <vnet/l2/l2_classify.h>
31 #include <vnet/ip/ip6.h>
32 #include <vnet/ip/ip4.h>
34 #include <classify/classify.api_enum.h>
35 #include <classify/classify.api_types.h>
37 #define REPLY_MSG_ID_BASE msg_id_base
38 #include <vlibapi/api_helper_macros.h>
40 static u16 msg_id_base;
42 #define foreach_classify_add_del_table_field \
53 static void vl_api_classify_pcap_lookup_table_t_handler
54 (vl_api_classify_pcap_lookup_table_t * mp)
56 vnet_classify_main_t *cm = &vnet_classify_main;
57 vl_api_registration_t *reg;
58 vl_api_classify_pcap_lookup_table_reply_t *rmp;
62 reg = vl_api_client_index_to_registration (mp->client_index);
66 u32 n_skip = ntohl (mp->skip_n_vectors);
67 u32 n_match = ntohl (mp->match_n_vectors);
68 u32 mask_len = ntohl (mp->mask_len);
69 u32 sw_if_index = ntohl (mp->sw_if_index);
71 if (n_skip > 5 || n_match == 0 || n_match > 5 ||
72 mask_len != n_match * sizeof (u32x4) || sw_if_index == ~0 ||
73 sw_if_index >= vec_len (cm->classify_table_index_by_sw_if_index))
75 rv = VNET_API_ERROR_INVALID_VALUE;
80 table_chain = classify_get_pcap_chain (cm, sw_if_index);
83 vec_validate (mask_vec, mask_len - 1);
84 clib_memcpy (mask_vec, mp->mask, mask_len);
86 if (table_chain != ~0)
87 table_index = classify_lookup_chain (table_chain,
88 mask_vec, n_skip, n_match);
93 rmp = vl_msg_api_alloc (sizeof (*rmp));
95 ntohs (REPLY_MSG_ID_BASE + VL_API_CLASSIFY_PCAP_LOOKUP_TABLE_REPLY);
96 rmp->context = mp->context;
97 rmp->retval = ntohl (rv);
98 rmp->table_index = htonl (table_index);
100 vl_api_send_msg (reg, (u8 *) rmp);
103 static void vl_api_classify_pcap_set_table_t_handler
104 (vl_api_classify_pcap_set_table_t * mp)
106 vnet_classify_main_t *cm = &vnet_classify_main;
107 vl_api_classify_pcap_set_table_reply_t *rmp;
108 vl_api_registration_t *reg;
111 reg = vl_api_client_index_to_registration (mp->client_index);
115 u32 table_index = ntohl (mp->table_index);
116 u32 sw_if_index = ntohl (mp->sw_if_index);
118 if (sw_if_index == ~0 ||
119 (table_index != ~0 && pool_is_free_index (cm->tables, table_index)))
121 rv = VNET_API_ERROR_INVALID_VALUE;
126 * Maybe reorder tables such that masks are most-specify to least-specific.
128 if (table_index != ~0 && mp->sort_masks)
129 table_index = classify_sort_table_chain (cm, table_index);
131 classify_set_pcap_chain (cm, sw_if_index, table_index);
134 rmp = vl_msg_api_alloc (sizeof (*rmp));
136 ntohs (REPLY_MSG_ID_BASE + VL_API_CLASSIFY_PCAP_SET_TABLE_REPLY);
137 rmp->context = mp->context;
138 rmp->retval = ntohl (rv);
139 rmp->table_index = htonl (table_index);
141 vl_api_send_msg (reg, (u8 *) rmp);
144 static void vl_api_classify_pcap_get_tables_t_handler
145 (vl_api_classify_pcap_get_tables_t * mp)
147 vnet_classify_main_t *cm = &vnet_classify_main;
148 vl_api_classify_pcap_get_tables_reply_t *rmp;
149 vl_api_registration_t *reg;
154 reg = vl_api_client_index_to_registration (mp->client_index);
158 u32 sw_if_index = ntohl (mp->sw_if_index);
159 if (sw_if_index == ~0
160 || sw_if_index >= vec_len (cm->classify_table_index_by_sw_if_index))
162 rv = VNET_API_ERROR_INVALID_VALUE;
166 u32 table_index = classify_get_pcap_chain (cm, sw_if_index);
167 if (table_index == ~0)
171 * Form a vector of all classifier tables in this chain.
173 vnet_classify_table_t *t;
176 for (i = table_index; i != ~0; i = t->next_table_index)
178 vec_add1 (tables, i);
179 t = pool_elt_at_index (cm->tables, i);
183 count = vec_len (tables);
184 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
186 ntohs (REPLY_MSG_ID_BASE + VL_API_CLASSIFY_PCAP_GET_TABLES_REPLY);
187 rmp->context = mp->context;
188 rmp->retval = ntohl (rv);
189 rmp->count = htonl (count);
191 for (i = 0; i < count; ++i)
193 rmp->indices[i] = htonl (tables[i]);
198 vl_api_send_msg (reg, (u8 *) rmp);
202 static void vl_api_classify_trace_lookup_table_t_handler
203 (vl_api_classify_trace_lookup_table_t * mp)
205 vl_api_classify_trace_lookup_table_reply_t *rmp;
206 vl_api_registration_t *reg;
208 u32 table_index = ~0;
210 reg = vl_api_client_index_to_registration (mp->client_index);
214 u32 n_skip = ntohl (mp->skip_n_vectors);
215 u32 n_match = ntohl (mp->match_n_vectors);
216 u32 mask_len = ntohl (mp->mask_len);
218 || n_match == 0 || n_match > 5 || mask_len != n_match * sizeof (u32x4))
220 rv = VNET_API_ERROR_INVALID_VALUE;
225 table_chain = classify_get_trace_chain ();
228 vec_validate (mask_vec, mask_len - 1);
229 clib_memcpy (mask_vec, mp->mask, mask_len);
231 if (table_chain != ~0)
232 table_index = classify_lookup_chain (table_chain,
233 mask_vec, n_skip, n_match);
237 rmp = vl_msg_api_alloc (sizeof (*rmp));
239 ntohs ((REPLY_MSG_ID_BASE + VL_API_CLASSIFY_TRACE_LOOKUP_TABLE_REPLY));
240 rmp->context = mp->context;
241 rmp->retval = ntohl (rv);
242 rmp->table_index = htonl (table_index);
244 vl_api_send_msg (reg, (u8 *) rmp);
247 static void vl_api_classify_trace_set_table_t_handler
248 (vl_api_classify_trace_set_table_t * mp)
250 vnet_classify_main_t *cm = &vnet_classify_main;
251 vl_api_classify_trace_set_table_reply_t *rmp;
252 vl_api_registration_t *reg;
255 reg = vl_api_client_index_to_registration (mp->client_index);
259 u32 table_index = ntohl (mp->table_index);
260 if (table_index != ~0 && pool_is_free_index (cm->tables, table_index))
262 rv = VNET_API_ERROR_INVALID_VALUE;
267 * Maybe reorder tables such that masks are most-specific to least-specific.
269 if (table_index != ~0 && mp->sort_masks)
270 table_index = classify_sort_table_chain (cm, table_index);
272 classify_set_trace_chain (cm, table_index);
275 rmp = vl_msg_api_alloc (sizeof (*rmp));
277 ntohs ((REPLY_MSG_ID_BASE + VL_API_CLASSIFY_TRACE_SET_TABLE_REPLY));
278 rmp->context = mp->context;
279 rmp->retval = ntohl (rv);
280 rmp->table_index = htonl (table_index);
282 vl_api_send_msg (reg, (u8 *) rmp);
285 static void vl_api_classify_trace_get_tables_t_handler
286 (vl_api_classify_trace_get_tables_t * mp)
288 vnet_classify_main_t *cm = &vnet_classify_main;
289 vl_api_classify_trace_get_tables_reply_t *rmp;
290 vl_api_registration_t *reg;
295 reg = vl_api_client_index_to_registration (mp->client_index);
299 u32 table_index = classify_get_trace_chain ();
300 if (table_index == ~0)
304 * Form a vector of all classifier tables in this chain.
306 vnet_classify_table_t *t;
309 for (i = table_index; i != ~0; i = t->next_table_index)
311 vec_add1 (tables, i);
312 t = pool_elt_at_index (cm->tables, i);
316 count = vec_len (tables);
317 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
319 ntohs (REPLY_MSG_ID_BASE + VL_API_CLASSIFY_TRACE_GET_TABLES_REPLY);
320 rmp->context = mp->context;
321 rmp->retval = ntohl (rv);
322 rmp->count = htonl (count);
324 for (i = 0; i < count; ++i)
326 rmp->indices[i] = htonl (tables[i]);
331 vl_api_send_msg (reg, (u8 *) rmp);
335 static void vl_api_classify_add_del_table_t_handler
336 (vl_api_classify_add_del_table_t * mp)
338 vl_api_classify_add_del_table_reply_t *rmp;
339 vnet_classify_main_t *cm = &vnet_classify_main;
340 vnet_classify_table_t *t;
344 foreach_classify_add_del_table_field;
347 #define _(a) a = ntohl(mp->a);
348 foreach_classify_add_del_table_field;
351 if (mask_len != match_n_vectors * sizeof (u32x4))
353 rv = VNET_API_ERROR_INVALID_VALUE;
357 /* The underlying API fails silently, on purpose, so check here */
358 if (mp->is_add == 0) /* delete */
360 if (pool_is_free_index (cm->tables, table_index))
362 rv = VNET_API_ERROR_NO_SUCH_TABLE;
366 else /* add or update */
368 if (table_index != ~0 && pool_is_free_index (cm->tables, table_index))
372 u8 current_data_flag = mp->current_data_flag;
373 i16 current_data_offset = clib_net_to_host_i16 (mp->current_data_offset);
375 rv = vnet_classify_add_del_table
376 (cm, mp->mask, nbuckets, memory_size,
377 skip_n_vectors, match_n_vectors,
378 next_table_index, miss_next_index, &table_index,
379 current_data_flag, current_data_offset, mp->is_add, mp->del_chain);
383 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
385 if (rv == 0 && mp->is_add)
387 t = pool_elt_at_index (cm->tables, table_index);
388 rmp->skip_n_vectors = htonl(t->skip_n_vectors);
389 rmp->match_n_vectors = htonl(t->match_n_vectors);
390 rmp->new_table_index = htonl(table_index);
394 rmp->skip_n_vectors = ~0;
395 rmp->match_n_vectors = ~0;
396 rmp->new_table_index = ~0;
402 static void vl_api_classify_add_del_session_t_handler
403 (vl_api_classify_add_del_session_t * mp)
405 vnet_classify_main_t *cm = &vnet_classify_main;
406 vl_api_classify_add_del_session_reply_t *rmp;
408 u32 table_index, hit_next_index, opaque_index, metadata, match_len;
411 vnet_classify_table_t *t;
413 table_index = ntohl (mp->table_index);
414 hit_next_index = ntohl (mp->hit_next_index);
415 opaque_index = ntohl (mp->opaque_index);
416 advance = ntohl (mp->advance);
418 metadata = ntohl (mp->metadata);
419 match_len = ntohl (mp->match_len);
421 if (pool_is_free_index (cm->tables, table_index))
423 rv = VNET_API_ERROR_NO_SUCH_TABLE;
427 t = pool_elt_at_index (cm->tables, table_index);
429 if (match_len != (t->skip_n_vectors + t->match_n_vectors) * sizeof (u32x4))
431 rv = VNET_API_ERROR_INVALID_VALUE;
435 rv = vnet_classify_add_del_session
436 (cm, table_index, mp->match, hit_next_index, opaque_index,
437 advance, action, metadata, mp->is_add);
440 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
444 vl_api_policer_classify_set_interface_t_handler
445 (vl_api_policer_classify_set_interface_t * mp)
447 vlib_main_t *vm = vlib_get_main ();
448 vl_api_policer_classify_set_interface_reply_t *rmp;
450 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
452 ip4_table_index = ntohl (mp->ip4_table_index);
453 ip6_table_index = ntohl (mp->ip6_table_index);
454 l2_table_index = ntohl (mp->l2_table_index);
455 sw_if_index = ntohl (mp->sw_if_index);
457 VALIDATE_SW_IF_INDEX (mp);
459 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
460 ip6_table_index, l2_table_index,
463 BAD_SW_IF_INDEX_LABEL;
465 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
469 send_policer_classify_details (u32 sw_if_index,
470 u32 table_index, vl_api_registration_t * reg,
473 vl_api_policer_classify_details_t *mp;
475 mp = vl_msg_api_alloc (sizeof (*mp));
476 clib_memset (mp, 0, sizeof (*mp));
477 mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_POLICER_CLASSIFY_DETAILS);
478 mp->context = context;
479 mp->sw_if_index = htonl (sw_if_index);
480 mp->table_index = htonl (table_index);
482 vl_api_send_msg (reg, (u8 *) mp);
486 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
488 vl_api_registration_t *reg;
489 policer_classify_main_t *pcm = &policer_classify_main;
492 u32 filter_sw_if_index;
494 reg = vl_api_client_index_to_registration (mp->client_index);
498 filter_sw_if_index = ntohl (mp->sw_if_index);
499 if (filter_sw_if_index
500 >= vec_len (pcm->classify_table_index_by_sw_if_index[mp->type]))
503 if (filter_sw_if_index != ~0)
505 &pcm->classify_table_index_by_sw_if_index[mp->type][filter_sw_if_index];
507 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
509 if (vec_len (vec_tbl))
511 for (i = 0; i < vec_len (vec_tbl); i++)
513 if (vec_elt (vec_tbl, i) == ~0)
516 send_policer_classify_details (i, vec_elt (vec_tbl, i), reg,
523 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
525 vl_api_registration_t *reg;
527 reg = vl_api_client_index_to_registration (mp->client_index);
531 vnet_classify_main_t *cm = &vnet_classify_main;
532 vnet_classify_table_t *t;
537 pool_foreach (t, cm->tables)
539 vec_add1 (table_ids, ntohl(t - cm->tables));
542 count = vec_len (table_ids);
544 vl_api_classify_table_ids_reply_t *rmp;
545 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
547 ntohs (REPLY_MSG_ID_BASE + VL_API_CLASSIFY_TABLE_IDS_REPLY);
548 rmp->context = mp->context;
549 rmp->count = ntohl (count);
550 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
553 vl_api_send_msg (reg, (u8 *) rmp);
555 vec_free (table_ids);
559 vl_api_classify_table_by_interface_t_handler
560 (vl_api_classify_table_by_interface_t * mp)
562 vl_api_classify_table_by_interface_reply_t *rmp;
565 u32 sw_if_index = ntohl (mp->sw_if_index);
568 vec_validate (acl, IN_OUT_ACL_N_TABLES - 1);
571 VALIDATE_SW_IF_INDEX (mp);
573 in_out_acl_main_t *am = &in_out_acl_main;
578 for (type = 0; type < IN_OUT_ACL_N_TABLES; type++)
581 am->classify_table_index_by_sw_if_index[IN_OUT_ACL_INPUT_TABLE_GROUP]
583 if (vec_len (vec_tbl))
585 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
587 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
591 acl[type] = vec_elt (vec_tbl, if_idx);
596 BAD_SW_IF_INDEX_LABEL;
599 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
601 rmp->sw_if_index = ntohl(sw_if_index);
602 rmp->l2_table_id = ntohl(acl[IN_OUT_ACL_TABLE_L2]);
603 rmp->ip4_table_id = ntohl(acl[IN_OUT_ACL_TABLE_IP4]);
604 rmp->ip6_table_id = ntohl(acl[IN_OUT_ACL_TABLE_IP6]);
611 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
613 vl_api_registration_t *reg;
615 reg = vl_api_client_index_to_registration (mp->client_index);
619 vl_api_classify_table_info_reply_t *rmp = 0;
621 vnet_classify_main_t *cm = &vnet_classify_main;
622 u32 table_id = ntohl (mp->table_id);
623 vnet_classify_table_t *t;
625 pool_foreach (t, cm->tables)
627 if (table_id == t - cm->tables)
629 rmp = vl_msg_api_alloc_as_if_client (
630 sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
632 ntohs (REPLY_MSG_ID_BASE + VL_API_CLASSIFY_TABLE_INFO_REPLY);
633 rmp->context = mp->context;
634 rmp->table_id = ntohl (table_id);
635 rmp->nbuckets = ntohl (t->nbuckets);
636 rmp->match_n_vectors = ntohl (t->match_n_vectors);
637 rmp->skip_n_vectors = ntohl (t->skip_n_vectors);
638 rmp->active_sessions = ntohl (t->active_elements);
639 rmp->next_table_index = ntohl (t->next_table_index);
640 rmp->miss_next_index = ntohl (t->miss_next_index);
641 rmp->mask_length = ntohl (t->match_n_vectors * sizeof (u32x4));
642 clib_memcpy (rmp->mask, t->mask,
643 t->match_n_vectors * sizeof (u32x4));
651 rmp = vl_msg_api_alloc (sizeof (*rmp));
653 ntohs (REPLY_MSG_ID_BASE + VL_API_CLASSIFY_TABLE_INFO_REPLY);
654 rmp->context = mp->context;
655 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
658 vl_api_send_msg (reg, (u8 *) rmp);
662 send_classify_session_details (vl_api_registration_t * reg,
665 vnet_classify_entry_t * e, u32 context)
667 vl_api_classify_session_details_t *rmp;
669 rmp = vl_msg_api_alloc (sizeof (*rmp) + match_length);
670 clib_memset (rmp, 0, sizeof (*rmp));
672 ntohs (REPLY_MSG_ID_BASE + VL_API_CLASSIFY_SESSION_DETAILS);
673 rmp->context = context;
674 rmp->table_id = ntohl (table_id);
675 rmp->hit_next_index = ntohl (e->next_index);
676 rmp->advance = ntohl (e->advance);
677 rmp->opaque_index = ntohl (e->opaque_index);
678 rmp->match_length = ntohl (match_length);
679 clib_memcpy (rmp->match, e->key, match_length);
681 vl_api_send_msg (reg, (u8 *) rmp);
685 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
687 vnet_classify_main_t *cm = &vnet_classify_main;
688 vl_api_registration_t *reg;
690 u32 table_id = ntohl (mp->table_id);
691 vnet_classify_table_t *t;
693 reg = vl_api_client_index_to_registration (mp->client_index);
698 pool_foreach (t, cm->tables)
700 if (table_id == t - cm->tables)
702 vnet_classify_bucket_t * b;
703 vnet_classify_entry_t * v, * save_v;
706 for (i = 0; i < t->nbuckets; i++)
712 save_v = vnet_classify_get_entry (t, b->offset);
713 for (j = 0; j < (1<<b->log2_pages); j++)
715 for (k = 0; k < t->entries_per_page; k++)
717 v = vnet_classify_entry_at_index
718 (t, save_v, j*t->entries_per_page + k);
719 if (vnet_classify_entry_is_free (v))
722 send_classify_session_details
723 (reg, table_id, t->match_n_vectors * sizeof (u32x4),
735 vl_api_flow_classify_set_interface_t_handler
736 (vl_api_flow_classify_set_interface_t * mp)
738 vlib_main_t *vm = vlib_get_main ();
739 vl_api_flow_classify_set_interface_reply_t *rmp;
741 u32 sw_if_index, ip4_table_index, ip6_table_index;
743 ip4_table_index = ntohl (mp->ip4_table_index);
744 ip6_table_index = ntohl (mp->ip6_table_index);
745 sw_if_index = ntohl (mp->sw_if_index);
747 VALIDATE_SW_IF_INDEX (mp);
749 rv = vnet_set_flow_classify_intfc (vm, sw_if_index, ip4_table_index,
750 ip6_table_index, mp->is_add);
752 BAD_SW_IF_INDEX_LABEL;
754 REPLY_MACRO (VL_API_FLOW_CLASSIFY_SET_INTERFACE_REPLY);
758 send_flow_classify_details (u32 sw_if_index,
759 u32 table_index, vl_api_registration_t * reg,
762 vl_api_flow_classify_details_t *mp;
764 mp = vl_msg_api_alloc (sizeof (*mp));
765 clib_memset (mp, 0, sizeof (*mp));
766 mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_FLOW_CLASSIFY_DETAILS);
767 mp->context = context;
768 mp->sw_if_index = htonl (sw_if_index);
769 mp->table_index = htonl (table_index);
771 vl_api_send_msg (reg, (u8 *) mp);
775 vl_api_flow_classify_dump_t_handler (vl_api_flow_classify_dump_t * mp)
777 vl_api_registration_t *reg;
778 flow_classify_main_t *pcm = &flow_classify_main;
781 u32 filter_sw_if_index;
783 reg = vl_api_client_index_to_registration (mp->client_index);
787 filter_sw_if_index = ntohl (mp->sw_if_index);
788 if (filter_sw_if_index
789 >= vec_len (pcm->classify_table_index_by_sw_if_index[mp->type]))
792 if (filter_sw_if_index != ~0)
794 &pcm->classify_table_index_by_sw_if_index[mp->type][filter_sw_if_index];
796 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
798 if (vec_len (vec_tbl))
800 for (i = 0; i < vec_len (vec_tbl); i++)
802 if (vec_elt (vec_tbl, i) == ~0)
805 send_flow_classify_details (i, vec_elt (vec_tbl, i), reg,
811 static void vl_api_classify_set_interface_ip_table_t_handler
812 (vl_api_classify_set_interface_ip_table_t * mp)
814 vlib_main_t *vm = vlib_get_main ();
815 vl_api_classify_set_interface_ip_table_reply_t *rmp;
818 VALIDATE_SW_IF_INDEX (mp);
820 u32 table_index = ntohl (mp->table_index);
821 u32 sw_if_index = ntohl (mp->sw_if_index);
824 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
826 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
828 BAD_SW_IF_INDEX_LABEL;
830 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
833 static void vl_api_classify_set_interface_l2_tables_t_handler
834 (vl_api_classify_set_interface_l2_tables_t * mp)
836 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
838 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
841 ip4_table_index = ntohl (mp->ip4_table_index);
842 ip6_table_index = ntohl (mp->ip6_table_index);
843 other_table_index = ntohl (mp->other_table_index);
844 sw_if_index = ntohl (mp->sw_if_index);
846 VALIDATE_SW_IF_INDEX (mp);
849 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
853 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
859 if (ip4_table_index != ~0 || ip6_table_index != ~0
860 || other_table_index != ~0)
866 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
868 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
871 BAD_SW_IF_INDEX_LABEL;
873 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
876 static void vl_api_input_acl_set_interface_t_handler
877 (vl_api_input_acl_set_interface_t * mp)
879 vlib_main_t *vm = vlib_get_main ();
880 vl_api_input_acl_set_interface_reply_t *rmp;
883 VALIDATE_SW_IF_INDEX (mp);
885 u32 ip4_table_index = ntohl (mp->ip4_table_index);
886 u32 ip6_table_index = ntohl (mp->ip6_table_index);
887 u32 l2_table_index = ntohl (mp->l2_table_index);
888 u32 sw_if_index = ntohl (mp->sw_if_index);
890 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
891 ip6_table_index, l2_table_index, mp->is_add);
893 BAD_SW_IF_INDEX_LABEL;
895 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
899 vl_api_punt_acl_add_del_t_handler (vl_api_punt_acl_add_del_t *mp)
901 vlib_main_t *vm = vlib_get_main ();
902 vl_api_punt_acl_add_del_reply_t *rmp;
905 rv = vnet_set_in_out_acl_intfc (
906 vm, 0 /* sw_if_index */, ~0 /* ip4_table_index */,
907 ~0 /* ip6_table_index */, ~0 /* l2_table_index */,
908 ntohl (mp->ip4_table_index), ntohl (mp->ip6_table_index), mp->is_add,
911 REPLY_MACRO (VL_API_PUNT_ACL_ADD_DEL_REPLY);
915 vl_api_punt_acl_get_t_handler (vl_api_punt_acl_get_t *mp)
917 vl_api_punt_acl_get_reply_t *rmp;
920 const in_out_acl_main_t *am = &in_out_acl_main;
923 am->classify_table_index_by_sw_if_index[IN_OUT_ACL_INPUT_TABLE_GROUP];
924 const u32 *ip4_table = tables[IN_OUT_ACL_TABLE_IP4_PUNT];
925 const u32 *ip6_table = tables[IN_OUT_ACL_TABLE_IP6_PUNT];
926 const u32 ip4_table_index = vec_len (ip4_table) ? ip4_table[0] : ~0;
927 const u32 ip6_table_index = vec_len (ip6_table) ? ip6_table[0] : ~0;
929 REPLY_MACRO2 (VL_API_PUNT_ACL_GET_REPLY, ({
930 rmp->ip4_table_index = ntohl (ip4_table_index);
931 rmp->ip6_table_index = ntohl (ip6_table_index);
935 static void vl_api_output_acl_set_interface_t_handler
936 (vl_api_output_acl_set_interface_t * mp)
938 vlib_main_t *vm = vlib_get_main ();
939 vl_api_output_acl_set_interface_reply_t *rmp;
942 VALIDATE_SW_IF_INDEX (mp);
944 u32 ip4_table_index = ntohl (mp->ip4_table_index);
945 u32 ip6_table_index = ntohl (mp->ip6_table_index);
946 u32 l2_table_index = ntohl (mp->l2_table_index);
947 u32 sw_if_index = ntohl (mp->sw_if_index);
949 rv = vnet_set_output_acl_intfc (vm, sw_if_index, ip4_table_index,
950 ip6_table_index, l2_table_index,
953 BAD_SW_IF_INDEX_LABEL;
955 REPLY_MACRO (VL_API_OUTPUT_ACL_SET_INTERFACE_REPLY);
958 #include <classify/classify.api.c>
960 static clib_error_t *
961 classify_api_hookup (vlib_main_t * vm)
963 api_main_t *am = vlibapi_get_main ();
966 * Trace space for classifier mask+match
968 vl_api_increase_msg_trace_size (am, VL_API_CLASSIFY_ADD_DEL_TABLE,
970 vl_api_increase_msg_trace_size (am, VL_API_CLASSIFY_ADD_DEL_SESSION,
974 * Set up the (msg_name, crc, message-id) table
976 msg_id_base = setup_message_id_table ();
981 VLIB_API_INIT_FUNCTION (classify_api_hookup);
984 * fd.io coding-style-patch-verification: ON
987 * eval: (c-set-style "gnu")