From 59fc0c0358b6c6205b5036589d6e0c59351ecaa4 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Thu, 15 Jun 2017 13:12:11 +0300 Subject: [PATCH] Factor out the "raw_socket" and "tap_interface" features This makes it possible to build smoltcp with the "std" feature on platforms without libc, such as redox. --- .travis.yml | 8 ++++---- Cargo.toml | 6 ++++-- README.md | 9 +++++++-- src/lib.rs | 2 +- src/phy/mod.rs | 10 +++++----- src/phy/sys/linux.rs | 9 +++++++-- src/phy/sys/mod.rs | 6 ++++-- 7 files changed, 32 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 64155b7..10953dd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,13 +2,13 @@ language: rust matrix: include: - rust: stable - env: FEATURES='std' MODE='test' + env: FEATURES='std raw_socket tap_interface' MODE='test' - rust: beta - env: FEATURES='std' MODE='test' + env: FEATURES='std raw_socket tap_interface' MODE='test' - rust: nightly - env: FEATURES='std' MODE='test' + env: FEATURES='std raw_socket tap_interface' MODE='test' - rust: nightly - env: FEATURES='std log' MODE='test' + env: FEATURES='std raw_socket tap_interface log' MODE='test' - rust: nightly env: FEATURES='alloc collections' MODE='build' - rust: nightly diff --git a/Cargo.toml b/Cargo.toml index d47de8f..f9b7a05 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,11 +23,13 @@ env_logger = "0.4" getopts = "0.2" [features] -std = ["managed/std", "libc"] +std = ["managed/std"] alloc = ["managed/alloc"] collections = ["managed/collections"] verbose = [] -default = ["std", "log", "verbose"] +raw_socket = ["libc"] +tap_interface = ["libc"] +default = ["std", "raw_socket", "tap_interface", "log", "verbose"] [[example]] name = "tcpdump" diff --git a/README.md b/README.md index 9d0e8c3..e5704b2 100644 --- a/README.md +++ b/README.md @@ -87,11 +87,16 @@ smoltcp = { version = "0.3", default-features = false, features = ["..."] } ### Feature `std` The `std` feature enables use of objects and slices owned by the networking stack through a -dependency on `std::boxed::Box` and `std::vec::Vec`. It also enables `smoltcp::phy::RawSocket` -and `smoltcp::phy::TapInterface`, if the platform supports it. +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 diff --git a/src/lib.rs b/src/lib.rs index 51d4938..0a18a48 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(feature = "std")] +#[cfg(any(feature = "raw_socket", feature="tap_interface"))] extern crate libc; #[cfg(feature = "alloc")] extern crate alloc; diff --git a/src/phy/mod.rs b/src/phy/mod.rs index 8cd78a0..fe21d82 100644 --- a/src/phy/mod.rs +++ b/src/phy/mod.rs @@ -102,21 +102,21 @@ impl Drop for EthernetTxBuffer { use Error; -#[cfg(feature = "std")] +#[cfg(any(feature = "raw_socket", feature="tap_interface"))] mod sys; mod tracer; mod fault_injector; -#[cfg(feature = "std")] +#[cfg(feature = "raw_socket")] mod raw_socket; -#[cfg(all(feature = "std", target_os = "linux"))] +#[cfg(all(feature = "tap_interface", target_os = "linux"))] mod tap_interface; pub use self::tracer::Tracer; pub use self::fault_injector::FaultInjector; -#[cfg(feature = "std")] +#[cfg(any(feature = "raw_socket"))] pub use self::raw_socket::RawSocket; -#[cfg(all(feature = "std", target_os = "linux"))] +#[cfg(all(feature = "tap_interface", target_os = "linux"))] pub use self::tap_interface::TapInterface; /// A description of device limitations. diff --git a/src/phy/sys/linux.rs b/src/phy/sys/linux.rs index db8c731..6486728 100644 --- a/src/phy/sys/linux.rs +++ b/src/phy/sys/linux.rs @@ -1,11 +1,16 @@ use libc; +#[cfg(any(feature = "raw_socket"))] pub const SIOCGIFMTU: libc::c_ulong = 0x8921; +#[cfg(any(feature = "raw_socket"))] pub const SIOCGIFINDEX: libc::c_ulong = 0x8933; +#[cfg(any(feature = "raw_socket"))] +pub const ETH_P_ALL: libc::c_short = 0x0003; +#[cfg(feature = "tap_interface")] pub const TUNSETIFF: libc::c_ulong = 0x400454CA; - +#[cfg(feature = "tap_interface")] pub const IFF_TAP: libc::c_int = 0x0002; +#[cfg(feature = "tap_interface")] pub const IFF_NO_PI: libc::c_int = 0x1000; -pub const ETH_P_ALL: libc::c_short = 0x0003; diff --git a/src/phy/sys/mod.rs b/src/phy/sys/mod.rs index 5b1573f..14b5ffb 100644 --- a/src/phy/sys/mod.rs +++ b/src/phy/sys/mod.rs @@ -5,12 +5,14 @@ use std::io; #[path = "linux.rs"] mod imp; +#[cfg(feature = "raw_socket")] pub mod raw_socket; -#[cfg(target_os = "linux")] +#[cfg(all(feature = "tap_interface", target_os = "linux"))] pub mod tap_interface; +#[cfg(feature = "raw_socket")] pub use self::raw_socket::RawSocketDesc; -#[cfg(target_os = "linux")] +#[cfg(all(feature = "tap_interface", target_os = "linux"))] pub use self::tap_interface::TapInterfaceDesc; #[repr(C)]