Skip to content

Zephyr TCP/IP replacement#114

Open
danielinux wants to merge 7 commits into
wolfSSL:masterfrom
danielinux:zephyr-tcpip-replace
Open

Zephyr TCP/IP replacement#114
danielinux wants to merge 7 commits into
wolfSSL:masterfrom
danielinux:zephyr-tcpip-replace

Conversation

@danielinux
Copy link
Copy Markdown
Member

  • Added routing tables support for IPv4 routing
  • Added patches to replace stock TCP/IP from Zephyr with wolfIP

Copilot AI review requested due to automatic review settings May 11, 2026 14:56
@danielinux danielinux changed the title Zephyr tcpip replace Zephyr TCP/IP replace May 11, 2026
@danielinux danielinux self-assigned this May 11, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends wolfIP with an IPv4 routing table (static routes + longest-prefix-match selection) and adds an out-of-tree Zephyr port that replaces Zephyr’s native IPv4/TCP/UDP stack with wolfIP via a custom L2 and socket-offload integration.

Changes:

  • Added routing table storage and public APIs (wolfIP_route_*) plus route-aware next-hop/interface selection.
  • Added a DNS server getter API (wolfIP_dns_server_get) and accompanying unit tests.
  • Added Zephyr port documentation and patch set (glue layer, L2 module, net-shell integration, and a TAP echo sample).

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
wolfip.h Adds route info struct, route API declarations, and POSIX-type inclusion tweaks; adds DNS server getter prototype.
src/wolfip.c Implements route table, LPM route lookup, route-aware nexthop/egress selection, and DNS server getter.
src/test/unit/unit.c Registers new unit tests for routing table behavior and DNS getter.
src/test/unit/unit_tests_proto.c Adds unit tests covering route LPM, default route deletion/fallback, update semantics, and connected-subnet precedence; adds DNS getter test.
port/zephyr/README.md Documents the Zephyr port design, usage, patch structure, and limitations.
port/zephyr/patches/0001-wolfip-glue-and-public-api.patch Adds Zephyr glue/runtime, control wrappers, Kconfig/CMake integration, and public Zephyr header.
port/zephyr/patches/0002-net-l2-wolfip-module.patch Adds NET_L2_WOLFIP to intercept raw Ethernet frames and delegate L3+ to wolfIP.
port/zephyr/patches/0003-net-shell-wolfip.patch Makes Zephyr net-shell commands work when wolfIP is enabled (route/arp/ipv4/dhcp/ping/tcp/udp, etc.).
port/zephyr/patches/0004-sample-wolfip-tap-echo.patch Adds a Zephyr native_sim TAP-based TCP/UDP echo sample using wolfIP.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/wolfip.c
Comment thread src/wolfip.c Outdated
Comment thread port/zephyr/patches/0001-wolfip-glue-and-public-api.patch
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Comment thread src/wolfip.c
Comment thread src/wolfip.c Outdated
Copy link
Copy Markdown

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #114

Scan targets checked: wolfip-bugs, wolfip-src
Findings: 1

Low (1)

Functional inconsistency in TX interface selection and MAC address derivation

Function: wolfIP_select_nexthop_ex, ip_output_add_header, wolfIP_ll_send_frame, arp_lookup
Category: Logic Error

The routed tx_if from wolfIP_select_nexthop_ex is used for wolfIP_ll_send_frame and arp_lookup operations, while ip_output_add_header still derives the Ethernet source MAC from wolfIP_socket_if_idx(t). This represents a functional inconsistency where different code paths may select different interfaces for routing decisions and MAC address derivation.

Recommendation: Verify that the MAC address derivation in ip_output_add_header is correctly synchronized with the interface selected by wolfIP_select_nexthop_ex, or document the intentional separation of concerns if this behavior is by design. This should be verified to ensure consistent interface selection across the TX path.


This review was generated automatically by Fenrir. Findings are non-blocking.

@danielinux
Copy link
Copy Markdown
Member Author

Fenrir has a point in its comment, but the refactor needed is outside the scope for this PR, and there is no functional issue associated, so leaving as is.

@danielinux danielinux changed the title Zephyr TCP/IP replace Zephyr TCP/IP replacement May 11, 2026
Copy link
Copy Markdown
Member

