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