From 0a8a962e940add17a78b3053316610396dcbded3 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sun, 24 Sep 2017 23:51:19 +0000 Subject: [PATCH] Reorganize features using namespaces, to match module hierarchy. I'm about to add a whole lot more features, and it's going to get quite confusing otherwise. --- .travis.yml | 14 ++++++++++---- Cargo.toml | 6 +++--- README.md | 14 ++++++++------ src/lib.rs | 2 +- src/phy/mod.rs | 12 ++++++------ src/phy/sys/linux.rs | 13 +++++++------ src/phy/sys/mod.rs | 8 ++++---- 7 files changed, 39 insertions(+), 30 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5bb6fee..04b8cf0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,22 @@ language: rust matrix: include: + # litmus check that we work on stable/beta - rust: stable - env: FEATURES='std raw_socket tap_interface' MODE='test' + env: FEATURES='default' MODE='test' - rust: beta - env: FEATURES='std raw_socket tap_interface' MODE='test' + env: FEATURES='default' MODE='test' + # actually test everything - rust: nightly - env: FEATURES='std raw_socket tap_interface' MODE='test' + env: FEATURES='default' MODE='test' - rust: nightly - env: FEATURES='std raw_socket tap_interface log' MODE='test' + env: FEATURES='std' MODE='test' - rust: nightly env: FEATURES='alloc' MODE='build' + - rust: nightly + env: FEATURES='phy-raw_socket' MODE='build' + - rust: nightly + env: FEATURES='phy-tap_interface' MODE='build' - rust: nightly env: FEATURES='' MODE='build' script: diff --git a/Cargo.toml b/Cargo.toml index b65e9fe..21912f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,9 +26,9 @@ getopts = "0.2" std = ["managed/std"] alloc = ["managed/alloc"] verbose = [] -raw_socket = ["libc"] -tap_interface = ["libc"] -default = ["std", "raw_socket", "tap_interface", "log", "verbose"] +"phy-raw_socket" = ["std", "libc"] +"phy-tap_interface" = ["std", "libc"] +default = ["std", "log", "phy-raw_socket", "phy-tap_interface"] [[example]] name = "tcpdump" diff --git a/README.md b/README.md index eaee59f..dacd4f8 100644 --- a/README.md +++ b/README.md @@ -94,17 +94,13 @@ dependency on `std::boxed::Box` and `std::vec::Vec`. This feature is enabled by default. -### Features `raw_socket` and `tap_interface` - -Enable `smoltcp::phy::RawSocket` and `smoltcp::phy::TapInterface`, respectively. - -These features are enabled by default. - ### Feature `alloc` The `alloc` feature enables use of objects owned by the networking stack through a dependency on collections from the `alloc` crate. This only works on nightly rustc. +This feature is disabled by default. + ### Feature `log` The `log` feature enables logging of events within the networking stack through @@ -125,6 +121,12 @@ or `BufWriter` is used, which are of course not available on heap-less systems. This feature is disabled by default. +### Features `phy-raw_socket` and `phy-tap_interface` + +Enable `smoltcp::phy::RawSocket` and `smoltcp::phy::TapInterface`, respectively. + +These features are enabled by default. + ## Hosted usage examples _smoltcp_, being a freestanding networking stack, needs to be able to transmit and receive diff --git a/src/lib.rs b/src/lib.rs index f799f3a..093d78e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,7 +72,7 @@ extern crate managed; #[cfg(any(test, feature = "std"))] #[macro_use] extern crate std; -#[cfg(any(feature = "raw_socket", feature="tap_interface"))] +#[cfg(any(feature = "phy-raw_socket", feature = "phy-tap_interface"))] extern crate libc; #[cfg(feature = "alloc")] extern crate alloc; diff --git a/src/phy/mod.rs b/src/phy/mod.rs index 7615f4d..894b252 100644 --- a/src/phy/mod.rs +++ b/src/phy/mod.rs @@ -106,7 +106,7 @@ impl Drop for EthernetTxBuffer { use Result; -#[cfg(any(feature = "raw_socket", feature = "tap_interface"))] +#[cfg(any(feature = "phy-raw_socket", feature = "phy-tap_interface"))] mod sys; mod tracer; @@ -114,12 +114,12 @@ mod fault_injector; mod pcap_writer; #[cfg(any(feature = "std", feature = "alloc"))] mod loopback; -#[cfg(feature = "raw_socket")] +#[cfg(feature = "phy-raw_socket")] mod raw_socket; -#[cfg(all(feature = "tap_interface", target_os = "linux"))] +#[cfg(all(feature = "phy-tap_interface", target_os = "linux"))] mod tap_interface; -#[cfg(any(feature = "raw_socket", feature = "tap_interface"))] +#[cfg(any(feature = "phy-raw_socket", feature = "phy-tap_interface"))] pub use self::sys::wait; pub use self::tracer::Tracer; @@ -127,9 +127,9 @@ pub use self::fault_injector::FaultInjector; pub use self::pcap_writer::{PcapLinkType, PcapMode, PcapSink, PcapWriter}; #[cfg(any(feature = "std", feature = "alloc"))] pub use self::loopback::Loopback; -#[cfg(any(feature = "raw_socket"))] +#[cfg(any(feature = "phy-raw_socket"))] pub use self::raw_socket::RawSocket; -#[cfg(all(feature = "tap_interface", target_os = "linux"))] +#[cfg(all(feature = "phy-tap_interface", target_os = "linux"))] pub use self::tap_interface::TapInterface; /// A tracer device for Ethernet frames. diff --git a/src/phy/sys/linux.rs b/src/phy/sys/linux.rs index 6486728..fdf52ba 100644 --- a/src/phy/sys/linux.rs +++ b/src/phy/sys/linux.rs @@ -1,16 +1,17 @@ use libc; -#[cfg(any(feature = "raw_socket"))] +#[cfg(any(feature = "phy-raw_socket", + feature = "phy-tap_interface"))] pub const SIOCGIFMTU: libc::c_ulong = 0x8921; -#[cfg(any(feature = "raw_socket"))] +#[cfg(any(feature = "phy-raw_socket"))] pub const SIOCGIFINDEX: libc::c_ulong = 0x8933; -#[cfg(any(feature = "raw_socket"))] +#[cfg(any(feature = "phy-raw_socket"))] pub const ETH_P_ALL: libc::c_short = 0x0003; -#[cfg(feature = "tap_interface")] +#[cfg(feature = "phy-tap_interface")] pub const TUNSETIFF: libc::c_ulong = 0x400454CA; -#[cfg(feature = "tap_interface")] +#[cfg(feature = "phy-tap_interface")] pub const IFF_TAP: libc::c_int = 0x0002; -#[cfg(feature = "tap_interface")] +#[cfg(feature = "phy-tap_interface")] pub const IFF_NO_PI: libc::c_int = 0x1000; diff --git a/src/phy/sys/mod.rs b/src/phy/sys/mod.rs index 3e99d56..87d0561 100644 --- a/src/phy/sys/mod.rs +++ b/src/phy/sys/mod.rs @@ -6,14 +6,14 @@ use std::os::unix::io::RawFd; #[path = "linux.rs"] mod imp; -#[cfg(feature = "raw_socket")] +#[cfg(feature = "phy-raw_socket")] pub mod raw_socket; -#[cfg(all(feature = "tap_interface", target_os = "linux"))] +#[cfg(all(feature = "phy-tap_interface", target_os = "linux"))] pub mod tap_interface; -#[cfg(feature = "raw_socket")] +#[cfg(feature = "phy-raw_socket")] pub use self::raw_socket::RawSocketDesc; -#[cfg(all(feature = "tap_interface", target_os = "linux"))] +#[cfg(all(feature = "phy-tap_interface", target_os = "linux"))] pub use self::tap_interface::TapInterfaceDesc; /// Wait until given file descriptor becomes readable, but no longer than given timeout.