ArpLayer

Struct ArpLayer 

Source
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: u64

Packet timeout (in ticks)

§cache_timeout: u64

Cache timeout (in ticks)

§stats: RwLock<NetworkLayerStats>

Statistics

§packet_counter: AtomicU32

Counter for packet queueing

Implementations§

Source§

impl ArpLayer

Source

pub fn new() -> Arc<Self>

Create a new ARP layer

Source

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).

Source

fn get_local_mac_for_interface(&self, interface: &str) -> Option<[u8; 6]>

Get local MAC address for an interface from EthernetLayer

Source

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

Get local IP address for an interface from Ipv4Layer

Source

fn get_default_interface(&self) -> Option<String>

Get default interface name from EthernetLayer

Source

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

Source

pub fn lookup(&self, ip_address: Ipv4Address) -> Option<[u8; 6]>

Look up MAC address for an IP (uses default interface)

Source

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

Source

pub fn add_entry(&self, ip_address: Ipv4Address, mac_address: [u8; 6])

Add entry to ARP cache (uses default interface)

Source

pub fn remove_entry_on_interface( &self, interface: &str, ip_address: Ipv4Address, )

Remove entry from ARP cache for a specific interface

Source

pub fn remove_entry(&self, ip_address: Ipv4Address)

Remove entry from ARP cache (uses default interface)

Source

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 resolve
  • context - Layer context (may contain “interface” key)
  • next_layers - Layers to pass through (typically Ethernet)
Source

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 bytes
  • interface - Interface the packet was received on (optional)
Source

pub fn receive_packet(&self, arp_bytes: &[u8]) -> Result<(), SocketError>

Process received ARP packet (legacy interface)

Source

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

Source

pub fn queue_packet(&self, ip_address: Ipv4Address, packet: Vec<u8>)

Queue a packet waiting for ARP resolution (uses default interface)

Source

fn get_timestamp(&self) -> u64

Get current timestamp (placeholder - should use actual system time)

Source

pub fn is_resolved(&self, ip_address: Ipv4Address) -> bool

Check if IP address is resolved on default interface

Source

pub fn is_resolved_on_interface( &self, interface: &str, ip_address: Ipv4Address, ) -> bool

Check if IP address is resolved on a specific interface

Trait Implementations§

Source§

impl NetworkLayer for ArpLayer

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 ArpLayer

§

impl !RefUnwindSafe for ArpLayer

§

impl Send for ArpLayer

§

impl Sync for ArpLayer

§

impl Unpin for ArpLayer

§

impl !UnwindSafe for ArpLayer

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.