xref: /freebsd/sys/net/bpf.h (revision ea906c4152774dff300bb26fbfc1e4188351c89a)
1 /*-
2  * Copyright (c) 1990, 1991, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from the Stanford/CMU enet packet filter,
6  * (net/enet.c) distributed as part of 4.3BSD, and code contributed
7  * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
8  * Berkeley Laboratory.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 4. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  *      @(#)bpf.h	8.1 (Berkeley) 6/10/93
35  *	@(#)bpf.h	1.34 (LBL)     6/16/96
36  *
37  * $FreeBSD$
38  */
39 
40 #ifndef _NET_BPF_H_
41 #define _NET_BPF_H_
42 
43 /* BSD style release date */
44 #define	BPF_RELEASE 199606
45 
46 typedef	int32_t	  bpf_int32;
47 typedef	u_int32_t bpf_u_int32;
48 
49 /*
50  * Alignment macros.  BPF_WORDALIGN rounds up to the next
51  * even multiple of BPF_ALIGNMENT.
52  */
53 #define BPF_ALIGNMENT sizeof(long)
54 #define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
55 
56 #define BPF_MAXINSNS 512
57 #define BPF_MAXBUFSIZE 0x80000
58 #define BPF_MINBUFSIZE 32
59 
60 /*
61  *  Structure for BIOCSETF.
62  */
63 struct bpf_program {
64 	u_int bf_len;
65 	struct bpf_insn *bf_insns;
66 };
67 
68 /*
69  * Struct returned by BIOCGSTATS.
70  */
71 struct bpf_stat {
72 	u_int bs_recv;		/* number of packets received */
73 	u_int bs_drop;		/* number of packets dropped */
74 };
75 
76 /*
77  * Struct return by BIOCVERSION.  This represents the version number of
78  * the filter language described by the instruction encodings below.
79  * bpf understands a program iff kernel_major == filter_major &&
80  * kernel_minor >= filter_minor, that is, if the value returned by the
81  * running kernel has the same major number and a minor number equal
82  * equal to or less than the filter being downloaded.  Otherwise, the
83  * results are undefined, meaning an error may be returned or packets
84  * may be accepted haphazardly.
85  * It has nothing to do with the source code version.
86  */
87 struct bpf_version {
88 	u_short bv_major;
89 	u_short bv_minor;
90 };
91 /* Current version number of filter architecture. */
92 #define BPF_MAJOR_VERSION 1
93 #define BPF_MINOR_VERSION 1
94 
95 /*
96  * Historically, BPF has supported a single buffering model, first using mbuf
97  * clusters in kernel, and later using malloc(9) buffers in kernel.  We now
98  * support multiple buffering modes, which may be queried and set using
99  * BIOCGETBUFMODE and BIOCSETBUFMODE.  So as to avoid handling the complexity
100  * of changing modes while sniffing packets, the mode becomes fixed once an
101  * interface has been attached to the BPF descriptor.
102  */
103 #define	BPF_BUFMODE_BUFFER	1	/* Kernel buffers with read(). */
104 #define	BPF_BUFMODE_ZBUF	2	/* Zero-copy buffers. */
105 
106 /*-
107  * Struct used by BIOCSETZBUF, BIOCROTZBUF: describes up to two zero-copy
108  * buffer as used by BPF.
109  */
110 struct bpf_zbuf {
111 	void	*bz_bufa;	/* Location of 'a' zero-copy buffer. */
112 	void	*bz_bufb;	/* Location of 'b' zero-copy buffer. */
113 	size_t	 bz_buflen;	/* Size of zero-copy buffers. */
114 };
115 
116 #define	BIOCGBLEN	_IOR('B',102, u_int)
117 #define	BIOCSBLEN	_IOWR('B',102, u_int)
118 #define	BIOCSETF	_IOW('B',103, struct bpf_program)
119 #define	BIOCFLUSH	_IO('B',104)
120 #define BIOCPROMISC	_IO('B',105)
121 #define	BIOCGDLT	_IOR('B',106, u_int)
122 #define BIOCGETIF	_IOR('B',107, struct ifreq)
123 #define BIOCSETIF	_IOW('B',108, struct ifreq)
124 #define BIOCSRTIMEOUT	_IOW('B',109, struct timeval)
125 #define BIOCGRTIMEOUT	_IOR('B',110, struct timeval)
126 #define BIOCGSTATS	_IOR('B',111, struct bpf_stat)
127 #define BIOCIMMEDIATE	_IOW('B',112, u_int)
128 #define BIOCVERSION	_IOR('B',113, struct bpf_version)
129 #define BIOCGRSIG	_IOR('B',114, u_int)
130 #define BIOCSRSIG	_IOW('B',115, u_int)
131 #define BIOCGHDRCMPLT	_IOR('B',116, u_int)
132 #define BIOCSHDRCMPLT	_IOW('B',117, u_int)
133 #define BIOCGDIRECTION	_IOR('B',118, u_int)
134 #define BIOCSDIRECTION	_IOW('B',119, u_int)
135 #define	BIOCSDLT	_IOW('B',120, u_int)
136 #define	BIOCGDLTLIST	_IOWR('B',121, struct bpf_dltlist)
137 #define	BIOCLOCK	_IO('B', 122)
138 #define	BIOCSETWF	_IOW('B',123, struct bpf_program)
139 #define	BIOCFEEDBACK	_IOW('B',124, u_int)
140 #define	BIOCGETBUFMODE	_IOR('B',125, u_int)
141 #define	BIOCSETBUFMODE	_IOW('B',126, u_int)
142 #define	BIOCGETZMAX	_IOR('B',127, size_t)
143 #define	BIOCROTZBUF	_IOR('B',128, struct bpf_zbuf)
144 #define	BIOCSETZBUF	_IOW('B',129, struct bpf_zbuf)
145 #define	BIOCSETFNR	_IOW('B',130, struct bpf_program)
146 
147 /* Obsolete */
148 #define	BIOCGSEESENT	BIOCGDIRECTION
149 #define	BIOCSSEESENT	BIOCSDIRECTION
150 
151 /* Packet directions */
152 enum bpf_direction {
153 	BPF_D_IN,	/* See incoming packets */
154 	BPF_D_INOUT,	/* See incoming and outgoing packets */
155 	BPF_D_OUT	/* See outgoing packets */
156 };
157 
158 /*
159  * Structure prepended to each packet.
160  */
161 struct bpf_hdr {
162 	struct timeval	bh_tstamp;	/* time stamp */
163 	bpf_u_int32	bh_caplen;	/* length of captured portion */
164 	bpf_u_int32	bh_datalen;	/* original length of packet */
165 	u_short		bh_hdrlen;	/* length of bpf header (this struct
166 					   plus alignment padding) */
167 };
168 /*
169  * Because the structure above is not a multiple of 4 bytes, some compilers
170  * will insist on inserting padding; hence, sizeof(struct bpf_hdr) won't work.
171  * Only the kernel needs to know about it; applications use bh_hdrlen.
172  */
173 #ifdef _KERNEL
174 #define	SIZEOF_BPF_HDR	(sizeof(struct bpf_hdr) <= 20 ? 18 : \
175     sizeof(struct bpf_hdr))
176 #endif
177 
178 /*
179  * When using zero-copy BPF buffers, a shared memory header is present
180  * allowing the kernel BPF implementation and user process to synchronize
181  * without using system calls.  This structure defines that header.  When
182  * accessing these fields, appropriate atomic operation and memory barriers
183  * are required in order not to see stale or out-of-order data; see bpf(4)
184  * for reference code to access these fields from userspace.
185  *
186  * The layout of this structure is critical, and must not be changed; if must
187  * fit in a single page on all architectures.
188  */
189 struct bpf_zbuf_header {
190 	volatile u_int	bzh_kernel_gen;	/* Kernel generation number. */
191 	volatile u_int	bzh_kernel_len;	/* Length of data in the buffer. */
192 	volatile u_int	bzh_user_gen;	/* User generation number. */
193 	u_int _bzh_pad[5];
194 };
195 
196 /*
197  * Data-link level type codes.
198  */
199 #define DLT_NULL	0	/* BSD loopback encapsulation */
200 #define DLT_EN10MB	1	/* Ethernet (10Mb) */
201 #define DLT_EN3MB	2	/* Experimental Ethernet (3Mb) */
202 #define DLT_AX25	3	/* Amateur Radio AX.25 */
203 #define DLT_PRONET	4	/* Proteon ProNET Token Ring */
204 #define DLT_CHAOS	5	/* Chaos */
205 #define DLT_IEEE802	6	/* IEEE 802 Networks */
206 #define DLT_ARCNET	7	/* ARCNET */
207 #define DLT_SLIP	8	/* Serial Line IP */
208 #define DLT_PPP		9	/* Point-to-point Protocol */
209 #define DLT_FDDI	10	/* FDDI */
210 #define DLT_ATM_RFC1483	11	/* LLC/SNAP encapsulated atm */
211 #define DLT_RAW		12	/* raw IP */
212 
213 /*
214  * These are values from BSD/OS's "bpf.h".
215  * These are not the same as the values from the traditional libpcap
216  * "bpf.h"; however, these values shouldn't be generated by any
217  * OS other than BSD/OS, so the correct values to use here are the
218  * BSD/OS values.
219  *
220  * Platforms that have already assigned these values to other
221  * DLT_ codes, however, should give these codes the values
222  * from that platform, so that programs that use these codes will
223  * continue to compile - even though they won't correctly read
224  * files of these types.
225  */
226 #define DLT_SLIP_BSDOS	15	/* BSD/OS Serial Line IP */
227 #define DLT_PPP_BSDOS	16	/* BSD/OS Point-to-point Protocol */
228 
229 #define DLT_ATM_CLIP	19	/* Linux Classical-IP over ATM */
230 
231 /*
232  * These values are defined by NetBSD; other platforms should refrain from
233  * using them for other purposes, so that NetBSD savefiles with link
234  * types of 50 or 51 can be read as this type on all platforms.
235  */
236 #define DLT_PPP_SERIAL	50	/* PPP over serial with HDLC encapsulation */
237 #define DLT_PPP_ETHER	51	/* PPP over Ethernet */
238 
239 /*
240  * Reserved for the Symantec Enterprise Firewall.
241  */
242 #define DLT_SYMANTEC_FIREWALL	99
243 
244 
245 /*
246  * This value was defined by libpcap 0.5; platforms that have defined
247  * it with a different value should define it here with that value -
248  * a link type of 104 in a save file will be mapped to DLT_C_HDLC,
249  * whatever value that happens to be, so programs will correctly
250  * handle files with that link type regardless of the value of
251  * DLT_C_HDLC.
252  *
253  * The name DLT_C_HDLC was used by BSD/OS; we use that name for source
254  * compatibility with programs written for BSD/OS.
255  *
256  * libpcap 0.5 defined it as DLT_CHDLC; we define DLT_CHDLC as well,
257  * for source compatibility with programs written for libpcap 0.5.
258  */
259 #define DLT_C_HDLC	104	/* Cisco HDLC */
260 #define DLT_CHDLC	DLT_C_HDLC
261 
262 #define DLT_IEEE802_11	105	/* IEEE 802.11 wireless */
263 
264 /*
265  * Values between 106 and 107 are used in capture file headers as
266  * link-layer types corresponding to DLT_ types that might differ
267  * between platforms; don't use those values for new DLT_ new types.
268  */
269 
270 /*
271  * Frame Relay; BSD/OS has a DLT_FR with a value of 11, but that collides
272  * with other values.
273  * DLT_FR and DLT_FRELAY packets start with the Q.922 Frame Relay header
274  * (DLCI, etc.).
275  */
276 #define DLT_FRELAY	107
277 
278 /*
279  * OpenBSD DLT_LOOP, for loopback devices; it's like DLT_NULL, except
280  * that the AF_ type in the link-layer header is in network byte order.
281  *
282  * OpenBSD defines it as 12, but that collides with DLT_RAW, so we
283  * define it as 108 here.  If OpenBSD picks up this file, it should
284  * define DLT_LOOP as 12 in its version, as per the comment above -
285  * and should not use 108 as a DLT_ value.
286  */
287 #define DLT_LOOP	108
288 
289 /*
290  * Values between 109 and 112 are used in capture file headers as
291  * link-layer types corresponding to DLT_ types that might differ
292  * between platforms; don't use those values for new DLT_ new types.
293  */
294 
295 /*
296  * Encapsulated packets for IPsec; DLT_ENC is 13 in OpenBSD, but that's
297  * DLT_SLIP_BSDOS in NetBSD, so we don't use 13 for it in OSes other
298  * than OpenBSD.
299  */
300 #define DLT_ENC	109
301 
302 /*
303  * This is for Linux cooked sockets.
304  */
305 #define DLT_LINUX_SLL	113
306 
307 /*
308  * Apple LocalTalk hardware.
309  */
310 #define DLT_LTALK	114
311 
312 /*
313  * Acorn Econet.
314  */
315 #define DLT_ECONET	115
316 
317 /*
318  * Reserved for use with OpenBSD ipfilter.
319  */
320 #define DLT_IPFILTER	116
321 
322 /*
323  * Reserved for use in capture-file headers as a link-layer type
324  * corresponding to OpenBSD DLT_PFLOG; DLT_PFLOG is 17 in OpenBSD,
325  * but that's DLT_LANE8023 in SuSE 6.3, so we can't use 17 for it
326  * in capture-file headers.
327  */
328 #define DLT_PFLOG	117
329 
330 /*
331  * Registered for Cisco-internal use.
332  */
333 #define DLT_CISCO_IOS	118
334 
335 /*
336  * Reserved for 802.11 cards using the Prism II chips, with a link-layer
337  * header including Prism monitor mode information plus an 802.11
338  * header.
339  */
340 #define DLT_PRISM_HEADER	119
341 
342 /*
343  * Reserved for Aironet 802.11 cards, with an Aironet link-layer header
344  * (see Doug Ambrisko's FreeBSD patches).
345  */
346 #define DLT_AIRONET_HEADER	120
347 
348 /*
349  * Reserved for use by OpenBSD's pfsync device.
350  */
351 #define DLT_PFSYNC	121
352 
353 /*
354  * Reserved for Siemens HiPath HDLC. XXX
355  */
356 #define DLT_HHDLC	121
357 
358 /*
359  * Reserved for RFC 2625 IP-over-Fibre Channel.
360  */
361 #define DLT_IP_OVER_FC	122
362 
363 /*
364  * Reserved for Full Frontal ATM on Solaris.
365  */
366 #define DLT_SUNATM	123
367 
368 /*
369  * Reserved as per request from Kent Dahlgren <kent@praesum.com>
370  * for private use.
371  */
372 #define DLT_RIO		124	/* RapidIO */
373 #define DLT_PCI_EXP	125	/* PCI Express */
374 #define DLT_AURORA	126	/* Xilinx Aurora link layer */
375 
376 /*
377  * BSD header for 802.11 plus a number of bits of link-layer information
378  * including radio information.
379  */
380 #ifndef DLT_IEEE802_11_RADIO
381 #define DLT_IEEE802_11_RADIO	127
382 #endif
383 
384 /*
385  * Reserved for TZSP encapsulation.
386  */
387 #define DLT_TZSP		128	/* Tazmen Sniffer Protocol */
388 
389 /*
390  * Reserved for Linux ARCNET.
391  */
392 #define DLT_ARCNET_LINUX	129
393 
394 /*
395  * Juniper-private data link types.
396  */
397 #define DLT_JUNIPER_MLPPP	130
398 #define DLT_JUNIPER_MLFR	131
399 #define DLT_JUNIPER_ES		132
400 #define DLT_JUNIPER_GGSN	133
401 #define DLT_JUNIPER_MFR		134
402 #define DLT_JUNIPER_ATM2	135
403 #define DLT_JUNIPER_SERVICES	136
404 #define DLT_JUNIPER_ATM1	137
405 
406 /*
407  * Apple IP-over-IEEE 1394, as per a request from Dieter Siegmund
408  * <dieter@apple.com>.  The header that's presented is an Ethernet-like
409  * header:
410  *
411  *	#define FIREWIRE_EUI64_LEN	8
412  *	struct firewire_header {
413  *		u_char  firewire_dhost[FIREWIRE_EUI64_LEN];
414  *		u_char  firewire_shost[FIREWIRE_EUI64_LEN];
415  *		u_short firewire_type;
416  *	};
417  *
418  * with "firewire_type" being an Ethernet type value, rather than,
419  * for example, raw GASP frames being handed up.
420  */
421 #define DLT_APPLE_IP_OVER_IEEE1394	138
422 
423 /*
424  * Various SS7 encapsulations, as per a request from Jeff Morriss
425  * <jeff.morriss[AT]ulticom.com> and subsequent discussions.
426  */
427 #define DLT_MTP2_WITH_PHDR	139	/* pseudo-header with various info, followed by MTP2 */
428 #define DLT_MTP2		140	/* MTP2, without pseudo-header */
429 #define DLT_MTP3		141	/* MTP3, without pseudo-header or MTP2 */
430 #define DLT_SCCP		142	/* SCCP, without pseudo-header or MTP2 or MTP3 */
431 
432 /*
433  * Reserved for DOCSIS.
434  */
435 #define DLT_DOCSIS	143
436 
437 /*
438  * Reserved for Linux IrDA.
439  */
440 #define DLT_LINUX_IRDA	144
441 
442 /*
443  * Reserved for IBM SP switch and IBM Next Federation switch.
444  */
445 #define DLT_IBM_SP	145
446 #define DLT_IBM_SN	146
447 
448 /*
449  * Reserved for private use.  If you have some link-layer header type
450  * that you want to use within your organization, with the capture files
451  * using that link-layer header type not ever be sent outside your
452  * organization, you can use these values.
453  *
454  * No libpcap release will use these for any purpose, nor will any
455  * tcpdump release use them, either.
456  *
457  * Do *NOT* use these in capture files that you expect anybody not using
458  * your private versions of capture-file-reading tools to read; in
459  * particular, do *NOT* use them in products, otherwise you may find that
460  * people won't be able to use tcpdump, or snort, or Ethereal, or... to
461  * read capture files from your firewall/intrusion detection/traffic
462  * monitoring/etc. appliance, or whatever product uses that DLT_ value,
463  * and you may also find that the developers of those applications will
464  * not accept patches to let them read those files.
465  *
466  * Also, do not use them if somebody might send you a capture using them
467  * for *their* private type and tools using them for *your* private type
468  * would have to read them.
469  *
470  * Instead, ask "tcpdump-workers@tcpdump.org" for a new DLT_ value,
471  * as per the comment above, and use the type you're given.
472  */
473 #define DLT_USER0		147
474 #define DLT_USER1		148
475 #define DLT_USER2		149
476 #define DLT_USER3		150
477 #define DLT_USER4		151
478 #define DLT_USER5		152
479 #define DLT_USER6		153
480 #define DLT_USER7		154
481 #define DLT_USER8		155
482 #define DLT_USER9		156
483 #define DLT_USER10		157
484 #define DLT_USER11		158
485 #define DLT_USER12		159
486 #define DLT_USER13		160
487 #define DLT_USER14		161
488 #define DLT_USER15		162
489 
490 /*
491  * For future use with 802.11 captures - defined by AbsoluteValue
492  * Systems to store a number of bits of link-layer information
493  * including radio information:
494  *
495  *	http://www.shaftnet.org/~pizza/software/capturefrm.txt
496  *
497  * but it might be used by some non-AVS drivers now or in the
498  * future.
499  */
500 #define DLT_IEEE802_11_RADIO_AVS 163	/* 802.11 plus AVS radio header */
501 
502 /*
503  * Juniper-private data link type, as per request from
504  * Hannes Gredler <hannes@juniper.net>.  The DLT_s are used
505  * for passing on chassis-internal metainformation such as
506  * QOS profiles, etc..
507  */
508 #define DLT_JUNIPER_MONITOR     164
509 
510 /*
511  * Reserved for BACnet MS/TP.
512  */
513 #define DLT_BACNET_MS_TP	165
514 
515 /*
516  * Another PPP variant as per request from Karsten Keil <kkeil@suse.de>.
517  *
518  * This is used in some OSes to allow a kernel socket filter to distinguish
519  * between incoming and outgoing packets, on a socket intended to
520  * supply pppd with outgoing packets so it can do dial-on-demand and
521  * hangup-on-lack-of-demand; incoming packets are filtered out so they
522  * don't cause pppd to hold the connection up (you don't want random
523  * input packets such as port scans, packets from old lost connections,
524  * etc. to force the connection to stay up).
525  *
526  * The first byte of the PPP header (0xff03) is modified to accomodate
527  * the direction - 0x00 = IN, 0x01 = OUT.
528  */
529 #define DLT_PPP_PPPD		166
530 
531 /*
532  * Names for backwards compatibility with older versions of some PPP
533  * software; new software should use DLT_PPP_PPPD.
534  */
535 #define DLT_PPP_WITH_DIRECTION	DLT_PPP_PPPD
536 #define DLT_LINUX_PPP_WITHDIRECTION	DLT_PPP_PPPD
537 
538 /*
539  * Juniper-private data link type, as per request from
540  * Hannes Gredler <hannes@juniper.net>.  The DLT_s are used
541  * for passing on chassis-internal metainformation such as
542  * QOS profiles, cookies, etc..
543  */
544 #define DLT_JUNIPER_PPPOE       167
545 #define DLT_JUNIPER_PPPOE_ATM   168
546 
547 #define DLT_GPRS_LLC		169	/* GPRS LLC */
548 #define DLT_GPF_T		170	/* GPF-T (ITU-T G.7041/Y.1303) */
549 #define DLT_GPF_F		171	/* GPF-F (ITU-T G.7041/Y.1303) */
550 
551 /*
552  * Requested by Oolan Zimmer <oz@gcom.com> for use in Gcom's T1/E1 line
553  * monitoring equipment.
554  */
555 #define DLT_GCOM_T1E1		172
556 #define DLT_GCOM_SERIAL		173
557 
558 /*
559  * Juniper-private data link type, as per request from
560  * Hannes Gredler <hannes@juniper.net>.  The DLT_ is used
561  * for internal communication to Physical Interface Cards (PIC)
562  */
563 #define DLT_JUNIPER_PIC_PEER    174
564 
565 /*
566  * Link types requested by Gregor Maier <gregor@endace.com> of Endace
567  * Measurement Systems.  They add an ERF header (see
568  * http://www.endace.com/support/EndaceRecordFormat.pdf) in front of
569  * the link-layer header.
570  */
571 #define DLT_ERF_ETH		175	/* Ethernet */
572 #define DLT_ERF_POS		176	/* Packet-over-SONET */
573 
574 /*
575  * Requested by Daniele Orlandi <daniele@orlandi.com> for raw LAPD
576  * for vISDN (http://www.orlandi.com/visdn/).  Its link-layer header
577  * includes additional information before the LAPD header, so it's
578  * not necessarily a generic LAPD header.
579  */
580 #define DLT_LINUX_LAPD		177
581 
582 /*
583  * Juniper-private data link type, as per request from
584  * Hannes Gredler <hannes@juniper.net>.
585  * The DLT_ are used for prepending meta-information
586  * like interface index, interface name
587  * before standard Ethernet, PPP, Frelay & C-HDLC Frames
588  */
589 #define DLT_JUNIPER_ETHER       178
590 #define DLT_JUNIPER_PPP         179
591 #define DLT_JUNIPER_FRELAY      180
592 #define DLT_JUNIPER_CHDLC       181
593 
594 /*
595  * Multi Link Frame Relay (FRF.16)
596  */
597 #define DLT_MFR                 182
598 
599 /*
600  * Juniper-private data link type, as per request from
601  * Hannes Gredler <hannes@juniper.net>.
602  * The DLT_ is used for internal communication with a
603  * voice Adapter Card (PIC)
604  */
605 #define DLT_JUNIPER_VP          183
606 
607 /*
608  * Arinc 429 frames.
609  * DLT_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>.
610  * Every frame contains a 32bit A429 label.
611  * More documentation on Arinc 429 can be found at
612  * http://www.condoreng.com/support/downloads/tutorials/ARINCTutorial.pdf
613  */
614 #define DLT_A429                184
615 
616 /*
617  * Arinc 653 Interpartition Communication messages.
618  * DLT_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>.
619  * Please refer to the A653-1 standard for more information.
620  */
621 #define DLT_A653_ICM            185
622 
623 /*
624  * USB packets, beginning with a USB setup header; requested by
625  * Paolo Abeni <paolo.abeni@email.it>.
626  */
627 #define DLT_USB			186
628 
629 /*
630  * Bluetooth HCI UART transport layer (part H:4); requested by
631  * Paolo Abeni.
632  */
633 #define DLT_BLUETOOTH_HCI_H4	187
634 
635 /*
636  * IEEE 802.16 MAC Common Part Sublayer; requested by Maria Cruz
637  * <cruz_petagay@bah.com>.
638  */
639 #define DLT_IEEE802_16_MAC_CPS	188
640 
641 /*
642  * USB packets, beginning with a Linux USB header; requested by
643  * Paolo Abeni <paolo.abeni@email.it>.
644  */
645 #define DLT_USB_LINUX		189
646 
647 /*
648  * Controller Area Network (CAN) v. 2.0B packets.
649  * DLT_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>.
650  * Used to dump CAN packets coming from a CAN Vector board.
651  * More documentation on the CAN v2.0B frames can be found at
652  * http://www.can-cia.org/downloads/?269
653  */
654 #define DLT_CAN20B              190
655 
656 /*
657  * IEEE 802.15.4, with address fields padded, as is done by Linux
658  * drivers; requested by Juergen Schimmer.
659  */
660 #define DLT_IEEE802_15_4_LINUX	191
661 
662 /*
663  * Per Packet Information encapsulated packets.
664  * DLT_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>.
665  */
666 #define DLT_PPI			192
667 
668 /*
669  * Header for 802.16 MAC Common Part Sublayer plus a radiotap radio header;
670  * requested by Charles Clancy.
671  */
672 #define DLT_IEEE802_16_MAC_CPS_RADIO	193
673 
674 /*
675  * Juniper-private data link type, as per request from
676  * Hannes Gredler <hannes@juniper.net>.
677  * The DLT_ is used for internal communication with a
678  * integrated service module (ISM).
679  */
680 #define DLT_JUNIPER_ISM         194
681 
682 /*
683  * IEEE 802.15.4, exactly as it appears in the spec (no padding, no
684  * nothing); requested by Mikko Saarnivala <mikko.saarnivala@sensinode.com>.
685  */
686 #define DLT_IEEE802_15_4	195
687 
688 /*
689  * Various link-layer types, with a pseudo-header, for SITA
690  * (http://www.sita.aero/); requested by Fulko Hew (fulko.hew@gmail.com).
691  */
692 #define DLT_SITA		196
693 
694 /*
695  * Various link-layer types, with a pseudo-header, for Endace DAG cards;
696  * encapsulates Endace ERF records.  Requested by Stephen Donnelly
697  * <stephen@endace.com>.
698  */
699 #define DLT_ERF			197
700 
701 /*
702  * Special header prepended to Ethernet packets when capturing from a
703  * u10 Networks board.  Requested by Phil Mulholland
704  * <phil@u10networks.com>.
705  */
706 #define DLT_RAIF1		198
707 
708 /*
709  * IPMB packet for IPMI, beginning with the I2C slave address, followed
710  * by the netFn and LUN, etc..  Requested by Chanthy Toeung
711  * <chanthy.toeung@ca.kontron.com>.
712  */
713 #define DLT_IPMB		199
714 
715 /*
716  * Juniper-private data link type, as per request from
717  * Hannes Gredler <hannes@juniper.net>.
718  * The DLT_ is used for capturing data on a secure tunnel interface.
719  */
720 #define DLT_JUNIPER_ST          200
721 
722 /*
723  * Bluetooth HCI UART transport layer (part H:4), with pseudo-header
724  * that includes direction information; requested by Paolo Abeni.
725  */
726 #define DLT_BLUETOOTH_HCI_H4_WITH_PHDR	201
727 
728 /*
729  * The instruction encodings.
730  */
731 /* instruction classes */
732 #define BPF_CLASS(code) ((code) & 0x07)
733 #define		BPF_LD		0x00
734 #define		BPF_LDX		0x01
735 #define		BPF_ST		0x02
736 #define		BPF_STX		0x03
737 #define		BPF_ALU		0x04
738 #define		BPF_JMP		0x05
739 #define		BPF_RET		0x06
740 #define		BPF_MISC	0x07
741 
742 /* ld/ldx fields */
743 #define BPF_SIZE(code)	((code) & 0x18)
744 #define		BPF_W		0x00
745 #define		BPF_H		0x08
746 #define		BPF_B		0x10
747 #define BPF_MODE(code)	((code) & 0xe0)
748 #define		BPF_IMM 	0x00
749 #define		BPF_ABS		0x20
750 #define		BPF_IND		0x40
751 #define		BPF_MEM		0x60
752 #define		BPF_LEN		0x80
753 #define		BPF_MSH		0xa0
754 
755 /* alu/jmp fields */
756 #define BPF_OP(code)	((code) & 0xf0)
757 #define		BPF_ADD		0x00
758 #define		BPF_SUB		0x10
759 #define		BPF_MUL		0x20
760 #define		BPF_DIV		0x30
761 #define		BPF_OR		0x40
762 #define		BPF_AND		0x50
763 #define		BPF_LSH		0x60
764 #define		BPF_RSH		0x70
765 #define		BPF_NEG		0x80
766 #define		BPF_JA		0x00
767 #define		BPF_JEQ		0x10
768 #define		BPF_JGT		0x20
769 #define		BPF_JGE		0x30
770 #define		BPF_JSET	0x40
771 #define BPF_SRC(code)	((code) & 0x08)
772 #define		BPF_K		0x00
773 #define		BPF_X		0x08
774 
775 /* ret - BPF_K and BPF_X also apply */
776 #define BPF_RVAL(code)	((code) & 0x18)
777 #define		BPF_A		0x10
778 
779 /* misc */
780 #define BPF_MISCOP(code) ((code) & 0xf8)
781 #define		BPF_TAX		0x00
782 #define		BPF_TXA		0x80
783 
784 /*
785  * The instruction data structure.
786  */
787 struct bpf_insn {
788 	u_short		code;
789 	u_char		jt;
790 	u_char		jf;
791 	bpf_u_int32	k;
792 };
793 
794 /*
795  * Macros for insn array initializers.
796  */
797 #define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
798 #define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
799 
800 /*
801  * Structure to retrieve available DLTs for the interface.
802  */
803 struct bpf_dltlist {
804 	u_int	bfl_len;	/* number of bfd_list array */
805 	u_int	*bfl_list;	/* array of DLTs */
806 };
807 
808 #ifdef _KERNEL
809 #ifdef MALLOC_DECLARE
810 MALLOC_DECLARE(M_BPF);
811 #endif
812 #ifdef SYSCTL_DECL
813 SYSCTL_DECL(_net_bpf);
814 #endif
815 
816 /*
817  * Rotate the packet buffers in descriptor d.  Move the store buffer into the
818  * hold slot, and the free buffer ino the store slot.  Zero the length of the
819  * new store buffer.  Descriptor lock should be held.
820  */
821 #define	ROTATE_BUFFERS(d)	do {					\
822 	(d)->bd_hbuf = (d)->bd_sbuf;					\
823 	(d)->bd_hlen = (d)->bd_slen;					\
824 	(d)->bd_sbuf = (d)->bd_fbuf;					\
825 	(d)->bd_slen = 0;						\
826 	(d)->bd_fbuf = NULL;						\
827 	bpf_bufheld(d);							\
828 } while (0)
829 
830 /*
831  * Descriptor associated with each attached hardware interface.
832  */
833 struct bpf_if {
834 	LIST_ENTRY(bpf_if)	bif_next;	/* list of all interfaces */
835 	LIST_HEAD(, bpf_d)	bif_dlist;	/* descriptor list */
836 	u_int bif_dlt;				/* link layer type */
837 	u_int bif_hdrlen;		/* length of header (with padding) */
838 	struct ifnet *bif_ifp;		/* corresponding interface */
839 	struct mtx	bif_mtx;	/* mutex for interface */
840 };
841 
842 void	 bpf_bufheld(struct bpf_d *d);
843 int	 bpf_validate(const struct bpf_insn *, int);
844 void	 bpf_tap(struct bpf_if *, u_char *, u_int);
845 void	 bpf_mtap(struct bpf_if *, struct mbuf *);
846 void	 bpf_mtap2(struct bpf_if *, void *, u_int, struct mbuf *);
847 void	 bpfattach(struct ifnet *, u_int, u_int);
848 void	 bpfattach2(struct ifnet *, u_int, u_int, struct bpf_if **);
849 void	 bpfdetach(struct ifnet *);
850 
851 void	 bpfilterattach(int);
852 u_int	 bpf_filter(const struct bpf_insn *, u_char *, u_int, u_int);
853 
854 static __inline int
855 bpf_peers_present(struct bpf_if *bpf)
856 {
857 
858 	if (!LIST_EMPTY(&bpf->bif_dlist))
859 		return (1);
860 	return (0);
861 }
862 
863 #define	BPF_TAP(_ifp,_pkt,_pktlen) do {				\
864 	if (bpf_peers_present((_ifp)->if_bpf))			\
865 		bpf_tap((_ifp)->if_bpf, (_pkt), (_pktlen));	\
866 } while (0)
867 #define	BPF_MTAP(_ifp,_m) do {					\
868 	if (bpf_peers_present((_ifp)->if_bpf)) {		\
869 		M_ASSERTVALID(_m);				\
870 		bpf_mtap((_ifp)->if_bpf, (_m));			\
871 	}							\
872 } while (0)
873 #define	BPF_MTAP2(_ifp,_data,_dlen,_m) do {			\
874 	if (bpf_peers_present((_ifp)->if_bpf)) {		\
875 		M_ASSERTVALID(_m);				\
876 		bpf_mtap2((_ifp)->if_bpf,(_data),(_dlen),(_m));	\
877 	}							\
878 } while (0)
879 #endif
880 
881 /*
882  * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
883  */
884 #define BPF_MEMWORDS 16
885 
886 #endif /* _NET_BPF_H_ */
887