Line data Source code
1 : /* 2 : * pcap_classify.h - Use the classifier to decide if a packet is captured 3 : * 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: 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 <vnet/classify/vnet_classify.h> 20 : #include <vnet/classify/trace_classify.h> 21 : 22 : /** @file pcap_classify.h 23 : * Use the vpp classifier to decide whether to capture packets 24 : */ 25 : 26 : /** @brief vnet_is_packet_pcaped 27 : * @param vlib_buffer_t *b - packet to capture 28 : * @return 0 => no capture, 1 => capture 29 : */ 30 : 31 : static_always_inline int 32 386 : vnet_is_packet_pcaped (vnet_pcap_t *pp, vlib_buffer_t *b, u32 sw_if_index) 33 : { 34 386 : const u32 pcap_sw_if_index = pp->pcap_sw_if_index; 35 386 : const u32 filter_classify_table_index = pp->filter_classify_table_index; 36 386 : const vlib_error_t pcap_error_index = pp->pcap_error_index; 37 : 38 386 : if (pcap_sw_if_index != 0) 39 : { 40 234 : if (~0 == sw_if_index) 41 117 : sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX]; 42 234 : if (pcap_sw_if_index != sw_if_index) 43 117 : return 0; /* wrong interface, skip */ 44 : } 45 : 46 269 : if (pcap_error_index != (vlib_error_t) ~0 && pcap_error_index != b->error) 47 1 : return 0; /* wrong error */ 48 : 49 447 : if (filter_classify_table_index != ~0 && 50 179 : vnet_is_packet_traced_inline (b, filter_classify_table_index, 51 : 0 /* full classify */) != 1) 52 93 : return 0; /* not matching the filter, skip */ 53 : 54 175 : return 1; /* success */ 55 : } 56 : 57 : /* 58 : * fd.io coding-style-patch-verification: ON 59 : * 60 : * Local Variables: 61 : * eval: (c-set-style "gnu") 62 : * End: 63 : */