Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix mtu calculation for raw_socket #611

Merged
merged 1 commit into from May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/phy/raw_socket.rs
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
@@ -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