Skip to content

Commit

Permalink
Determine MTU in TapInterface instead of hardcoding 1536.
Browse files Browse the repository at this point in the history
whitequark committed Jul 23, 2017
1 parent c5fc8f7 commit d5610e7
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/phy/sys/tap_interface.rs
Original file line number Diff line number Diff line change
@@ -30,6 +30,16 @@ impl TapInterfaceDesc {
ifreq_ioctl(self.lower, &mut self.ifreq, imp::TUNSETIFF).map(|_| ())
}

pub fn interface_mtu(&mut self) -> io::Result<usize> {
let lower = unsafe {
let lower = libc::socket(libc::AF_INET, libc::SOCK_DGRAM, libc::IPPROTO_IP);
if lower == -1 { return Err(io::Error::last_os_error()) }
lower
};

ifreq_ioctl(lower, &mut self.ifreq, imp::SIOCGIFMTU).map(|mtu| mtu as usize)
}

fn wait(&mut self, ms: u32) -> io::Result<bool> {
unsafe {
let mut readfds = mem::uninitialized::<libc::fd_set>();
3 changes: 2 additions & 1 deletion src/phy/tap_interface.rs
Original file line number Diff line number Diff line change
@@ -22,9 +22,10 @@ impl TapInterface {
pub fn new(name: &str) -> io::Result<TapInterface> {
let mut lower = sys::TapInterfaceDesc::new(name)?;
lower.attach_interface()?;
let mtu = lower.interface_mtu()?;
Ok(TapInterface {
lower: Rc::new(RefCell::new(lower)),
mtu: 1536 // FIXME: get the real value somehow
mtu: mtu
})
}
}

0 comments on commit d5610e7

Please sign in to comment.