$ show smoltcp-rs/smoltcp
smoltcp is a standalone, event-driven TCP/IP network stack designed for bare-metal and real-time embedded systems. It operates without a heap, using compile-time fixed-size buffers and `no_std` Rust. The stack implements a full suite of protocols: Ethernet, ARP, IPv4/IPv6, TCP, UDP, ICMP, DHCPv4, DNS, IGMP/MLD, 6LoWPAN, RPL, and IPsec (AH/ESP). It is structured into modular layers: `wire/` for packet parsing and emission, `iface/` for interface logic (routing, neighbor discovery, fragmentation, multicast), `socket/` for transport and application sockets, `phy/` for hardware abstraction (loopback, raw sockets, TUN/TAP, pcap, fault injection), and `storage/` for reusable data structures (ring buffers, assemblers). The architecture follows a `Packet`/`Repr` pattern for each protocol, enabling zero-copy parsing and emission. The stack is highly configurable via feature flags, allowing minimal builds for constrained devices. It includes extensive unit tests, integration tests (including a network simulator), fuzz targets, and benchmarks. The codebase demonstrates strong engineering practices with RFC compliance, pluggable congestion control (Reno, Cubic), and async support via waker registration. It is primarily a library for use in embedded projects, IoT devices, and any environment requiring a lightweight, reliable network stack without an operating system.
The LLM identified 5 files worth highlighting for reuse:
A generic, zero-copy ring buffer supporting both discrete element access and continuous slice access. It is used internally by UDP and raw sockets for packet buffering. The implementation is self-contained, no_std compatible, and can be extracted for any project needing a fixed-capacity FIFO with efficient enqueue/dequeue and optional overwrite behavior.
A generic data reassembler that tracks holes in a sequence space using a configurable maximum number of segments. It is used for IPv4 fragmentation reassembly and TCP reordering. The implementation is self-contained, no_std compatible, and can be reused for any protocol requiring out-of-order data reassembly with bounded memory.
A classical TCP Reno congestion controller implementing slow start, congestion avoidance, fast recovery, and retransmission timeout. It follows RFC 5681 and is designed as a pluggable component via the `Controller` trait. The implementation is self-contained, well-tested, and can be extracted for use in other TCP stacks or network simulations.
Defines the `Device` trait with `RxToken` and `TxToken` for hardware abstraction, along with `DeviceCapabilities` and `ChecksumCapabilities`. This pattern enables middleware stacking (e.g., Tracer, FaultInjector, PcapWriter) and is reusable for any network stack needing a clean separation between protocol logic and physical I/O.
Provides IP address types (`Address`, `Cidr`, `Endpoint`), protocol enums, and a comprehensive checksum module implementing RFC 1071. The checksum functions (`data`, `combine`, `pseudo_header_v4/v6`) are pure, no_std compatible, and can be reused in any project requiring IP checksum computation without pulling in the entire stack.