Skip to content
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

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

Open
6 tasks done
rrelande opened this issue Feb 13, 2024 · 1 comment
Open
6 tasks done

Comments

@rrelande
Copy link

rrelande commented Feb 13, 2024

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • 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 #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 
@d-a-v
Copy link
Collaborator

d-a-v commented Feb 13, 2024

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).

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

No branches or pull requests

2 participants