Skip to content

[WIP] net/lwip: [EXPERIMENTAL] Add auxiliary lwIP stack for sim. - #20160

Draft
elokuucadiaN wants to merge 1 commit into
apache:masterfrom
elokuucadiaN:lwip-sim-integration
Draft

elokuucadiaN wants to merge 1 commit into
apache:masterfrom
elokuucadiaN:lwip-sim-integration

Conversation

@elokuucadiaN

Copy link
Copy Markdown

Supersedes #20159, which GitHub closed automatically when the source branch was renamed.

Summary

  • Add the complete lwIP 2.0.3 source tree as an optional auxiliary stack. Its BSD license is retained in net/lwip/lwip-2.0.3/COPYING.
  • Add the NuttX sys_arch port, Ethernet link adapter, and a raw L2 tap for the simulator network driver. Applications select the prefixed lwip_* API; native NuttX socket routing is unchanged.
  • Add sim:lwip configuration and documentation, including the requirement to initialize lwIP from a long-lived context.
  • This initial integration is simulator-only and experimental. The tests use three local nuttx-apps programs that are not included in this NuttX PR; there is no dependent apps PR.

Impact

  • New feature: Yes, behind CONFIG_NET_LWIP, currently limited to ARCH_BOARD_SIM && NET_PKT.
  • Existing users and compatibility: No change when the option is disabled. With the option enabled, applications must explicitly use the lwip_* API and initialize the auxiliary stack in a persistent context.
  • Build: Adds the optional lwIP sources and sim:lwip configuration; no default configuration is changed.
  • Hardware: Simulator Ethernet only. No physical board or hardware driver is changed.
  • Documentation: Documentation/components/net/lwip.rst is included.
  • Security: A second TCP/IP stack and raw link-layer tap increase the enabled build's network attack surface; this experimental option is disabled by default.

Testing

  • Build host: WSL2 Ubuntu 22.04, x86_64, GCC 11.4.0.

  • Target: sim:lwip, NuttX master base bc116157329946d2f7e6c82eb4b2d82009a41ebb; fresh export from the staged Git tree, make olddefconfig && make -j8 completed successfully.

  • Local test setup: BOARDCTL_FINALINIT disabled and the three local test programs enabled only in the isolated build configuration. The local NSH test harness calls nuttx_lwip_initialize() from its persistent context. These test-only apps and configuration changes are not included in this PR.

  • Runtime: Within one NSH session over a TAP interface (10.0.1.1/24), the host receiver logged:

    UDP ('10.0.1.3', 49153): 16 bytes, b'hello from lwip\n'
    TCP ('10.0.1.3', 49153): b'hello from lwip tcp\n'
    TCP ('10.0.1.3', 49153): received 20 bytes in 1.009 s
    TCP ('10.0.1.3', 49154): received 67108864 bytes in 4.697 s
    tcpbench: total=67108864 bytes time=4.696763 sec throughput=114.307 Mbps
    
  • NuttX nxstyle completed with no diagnostics for the ten NuttX-written/modified C and header files. The complete vendored lwIP tree is preserved verbatim; git diff --check reports pre-existing trailing whitespace in third-party files.

  • No physical hardware runtime result is available: the current link adapter only supports sim. This is a draft for architecture and scope discussion, not a request to merge without meeting the project's testing requirements.

PR verification self-check

  • One functional change: optional auxiliary lwIP integration.
  • Required scope, impact, testing limitations, and documentation described.
  • All contribution requirements are satisfied; hardware testing and third-party lint disposition remain open.
  • Work in progress; keep this PR as a draft.
  • Ready for review and merge.

Integrate the complete lwIP 2.0.3 source tree as an optional stack alongside
NuttX networking. Add a NuttX sys_arch port, an Ethernet adapter, and a
simulator L2 tap so applications can explicitly use the lwip_* socket API
without replacing native NuttX socket routing.

Provide sim:lwip configuration and documentation for setup and the required
long-lived initialization context. The implementation is currently limited
to the simulator Ethernet driver and remains experimental.

Verified with a clean WSL2 Ubuntu 22.04 / GCC 11.4.0 sim:lwip build. In one
simulator session, UDP delivered 16 bytes, TCP delivered 20 bytes, and a
TCP transfer delivered 67108864 bytes in 4.697 seconds. Test applications
are maintained outside this NuttX change.

Assisted-by: Codex:gpt-5
Assisted-by: Codex:gpt-5.6-sol
Signed-off-by: 21c <2022685682@qq.com>
@xiaoxiang781216

xiaoxiang781216 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

@elokuucadiaN but why do we need integrate lwip? nuttx has the native tcp/ip support.

Comment thread net/lwip/arch/cc.h
@@ -1,5 +1,5 @@
/****************************************************************************
* arch/arm/src/stm32h5/stm32_mpuinit.c
* net/lwip/arch/cc.h

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nuttx normally doesn't add the 3rd party source code into git directly

const uint8_t *buf,
unsigned int len);

int sim_netdriver_l2tap_register(int devidx,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why not reuse sim_tapdev_xxx

@github-actions github-actions Bot added Area: Documentation Improvements or additions to documentation Arch: simulator Issues related to the SIMulator Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. Board: simulator labels Sep 16, 2026
@acassis

acassis commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

@elokuucadiaN I think the question that @xiaoxiang781216 raised is valid: you forgot to explain "why?"

I know that Samsung used lwIP because they thought that the default stack was slow; but in fact they were using the default network stack parameters that is tailored to fit on small devices, so buffers were minimum, fragmentation were huge, etc. Configuring the network stack correctly it is so fast as lwIP or even faster than lwIP.

That said, I think having an option to use lwIP on NuttX is fine, the only problem is this: probably you will add it and disappear, so it will be "another baby" for our small community to take care :-)

@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@acassis

acassis commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

@elokuucadiaN suggestion: instead of close an open PR you can use "git rebase -i ..." and later "git push -f"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: simulator Issues related to the SIMulator Area: Documentation Improvements or additions to documentation Board: simulator Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants