Ipv4Layer

Struct Ipv4Layer 

Source
pub struct Ipv4Layer {
    addresses: RwLock<BTreeMap<String, Vec<Ipv4AddressInfo>>>,
    routing_table: RwLock<Vec<RouteEntry>>,
    protocols: RwLock<BTreeMap<u8, Arc<dyn NetworkLayer>>>,
    stats: RwLock<NetworkLayerStats>,
    default_ttl: u8,
}
Expand description

IPv4 layer

Handles IPv4 packet encapsulation and decapsulation. Manages multiple addresses per interface and routing table.

Fields§

§addresses: RwLock<BTreeMap<String, Vec<Ipv4AddressInfo>>>

Interface name -> list of IPv4 addresses

§routing_table: RwLock<Vec<RouteEntry>>

Routing table (ordered by specificity)

§protocols: RwLock<BTreeMap<u8, Arc<dyn NetworkLayer>>>

Protocol handlers registered by protocol number

§stats: RwLock<NetworkLayerStats>

Statistics

§default_ttl: u8

Default TTL

Implementations§

Source§

impl Ipv4Layer

Source

pub fn new() -> Arc<Self>

Create a new IPv4 layer

Source

pub fn init(network_manager: &NetworkManager)

Initialize and register the IPv4 layer with NetworkManager

Registers with NetworkManager and registers itself with EthernetLayer for EtherType 0x0800 (IPv4).

§Panics

Panics if EthernetLayer is not registered (must be initialized first).

Source

pub fn add_address(&self, interface: &str, info: Ipv4AddressInfo)

Add an IPv4 address to an interface

Source

pub fn remove_address(&self, interface: &str, ip: Ipv4Address)

Remove an IPv4 address from an interface

Source

pub fn get_addresses(&self, interface: &str) -> Vec<Ipv4AddressInfo>

Get all addresses for an interface

Source

pub fn get_primary_ip(&self, interface: &str) -> Option<Ipv4Address>

Get primary IP address for an interface

Source

pub fn add_route(&self, entry: RouteEntry)

Add a route to the routing table

Source

pub fn remove_route(&self, destination: Ipv4Address, netmask: Ipv4Address)

Remove a route from the routing table

Source

pub fn set_default_gateway(&self, gateway: Ipv4Address, interface: &str)

Set default gateway

Source

pub fn select_source( &self, dest: Ipv4Address, ) -> Option<(String, Ipv4Address, Option<Ipv4Address>)>

Select source IP and interface for a destination

Returns (interface_name, source_ip, optional_gateway)

Source

fn ip_matches_route(&self, ip: Ipv4Address, route: &RouteEntry) -> bool

Check if an IP matches a route

Source

fn same_subnet( &self, ip1: Ipv4Address, ip2: Ipv4Address, mask: Ipv4Address, ) -> bool

Check if two IPs are in the same subnet

Source

pub fn is_local_ip(&self, ip: Ipv4Address) -> bool

Check if an IP is local (assigned to any interface)

Source

pub fn get_protocol_handler( &self, proto_num: u8, ) -> Option<Arc<dyn NetworkLayer>>

Get protocol handler for a protocol number

Trait Implementations§

Source§

impl NetworkLayer for Ipv4Layer

Source§

fn register_protocol(&self, proto_num: u16, handler: Arc<dyn NetworkLayer>)

Register a protocol handler for this layer Read more
Source§

fn send( &self, packet: &[u8], context: &LayerContext, next_layers: &[Arc<dyn NetworkLayer>], ) -> Result<(), SocketError>

Send a packet through this layer Read more
Source§

fn receive( &self, packet: &[u8], _context: Option<&LayerContext>, ) -> Result<(), SocketError>

Receive and process a packet at this layer Read more
Source§

fn name(&self) -> &'static str

Get layer name for debugging
Source§

fn stats(&self) -> NetworkLayerStats

Get layer statistics
Source§

fn as_any(&self) -> &dyn Any

Cast to Any for safe downcasting
Source§

fn configure( &self, config: &SocketConfig, next_layers: &[Arc<dyn NetworkLayer>], ) -> Result<(), SocketError>

Configure this layer with socket-specific parameters Read more

Auto Trait Implementations§

§

impl !Freeze for Ipv4Layer

§

impl !RefUnwindSafe for Ipv4Layer

§

impl Send for Ipv4Layer

§

impl Sync for Ipv4Layer

§

impl Unpin for Ipv4Layer

§

impl !UnwindSafe for Ipv4Layer

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.