summary refs log tree commit diff
path: root/devices/src/virtio/vhost
diff options
context:
space:
mode:
authorStephen Barber <smbarber@chromium.org>2018-02-13 22:47:07 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-02-21 01:06:42 -0800
commit308ff60601994ece51e94c1afa3b0e4d0beaea33 (patch)
tree917593cc724d9cdd42563fd2bd8b003bb1ee2089 /devices/src/virtio/vhost
parent8f002f5c4a4c294b8838560948649b655dd3d772 (diff)
downloadcrosvm-308ff60601994ece51e94c1afa3b0e4d0beaea33.tar
crosvm-308ff60601994ece51e94c1afa3b0e4d0beaea33.tar.gz
crosvm-308ff60601994ece51e94c1afa3b0e4d0beaea33.tar.bz2
crosvm-308ff60601994ece51e94c1afa3b0e4d0beaea33.tar.lz
crosvm-308ff60601994ece51e94c1afa3b0e4d0beaea33.tar.xz
crosvm-308ff60601994ece51e94c1afa3b0e4d0beaea33.tar.zst
crosvm-308ff60601994ece51e94c1afa3b0e4d0beaea33.zip
net_util: add tap support for mac address
Allow get/set for the host mac on the tap interface. Also add read accessors
for the host IP address and netmask, and make using IFF_VNET_HDR optional.

BUG=none
TEST=./build_test

Change-Id: I9999bf5aa8aa35b8cae702d9bc6f94602d6fe32e
Reviewed-on: https://chromium-review.googlesource.com/918406
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Diffstat (limited to 'devices/src/virtio/vhost')
-rw-r--r--devices/src/virtio/vhost/mod.rs2
-rw-r--r--devices/src/virtio/vhost/net.rs11
2 files changed, 10 insertions, 3 deletions
diff --git a/devices/src/virtio/vhost/mod.rs b/devices/src/virtio/vhost/mod.rs
index 1a45c5b..0039a5a 100644
--- a/devices/src/virtio/vhost/mod.rs
+++ b/devices/src/virtio/vhost/mod.rs
@@ -31,6 +31,8 @@ pub enum Error {
     TapSetIp(TapError),
     /// Setting tap netmask failed.
     TapSetNetmask(TapError),
+    /// Setting tap mac address failed.
+    TapSetMacAddress(TapError),
     /// Setting tap interface offload flags failed.
     TapSetOffload(TapError),
     /// Setting vnet header size failed.
diff --git a/devices/src/virtio/vhost/net.rs b/devices/src/virtio/vhost/net.rs
index fa8df76..694dc6a 100644
--- a/devices/src/virtio/vhost/net.rs
+++ b/devices/src/virtio/vhost/net.rs
@@ -10,7 +10,7 @@ use std::sync::atomic::AtomicUsize;
 use std::thread;
 
 use net_sys;
-use net_util::TapT;
+use net_util::{MacAddress, TapT};
 
 use sys_util::{EventFd, GuestMemory};
 use vhost::NetT as VhostNetT;
@@ -41,12 +41,16 @@ where
 {
     /// Create a new virtio network device with the given IP address and
     /// netmask.
-    pub fn new(ip_addr: Ipv4Addr, netmask: Ipv4Addr, mem: &GuestMemory) -> Result<Net<T, U>> {
+    pub fn new(ip_addr: Ipv4Addr,
+               netmask: Ipv4Addr,
+               mac_addr: MacAddress,
+               mem: &GuestMemory) -> Result<Net<T, U>> {
         let kill_evt = EventFd::new().map_err(Error::CreateKillEventFd)?;
 
-        let tap: T = T::new().map_err(Error::TapOpen)?;
+        let tap: T = T::new(true).map_err(Error::TapOpen)?;
         tap.set_ip_addr(ip_addr).map_err(Error::TapSetIp)?;
         tap.set_netmask(netmask).map_err(Error::TapSetNetmask)?;
+        tap.set_mac_address(mac_addr).map_err(Error::TapSetMacAddress)?;
 
         // Set offload flags to match the virtio features below.
         tap.set_offload(
@@ -239,6 +243,7 @@ pub mod tests {
         Net::<FakeTap, FakeNet<FakeTap>>::new(
             Ipv4Addr::new(127, 0, 0, 1),
             Ipv4Addr::new(255, 255, 255, 0),
+            "de:21:e8:47:6b:6a".parse().unwrap(),
             &guest_memory,
         ).unwrap()
     }