pub struct EthernetLayer {
interfaces: RwLock<BTreeMap<String, EthernetInterfaceInfo>>,
devices: RwLock<BTreeMap<String, Arc<dyn NetworkInterface>>>,
default_interface: RwLock<Option<String>>,
protocols: RwLock<BTreeMap<u16, Arc<dyn NetworkLayer>>>,
stats: RwLock<NetworkLayerStats>,
}Expand description
Ethernet layer
Handles Ethernet II frame encapsulation and decapsulation. Manages multiple interfaces and routes frames based on EtherType field.
Fields§
§interfaces: RwLock<BTreeMap<String, EthernetInterfaceInfo>>Registered interfaces: name -> info
devices: RwLock<BTreeMap<String, Arc<dyn NetworkInterface>>>Interface devices: name -> device (kept separate for Arc
default_interface: RwLock<Option<String>>Default interface name
protocols: RwLock<BTreeMap<u16, Arc<dyn NetworkLayer>>>Protocol handlers registered by EtherType
stats: RwLock<NetworkLayerStats>Statistics
Implementations§
Source§impl EthernetLayer
impl EthernetLayer
Sourcepub fn init(network_manager: &NetworkManager)
pub fn init(network_manager: &NetworkManager)
Initialize and register the Ethernet layer with NetworkManager
This is the first layer to be initialized as it has no dependencies. Other layers (IPv4, ARP) will register their protocols with this layer.
Sourcepub fn register_interface(
&self,
name: &str,
mac: MacAddress,
device: Arc<dyn NetworkInterface>,
)
pub fn register_interface( &self, name: &str, mac: MacAddress, device: Arc<dyn NetworkInterface>, )
Register a network interface
Sourcepub fn unregister_interface(&self, name: &str)
pub fn unregister_interface(&self, name: &str)
Unregister a network interface
Sourcepub fn get_interface(&self, name: &str) -> Option<EthernetInterfaceInfo>
pub fn get_interface(&self, name: &str) -> Option<EthernetInterfaceInfo>
Get interface info by name
Sourcepub fn get_mac(&self, name: &str) -> Option<MacAddress>
pub fn get_mac(&self, name: &str) -> Option<MacAddress>
Get MAC address for an interface
Sourcepub fn get_default_interface(&self) -> Option<String>
pub fn get_default_interface(&self) -> Option<String>
Get default interface name
Sourcepub fn set_default_interface(&self, name: &str)
pub fn set_default_interface(&self, name: &str)
Set default interface
Sourcepub fn list_interfaces(&self) -> Vec<String>
pub fn list_interfaces(&self) -> Vec<String>
Get all interface names
Sourcefn get_device(&self, name: &str) -> Option<Arc<dyn NetworkInterface>>
fn get_device(&self, name: &str) -> Option<Arc<dyn NetworkInterface>>
Get device for an interface
Sourcefn resolve_dest_mac(
&self,
context: &LayerContext,
interface: &str,
) -> Result<[u8; 6], SocketError>
fn resolve_dest_mac( &self, context: &LayerContext, interface: &str, ) -> Result<[u8; 6], SocketError>
Resolve destination MAC address for sending
This method determines the destination MAC address for an outgoing packet:
- If explicit
eth_dst_macis in context, use it directly - If destination is broadcast IP (255.255.255.255), use broadcast MAC
- Otherwise, look up in ARP cache (using
next_hopif set, elsedst_ip)
§Arguments
context- Layer context with addressing infointerface- Interface name for per-interface ARP cache lookup
§Returns
MAC address to use as destination, or error if resolution fails
Sourcepub fn receive_on_interface(
&self,
frame: &[u8],
interface: &str,
) -> Result<(), SocketError>
pub fn receive_on_interface( &self, frame: &[u8], interface: &str, ) -> Result<(), SocketError>
Receive a frame on a specific interface
This method should be called by drivers to process incoming frames. It passes the interface name to upper layers via context.