diff options
author | Chirantan Ekbote <chirantan@chromium.org> | 2018-11-16 13:26:53 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-01-07 19:40:14 -0800 |
commit | 49fa08f17b00527ce5ed23600fb3c53ce3533113 (patch) | |
tree | 3a23e8421ed11a53f9e1f81b78e2ab16397f4c19 /src/linux.rs | |
parent | 7a97366e961ea0260e16fdcd03ef37a2abd898b2 (diff) | |
download | crosvm-49fa08f17b00527ce5ed23600fb3c53ce3533113.tar crosvm-49fa08f17b00527ce5ed23600fb3c53ce3533113.tar.gz crosvm-49fa08f17b00527ce5ed23600fb3c53ce3533113.tar.bz2 crosvm-49fa08f17b00527ce5ed23600fb3c53ce3533113.tar.lz crosvm-49fa08f17b00527ce5ed23600fb3c53ce3533113.tar.xz crosvm-49fa08f17b00527ce5ed23600fb3c53ce3533113.tar.zst crosvm-49fa08f17b00527ce5ed23600fb3c53ce3533113.zip |
net_util: Get tap interface name when using a raw fd
We use the tap device interface name in some ioctls. When we are creating a Tap struct from a raw fd make sure that we also grab the interface name so that these ioctls don't fail later. BUG=b:80150167 TEST=run the plugin_net_config test Change-Id: Ic308ebd55d0545c1b445fc6abdf017fdc7ab594b Signed-off-by: Chirantan Ekbote <chirantan@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1341104
Diffstat (limited to 'src/linux.rs')
-rw-r--r-- | src/linux.rs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/linux.rs b/src/linux.rs index 5f607fb..35bb98f 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -29,7 +29,7 @@ use devices::{self, PciDevice, VirtioPciDevice}; use io_jail::{self, Minijail}; use kvm::*; use msg_socket::{MsgReceiver, MsgSender, UnlinkMsgSocket}; -use net_util::Tap; +use net_util::{Error as NetError, Tap}; use qcow::{self, ImageType, QcowFile}; use sys_util; use sys_util::*; @@ -56,6 +56,7 @@ pub enum Error { CreatePollContext(sys_util::Error), CreateSignalFd(sys_util::SignalFdError), CreateSocket(io::Error), + CreateTapDevice(NetError), CreateTimerFd(sys_util::Error), DetectImageType(qcow::Error), DeviceJail(io_jail::Error), @@ -108,6 +109,7 @@ impl fmt::Display for Error { Error::CreatePollContext(e) => write!(f, "failed to create poll context: {:?}", e), Error::CreateSignalFd(e) => write!(f, "failed to create signalfd: {:?}", e), Error::CreateSocket(e) => write!(f, "failed to create socket: {}", e), + Error::CreateTapDevice(e) => write!(f, "failed to create tap device: {:?}", e), Error::CreateTimerFd(e) => write!(f, "failed to create timerfd: {}", e), Error::DetectImageType(e) => write!(f, "failed to detect disk image type: {:?}", e), Error::DeviceJail(e) => write!(f, "failed to jail device: {}", e), @@ -309,7 +311,10 @@ fn create_virtio_devs( // We checked above that if the IP is defined, then the netmask is, too. if let Some(tap_fd) = cfg.tap_fd { // Safe because we ensure that we get a unique handle to the fd. - let tap = unsafe { Tap::from_raw_fd(validate_raw_fd(tap_fd)?) }; + let tap = unsafe { + Tap::from_raw_fd(validate_raw_fd(tap_fd).map_err(Error::ValidateRawFd)?) + .map_err(Error::CreateTapDevice)? + }; let net_box = Box::new(devices::virtio::Net::from(tap).map_err(Error::NetDeviceNew)?); let jail = if cfg.multiprocess { |