EthernetLayer

Struct EthernetLayer 

Source
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 handling)

§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

Source

pub fn new() -> Arc<Self>

Create a new Ethernet layer

Source

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.

Source

pub fn register_interface( &self, name: &str, mac: MacAddress, device: Arc<dyn NetworkInterface>, )

Register a network interface

Source

pub fn unregister_interface(&self, name: &str)

Unregister a network interface

Source

pub fn get_interface(&self, name: &str) -> Option<EthernetInterfaceInfo>

Get interface info by name

Source

pub fn get_mac(&self, name: &str) -> Option<MacAddress>

Get MAC address for an interface

Source

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

Get default interface name

Source

pub fn set_default_interface(&self, name: &str)

Set default interface

Source

pub fn list_interfaces(&self) -> Vec<String>

Get all interface names

Source

fn get_device(&self, name: &str) -> Option<Arc<dyn NetworkInterface>>

Get device for an interface

Source

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:

  1. If explicit eth_dst_mac is in context, use it directly
  2. If destination is broadcast IP (255.255.255.255), use broadcast MAC
  3. Otherwise, look up in ARP cache (using next_hop if set, else dst_ip)
§Arguments
  • context - Layer context with addressing info
  • interface - Interface name for per-interface ARP cache lookup
§Returns

MAC address to use as destination, or error if resolution fails

Source

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.

Trait Implementations§

Source§

impl NetworkLayer for EthernetLayer

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, frame: &[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 EthernetLayer

§

impl !RefUnwindSafe for EthernetLayer

§

impl Send for EthernetLayer

§

impl Sync for EthernetLayer

§

impl Unpin for EthernetLayer

§

impl !UnwindSafe for EthernetLayer

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.