neli/consts/
netfilter.rs

1//! Constants for netfilter related protocols
2//!
3//! Note that this doesn't cover everything yet, both the list of
4//! types and variants in enums will be added over time.
5
6use crate as neli;
7
8use neli_proc_macros::neli_enum;
9
10/// Attributes inside a netfilter log packet message.
11///
12/// These are send by the kernel and describe a logged packet.
13#[neli_enum(serialized_type = "u16")]
14pub enum NfLogAttr {
15    PacketHdr = libc::NFULA_PACKET_HDR as u16,
16    Mark = libc::NFULA_MARK as u16,
17    Timestamp = libc::NFULA_TIMESTAMP as u16,
18    IfindexIndev = libc::NFULA_IFINDEX_INDEV as u16,
19    IfindexOutdev = libc::NFULA_IFINDEX_OUTDEV as u16,
20    IfindexPhyindev = libc::NFULA_IFINDEX_PHYSINDEV as u16,
21    IfindexPhyoutdev = libc::NFULA_IFINDEX_PHYSOUTDEV as u16,
22    Hwaddr = libc::NFULA_HWADDR as u16,
23    Payload = libc::NFULA_PAYLOAD as u16,
24    Prefix = libc::NFULA_PREFIX as u16,
25    Uid = libc::NFULA_UID as u16,
26    Seq = libc::NFULA_SEQ as u16,
27    SeqGlobal = libc::NFULA_SEQ_GLOBAL as u16,
28    Gid = libc::NFULA_GID as u16,
29    Hwtype = libc::NFULA_HWTYPE as u16,
30    Hwheader = libc::NFULA_HWHEADER as u16,
31    Hwlen = libc::NFULA_HWLEN as u16,
32    Ct = libc::NFULA_CT as u16,
33    CtInfo = libc::NFULA_CT_INFO as u16,
34}
35
36/// Configuration attributes for netfilter logging.
37#[neli_enum(serialized_type = "u16")]
38pub enum NfLogCfg {
39    Cmd = libc::NFULA_CFG_CMD as u16,
40    Mode = libc::NFULA_CFG_MODE as u16,
41    NlBufSize = libc::NFULA_CFG_NLBUFSIZ as u16,
42    Timeout = libc::NFULA_CFG_TIMEOUT as u16,
43    QThresh = libc::NFULA_CFG_QTHRESH as u16,
44    Flags = libc::NFULA_CFG_FLAGS as u16,
45}
46
47const fn nfnl_msg_type(subsys: u8, msg: u8) -> u16 {
48    ((subsys as u16) << 8) | (msg as u16)
49}
50
51/// Messages related to the netfilter netlink protocols.
52///
53/// These appear on the
54/// [`NlFamily::Netfilter`][crate::consts::socket::NlFamily::Netfilter]
55/// sockets.
56#[neli_enum(serialized_type = "u16")]
57pub enum NetfilterMsg {
58    // TODO: Docs here /// A logged packet, going from kernel to userspace.
59    LogPacket = nfnl_msg_type(libc::NFNL_SUBSYS_ULOG as u8, libc::NFULNL_MSG_PACKET as u8),
60    // TODO: Docs here /// A logging configuration request, going from userspace to kernel.
61    LogConfig = nfnl_msg_type(libc::NFNL_SUBSYS_ULOG as u8, libc::NFULNL_MSG_CONFIG as u8),
62}
63
64impl_trait! {
65    /// Parameters for the [`NfLogCfg::Cmd`].
66    pub LogCfgCmd, u8,
67    /// Wrapper that is valid anywhere that accepts a value
68    /// implementing the [`LogCfgCmd`] trait
69    pub LogCfgCmdWrapper,
70    LogCmd
71}
72
73/// Command value for the [`NfLogCfg::Cmd`].
74#[neli_enum(serialized_type = "u8")]
75pub enum LogCmd {
76    Bind = libc::NFULNL_CFG_CMD_BIND as u8,
77    Unbind = libc::NFULNL_CFG_CMD_UNBIND as u8,
78    PfBind = libc::NFULNL_CFG_CMD_PF_BIND as u8,
79    PfUnbind = libc::NFULNL_CFG_CMD_PF_UNBIND as u8,
80}
81
82/// Copy mode of the logged packets.
83#[neli_enum(serialized_type = "u8")]
84pub enum LogCopyMode {
85    None = libc::NFULNL_COPY_NONE as u8,
86    Meta = libc::NFULNL_COPY_META as u8,
87    Packet = libc::NFULNL_COPY_PACKET as u8,
88}