xref: /aosp_15_r20/external/libpcap/pcap/nflog.h (revision 8b26181f966a6af5cf6981a6f474313de533bb28)
1*8b26181fSAndroid Build Coastguard Worker /*
2*8b26181fSAndroid Build Coastguard Worker  * Copyright (c) 2013, Petar Alilovic,
3*8b26181fSAndroid Build Coastguard Worker  * Faculty of Electrical Engineering and Computing, University of Zagreb
4*8b26181fSAndroid Build Coastguard Worker  * All rights reserved
5*8b26181fSAndroid Build Coastguard Worker  *
6*8b26181fSAndroid Build Coastguard Worker  * Redistribution and use in source and binary forms, with or without
7*8b26181fSAndroid Build Coastguard Worker  * modification, are permitted provided that the following conditions are met:
8*8b26181fSAndroid Build Coastguard Worker  *
9*8b26181fSAndroid Build Coastguard Worker  * * Redistributions of source code must retain the above copyright notice,
10*8b26181fSAndroid Build Coastguard Worker  *	 this list of conditions and the following disclaimer.
11*8b26181fSAndroid Build Coastguard Worker  * * Redistributions in binary form must reproduce the above copyright
12*8b26181fSAndroid Build Coastguard Worker  *	 notice, this list of conditions and the following disclaimer in the
13*8b26181fSAndroid Build Coastguard Worker  *	 documentation and/or other materials provided with the distribution.
14*8b26181fSAndroid Build Coastguard Worker  *
15*8b26181fSAndroid Build Coastguard Worker  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
16*8b26181fSAndroid Build Coastguard Worker  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17*8b26181fSAndroid Build Coastguard Worker  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18*8b26181fSAndroid Build Coastguard Worker  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
19*8b26181fSAndroid Build Coastguard Worker  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20*8b26181fSAndroid Build Coastguard Worker  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21*8b26181fSAndroid Build Coastguard Worker  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22*8b26181fSAndroid Build Coastguard Worker  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*8b26181fSAndroid Build Coastguard Worker  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*8b26181fSAndroid Build Coastguard Worker  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
25*8b26181fSAndroid Build Coastguard Worker  * DAMAGE.
26*8b26181fSAndroid Build Coastguard Worker  */
27*8b26181fSAndroid Build Coastguard Worker 
28*8b26181fSAndroid Build Coastguard Worker #ifndef lib_pcap_nflog_h
29*8b26181fSAndroid Build Coastguard Worker #define lib_pcap_nflog_h
30*8b26181fSAndroid Build Coastguard Worker 
31*8b26181fSAndroid Build Coastguard Worker #include <pcap/pcap-inttypes.h>
32*8b26181fSAndroid Build Coastguard Worker 
33*8b26181fSAndroid Build Coastguard Worker /*
34*8b26181fSAndroid Build Coastguard Worker  * Structure of an NFLOG header and TLV parts, as described at
35*8b26181fSAndroid Build Coastguard Worker  * https://www.tcpdump.org/linktypes/LINKTYPE_NFLOG.html
36*8b26181fSAndroid Build Coastguard Worker  *
37*8b26181fSAndroid Build Coastguard Worker  * The NFLOG header is big-endian.
38*8b26181fSAndroid Build Coastguard Worker  *
39*8b26181fSAndroid Build Coastguard Worker  * The TLV length and type are in host byte order.  The value is either
40*8b26181fSAndroid Build Coastguard Worker  * big-endian or is an array of bytes in some externally-specified byte
41*8b26181fSAndroid Build Coastguard Worker  * order (text string, link-layer address, link-layer header, packet
42*8b26181fSAndroid Build Coastguard Worker  * data, etc.).
43*8b26181fSAndroid Build Coastguard Worker  */
44*8b26181fSAndroid Build Coastguard Worker typedef struct nflog_hdr {
45*8b26181fSAndroid Build Coastguard Worker 	uint8_t		nflog_family;	/* address family */
46*8b26181fSAndroid Build Coastguard Worker 	uint8_t		nflog_version;	/* version */
47*8b26181fSAndroid Build Coastguard Worker 	uint16_t	nflog_rid;	/* resource ID */
48*8b26181fSAndroid Build Coastguard Worker } nflog_hdr_t;
49*8b26181fSAndroid Build Coastguard Worker 
50*8b26181fSAndroid Build Coastguard Worker typedef struct nflog_tlv {
51*8b26181fSAndroid Build Coastguard Worker 	uint16_t	tlv_length;	/* tlv length */
52*8b26181fSAndroid Build Coastguard Worker 	uint16_t	tlv_type;	/* tlv type */
53*8b26181fSAndroid Build Coastguard Worker 	/* value follows this */
54*8b26181fSAndroid Build Coastguard Worker } nflog_tlv_t;
55*8b26181fSAndroid Build Coastguard Worker 
56*8b26181fSAndroid Build Coastguard Worker typedef struct nflog_packet_hdr {
57*8b26181fSAndroid Build Coastguard Worker 	uint16_t	hw_protocol;	/* hw protocol */
58*8b26181fSAndroid Build Coastguard Worker 	uint8_t		hook;		/* netfilter hook */
59*8b26181fSAndroid Build Coastguard Worker 	uint8_t		pad;		/* padding to 32 bits */
60*8b26181fSAndroid Build Coastguard Worker } nflog_packet_hdr_t;
61*8b26181fSAndroid Build Coastguard Worker 
62*8b26181fSAndroid Build Coastguard Worker typedef struct nflog_hwaddr {
63*8b26181fSAndroid Build Coastguard Worker 	uint16_t	hw_addrlen;	/* address length */
64*8b26181fSAndroid Build Coastguard Worker 	uint16_t	pad;		/* padding to 32-bit boundary */
65*8b26181fSAndroid Build Coastguard Worker 	uint8_t		hw_addr[8];	/* address, up to 8 bytes */
66*8b26181fSAndroid Build Coastguard Worker } nflog_hwaddr_t;
67*8b26181fSAndroid Build Coastguard Worker 
68*8b26181fSAndroid Build Coastguard Worker typedef struct nflog_timestamp {
69*8b26181fSAndroid Build Coastguard Worker 	uint64_t	sec;
70*8b26181fSAndroid Build Coastguard Worker 	uint64_t	usec;
71*8b26181fSAndroid Build Coastguard Worker } nflog_timestamp_t;
72*8b26181fSAndroid Build Coastguard Worker 
73*8b26181fSAndroid Build Coastguard Worker /*
74*8b26181fSAndroid Build Coastguard Worker  * TLV types.
75*8b26181fSAndroid Build Coastguard Worker  */
76*8b26181fSAndroid Build Coastguard Worker #define NFULA_PACKET_HDR		1	/* nflog_packet_hdr_t */
77*8b26181fSAndroid Build Coastguard Worker #define NFULA_MARK			2	/* packet mark from skbuff */
78*8b26181fSAndroid Build Coastguard Worker #define NFULA_TIMESTAMP			3	/* nflog_timestamp_t for skbuff's time stamp */
79*8b26181fSAndroid Build Coastguard Worker #define NFULA_IFINDEX_INDEV		4	/* ifindex of device on which packet received (possibly bridge group) */
80*8b26181fSAndroid Build Coastguard Worker #define NFULA_IFINDEX_OUTDEV		5	/* ifindex of device on which packet transmitted (possibly bridge group) */
81*8b26181fSAndroid Build Coastguard Worker #define NFULA_IFINDEX_PHYSINDEV		6	/* ifindex of physical device on which packet received (not bridge group) */
82*8b26181fSAndroid Build Coastguard Worker #define NFULA_IFINDEX_PHYSOUTDEV	7	/* ifindex of physical device on which packet transmitted (not bridge group) */
83*8b26181fSAndroid Build Coastguard Worker #define NFULA_HWADDR			8	/* nflog_hwaddr_t for hardware address */
84*8b26181fSAndroid Build Coastguard Worker #define NFULA_PAYLOAD			9	/* packet payload */
85*8b26181fSAndroid Build Coastguard Worker #define NFULA_PREFIX			10	/* text string - null-terminated, count includes NUL */
86*8b26181fSAndroid Build Coastguard Worker #define NFULA_UID			11	/* UID owning socket on which packet was sent/received */
87*8b26181fSAndroid Build Coastguard Worker #define NFULA_SEQ			12	/* sequence number of packets on this NFLOG socket */
88*8b26181fSAndroid Build Coastguard Worker #define NFULA_SEQ_GLOBAL		13	/* sequence number of pakets on all NFLOG sockets */
89*8b26181fSAndroid Build Coastguard Worker #define NFULA_GID			14	/* GID owning socket on which packet was sent/received */
90*8b26181fSAndroid Build Coastguard Worker #define NFULA_HWTYPE			15	/* ARPHRD_ type of skbuff's device */
91*8b26181fSAndroid Build Coastguard Worker #define NFULA_HWHEADER			16	/* skbuff's MAC-layer header */
92*8b26181fSAndroid Build Coastguard Worker #define NFULA_HWLEN			17	/* length of skbuff's MAC-layer header */
93*8b26181fSAndroid Build Coastguard Worker 
94*8b26181fSAndroid Build Coastguard Worker #endif
95