nf 0.1.0

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

/// Attribute handling and TLV format operations
pub mod attr;
/// CAN bus protocol support
pub mod can;
/// Callback handling for netlink message processing
pub mod cb;
/// Connection tracking (conntrack) definitions and types
pub mod ct;
/// Core netlink protocol constants and structures
pub mod netlink;
/// Netlink message structure and operations
pub mod nlmsg;
/// Socket abstraction and operations
pub mod socket;

use crate::mnl::nlmsg::Header;
use std::mem::size_of;

/// System constant for page size retrieval
pub const _SC_PAGESIZE: i32 = 30;

/// Alignment boundary for netlink data structures
pub const ALIGNTO: usize = 4;

/// Aligns a length to the netlink alignment boundary
///
/// # Parameters
/// * `len` - Length to align
///
/// # Returns
/// The aligned length
pub const fn ALIGN(len: usize) -> usize {
    ((len) + ALIGNTO - 1) & !(ALIGNTO - 1)
}

/// Size of a netlink message header, aligned
pub const MNL_NLMSG_HDRLEN: usize = ALIGN(size_of::<Header>());

/// Return code from callbacks indicating an error occurred
pub const MNL_CB_ERROR: i32 = -1;
/// Return code from callbacks indicating processing should stop
pub const MNL_CB_STOP: i32 = 0;
/// Return code from callbacks indicating successful processing
pub const MNL_CB_OK: i32 = 1;

/// Socket option level for netlink-specific socket options
pub const SOL_NETLINK: u32 = 270;

/// Calculate the number of elements in an array
///
/// # Parameters
/// * `a` - Reference to the array
///
/// # Returns
/// The number of elements in the array
pub const fn ARRAY_SIZE<T>(a: &[T]) -> usize {
    size_of_val(a) / size_of::<T>()
}