From 30a819579cb396db1c975ae8e08477129aa7950d Mon Sep 17 00:00:00 2001 From: Benoît Ganne Date: Fri, 26 Feb 2021 13:47:41 +0100 Subject: classify: honor pcap interface filter also when classify filter is used MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Type: fix Change-Id: Ic32550ee9c5d76d232d8b67a7810611f6c8b9177 Signed-off-by: Benoît Ganne --- src/vnet/classify/pcap_classify.h | 59 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/vnet/classify/pcap_classify.h (limited to 'src/vnet/classify/pcap_classify.h') diff --git a/src/vnet/classify/pcap_classify.h b/src/vnet/classify/pcap_classify.h new file mode 100644 index 00000000000..1f1c38fd6e6 --- /dev/null +++ b/src/vnet/classify/pcap_classify.h @@ -0,0 +1,59 @@ +/* + * pcap_classify.h - Use the classifier to decide if a packet is captured + * + * Copyright (c) 2021 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include + +/** @file pcap_classify.h + * Use the vpp classifier to decide whether to capture packets + */ + +/** @brief vnet_is_packet_pcaped + * @param vlib_buffer_t *b - packet to capture + * @return 0 => no capture, 1 => capture + */ + +static_always_inline int +vnet_is_packet_pcaped (vnet_pcap_t *pp, vlib_buffer_t *b, u32 sw_if_index) +{ + const u32 pcap_sw_if_index = pp->pcap_sw_if_index; + const u32 filter_classify_table_index = pp->filter_classify_table_index; + + if (pcap_sw_if_index != 0) + { + if (~0 == sw_if_index) + sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX]; + if (pcap_sw_if_index != sw_if_index) + return 0; /* wrong interface, skip */ + } + + if (filter_classify_table_index != ~0 && + vnet_is_packet_traced_inline (b, filter_classify_table_index, + 0 /* full classify */) != 1) + return 0; /* not matching the filter, skip */ + + return 1; /* success */ +} + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ -- cgit 1.2.3-korg