Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "smoltcp"
version = "0.12.0"
edition = "2021"
edition = "2024"
rust-version = "1.87"
authors = ["whitequark <whitequark@whitequark.org>"]
description = "A TCP/IP stack designed for bare-metal, real-time systems without a heap."
Expand Down
2 changes: 1 addition & 1 deletion examples/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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::phy::{Device, Medium, wait as phy_wait};
use smoltcp::socket::tcp;
use smoltcp::time::{Duration, Instant};
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr};
Expand Down
2 changes: 1 addition & 1 deletion examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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::phy::{Device, Medium, wait as phy_wait};
use smoltcp::socket::tcp;
use smoltcp::time::Instant;
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address, Ipv6Address};
Expand Down
2 changes: 1 addition & 1 deletion examples/dhcp_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use smoltcp::socket::dhcpv4;
use smoltcp::time::Instant;
use smoltcp::wire::{EthernetAddress, IpCidr, Ipv4Cidr};
use smoltcp::{
phy::{wait as phy_wait, Device, Medium},
phy::{Device, Medium, wait as phy_wait},
time::Duration,
};

Expand Down
2 changes: 1 addition & 1 deletion examples/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod utils;

use smoltcp::iface::{Config, Interface, SocketSet};
use smoltcp::phy::Device;
use smoltcp::phy::{wait as phy_wait, Medium};
use smoltcp::phy::{Medium, wait as phy_wait};
use smoltcp::socket::dns::{self, GetQueryResultError};
use smoltcp::time::Instant;
use smoltcp::wire::{DnsQueryType, EthernetAddress, IpAddress, IpCidr, Ipv4Address, Ipv6Address};
Expand Down
2 changes: 1 addition & 1 deletion examples/httpclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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::phy::{Device, Medium, wait as phy_wait};
use smoltcp::socket::tcp;
use smoltcp::time::Instant;
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address, Ipv6Address};
Expand Down
2 changes: 1 addition & 1 deletion examples/loopback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ mod mock {
#[cfg(feature = "std")]
mod mock {
use smoltcp::time::{Duration, Instant};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};

// should be AtomicU64 but that's unstable
#[derive(Debug, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion examples/multicast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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, wait as phy_wait};
use smoltcp::socket::{raw, udp};
use smoltcp::time::Instant;
use smoltcp::wire::{
Expand Down
2 changes: 1 addition & 1 deletion examples/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ 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::phy::wait as phy_wait;
use smoltcp::socket::icmp;
use smoltcp::wire::{
EthernetAddress, Icmpv4Packet, Icmpv4Repr, Icmpv6Packet, Icmpv6Repr, IpAddress, IpCidr,
Expand Down
2 changes: 1 addition & 1 deletion examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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, wait as phy_wait};
use smoltcp::socket::{tcp, udp};
use smoltcp::time::{Duration, Instant};
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address, Ipv6Address};
Expand Down
2 changes: 1 addition & 1 deletion examples/sixlowpan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ 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, RawSocket, wait as phy_wait};
use smoltcp::socket::tcp;
use smoltcp::socket::udp;
use smoltcp::time::Instant;
Expand Down
2 changes: 1 addition & 1 deletion examples/sixlowpan_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ 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, RawSocket, wait as phy_wait};
use smoltcp::socket::tcp;
use smoltcp::wire::{EthernetAddress, Ieee802154Address, Ieee802154Pan, IpAddress, IpCidr};

