Trait netstack3_base::PortAllocImpl

source ·
pub trait PortAllocImpl {
    type Id: Hash;
    type PortAvailableArg;

    const EPHEMERAL_RANGE: RangeInclusive<u16>;

    // Required method
    fn is_port_available(
        &self,
        id: &Self::Id,
        port: u16,
        arg: &Self::PortAvailableArg,
    ) -> bool;

    // Provided method
    fn rand_ephemeral<R: Rng>(rng: &mut R) -> EphemeralPort<Self> { ... }
}
Expand description

Trait that configures the behavior of port allocation.

PortAllocImpl provides the types, custom behaviors, and port availability checks necessary to operate the port allocation algorithm.

Required Associated Types§

source

type Id: Hash

The “flow” identifier used to allocate port Ids.

The Id is typically the 3 elements other other than the local port in the 4-tuple (local IP:port, remote IP:port) that is used to uniquely identify the flow information of a connection.

source

type PortAvailableArg

An extra argument passed to is_port_available.

Required Associated Constants§

source

const EPHEMERAL_RANGE: RangeInclusive<u16>

The range of ports that can be allocated.

Local ports used in transport protocols are called Ephemeral Ports. Different transport protocols may define different ranges for the issued ports. Port allocation algorithms should guarantee to return a port in this range.

Required Methods§

source

fn is_port_available( &self, id: &Self::Id, port: u16, arg: &Self::PortAvailableArg, ) -> bool

Checks if port is available to be used for the flow id.

Implementers return true if the provided port is available to be used for a given flow id. An available port is a port that would not conflict for the given id plus ideally the port is not in LISTEN or CLOSED states for a given protocol (see RFC 6056).

Note: Callers must guarantee that the given port being checked is within the EPHEMERAL_RANGE.

Provided Methods§

source

fn rand_ephemeral<R: Rng>(rng: &mut R) -> EphemeralPort<Self>

Returns a random ephemeral port in EPHEMERAL_RANGE

Object Safety§

This trait is not object safe.

Implementors§