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

fix(mdns): fix compiling issue when disabling IPv4 (IDFGH-11453) #414

Merged
merged 2 commits into from
Feb 6, 2024

Conversation

wqx6
Copy link
Contributor

@wqx6 wqx6 commented Nov 3, 2023

IDF v5.1 provides a menuconfig option to disable IPv4 in LwIP. And mdns component compiling would fail when disabling IPv4

@igrr
Copy link
Member

igrr commented Nov 14, 2023

It would be nice to also add an sdkconfig.ci.* configuration with IPV4 disabled, so that at least the builds for this use case are validated in CI.

@github-actions github-actions bot changed the title fix(mdns): fix compiling issue when disabling IPv4 fix(mdns): fix compiling issue when disabling IPv4 (IDFGH-11453) Nov 14, 2023
@@ -17,6 +17,7 @@
#include "mdns_networking.h"
#include "esp_log.h"
#include "esp_random.h"
#include "lwip/opt.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use lwip headers from this file, it's supposed to be network stack independent.

You can use CONIG_LWIP_IPV4 instead or define a MNDS_IPV4 based on the config option in mdns_config.h

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONFIG_LWIP_IPV4 was introduced in IDF v5.1 but this managed component is for IDF version>=5.0, so I didn't use this config option here. May I create a menuconfig option in this component instead of using CONIG_LWIP_IPV4?

@wqx6 wqx6 force-pushed the fix/mdns_disable_ipv4 branch 2 times, most recently from 9a490aa to 562987d Compare November 16, 2023 10:46
@wqx6
Copy link
Contributor Author

wqx6 commented Nov 16, 2023

It would be nice to also add an sdkconfig.ci.* configuration with IPV4 disabled, so that at least the builds for this use case are validated in CI.

Added an configuration file that disables IPv4.

Copy link
Collaborator

@david-cermak david-cermak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in general.

The only concern is the LWIP dependency that you're bringing to everything or introduction of our own config options.

I cannot think of a decently elegant way to address this issue, but probably creating definitions of MDNS_IPV4/6 in mdns_config.h based on global config options and IDF release versions.

components/mdns/Kconfig Outdated Show resolved Hide resolved
@@ -185,7 +185,7 @@ static inline void _mdns_clean_netif_ptr(mdns_if_t tcpip_if)
static mdns_if_t _mdns_get_if_from_esp_netif(esp_netif_t *esp_netif)
{
for (int i = 0; i < MDNS_MAX_INTERFACES; ++i) {
if (esp_netif == s_esp_netifs[i].netif) {
if (esp_netif == s_esp_netifs[i].netif || (s_esp_netifs[i].predefined && esp_netif == esp_netif_from_preset_if(s_esp_netifs[i].predef_if))) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain the reason behind this change? I thought the static array already contains the predef netif, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The predefined netifs in the static array are NULL when firstly calling this function if IPv4 is disabled, and the mld6_joingroup_netif will not be called rightly then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment here/

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The predefined netifs in the static array are NULL

@gabsuren Could you please check?

@wqx6 Do you use the predefined interfaces (default STA, AP or Ethernet) or do you initialize netifs manually?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I used predefined STA interface

components/mdns/mdns.c Outdated Show resolved Hide resolved
components/mdns/mdns_networking_lwip.c Outdated Show resolved Hide resolved
components/mdns/mdns_networking_lwip.c Outdated Show resolved Hide resolved
components/mdns/mdns_networking_socket.c Outdated Show resolved Hide resolved
@wqx6 wqx6 force-pushed the fix/mdns_disable_ipv4 branch 10 times, most recently from 86e600d to 92883ce Compare November 20, 2023 03:00
@wqx6
Copy link
Contributor Author

wqx6 commented Nov 20, 2023

The CI fails for socket example, but I can resolve the hostnames with the socket sdkconfig locally. @david-cermak

@wqx6
Copy link
Contributor Author

wqx6 commented Dec 12, 2023

Could you please try rerunning it a few times to see if you can reproduce the issue?

I have run the pytest script for over 10 times, but none of them failed.

@wqx6 wqx6 force-pushed the fix/mdns_disable_ipv4 branch 10 times, most recently from 8e26ccb to b67aeec Compare January 10, 2024 10:43
@wqx6 wqx6 force-pushed the fix/mdns_disable_ipv4 branch 2 times, most recently from 6cbb5c4 to 41a9c9c Compare January 15, 2024 11:48
@chshu
Copy link

chshu commented Jan 25, 2024

@david-cermak @gabsuren The previous CI issue has been fixed. Could you review and merge it if no other comments? We also want to make a new mDNS release to publish this change, it's required by the Matter Sleep example for C6.

@@ -64,6 +64,7 @@ def mdns_server(esp_host, events):
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, 'eth0\0'.encode('utf-8'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we are binding it to eth0 only?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the pytest script is using eth0 to communicate with the test board on CI runner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two things concerning with this change.

  1. The tests may fail if we switch to a different interface or operating system, such as macOS or Windows. I can address this issue later by updating pytest myself.
  2. More worryingly, it's unclear why the tests were passing previously without being bound to the specific interface. This raises questions about potential breaking changes that could arise from this discrepancy.

Copy link
Contributor

@gabsuren gabsuren Feb 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wqx6 I have executed the changes without binding, in separate PR503 and it passed
https://github.com/espressif/esp-protocols/actions/runs/7783718151

So I suppose this change is not necessary . Could you please, revert this and rebase with master so we can merge it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

Comment on lines -350 to -356
mdns_ip_protocol_t other_ip_proto = ip_protocol == MDNS_IP_PROTOCOL_V4 ? MDNS_IP_PROTOCOL_V6 : MDNS_IP_PROTOCOL_V4;
int err = join_mdns_multicast_group(sock, netif, other_ip_proto);
if (err < 0) {
ESP_LOGE(TAG, "Failed to add ipv6 multicast group for protocol %d", ip_protocol);
return false;
}
s_interfaces[tcpip_if].proto |= (other_ip_proto == MDNS_IP_PROTOCOL_V4 ? PROTO_IPV4 : PROTO_IPV6);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why this was removed? The idea is that we already have a socket supporting one IP protocol (say IPv4) and someone calls create_pcb(same_netif, IPv6). Then we'll never join the IPv6 multicast group, correct?

Copy link
Contributor Author

@wqx6 wqx6 Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The create_pcb(some_netif, IPv6) will still call join_mdns_multicast_group(sock, netif, IPv6); in the following code.

But if we keep the original logic, When we already have a socket supporting IPv4, and then someone calls create_pcb(some_netif, IPv4), the netif will never join IPv4 multicast group.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. so you actually always join the multicast group (again).
This would (probably?) work as we guard this in mdns.c using mdns_is_netif_ready() API.

Copy link
Collaborator

@david-cermak david-cermak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes LGTM, provided that the socket networking part has been tested with IPv4 only and dual stack.

@gabsuren gabsuren merged commit 891384c into espressif:master Feb 6, 2024
59 of 60 checks passed
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

Successfully merging this pull request may close these issues.

6 participants