Blame pcap/sll.h

Packit 209cc3
/*-
Packit 209cc3
 * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
Packit 209cc3
 *	The Regents of the University of California.  All rights reserved.
Packit 209cc3
 *
Packit 209cc3
 * This code is derived from the Stanford/CMU enet packet filter,
Packit 209cc3
 * (net/enet.c) distributed as part of 4.3BSD, and code contributed
Packit 209cc3
 * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
Packit 209cc3
 * Berkeley Laboratory.
Packit 209cc3
 *
Packit 209cc3
 * Redistribution and use in source and binary forms, with or without
Packit 209cc3
 * modification, are permitted provided that the following conditions
Packit 209cc3
 * are met:
Packit 209cc3
 * 1. Redistributions of source code must retain the above copyright
Packit 209cc3
 *    notice, this list of conditions and the following disclaimer.
Packit 209cc3
 * 2. Redistributions in binary form must reproduce the above copyright
Packit 209cc3
 *    notice, this list of conditions and the following disclaimer in the
Packit 209cc3
 *    documentation and/or other materials provided with the distribution.
Packit 209cc3
 * 3. All advertising materials mentioning features or use of this software
Packit 209cc3
 *    must display the following acknowledgement:
Packit 209cc3
 *      This product includes software developed by the University of
Packit 209cc3
 *      California, Berkeley and its contributors.
Packit 209cc3
 * 4. Neither the name of the University nor the names of its contributors
Packit 209cc3
 *    may be used to endorse or promote products derived from this software
Packit 209cc3
 *    without specific prior written permission.
Packit 209cc3
 *
Packit 209cc3
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
Packit 209cc3
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit 209cc3
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit 209cc3
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
Packit 209cc3
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit 209cc3
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit 209cc3
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit 209cc3
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit 209cc3
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit 209cc3
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit 209cc3
 * SUCH DAMAGE.
Packit 209cc3
 */
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * For captures on Linux cooked sockets, we construct a fake header
Packit 209cc3
 * that includes:
Packit 209cc3
 *
Packit 209cc3
 *	a 2-byte "packet type" which is one of:
Packit 209cc3
 *
Packit 209cc3
 *		LINUX_SLL_HOST		packet was sent to us
Packit 209cc3
 *		LINUX_SLL_BROADCAST	packet was broadcast
Packit 209cc3
 *		LINUX_SLL_MULTICAST	packet was multicast
Packit 209cc3
 *		LINUX_SLL_OTHERHOST	packet was sent to somebody else
Packit 209cc3
 *		LINUX_SLL_OUTGOING	packet was sent *by* us;
Packit 209cc3
 *
Packit 209cc3
 *	a 2-byte Ethernet protocol field;
Packit 209cc3
 *
Packit 209cc3
 *	a 2-byte link-layer type;
Packit 209cc3
 *
Packit 209cc3
 *	a 2-byte link-layer address length;
Packit 209cc3
 *
Packit 209cc3
 *	an 8-byte source link-layer address, whose actual length is
Packit 209cc3
 *	specified by the previous value.
Packit 209cc3
 *
Packit 209cc3
 * All fields except for the link-layer address are in network byte order.
Packit 209cc3
 *
Packit 209cc3
 * DO NOT change the layout of this structure, or change any of the
Packit 209cc3
 * LINUX_SLL_ values below.  If you must change the link-layer header
Packit 209cc3
 * for a "cooked" Linux capture, introduce a new DLT_ type (ask
Packit 209cc3
 * "tcpdump-workers@lists.tcpdump.org" for one, so that you don't give it
Packit 209cc3
 * a value that collides with a value already being used), and use the
Packit 209cc3
 * new header in captures of that type, so that programs that can
Packit 209cc3
 * handle DLT_LINUX_SLL captures will continue to handle them correctly
Packit 209cc3
 * without any change, and so that capture files with different headers
Packit 209cc3
 * can be told apart and programs that read them can dissect the
Packit 209cc3
 * packets in them.
Packit 209cc3
 */
Packit 209cc3
Packit 209cc3
#ifndef lib_pcap_sll_h
Packit 209cc3
#define lib_pcap_sll_h
Packit 209cc3
Packit 209cc3
#include <pcap/pcap-inttypes.h>
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * A DLT_LINUX_SLL fake link-layer header.
Packit 209cc3
 */
