2 * pcap_classify.h - Use the classifier to decide if a packet is captured
4 * Copyright (c) 2021 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 <vnet/classify/vnet_classify.h>
20 #include <vnet/classify/trace_classify.h>
22 /** @file pcap_classify.h
23 * Use the vpp classifier to decide whether to capture packets
26 /** @brief vnet_is_packet_pcaped
27 * @param vlib_buffer_t *b - packet to capture
28 * @return 0 => no capture, 1 => capture
31 static_always_inline int
32 vnet_is_packet_pcaped (vnet_pcap_t *pp, vlib_buffer_t *b, u32 sw_if_index)
34 const u32 pcap_sw_if_index = pp->pcap_sw_if_index;
35 const u32 filter_classify_table_index = pp->filter_classify_table_index;
36 const vlib_error_t pcap_error_index = pp->pcap_error_index;
38 if (pcap_sw_if_index != 0)
40 if (~0 == sw_if_index)
41 sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
42 if (pcap_sw_if_index != sw_if_index)
43 return 0; /* wrong interface, skip */
46 if (pcap_error_index != (vlib_error_t) ~0 && pcap_error_index != b->error)
47 return 0; /* wrong error */
49 if (filter_classify_table_index != ~0 &&
50 vnet_is_packet_traced_inline (b, filter_classify_table_index,
51 0 /* full classify */) != 1)
52 return 0; /* not matching the filter, skip */
54 return 1; /* success */
58 * fd.io coding-style-patch-verification: ON
61 * eval: (c-set-style "gnu")