Skip to content

Broaden IPv6 support in MicroPython by default. #17545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

andrewleech
Copy link
Contributor

@andrewleech andrewleech commented Jun 21, 2025

Summary

This PR broadens IPv6 support, enabling it by default on supported platforms.

It was originally part of #16459 but I felt it should be tested separately.

This turns on some of the missing pieces to ensure auto detection to work correctly, similar to mdns in ipv4.
Part of this was consolidating changes from #15422 into the common settings for all ports.

With the work on usb-networking I've found ipv6 very helpful for local devices to not need to worry about dhcp configuration and discovery, ipv6 can "just work" without ip address collisions from multiple devices.

Core IPv6 Features

LWIP IPv6 Configuration:

  • Consolidates more of the common lwip configuration.
  • Enables LWIP_IPV6 support by default in common LWIP configuration
  • Configures IPv6 autoconfiguration (LWIP_IPV6_AUTOCONFIG)
  • Enables IPv6 multicast listener discovery (LWIP_IPV6_MLD)
  • Supports multicast ping responses for neighbor discovery

Ethernet Driver IPv6 Support:

  • STM32 ethernet driver: IPv6 packet handling and multicast support
  • i.MX RT ethernet driver: IPv6 packet handling and multicast support
  • ESP-Hosted WiFi driver: IPv6 support for ESP-hosted network interface

Implementation Pattern:
Each network driver follows a consistent IPv6 integration pattern:

  • Include lwip/ethip6.h when LWIP_IPV6 is enabled
  • Set output_ip6 to ethip6_output for IPv6 packet handling
  • Add NETIF_FLAG_MLD6 flag for IPv6 multicast support
  • Create IPv6 link-local address after interface initialization

Files Modified

Core LWIP Configuration:

  • extmod/lwip-include/lwipopts_common.h: Enable IPv6 by default with autoconfig

Network Drivers:

  • ports/stm32/eth.c: Add IPv6 support to STM32 ethernet driver
  • ports/mimxrt/eth.c: Add IPv6 support to i.MX RT ethernet driver
  • drivers/esp-hosted/esp_hosted_netif.c: Add IPv6 support to ESP-hosted driver

Port Configuration Cleanup:

  • ports/renesas-ra/lwip_inc/lwipopts.h: Remove port-specific IPv6 disable
  • ports/mimxrt/lwip_inc/lwipopts.h: Remove port-specific IPv6 disable

Test Coverage

New IPv6-Specific Tests:

  • tests/extmod/socket_ipv6_basic.py: Basic IPv6 socket operations and binding
  • tests/multi_net/tcp_data_ipv6.py: IPv6 TCP client-server communication
  • tests/multi_net/udp_data_ipv6.py: IPv6 UDP client-server communication
  • tests/net_inet/getaddrinfo_ipv6.py: IPv6 DNS resolution and dual-stack support

All tests include graceful fallback when IPv6 support is not available.

Testing

Unix Port Testing (Completed):

  • ✅ Basic IPv6 socket creation and binding operations
  • ✅ IPv6 TCP client-server data transfer via multi-instance tests
  • ✅ IPv6 UDP client-server communication with packet loss tolerance
  • ✅ IPv6 DNS resolution including dual-stack and domain name resolution
  • ✅ All tests pass on Unix port with full IPv6 network stack

On-Device Testing (Pending):

  • STM32 boards with ethernet: IPv6 functionality verification needed
  • i.MX RT boards with ethernet: IPv6 functionality verification needed
  • ESP32/ESP8266 with ESP-hosted: IPv6 WiFi connectivity verification needed

Test Commands:

# Basic socket tests
./tests/run-tests.py tests/extmod/socket_ipv6_basic.py

# Multi-instance communication tests  
./tests/run-multitests.py tests/multi_net/tcp_data_ipv6.py
./tests/run-multitests.py tests/multi_net/udp_data_ipv6.py

# DNS resolution tests
./tests/run-tests.py tests/net_inet/getaddrinfo_ipv6.py

Trade-offs and Alternatives

Benefits:

  • Enables modern IPv6 networking capabilities
  • Maintains full backward compatibility with existing IPv4 code
  • Consistent implementation across multiple hardware platforms
  • Comprehensive test coverage for validation

Code Size Impact:

  • Minor increase in code size due to IPv6 protocol stack inclusion
  • Only affects builds with networking enabled
  • Can be disabled by setting LWIP_IPV6=0 if needed

