← index #3683PR #17545
Likely Duplicate · medium · value 2.726
QUERY · ISSUE

IPv6 Support in micropython for ESP32 (or anything for that matter)

openby owendelongopened 2018-03-26updated 2026-01-25
port-esp32

It looks like LWIP in the ESP-IDF being used for micropython has IPv6 support.

Is there an effort to take advantage of the yet? I found some documentation which stated that IPv6 support was "port" dependent, but I have yet to find any port of micropython with IPv6 support enabled.

It looks like the current build has IPv6 capabilities in the usocket module, but it looks like there are no IPv6 capabilities in the network or WLAN class implementations which means that the interface can't get an IPv6 address, etc.

I'm willing to put some effort into trying to do the needful, but the existing API seems to be so thoroughly incapable of understanding that there could possibly be any protocol other than IPv4 that I'm unsure how to go about providing a mergeable codebase that wouldn't break people's existing code.

Further, I'd like to know if there are any standard APIs for IPv6 interface configuration that I should be following as the existing interface configuration capabilities in the ESP32 port are quite thoroughly incapable of such.

Any pointers (or ideally a solution already developed) greatly appreciated.

CANDIDATE · PULL REQUEST

Broaden IPv6 support in MicroPython by default.

openby andrewleechopened 2025-06-21updated 2025-07-31

Summary

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

It was originally part of https://github.com/micropython/micropython/pull/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 https://github.com/micropython/micropython/pull/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.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied