Skip to content

FIX IPv4-ONLY AsyncUDP::listenMulticast() for receiving IPv6 #11443

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

Conversation

nikiwaibel
Copy link

Description of Change

AsyncUDP::listenMulticast() properly receives packets sent to IPv4 multicast addresses like 239.1.2.3, but it is not receiving packets sent to IPv6 multicast addresses like ff12::6ood:cafe.

The root cause is a bit hidden: listen(NULL, port) would match AsyncUDP::listen(const ip_addr_t *addr, uint16_t port), which calls _udp_bind(_pcb, addr, port), which uses the lwIP API to call udp_bind(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port) at the end. If lwIP has LWIP_IPV4 enabled, it checks if ipaddr == NULL and sets it to IP4_ADDR_ANY. So an IPv6 address is never bound.

This fix checks the IP address passed to AsyncUDP::listenMulticast(). If it is an IPv6 address, it constructs and passes the IPv6 any address (::); otherwise (IPv4), it constructs and passes the IPv4 any address (0.0.0.0).

Tests scenarios

Heltec v3

Related links

Fix #9970

@nikiwaibel nikiwaibel requested a review from me-no-dev as a code owner June 6, 2025 16:20
@CLAassistant
Copy link

CLAassistant commented Jun 6, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

github-actions bot commented Jun 6, 2025

Warnings
⚠️

The source branch "FIX-AsyncUDP-multicast-IPv4ONLY" incorrect format:

  • contains uppercase letters. This can cause troubles on case-insensitive file systems (macOS).
    Please rename your branch.

👋 Hello nikiwaibel, we appreciate your contribution to this project!


📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more.

🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project.

Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- Resolve all warnings (⚠️ ) before requesting a review from human reviewers - they will appreciate it.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests.

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫 dangerJS against 7b85dd0

@nikiwaibel nikiwaibel force-pushed the FIX-AsyncUDP-multicast-IPv4ONLY branch from 1753233 to 9bde886 Compare June 6, 2025 21:44
AsyncUDP::listenMulticast() properly receives packets sent to IPv4
multicast addresses like 239.1.2.3, but it is not receiving packets sent
to IPv6 multicast addresses like ff12::6ood:cafe.

The root cause is a bit hidden: listen(NULL, port) would match
AsyncUDP::listen(const ip_addr_t *addr, uint16_t port), which calls
_udp_bind(_pcb, addr, port), which uses the lwIP API to call
udp_bind(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port) at
the end. If lwIP has LWIP_IPV4 enabled, it checks if ipaddr == NULL and
sets it to IP4_ADDR_ANY. So an IPv6 address is never bound.

This fix checks the IP address passed to AsyncUDP::listenMulticast(). If
it is an IPv6 address, it constructs and passes the IPv6 any address
(::); otherwise (IPv4), it constructs and passes the IPv4 any address
(0.0.0.0).
@nikiwaibel nikiwaibel force-pushed the FIX-AsyncUDP-multicast-IPv4ONLY branch from 9bde886 to 7b85dd0 Compare June 6, 2025 21:47
@nikiwaibel nikiwaibel closed this Jun 6, 2025
@nikiwaibel nikiwaibel deleted the FIX-AsyncUDP-multicast-IPv4ONLY branch June 6, 2025 21:55
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.

AsyncUDP ipv6 Multicast not working
2 participants