FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
trace_classify.h
Go to the documentation of this file.
1 /*
2  * trace_classify.h - Use the classifier to decide if a packet is traced
3  *
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:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17 #include <vlib/vlib.h>
18 #include <vnet/vnet.h>
19 #include <vppinfra/error.h>
21 
22 /** @file trace_classify.h
23  * Use the vpp classifier to decide whether to trace packets
24  */
25 
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
31  */
32 
33 static inline int
35  u32 classify_table_index, int func)
36 {
40  u64 hash;
41 
42  /*$$$ add custom classifiers here, if any */
43  if (func != 0)
44  return -1;
45 
46  /* This will happen... */
47  if (pool_is_free_index (vcm->tables, classify_table_index))
48  return -1;
49 
50  /* Get the table */
51  t = pool_elt_at_index (vcm->tables, classify_table_index);
52 
53  /* Hash the packet */
55 
56  /* See if there's a matching entry */
58  0 /* time = 0, disables hit-counter */ );
59  /* Hit means trace the packet... */
60  if (e)
61  {
62  /* Manual hit accounting */
63  e->hits++;
64  return 1;
65  }
66 
67  /*
68  * Look for a hit in a less-specific table.
69  * Performance hint: for this use-case, don't go there.
70  */
71  while (1)
72  {
73  /* Most likely, we're done right now */
74  if (PREDICT_TRUE (t->next_table_index == ~0))
75  return 0;
76  t = pool_elt_at_index (vcm->tables, t->next_table_index);
77 
78  /* Compute hash for this table */
80 
81  /* See if there's a matching entry */
83  0 /* time = 0, disables hit-counter */ );
84  if (e)
85  {
86  /* Manual hit accounting */
87  e->hits++;
88  return 1;
89  }
90  }
91  /* NOTREACHED */
92 }
93 
94 /*
95  * fd.io coding-style-patch-verification: ON
96  *
97  * Local Variables:
98  * eval: (c-set-style "gnu")
99  * End:
100  */
vlib.h
vnet_classify_entry_t
struct _vnet_classify_entry vnet_classify_entry_t
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:553
vnet_classify_main
vnet_classify_main_t vnet_classify_main
Definition: vnet_classify.c:32
vnet_classify_find_entry
vnet_classify_entry_t * vnet_classify_find_entry(vnet_classify_table_t *t, u8 *h, u64 hash, f64 now)
Definition: vnet_classify.c:657
pool_is_free_index
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:302
error.h
vnet_classify_table_t
Definition: vnet_classify.h:147
vnet_classify_table_t::next_table_index
u32 next_table_index
Definition: vnet_classify.h:170
u64
unsigned long u64
Definition: types.h:89
u32
unsigned int u32
Definition: types.h:88
vnet_classify_main_t
struct _vnet_classify_main vnet_classify_main_t
Definition: vnet_classify.h:61
vnet_classify_hash_packet
u64 vnet_classify_hash_packet(vnet_classify_table_t *t, u8 *h)
vnet_classify.h
vnet_is_packet_traced_inline
static int vnet_is_packet_traced_inline(vlib_buffer_t *b, u32 classify_table_index, int func)
vnet_is_packet_traced
Definition: trace_classify.h:34
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
vlib_buffer_get_current
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:257
vnet.h
PREDICT_TRUE
#define PREDICT_TRUE(x)
Definition: clib.h:125
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
classify_table_index
u32 classify_table_index
Definition: fib_types.api:68