diff --git a/src/agent/Cargo.toml b/src/agent/Cargo.toml index 8050d02ce2..a13d9a94e1 100644 --- a/src/agent/Cargo.toml +++ b/src/agent/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" oci = { path = "oci" } rustjail = { path = "rustjail" } protocols = { path = "protocols" } +netlink = { path = "netlink" } lazy_static = "1.3.0" error-chain = "0.12.1" grpcio = { git="https://github.com/alipay/grpc-rs", branch="rust_agent" } diff --git a/src/agent/netlink/Cargo.toml b/src/agent/netlink/Cargo.toml new file mode 100644 index 0000000000..2b2bf0af5f --- /dev/null +++ b/src/agent/netlink/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "netlink" +version = "0.1.0" +authors = ["Yang Bo "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +libc = "0.2.58" +nix = "0.14.1" +protobuf = "2.6.1" +rustjail = { path = "../rustjail" } +protocols = { path = "../protocols" } +slog = { version = "2.5.2", features = ["dynamic-keys", "max_level_trace", "release_max_level_info"] } +slog-json = "2.3.0" +slog-async = "2.3.0" +slog-scope = "4.1.2" +scan_fmt = "0.2.3" diff --git a/src/agent/src/netlink.rs b/src/agent/netlink/src/lib.rs similarity index 99% rename from src/agent/src/netlink.rs rename to src/agent/netlink/src/lib.rs index 9749645c06..b484d6b6f3 100644 --- a/src/agent/src/netlink.rs +++ b/src/agent/netlink/src/lib.rs @@ -6,8 +6,24 @@ #![allow(non_camel_case_types)] #![allow(non_upper_case_globals)] #![allow(dead_code)] +#![allow(unused_parens)] +#![allow(unused_unsafe)] + +extern crate libc; +extern crate nix; +extern crate protobuf; +extern crate protocols; +extern crate rustjail; + +#[macro_use] +extern crate slog; +extern crate slog_async; +extern crate slog_json; +extern crate slog_scope; + +#[macro_use] +extern crate scan_fmt; -use libc; use nix::errno::Errno; use protobuf::RepeatedField; use protocols::types::{IPAddress, IPFamily, Interface, Route}; @@ -2834,7 +2850,7 @@ impl From for RtIPAddr { #[cfg(test)] mod tests { - use crate::netlink::{nlmsghdr, NLMSG_ALIGNTO, RTA_ALIGNTO, RTM_BASE}; + use crate::{nlmsghdr, NLMSG_ALIGNTO, RTA_ALIGNTO, RTM_BASE}; use libc; use std::mem; #[test] diff --git a/src/agent/src/grpc.rs b/src/agent/src/grpc.rs index afe716c75d..441b7120c3 100644 --- a/src/agent/src/grpc.rs +++ b/src/agent/src/grpc.rs @@ -33,10 +33,10 @@ use crate::device::{add_devices, rescan_pci_bus}; use crate::linux_abi::*; use crate::mount::{add_storages, remove_mounts, STORAGEHANDLERLIST}; use crate::namespace::{NSTYPEIPC, NSTYPEPID, NSTYPEUTS}; -use crate::netlink::{RtnlHandle, NETLINK_ROUTE}; use crate::random; use crate::sandbox::Sandbox; use crate::version::{AGENT_VERSION, API_VERSION}; +use netlink::{RtnlHandle, NETLINK_ROUTE}; use libc::{self, c_ushort, pid_t, winsize, TIOCSWINSZ}; use serde_json; diff --git a/src/agent/src/main.rs b/src/agent/src/main.rs index 6f34bb0119..a408922493 100644 --- a/src/agent/src/main.rs +++ b/src/agent/src/main.rs @@ -24,6 +24,8 @@ extern crate oci; extern crate slog; extern crate slog_async; extern crate slog_json; +#[macro_use] +extern crate netlink; use futures::*; use nix::sys::wait::{self, WaitStatus}; @@ -48,7 +50,6 @@ mod linux_abi; mod logging; mod mount; mod namespace; -pub mod netlink; mod network; pub mod random; mod sandbox; diff --git a/src/agent/src/sandbox.rs b/src/agent/src/sandbox.rs index 13f365bc74..ea900bcee0 100644 --- a/src/agent/src/sandbox.rs +++ b/src/agent/src/sandbox.rs @@ -7,9 +7,9 @@ use crate::linux_abi::*; use crate::mount::{get_mount_fs_type, remove_mounts, TYPEROOTFS}; use crate::namespace::Namespace; -use crate::netlink::{RtnlHandle, NETLINK_ROUTE}; use crate::network::Network; use libc::pid_t; +use netlink::{RtnlHandle, NETLINK_ROUTE}; use protocols::agent::OnlineCPUMemRequest; use regex::Regex; use rustjail::cgroups; diff --git a/src/agent/src/uevent.rs b/src/agent/src/uevent.rs index 9165a155d3..de79705ec4 100644 --- a/src/agent/src/uevent.rs +++ b/src/agent/src/uevent.rs @@ -5,9 +5,9 @@ use crate::device::online_device; use crate::linux_abi::*; -use crate::netlink::{RtnlHandle, NETLINK_UEVENT}; use crate::sandbox::Sandbox; use crate::GLOBAL_DEVICE_WATCHER; +use netlink::{RtnlHandle, NETLINK_UEVENT}; use slog::Logger; use std::sync::{Arc, Mutex}; use std::thread;