Expand Down
2 changes: 1 addition & 1 deletion examples/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use env_logger::Builder;
use getopts::{Matches, Options};
#[cfg(feature = "log")]
use log::{trace, Level, LevelFilter};
use log::{Level, LevelFilter, trace};
use std::env;
use std::fs::File;
use std::io::{self, Write};
Expand Down
8 changes: 6 additions & 2 deletions src/iface/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,9 @@ impl Interface {
#[cfg(feature = "_proto-fragmentation")]
pub fn set_reassembly_timeout(&mut self, timeout: Duration) {
if timeout > Duration::from_secs(60) {
net_debug!("RFC 4944 specifies that the reassembly timeout MUST be set to a maximum of 60 seconds");
net_debug!(
"RFC 4944 specifies that the reassembly timeout MUST be set to a maximum of 60 seconds"
);
}
self.fragments.reassembly_timeout = timeout;
}
Expand Down Expand Up @@ -1282,7 +1284,9 @@ impl InterfaceInner {

#[cfg(not(feature = "proto-ipv4-fragmentation"))]
{
net_debug!("Enable the `proto-ipv4-fragmentation` feature for fragmentation support.");
net_debug!(
"Enable the `proto-ipv4-fragmentation` feature for fragmentation support."
);
Ok(())
}
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/iface/interface/multicast.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use core::result::Result;
use heapless::{LinearMap, Vec};

#[cfg(any(feature = "proto-ipv4", feature = "proto-ipv6"))]
use super::{check, IpPayload, Packet};
use super::{Interface, InterfaceInner};
#[cfg(any(feature = "proto-ipv4", feature = "proto-ipv6"))]
use super::{IpPayload, Packet, check};
use crate::config::{IFACE_MAX_ADDR_COUNT, IFACE_MAX_MULTICAST_GROUP_COUNT};
use crate::phy::{Device, PacketMeta};
use crate::wire::*;
Expand Down Expand Up @@ -191,7 +191,7 @@ impl Interface {
.multicast
.groups
.iter()
.find(|(_, &state)| state == GroupState::Joining)
.find(|&(_, &state)| state == GroupState::Joining)
{
match addr {
#[cfg(feature = "proto-ipv4")]
Expand Down Expand Up @@ -239,7 +239,7 @@ impl Interface {
.multicast
.groups
.iter()
.find(|(_, &state)| state == GroupState::Leaving)
.find(|&(_, &state)| state == GroupState::Leaving)
{
match addr {
#[cfg(feature = "proto-ipv4")]
Expand Down
168 changes: 102 additions & 66 deletions src/iface/interface/tests/ipv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,32 @@ fn test_any_ip_accept_arp(#[case] medium: Medium) {

let (mut iface, mut sockets, _) = setup(medium);

assert!(iface
.inner
.process_ethernet(
&mut sockets,
PacketMeta::default(),
ETHERNET_FRAME_ARP(buffer.as_mut()),
&mut iface.fragments,
)
.is_none());
assert!(
iface
.inner
.process_ethernet(
&mut sockets,
PacketMeta::default(),
ETHERNET_FRAME_ARP(buffer.as_mut()),
&mut iface.fragments,
)
.is_none()
);

// Accept any IP address
iface.set_any_ip(true);

assert!(iface
.inner
.process_ethernet(
&mut sockets,
PacketMeta::default(),
ETHERNET_FRAME_ARP(buffer.as_mut()),
&mut iface.fragments,
)
.is_some());
assert!(
iface
.inner
.process_ethernet(
&mut sockets,
PacketMeta::default(),
ETHERNET_FRAME_ARP(buffer.as_mut()),
&mut iface.fragments,
)
.is_some()
);
}

#[rstest]
Expand Down Expand Up @@ -174,66 +178,98 @@ fn test_local_subnet_broadcasts(#[case] medium: Medium) {
});
});

assert!(iface
.inner
.is_broadcast_v4(Ipv4Address::new(255, 255, 255, 255)));
assert!(!iface
.inner
.is_broadcast_v4(Ipv4Address::new(255, 255, 255, 254)));
assert!(iface
.inner
.is_broadcast_v4(Ipv4Address::new(192, 168, 1, 255)));
assert!(!iface
.inner
.is_broadcast_v4(Ipv4Address::new(192, 168, 1, 254)));
assert!(
iface
.inner
.is_broadcast_v4(Ipv4Address::new(255, 255, 255, 255))
);
assert!(
!iface
.inner
.is_broadcast_v4(Ipv4Address::new(255, 255, 255, 254))
);
assert!(
iface
.inner
.is_broadcast_v4(Ipv4Address::new(192, 168, 1, 255))
);
assert!(
!iface
.inner
.is_broadcast_v4(Ipv4Address::new(192, 168, 1, 254))
);

iface.update_ip_addrs(|addrs| {
addrs.iter_mut().next().map(|addr| {
*addr = IpCidr::Ipv4(Ipv4Cidr::new(Ipv4Address::new(192, 168, 23, 24), 16));
});
});
assert!(iface
.inner
.is_broadcast_v4(Ipv4Address::new(255, 255, 255, 255)));
assert!(!iface
.inner
.is_broadcast_v4(Ipv4Address::new(255, 255, 255, 254)));
assert!(!iface
.inner
.is_broadcast_v4(Ipv4Address::new(192, 168, 23, 255)));
assert!(!iface
.inner
.is_broadcast_v4(Ipv4Address::new(192, 168, 23, 254)));
assert!(!iface
.inner
.is_broadcast_v4(Ipv4Address::new(192, 168, 255, 254)));
assert!(iface
.inner
.is_broadcast_v4(Ipv4Address::new(192, 168, 255, 255)));
assert!(
iface
.inner
.is_broadcast_v4(Ipv4Address::new(255, 255, 255, 255))
);
assert!(
!iface
.inner
.is_broadcast_v4(Ipv4Address::new(255, 255, 255, 254))
);
assert!(
!iface
.inner
.is_broadcast_v4(Ipv4Address::new(192, 168, 23, 255))
);
assert!(
!iface
.inner
.is_broadcast_v4(Ipv4Address::new(192, 168, 23, 254))
);
assert!(
!iface
.inner
.is_broadcast_v4(Ipv4Address::new(192, 168, 255, 254))
);
assert!(
iface
.inner
.is_broadcast_v4(Ipv4Address::new(192, 168, 255, 255))
);

iface.update_ip_addrs(|addrs| {
addrs.iter_mut().next().map(|addr| {
*addr = IpCidr::Ipv4(Ipv4Cidr::new(Ipv4Address::new(192, 168, 23, 24), 8));
});
});
assert!(iface
.inner
.is_broadcast_v4(Ipv4Address::new(255, 255, 255, 255)));
assert!(!iface
.inner
.is_broadcast_v4(Ipv4Address::new(255, 255, 255, 254)));
assert!(!iface
.inner
.is_broadcast_v4(Ipv4Address::new(192, 23, 1, 255)));
assert!(!iface
.inner
.is_broadcast_v4(Ipv4Address::new(192, 23, 1, 254)));
assert!(!iface
.inner
.is_broadcast_v4(Ipv4Address::new(192, 255, 255, 254)));
assert!(iface
.inner
.is_broadcast_v4(Ipv4Address::new(192, 255, 255, 255)));
assert!(
iface
.inner
.is_broadcast_v4(Ipv4Address::new(255, 255, 255, 255))
);
assert!(
!iface
.inner
.is_broadcast_v4(Ipv4Address::new(255, 255, 255, 254))
);
assert!(
!iface
.inner
.is_broadcast_v4(Ipv4Address::new(192, 23, 1, 255))
);
assert!(
!iface
.inner
.is_broadcast_v4(Ipv4Address::new(192, 23, 1, 254))
);
assert!(
!iface
.inner
.is_broadcast_v4(Ipv4Address::new(192, 255, 255, 254))
);
assert!(
iface
.inner
.is_broadcast_v4(Ipv4Address::new(192, 255, 255, 255))
);
}

#[rstest]
Expand Down
Loading