Skip to content

Commit

Permalink
fix mtu calculation for raw raw_socket
Browse files Browse the repository at this point in the history
Previously, the ethernet frame header was added twice to the MTU. The
first time in `interface_mtu` and a second time after calling
`interface_mtu` in the raw socket `new` function. I removed the one in
the `interface_mtu` function.
  • Loading branch information
thvdveld committed May 12, 2022
1 parent 71a328b commit b283356
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/phy/raw_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl RawSocket {
Ok(RawSocket {
medium,
lower: Rc::new(RefCell::new(lower)),
mtu: mtu,
mtu,
})
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/phy/sys/raw_socket.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::*;
use crate::phy::Medium;
use crate::wire::EthernetFrame;
use std::os::unix::io::{AsRawFd, RawFd};
use std::{io, mem};

Expand Down Expand Up @@ -48,11 +47,7 @@ impl RawSocketDesc {
}

pub fn interface_mtu(&mut self) -> io::Result<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())
ifreq_ioctl(self.lower, &mut self.ifreq, imp::SIOCGIFMTU).map(|mtu| mtu as usize)
}

pub fn bind_interface(&mut self) -> io::Result<()> {
Expand Down

0 comments on commit b283356

Please sign in to comment.