@dgarske dgarske left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

@dgarske dgarske removed their assignment May 11, 2026
@dgarske dgarske assigned dgarske and unassigned ColtonWilley May 19, 2026
Comment thread wolfip.h
#if defined(__has_include)
#if __has_include(<sys/socket.h>)
#include <sys/socket.h>
#if __has_include(<sys/uio.h>)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing with Zephyr native_sim build:

FAIL ; wolfip.h redefines struct iovec/struct msghdr under Zephyr's POSIX layer

Zephyr native_sim build

Workspace set up at ~/zephyr-workspace/:

  • west 1.5.0 in ~/zephyr-venv/
  • Zephyr v4.4.0 shallow-cloned (release 684c9e8f)
  • All modules updated via west update --narrow -o=--depth=1
  • Zephyr SDK 1.0.1 minimal (host tools) installed at ~/zephyr-sdk/zephyr-sdk-1.0.1/
  • ~/wolfip -> /home/davidgarske/GitHub/wolfip-alt symlink so
    ${ZEPHYR_BASE}/../../wolfip resolves (per subsys/net/lib/wolfip/CMakeLists.txt:5)

All 4 patches applied cleanly (no --whitespace=nowarn complaints,
no hand fixups):

0001-wolfip-glue-and-public-api.patch     OK
0002-net-l2-wolfip-module.patch           OK
0003-net-shell-wolfip.patch               OK
0004-sample-wolfip-tap-echo.patch         OK

CMake configure succeeded. Build FAILED partway through, while compiling
/home/davidgarske/wolfip/src/wolfip.c for the wolfip library object.

Root cause: redefinition of struct iovec/struct msghdr on Zephyr

In file included from .../zephyr/include/zephyr/net/net_ip.h:2304,
                 from .../zephyr/include/zephyr/net/socket.h:33,
                 from .../zephyr/include/zephyr/posix/sys/socket.h:13,
                 from .../wolfip/wolfip.h:286,
                 from .../wolfip/src/wolfip.c:32:
.../zephyr/include/zephyr/net/net_compat.h:112:35: error: redefinition of
  struct net_iovec
  112 | #define iovec   net_iovec
.../wolfip/wolfip.h:295:8: note: in expansion of macro iovec
  295 | struct iovec { void *iov_base; size_t iov_len; };
.../zephyr/include/zephyr/net/net_ip.h:287:8: note: originally defined here
  287 | struct net_iovec {
...same error pattern for msghdr -> net_msghdr at wolfip.h:296...

Walkthrough of wolfip/wolfip.h:278-305:

#if defined(__has_include)
#if __has_include(<sys/socket.h>)
#include <sys/socket.h>                 /* Zephyr provides this; it transitively
                                           defines `iovec` -> `net_iovec` and
                                           `msghdr` -> `net_msghdr` */
#if __has_include(<sys/uio.h>)
#include <sys/uio.h>                    /* Zephyr does NOT ship this */
#define WOLFIP_HAVE_POSIX_TYPES 1
#endif
#endif
#endif

#ifndef WOLFIP_HAVE_POSIX_TYPES         /* still undefined under Zephyr */
struct iovec { void *iov_base; size_t iov_len; };   /* expands to
                                                       struct net_iovec - clash */
struct msghdr { ... };                              /* same for msghdr */
#endif

Under Zephyr's POSIX layer, <sys/socket.h> exists but <sys/uio.h> does not.
The current logic assumes POSIX systems ship them together. They don't on
Zephyr.

Suggested fix (for the author - not applied here)

Add Zephyr to the systems whose system iovec/msghdr is considered authoritative:

#if defined(__ZEPHYR__)
/* Zephyr's <zephyr/net/net_compat.h> aliases iovec/msghdr to net_* via
 * macros; the POSIX layer's <sys/socket.h> drags it in. Use those instead
 * of our local fallbacks. */
#define WOLFIP_HAVE_POSIX_TYPES 1
#endif

#if !defined(WOLFIP_HAVE_POSIX_TYPES) && defined(__has_include)
... existing block ...
#endif

Or, equivalently, gate the local struct definitions on !defined(iovec) /
!defined(msghdr) after the include block - the Zephyr macros block their
expansion in the same way.

@dgarske dgarske removed their assignment May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants