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

Add network interface settings for mDNS/LLMNR #5520

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

t3hk0d3
Copy link

@t3hk0d3 t3hk0d3 commented Jan 1, 2025

Proposed change

Currently there is an issue with mDNS announcement enabled by default on all interfaces.
See #5435 and home-assistant/operating-system#1163

This PR is a second take to fix this issue.
First attempt #5455 was using heuristic logic to enable mDNS annoucement only for primary interface.
After some discusison with @agners we decided that's not an unacceptable solution, because it would break mDNS for people without installed mDNS reflector on router.

This PR take a different route to solve this issue:

  • reads status of mDNS/LLMNR from D-Bus
  • if status is not set: it will fallback to current behaviour - set it to announce.
  • exposes these new properties to API

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (which adds functionality to the supervisor)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Ruff (ruff format supervisor tests)
  • Tests have been added to verify that the new code works.

If API endpoints or add-on configuration are added/changed:

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for configuring Multicast DNS (mDNS) and Link-Local Multicast Name Resolution (LLMNR) settings for network interfaces
    • Introduced new configuration options to control mDNS and LLMNR behavior (OFF, RESOLVE, ANNOUNCE)
  • Improvements

    • Enhanced network interface configuration API to include mDNS and LLMNR settings
    • Expanded network connection properties to support more detailed network service discovery options

@agners agners marked this pull request as ready for review January 14, 2025 10:31
Copy link

coderabbitai bot commented Jan 14, 2025

Warning

Rate limit exceeded

@agners has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 3 minutes and 27 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between aebd21d and 0b7f2b6.

📒 Files selected for processing (2)
  • supervisor/api/network.py (5 hunks)
  • supervisor/dbus/network/configuration.py (1 hunks)
📝 Walkthrough

Walkthrough

The pull request introduces comprehensive support for Multicast DNS (mDNS) and Link-Local Multicast Name Resolution (LLMNR) configurations across multiple files in the supervisor network management system. The changes add new attributes, constants, and methods to enable configuration and retrieval of mDNS and LLMNR settings for network interfaces. This enhancement allows more granular control over local network service discovery by providing options to turn these services off, enable resolution, or enable announcement.

Changes

File Change Summary
supervisor/api/network.py Added ATTR_MDNS and ATTR_LLMNR attributes; Updated interface_struct and interface_update methods to support mDNS and LLMNR settings
supervisor/const.py Added constants ATTR_LLMNR and ATTR_MDNS
supervisor/dbus/const.py Added MulticastDnsValue enumeration for mDNS/LLDP connection states
supervisor/dbus/network/configuration.py Added optional mdns and lldmp attributes to ConnectionProperties
supervisor/dbus/network/setting/__init__.py Added constants CONF_ATTR_CONNECTION_MDNS and CONF_ATTR_CONNECTION_LLMNR
supervisor/dbus/network/setting/generate.py Added _map_mdns_setting function; Updated get_connection_from_interface to use new mapping
supervisor/host/configuration.py Added mdns and llmnr attributes to Interface; Added _map_nm_multicast_dns method
supervisor/host/const.py Added MulticastDnsMode enumeration

Sequence Diagram

sequenceDiagram
    participant API as Network API
    participant Configuration as Host Configuration
    participant DBus as DBus Network Setting
    
    API->>Configuration: Request Interface Details
    Configuration-->>API: Return Interface with mDNS/LLMNR Settings
    
    API->>DBus: Update Network Interface
    DBus->>DBus: Map mDNS/LLMNR Settings
    DBus-->>API: Confirm Configuration Update
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (4)
supervisor/host/const.py (1)

75-80: Enhance enum documentation with mode descriptions.

The enum documentation could be more helpful by describing what each mode does:

 class MulticastDnsMode(StrEnum):
-    """Multicast DNS (MDNS/LLMNR) mode."""
+    """Multicast DNS (MDNS/LLMNR) mode.
+    
+    OFF: Disable mDNS/LLMNR completely
+    RESOLVE: Enable only name resolution
+    ANNOUNCE: Enable both name resolution and service announcements
+    """
supervisor/dbus/network/setting/generate.py (1)

137-144: Add error handling for invalid modes.

The mapping function should handle invalid mode values gracefully.

 def _map_mdns_setting(mode: MulticastDnsMode | None) -> int:
+    """Map MulticastDnsMode to integer value.
+    
+    Args:
+        mode: The MulticastDnsMode to map, or None for default
+    Returns:
+        Integer value representing the mode
+    Raises:
+        ValueError: If an invalid mode is provided
+    """
     mapping = {
         MulticastDnsMode.OFF: MulticastDnsValue.OFF,
         MulticastDnsMode.RESOLVE: MulticastDnsValue.RESOLVE,
         MulticastDnsMode.ANNOUNCE: MulticastDnsValue.ANNOUNCE,
     }
 
+    if mode is not None and mode not in mapping:
+        raise ValueError(f"Invalid MulticastDnsMode: {mode}")
     return int(mapping[mode] if mode else MulticastDnsValue.ANNOUNCE)
supervisor/host/configuration.py (1)

280-288: Add error handling and documentation to _map_nm_multicast_dns.

The method needs error handling for invalid modes and proper documentation.

     @staticmethod
     def _map_nm_multicast_dns(mode: int | None) -> MulticastDnsMode | None:
+        """Map integer mode to MulticastDnsMode.
+
+        Args:
+            mode: Integer value representing the mode, or None
+        Returns:
+            Corresponding MulticastDnsMode value, or None if mode is None
+        Raises:
+            ValueError: If an invalid mode value is provided
+        """
+        if mode is None:
+            return None
+
         mapping = {
             MulticastDnsValue.OFF: MulticastDnsMode.OFF,
             MulticastDnsValue.RESOLVE: MulticastDnsMode.RESOLVE,
             MulticastDnsValue.ANNOUNCE: MulticastDnsMode.ANNOUNCE,
         }
 
+        if mode not in mapping:
+            raise ValueError(f"Invalid multicast DNS mode value: {mode}")
         return mapping[mode]
supervisor/const.py (1)

Line range hint 1-1: Consider adding documentation for the new mDNS/LLMNR settings.

To improve maintainability and user experience, consider:

  1. Adding docstrings to explain the purpose and usage of the new mDNS/LLMNR settings.
  2. Updating the API documentation to describe the new configuration options.
  3. Including examples of common configuration scenarios.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c2f6e31 and aebd21d.

📒 Files selected for processing (8)
  • supervisor/api/network.py (5 hunks)
  • supervisor/const.py (2 hunks)
  • supervisor/dbus/const.py (1 hunks)
  • supervisor/dbus/network/configuration.py (1 hunks)
  • supervisor/dbus/network/setting/__init__.py (1 hunks)
  • supervisor/dbus/network/setting/generate.py (3 hunks)
  • supervisor/host/configuration.py (5 hunks)
  • supervisor/host/const.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
supervisor/const.py (6)

Pattern */**(html|markdown|md): - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure the goal of the instruction is fronted.

  • Apply the Microsoft Style Guide to ensure documentation maintains clarity and conciseness.
  • In step-by-step instructions, front the location phrase in the instructional sentence.
  • In step-by-step instructions, front the 'goal' in the instructional sentence.
  • In step-by-step instructions, if in doubt what to front, front the 'goal' before the location phrase in the instructional sentence.
  • do not hyphenate terms like 'top-right' or 'bottom-left' with 'corner'

Pattern */**(html|markdown|md): - Use bold to mark UI strings.

  • If "" are used to mark UI strings, replace them by bold.

Pattern */**(html|markdown|md): - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"


Pattern */**(html|markdown|md): - Use sentence-style capitalization also in headings.


Pattern */**(html|markdown|md): do not comment on HTML used for icons


Pattern */**(html|markdown|md): Avoid flagging inline HTML for embedding videos in future reviews for this repository.

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Run tests Python 3.12.8
  • GitHub Check: Build armv7 supervisor
  • GitHub Check: Build armhf supervisor
  • GitHub Check: Build aarch64 supervisor
🔇 Additional comments (5)
supervisor/dbus/network/setting/__init__.py (1)

222-223: LGTM! The new mDNS and LLMNR attributes are correctly integrated.

The implementation follows the existing pattern and properly extracts the attributes from the connection data.

supervisor/api/network.py (2)

96-97: LGTM! Schema validation is correctly implemented.

The schema properly uses MulticastDnsMode for type coercion of both mDNS and LLMNR fields.


240-243: LGTM! Update logic correctly handles the new attributes.

The implementation properly updates the interface with the new mDNS and LLMNR settings.

supervisor/dbus/const.py (1)

299-305: LGTM! The MulticastDnsValue enum is well-defined.

The enum values are properly ordered from least to most permissive (OFF → RESOLVE → ANNOUNCE) and follow Python's enum best practices.

supervisor/const.py (1)

231-231: LGTM! The new attributes follow the naming convention.

The attributes are correctly placed in alphabetical order and follow the existing naming pattern.

Also applies to: 241-241

supervisor/dbus/network/configuration.py Outdated Show resolved Hide resolved
Comment on lines +157 to +162
if inet.settings and inet.settings.connection:
mdns = inet.settings.connection.mdns
lldmp = inet.settings.connection.lldmp
else:
mdns = None
lldmp = None
Copy link

@coderabbitai coderabbitai bot Jan 14, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix typo in variable name: 'lldmp' should be 'llmnr'.

The variable name 'lldmp' should be 'llmnr' for consistency.

-            lldmp = inet.settings.connection.lldmp
+            llmnr = inet.settings.connection.llmnr
-            lldmp = None
+            llmnr = None

Committable suggestion skipped: line range outside the PR's diff.

Copy link
Member

Choose a reason for hiding this comment

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

The bot is right, this should be corrected as well.

Copy link

Choose a reason for hiding this comment

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

@sairon Yes, I found that the typo appears in multiple places. The correction should be made in:

  1. supervisor/host/configuration.py:

    • Change lldmp = inet.settings.connection.lldmp to llmnr = inet.settings.connection.llmnr
    • Change lldmp = None to llmnr = None
    • Change Interface._map_nm_multicast_dns(lldmp) to Interface._map_nm_multicast_dns(llmnr)
  2. supervisor/dbus/const.py:

    • Update the docstring from """Connection MulticastDNS (mdns/lldmp) values.""" to """Connection MulticastDNS (mdns/llmnr) values."""

This will ensure consistency throughout the codebase by using the correct terminology (LLMNR - Link-Local Multicast Name Resolution) everywhere.

🔗 Analysis chain
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all occurrences of 'lldmp' in the codebase
rg "lldmp" -l

Length of output: 71


Script:

#!/bin/bash
echo "=== supervisor/host/configuration.py ==="
rg "lldmp" -A 2 supervisor/host/configuration.py
echo -e "\n=== supervisor/dbus/const.py ==="
rg "lldmp" -A 2 supervisor/dbus/const.py

Length of output: 536

supervisor/api/network.py Outdated Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Default mDNS settings results in network flooding
3 participants