Alternative Approaches Considered:

  • Port-by-port IPv6 enablement: Rejected in favor of unified approach
  • Optional IPv6 support: Current implementation provides good defaults while allowing override

The implementation provides a solid foundation for IPv6 networking across the MicroPython ecosystem with minimal disruption to existing functionality.

@andrewleech andrewleech marked this pull request as draft June 21, 2025 21:30
Copy link

codecov bot commented Jun 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.56%. Comparing base (09541b7) to head (e17730a).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #17545   +/-   ##
=======================================
  Coverage   98.56%   98.56%           
=======================================
  Files         169      169           
  Lines       21950    21950           
=======================================
  Hits        21636    21636           
  Misses        314      314           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

github-actions bot commented Jun 21, 2025

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:  -620 -0.068% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@andrewleech andrewleech changed the title Add comprehensive IPv6 support to MicroPython networking stack Broaden IPv6 support in MicroPython by default. Jun 21, 2025
@andrewleech andrewleech force-pushed the ipv6_support branch 6 times, most recently from 7bc5cb2 to ee0881d Compare June 22, 2025 10:29
pi-anl added 7 commits June 22, 2025 20:31
Enable IPv6 support by default in the common LWIP configuration:
- LWIP_IPV6=1: Enable IPv6 protocol stack
- LWIP_IPV6_AUTOCONFIG=1: Enable IPv6 autoconfiguration
- LWIP_IPV6_MLD=1: Enable IPv6 Multicast Listener Discovery
- LWIP_ND6_NUM_DESTINATIONS=4: Set neighbor discovery cache size
- LWIP_ND6_QUEUEING=0: Disable ND6 queueing to reduce RAM usage

Also includes atoi declaration and redirect for LWIP compatibility.

Signed-off-by: Andrew Leech <[email protected]>
LWIP uses atoi in netif_find and getaddrinfo functions but some
MicroPython ports don't provide it. Add lwip_atoi implementation
for LWIP's use, redirected via lwipopts_common.h define.

Signed-off-by: Andrew Leech <[email protected]>
Add IPv6 support by:
- Including lwip/ethip6.h header when LWIP_IPV6 is enabled
- Setting output_ip6 to ethip6_output for IPv6 packet handling
- Adding NETIF_FLAG_MLD6 flag for IPv6 multicast support
- Creating IPv6 link-local address after interface initialization
- Remove redundant LWIP_IPV6 definition (now in common config)

Signed-off-by: Andrew Leech <[email protected]>
Add IPv6 support by:
- Including lwip/ethip6.h header when LWIP_IPV6 is enabled
- Setting output_ip6 to ethip6_output for IPv6 packet handling
- Adding NETIF_FLAG_MLD6 flag for IPv6 multicast support
- Creating IPv6 link-local address after interface initialization

Signed-off-by: Andrew Leech <[email protected]>
Add IPv6 support by:
- Including lwip/ethip6.h header when LWIP_IPV6 is enabled
- Setting output_ip6 to ethip6_output for IPv6 packet handling
- Adding NETIF_FLAG_MLD6 flag for IPv6 multicast support
- Creating IPv6 link-local address after interface initialization

Signed-off-by: Andrew Leech <[email protected]>
Remove local LWIP_IPV6 definition to use the common IPv6 configuration
from extmod/lwip-include/lwipopts_common.h.

Signed-off-by: Andrew Leech <[email protected]>
IPv6 settings are now defined in the common LWIP configuration:
- LWIP_IPV6 is enabled by default in lwipopts_common.h
- LWIP_ND6_NUM_DESTINATIONS is set to 4 in lwipopts_common.h
- LWIP_ND6_QUEUEING is set to 0 in lwipopts_common.h

Signed-off-by: Andrew Leech <[email protected]>
@andrewleech andrewleech force-pushed the ipv6_support branch 2 times, most recently from c4e1886 to ac1d326 Compare June 22, 2025 10:56
…ion.

Enable IPv6 support when ROM level is at least EXTRA and consolidate
IPv6 configuration settings in the common LWIP configuration:
- LWIP_IPV6=MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA
- LWIP_IPV6_AUTOCONFIG=1: Enable IPv6 autoconfiguration
- LWIP_IPV6_MLD=1: Enable IPv6 Multicast Listener Discovery
- LWIP_ND6_NUM_DESTINATIONS=4: Set neighbor discovery cache size
- LWIP_ND6_QUEUEING=0: Disable ND6 queueing to reduce RAM usage

Also includes atoi declaration and redirect for LWIP compatibility.

Signed-off-by: Andrew Leech <[email protected]>
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.

2 participants