pub struct ArpLayer {
cache: RwLock<BTreeMap<(String, u32), ArpCacheEntry>>,
pending: RwLock<BTreeMap<(String, u32), ArpPendingEntry>>,
timeout_ticks: u64,
cache_timeout: u64,
stats: RwLock<NetworkLayerStats>,
packet_counter: AtomicU32,
}Expand description
ARP layer
Manages ARP cache and handles ARP requests/replies. Implements NetworkLayer trait for integration with protocol stack.
§Design
The ARP layer is fully interface-aware:
- Cache is per-interface: (interface, IP) -> MAC
- Each interface has its own ARP table
- MAC/IP addresses are obtained from EthernetLayer/Ipv4Layer
Fields§
§cache: RwLock<BTreeMap<(String, u32), ArpCacheEntry>>ARP cache: (interface_name, IP) -> entry
pending: RwLock<BTreeMap<(String, u32), ArpPendingEntry>>Pending ARP resolutions: (interface_name, IP) -> pending entry
timeout_ticks: u64Packet timeout (in ticks)
cache_timeout: u64Cache timeout (in ticks)
stats: RwLock<NetworkLayerStats>Statistics
packet_counter: AtomicU32Counter for packet queueing
Implementations§
Source§impl ArpLayer
impl ArpLayer
Sourcepub fn init(network_manager: &NetworkManager)
pub fn init(network_manager: &NetworkManager)
Initialize and register the ARP layer with NetworkManager
Registers with NetworkManager and registers itself with EthernetLayer for EtherType 0x0806 (ARP).
§Panics
Panics if EthernetLayer is not registered (must be initialized first).
Sourcefn get_local_mac_for_interface(&self, interface: &str) -> Option<[u8; 6]>
fn get_local_mac_for_interface(&self, interface: &str) -> Option<[u8; 6]>
Get local MAC address for an interface from EthernetLayer
Sourcefn get_local_ip_for_interface(&self, interface: &str) -> Option<Ipv4Address>
fn get_local_ip_for_interface(&self, interface: &str) -> Option<Ipv4Address>
Get local IP address for an interface from Ipv4Layer
Sourcefn get_default_interface(&self) -> Option<String>
fn get_default_interface(&self) -> Option<String>
Get default interface name from EthernetLayer
Sourcepub fn lookup_on_interface(
&self,
interface: &str,
ip_address: Ipv4Address,
) -> Option<[u8; 6]>
pub fn lookup_on_interface( &self, interface: &str, ip_address: Ipv4Address, ) -> Option<[u8; 6]>
Look up MAC address for an IP on a specific interface
Sourcepub fn lookup(&self, ip_address: Ipv4Address) -> Option<[u8; 6]>
pub fn lookup(&self, ip_address: Ipv4Address) -> Option<[u8; 6]>
Look up MAC address for an IP (uses default interface)
Sourcepub fn add_entry_on_interface(
&self,
interface: &str,
ip_address: Ipv4Address,
mac_address: [u8; 6],
)
pub fn add_entry_on_interface( &self, interface: &str, ip_address: Ipv4Address, mac_address: [u8; 6], )
Add entry to ARP cache for a specific interface
Sourcepub fn add_entry(&self, ip_address: Ipv4Address, mac_address: [u8; 6])
pub fn add_entry(&self, ip_address: Ipv4Address, mac_address: [u8; 6])
Add entry to ARP cache (uses default interface)
Sourcepub fn remove_entry_on_interface(
&self,
interface: &str,
ip_address: Ipv4Address,
)
pub fn remove_entry_on_interface( &self, interface: &str, ip_address: Ipv4Address, )
Remove entry from ARP cache for a specific interface
Sourcepub fn remove_entry(&self, ip_address: Ipv4Address)
pub fn remove_entry(&self, ip_address: Ipv4Address)
Remove entry from ARP cache (uses default interface)
Sourcepub fn send_request(
&self,
target_ip: Ipv4Address,
context: &LayerContext,
next_layers: &[Arc<dyn NetworkLayer>],
) -> Result<(), SocketError>
pub fn send_request( &self, target_ip: Ipv4Address, context: &LayerContext, next_layers: &[Arc<dyn NetworkLayer>], ) -> Result<(), SocketError>
Send ARP request
§Arguments
target_ip- IP address to resolvecontext- Layer context (may contain “interface” key)next_layers- Layers to pass through (typically Ethernet)
Sourcepub fn receive_packet_on_interface(
&self,
arp_bytes: &[u8],
interface: Option<&str>,
) -> Result<(), SocketError>
pub fn receive_packet_on_interface( &self, arp_bytes: &[u8], interface: Option<&str>, ) -> Result<(), SocketError>
Process received ARP packet
§Arguments
arp_bytes- Raw ARP packet bytesinterface- Interface the packet was received on (optional)
Sourcepub fn receive_packet(&self, arp_bytes: &[u8]) -> Result<(), SocketError>
pub fn receive_packet(&self, arp_bytes: &[u8]) -> Result<(), SocketError>
Process received ARP packet (legacy interface)
Sourcepub fn queue_packet_on_interface(
&self,
interface: &str,
ip_address: Ipv4Address,
packet: Vec<u8>,
)
pub fn queue_packet_on_interface( &self, interface: &str, ip_address: Ipv4Address, packet: Vec<u8>, )
Queue a packet waiting for ARP resolution on a specific interface
Sourcepub fn queue_packet(&self, ip_address: Ipv4Address, packet: Vec<u8>)
pub fn queue_packet(&self, ip_address: Ipv4Address, packet: Vec<u8>)
Queue a packet waiting for ARP resolution (uses default interface)
Sourcefn get_timestamp(&self) -> u64
fn get_timestamp(&self) -> u64
Get current timestamp (placeholder - should use actual system time)
Sourcepub fn is_resolved(&self, ip_address: Ipv4Address) -> bool
pub fn is_resolved(&self, ip_address: Ipv4Address) -> bool
Check if IP address is resolved on default interface
Sourcepub fn is_resolved_on_interface(
&self,
interface: &str,
ip_address: Ipv4Address,
) -> bool
pub fn is_resolved_on_interface( &self, interface: &str, ip_address: Ipv4Address, ) -> bool
Check if IP address is resolved on a specific interface