Packit 209cc3
#define SLL_HDR_LEN	16		/* total header length */
Packit 209cc3
#define SLL_ADDRLEN	8		/* length of address field */
Packit 209cc3
Packit 209cc3
struct sll_header {
Packit 209cc3
	uint16_t sll_pkttype;		/* packet type */
Packit 209cc3
	uint16_t sll_hatype;		/* link-layer address type */
Packit 209cc3
	uint16_t sll_halen;		/* link-layer address length */
Packit 209cc3
	uint8_t  sll_addr[SLL_ADDRLEN];	/* link-layer address */
Packit 209cc3
	uint16_t sll_protocol;		/* protocol */
Packit 209cc3
};
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * A DLT_LINUX_SLL2 fake link-layer header.
Packit 209cc3
 */
Packit 209cc3
#define SLL2_HDR_LEN	20		/* total header length */
Packit 209cc3
Packit 209cc3
struct sll2_header {
Packit 209cc3
	uint16_t sll2_protocol;			/* protocol */
Packit 209cc3
	uint16_t sll2_reserved_mbz;		/* reserved - must be zero */
Packit 209cc3
	uint32_t sll2_if_index;			/* 1-based interface index */
Packit 209cc3
	uint16_t sll2_hatype;			/* link-layer address type */
Packit 209cc3
	uint8_t  sll2_pkttype;			/* packet type */
Packit 209cc3
	uint8_t  sll2_halen;			/* link-layer address length */
Packit 209cc3
	uint8_t  sll2_addr[SLL_ADDRLEN];	/* link-layer address */
Packit 209cc3
};
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * The LINUX_SLL_ values for "sll_pkttype" and LINUX_SLL2_ values for
Packit 209cc3
 * "sll2_pkttype"; these correspond to the PACKET_ values on Linux,
Packit 209cc3
 * which are defined by a header under include/uapi in the current
Packit 209cc3
 * kernel source, and are thus not going to change on Linux.  We
Packit 209cc3
 * define them here so that they're available even on systems other
Packit 209cc3
 * than Linux.
Packit 209cc3
 */
Packit 209cc3
#define LINUX_SLL_HOST		0
Packit 209cc3
#define LINUX_SLL_BROADCAST	1
Packit 209cc3
#define LINUX_SLL_MULTICAST	2
Packit 209cc3
#define LINUX_SLL_OTHERHOST	3
Packit 209cc3
#define LINUX_SLL_OUTGOING	4
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * The LINUX_SLL_ values for "sll_protocol" and LINUX_SLL2_ values for
Packit 209cc3
 * "sll2_protocol"; these correspond to the ETH_P_ values on Linux, but
Packit 209cc3
 * are defined here so that they're available even on systems other than
Packit 209cc3
 * Linux.  We assume, for now, that the ETH_P_ values won't change in
Packit 209cc3
 * Linux; if they do, then:
Packit 209cc3
 *
Packit 209cc3
 *	if we don't translate them in "pcap-linux.c", capture files
Packit 209cc3
 *	won't necessarily be readable if captured on a system that
Packit 209cc3
 *	defines ETH_P_ values that don't match these values;
Packit 209cc3
 *
Packit 209cc3
 *	if we do translate them in "pcap-linux.c", that makes life
Packit 209cc3
 *	unpleasant for the BPF code generator, as the values you test
Packit 209cc3
 *	for in the kernel aren't the values that you test for when
Packit 209cc3
 *	reading a capture file, so the fixup code run on BPF programs
Packit 209cc3
 *	handed to the kernel ends up having to do more work.
Packit 209cc3
 *
Packit 209cc3
 * Add other values here as necessary, for handling packet types that
Packit 209cc3
 * might show up on non-Ethernet, non-802.x networks.  (Not all the ones
Packit 209cc3
 * in the Linux "if_ether.h" will, I suspect, actually show up in
Packit 209cc3
 * captures.)
Packit 209cc3
 */
Packit 209cc3
#define LINUX_SLL_P_802_3	0x0001	/* Novell 802.3 frames without 802.2 LLC header */
Packit 209cc3
#define LINUX_SLL_P_802_2	0x0004	/* 802.2 frames (not D/I/X Ethernet) */
Packit 209cc3
#define LINUX_SLL_P_CAN		0x000C	/* CAN frames, with SocketCAN pseudo-headers */
Packit 209cc3
#define LINUX_SLL_P_CANFD	0x000D	/* CAN FD frames, with SocketCAN pseudo-headers */
Packit 209cc3
Packit 209cc3
#endif