-
Notifications
You must be signed in to change notification settings - Fork 136
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
Conversation
fd080cd
to
b02c99d
Compare
b02c99d
to
b5a29ae
Compare
It would be nice to also add an |
components/mdns/mdns.c
Outdated
@@ -17,6 +17,7 @@ | |||
#include "mdns_networking.h" | |||
#include "esp_log.h" | |||
#include "esp_random.h" | |||
#include "lwip/opt.h" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
?
9a490aa
to
562987d
Compare
Added an configuration file that disables IPv4. |
There was a problem hiding this 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/mdns.c
Outdated
@@ -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))) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comment here/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
86e600d
to
92883ce
Compare
The CI fails for socket example, but I can resolve the hostnames with the socket sdkconfig locally. @david-cermak |
I have run the pytest script for over 10 times, but none of them failed. |
ba002a9
to
d4eb6a7
Compare
8e26ccb
to
b67aeec
Compare
6cbb5c4
to
41a9c9c
Compare
41a9c9c
to
5000a9a
Compare
@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')) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I didn't bind the interface, CI will fail https://github.com/espressif/esp-protocols/actions/runs/7550392768/job/20556119271
There was a problem hiding this comment.
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.
- 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.
- 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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
0e29823
to
5000a9a
Compare
IDF v5.1 provides a menuconfig option to disable IPv4 in LwIP. And mdns component compiling would fail when disabling IPv4