pub struct NetworkInterface {
name: String,
mac_address: EthernetAddress,
device: Arc<dyn NetDevice>,
ip_addresses: SpinLock<Vec<IpCidr>>,
ipv4_gateway: SpinLock<Option<Ipv4Address>>,
interrupt_enabled: SpinLock<bool>,
last_interrupt_time: SpinLock<Instant>,
}Expand description
网络接口
Fields§
§name: String§mac_address: EthernetAddress§device: Arc<dyn NetDevice>§ip_addresses: SpinLock<Vec<IpCidr>>§ipv4_gateway: SpinLock<Option<Ipv4Address>>§interrupt_enabled: SpinLock<bool>§last_interrupt_time: SpinLock<Instant>Implementations§
Source§impl NetworkInterface
impl NetworkInterface
Sourcepub fn mac_address(&self) -> EthernetAddress
pub fn mac_address(&self) -> EthernetAddress
获取MAC地址
Sourcepub fn add_ip_address(&self, ip_cidr: IpCidr)
pub fn add_ip_address(&self, ip_cidr: IpCidr)
设置IP地址
Sourcepub fn ip_addresses(&self) -> Vec<IpCidr>
pub fn ip_addresses(&self) -> Vec<IpCidr>
获取所有IP地址
Sourcepub fn set_ipv4_gateway(&self, gateway: Option<Ipv4Address>)
pub fn set_ipv4_gateway(&self, gateway: Option<Ipv4Address>)
设置IPv4网关
Sourcepub fn ipv4_gateway(&self) -> Option<Ipv4Address>
pub fn ipv4_gateway(&self) -> Option<Ipv4Address>
获取IPv4网关
Sourcepub fn enable_interrupt(&self)
pub fn enable_interrupt(&self)
启用中断
Sourcepub fn disable_interrupt(&self)
pub fn disable_interrupt(&self)
禁用中断
Sourcepub fn is_interrupt_enabled(&self) -> bool
pub fn is_interrupt_enabled(&self) -> bool
检查中断是否启用
Sourcepub fn update_interrupt_time(&self)
pub fn update_interrupt_time(&self)
更新最后中断时间
Sourcepub fn create_smoltcp_interface(&self) -> SmoltcpInterface
pub fn create_smoltcp_interface(&self) -> SmoltcpInterface
创建smoltcp以太网接口
返回一个 SmoltcpInterface 包装器,它拥有 NetDeviceAdapter 和 Interface, 确保两者有相同的生命周期,避免悬垂指针问题。
Trait Implementations§
Source§impl Driver for NetworkInterface
实现Driver trait
impl Driver for NetworkInterface
实现Driver trait
fn try_handle_interrupt(&self, irq: Option<usize>) -> bool
fn device_type(&self) -> DeviceType
fn get_id(&self) -> String
Source§fn as_net_arc(self: Arc<Self>) -> Option<Arc<dyn NetDevice>>
fn as_net_arc(self: Arc<Self>) -> Option<Arc<dyn NetDevice>>
将驱动程序转换为网络驱动程序 Arc(如果适用)
Source§fn as_block(&self) -> Option<&dyn BlockDriver>
fn as_block(&self) -> Option<&dyn BlockDriver>
将驱动程序转换为块设备驱动程序(如果适用)
Source§fn as_block_arc(self: Arc<Self>) -> Option<Arc<dyn BlockDriver>>
fn as_block_arc(self: Arc<Self>) -> Option<Arc<dyn BlockDriver>>
将驱动程序转换为块设备驱动程序 Arc(如果适用)
Source§fn as_rtc_arc(self: Arc<Self>) -> Option<Arc<dyn RtcDriver>>
fn as_rtc_arc(self: Arc<Self>) -> Option<Arc<dyn RtcDriver>>
将驱动程序转换为实时时钟驱动程序 Arc(如果适用)
Source§fn as_serial(&self) -> Option<&dyn SerialDriver>
fn as_serial(&self) -> Option<&dyn SerialDriver>
将驱动程序转换为串口驱动程序(如果适用)