Skip to main content

NatConfig

Struct NatConfig 

Source
pub struct NatConfig {
    pub flags: u16,
    pub ipv4_min: Option<Ipv4Addr>,
    pub ipv4_max: Option<Ipv4Addr>,
    pub ipv6_min: Option<Ipv6Addr>,
    pub ipv6_max: Option<Ipv6Addr>,
    pub port_min: Option<u16>,
    pub port_max: Option<u16>,
}
Expand description

NAT configuration for use with ct() action.

§Examples

// SNAT to a single IP
NatConfig::snat(Ipv4Addr::new(10, 0, 0, 1))

// SNAT with IP range
NatConfig::snat_range(
    Ipv4Addr::new(10, 0, 0, 1),
    Ipv4Addr::new(10, 0, 0, 10),
)

// DNAT with port
NatConfig::dnat(Ipv4Addr::new(192, 168, 1, 1)).port(8080)

// SNAT with port range and random selection
NatConfig::snat(Ipv4Addr::new(10, 0, 0, 1))
    .port_range(5000, 6000)
    .random()

Fields§

§flags: u16

NAT flags (SRC/DST, persistent, hash, random)

§ipv4_min: Option<Ipv4Addr>

Minimum IPv4 address (if IPv4 NAT)

§ipv4_max: Option<Ipv4Addr>

Maximum IPv4 address (if range)

§ipv6_min: Option<Ipv6Addr>

Minimum IPv6 address (if IPv6 NAT)

§ipv6_max: Option<Ipv6Addr>

Maximum IPv6 address (if range)

§port_min: Option<u16>

Minimum port (if port NAT)

§port_max: Option<u16>

Maximum port (if port range)

Implementations§

Source§

impl NatConfig

Source

pub fn snat(addr: Ipv4Addr) -> Self

Create a SNAT configuration with a single IPv4 address.

Source

pub fn snat_range(min: Ipv4Addr, max: Ipv4Addr) -> Self

Create a SNAT configuration with an IPv4 address range.

Source

pub fn dnat(addr: Ipv4Addr) -> Self

Create a DNAT configuration with a single IPv4 address.

Source

pub fn dnat_range(min: Ipv4Addr, max: Ipv4Addr) -> Self

Create a DNAT configuration with an IPv4 address range.

Source

pub fn snat_v6(addr: Ipv6Addr) -> Self

Create a SNAT configuration with a single IPv6 address.

Source

pub fn dnat_v6(addr: Ipv6Addr) -> Self

Create a DNAT configuration with a single IPv6 address.

Source

pub fn snat_v6_range(min: Ipv6Addr, max: Ipv6Addr) -> Self

Create a SNAT configuration with an IPv6 address range.

Source

pub fn dnat_v6_range(min: Ipv6Addr, max: Ipv6Addr) -> Self

Create a DNAT configuration with an IPv6 address range.

Source

pub fn port(self, port: u16) -> Self

Set a single port for NAT.

Source

pub fn port_range(self, min: u16, max: u16) -> Self

Set a port range for NAT.

Source

pub fn persistent(self) -> Self

Use persistent NAT mapping (survives restarts).

Source

pub fn hash(self) -> Self

Use hash-based port selection.

Source

pub fn random(self) -> Self

Use random port selection.

Trait Implementations§

Source§

impl Clone for NatConfig

Source§

fn clone(&self) -> NatConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NatConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for NatConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.