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 <vnet/vnet_msg_enum.h>
36 #define vl_typedefs /* define message structures */
37 #include <vnet/vnet_all_api_h.h>
40 #define vl_endianfun /* define message structures */
41 #include <vnet/vnet_all_api_h.h>
44 /* instantiate all the print functions we know about */
45 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
47 #include <vnet/vnet_all_api_h.h>
50 #include <vlibapi/api_helper_macros.h>
52 #define foreach_vpe_api_msg \
53 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
54 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
55 _(CLASSIFY_TABLE_IDS, classify_table_ids) \
56 _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
57 _(CLASSIFY_TABLE_INFO, classify_table_info) \
58 _(CLASSIFY_SESSION_DUMP, classify_session_dump) \
59 _(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface) \
60 _(POLICER_CLASSIFY_DUMP, policer_classify_dump) \
61 _(FLOW_CLASSIFY_SET_INTERFACE, flow_classify_set_interface) \
62 _(FLOW_CLASSIFY_DUMP, flow_classify_dump) \
63 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
64 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
65 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
66 _(OUTPUT_ACL_SET_INTERFACE, output_acl_set_interface) \
67 _(CLASSIFY_PCAP_LOOKUP_TABLE, classify_pcap_lookup_table) \
68 _(CLASSIFY_PCAP_SET_TABLE, classify_pcap_set_table) \
69 _(CLASSIFY_PCAP_GET_TABLES, classify_pcap_get_tables) \
70 _(CLASSIFY_TRACE_LOOKUP_TABLE, classify_trace_lookup_table) \
71 _(CLASSIFY_TRACE_SET_TABLE, classify_trace_set_table) \
72 _(CLASSIFY_TRACE_GET_TABLES, classify_trace_get_tables) \
75 #define foreach_classify_add_del_table_field \
86 static void vl_api_classify_pcap_lookup_table_t_handler
87 (vl_api_classify_pcap_lookup_table_t * mp)
89 vnet_classify_main_t *cm = &vnet_classify_main;
90 vl_api_registration_t *reg;
91 vl_api_classify_pcap_lookup_table_reply_t *rmp;
95 reg = vl_api_client_index_to_registration (mp->client_index);
99 u32 n_skip = ntohl (mp->skip_n_vectors);
100 u32 n_match = ntohl (mp->match_n_vectors);
101 u32 mask_len = ntohl (mp->mask_len);
102 u32 sw_if_index = ntohl (mp->sw_if_index);
105 || 0 <= n_match || n_match > 5
106 || mask_len != n_match * sizeof (u32x4)
108 || sw_if_index >= vec_len (cm->classify_table_index_by_sw_if_index))
110 rv = VNET_API_ERROR_INVALID_VALUE;
115 table_chain = classify_get_pcap_chain (cm, sw_if_index);
118 vec_validate (mask_vec, mask_len - 1);
119 clib_memcpy (mask_vec, mp->mask, mask_len);
121 if (table_chain != ~0)
122 table_index = classify_lookup_chain (table_chain,
123 mask_vec, n_skip, n_match);
128 rmp = vl_msg_api_alloc (sizeof (*rmp));
129 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_PCAP_LOOKUP_TABLE_REPLY);
130 rmp->context = mp->context;
131 rmp->retval = ntohl (rv);
132 rmp->table_index = htonl (table_index);
134 vl_api_send_msg (reg, (u8 *) rmp);
137 static void vl_api_classify_pcap_set_table_t_handler
138 (vl_api_classify_pcap_set_table_t * mp)
140 vnet_classify_main_t *cm = &vnet_classify_main;
141 vl_api_classify_pcap_set_table_reply_t *rmp;
142 vl_api_registration_t *reg;
145 reg = vl_api_client_index_to_registration (mp->client_index);
149 u32 table_index = ntohl (mp->table_index);
150 u32 sw_if_index = ntohl (mp->sw_if_index);
152 if (sw_if_index == ~0
153 || sw_if_index >= vec_len (cm->classify_table_index_by_sw_if_index)
154 || (table_index != ~0 && pool_is_free_index (cm->tables, table_index)))
156 rv = VNET_API_ERROR_INVALID_VALUE;
161 * Maybe reorder tables such that masks are most-specify to least-specific.
163 if (table_index != ~0 && mp->sort_masks)
164 table_index = classify_sort_table_chain (cm, table_index);
166 classify_set_pcap_chain (cm, sw_if_index, table_index);
169 rmp = vl_msg_api_alloc (sizeof (*rmp));
170 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_PCAP_SET_TABLE_REPLY);
171 rmp->context = mp->context;
172 rmp->retval = ntohl (rv);
173 rmp->table_index = htonl (table_index);
175 vl_api_send_msg (reg, (u8 *) rmp);
178 static void vl_api_classify_pcap_get_tables_t_handler
179 (vl_api_classify_pcap_get_tables_t * mp)
181 vnet_classify_main_t *cm = &vnet_classify_main;
182 vl_api_classify_pcap_get_tables_reply_t *rmp;
183 vl_api_registration_t *reg;
188 reg = vl_api_client_index_to_registration (mp->client_index);
192 u32 sw_if_index = ntohl (mp->sw_if_index);
193 if (sw_if_index == ~0
194 || sw_if_index >= vec_len (cm->classify_table_index_by_sw_if_index))
196 rv = VNET_API_ERROR_INVALID_VALUE;
200 u32 table_index = classify_get_pcap_chain (cm, sw_if_index);
201 if (table_index == ~0)
205 * Form a vector of all classifier tables in this chain.
207 vnet_classify_table_t *t;
210 for (i = table_index; i != ~0; i = t->next_table_index)
212 vec_add1 (tables, i);
213 t = pool_elt_at_index (cm->tables, i);
217 count = vec_len (tables);
218 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
219 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_PCAP_GET_TABLES_REPLY);
220 rmp->context = mp->context;
221 rmp->retval = ntohl (rv);
222 rmp->count = htonl (count);
224 for (i = 0; i < count; ++i)
226 rmp->indices[i] = htonl (tables[i]);
231 vl_api_send_msg (reg, (u8 *) rmp);
235 static void vl_api_classify_trace_lookup_table_t_handler
236 (vl_api_classify_trace_lookup_table_t * mp)
238 vl_api_classify_trace_lookup_table_reply_t *rmp;
239 vl_api_registration_t *reg;
241 u32 table_index = ~0;
243 reg = vl_api_client_index_to_registration (mp->client_index);
247 u32 n_skip = ntohl (mp->skip_n_vectors);
248 u32 n_match = ntohl (mp->match_n_vectors);
249 u32 mask_len = ntohl (mp->mask_len);
251 || n_match == 0 || n_match > 5 || mask_len != n_match * sizeof (u32x4))
253 rv = VNET_API_ERROR_INVALID_VALUE;
258 table_chain = classify_get_trace_chain ();
261 vec_validate (mask_vec, mask_len - 1);
262 clib_memcpy (mask_vec, mp->mask, mask_len);
264 if (table_chain != ~0)
265 table_index = classify_lookup_chain (table_chain,
266 mask_vec, n_skip, n_match);
270 rmp = vl_msg_api_alloc (sizeof (*rmp));
271 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TRACE_LOOKUP_TABLE_REPLY));
272 rmp->context = mp->context;
273 rmp->retval = ntohl (rv);
274 rmp->table_index = htonl (table_index);
276 vl_api_send_msg (reg, (u8 *) rmp);
279 static void vl_api_classify_trace_set_table_t_handler
280 (vl_api_classify_trace_set_table_t * mp)
282 vnet_classify_main_t *cm = &vnet_classify_main;
283 vl_api_classify_trace_set_table_reply_t *rmp;
284 vl_api_registration_t *reg;
287 reg = vl_api_client_index_to_registration (mp->client_index);
291 u32 table_index = ntohl (mp->table_index);
292 if (table_index != ~0 && pool_is_free_index (cm->tables, table_index))
294 rv = VNET_API_ERROR_INVALID_VALUE;
299 * Maybe reorder tables such that masks are most-specific to least-specific.
301 if (table_index != ~0 && mp->sort_masks)
302 table_index = classify_sort_table_chain (cm, table_index);
304 classify_set_trace_chain (cm, table_index);
307 rmp = vl_msg_api_alloc (sizeof (*rmp));
308 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TRACE_SET_TABLE_REPLY));
309 rmp->context = mp->context;
310 rmp->retval = ntohl (rv);
311 rmp->table_index = htonl (table_index);
313 vl_api_send_msg (reg, (u8 *) rmp);
316 static void vl_api_classify_trace_get_tables_t_handler
317 (vl_api_classify_trace_get_tables_t * mp)
319 vnet_classify_main_t *cm = &vnet_classify_main;
320 vl_api_classify_trace_get_tables_reply_t *rmp;
321 vl_api_registration_t *reg;
326 reg = vl_api_client_index_to_registration (mp->client_index);
330 u32 table_index = classify_get_trace_chain ();
331 if (table_index == ~0)
335 * Form a vector of all classifier tables in this chain.
337 vnet_classify_table_t *t;
340 for (i = table_index; i != ~0; i = t->next_table_index)
342 vec_add1 (tables, i);
343 t = pool_elt_at_index (cm->tables, i);
347 count = vec_len (tables);
348 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
349 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TRACE_GET_TABLES_REPLY);
350 rmp->context = mp->context;
351 rmp->retval = ntohl (rv);
352 rmp->count = htonl (count);
354 for (i = 0; i < count; ++i)
356 rmp->indices[i] = htonl (tables[i]);
361 vl_api_send_msg (reg, (u8 *) rmp);
365 static void vl_api_classify_add_del_table_t_handler
366 (vl_api_classify_add_del_table_t * mp)
368 vl_api_classify_add_del_table_reply_t *rmp;
369 vnet_classify_main_t *cm = &vnet_classify_main;
370 vnet_classify_table_t *t;
374 foreach_classify_add_del_table_field;
377 #define _(a) a = ntohl(mp->a);
378 foreach_classify_add_del_table_field;
381 if (mask_len != match_n_vectors * sizeof (u32x4))
383 rv = VNET_API_ERROR_INVALID_VALUE;
387 /* The underlying API fails silently, on purpose, so check here */
388 if (mp->is_add == 0) /* delete */
390 if (pool_is_free_index (cm->tables, table_index))
392 rv = VNET_API_ERROR_NO_SUCH_TABLE;
396 else /* add or update */
398 if (table_index != ~0 && pool_is_free_index (cm->tables, table_index))
402 u8 current_data_flag = mp->current_data_flag;
403 i16 current_data_offset = clib_net_to_host_i16 (mp->current_data_offset);
405 rv = vnet_classify_add_del_table
406 (cm, mp->mask, nbuckets, memory_size,
407 skip_n_vectors, match_n_vectors,
408 next_table_index, miss_next_index, &table_index,
409 current_data_flag, current_data_offset, mp->is_add, mp->del_chain);
413 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
415 if (rv == 0 && mp->is_add)
417 t = pool_elt_at_index (cm->tables, table_index);
418 rmp->skip_n_vectors = htonl(t->skip_n_vectors);
419 rmp->match_n_vectors = htonl(t->match_n_vectors);
420 rmp->new_table_index = htonl(table_index);
424 rmp->skip_n_vectors = ~0;
425 rmp->match_n_vectors = ~0;
426 rmp->new_table_index = ~0;
432 static void vl_api_classify_add_del_session_t_handler
433 (vl_api_classify_add_del_session_t * mp)
435 vnet_classify_main_t *cm = &vnet_classify_main;
436 vl_api_classify_add_del_session_reply_t *rmp;
438 u32 table_index, hit_next_index, opaque_index, metadata, match_len;
441 vnet_classify_table_t *t;
443 table_index = ntohl (mp->table_index);
444 hit_next_index = ntohl (mp->hit_next_index);
445 opaque_index = ntohl (mp->opaque_index);
446 advance = ntohl (mp->advance);
448 metadata = ntohl (mp->metadata);
449 match_len = ntohl (mp->match_len);
451 if (pool_is_free_index (cm->tables, table_index))
453 rv = VNET_API_ERROR_NO_SUCH_TABLE;
457 t = pool_elt_at_index (cm->tables, table_index);
459 if (match_len != (t->skip_n_vectors + t->match_n_vectors) * sizeof (u32x4))
461 rv = VNET_API_ERROR_INVALID_VALUE;
465 rv = vnet_classify_add_del_session
466 (cm, table_index, mp->match, hit_next_index, opaque_index,
467 advance, action, metadata, mp->is_add);
470 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
474 vl_api_policer_classify_set_interface_t_handler
475 (vl_api_policer_classify_set_interface_t * mp)
477 vlib_main_t *vm = vlib_get_main ();
478 vl_api_policer_classify_set_interface_reply_t *rmp;
480 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
482 ip4_table_index = ntohl (mp->ip4_table_index);
483 ip6_table_index = ntohl (mp->ip6_table_index);
484 l2_table_index = ntohl (mp->l2_table_index);
485 sw_if_index = ntohl (mp->sw_if_index);
487 VALIDATE_SW_IF_INDEX (mp);
489 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
490 ip6_table_index, l2_table_index,
493 BAD_SW_IF_INDEX_LABEL;
495 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
499 send_policer_classify_details (u32 sw_if_index,
500 u32 table_index, vl_api_registration_t * reg,
503 vl_api_policer_classify_details_t *mp;
505 mp = vl_msg_api_alloc (sizeof (*mp));
506 clib_memset (mp, 0, sizeof (*mp));
507 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
508 mp->context = context;
509 mp->sw_if_index = htonl (sw_if_index);
510 mp->table_index = htonl (table_index);
512 vl_api_send_msg (reg, (u8 *) mp);
516 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
518 vl_api_registration_t *reg;
519 policer_classify_main_t *pcm = &policer_classify_main;
522 u32 filter_sw_if_index;
524 reg = vl_api_client_index_to_registration (mp->client_index);
528 filter_sw_if_index = ntohl (mp->sw_if_index);
529 if (filter_sw_if_index
530 >= vec_len (pcm->classify_table_index_by_sw_if_index[mp->type]))
533 if (filter_sw_if_index != ~0)
535 &pcm->classify_table_index_by_sw_if_index[mp->type][filter_sw_if_index];
537 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
539 if (vec_len (vec_tbl))
541 for (i = 0; i < vec_len (vec_tbl); i++)
543 if (vec_elt (vec_tbl, i) == ~0)
546 send_policer_classify_details (i, vec_elt (vec_tbl, i), reg,
553 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
555 vl_api_registration_t *reg;
557 reg = vl_api_client_index_to_registration (mp->client_index);
561 vnet_classify_main_t *cm = &vnet_classify_main;
562 vnet_classify_table_t *t;
567 pool_foreach (t, cm->tables)
569 vec_add1 (table_ids, ntohl(t - cm->tables));
572 count = vec_len (table_ids);
574 vl_api_classify_table_ids_reply_t *rmp;
575 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
576 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
577 rmp->context = mp->context;
578 rmp->count = ntohl (count);
579 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
582 vl_api_send_msg (reg, (u8 *) rmp);
584 vec_free (table_ids);
588 vl_api_classify_table_by_interface_t_handler
589 (vl_api_classify_table_by_interface_t * mp)
591 vl_api_classify_table_by_interface_reply_t *rmp;
594 u32 sw_if_index = ntohl (mp->sw_if_index);
597 vec_validate (acl, IN_OUT_ACL_N_TABLES - 1);
600 VALIDATE_SW_IF_INDEX (mp);
602 in_out_acl_main_t *am = &in_out_acl_main;
607 for (type = 0; type < IN_OUT_ACL_N_TABLES; type++)
610 am->classify_table_index_by_sw_if_index[IN_OUT_ACL_INPUT_TABLE_GROUP]
612 if (vec_len (vec_tbl))
614 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
616 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
620 acl[type] = vec_elt (vec_tbl, if_idx);
625 BAD_SW_IF_INDEX_LABEL;
628 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
630 rmp->sw_if_index = ntohl(sw_if_index);
631 rmp->l2_table_id = ntohl(acl[IN_OUT_ACL_TABLE_L2]);
632 rmp->ip4_table_id = ntohl(acl[IN_OUT_ACL_TABLE_IP4]);
633 rmp->ip6_table_id = ntohl(acl[IN_OUT_ACL_TABLE_IP6]);
640 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
642 vl_api_registration_t *reg;
644 reg = vl_api_client_index_to_registration (mp->client_index);
648 vl_api_classify_table_info_reply_t *rmp = 0;
650 vnet_classify_main_t *cm = &vnet_classify_main;
651 u32 table_id = ntohl (mp->table_id);
652 vnet_classify_table_t *t;
655 pool_foreach (t, cm->tables)
657 if (table_id == t - cm->tables)
659 rmp = vl_msg_api_alloc_as_if_client
660 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
661 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
662 rmp->context = mp->context;
663 rmp->table_id = ntohl(table_id);
664 rmp->nbuckets = ntohl(t->nbuckets);
665 rmp->match_n_vectors = ntohl(t->match_n_vectors);
666 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
667 rmp->active_sessions = ntohl(t->active_elements);
668 rmp->next_table_index = ntohl(t->next_table_index);
669 rmp->miss_next_index = ntohl(t->miss_next_index);
670 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
671 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
680 rmp = vl_msg_api_alloc (sizeof (*rmp));
681 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
682 rmp->context = mp->context;
683 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
686 vl_api_send_msg (reg, (u8 *) rmp);
690 send_classify_session_details (vl_api_registration_t * reg,
693 vnet_classify_entry_t * e, u32 context)
695 vl_api_classify_session_details_t *rmp;
697 rmp = vl_msg_api_alloc (sizeof (*rmp));
698 clib_memset (rmp, 0, sizeof (*rmp));
699 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
700 rmp->context = context;
701 rmp->table_id = ntohl (table_id);
702 rmp->hit_next_index = ntohl (e->next_index);
703 rmp->advance = ntohl (e->advance);
704 rmp->opaque_index = ntohl (e->opaque_index);
705 rmp->match_length = ntohl (match_length);
706 clib_memcpy (rmp->match, e->key, match_length);
708 vl_api_send_msg (reg, (u8 *) rmp);
712 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
714 vnet_classify_main_t *cm = &vnet_classify_main;
715 vl_api_registration_t *reg;
717 u32 table_id = ntohl (mp->table_id);
718 vnet_classify_table_t *t;
720 reg = vl_api_client_index_to_registration (mp->client_index);
725 pool_foreach (t, cm->tables)
727 if (table_id == t - cm->tables)
729 vnet_classify_bucket_t * b;
730 vnet_classify_entry_t * v, * save_v;
733 for (i = 0; i < t->nbuckets; i++)
739 save_v = vnet_classify_get_entry (t, b->offset);
740 for (j = 0; j < (1<<b->log2_pages); j++)
742 for (k = 0; k < t->entries_per_page; k++)
744 v = vnet_classify_entry_at_index
745 (t, save_v, j*t->entries_per_page + k);
746 if (vnet_classify_entry_is_free (v))
749 send_classify_session_details
750 (reg, table_id, t->match_n_vectors * sizeof (u32x4),
762 vl_api_flow_classify_set_interface_t_handler
763 (vl_api_flow_classify_set_interface_t * mp)
765 vlib_main_t *vm = vlib_get_main ();
766 vl_api_flow_classify_set_interface_reply_t *rmp;
768 u32 sw_if_index, ip4_table_index, ip6_table_index;
770 ip4_table_index = ntohl (mp->ip4_table_index);
771 ip6_table_index = ntohl (mp->ip6_table_index);
772 sw_if_index = ntohl (mp->sw_if_index);
774 VALIDATE_SW_IF_INDEX (mp);
776 rv = vnet_set_flow_classify_intfc (vm, sw_if_index, ip4_table_index,
777 ip6_table_index, mp->is_add);
779 BAD_SW_IF_INDEX_LABEL;
781 REPLY_MACRO (VL_API_FLOW_CLASSIFY_SET_INTERFACE_REPLY);
785 send_flow_classify_details (u32 sw_if_index,
786 u32 table_index, vl_api_registration_t * reg,
789 vl_api_flow_classify_details_t *mp;
791 mp = vl_msg_api_alloc (sizeof (*mp));
792 clib_memset (mp, 0, sizeof (*mp));
793 mp->_vl_msg_id = ntohs (VL_API_FLOW_CLASSIFY_DETAILS);
794 mp->context = context;
795 mp->sw_if_index = htonl (sw_if_index);
796 mp->table_index = htonl (table_index);
798 vl_api_send_msg (reg, (u8 *) mp);
802 vl_api_flow_classify_dump_t_handler (vl_api_flow_classify_dump_t * mp)
804 vl_api_registration_t *reg;
805 flow_classify_main_t *pcm = &flow_classify_main;
808 u32 filter_sw_if_index;
810 reg = vl_api_client_index_to_registration (mp->client_index);
814 filter_sw_if_index = ntohl (mp->sw_if_index);
815 if (filter_sw_if_index
816 >= vec_len (pcm->classify_table_index_by_sw_if_index[mp->type]))
819 if (filter_sw_if_index != ~0)
821 &pcm->classify_table_index_by_sw_if_index[mp->type][filter_sw_if_index];
823 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
825 if (vec_len (vec_tbl))
827 for (i = 0; i < vec_len (vec_tbl); i++)
829 if (vec_elt (vec_tbl, i) == ~0)
832 send_flow_classify_details (i, vec_elt (vec_tbl, i), reg,
838 static void vl_api_classify_set_interface_ip_table_t_handler
839 (vl_api_classify_set_interface_ip_table_t * mp)
841 vlib_main_t *vm = vlib_get_main ();
842 vl_api_classify_set_interface_ip_table_reply_t *rmp;
845 VALIDATE_SW_IF_INDEX (mp);
847 u32 table_index = ntohl (mp->table_index);
848 u32 sw_if_index = ntohl (mp->sw_if_index);
851 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
853 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
855 BAD_SW_IF_INDEX_LABEL;
857 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
860 static void vl_api_classify_set_interface_l2_tables_t_handler
861 (vl_api_classify_set_interface_l2_tables_t * mp)
863 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
865 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
868 ip4_table_index = ntohl (mp->ip4_table_index);
869 ip6_table_index = ntohl (mp->ip6_table_index);
870 other_table_index = ntohl (mp->other_table_index);
871 sw_if_index = ntohl (mp->sw_if_index);
873 VALIDATE_SW_IF_INDEX (mp);
876 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
880 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
886 if (ip4_table_index != ~0 || ip6_table_index != ~0
887 || other_table_index != ~0)
893 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
895 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
898 BAD_SW_IF_INDEX_LABEL;
900 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
903 static void vl_api_input_acl_set_interface_t_handler
904 (vl_api_input_acl_set_interface_t * mp)
906 vlib_main_t *vm = vlib_get_main ();
907 vl_api_input_acl_set_interface_reply_t *rmp;
910 VALIDATE_SW_IF_INDEX (mp);
912 u32 ip4_table_index = ntohl (mp->ip4_table_index);
913 u32 ip6_table_index = ntohl (mp->ip6_table_index);
914 u32 l2_table_index = ntohl (mp->l2_table_index);
915 u32 sw_if_index = ntohl (mp->sw_if_index);
917 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
918 ip6_table_index, l2_table_index, mp->is_add);
920 BAD_SW_IF_INDEX_LABEL;
922 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
925 static void vl_api_output_acl_set_interface_t_handler
926 (vl_api_output_acl_set_interface_t * mp)
928 vlib_main_t *vm = vlib_get_main ();
929 vl_api_output_acl_set_interface_reply_t *rmp;
932 VALIDATE_SW_IF_INDEX (mp);
934 u32 ip4_table_index = ntohl (mp->ip4_table_index);
935 u32 ip6_table_index = ntohl (mp->ip6_table_index);
936 u32 l2_table_index = ntohl (mp->l2_table_index);
937 u32 sw_if_index = ntohl (mp->sw_if_index);
939 rv = vnet_set_output_acl_intfc (vm, sw_if_index, ip4_table_index,
940 ip6_table_index, l2_table_index,
943 BAD_SW_IF_INDEX_LABEL;
945 REPLY_MACRO (VL_API_OUTPUT_ACL_SET_INTERFACE_REPLY);
949 * classify_api_hookup
950 * Add vpe's API message handlers to the table.
951 * vlib has already mapped shared memory and
952 * added the client registration handlers.
953 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
955 #define vl_msg_name_crc_list
956 #include <vnet/vnet_all_api_h.h>
957 #undef vl_msg_name_crc_list
960 setup_message_id_table (api_main_t * am)
962 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
963 foreach_vl_msg_name_crc_classify;
967 static clib_error_t *
968 classify_api_hookup (vlib_main_t * vm)
970 api_main_t *am = vlibapi_get_main ();
973 vl_msg_api_set_handlers(VL_API_##N, #n, \
974 vl_api_##n##_t_handler, \
976 vl_api_##n##_t_endian, \
977 vl_api_##n##_t_print, \
978 sizeof(vl_api_##n##_t), 1);
983 * Set up the (msg_name, crc, message-id) table
985 setup_message_id_table (am);
990 VLIB_API_INIT_FUNCTION (classify_api_hookup);
993 * fd.io coding-style-patch-verification: ON
996 * eval: (c-set-style "gnu")