summaryrefslogtreecommitdiffstats
path: root/src/vnet/classify/pcap_classify.h
blob: e079816f62c27b8048ac3c3b49832a0f2228c770 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * 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 <vlib/vlib.h>
#include <vnet/vnet.h>
#include <vnet/classify/vnet_classify.h>
#include <vnet/classify/trace_classify.h>

/** @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;
  const vlib_error_t pcap_error_index = pp->pcap_error_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 (pcap_error_index != (vlib_error_t) ~0 && pcap_error_index != b->error)
    return 0; /* wrong error */

  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:
 */