Skip to content

Add the netif BSD sockets index (necessary for running mDNS on the ESP-IDF)#247

Merged
ivmarkov merged 1 commit intoproject-chip:mainfrom
sysgrok:next
Jun 13, 2025
Merged

Add the netif BSD sockets index (necessary for running mDNS on the ESP-IDF)#247
ivmarkov merged 1 commit intoproject-chip:mainfrom
sysgrok:next

Conversation

@ivmarkov
Copy link
Contributor

@ivmarkov ivmarkov commented Jun 12, 2025

With the big stream of changes in #233 / #237 - and particularly the Networks' management - I did not carry over the network interface index (a STD / BSD sockets' thing) from rs-matter-stack into rs-matter as rs-matter and the Network Diagnostics cluster impl in particular does not need it as it is not reported it in the cluster attributes.

However I forgot that the built-in mDNS responder might also use the NetifInfo type and the NetifDiag trait downstream (and it does!).

The problem is specifically when rs-matter is running on top of ESP-IDF (with the esp-idf-matter helper crate) because - for some reason - ESP-IDF really does not like to open a multicast UDP socket with the "default"/"all" network interface = 0. It must be the index of a concrete network interface (Eth or Wifi), as ESP-IDF cannot multicast on "all".

So when the built-in mDNS responder grabs the most suitable netif reported by NetifDiag on which to operate, it does it with interface index 0, and opening the mDNS multicast socket immediately fails on the ESP IDF therefore.

The solution is to "thread" the interface index together with the other netif parameters in the NetifInfo struct, so that the built-in mDNS can grab the correct index for that particular netif.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @ivmarkov, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a necessary change to the NetifInfo structure to include the network interface index. This is crucial for ensuring compatibility and correct behavior of the built-in mDNS responder, particularly when running on platforms like ESP-IDF that require explicit interface binding for multicast operations.

Highlights

  • Network Interface Information: Added a new field netif_index of type u32 to the NetifInfo struct in rs-matter/src/data_model/sdm/gen_diag.rs. This field is intended to store the BSD sockets index for the network interface.
  • Platform Compatibility (ESP-IDF): The addition of the netif_index is specifically required to address an issue on the ESP-IDF platform where the built-in mDNS responder needs a concrete network interface index (not 0) to successfully bind multicast UDP sockets.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configureGemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a netif_index field to the NetifInfo struct. This change is well-motivated by the need to support mDNS on ESP-IDF, which requires a specific network interface index for multicast operations.

The primary feedback focuses on enhancing the robustness of this new field by suggesting the use of Option<u32> instead of u32. This change would make it explicit when an interface index is not available, aligning with Rust best practices and helping to prevent potential issues arising from ambiguous interpretations of a default value like 0.

Copy link
Contributor

@bjoernQ bjoernQ left a comment

Choose a reason for hiding this comment

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

LGTM

@ivmarkov ivmarkov merged commit ac7df9a into project-chip:main Jun 13, 2025
12 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.

2 participants