FD.io VPP  v19.04-6-g6f05f72
Vector Packet Processing
pcap.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /*
16  * pcap.h: libpcap packet capture format
17  *
18  * Copyright (c) 2008 Eliot Dresselhaus
19  *
20  * Permission is hereby granted, free of charge, to any person obtaining
21  * a copy of this software and associated documentation files (the
22  * "Software"), to deal in the Software without restriction, including
23  * without limitation the rights to use, copy, modify, merge, publish,
24  * distribute, sublicense, and/or sell copies of the Software, and to
25  * permit persons to whom the Software is furnished to do so, subject to
26  * the following conditions:
27  *
28  * The above copyright notice and this permission notice shall be
29  * included in all copies or substantial portions of the Software.
30  *
31  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38  */
39 /**
40  * @file
41  * @brief PCAP utility definitions
42  */
43 #ifndef included_vppinfra_pcap_h
44 #define included_vppinfra_pcap_h
45 
46 #include <vppinfra/types.h>
47 #include <vppinfra/cache.h>
48 #include <vppinfra/mem.h>
49 #include <vppinfra/lock.h>
50 
51 /**
52  * @brief Known libpcap encap types
53  *
54  * These codes end up in the pcap file header.
55  * If you decide to build a wireshark dissector,
56  * you'll need to know that these codes are mapped
57  * through the pcap_to_wtap_map[] array in .../wiretap/pcap-common.c.
58  *
59  * For example:
60  *
61  * { 280, WTAP_ENCAP_VPP },
62  *
63  * A file with the officially-allocated vpp packet type PCAP_PACKET_TYPE_vpp
64  * aka 280, will need a top-level dissector registered to
65  * deal with WTAP_ENCAP_VPP [=206].
66  *
67  * Something like so:
68  *
69  * dissector_add_uint("wtap_encap", WTAP_ENCAP_VPP, vpp_dissector_handle);
70  *
71  */
72 #define foreach_vnet_pcap_packet_type \
73  _ (null, 0) \
74  _ (ethernet, 1) \
75  _ (ppp, 9) \
76  _ (ip, 12) \
77  _ (hdlc, 104) \
78  _ (user0, 147) \
79  _ (user1, 148) \
80  _ (user2, 149) \
81  _ (user3, 150) \
82  _ (user4, 151) \
83  _ (user5, 152) \
84  _ (user6, 153) \
85  _ (user7, 154) \
86  _ (user8, 155) \
87  _ (user9, 156) \
88  _ (user10, 157) \
89  _ (user11, 158) \
90  _ (user12, 159) \
91  _ (user13, 160) \
92  _ (user14, 161) \
93  _ (user15, 162) \
94  _ (vpp, 280) \
95 
96 typedef enum
97 {
98 #define _(f,n) PCAP_PACKET_TYPE_##f = (n),
100 #undef _
102 
103 #define foreach_pcap_file_header \
104  /** 0xa1b2c3d4 host byte order. \
105  0xd4c3b2a1 => need to byte swap everything. */ \
106  _ (u32, magic) \
107  \
108  /** Currently major 2 minor 4. */ \
109  _ (u16, major_version) \
110  _ (u16, minor_version) \
111  \
112  /** 0 for GMT. */ \
113  _ (u32, time_zone) \
114  \
115  /** Accuracy of timestamps. Typically set to 0. */ \
116  _ (u32, sigfigs) \
117  \
118  /** Size of largest packet in file. */ \
119  _ (u32, max_packet_size_in_bytes) \
120  \
121  /** One of vnet_pcap_packet_type_t. */ \
122  _ (u32, packet_type)
123 
124 /** File header struct */
125 typedef struct
126 {
127 #define _(t, f) t f;
129 #undef _
131 
132 #define foreach_pcap_packet_header \
133  /** Time stamp in seconds */ \
134  _ (u32, time_in_sec) \
135  /** Time stamp in microseconds. */ \
136  _ (u32, time_in_usec) \
137  \
138  /** Number of bytes stored in file. */ \
139  _ (u32, n_packet_bytes_stored_in_file) \
140  /** Number of bytes in actual packet. */ \
141  _ (u32, n_bytes_in_packet)
142 
143 /** Packet header. */
144 typedef struct
145 {
146 #define _(t, f) t f;
148 #undef _
149  /** Packet data follows. */
150  u8 data[0];
152 
153 /**
154  * @brief PCAP main state data structure
155  */
156 typedef struct
157 {
158  /** spinlock to protect e.g. pcap_data */
160 
161  /** File name of pcap output. */
162  char *file_name;
163 
164  /** Number of packets to capture. */
166 
167  /** Packet type */
169 
170  /** Number of packets currently captured. */
172 
173  /** flags */
175 #define PCAP_MAIN_INIT_DONE (1 << 0)
176 
177  /** File descriptor for reading/writing. */
179 
180  /** Bytes written */
182 
183  /** Vector of pcap data. */
185 
186  /** Packets read from file. */
188 
189  /** Timestamps */
191 
192  /** Min/Max Packet bytes */
193  u32 min_packet_bytes, max_packet_bytes;
194 } pcap_main_t;
195 
196 #endif /* included_vppinfra_pcap_h */
197 
198 /*
199  * fd.io coding-style-patch-verification: ON
200  *
201  * Local Variables:
202  * eval: (c-set-style "gnu")
203  * End:
204  */
char * file_name
File name of pcap output.
Definition: pcap.h:162
u32 flags
flags
Definition: pcap.h:174
int file_descriptor
File descriptor for reading/writing.
Definition: pcap.h:178
u32 n_packets_to_capture
Number of packets to capture.
Definition: pcap.h:165
unsigned long u64
Definition: types.h:89
u8 data[128]
Definition: ipsec.api:248
unsigned char u8
Definition: types.h:56
PCAP main state data structure.
Definition: pcap.h:156
clib_spinlock_t lock
spinlock to protect e.g.
Definition: pcap.h:159
#define foreach_pcap_packet_header
Definition: pcap.h:132
u32 n_pcap_data_written
Bytes written.
Definition: pcap.h:181
unsigned int u32
Definition: types.h:88
pcap_packet_type_t
Definition: pcap.h:96
u8 * pcap_data
Vector of pcap data.
Definition: pcap.h:184
Packet header.
Definition: pcap.h:144
u32 min_packet_bytes
Min/Max Packet bytes.
Definition: pcap.h:193
u64 * timestamps
Timestamps.
Definition: pcap.h:190
pcap_packet_type_t packet_type
Packet type.
Definition: pcap.h:168
File header struct.
Definition: pcap.h:125
u8 ** packets_read
Packets read from file.
Definition: pcap.h:187
u32 n_packets_captured
Number of packets currently captured.
Definition: pcap.h:171
#define foreach_vnet_pcap_packet_type
Known libpcap encap types.
Definition: pcap.h:72
#define foreach_pcap_file_header
Definition: pcap.h:103