Browse Source

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.
Egor Karavaev 7 years ago
parent
commit
80c20adbf8
7 changed files with 32 additions and 18 deletions
  1. 4 4
      .travis.yml
  2. 4 2
      Cargo.toml
  3. 7 2
      README.md
  4. 1 1
      src/lib.rs
  5. 5 5
      src/phy/mod.rs
  6. 7 2
      src/phy/sys/linux.rs
  7. 4 2
      src/phy/sys/mod.rs

+ 4 - 4
.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

+ 4 - 2
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"

+ 7 - 2
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

+ 1 - 1
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;

+ 5 - 5
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.

+ 7 - 2
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;

+ 4 - 2
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)]