diff --git a/src/phy/sys/raw_socket.rs b/src/phy/sys/raw_socket.rs index 2b60bd7..368f62d 100644 --- a/src/phy/sys/raw_socket.rs +++ b/src/phy/sys/raw_socket.rs @@ -2,6 +2,7 @@ use std::{mem, io}; use std::os::unix::io::{RawFd, AsRawFd}; use libc; use super::*; +use crate::wire::EthernetFrame; #[derive(Debug)] pub struct RawSocketDesc { @@ -31,7 +32,10 @@ impl RawSocketDesc { } pub fn interface_mtu(&mut self) -> io::Result { - ifreq_ioctl(self.lower, &mut self.ifreq, imp::SIOCGIFMTU).map(|mtu| mtu as usize) + // SIOCGIFMTU returns the IP MTU (typically 1500 bytes.) + // smoltcp counts the entire Ethernet packet in the MTU, so add the Ethernet header size to it. + let ip_mtu = ifreq_ioctl(self.lower, &mut self.ifreq, imp::SIOCGIFMTU).map(|mtu| mtu as usize)?; + Ok(ip_mtu + EthernetFrame::<&[u8]>::header_len()) } pub fn bind_interface(&mut self) -> io::Result<()> { diff --git a/src/phy/sys/tap_interface.rs b/src/phy/sys/tap_interface.rs index f89597f..29b1ffa 100644 --- a/src/phy/sys/tap_interface.rs +++ b/src/phy/sys/tap_interface.rs @@ -2,6 +2,7 @@ use std::io; use std::os::unix::io::{RawFd, AsRawFd}; use libc; use super::*; +use crate::wire::EthernetFrame; #[derive(Debug)] pub struct TapInterfaceDesc { @@ -42,11 +43,13 @@ impl TapInterfaceDesc { lower }; - let mtu = ifreq_ioctl(lower, &mut self.ifreq, imp::SIOCGIFMTU).map(|mtu| mtu as usize); + let ip_mtu = ifreq_ioctl(lower, &mut self.ifreq, imp::SIOCGIFMTU).map(|mtu| mtu as usize); unsafe { libc::close(lower); } - mtu + // SIOCGIFMTU returns the IP MTU (typically 1500 bytes.) + // smoltcp counts the entire Ethernet packet in the MTU, so add the Ethernet header size to it. + Ok(ip_mtu? + EthernetFrame::<&[u8]>::header_len()) } pub fn recv(&mut self, buffer: &mut [u8]) -> io::Result {