xref: /netbsd-src/external/bsd/libpcap/dist/pcap/sll.h (revision 8bda04910f1f2c366c51d4cbd40df19f5b57f1dd)
1*8bda0491Schristos /*	$NetBSD: sll.h,v 1.6 2024/09/02 15:33:39 christos Exp $	*/
2d9186219Schristos 
3bf1df6d1Schristos /*-
4bf1df6d1Schristos  * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
5bf1df6d1Schristos  *	The Regents of the University of California.  All rights reserved.
6bf1df6d1Schristos  *
7bf1df6d1Schristos  * This code is derived from the Stanford/CMU enet packet filter,
8bf1df6d1Schristos  * (net/enet.c) distributed as part of 4.3BSD, and code contributed
9bf1df6d1Schristos  * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
10bf1df6d1Schristos  * Berkeley Laboratory.
11bf1df6d1Schristos  *
12bf1df6d1Schristos  * Redistribution and use in source and binary forms, with or without
13bf1df6d1Schristos  * modification, are permitted provided that the following conditions
14bf1df6d1Schristos  * are met:
15bf1df6d1Schristos  * 1. Redistributions of source code must retain the above copyright
16bf1df6d1Schristos  *    notice, this list of conditions and the following disclaimer.
17bf1df6d1Schristos  * 2. Redistributions in binary form must reproduce the above copyright
18bf1df6d1Schristos  *    notice, this list of conditions and the following disclaimer in the
19bf1df6d1Schristos  *    documentation and/or other materials provided with the distribution.
20bf1df6d1Schristos  * 3. All advertising materials mentioning features or use of this software
21bf1df6d1Schristos  *    must display the following acknowledgement:
22bf1df6d1Schristos  *      This product includes software developed by the University of
23bf1df6d1Schristos  *      California, Berkeley and its contributors.
24bf1df6d1Schristos  * 4. Neither the name of the University nor the names of its contributors
25bf1df6d1Schristos  *    may be used to endorse or promote products derived from this software
26bf1df6d1Schristos  *    without specific prior written permission.
27bf1df6d1Schristos  *
28bf1df6d1Schristos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29bf1df6d1Schristos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30bf1df6d1Schristos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31bf1df6d1Schristos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32bf1df6d1Schristos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33bf1df6d1Schristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34bf1df6d1Schristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35bf1df6d1Schristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36bf1df6d1Schristos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37bf1df6d1Schristos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38bf1df6d1Schristos  * SUCH DAMAGE.
39bf1df6d1Schristos  */
40bf1df6d1Schristos 
41bf1df6d1Schristos /*
42bf1df6d1Schristos  * For captures on Linux cooked sockets, we construct a fake header
43bf1df6d1Schristos  * that includes:
44bf1df6d1Schristos  *
45bf1df6d1Schristos  *	a 2-byte "packet type" which is one of:
46bf1df6d1Schristos  *
47bf1df6d1Schristos  *		LINUX_SLL_HOST		packet was sent to us
48bf1df6d1Schristos  *		LINUX_SLL_BROADCAST	packet was broadcast
49bf1df6d1Schristos  *		LINUX_SLL_MULTICAST	packet was multicast
50bf1df6d1Schristos  *		LINUX_SLL_OTHERHOST	packet was sent to somebody else
51bf1df6d1Schristos  *		LINUX_SLL_OUTGOING	packet was sent *by* us;
52bf1df6d1Schristos  *
53bf1df6d1Schristos  *	a 2-byte Ethernet protocol field;
54bf1df6d1Schristos  *
55bf1df6d1Schristos  *	a 2-byte link-layer type;
56bf1df6d1Schristos  *
57bf1df6d1Schristos  *	a 2-byte link-layer address length;
58bf1df6d1Schristos  *
59bf1df6d1Schristos  *	an 8-byte source link-layer address, whose actual length is
60bf1df6d1Schristos  *	specified by the previous value.
61bf1df6d1Schristos  *
62bf1df6d1Schristos  * All fields except for the link-layer address are in network byte order.
63bf1df6d1Schristos  *
64bf1df6d1Schristos  * DO NOT change the layout of this structure, or change any of the
65bf1df6d1Schristos  * LINUX_SLL_ values below.  If you must change the link-layer header
66bf1df6d1Schristos  * for a "cooked" Linux capture, introduce a new DLT_ type (ask
67bf1df6d1Schristos  * "tcpdump-workers@lists.tcpdump.org" for one, so that you don't give it
68bf1df6d1Schristos  * a value that collides with a value already being used), and use the
69bf1df6d1Schristos  * new header in captures of that type, so that programs that can
70bf1df6d1Schristos  * handle DLT_LINUX_SLL captures will continue to handle them correctly
71bf1df6d1Schristos  * without any change, and so that capture files with different headers
72bf1df6d1Schristos  * can be told apart and programs that read them can dissect the
73bf1df6d1Schristos  * packets in them.
74bf1df6d1Schristos  */
75bf1df6d1Schristos 
76bf1df6d1Schristos #ifndef lib_pcap_sll_h
77bf1df6d1Schristos #define lib_pcap_sll_h
78bf1df6d1Schristos 
79bb746009Schristos #include <pcap/pcap-inttypes.h>
80bb746009Schristos 
81bf1df6d1Schristos /*
82bf1df6d1Schristos  * A DLT_LINUX_SLL fake link-layer header.
83bf1df6d1Schristos  */
84bf1df6d1Schristos #define SLL_HDR_LEN	16		/* total header length */
85bf1df6d1Schristos #define SLL_ADDRLEN	8		/* length of address field */
86bf1df6d1Schristos 
87bf1df6d1Schristos struct sll_header {
883b604290Schristos 	uint16_t sll_pkttype;		/* packet type */
893b604290Schristos 	uint16_t sll_hatype;		/* link-layer address type */
903b604290Schristos 	uint16_t sll_halen;		/* link-layer address length */
913b604290Schristos 	uint8_t  sll_addr[SLL_ADDRLEN];	/* link-layer address */
923b604290Schristos 	uint16_t sll_protocol;		/* protocol */
93bf1df6d1Schristos };
94bf1df6d1Schristos 
95bf1df6d1Schristos /*
96bb746009Schristos  * A DLT_LINUX_SLL2 fake link-layer header.
97bb746009Schristos  */
98bb746009Schristos #define SLL2_HDR_LEN	20		/* total header length */
99bb746009Schristos 
100bb746009Schristos struct sll2_header {
101bb746009Schristos 	uint16_t sll2_protocol;			/* protocol */
102bb746009Schristos 	uint16_t sll2_reserved_mbz;		/* reserved - must be zero */
103bb746009Schristos 	uint32_t sll2_if_index;			/* 1-based interface index */
104bb746009Schristos 	uint16_t sll2_hatype;			/* link-layer address type */
105bb746009Schristos 	uint8_t  sll2_pkttype;			/* packet type */
106bb746009Schristos 	uint8_t  sll2_halen;			/* link-layer address length */
107bb746009Schristos 	uint8_t  sll2_addr[SLL_ADDRLEN];	/* link-layer address */
108bb746009Schristos };
109bb746009Schristos 
110bb746009Schristos /*
111bb746009Schristos  * The LINUX_SLL_ values for "sll_pkttype" and LINUX_SLL2_ values for
112bb746009Schristos  * "sll2_pkttype"; these correspond to the PACKET_ values on Linux,
113bb746009Schristos  * which are defined by a header under include/uapi in the current
114bb746009Schristos  * kernel source, and are thus not going to change on Linux.  We
115bb746009Schristos  * define them here so that they're available even on systems other
116bb746009Schristos  * than Linux.
117bf1df6d1Schristos  */
118bf1df6d1Schristos #define LINUX_SLL_HOST		0
119bf1df6d1Schristos #define LINUX_SLL_BROADCAST	1
120bf1df6d1Schristos #define LINUX_SLL_MULTICAST	2
121bf1df6d1Schristos #define LINUX_SLL_OTHERHOST	3
122bf1df6d1Schristos #define LINUX_SLL_OUTGOING	4
123bf1df6d1Schristos 
124bf1df6d1Schristos /*
125bb746009Schristos  * The LINUX_SLL_ values for "sll_protocol" and LINUX_SLL2_ values for
126bb746009Schristos  * "sll2_protocol"; these correspond to the ETH_P_ values on Linux, but
127bb746009Schristos  * are defined here so that they're available even on systems other than
128bb746009Schristos  * Linux.  We assume, for now, that the ETH_P_ values won't change in
129bb746009Schristos  * Linux; if they do, then:
130bf1df6d1Schristos  *
131bf1df6d1Schristos  *	if we don't translate them in "pcap-linux.c", capture files
132bf1df6d1Schristos  *	won't necessarily be readable if captured on a system that
133bf1df6d1Schristos  *	defines ETH_P_ values that don't match these values;
134bf1df6d1Schristos  *
135bf1df6d1Schristos  *	if we do translate them in "pcap-linux.c", that makes life
136bf1df6d1Schristos  *	unpleasant for the BPF code generator, as the values you test
137bf1df6d1Schristos  *	for in the kernel aren't the values that you test for when
138bf1df6d1Schristos  *	reading a capture file, so the fixup code run on BPF programs
139bf1df6d1Schristos  *	handed to the kernel ends up having to do more work.
140bf1df6d1Schristos  *
141bf1df6d1Schristos  * Add other values here as necessary, for handling packet types that
142bf1df6d1Schristos  * might show up on non-Ethernet, non-802.x networks.  (Not all the ones
143bf1df6d1Schristos  * in the Linux "if_ether.h" will, I suspect, actually show up in
144bf1df6d1Schristos  * captures.)
145bf1df6d1Schristos  */
146bf1df6d1Schristos #define LINUX_SLL_P_802_3	0x0001	/* Novell 802.3 frames without 802.2 LLC header */
147bf1df6d1Schristos #define LINUX_SLL_P_802_2	0x0004	/* 802.2 frames (not D/I/X Ethernet) */
148db7feebfSchristos #define LINUX_SLL_P_CAN		0x000C	/* CAN frames, with SocketCAN pseudo-headers */
149db7feebfSchristos #define LINUX_SLL_P_CANFD	0x000D	/* CAN FD frames, with SocketCAN pseudo-headers */
150*8bda0491Schristos #define LINUX_SLL_P_CANXL	0x000E	/* CAN XL frames, with SocketCAN pseudo-headers */
151bf1df6d1Schristos 
152bf1df6d1Schristos #endif
153