Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 29 additions & 24 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[workspace]
members = ["smoltcp-device", "smoltcp-device-mock", "smoltcp-device-unix"]

[package]
name = "smoltcp"
version = "0.12.0"
Expand Down Expand Up @@ -28,6 +31,7 @@ bitflags = { version = "1.0", default-features = false }
defmt = { version = "0.3.8", optional = true, features = ["ip_in_core"] }
cfg-if = "1.0.0"
heapless = "0.8"
smoltcp-device = { version = "0.1.0", path = "smoltcp-device" }

[dev-dependencies]
env_logger = "0.10"
Expand All @@ -38,18 +42,19 @@ rstest = "0.17"
insta = "1.41.1"
rand_chacha = "0.3.1"
idna = { version = "=1.0.1" }
smoltcp-device-mock = { path = "smoltcp-device-mock" }

[target.'cfg(unix)'.dev-dependencies]
smoltcp-device-unix = { path = "smoltcp-device-unix" }

[features]
std = ["managed/std", "alloc"]
std = ["managed/std", "alloc", "smoltcp-device/std"]
alloc = ["managed/alloc", "defmt?/alloc"]
verbose = []
defmt = ["dep:defmt", "heapless/defmt-03"]
"medium-ethernet" = ["socket"]
"medium-ip" = ["socket"]
"medium-ieee802154" = ["socket", "proto-sixlowpan"]

"phy-raw_socket" = ["std", "libc"]
"phy-tuntap_interface" = ["std", "libc", "medium-ethernet"]
defmt = ["dep:defmt", "heapless/defmt-03", "smoltcp-device/defmt"]
"medium-ethernet" = ["socket", "smoltcp-device/requires-medium-ethernet", "smoltcp-device-mock/medium-ethernet", "smoltcp-device-unix/medium-ethernet"]
"medium-ip" = ["socket", "smoltcp-device/requires-medium-ip", "smoltcp-device-mock/medium-ip", "smoltcp-device-unix/medium-ip"]
"medium-ieee802154" = ["socket", "proto-sixlowpan", "smoltcp-device/requires-medium-ieee802154", "smoltcp-device-mock/medium-ieee802154", "smoltcp-device-unix/medium-ieee802154"]

"proto-ipv4" = []
"proto-ipv4-fragmentation" = ["proto-ipv4", "_proto-fragmentation"]
Expand Down Expand Up @@ -93,14 +98,13 @@ defmt = ["dep:defmt", "heapless/defmt-03"]
# Enable Reno TCP congestion control algorithm, and it is used as a default congestion controller.
"socket-tcp-reno" = []

"packetmeta-id" = []
"packetmeta-id" = ["smoltcp-device/packetmeta-id"]

"async" = []

