mtu: per-interface MTU configuration via netcfg
LinkDevice trait gains set_mtu(mtu) with default no-op. EthernetLink stores mtu in field, clamped to 576-9000 (RFC 791 min/max). netcfg/ifaces/eth0/mtu becomes rw: cat /scheme/netcfg/ifaces/eth0/mtu → '1500' (default) echo 1400 > .../mtu → VPN MTU echo 9000 > .../mtu → jumbo frames Clamped to [576, 9000]: - 576: minimum for IPv4 (RFC 791) - 9000: standard jumbo frame MTU Useful for VPNs (MTU 1400 to avoid fragmentation through tunnel overhead), jumbo frames (MTU 9000 on datacenter networks), and constrained paths.
This commit is contained in:
@@ -86,6 +86,7 @@ pub struct EthernetLink {
|
||||
hardware_address: Option<EthernetAddress>,
|
||||
ip_address: Option<IpCidr>,
|
||||
qdisc_config: QdiscConfig,
|
||||
mtu: usize,
|
||||
stats: Stats,
|
||||
arp_requests: u64,
|
||||
arp_replies: u64,
|
||||
@@ -121,6 +122,7 @@ impl EthernetLink {
|
||||
ndp_state: Default::default(),
|
||||
slaac_state: Default::default(),
|
||||
qdisc_config: QdiscConfig::default(),
|
||||
mtu: Self::MTU,
|
||||
stats: Stats::default(),
|
||||
neighbor_cache: Default::default(),
|
||||
arp_requests: 0,
|
||||
@@ -894,5 +896,13 @@ impl LinkDevice for EthernetLink {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn mtu(&self) -> usize {
|
||||
self.mtu
|
||||
}
|
||||
|
||||
fn set_mtu(&mut self, mtu: usize) {
|
||||
self.mtu = mtu.clamp(576, 9000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,8 @@ pub trait LinkDevice {
|
||||
1500
|
||||
}
|
||||
|
||||
fn set_mtu(&mut self, _mtu: usize) {}
|
||||
|
||||
fn link_state(&self) -> &'static str {
|
||||
"unknown"
|
||||
}
|
||||
|
||||
@@ -452,12 +452,25 @@ fn mk_root_node(
|
||||
}
|
||||
},
|
||||
"mtu" => {
|
||||
ro [devices] || {
|
||||
rw [devices] (Option<usize>, None)
|
||||
|| {
|
||||
match devices.borrow().get("eth0") {
|
||||
Some(dev) => format!("{}\n", dev.mtu()),
|
||||
None => "Device not found\n".into(),
|
||||
}
|
||||
}
|
||||
|cur_value, line| {
|
||||
let mtu = line.trim().parse::<usize>()
|
||||
.map_err(|_| SyscallError::new(syscall::EINVAL))?;
|
||||
if let Some(dev) = devices.borrow_mut().get_mut("eth0") {
|
||||
dev.set_mtu(mtu);
|
||||
*cur_value = Some(mtu);
|
||||
Ok(())
|
||||
} else {
|
||||
Err(SyscallError::new(syscall::ENODEV))
|
||||
}
|
||||
}
|
||||
|_cur_value| { Ok(()) }
|
||||
},
|
||||
"qdisc" => {
|
||||
ro [devices] || {
|
||||
|
||||
Reference in New Issue
Block a user