Description
Board
m5stack-core2
Device Description
M5Stack Core2 ESP32 IoT Development Kit for AWS IoT Kit, https://shop.m5stack.com/products/m5stack-core2-esp32-iot-development-kit-for-aws-iot-edukit?variant=37687799251116
Hardware Configuration
Just the M5Stack Core2
Version
latest master (checkout manually)
IDE Name
PlatformIO
Operating System
Ubuntu 22.04
Flash frequency
240Mhz
PSRAM enabled
yes
Upload speed
115200
Description
Issue
The localIPv6()
and globalIPv6()
accessors in WiFiSTA.h
are implemented inconsistently with how localIP()
is implemented, and how localIP()
and remoteIP()
are used in WiFiClient.h
.
What should happen
globalIPv6()
should be removedlocalIP()
should continue to return the local host global scope IPv4 addresslocalIPv6()
should change to be consistent and return the local host global scope IPv6 address, if available- If a global scope IPv6 address is not available, then
localIPv6()
should return (in priority order) a local host ULA IPv6 address, or a local host link-local scope IPv6 address.- This is consistent with
localIP()
which may return the local host link-local scope IPv4 address (if there is no global scope IPv4 and link-local IPv4 is enable in LWIP)
- This is consistent with
- Some mechanism should be provided to get the other additional IPv6 addresses
Mechanism for additional IPv6 addresses
Ideally:
- For additional IPv6 addresses, change the signature to
IPAddress localIPv6(uint8_t address_no = 0)
, similar todnsIP(dns_no)
.- Return prioritised as above, with
0
(i.e. just defaultlocalIP()
) returning global scope if available 1
,2
, etc returning subsequent addresses- Once addresses have run out, return empty result.
- Common scenario examples:
a. Single global scope IPv6 address,0
= global scope address,1
= link-local scope address
b. No global scope IPv6 address,0
= link-local scope address
- Return prioritised as above, with
Alternative:
- Add
globalScopeIPv6()
to return a global scope IPv6 (same as current globalIPv6())- May not have have a global scope IPv6 address if not available on the network (e.g. no RA)
- Add
linkScopeIPv6()
to return a link-local scope IPv6 (same as current localIPv6())- This avoids using the term 'local' with a different meaning; linkLocalScopeIPv6() address could be another option, which uses the correct name and does not have inconsistent use of 'local', but may still cause confusion. linkScopeIPv6() completely avoids the use of the word 'local'.
- A node will always have a link-local IPv6 (if IPv6 is enabled), as it is auto-configured.
- A drawback of this approach is it only gets 2 addresses when there may be more
Sketch
No directly relevant; the issue is inconsistent naming.
Debug Message
n/a
Other Steps to Reproduce
Background
The new (alpha 3) code in WiFiSTA.h
header has several accessors to get the different IP addresses of the local station:
IPAddress localIP();
IPAddress localIPv6();
IPAddress globalIPv6();
This is only alpha, so it would be good to see the naming here fixed before release.
However the usage of the terms here is inconsistent, with some confusion between local as opposed to remote and the concept of link-local addresses.
For comparison WiFiClient.h
header (and WiFiUdp.h
) has the following accessors, representing a connection where localIP()
is the local end and remoteIP()
is the remote end:
IPAddress remoteIP() const;
IPAddress localIP() const;
As IPAddress now supports IPv6, these connection address could be a local, and remote, IPv6 address, or IPv4.
The WiFiSTA.h
accessor of localIP()
is similar, in that it represents the local (as opposed to remote), usually an IPv4 private network address, e.g. 192.168.0.x
. In the current implementation it is limited to IPv4 addresses.
Whilst it happens to usually be a private address range, a company with a public IPv4 address allocation could use it for WiFi, and the LWIP option CONFIG_LWIP_AUTOIP
could also allow the device to self-assign an address in the IPv4 local-link range 169.256/16
range (see RFC 3927).
So localIP()
could be a private IPv4 address, global IPv4 address, or a link-local IPv4 address.
However localIP()
does not give you IPv6 addresses, even if they are the only ones available (e.g. IPv6 only network).
There is a localIPv6()
accessor, however it appears to have been misinterpretted as being for link-local addresses only, an apparent confusion between local and link-local. This is inconsistent with the IPv4 version which is usually a private or global address (but could be link local).
Further the confusing accessor globalIPv6()
has been introduced.
To show the best/most appropriate local address client code needs to check globalIPv6()
first, then localIP()
, then localIPv6()
, when all they want to know is what is their IP address.
Only allowing a single return result is probably okay for IPv4, where multiple addresses are rare, but for IPv6 not only is it common to have at least two addresses (you keep your link-local address when you acquire a global one), but it is also common to have multiple global addresses (although LWIP doesn't yet support DHCPv6 or private extensions, so commonly will only have 2).
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.
Historical note - original suggestions:
- localIPv6() and globalIPv6() should be removed
- localIP() should return the most relevant IPAddress, of any type, for the station, i.e. same as localIP() for WiFiClient.h, it could be IPv6 or IPv4.
- The priority order should be, if available: global IPv6 address, global IPv4 address, link-local IPv6 address, link-local IPv4 address, or the empty address.
- This means on any IPv4 only network, or when enableIPv6() is not set, localIP() will always return an IPv4 address (backwards compatible).
- Only an IPv6-only system, localIP() will return the local (as opposed to remote) IPv6 address, with a preference for a global IPv6 address, if available, over a link-local address.
Metadata
Metadata
Assignees
Type
Projects
Status