summary refs log tree commit diff
path: root/net_util
diff options
context:
space:
mode:
authorJorge E. Moreira <jemoreira@google.com>2019-03-15 18:07:01 -0700
committerchrome-bot <chrome-bot@chromium.org>2019-03-28 11:17:26 -0700
commit96e26c2681ee73b6a1e1d2d99aa53a1d21fa494b (patch)
tree8ad061ef85a94ecfe58ae391e18236c2a09b07de /net_util
parent788d0de96acdb1a480a32c46c4622f0891af11fe (diff)
downloadcrosvm-96e26c2681ee73b6a1e1d2d99aa53a1d21fa494b.tar
crosvm-96e26c2681ee73b6a1e1d2d99aa53a1d21fa494b.tar.gz
crosvm-96e26c2681ee73b6a1e1d2d99aa53a1d21fa494b.tar.bz2
crosvm-96e26c2681ee73b6a1e1d2d99aa53a1d21fa494b.tar.lz
crosvm-96e26c2681ee73b6a1e1d2d99aa53a1d21fa494b.tar.xz
crosvm-96e26c2681ee73b6a1e1d2d99aa53a1d21fa494b.tar.zst
crosvm-96e26c2681ee73b6a1e1d2d99aa53a1d21fa494b.zip
Validate and configure tap interfaces from --tap_fd
Checks for the IFF_NO_PI and IFF_VNET_HDR flags, failing if those are
not set.
Sets the offload and vnet header sizes to the required values, instead
of trusting the values on the interface.

Bug=b/128686192

Change-Id: Ibbbfbf3cdedd6e64cdcfb446bcdfb26b4fd38395
Reviewed-on: https://chromium-review.googlesource.com/1526771
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Diffstat (limited to 'net_util')
-rw-r--r--net_util/src/lib.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/net_util/src/lib.rs b/net_util/src/lib.rs
index 066b7d8..456608c 100644
--- a/net_util/src/lib.rs
+++ b/net_util/src/lib.rs
@@ -170,6 +170,7 @@ impl Display for MacAddress {
 pub struct Tap {
     tap_file: File,
     if_name: [u8; 16usize],
+    if_flags: ::std::os::raw::c_short,
 }
 
 impl Tap {
@@ -187,6 +188,7 @@ impl Tap {
         Ok(Tap {
             tap_file,
             if_name: ifreq.ifr_ifrn.ifrn_name.as_ref().clone(),
+            if_flags: ifreq.ifr_ifru.ifru_flags.as_ref().clone(),
         })
     }
 }
@@ -225,6 +227,9 @@ pub trait TapT: Read + Write + AsRawFd + Send + Sized {
     fn set_vnet_hdr_size(&self, size: c_int) -> Result<()>;
 
     fn get_ifreq(&self) -> net_sys::ifreq;
+
+    /// Get the interface flags
+    fn if_flags(&self) -> u32;
 }
 
 impl TapT for Tap {
@@ -278,6 +283,7 @@ impl TapT for Tap {
         Ok(Tap {
             tap_file: tuntap,
             if_name: unsafe { *ifreq.ifr_ifrn.ifrn_name.as_ref() },
+            if_flags: unsafe { *ifreq.ifr_ifru.ifru_flags.as_ref() },
         })
     }
 
@@ -465,8 +471,22 @@ impl TapT for Tap {
             ifrn_name.clone_from_slice(&self.if_name);
         }
 
+        // This sets the flags with which the interface was created, which is the only entry we set
+        // on the second union.
+        unsafe {
+            ifreq
+                .ifr_ifru
+                .ifru_flags
+                .as_mut()
+                .clone_from(&self.if_flags);
+        }
+
         ifreq
     }
+
+    fn if_flags(&self) -> u32 {
+        self.if_flags as u32
+    }
 }
 
 impl Read for Tap {
@@ -554,6 +574,10 @@ pub mod fakes {
             let ifreq: net_sys::ifreq = Default::default();
             ifreq
         }
+
+        fn if_flags(&self) -> u32 {
+            net_sys::IFF_TAP
+        }
     }
 
     impl Drop for FakeTap {