diff --git a/Cargo.toml b/Cargo.toml index a331262..3772017 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ netlink-packet-utils = { version = "0.5" } netlink-packet-route = { version = "0.17" } netlink-packet-core = { version = "0.7" } netlink-proto = { default-features = false, version = "0.11" } -nix = { version = "0.26.1", default-features = false, features = ["fs", "mount", "sched", "signal"] } +nix = { version = "0.27.1", default-features = false, features = ["fs", "mount", "sched", "signal"] } tokio = { version = "1.0.1", features = ["rt"], optional = true} async-global-executor = { version = "2.0.2", optional = true } diff --git a/src/ns.rs b/src/ns.rs index efc65f8..ad3a17f 100644 --- a/src/ns.rs +++ b/src/ns.rs @@ -10,7 +10,7 @@ use nix::{ }, unistd::{fork, ForkResult}, }; -use std::{option::Option, path::Path, process::exit}; +use std::{option::Option, os::fd::BorrowedFd, path::Path, process::exit}; // if "only" smol or smol+tokio were enabled, we use smol because // it doesn't require an active tokio runtime - just to be sure. @@ -329,7 +329,10 @@ impl NetworkNamespace { } setns_flags.insert(CloneFlags::CLONE_NEWNET); - if let Err(e) = nix::sched::setns(fd, setns_flags) { + if let Err(e) = nix::sched::setns( + unsafe { BorrowedFd::borrow_raw(fd) }, + setns_flags, + ) { log::error!("setns error: {}", e); let err_msg = format!("setns error: {e}"); let _ = nix::unistd::unlink(ns_path); diff --git a/src/traffic_control/add_filter.rs b/src/traffic_control/add_filter.rs index 335870c..64c50d7 100644 --- a/src/traffic_control/add_filter.rs +++ b/src/traffic_control/add_filter.rs @@ -162,7 +162,7 @@ impl TrafficFilterNewRequest { #[cfg(test)] mod test { - use std::{fs::File, os::unix::io::AsRawFd, path::Path}; + use std::{fs::File, os::fd::AsFd, path::Path}; use futures::stream::TryStreamExt; use netlink_packet_route::LinkMessage; @@ -193,7 +193,7 @@ mod test { // entry new ns let ns_path = Path::new(NETNS_PATH); let file = File::open(ns_path.join(path)).unwrap(); - setns(file.as_raw_fd(), CloneFlags::CLONE_NEWNET).unwrap(); + setns(file.as_fd(), CloneFlags::CLONE_NEWNET).unwrap(); Self { path: path.to_string(), @@ -205,7 +205,7 @@ mod test { impl Drop for Netns { fn drop(&mut self) { println!("exit ns: {}", self.path); - setns(self.last.as_raw_fd(), CloneFlags::CLONE_NEWNET).unwrap(); + setns(self.last.as_fd(), CloneFlags::CLONE_NEWNET).unwrap(); let ns_path = Path::new(NETNS_PATH).join(&self.path); nix::mount::umount2(&ns_path, nix::mount::MntFlags::MNT_DETACH) diff --git a/src/traffic_control/add_qdisc.rs b/src/traffic_control/add_qdisc.rs index 0f294cf..1325cfb 100644 --- a/src/traffic_control/add_qdisc.rs +++ b/src/traffic_control/add_qdisc.rs @@ -73,7 +73,7 @@ impl QDiscNewRequest { #[cfg(test)] mod test { - use std::{fs::File, os::unix::io::AsRawFd, path::Path}; + use std::{fs::File, os::fd::AsFd, path::Path}; use futures::stream::TryStreamExt; use nix::sched::{setns, CloneFlags}; @@ -106,7 +106,7 @@ mod test { // entry new ns let ns_path = Path::new(NETNS_PATH); let file = File::open(ns_path.join(path)).unwrap(); - setns(file.as_raw_fd(), CloneFlags::CLONE_NEWNET).unwrap(); + setns(file.as_fd(), CloneFlags::CLONE_NEWNET).unwrap(); Self { path: path.to_string(), @@ -118,7 +118,7 @@ mod test { impl Drop for Netns { fn drop(&mut self) { println!("exit ns: {}", self.path); - setns(self.last.as_raw_fd(), CloneFlags::CLONE_NEWNET).unwrap(); + setns(self.last.as_fd(), CloneFlags::CLONE_NEWNET).unwrap(); let ns_path = Path::new(NETNS_PATH).join(&self.path); nix::mount::umount2(&ns_path, nix::mount::MntFlags::MNT_DETACH)