sll.h revision 335640
1335640Shselasky/*-
2335640Shselasky * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3335640Shselasky *	The Regents of the University of California.  All rights reserved.
4335640Shselasky *
5335640Shselasky * This code is derived from the Stanford/CMU enet packet filter,
6335640Shselasky * (net/enet.c) distributed as part of 4.3BSD, and code contributed
7335640Shselasky * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
8335640Shselasky * Berkeley Laboratory.
9335640Shselasky *
10335640Shselasky * Redistribution and use in source and binary forms, with or without
11335640Shselasky * modification, are permitted provided that the following conditions
12335640Shselasky * are met:
13335640Shselasky * 1. Redistributions of source code must retain the above copyright
14335640Shselasky *    notice, this list of conditions and the following disclaimer.
15335640Shselasky * 2. Redistributions in binary form must reproduce the above copyright
16335640Shselasky *    notice, this list of conditions and the following disclaimer in the
17335640Shselasky *    documentation and/or other materials provided with the distribution.
18335640Shselasky * 3. All advertising materials mentioning features or use of this software
19335640Shselasky *    must display the following acknowledgement:
20335640Shselasky *      This product includes software developed by the University of
21335640Shselasky *      California, Berkeley and its contributors.
22335640Shselasky * 4. Neither the name of the University nor the names of its contributors
23335640Shselasky *    may be used to endorse or promote products derived from this software
24335640Shselasky *    without specific prior written permission.
25335640Shselasky *
26335640Shselasky * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27335640Shselasky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28335640Shselasky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29335640Shselasky * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30335640Shselasky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31335640Shselasky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32335640Shselasky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33335640Shselasky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34335640Shselasky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35335640Shselasky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36335640Shselasky * SUCH DAMAGE.
37335640Shselasky */
38335640Shselasky
39335640Shselasky/*
40335640Shselasky * For captures on Linux cooked sockets, we construct a fake header
41335640Shselasky * that includes:
42335640Shselasky *
43335640Shselasky *	a 2-byte "packet type" which is one of:
44335640Shselasky *
45335640Shselasky *		LINUX_SLL_HOST		packet was sent to us
46335640Shselasky *		LINUX_SLL_BROADCAST	packet was broadcast
47335640Shselasky *		LINUX_SLL_MULTICAST	packet was multicast
48335640Shselasky *		LINUX_SLL_OTHERHOST	packet was sent to somebody else
49335640Shselasky *		LINUX_SLL_OUTGOING	packet was sent *by* us;
50335640Shselasky *
51335640Shselasky *	a 2-byte Ethernet protocol field;
52335640Shselasky *
53335640Shselasky *	a 2-byte link-layer type;
54335640Shselasky *
55335640Shselasky *	a 2-byte link-layer address length;
56335640Shselasky *
57335640Shselasky *	an 8-byte source link-layer address, whose actual length is
58335640Shselasky *	specified by the previous value.
59335640Shselasky *
60335640Shselasky * All fields except for the link-layer address are in network byte order.
61335640Shselasky *
62335640Shselasky * DO NOT change the layout of this structure, or change any of the
63335640Shselasky * LINUX_SLL_ values below.  If you must change the link-layer header
64335640Shselasky * for a "cooked" Linux capture, introduce a new DLT_ type (ask
65335640Shselasky * "tcpdump-workers@lists.tcpdump.org" for one, so that you don't give it
66335640Shselasky * a value that collides with a value already being used), and use the
67335640Shselasky * new header in captures of that type, so that programs that can
68335640Shselasky * handle DLT_LINUX_SLL captures will continue to handle them correctly
69335640Shselasky * without any change, and so that capture files with different headers
70335640Shselasky * can be told apart and programs that read them can dissect the
71335640Shselasky * packets in them.
72335640Shselasky */
73335640Shselasky
74335640Shselasky#ifndef lib_pcap_sll_h
75335640Shselasky#define lib_pcap_sll_h
76335640Shselasky
77335640Shselasky/*
78335640Shselasky * A DLT_LINUX_SLL fake link-layer header.
79335640Shselasky */
80335640Shselasky#define SLL_HDR_LEN	16		/* total header length */
81335640Shselasky#define SLL_ADDRLEN	8		/* length of address field */
82335640Shselasky
83335640Shselasky#include <pcap/pcap-inttypes.h>
84335640Shselasky
85335640Shselaskystruct sll_header {
86335640Shselasky	uint16_t sll_pkttype;		/* packet type */
87335640Shselasky	uint16_t sll_hatype;		/* link-layer address type */
88335640Shselasky	uint16_t sll_halen;		/* link-layer address length */
89335640Shselasky	uint8_t sll_addr[SLL_ADDRLEN];	/* link-layer address */
90335640Shselasky	uint16_t sll_protocol;		/* protocol */
91335640Shselasky};
92335640Shselasky
93335640Shselasky/*
94335640Shselasky * The LINUX_SLL_ values for "sll_pkttype"; these correspond to the
95335640Shselasky * PACKET_ values on Linux, but are defined here so that they're
96335640Shselasky * available even on systems other than Linux, and so that they
97335640Shselasky * don't change even if the PACKET_ values change.
98335640Shselasky */
99335640Shselasky#define LINUX_SLL_HOST		0
100335640Shselasky#define LINUX_SLL_BROADCAST	1
101335640Shselasky#define LINUX_SLL_MULTICAST	2
102335640Shselasky#define LINUX_SLL_OTHERHOST	3
103335640Shselasky#define LINUX_SLL_OUTGOING	4
104335640Shselasky
105335640Shselasky/*
106335640Shselasky * The LINUX_SLL_ values for "sll_protocol"; these correspond to the
107335640Shselasky * ETH_P_ values on Linux, but are defined here so that they're
108335640Shselasky * available even on systems other than Linux.  We assume, for now,
109335640Shselasky * that the ETH_P_ values won't change in Linux; if they do, then:
110335640Shselasky *
111335640Shselasky *	if we don't translate them in "pcap-linux.c", capture files
112335640Shselasky *	won't necessarily be readable if captured on a system that
113335640Shselasky *	defines ETH_P_ values that don't match these values;
114335640Shselasky *
115335640Shselasky *	if we do translate them in "pcap-linux.c", that makes life
116335640Shselasky *	unpleasant for the BPF code generator, as the values you test
117335640Shselasky *	for in the kernel aren't the values that you test for when
118335640Shselasky *	reading a capture file, so the fixup code run on BPF programs
119335640Shselasky *	handed to the kernel ends up having to do more work.
120335640Shselasky *
121335640Shselasky * Add other values here as necessary, for handling packet types that
122335640Shselasky * might show up on non-Ethernet, non-802.x networks.  (Not all the ones
123335640Shselasky * in the Linux "if_ether.h" will, I suspect, actually show up in
124335640Shselasky * captures.)
125335640Shselasky */
126335640Shselasky#define LINUX_SLL_P_802_3	0x0001	/* Novell 802.3 frames without 802.2 LLC header */
127335640Shselasky#define LINUX_SLL_P_802_2	0x0004	/* 802.2 frames (not D/I/X Ethernet) */
128335640Shselasky#define LINUX_SLL_P_CAN		0x000C	/* CAN frames, with SocketCAN pseudo-headers */
129335640Shselasky#define LINUX_SLL_P_CANFD	0x000D	/* CAN FD frames, with SocketCAN pseudo-headers */
130335640Shselasky
131335640Shselasky#endif
132