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
77356341Scy#include <pcap/pcap-inttypes.h>
78356341Scy
79335640Shselasky/*
80335640Shselasky * A DLT_LINUX_SLL fake link-layer header.
81335640Shselasky */
82335640Shselasky#define SLL_HDR_LEN	16		/* total header length */
83335640Shselasky#define SLL_ADDRLEN	8		/* length of address field */
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 */
89356341Scy	uint8_t  sll_addr[SLL_ADDRLEN];	/* link-layer address */
90335640Shselasky	uint16_t sll_protocol;		/* protocol */
91335640Shselasky};
92335640Shselasky
93335640Shselasky/*
94356341Scy * A DLT_LINUX_SLL2 fake link-layer header.
95335640Shselasky */
96356341Scy#define SLL2_HDR_LEN	20		/* total header length */
97356341Scy
98356341Scystruct sll2_header {
99356341Scy	uint16_t sll2_protocol;			/* protocol */
100356341Scy	uint16_t sll2_reserved_mbz;		/* reserved - must be zero */
101356341Scy	uint32_t sll2_if_index;			/* 1-based interface index */
102356341Scy	uint16_t sll2_hatype;			/* link-layer address type */
103356341Scy	uint8_t  sll2_pkttype;			/* packet type */
104356341Scy	uint8_t  sll2_halen;			/* link-layer address length */
105356341Scy	uint8_t  sll2_addr[SLL_ADDRLEN];	/* link-layer address */
106356341Scy};
107356341Scy
108356341Scy/*
109356341Scy * The LINUX_SLL_ values for "sll_pkttype" and LINUX_SLL2_ values for
110356341Scy * "sll2_pkttype"; these correspond to the PACKET_ values on Linux,
111356341Scy * which are defined by a header under include/uapi in the current
112356341Scy * kernel source, and are thus not going to change on Linux.  We
113356341Scy * define them here so that they're available even on systems other
114356341Scy * than Linux.
115356341Scy */
116335640Shselasky#define LINUX_SLL_HOST		0
117335640Shselasky#define LINUX_SLL_BROADCAST	1
118335640Shselasky#define LINUX_SLL_MULTICAST	2
119335640Shselasky#define LINUX_SLL_OTHERHOST	3
120335640Shselasky#define LINUX_SLL_OUTGOING	4
121335640Shselasky
122335640Shselasky/*
123356341Scy * The LINUX_SLL_ values for "sll_protocol" and LINUX_SLL2_ values for
124356341Scy * "sll2_protocol"; these correspond to the ETH_P_ values on Linux, but
125356341Scy * are defined here so that they're available even on systems other than
126356341Scy * Linux.  We assume, for now, that the ETH_P_ values won't change in
127356341Scy * Linux; if they do, then:
128335640Shselasky *
129335640Shselasky *	if we don't translate them in "pcap-linux.c", capture files
130335640Shselasky *	won't necessarily be readable if captured on a system that
131335640Shselasky *	defines ETH_P_ values that don't match these values;
132335640Shselasky *
133335640Shselasky *	if we do translate them in "pcap-linux.c", that makes life
134335640Shselasky *	unpleasant for the BPF code generator, as the values you test
135335640Shselasky *	for in the kernel aren't the values that you test for when
136335640Shselasky *	reading a capture file, so the fixup code run on BPF programs
137335640Shselasky *	handed to the kernel ends up having to do more work.
138335640Shselasky *
139335640Shselasky * Add other values here as necessary, for handling packet types that
140335640Shselasky * might show up on non-Ethernet, non-802.x networks.  (Not all the ones
141335640Shselasky * in the Linux "if_ether.h" will, I suspect, actually show up in
142335640Shselasky * captures.)
143335640Shselasky */
144335640Shselasky#define LINUX_SLL_P_802_3	0x0001	/* Novell 802.3 frames without 802.2 LLC header */
145335640Shselasky#define LINUX_SLL_P_802_2	0x0004	/* 802.2 frames (not D/I/X Ethernet) */
146335640Shselasky#define LINUX_SLL_P_CAN		0x000C	/* CAN frames, with SocketCAN pseudo-headers */
147335640Shselasky#define LINUX_SLL_P_CANFD	0x000D	/* CAN FD frames, with SocketCAN pseudo-headers */
148335640Shselasky
149335640Shselasky#endif
150