2 * trace_classify.h - Use the classifier to decide if a packet is traced
4 * Copyright (c) 2019 Cisco and/or its affiliates.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 #include <vlib/vlib.h>
18 #include <vnet/vnet.h>
19 #include <vppinfra/error.h>
20 #include <vnet/classify/vnet_classify.h>
22 /** @file trace_classify.h
23 * Use the vpp classifier to decide whether to trace packets
26 /** @brief vnet_is_packet_traced
27 * @param vlib_buffer_t *b - packet to classify
28 * @param int func - 0 => use classifier w/ supplied table index
29 * @param u32 classify_table_index - classifier table index
30 * @return 0 => no trace, 1 => trace, -1 => error
32 int vnet_is_packet_traced (vlib_buffer_t *b, u32 classify_table_index,
36 vnet_is_packet_traced_inline (vlib_buffer_t * b,
37 u32 classify_table_index, int func)
39 vnet_classify_main_t *vcm = &vnet_classify_main;
40 vnet_classify_table_t *t;
41 vnet_classify_entry_t *e;
44 /*$$$ add custom classifiers here, if any */
48 /* This will happen... */
49 if (pool_is_free_index (vcm->tables, classify_table_index))
53 t = pool_elt_at_index (vcm->tables, classify_table_index);
56 hash = vnet_classify_hash_packet (t, vlib_buffer_get_current (b));
58 /* See if there's a matching entry */
59 e = vnet_classify_find_entry (t, vlib_buffer_get_current (b), hash,
60 0 /* time = 0, disables hit-counter */ );
61 /* Hit means trace the packet... */
64 /* Manual hit accounting */
70 * Look for a hit in a less-specific table.
71 * Performance hint: for this use-case, don't go there.
75 /* Most likely, we're done right now */
76 if (PREDICT_TRUE (t->next_table_index == ~0))
78 t = pool_elt_at_index (vcm->tables, t->next_table_index);
80 /* Compute hash for this table */
81 hash = vnet_classify_hash_packet (t, vlib_buffer_get_current (b));
83 /* See if there's a matching entry */
84 e = vnet_classify_find_entry (t, vlib_buffer_get_current (b), hash,
85 0 /* time = 0, disables hit-counter */ );
88 /* Manual hit accounting */
97 * fd.io coding-style-patch-verification: ON
100 * eval: (c-set-style "gnu")