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