default = [
"std", "log", # needed for `cargo test --no-default-features --features default` :/
"medium-ethernet", "medium-ip", "medium-ieee802154",
"phy-raw_socket", "phy-tuntap_interface",
"proto-ipv4", "proto-dhcpv4", "proto-ipv6", "proto-dns",
"proto-ipv4-fragmentation", "proto-sixlowpan-fragmentation",
"socket-raw", "socket-icmp", "socket-udp", "socket-tcp", "socket-dhcpv4", "socket-dns", "socket-mdns",
Expand All @@ -113,6 +117,7 @@ default = [

"_proto-fragmentation" = []

# Prevents running netsim (slow) with the other tests.
"_netsim" = []

# BEGIN AUTOGENERATED CONFIG FEATURES
Expand Down Expand Up @@ -285,59 +290,59 @@ required-features = ["std"]

[[example]]
name = "tcpdump"
required-features = ["std", "phy-raw_socket", "proto-ipv4"]
required-features = ["std", "log", "medium-ethernet", "proto-ipv4"]

[[example]]
name = "httpclient"
required-features = ["std", "medium-ethernet", "medium-ip", "phy-tuntap_interface", "proto-ipv4", "proto-ipv6", "socket-tcp"]
required-features = ["std", "log", "medium-ethernet", "medium-ip", "proto-ipv4", "proto-ipv6", "socket-tcp"]

[[example]]
name = "ping"
required-features = ["std", "medium-ethernet", "medium-ip", "phy-tuntap_interface", "proto-ipv4", "proto-ipv6", "socket-icmp"]
required-features = ["std", "log", "medium-ethernet", "medium-ip", "proto-ipv4", "proto-ipv6", "socket-icmp"]

[[example]]
name = "server"
required-features = ["std", "medium-ethernet", "medium-ip", "phy-tuntap_interface", "proto-ipv4", "socket-tcp", "socket-udp"]
required-features = ["std", "log", "medium-ethernet", "medium-ip", "proto-ipv4", "socket-tcp", "socket-udp"]

[[example]]
name = "client"
required-features = ["std", "medium-ethernet", "medium-ip", "phy-tuntap_interface", "proto-ipv4", "socket-tcp", "socket-udp"]
required-features = ["std", "log", "medium-ethernet", "medium-ip", "proto-ipv4", "socket-tcp", "socket-udp"]

[[example]]
name = "loopback"
required-features = ["log", "medium-ethernet", "proto-ipv4", "socket-tcp"]
required-features = ["log", "medium-ethernet", "medium-ip", "medium-ieee802154", "proto-ipv4", "socket-tcp"]

[[example]]
name = "loopback_benchmark"
required-features = ["std", "log", "medium-ethernet", "proto-ipv4", "socket-tcp"]
required-features = ["std", "log", "medium-ethernet", "medium-ip", "medium-ieee802154", "proto-ipv4", "socket-tcp"]

[[example]]
name = "multicast"
required-features = ["std", "medium-ethernet", "medium-ip", "phy-tuntap_interface", "proto-ipv4", "multicast", "socket-udp"]
required-features = ["std", "log", "medium-ethernet", "medium-ip", "proto-ipv4", "multicast", "socket-udp"]

[[example]]
name = "multicast6"
required-features = ["std", "medium-ethernet", "medium-ip", "phy-tuntap_interface", "proto-ipv6", "socket-udp"]
required-features = ["std", "log", "medium-ethernet", "medium-ip", "proto-ipv6", "socket-udp"]

[[example]]
name = "benchmark"
required-features = ["std", "medium-ethernet", "medium-ip", "phy-tuntap_interface", "proto-ipv4", "socket-raw", "socket-udp"]
required-features = ["std", "log", "medium-ethernet", "medium-ip", "proto-ipv4", "socket-raw", "socket-udp"]

[[example]]
name = "dhcp_client"
required-features = ["std", "medium-ethernet", "medium-ip", "phy-tuntap_interface", "proto-ipv4", "proto-dhcpv4", "socket-raw"]
required-features = ["std", "log", "medium-ethernet", "medium-ip", "proto-ipv4", "proto-dhcpv4", "socket-raw"]

[[example]]
name = "sixlowpan"
required-features = ["std", "medium-ieee802154", "phy-raw_socket", "proto-sixlowpan", "proto-sixlowpan-fragmentation", "socket-udp"]
required-features = ["std", "log", "medium-ethernet", "medium-ieee802154", "medium-ip", "proto-sixlowpan", "proto-sixlowpan-fragmentation", "socket-udp"]

[[example]]
name = "sixlowpan_benchmark"
required-features = ["std", "medium-ieee802154", "phy-raw_socket", "proto-sixlowpan", "proto-sixlowpan-fragmentation", "socket-udp"]
required-features = ["std", "log", "medium-ethernet", "medium-ieee802154", "medium-ip", "proto-sixlowpan", "proto-sixlowpan-fragmentation", "socket-udp"]

[[example]]
name = "dns"
required-features = ["std", "medium-ethernet", "medium-ip", "phy-tuntap_interface", "proto-ipv4", "socket-dns"]
required-features = ["std", "log", "medium-ethernet", "medium-ip", "proto-ipv4", "socket-dns"]

[profile.release]
debug = 2
17 changes: 11 additions & 6 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ RUSTC_VERSIONS=(
FEATURES_TEST=(
"default"
"std,proto-ipv4"
"std,medium-ethernet,phy-raw_socket,proto-ipv6,socket-udp,socket-dns"
"std,medium-ethernet,phy-tuntap_interface,proto-ipv6,socket-udp"
"std,medium-ethernet,proto-ipv6,socket-udp,socket-dns"
"std,medium-ethernet,proto-ipv6,socket-udp"
"std,medium-ethernet,proto-ipv4,proto-ipv4-fragmentation,socket-raw,socket-dns"
"std,medium-ethernet,proto-ipv4,multicast,socket-raw,socket-dns"
"std,medium-ethernet,proto-ipv4,socket-udp,socket-tcp,socket-dns"
Expand All @@ -40,16 +40,19 @@ FEATURES_TEST_NIGHTLY=(
)

FEATURES_CHECK=(
"medium-ip,medium-ethernet,medium-ieee802154,proto-ipv6,proto-ipv6,multicast,proto-dhcpv4,proto-ipsec,socket-raw,socket-udp,socket-tcp,socket-icmp,socket-dns,async"
"defmt,medium-ip,medium-ethernet,proto-ipv6,proto-ipv6,multicast,proto-dhcpv4,socket-raw,socket-udp,socket-tcp,socket-icmp,socket-dns,async"
"defmt,alloc,medium-ip,medium-ethernet,proto-ipv6,proto-ipv6,multicast,proto-dhcpv4,socket-raw,socket-udp,socket-tcp,socket-icmp,socket-dns,async"
"medium-ieee802154,proto-sixlowpan,socket-dns"
"medium-ip,medium-ethernet,medium-ieee802154,proto-ipv6,proto-ipv6,multicast,proto-dhcpv4,proto-ipsec,socket-raw,socket-udp,socket-tcp,socket-icmp,socket-dns,async,smoltcp-device/provides-medium-ethernet,smoltcp-device/provides-medium-ip,smoltcp-device/provides-medium-ieee802154"
"defmt,medium-ip,medium-ethernet,proto-ipv6,proto-ipv6,multicast,proto-dhcpv4,socket-raw,socket-udp,socket-tcp,socket-icmp,socket-dns,async,smoltcp-device/provides-medium-ethernet,smoltcp-device/provides-medium-ip"
"log,medium-ip,medium-ethernet,proto-ipv6,proto-ipv6,multicast,proto-dhcpv4,socket-raw,socket-udp,socket-tcp,socket-icmp,socket-dns,async,smoltcp-device/provides-medium-ethernet,smoltcp-device/provides-medium-ip"
"defmt,alloc,medium-ip,medium-ethernet,proto-ipv6,proto-ipv6,multicast,proto-dhcpv4,socket-raw,socket-udp,socket-tcp,socket-icmp,socket-dns,async,smoltcp-device/provides-medium-ethernet,smoltcp-device/provides-medium-ip"
"medium-ieee802154,proto-sixlowpan,socket-dns,smoltcp-device/provides-medium-ieee802154"
)

test() {
local version=$1
rustup toolchain install $version

cargo +$version test -p smoltcp-device

for features in ${FEATURES_TEST[@]}; do
cargo +$version test --no-default-features --features "$features"
done
Expand Down Expand Up @@ -99,6 +102,8 @@ build_16bit() {
}

coverage() {
cargo llvm-cov --no-report -p smoltcp-device
cargo llvm-cov --no-report -p smoltcp-device --features std
for features in ${FEATURES_TEST[@]}; do
cargo llvm-cov --no-report --no-default-features --features "$features"
done
Expand Down
3 changes: 2 additions & 1 deletion examples/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::thread;

use smoltcp::iface::{Config, Interface, SocketSet};
use smoltcp::phy::{wait as phy_wait, Device, Medium};
use smoltcp::socket::tcp;
use smoltcp::time::{Duration, Instant};
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr};
use smoltcp_device::{Device, Medium};
use smoltcp_device_unix::wait as phy_wait;

const AMOUNT: usize = 1_000_000_000;

Expand Down
3 changes: 2 additions & 1 deletion examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use std::os::unix::io::AsRawFd;
use std::str::{self, FromStr};

use smoltcp::iface::{Config, Interface, SocketSet};
use smoltcp::phy::{wait as phy_wait, Device, Medium};
use smoltcp::socket::tcp;
use smoltcp::time::Instant;
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address, Ipv6Address};
use smoltcp_device::{Device, Medium};
use smoltcp_device_unix::wait as phy_wait;

fn main() {
utils::setup_logging("");
Expand Down
7 changes: 3 additions & 4 deletions examples/dhcp_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ use std::os::unix::io::AsRawFd;

use smoltcp::iface::{Config, Interface, SocketSet};
use smoltcp::socket::dhcpv4;
use smoltcp::time::Duration;
use smoltcp::time::Instant;
use smoltcp::wire::{EthernetAddress, IpCidr, Ipv4Cidr};
use smoltcp::{
phy::{wait as phy_wait, Device, Medium},
time::Duration,
};
use smoltcp_device::{Device, Medium};
use smoltcp_device_unix::wait as phy_wait;

fn main() {
#[cfg(feature = "log")]
Expand Down
4 changes: 2 additions & 2 deletions examples/dns.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
mod utils;

use smoltcp::iface::{Config, Interface, SocketSet};
use smoltcp::phy::Device;
use smoltcp::phy::{wait as phy_wait, Medium};
use smoltcp::socket::dns::{self, GetQueryResultError};
use smoltcp::time::Instant;
use smoltcp::wire::{DnsQueryType, EthernetAddress, IpAddress, IpCidr, Ipv4Address, Ipv6Address};
use smoltcp_device::{Device, Medium};
use smoltcp_device_unix::wait as phy_wait;
use std::os::unix::io::AsRawFd;

fn main() {
Expand Down
3 changes: 2 additions & 1 deletion examples/httpclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ use std::str::{self, FromStr};
use url::Url;

use smoltcp::iface::{Config, Interface, SocketSet};
use smoltcp::phy::{wait as phy_wait, Device, Medium};
use smoltcp::socket::tcp;
use smoltcp::time::Instant;
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address, Ipv6Address};
use smoltcp_device::{Device, Medium};
use smoltcp_device_unix::wait as phy_wait;

fn main() {
utils::setup_logging("");
Expand Down
3 changes: 2 additions & 1 deletion examples/multicast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ mod utils;
use std::os::unix::io::AsRawFd;

use smoltcp::iface::{Config, Interface, SocketSet};
use smoltcp::phy::{wait as phy_wait, Device, Medium};
use smoltcp::phy::{Device, Medium};
use smoltcp::socket::{raw, udp};
use smoltcp::time::Instant;
use smoltcp::wire::{
EthernetAddress, IgmpPacket, IgmpRepr, IpAddress, IpCidr, IpProtocol, IpVersion, Ipv4Address,
Ipv4Packet, Ipv6Address,
};
use smoltcp_device_unix::wait as phy_wait;

const MDNS_PORT: u16 = 5353;
const MDNS_GROUP: Ipv4Address = Ipv4Address::new(224, 0, 0, 251);
Expand Down
2 changes: 1 addition & 1 deletion examples/multicast6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ mod utils;
use std::os::unix::io::AsRawFd;

use smoltcp::iface::{Config, Interface, SocketSet};
use smoltcp::phy::wait as phy_wait;
use smoltcp::phy::{Device, Medium};
use smoltcp::socket::udp;
use smoltcp::time::Instant;
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv6Address};
use smoltcp_device_unix::wait as phy_wait;

// Note: If testing with a tap interface in linux, you may need to specify the
// interface index when addressing. E.g.,
Expand Down
2 changes: 1 addition & 1 deletion examples/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::os::unix::io::AsRawFd;
use std::str::FromStr;

use smoltcp::iface::Config;
use smoltcp::phy::wait as phy_wait;
use smoltcp::phy::Device;
use smoltcp::socket::icmp;
use smoltcp::wire::{
Expand All @@ -19,6 +18,7 @@ use smoltcp::{
phy::Medium,
time::{Duration, Instant},
};
use smoltcp_device_unix::wait as phy_wait;

macro_rules! send_icmp_ping {
( $repr_type:ident, $packet_type:ident, $ident:expr, $seq_no:expr,
Expand Down
3 changes: 2 additions & 1 deletion examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use std::fmt::Write;
use std::os::unix::io::AsRawFd;

use smoltcp::iface::{Config, Interface, SocketSet};
use smoltcp::phy::{wait as phy_wait, Device, Medium};
use smoltcp::phy::{Device, Medium};
use smoltcp::socket::{tcp, udp};
use smoltcp::time::{Duration, Instant};
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address, Ipv6Address};
use smoltcp_device_unix::wait as phy_wait;

fn main() {
utils::setup_logging("");
Expand Down
3 changes: 2 additions & 1 deletion examples/sixlowpan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ use std::os::unix::io::AsRawFd;
use std::str;

use smoltcp::iface::{Config, Interface, SocketSet};
use smoltcp::phy::{wait as phy_wait, Device, Medium, RawSocket};
use smoltcp::phy::{Device, Medium};
use smoltcp::socket::tcp;
use smoltcp::socket::udp;
use smoltcp::time::Instant;
use smoltcp::wire::{EthernetAddress, Ieee802154Address, Ieee802154Pan, IpAddress, IpCidr};
use smoltcp_device_unix::{wait as phy_wait, RawSocket};

fn main() {
utils::setup_logging("");
Expand Down
5 changes: 3 additions & 2 deletions examples/sixlowpan_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//!
//!
//! # Setup
//!
//!
//! modprobe mac802154_hwsim
//!
//! ip link set wpan0 down
Expand Down Expand Up @@ -47,9 +47,10 @@ use std::os::unix::io::AsRawFd;
use std::str;

use smoltcp::iface::{Config, Interface, SocketSet};
use smoltcp::phy::{wait as phy_wait, Device, Medium, RawSocket};
use smoltcp::phy::{Device, Medium};
use smoltcp::socket::tcp;
use smoltcp::wire::{EthernetAddress, Ieee802154Address, Ieee802154Pan, IpAddress, IpCidr};
use smoltcp_device_unix::{wait as phy_wait, RawSocket};

//For benchmark
use smoltcp::time::{Duration, Instant};
Expand Down
4 changes: 2 additions & 2 deletions examples/tcpdump.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use smoltcp::phy::wait as phy_wait;
use smoltcp::phy::{Device, RawSocket, RxToken};
use smoltcp::phy::{Device, RxToken};
use smoltcp::time::Instant;
use smoltcp::wire::{EthernetFrame, PrettyPrinter};
use smoltcp_device_unix::{wait as phy_wait, RawSocket};
use std::env;
use std::os::unix::io::AsRawFd;

Expand Down
4 changes: 1 addition & 3 deletions examples/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ use std::process;
use std::str::{self, FromStr};
use std::time::{SystemTime, UNIX_EPOCH};

#[cfg(feature = "phy-tuntap_interface")]
use smoltcp::phy::TunTapInterface;
use smoltcp::phy::{Device, FaultInjector, Medium, Tracer};
use smoltcp::phy::{PcapMode, PcapWriter};
use smoltcp::time::{Duration, Instant};
use smoltcp_device_unix::TunTapInterface;

#[cfg(feature = "log")]
pub fn setup_logging_with_clock<F>(filter: &str, since_startup: F)
Expand Down Expand Up @@ -96,7 +95,6 @@ pub fn add_tuntap_options(opts: &mut Options, _free: &mut [&str]) {
opts.optopt("", "tap", "TAP interface to use", "tap0");
}

#[cfg(feature = "phy-tuntap_interface")]
pub fn parse_tuntap_options(matches: &mut Matches) -> TunTapInterface {
let tun = matches.opt_str("tun");
let tap = matches.opt_str("tap");
Expand Down
1 change: 1 addition & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ libfuzzer-sys = "0.4"
arbitrary = { version = "1", features = ["derive"] }
getopts = "0.2"
smoltcp = { path = ".." }
smoltcp-device = { path = "../smoltcp-device", features = ["provides-medium-ethernet", "provides-medium-ip", "provides-medium-ieee802154"] }

# Prevent this from interfering with workspaces
[workspace]
Expand Down
13 changes: 13 additions & 0 deletions smoltcp-device-mock/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "smoltcp-device-mock"
version = "0.1.0"
edition = "2021"
rust-version = "1.81"

[dependencies]
smoltcp-device = { version = "0.1.0", path = "../smoltcp-device" }

[features]
medium-ethernet = ["smoltcp-device/provides-medium-ethernet"]
medium-ieee802154 = ["smoltcp-device/provides-medium-ieee802154"]
medium-ip = ["smoltcp-device/provides-medium-ip"]
Loading