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

[IDF5.x] Client remoteIP incorrect #8774

Closed
1 task done
TD-er opened this issue Oct 16, 2023 · 5 comments
Closed
1 task done

[IDF5.x] Client remoteIP incorrect #8774

TD-er opened this issue Oct 16, 2023 · 5 comments
Labels
Area: WiFi Issue related to WiFi Status: Needs investigation We need to do some research before taking next steps on this issue

Comments

@TD-er
Copy link
Contributor

TD-er commented Oct 16, 2023

Board

ESP32 (classic)

Device Description

WROOM ESP32

Hardware Configuration

Version

other

IDE Name

PlatformIO

Operating System

Windows 11

Flash frequency

40MHz

PSRAM enabled

yes

Upload speed

115200

Description

When calling web_server.client().remoteIP() I no longer get the IP-adres of the connected client.
In my project (ESPEasy) I try to block connections not coming from the local subnet.
In some occasions the browser doesn't seem to provide the client IP, so there was an exception for 0.0.0.0 to be allowed.
This has been working fine for years and doesn't seem to be a problem on ESP32-S2/C3
But on the ESP32 classic, I'm now experiencing blocks even with random looking reported remote IP-addresses like 35.0.6.0. (I'm on the same subnet as my ESP node)

On ESP32-S3/C3 running ESP32 SDK 5.1.1.230920 I noticed I never see the client IP (remoteIP()) anymore.
On recent builds using the same code build with ESP32 SDK 4.4.5.230614 I can get the client IP just fine.

I use @Jason2866 's packaged platform packages:

  • IDF 5.1: platform = https://github.com/Jason2866/platform-espressif32.git#ae949bcf416213717662095f67cd76d85a810529
  • IDF 4.4.5:
platform                    = https://github.com/tasmota/platform-espressif32/releases/download/2023.10.03/platform-espressif32.zip
platform_packages           = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/1645/framework-arduinoespressif32-release_v4.4_spiffs-e3fc63b439.zip

Sketch

-

Debug Message

-

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@TD-er TD-er added the Status: Awaiting triage Issue is waiting for triage label Oct 16, 2023
@VojtechBartoska
Copy link
Contributor

Hi, seems this is caused by breaking changes in migration from 2.X to 3.X. We will soon finish migration guide and I will create one issue, where we will collect all the questions and possible issue to not overflow project issue tracker.

@TD-er
Copy link
Contributor Author

TD-er commented Oct 16, 2023

OK, can you maybe already tell me which function I should use here so I can already test with it?
I may have other related issues and I guess it would be useful if I already understand where to look, to save you time and perhaps I can then also help completing that new migration guide as I already have done a lot of the migration myself in my project.

@VojtechBartoska
Copy link
Contributor

#8716 here is the Migration Guide PR

@VojtechBartoska VojtechBartoska added 3.0 migration issue relates to migration from 2.X to 3.X version Type: Question Only question and removed Status: Awaiting triage Issue is waiting for triage labels Oct 16, 2023
@P-R-O-C-H-Y P-R-O-C-H-Y added Status: Needs investigation We need to do some research before taking next steps on this issue Area: WiFi Issue related to WiFi and removed Type: Question Only question 3.0 migration issue relates to migration from 2.X to 3.X version labels Oct 18, 2023
@TD-er
Copy link
Contributor Author

TD-er commented Oct 18, 2023

OK, so it wasn't an API change.

I suspect it may have something to do with clientSocketHandle.
And if this is true, then this function will also not work when checking 2 of such clients:

bool WiFiClient::operator==(const WiFiClient& rhs)

Here is the client being set in the WebServer:

void WebServer::handleClient() {
  if (_currentStatus == HC_NONE) {
    _currentClient = _server.available();

However....

WiFiClient WiFiServer::available(){
  if(!_listening)
    return WiFiClient();

This function also returns a default WiFiClient() when client_sock < 0 (may happen when sockfd is has not been set?) or either of the setsockopt calls return false.

N.B. I do not (yet) use IPv6 and it seems like sockfd is only set when you can create a socket for the AF_INET6 domain.

So it seems like either the sockfd is the culprit here or _listening ??

N.B.2: _listening is only set to true when the WiFiServer::begin does not return before the end of the function.
So that makes sockfd the main suspect here I guess?

@TD-er
Copy link
Contributor Author

TD-er commented Feb 19, 2024

By the way, this seems to be fixed, so I will close it now.

@TD-er TD-er closed this as completed Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: WiFi Issue related to WiFi Status: Needs investigation We need to do some research before taking next steps on this issue
Projects
None yet
Development

No branches or pull requests

3 participants