WolfIP:轻量级TCP/IP协议栈,无动态内存分配。
WolfIP: Lightweight TCP/IP stack with no dynamic memory allocations

原始链接: https://github.com/wolfssl/wolfip

wolfIP是一个专为资源受限的嵌入式系统设计的TCP/IP协议栈,优先考虑零动态内存占用。它以端点模式运行,通过单个网络接口建立连接,并使用类似BSD的非阻塞套接字API和自定义回调函数。 该协议栈支持关键协议,包括IPv4、ICMP、UDP和TCP(具有拥塞控制、SACK和时间戳等功能),以及DHCP和DNS客户端等应用程序,以及利用wolfSSL的HTTP/HTTPS服务器。 一个独特的功能是它的POSIX shim,`libwolfip.so`,允许将标准的套接字调用重定向到wolfIP,以便通过TAP接口使用`nc`和`ping`等工具进行测试。 此外,还提供了一个专用的FreeRTOS移植版本,采用后台任务和互斥锁保护的套接字访问。 wolfIP采用GPLv3许可,为嵌入式应用提供了一种强大且内存高效的网络解决方案。

## WolfIP:轻量级TCP/IP协议栈 WolfIP是一个新的、为嵌入式系统设计的TCP/IP协议栈,最近在Hacker News上分享。其关键特性是完全没有动态内存分配,旨在实现稳定性和可预测性。 讨论很快转向了与现有协议栈的比较,例如passt(用于QEMU和Podman容器)、Contiki uIP和lwIP。虽然这些替代方案已经存在,但WolfSSL(WolfIP的创建者)经常提供认证包和支持服务,吸引了需要保证可靠性和减轻责任的项目。他们还提供商业许可选项,以及GPL许可的代码。 一个核心争论集中在动态分配的必要性上。传统的TCP/IP实现由于缓冲而占用大量内存,但固定大小的缓冲区可以在受限的环境中工作。对话还涉及IPv6的持续采用,一些人认为其复杂性超过了其优势,特别是考虑到需要双栈配置和潜在的兼容性问题。最终,WolfIP为资源受限且确定性行为至关重要的设备提供了一种利基解决方案。
相关文章

原文

Description and project goals

wolfIP is a TCP/IP stack with no dynamic memory allocations, designed to be used in resource-constrained embedded systems.

Endpoint only mode is supported, which means that wolfip can be used to establish network connections but it does not route traffic between different network interfaces.

A single network interface can be associated with the device.

  • BSD-like, non blocking socket API, with custom callbacks
  • No dynamic memory allocation
    • Fixed number of concurrent sockets
    • Pre-allocated buffers for packet processing in static memory
Layer Protocol Features RFC(s)
Data Link Ethernet II Frame encapsulation IEEE 802.3
Data Link ARP Address resolution, request/reply RFC 826
Network IPv4 Datagram delivery, TTL handling RFC 791
Network IPv4 Forwarding Multi-interface routing (optional) RFC 1812
Network ICMP Echo request/reply, TTL exceeded RFC 792
Network IPsec ESP Transport mode RFC 4303
Transport UDP Unicast datagrams, checksum RFC 768
Transport TCP Connection management, reliable delivery RFC 793, RFC 9293
Transport TCP Maximum Segment Size negotiation RFC 793
Transport TCP TCP Timestamps, RTT measurement, PAWS, Window Scaling RFC 7323
Transport TCP Retransmission timeout (RTO) computation RFC 6298, RFC 5681
Transport TCP TCP SACK RFC 2018, RFC 2883, RFC 6675
Transport TCP Congestion Control: Slow start, congestion avoidance RFC 5681
Transport TCP Fast Retransmit, triple duplicate ACK detection RFC 5681
Application DHCP Client only (DORA) RFC 2131
Application DNS A and PTR record queries (client) RFC 1035
Application HTTP/HTTPS Server with wolfSSL TLS support RFC 9110

Functional tests with LD_PRELOAD

The POSIX shim builds libwolfip.so, which can be injected in front of host tools so that calls to socket(2) and friends are redirected to the wolfIP stack and the TAP device (wtcp0). After running make:

sudo LD_PRELOAD=$PWD/libwolfip.so nc 10.10.10.2 80

The example above mirrors the existing nc-driven demos: any TCP sockets opened by the intercepted process are serviced by wolfIP instead of the host kernel.

ICMP datagram sockets can be validated the same way. With the TAP interface created automatically by the shim and the host endpoint configured in config.h (HOST_STACK_IP defaults to 10.10.10.1), run:

sudo LD_PRELOAD=$PWD/libwolfip.so ping -I wtcp0 -c5 10.10.10.1

The -I wtcp0 flag pins the test to the injected interface and -c5 generates five echo requests. Successful replies confirm the ICMP datagram socket support end-to-end through the tap device.

wolfIP now includes a dedicated FreeRTOS wrapper port at:

  • src/port/freeRTOS/bsd_socket.c
  • src/port/freeRTOS/bsd_socket.h

This port follows the same model as the POSIX wrapper:

  • One background task loops on wolfIP_poll()
  • Socket wrappers serialize stack access with a mutex
  • Blocking operations wait on callback-driven wakeups (instead of busy polling)

wolfIP is licensed under the GPLv3 license. See the LICENSE file for details. Copyright (c) 2025 wolfSSL Inc.

联系我们 contact @ memedata.com