Quellcode durchsuchen

Determine MTU in TapInterface instead of hardcoding 1536.

whitequark vor 7 Jahren
Ursprung
Commit
d5610e7826
2 geänderte Dateien mit 12 neuen und 1 gelöschten Zeilen
  1. 10 0
      src/phy/sys/tap_interface.rs
  2. 2 1
      src/phy/tap_interface.rs

+ 10 - 0
src/phy/sys/tap_interface.rs

@@ -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>();

+ 2 - 1
src/phy/tap_interface.rs

@@ -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
         })
     }
 }