BenoƮt Ganne | 30a8195 | 2021-02-26 13:47:41 +0100 | [diff] [blame^] | 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 | vnet_is_packet_pcaped (vnet_pcap_t *pp, vlib_buffer_t *b, u32 sw_if_index) |
| 33 | { |
| 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 | |
| 37 | if (pcap_sw_if_index != 0) |
| 38 | { |
| 39 | if (~0 == sw_if_index) |
| 40 | sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX]; |
| 41 | if (pcap_sw_if_index != sw_if_index) |
| 42 | return 0; /* wrong interface, skip */ |
| 43 | } |
| 44 | |
| 45 | if (filter_classify_table_index != ~0 && |
| 46 | vnet_is_packet_traced_inline (b, filter_classify_table_index, |
| 47 | 0 /* full classify */) != 1) |
| 48 | return 0; /* not matching the filter, skip */ |
| 49 | |
| 50 | return 1; /* success */ |
| 51 | } |
| 52 | |
| 53 | /* |
| 54 | * fd.io coding-style-patch-verification: ON |
| 55 | * |
| 56 | * Local Variables: |
| 57 | * eval: (c-set-style "gnu") |
| 58 | * End: |
| 59 | */ |