From 5f787217cc48e526c6244cd39db4f944fadfcd88 Mon Sep 17 00:00:00 2001 From: Chirantan Ekbote Date: Thu, 31 May 2018 15:31:31 -0700 Subject: net: Allow passing in a configured tap fd on the command line Allow the process that spawned crosvm to pass in a configured tap file descriptor for networking. If this option is provided then crosvm will ignore the other networking related command line flags (like mac address, netmask, etc). Passing in a configured tap device allows us to run crosvm without having to give it CAP_NET_ADMIN. BUG=none TEST=Start a container and verify that networking still works Change-Id: I70b9e6ae030d66c4882e4e48804dc2f29d9874ba Signed-off-by: Chirantan Ekbote Reviewed-on: https://chromium-review.googlesource.com/1081394 Reviewed-by: Zach Reizner --- net_util/src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'net_util') diff --git a/net_util/src/lib.rs b/net_util/src/lib.rs index 273c1ca..0826729 100644 --- a/net_util/src/lib.rs +++ b/net_util/src/lib.rs @@ -449,6 +449,15 @@ impl AsRawFd for Tap { } } +impl FromRawFd for Tap { + unsafe fn from_raw_fd(fd: RawFd) -> Tap { + Tap { + tap_file: File::from_raw_fd(fd), + if_name: [0; 16usize], + } + } +} + pub mod fakes { use super::*; use std::fs::OpenOptions; -- cgit 1.4.1