Skip to content

aggregation: browse mDNS from port 5353 so peers answer by multicast - #720

Open
mfaferek93 wants to merge 1 commit into
mainfrom
fix/mdns-browse-from-5353
Open

mfaferek93 wants to merge 1 commit into
mainfrom
fix/mdns-browse-from-5353

Conversation

@mfaferek93

Copy link
Copy Markdown
Collaborator

Problem

browse_loop opened its query socket on an ephemeral port. The vendored mdns library then sets the QU (unicast-response) bit on the PTR query, so every peer answers by unicast to that ephemeral port. A host firewall that allows only the mdns service (udp/5353), which is the usual setup on an appliance, drops those replies. Discovery never finds a peer, with no error.

Fix

Bind the browse socket to 5353. The library clears the QU bit for a socket on 5353, peers answer by multicast to 5353, and the standard mdns firewall rule lets it in. The socket shares 5353 with our announce socket and with avahi through SO_REUSEADDR/SO_REUSEPORT, which mdns_socket_open_ipv4 already sets. If 5353 cannot be bound, it falls back to an ephemeral port as before and says so in the log.

Tests

  • New MdnsDiscovery.browse_query_asks_for_multicast_replies: listens on 5353, starts discovery and checks the PTR query has the QU bit clear. Skips when 5353 or multicast loopback is not available. Fails without the fix, passes with it.
  • test_mdns_discovery (24), test_aggregation_manager (72), test_aggregation_classification (10) pass.

On real hardware: a RevPi (Debian bookworm, firewalld public zone ssh http https mdns, avahi running) and a robot gateway announcing on the same LAN.

  • Before: discover enabled, peer list still empty after 90 s.
  • After: robot found and online after 6 s, its components merged (jetson, driver_board, lidar as peer:m3pro-yahboom). No extra firewall rule.

From an ephemeral port the PTR query sets the QU bit and peers answer by
unicast to that port, which a host firewall allowing only the mdns
service drops. Bind the browse socket to 5353 (shared with announce and
avahi), fall back to an ephemeral port when 5353 is unavailable.
Copilot AI balanced review requested due to automatic review settings October 11, 2026 19:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The regression test can silently skip, and the new fallback branch lacks deterministic coverage.

2 open findings
What changed in this PR

Updates mDNS peer discovery to request multicast replies through UDP port 5353, with an ephemeral-port fallback.

Changes:

  • Binds browse sockets to port 5353 and improves logging.
  • Adds a test that inspects the query’s QU bit.
File Description
src/​ros2_medkit_gateway/​src/​core/​aggregation/​mdns_discovery.cpp Adds port 5353 binding and fallback behavior.
src/​ros2_medkit_gateway/​test/​test_mdns_discovery.cpp Adds multicast-query regression coverage.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +527 to +529
if (sock < 0) {
on_mdns_port = false;
sock = mdns_socket_open_ipv4(nullptr);
Comment on lines +445 to +446
if (listener < 0) {
GTEST_SKIP() << "cannot bind udp/5353 here";

This branch has not been deployed

No deployments
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.

2 participants