Skip to content

Commit e1aed24

Browse files
committed
tap: keeping only an fd around after jailing...
is not a correct option for making use of /dev/net/tun. We need to obtain an fd everytime we create a tap interface. Signed-off-by: Diana Popa <[email protected]>
1 parent 7207fde commit e1aed24

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

net_util/src/tap.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,13 @@ impl Tap {
6363
pub fn open_named(if_name: &str) -> Result<Tap> {
6464
let terminated_if_name = build_terminated_if_name(if_name)?;
6565

66-
let fd = if ::data_model::FIRECRACKER_IS_JAILED.load(::std::sync::atomic::Ordering::Relaxed)
67-
{
68-
// This is the /dev/net/tun fd inherited from the jailer.
69-
::jailer::DEV_NET_TUN_FD
70-
} else {
71-
unsafe {
72-
// Open calls are safe because we give a constant nul-terminated
73-
// string and verify the result.
74-
libc::open(
75-
b"/dev/net/tun\0".as_ptr() as *const c_char,
76-
libc::O_RDWR | libc::O_NONBLOCK | libc::O_CLOEXEC,
77-
)
78-
}
66+
let fd = unsafe {
67+
// Open calls are safe because we give a constant null-terminated
68+
// string and verify the result.
69+
libc::open(
70+
b"/dev/net/tun\0".as_ptr() as *const c_char,
71+
libc::O_RDWR | libc::O_NONBLOCK | libc::O_CLOEXEC,
72+
)
7973
};
8074
if fd < 0 {
8175
return Err(Error::OpenTun(IoError::last_os_error()));

0 commit comments

Comments
 (0)