Arduino icon indicating copy to clipboard operation
Arduino copied to clipboard

Cannot loop traffic to internal real network interface - not using loopback

Open rrelande opened this issue 2 years ago • 1 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: [ESP-12]
  • Core Version: 3.1.2
  • Development Env: [Platformio]
  • Operating System: [Windows]

Settings in IDE

  • Module: [Generic ESP8266 Module|]
  • Flash Mode: [qio]
  • Flash Size: [4MB]
  • lwip Variant: [v2 Lower Memory]
  • Reset Method: [ck|nodemcu]
  • Flash Frequency: [40Mhz]
  • CPU Frequency: [80Mhz|]
  • Upload Using: [SERIAL]
  • Upload Speed: [115200

Problem Description

it it previously indicated that local loopback interface 127.0.0.1 is not available in lwip2 and advised against trying to use. as documented in https://github.com/esp8266/Arduino/issues/6437 previous case suggests to use the local available real interface instead of 127.0.0.1 as loopback. however as seen below, traffic routed to the local UDP socket is not received by the stack.

the UDP client listens to external traffic and sees traffic coming from netcat on another computer. but not from internal stack

MCVE Sketch

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

#define WIFI_SSID "xxxxxx"
#define WIFI_PASSWORD "yyyyy"
#define SYSLOG_SERVER "lmSyslog.local"
#define SYSLOG_PORT 514

WiFiUDP udpServer, udpClient;
unsigned int received_bytes = 0;

void setup()
{
    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
    while (WiFi.status() != WL_CONNECTED)
    {
        delay(500);
    }
    digitalWrite(LED_PIN, HIGH);

    Serial.begin(9600, SERIAL_8N1);
    udpServer.begin(SYSLOG_PORT);
    delay(100);
};

// the loop routine runs over and over again forever:
void loop()
{
    Serial.print("Sending to loopback server on local interface not loopback 127.0.0.1 ");
    delay(100);
    udpClient.beginPacket(WiFi.localIP(), SYSLOG_PORT);
    udpClient.write("Hello, world");
    udpClient.endPacket();
    delay(100);
    received_bytes = udpServer.parsePacket();
    Serial.printf("Relay loop on %s, UDP queue size %d \n", WiFi.localIP().toString().c_str(),  received_bytes);
    for (int i = 0; i < received_bytes; i++)
    {
        char c = udpServer.read();
        Serial.printf("%c", c);
    }

    delay(1000);
};

Debug Messages


ing to loopback server on local interface not loopback 127.0.0.1 Relay loop on 192.168.0.171, UDP queue size 0 
Sending to loopback server on local interface not loopback 127.0.0.1 Relay loop on 192.168.0.171, UDP queue size 0 
Sending to loopback server on local interface not loopback 127.0.0.1 Relay loop on 192.168.0.171, UDP queue size 0 
Sending to loopback server on local interface not loopback 127.0.0.1 Relay loop on 192.168.0.171, UDP queue size 0 
Sending to loopback server on local interface not loopback 127.0.0.1 Relay loop on 192.168.0.171, UDP queue size 0 
Sending to loopback server on local interface not loopback 127.0.0.1 Relay loop on 192.168.0.171, UDP queue size 0 
Sending to loopback server on local interface not loopback 127.0.0.1 Relay loop on 192.168.0.171, UDP queue size 17 
UDP test message
Sending to loopback server on local interface not loopback 127.0.0.1 Relay loop on 192.168.0.171, UDP queue size 0 
Sending to loopback server on local interface not loopback 127.0.0.1 Relay loop on 192.168.0.171, UDP queue size 0 
Sending to loopback server on local interface not loopback 127.0.0.1 Relay loop on 192.168.0.171, UDP queue size 0 

rrelande avatar Feb 13 '24 06:02 rrelande

The loopback interface is explicitly disabled in the current configuration.

Then these packets are not retained so they should be(?) sent, and are lost in the network: they are probably discarded by the switch integrated in the AP because this is a non-sense to send a packet back to its sender.

This could also be checked using the included netdump library for which we have a provided example. It allows to monitor everything coming in to and out from all network interfaces of the esp8266. It often helps to understand what happens around the network interface (tcpdump-like).

d-a-v avatar Feb 13 '24 10:02 d-a-v