From b283356679b6d8b7295937673c67a12d1167d5c1 Mon Sep 17 00:00:00 2001 From: Thibaut Vandervelden Date: Thu, 12 May 2022 14:22:44 +0200 Subject: [PATCH] fix mtu calculation for raw raw_socket 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. --- src/phy/raw_socket.rs | 2 +- src/phy/sys/raw_socket.rs | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/phy/raw_socket.rs b/src/phy/raw_socket.rs index 49e7470a1..b266156aa 100644 --- a/src/phy/raw_socket.rs +++ b/src/phy/raw_socket.rs @@ -43,7 +43,7 @@ impl RawSocket { Ok(RawSocket { medium, lower: Rc::new(RefCell::new(lower)), - mtu: mtu, + mtu, }) } } diff --git a/src/phy/sys/raw_socket.rs b/src/phy/sys/raw_socket.rs index 951f358dd..f37fe960f 100644 --- a/src/phy/sys/raw_socket.rs +++ b/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}; @@ -48,11 +47,7 @@ impl RawSocketDesc { } pub fn interface_mtu(&mut self) -> io::Result { - // 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<()> {