Arduino icon indicating copy to clipboard operation
Arduino copied to clipboard

WiFiClient cannot connect to IPv6 link local address

Open Jamesits opened this issue 5 years ago • 5 comments

Basic Infos

  • [x] This issue complies with the issue POLICY doc.
  • [x] I have read the documentation at readthedocs and the issue is not addressed there.
  • [x] I have tested that the issue is present in current master branch (aka latest git).
  • [x] I have searched the issue tracker for a similar issue.
  • [x] If there is a stack dump, I have decoded it.
  • [x] I have filled out all fields below.

Platform

  • Hardware: ESP8266MOD
  • Core Version: 2.5.2
  • Development Env: Arduino IDE
  • Operating System: Windows

Settings in IDE

  • Module: Wemos D1 R2 & mini
  • Flash Size: 4MB
  • lwip Variant: v2 IPv6 Higher Bandwidth
  • Reset Method: ck
  • CPU Frequency: 80Mhz
  • Upload Using: SERIAL
  • Upload Speed: 921600

Problem Description

As per https://github.com/esp8266/Arduino/pull/5136, IPv6 is supported on the recent versions of ESP8266. However, I observed that WiFiClient.connect() is not able to connect to an IPv6 link-local IP address (fe80::/10) on the same network with the ESP8266.

MCVE Sketch

#include <ESP8266WiFi.h>

#define STA_SSID "your-ssid"
#define STA_PSWD "your-wifi-password"
#define SERVER_IP "fe80::aaaa:bbff:fecc:dddd"

IPAddress server;
WiFiClient client;

void setup() {
  Serial.begin(115200);

  WiFi.mode(WIFI_STA);
  WiFi.setAutoConnect(true);
  WiFi.setAutoReconnect(true);
  WiFi.begin(STA_SSID, STA_PSWD);
}

void loop() {
    Serial.println("\nStarting connection...");
    // if you get a connection, report back via serial:
    server.fromString(SERVER_IP);
    if (client.connect(server, 8000)) {
      Serial.println("connected");
      // Make a HTTP request:
      client.println("GET / HTTP/1.0");
      client.println();
    } else {
      Serial.println("Failed to connect");
    }
    delay(500);
}

Debug Messages

Sketch output:

Starting connection...
Failed to connect

I've done a packet capture on the server and can see NO packets from ESP8266.

Jamesits avatar Oct 10 '19 08:10 Jamesits

Is there any update on this?

theGeekyLad avatar Jan 02 '22 12:01 theGeekyLad

I am still not an IPv6 specialist.

My linux laptop cannot reach my server through fe80: and I need to add the interface name, like: $ ping fe80:...:852c%wlp2s0. However $ ping fd6f:...:852c works.

Can you give it a try ?

d-a-v avatar Jan 04 '22 21:01 d-a-v

@d-a-v Normally you'd need to bind to an interface when using fe80 link-local IPs since they are bound to an interface. There is no way to do this on the ESP8266 SDK...

Jamesits avatar Jan 05 '22 05:01 Jamesits

lwIP has it and we use it: https://github.com/esp8266/Arduino/blob/a05a71fa9d2e6b143cb34f01b47e22c4b66b80a1/libraries/ESP8266WiFi/src/include/UdpContext.h#L99-L104 https://github.com/esp8266/Arduino/blob/c312a2eaf1356ceaafad7c4935fa850e087c84fe/libraries/ESP8266WiFi/src/include/ClientContext.h#L134-L139

netif_default should be set to the STA interface (<= this is next version and this is current version).

d-a-v avatar Jan 05 '22 09:01 d-a-v

I was asking to try because fd6f: is not public and is a reserved address dedicated to local area, as fe80: is reserved for the link only. I don't remember and I have no ipv6 environment right now to check if the ipv6 implementation of lwIP binds to this domain too. Please correct me if I'm mistaken.

d-a-v avatar Jan 05 '22 09:01 d-a-v