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: u8Default TTL
Implementations§
Source§impl Ipv4Layer
impl Ipv4Layer
Sourcepub fn init(network_manager: &NetworkManager)
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).
Sourcepub fn add_address(&self, interface: &str, info: Ipv4AddressInfo)
pub fn add_address(&self, interface: &str, info: Ipv4AddressInfo)
Add an IPv4 address to an interface
Sourcepub fn remove_address(&self, interface: &str, ip: Ipv4Address)
pub fn remove_address(&self, interface: &str, ip: Ipv4Address)
Remove an IPv4 address from an interface
Sourcepub fn get_addresses(&self, interface: &str) -> Vec<Ipv4AddressInfo>
pub fn get_addresses(&self, interface: &str) -> Vec<Ipv4AddressInfo>
Get all addresses for an interface
Sourcepub fn get_primary_ip(&self, interface: &str) -> Option<Ipv4Address>
pub fn get_primary_ip(&self, interface: &str) -> Option<Ipv4Address>
Get primary IP address for an interface
Sourcepub fn add_route(&self, entry: RouteEntry)
pub fn add_route(&self, entry: RouteEntry)
Add a route to the routing table
Sourcepub fn remove_route(&self, destination: Ipv4Address, netmask: Ipv4Address)
pub fn remove_route(&self, destination: Ipv4Address, netmask: Ipv4Address)
Remove a route from the routing table
Sourcepub fn set_default_gateway(&self, gateway: Ipv4Address, interface: &str)
pub fn set_default_gateway(&self, gateway: Ipv4Address, interface: &str)
Set default gateway
Sourcepub fn select_source(
&self,
dest: Ipv4Address,
) -> Option<(String, Ipv4Address, Option<Ipv4Address>)>
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)
Sourcefn ip_matches_route(&self, ip: Ipv4Address, route: &RouteEntry) -> bool
fn ip_matches_route(&self, ip: Ipv4Address, route: &RouteEntry) -> bool
Check if an IP matches a route
Sourcefn same_subnet(
&self,
ip1: Ipv4Address,
ip2: Ipv4Address,
mask: Ipv4Address,
) -> bool
fn same_subnet( &self, ip1: Ipv4Address, ip2: Ipv4Address, mask: Ipv4Address, ) -> bool
Check if two IPs are in the same subnet
Sourcepub fn is_local_ip(&self, ip: Ipv4Address) -> bool
pub fn is_local_ip(&self, ip: Ipv4Address) -> bool
Check if an IP is local (assigned to any interface)
Sourcepub fn get_protocol_handler(
&self,
proto_num: u8,
) -> Option<Arc<dyn NetworkLayer>>
pub fn get_protocol_handler( &self, proto_num: u8, ) -> Option<Arc<dyn NetworkLayer>>
Get protocol handler for a protocol number