nf 0.1.0

A port of the netfilter framework written entirely in rust.
Documentation
#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)]

/// Routing/device hook netlink family
pub const NETLINK_ROUTE: u32 = 0; /* Routing/device hook */
/// Unused netlink family number
pub const NETLINK_UNUSED: u32 = 1; /* Unused number */
/// Reserved for user mode socket protocols
pub const NETLINK_USERSOCK: u32 = 2; /* Reserved for user mode socket protocols */
/// Unused number, formerly ip_queue
pub const NETLINK_FIREWALL: u32 = 3; /* Unused number, formerly ip_queue */
/// Socket monitoring netlink family
pub const NETLINK_SOCK_DIAG: u32 = 4; /* socket monitoring */
/// Netfilter/iptables ULOG netlink family
pub const NETLINK_NFLOG: u32 = 5; /* netfilter/iptables ULOG */
/// IPsec netlink family
pub const NETLINK_XFRM: u32 = 6; /* ipsec */
/// SELinux event notifications netlink family
pub const NETLINK_SELINUX: u32 = 7; /* SELinux event notifications */
/// Open-iSCSI netlink family
pub const NETLINK_ISCSI: u32 = 8; /* Open-iSCSI */
/// Auditing netlink family
pub const NETLINK_AUDIT: u32 = 9; /* auditing */
/// Forwarding Information Base lookup netlink family
pub const NETLINK_FIB_LOOKUP: u32 = 10;
/// General-purpose connector netlink family
pub const NETLINK_CONNECTOR: u32 = 11;
/// Netfilter subsystem netlink family
pub const NETLINK_NETFILTER: u32 = 12; /* netfilter subsystem */
/// IPv6 firewall netlink family
pub const NETLINK_IP6_FW: u32 = 13;
/// DECnet routing messages netlink family
pub const NETLINK_DNRTMSG: u32 = 14; /* DECnet routing messages */
/// Kernel messages to userspace netlink family
pub const NETLINK_KOBJECT_UEVENT: u32 = 15; /* Kernel messages to userspace */
/// Generic netlink family
pub const NETLINK_GENERIC: u32 = 16;
/* leave room for NETLINK_DM (DM Events) */
/// SCSI Transports netlink family
pub const NETLINK_SCSITRANSPORT: u32 = 18; /* SCSI Transports */
/// eCryptfs netlink family
pub const NETLINK_ECRYPTFS: u32 = 19;
/// RDMA netlink family
pub const NETLINK_RDMA: u32 = 20;
/// Crypto layer netlink family
pub const NETLINK_CRYPTO: u32 = 21; /* Crypto layer */

/// Alias for NETLINK_SOCK_DIAG (socket monitoring)
pub const NETLINK_INET_DIAG: u32 = NETLINK_SOCK_DIAG;

/// Maximum number of netlink families
pub const MAX_LINKS: u32 = 32;

/// Alignment boundary for netlink messages
pub const NLMSG_ALIGNTO: u32 = 4;

/* Netlink socket options */
/// Socket option to add a membership to a multicast group
pub const NETLINK_ADD_MEMBERSHIP: i32 = 1;
/// Socket option to drop a membership from a multicast group
pub const NETLINK_DROP_MEMBERSHIP: i32 = 2;
/// Socket option to receive sender credentials and ancillary data
pub const NETLINK_PKTINFO: i32 = 3;
/// Socket option to broadcast errors to all listening sockets
pub const NETLINK_BROADCAST_ERROR: i32 = 4;
/// Socket option to disable ENOBUFS notifications
pub const NETLINK_NO_ENOBUFS: i32 = 5;

/// Major number for networking devices
pub const NET_MAJOR: u32 = 36; /* Major 36 is reserved for networking */

/// Netlink socket address structure
///
/// Used to specify addresses for netlink sockets, including
/// the address family, process ID, and multicast groups mask.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(C)]
pub struct sockaddr_nl {
    /// Address family (AF_NETLINK)
    pub nl_family: u16, /* AF_NETLINK	*/
    /// Padding (must be zero)
    pub nl_pad: u16,    /* zero		*/
    /// Port ID (process ID or socket ID)
    pub nl_pid: u32,    /* port ID	*/
    /// Multicast groups mask
    pub nl_groups: u32, /* multicast groups mask */
}

/// Netlink message header structure
///
/// Represents the header of a netlink message.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(C)]
pub struct nlmsghdr {
    /// Length of message including header
    pub nlmsg_len: u32,   /* Length of message including header */
    /// Message content
    pub nlmsg_type: u16,  /* Message content */
    /// Additional flags
    pub nlmsg_flags: u16, /* Additional flags */
    /// Sequence number
    pub nlmsg_seq: u32,   /* Sequence number */
    /// Sending process port ID
    pub nlmsg_pid: u32,   /* Sending process port ID */
}

/// Netlink message error structure
///
/// Contains error code and the header of the failed message.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(C)]
pub struct nlmsgerr {
    /// Error code (negative errno value)
    pub error: i32,
    /// Header of the message that caused the error
    pub msg: nlmsghdr,
}

/// Netlink packet information structure
///
/// Contains sender information for a netlink message.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(C)]
pub struct nl_pktinfo {
    /// Group ID that the message was sent to
    pub group: u32,
}

/// Netlink attribute structure
///
/// Represents type-length-value (TLV) attributes in netlink messages.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(C)]
pub struct nlattr {
    /// Length of attribute including header
    pub nla_len: u16,
    /// Type of attribute
    pub nla_type: u16,
}