rsmnl_linux/netfilter/
nfnetlink_log.rs

1use errno::Errno;
2use mnl::{Attr, AttrTbl, MsgVec, Result};
3use netfilter::nfnetlink_conntrack::CtattrTypeTbl;
4
5// This file describes the netlink messages (i.e. 'protocol packets'),
6// and not any kind of function definitions.  It is shared between kernel and
7// userspace.  Don't put kernel specific stuff in here
8
9#[repr(u16)]
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
11pub enum NfulnlMsgTypes {
12    // NFULNL_MSG_
13    Packet = 0, // packet from kernel to userspace
14    Config,     // connect to a particular queue
15    MAX,
16}
17pub const NFULNL_MSG_PACKET: u16 = NfulnlMsgTypes::Packet as u16;
18pub const NFULNL_MSG_CONFIG: u16 = NfulnlMsgTypes::Config as u16;
19pub const NFULNL_MSG_MAX: u16 = NfulnlMsgTypes::MAX as u16;
20
21#[repr(C)]
22#[derive(Debug, Clone, Copy)]
23pub struct NfulnlMsgPacketHdr {
24    pub hw_protocol: u16, // hw protocol (network order)
25    pub hook: u8,         // netfilter hook
26    pub _pad: u8,
27}
28
29#[repr(C)]
30#[derive(Debug, Clone, Copy)]
31pub struct NfulnlMsgPacketHw {
32    pub hw_addrlen: u16,
33    pub _pad: u16,
34    pub hw_addr: [u8; 8usize],
35}
36
37#[repr(C)]
38#[derive(Debug, Clone, Copy)]
39pub struct NfulnlMsgPacketTimestamp {
40    pub sec: u64,
41    pub usec: u64,
42}
43
44#[repr(u16)]
45#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, NlaType)]
46#[tbname = "NfulnlVlanAttrTbl"]
47pub enum NfulnlVlanAttr {
48    Unspec,
49
50    #[nla_type(u16, proto)]
51    Proto, /* __be16 skb vlan_proto */
52
53    #[nla_type(u16, tci)]
54    Tci, /* __be16 skb htons(vlan_tci) */
55
56    _MAX,
57}
58
59#[repr(u16)]
60#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, NlaType)]
61#[tbname = "NfulnlAttrTypeTbl"]
62pub enum NfulnlAttrType {
63    UNSPEC = 0,
64
65    #[nla_type(NfulnlMsgPacketHdr, packet_hdr)]
66    PacketHdr,
67
68    #[nla_type(u32, mark)]
69    Mark, // __u32 nfmark
70
71    #[nla_type(NfulnlMsgPacketTimestamp, timestamp)]
72    Timestamp, // nfulnl_msg_packet_timestamp
73
74    #[nla_type(u32, ifindex_indev)]
75    IfindexIndev, // __u32 ifindex
76
77    #[nla_type(u32, ifindex_outdev)]
78    IfindexOutdev, // __u32 ifindex
79
80    #[nla_type(u32, ifindex_physindev)]
81    IfindexPhysindev, // __u32 ifindex
82
83    #[nla_type(u32, ifindex_physoutdev)]
84    IfindexPhysoutdev, // __u32 ifindex
85
86    #[nla_type(NfulnlMsgPacketHw, hwaddr)]
87    Hwaddr, // nfulnl_msg_packet_hw
88
89    #[nla_type(bytes, payload)]
90    Payload, // opaque data payload
91
92    #[nla_type(str, prefix)]
93    Prefix, // string prefix
94
95    #[nla_type(u32, uid)]
96    Uid, // user id of socket
97
98    #[nla_type(u32, seq)]
99    Seq, // instance-local sequence number
100
101    #[nla_type(u32, seq_global)]
102    SeqGlobal, // global sequence number
103
104    #[nla_type(u32, gid)]
105    Gid, // group id of socket
106
107    #[nla_type(u16, hwtype)]
108    Hwtype, // hardware type
109
110    #[nla_type(bytes, hwheader)]
111    Hwheader, // hardware header
112
113    #[nla_type(u16, hwlen)]
114    Hwlen, // hardware header length
115
116    #[nla_nest(CtattrTypeTbl, ct)]
117    Ct, // nf_conntrack_netlink.h
118
119    #[nla_type(u32, ct_info)]
120    CtInfo, // enum ip_conntrack_info
121
122    #[nla_nest(NfulnlVlanAttrTbl, vlan)]
123    Vlan, // nested attribute: packet vlan info
124
125    #[nla_type(bytes, l2hdr)]
126    L2Hdr, // full L2 header
127
128    _MAX,
129}
130
131#[repr(u8)]
132#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
133pub enum NfulnlMsgConfigCmds {
134    // NFULNL_CFG_CMD_
135    None = 0,
136    Bind,
137    Unbind,
138    PfBind,
139    PfUnbind,
140}
141
142#[repr(C, packed)]
143#[derive(Debug, Clone, Copy)]
144pub struct NfulnlMsgConfigCmd {
145    pub command: u8, // nfulnl_msg_config_cmds
146}
147
148#[repr(C, packed)]
149#[derive(Debug, Clone, Copy)]
150pub struct NfulnlMsgConfigMode {
151    pub copy_range: u32,
152    pub copy_mode: u8,
153    pub _pad: u8,
154}
155
156#[repr(u16)]
157#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, NlaType)]
158pub enum NfulnlAttrConfig {
159    Unspec = 0,
160
161    #[nla_type(NfulnlMsgConfigCmd, cmd)]
162    Cmd, // nfulnl_msg_config_cmd
163
164    #[nla_type(NfulnlMsgConfigMode, mode)]
165    Mode, // nfulnl_msg_config_mode
166
167    Nlbufsiz, // __u32 buffer size
168    Timeout,  // __u32 in 1/100 s
169    Qthresh,  // __u32
170    Flags,    // __u16
171    _MAX,
172}
173
174pub const NFULNL_COPY_NONE: u8 = 0x00;
175pub const NFULNL_COPY_META: u8 = 0x01;
176pub const NFULNL_COPY_PACKET: u8 = 0x02;
177// 0xff is reserved, don't use it for new copy modes.
178
179pub const NFULNL_CFG_F_SEQ: u16 = 0x0001;
180pub const NFULNL_CFG_F_SEQ_GLOBAL: u16 = 0x0002;
181pub const NFULNL_CFG_F_CONNTRACK: u16 = 0x0004;