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 || sw_if_index >= vec_len (cm->classify_table_index_by_sw_if_index)
120 || (table_index != ~0 && pool_is_free_index (cm->tables, table_index)))
122 rv = VNET_API_ERROR_INVALID_VALUE;
127 * Maybe reorder tables such that masks are most-specify to least-specific.
129 if (table_index != ~0 && mp->sort_masks)
130 table_index = classify_sort_table_chain (cm, table_index);
132 classify_set_pcap_chain (cm, sw_if_index, table_index);
135 rmp = vl_msg_api_alloc (sizeof (*rmp));
137 ntohs (REPLY_MSG_ID_BASE + VL_API_CLASSIFY_PCAP_SET_TABLE_REPLY);
138 rmp->context = mp->context;
139 rmp->retval = ntohl (rv);
140 rmp->table_index = htonl (table_index);
142 vl_api_send_msg (reg, (u8 *) rmp);
145 static void vl_api_classify_pcap_get_tables_t_handler
146 (vl_api_classify_pcap_get_tables_t * mp)
148 vnet_classify_main_t *cm = &vnet_classify_main;
149 vl_api_classify_pcap_get_tables_reply_t *rmp;
150 vl_api_registration_t *reg;
155 reg = vl_api_client_index_to_registration (mp->client_index);
159 u32 sw_if_index = ntohl (mp->sw_if_index);
160 if (sw_if_index == ~0
161 || sw_if_index >= vec_len (cm->classify_table_index_by_sw_if_index))
163 rv = VNET_API_ERROR_INVALID_VALUE;
167 u32 table_index = classify_get_pcap_chain (cm, sw_if_index);
168 if (table_index == ~0)
172 * Form a vector of all classifier tables in this chain.
174 vnet_classify_table_t *t;
177 for (i = table_index; i != ~0; i = t->next_table_index)
179 vec_add1 (tables, i);
180 t = pool_elt_at_index (cm->tables, i);
184 count = vec_len (tables);
185 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
187 ntohs (REPLY_MSG_ID_BASE + VL_API_CLASSIFY_PCAP_GET_TABLES_REPLY);
188 rmp->context = mp->context;
189 rmp->retval = ntohl (rv);
190 rmp->count = htonl (count);
192 for (i = 0; i < count; ++i)
194 rmp->indices[i] = htonl (tables[i]);
199 vl_api_send_msg (reg, (u8 *) rmp);
203 static void vl_api_classify_trace_lookup_table_t_handler
204 (vl_api_classify_trace_lookup_table_t * mp)
206 vl_api_classify_trace_lookup_table_reply_t *rmp;
207 vl_api_registration_t *reg;
209 u32 table_index = ~0;
211 reg = vl_api_client_index_to_registration (mp->client_index);
215 u32 n_skip = ntohl (mp->skip_n_vectors);
216 u32 n_match = ntohl (mp->match_n_vectors);
217 u32 mask_len = ntohl (mp->mask_len);
219 || n_match == 0 || n_match > 5 || mask_len != n_match * sizeof (u32x4))
221 rv = VNET_API_ERROR_INVALID_VALUE;
226 table_chain = classify_get_trace_chain ();
229 vec_validate (mask_vec, mask_len - 1);
230 clib_memcpy (mask_vec, mp->mask, mask_len);
232 if (table_chain != ~0)
233 table_index = classify_lookup_chain (table_chain,
234 mask_vec, n_skip, n_match);
238 rmp = vl_msg_api_alloc (sizeof (*rmp));
240 ntohs ((REPLY_MSG_ID_BASE + VL_API_CLASSIFY_TRACE_LOOKUP_TABLE_REPLY));
241 rmp->context = mp->context;
242 rmp->retval = ntohl (rv);
243 rmp->table_index = htonl (table_index);
245 vl_api_send_msg (reg, (u8 *) rmp);
248 static void vl_api_classify_trace_set_table_t_handler
249 (vl_api_classify_trace_set_table_t * mp)
251 vnet_classify_main_t *cm = &vnet_classify_main;
252 vl_api_classify_trace_set_table_reply_t *rmp;
253 vl_api_registration_t *reg;
256 reg = vl_api_client_index_to_registration (mp->client_index);
260 u32 table_index = ntohl (mp->table_index);
261 if (table_index != ~0 && pool_is_free_index (cm->tables, table_index))
263 rv = VNET_API_ERROR_INVALID_VALUE;
268 * Maybe reorder tables such that masks are most-specific to least-specific.
270 if (table_index != ~0 && mp->sort_masks)
271 table_index = classify_sort_table_chain (cm, table_index);
273 classify_set_trace_chain (cm, table_index);
276 rmp = vl_msg_api_alloc (sizeof (*rmp));
278 ntohs ((REPLY_MSG_ID_BASE + VL_API_CLASSIFY_TRACE_SET_TABLE_REPLY));
279 rmp->context = mp->context;
280 rmp->retval = ntohl (rv);
281 rmp->table_index = htonl (table_index);
283 vl_api_send_msg (reg, (u8 *) rmp);
286 static void vl_api_classify_trace_get_tables_t_handler
287 (vl_api_classify_trace_get_tables_t * mp)
289 vnet_classify_main_t *cm = &vnet_classify_main;
290 vl_api_classify_trace_get_tables_reply_t *rmp;
291 vl_api_registration_t *reg;
296 reg = vl_api_client_index_to_registration (mp->client_index);
300 u32 table_index = classify_get_trace_chain ();
301 if (table_index == ~0)
305 * Form a vector of all classifier tables in this chain.
307 vnet_classify_table_t *t;
310 for (i = table_index; i != ~0; i = t->next_table_index)
312 vec_add1 (tables, i);
313 t = pool_elt_at_index (cm->tables, i);
317 count = vec_len (tables);
318 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
320 ntohs (REPLY_MSG_ID_BASE + VL_API_CLASSIFY_TRACE_GET_TABLES_REPLY);
321 rmp->context = mp->context;
322 rmp->retval = ntohl (rv);
323 rmp->count = htonl (count);
325 for (i = 0; i < count; ++i)
327 rmp->indices[i] = htonl (tables[i]);
332 vl_api_send_msg (reg, (u8 *) rmp);
336 static void vl_api_classify_add_del_table_t_handler
337 (vl_api_classify_add_del_table_t * mp)
339 vl_api_classify_add_del_table_reply_t *rmp;
340 vnet_classify_main_t *cm = &vnet_classify_main;
341 vnet_classify_table_t *t;
345 foreach_classify_add_del_table_field;
348 #define _(a) a = ntohl(mp->a);
349 foreach_classify_add_del_table_field;
352 if (mask_len != match_n_vectors * sizeof (u32x4))
354 rv = VNET_API_ERROR_INVALID_VALUE;
358 /* The underlying API fails silently, on purpose, so check here */
359 if (mp->is_add == 0) /* delete */
361 if (pool_is_free_index (cm->tables, table_index))
363 rv = VNET_API_ERROR_NO_SUCH_TABLE;
367 else /* add or update */
369 if (table_index != ~0 && pool_is_free_index (cm->tables, table_index))
373 u8 current_data_flag = mp->current_data_flag;
374 i16 current_data_offset = clib_net_to_host_i16 (mp->current_data_offset);
376 rv = vnet_classify_add_del_table
377 (cm, mp->mask, nbuckets, memory_size,
378 skip_n_vectors, match_n_vectors,
379 next_table_index, miss_next_index, &table_index,
380 current_data_flag, current_data_offset, mp->is_add, mp->del_chain);
384 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
386 if (rv == 0 && mp->is_add)
388 t = pool_elt_at_index (cm->tables, table_index);
389 rmp->skip_n_vectors = htonl(t->skip_n_vectors);
390 rmp->match_n_vectors = htonl(t->match_n_vectors);
391 rmp->new_table_index = htonl(table_index);
395 rmp->skip_n_vectors = ~0;
396 rmp->match_n_vectors = ~0;
397 rmp->new_table_index = ~0;
403 static void vl_api_classify_add_del_session_t_handler
404 (vl_api_classify_add_del_session_t * mp)
406 vnet_classify_main_t *cm = &vnet_classify_main;
407 vl_api_classify_add_del_session_reply_t *rmp;
409 u32 table_index, hit_next_index, opaque_index, metadata, match_len;
412 vnet_classify_table_t *t;
414 table_index = ntohl (mp->table_index);
415 hit_next_index = ntohl (mp->hit_next_index);
416 opaque_index = ntohl (mp->opaque_index);
417 advance = ntohl (mp->advance);
419 metadata = ntohl (mp->metadata);
420 match_len = ntohl (mp->match_len);
422 if (pool_is_free_index (cm->tables, table_index))
424 rv = VNET_API_ERROR_NO_SUCH_TABLE;
428 t = pool_elt_at_index (cm->tables, table_index);
430 if (match_len != (t->skip_n_vectors + t->match_n_vectors) * sizeof (u32x4))
432 rv = VNET_API_ERROR_INVALID_VALUE;
436 rv = vnet_classify_add_del_session
437 (cm, table_index, mp->match, hit_next_index, opaque_index,
438 advance, action, metadata, mp->is_add);
441 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
445 vl_api_policer_classify_set_interface_t_handler
446 (vl_api_policer_classify_set_interface_t * mp)
448 vlib_main_t *vm = vlib_get_main ();
449 vl_api_policer_classify_set_interface_reply_t *rmp;
451 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
453 ip4_table_index = ntohl (mp->ip4_table_index);
454 ip6_table_index = ntohl (mp->ip6_table_index);
455 l2_table_index = ntohl (mp->l2_table_index);
456 sw_if_index = ntohl (mp->sw_if_index);
458 VALIDATE_SW_IF_INDEX (mp);
460 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
461 ip6_table_index, l2_table_index,
464 BAD_SW_IF_INDEX_LABEL;
466 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
470 send_policer_classify_details (u32 sw_if_index,
471 u32 table_index, vl_api_registration_t * reg,
474 vl_api_policer_classify_details_t *mp;
476 mp = vl_msg_api_alloc (sizeof (*mp));
477 clib_memset (mp, 0, sizeof (*mp));
478 mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_POLICER_CLASSIFY_DETAILS);
479 mp->context = context;
480 mp->sw_if_index = htonl (sw_if_index);
481 mp->table_index = htonl (table_index);
483 vl_api_send_msg (reg, (u8 *) mp);
487 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
489 vl_api_registration_t *reg;
490 policer_classify_main_t *pcm = &policer_classify_main;
493 u32 filter_sw_if_index;
495 reg = vl_api_client_index_to_registration (mp->client_index);
499 filter_sw_if_index = ntohl (mp->sw_if_index);
500 if (filter_sw_if_index
501 >= vec_len (pcm->classify_table_index_by_sw_if_index[mp->type]))
504 if (filter_sw_if_index != ~0)
506 &pcm->classify_table_index_by_sw_if_index[mp->type][filter_sw_if_index];
508 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
510 if (vec_len (vec_tbl))
512 for (i = 0; i < vec_len (vec_tbl); i++)
514 if (vec_elt (vec_tbl, i) == ~0)
517 send_policer_classify_details (i, vec_elt (vec_tbl, i), reg,
524 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
526 vl_api_registration_t *reg;
528 reg = vl_api_client_index_to_registration (mp->client_index);
532 vnet_classify_main_t *cm = &vnet_classify_main;
533 vnet_classify_table_t *t;
538 pool_foreach (t, cm->tables)
540 vec_add1 (table_ids, ntohl(t - cm->tables));
543 count = vec_len (table_ids);
545 vl_api_classify_table_ids_reply_t *rmp;
546 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
548 ntohs (REPLY_MSG_ID_BASE + VL_API_CLASSIFY_TABLE_IDS_REPLY);
549 rmp->context = mp->context;
550 rmp->count = ntohl (count);
551 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
554 vl_api_send_msg (reg, (u8 *) rmp);
556 vec_free (table_ids);
560 vl_api_classify_table_by_interface_t_handler
561 (vl_api_classify_table_by_interface_t * mp)
563 vl_api_classify_table_by_interface_reply_t *rmp;
566 u32 sw_if_index = ntohl (mp->sw_if_index);
569 vec_validate (acl, IN_OUT_ACL_N_TABLES - 1);
572 VALIDATE_SW_IF_INDEX (mp);
574 in_out_acl_main_t *am = &in_out_acl_main;
579 for (type = 0; type < IN_OUT_ACL_N_TABLES; type++)
582 am->classify_table_index_by_sw_if_index[IN_OUT_ACL_INPUT_TABLE_GROUP]
584 if (vec_len (vec_tbl))
586 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
588 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
592 acl[type] = vec_elt (vec_tbl, if_idx);
597 BAD_SW_IF_INDEX_LABEL;
600 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
602 rmp->sw_if_index = ntohl(sw_if_index);
603 rmp->l2_table_id = ntohl(acl[IN_OUT_ACL_TABLE_L2]);
604 rmp->ip4_table_id = ntohl(acl[IN_OUT_ACL_TABLE_IP4]);
605 rmp->ip6_table_id = ntohl(acl[IN_OUT_ACL_TABLE_IP6]);
612 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
614 vl_api_registration_t *reg;
616 reg = vl_api_client_index_to_registration (mp->client_index);
620 vl_api_classify_table_info_reply_t *rmp = 0;
622 vnet_classify_main_t *cm = &vnet_classify_main;
623 u32 table_id = ntohl (mp->table_id);
624 vnet_classify_table_t *t;
626 pool_foreach (t, cm->tables)
628 if (table_id == t - cm->tables)
630 rmp = vl_msg_api_alloc_as_if_client (
631 sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
633 ntohs (REPLY_MSG_ID_BASE + VL_API_CLASSIFY_TABLE_INFO_REPLY);
634 rmp->context = mp->context;
635 rmp->table_id = ntohl (table_id);
636 rmp->nbuckets = ntohl (t->nbuckets);
637 rmp->match_n_vectors = ntohl (t->match_n_vectors);
638 rmp->skip_n_vectors = ntohl (t->skip_n_vectors);
639 rmp->active_sessions = ntohl (t->active_elements);
640 rmp->next_table_index = ntohl (t->next_table_index);
641 rmp->miss_next_index = ntohl (t->miss_next_index);
642 rmp->mask_length = ntohl (t->match_n_vectors * sizeof (u32x4));
643 clib_memcpy (rmp->mask, t->mask,
644 t->match_n_vectors * sizeof (u32x4));
652 rmp = vl_msg_api_alloc (sizeof (*rmp));
654 ntohs (REPLY_MSG_ID_BASE + VL_API_CLASSIFY_TABLE_INFO_REPLY);
655 rmp->context = mp->context;
656 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
659 vl_api_send_msg (reg, (u8 *) rmp);
663 send_classify_session_details (vl_api_registration_t * reg,
666 vnet_classify_entry_t * e, u32 context)
668 vl_api_classify_session_details_t *rmp;
670 rmp = vl_msg_api_alloc (sizeof (*rmp));
671 clib_memset (rmp, 0, sizeof (*rmp));
673 ntohs (REPLY_MSG_ID_BASE + VL_API_CLASSIFY_SESSION_DETAILS);
674 rmp->context = context;
675 rmp->table_id = ntohl (table_id);
676 rmp->hit_next_index = ntohl (e->next_index);
677 rmp->advance = ntohl (e->advance);
678 rmp->opaque_index = ntohl (e->opaque_index);
679 rmp->match_length = ntohl (match_length);
680 clib_memcpy (rmp->match, e->key, match_length);
682 vl_api_send_msg (reg, (u8 *) rmp);
686 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
688 vnet_classify_main_t *cm = &vnet_classify_main;
689 vl_api_registration_t *reg;
691 u32 table_id = ntohl (mp->table_id);
692 vnet_classify_table_t *t;
694 reg = vl_api_client_index_to_registration (mp->client_index);
699 pool_foreach (t, cm->tables)
701 if (table_id == t - cm->tables)
703 vnet_classify_bucket_t * b;
704 vnet_classify_entry_t * v, * save_v;
707 for (i = 0; i < t->nbuckets; i++)
713 save_v = vnet_classify_get_entry (t, b->offset);
714 for (j = 0; j < (1<<b->log2_pages); j++)
716 for (k = 0; k < t->entries_per_page; k++)
718 v = vnet_classify_entry_at_index
719 (t, save_v, j*t->entries_per_page + k);
720 if (vnet_classify_entry_is_free (v))
723 send_classify_session_details
724 (reg, table_id, t->match_n_vectors * sizeof (u32x4),
736 vl_api_flow_classify_set_interface_t_handler
737 (vl_api_flow_classify_set_interface_t * mp)
739 vlib_main_t *vm = vlib_get_main ();
740 vl_api_flow_classify_set_interface_reply_t *rmp;
742 u32 sw_if_index, ip4_table_index, ip6_table_index;
744 ip4_table_index = ntohl (mp->ip4_table_index);
745 ip6_table_index = ntohl (mp->ip6_table_index);
746 sw_if_index = ntohl (mp->sw_if_index);
748 VALIDATE_SW_IF_INDEX (mp);
750 rv = vnet_set_flow_classify_intfc (vm, sw_if_index, ip4_table_index,
751 ip6_table_index, mp->is_add);
753 BAD_SW_IF_INDEX_LABEL;
755 REPLY_MACRO (VL_API_FLOW_CLASSIFY_SET_INTERFACE_REPLY);
759 send_flow_classify_details (u32 sw_if_index,
760 u32 table_index, vl_api_registration_t * reg,
763 vl_api_flow_classify_details_t *mp;
765 mp = vl_msg_api_alloc (sizeof (*mp));
766 clib_memset (mp, 0, sizeof (*mp));
767 mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_FLOW_CLASSIFY_DETAILS);
768 mp->context = context;
769 mp->sw_if_index = htonl (sw_if_index);
770 mp->table_index = htonl (table_index);
772 vl_api_send_msg (reg, (u8 *) mp);
776 vl_api_flow_classify_dump_t_handler (vl_api_flow_classify_dump_t * mp)
778 vl_api_registration_t *reg;
779 flow_classify_main_t *pcm = &flow_classify_main;
782 u32 filter_sw_if_index;
784 reg = vl_api_client_index_to_registration (mp->client_index);
788 filter_sw_if_index = ntohl (mp->sw_if_index);
789 if (filter_sw_if_index
790 >= vec_len (pcm->classify_table_index_by_sw_if_index[mp->type]))
793 if (filter_sw_if_index != ~0)
795 &pcm->classify_table_index_by_sw_if_index[mp->type][filter_sw_if_index];
797 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
799 if (vec_len (vec_tbl))
801 for (i = 0; i < vec_len (vec_tbl); i++)
803 if (vec_elt (vec_tbl, i) == ~0)
806 send_flow_classify_details (i, vec_elt (vec_tbl, i), reg,
812 static void vl_api_classify_set_interface_ip_table_t_handler
813 (vl_api_classify_set_interface_ip_table_t * mp)
815 vlib_main_t *vm = vlib_get_main ();
816 vl_api_classify_set_interface_ip_table_reply_t *rmp;
819 VALIDATE_SW_IF_INDEX (mp);
821 u32 table_index = ntohl (mp->table_index);
822 u32 sw_if_index = ntohl (mp->sw_if_index);
825 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
827 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
829 BAD_SW_IF_INDEX_LABEL;
831 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
834 static void vl_api_classify_set_interface_l2_tables_t_handler
835 (vl_api_classify_set_interface_l2_tables_t * mp)
837 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
839 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
842 ip4_table_index = ntohl (mp->ip4_table_index);
843 ip6_table_index = ntohl (mp->ip6_table_index);
844 other_table_index = ntohl (mp->other_table_index);
845 sw_if_index = ntohl (mp->sw_if_index);
847 VALIDATE_SW_IF_INDEX (mp);
850 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
854 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
860 if (ip4_table_index != ~0 || ip6_table_index != ~0
861 || other_table_index != ~0)
867 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
869 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
872 BAD_SW_IF_INDEX_LABEL;
874 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
877 static void vl_api_input_acl_set_interface_t_handler
878 (vl_api_input_acl_set_interface_t * mp)
880 vlib_main_t *vm = vlib_get_main ();
881 vl_api_input_acl_set_interface_reply_t *rmp;
884 VALIDATE_SW_IF_INDEX (mp);
886 u32 ip4_table_index = ntohl (mp->ip4_table_index);
887 u32 ip6_table_index = ntohl (mp->ip6_table_index);
888 u32 l2_table_index = ntohl (mp->l2_table_index);
889 u32 sw_if_index = ntohl (mp->sw_if_index);
891 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
892 ip6_table_index, l2_table_index, mp->is_add);
894 BAD_SW_IF_INDEX_LABEL;
896 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
900 vl_api_punt_acl_add_del_t_handler (vl_api_punt_acl_add_del_t *mp)
902 vlib_main_t *vm = vlib_get_main ();
903 vl_api_punt_acl_add_del_reply_t *rmp;
906 rv = vnet_set_in_out_acl_intfc (
907 vm, 0 /* sw_if_index */, ~0 /* ip4_table_index */,
908 ~0 /* ip6_table_index */, ~0 /* l2_table_index */,
909 ntohl (mp->ip4_table_index), ntohl (mp->ip6_table_index), mp->is_add,
912 REPLY_MACRO (VL_API_PUNT_ACL_ADD_DEL_REPLY);
916 vl_api_punt_acl_get_t_handler (vl_api_punt_acl_get_t *mp)
918 vl_api_punt_acl_get_reply_t *rmp;
921 const in_out_acl_main_t *am = &in_out_acl_main;
924 am->classify_table_index_by_sw_if_index[IN_OUT_ACL_INPUT_TABLE_GROUP];
925 const u32 *ip4_table = tables[IN_OUT_ACL_TABLE_IP4_PUNT];
926 const u32 *ip6_table = tables[IN_OUT_ACL_TABLE_IP6_PUNT];
927 const u32 ip4_table_index = vec_len (ip4_table) ? ip4_table[0] : ~0;
928 const u32 ip6_table_index = vec_len (ip6_table) ? ip6_table[0] : ~0;
930 REPLY_MACRO2 (VL_API_PUNT_ACL_GET_REPLY, ({
931 rmp->ip4_table_index = ntohl (ip4_table_index);
932 rmp->ip6_table_index = ntohl (ip6_table_index);
936 static void vl_api_output_acl_set_interface_t_handler
937 (vl_api_output_acl_set_interface_t * mp)
939 vlib_main_t *vm = vlib_get_main ();
940 vl_api_output_acl_set_interface_reply_t *rmp;
943 VALIDATE_SW_IF_INDEX (mp);
945 u32 ip4_table_index = ntohl (mp->ip4_table_index);
946 u32 ip6_table_index = ntohl (mp->ip6_table_index);
947 u32 l2_table_index = ntohl (mp->l2_table_index);
948 u32 sw_if_index = ntohl (mp->sw_if_index);
950 rv = vnet_set_output_acl_intfc (vm, sw_if_index, ip4_table_index,
951 ip6_table_index, l2_table_index,
954 BAD_SW_IF_INDEX_LABEL;
956 REPLY_MACRO (VL_API_OUTPUT_ACL_SET_INTERFACE_REPLY);
959 #include <classify/classify.api.c>
961 static clib_error_t *
962 classify_api_hookup (vlib_main_t * vm)
964 api_main_t *am = vlibapi_get_main ();
967 * Trace space for classifier mask+match
969 vl_api_increase_msg_trace_size (am, VL_API_CLASSIFY_ADD_DEL_TABLE,
971 vl_api_increase_msg_trace_size (am, VL_API_CLASSIFY_ADD_DEL_SESSION,
975 * Set up the (msg_name, crc, message-id) table
977 msg_id_base = setup_message_id_table ();
982 VLIB_API_INIT_FUNCTION (classify_api_hookup);
985 * fd.io coding-style-patch-verification: ON
988 * eval: (c-set-style "gnu")