Skip to content

Miscellaneous fixes#2175

Merged
limetech merged 26 commits into
unraid:masterfrom
bergware:master
Apr 28, 2025
Merged

Miscellaneous fixes#2175
limetech merged 26 commits into
unraid:masterfrom
bergware:master

Conversation

@bergware

@bergware bergware commented Apr 26, 2025

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Improved detection of wireless and wired network interface status, including enhanced support for roaming profiles and security types.
    • Docker now automatically refreshes network options and supports refined storage driver selection and log rotation settings.
    • Wireless page and related interfaces handle SSID and network information with improved data validation and display logic.
    • Added normalization of bitrate display for network interfaces.
  • Bug Fixes

    • Prevented network configuration and Docker routing with incomplete or invalid network parameters.
    • Enhanced reliability of carrier detection and interface selection for network and Docker operations.
  • Refactor

    • Consolidated network interface checks and carrier detection into reusable helper functions.
    • Streamlined logic for handling wireless security profiles and Docker network setup.
  • Style

    • Improved formatting and code organization for better maintainability.

@coderabbitai

coderabbitai Bot commented Apr 26, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This update introduces several enhancements and refactorings across network and wireless management scripts, Docker initialization, and related PHP modules. Notable changes include the addition of helper functions for network device existence and carrier status checks, improved logic for selecting network interfaces, and more robust handling of wireless security types, including roaming profiles. Docker configuration logic is consolidated into a new function, with refined storage driver selection and log rotation options. Wireless SSID handling is improved with a dedicated quote-escaping function, and bitrate normalization is added for wireless statistics. UI and backend checks are updated to align with these backend improvements.

Changes

File(s) Change Summary
etc/rc.d/rc.wireless Refactored security type handling to support roaming profiles and deprecated WEP; added priority function for security types; renamed and enhanced carrier_up to carrier with retries and interface existence checks; updated logic in wifi_running, wifi_start, and wifi_join to use new carrier and security handling; improved WPA configuration generation and logging.
emhttp/plugins/dynamix/include/update.wireguard.php Added isPort() and carrier() helper functions for device existence and carrier checks; updated thisNet() to use these helpers and improve interface selection logic; guarded Docker routing and config commands against missing network parameters in addDocker() and parseInput(); minor formatting adjustment.
etc/rc.d/rc.docker Refactored carrier detection to wait for interface up with timeout; extracted Docker option and active port logic into new docker_read_options(); improved storage driver selection and Docker log rotation options; adjusted IPv6 NAT and MTU handling; integrated new logic into Docker service lifecycle.
emhttp/plugins/dynamix/Wireless.page Changed UI logic to update network list only if wifi.other is a string, not just based on length.
emhttp/plugins/dynamix/include/Wireless.php Added escapeSSID() helper for SSID sanitization; replaced inline quote escaping in saveAttr(); changed logic for hiding UI elements based on manual join status.
emhttp/plugins/dynamix/include/NetworkInfo.php Renamed port() to isPort(); added normalizeBitrate() for parsing and formatting wireless bitrate values; applied normalization to RX/TX rates; updated calls to use new function names.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant rc.wireless
    participant WPA_Supplicant
    participant NetworkInterface

    User->>rc.wireless: Start WiFi
    rc.wireless->>NetworkInterface: carrier(interface, retries)
    alt Interface exists and carrier up
        rc.wireless->>rc.wireless: Determine SECURITY types (incl. roaming)
        rc.wireless->>rc.wireless: For each SECURITY, call wpa_configuration()
        rc.wireless->>WPA_Supplicant: Launch with generated config
        WPA_Supplicant-->>rc.wireless: Connection result
    else Interface missing or no carrier
        rc.wireless-->>User: Fail to start WiFi
    end
Loading
sequenceDiagram
    participant rc.docker
    participant docker_read_options
    participant NetworkInterface

    rc.docker->>docker_read_options: Initialize Docker options
    docker_read_options->>NetworkInterface: carrier(interface, timeout)
    docker_read_options->>docker_read_options: Select active port, set options
    docker_read_options-->>rc.docker: Docker options ready
    rc.docker->>rc.docker: Start or restart Docker with new options
Loading
sequenceDiagram
    participant update.wireguard.php
    participant isPort
    participant carrier

    update.wireguard.php->>isPort: Check device existence
    alt Exists
        update.wireguard.php->>carrier: Check carrier status (with loop)
        alt Carrier up
            update.wireguard.php-->>update.wireguard.php: Use device for routing
        else No carrier
            update.wireguard.php->>isPort: Check wlan0
            update.wireguard.php->>carrier: Check wlan0 carrier
            alt wlan0 carrier up
                update.wireguard.php-->>update.wireguard.php: Switch to wlan0
            else
                update.wireguard.php-->>update.wireguard.php: No suitable device
            end
        end
    else
        update.wireguard.php-->>update.wireguard.php: No device found
    end
Loading

Possibly related PRs

  • unraid/webgui#2165: Also modifies emhttp/plugins/dynamix/include/Wireless.php to improve SSID handling by escaping double quotes, similar to the introduction of the escapeSSID helper in this PR.

Suggested reviewers

  • MrAungThuHtet

Poem

Hopping through scripts with nimble delight,
I check for the carrier, morning and night.
With quotes now escaped and bitrates so neat,
Docker and WiFi both skip to my beat.
Roaming or wired, the logic’s robust—
This bunny ensures your network’s a must!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 148e9ae and 2879a50.

📒 Files selected for processing (1)
  • emhttp/plugins/dynamix/include/Wireless.php (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • emhttp/plugins/dynamix/include/Wireless.php

🪧 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 sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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 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.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 1f89828 and a558b49.

📒 Files selected for processing (3)
  • emhttp/plugins/dynamix/include/update.wireguard.php (1 hunks)
  • etc/rc.d/rc.docker (2 hunks)
  • etc/rc.d/rc.wireless (7 hunks)
🔇 Additional comments (11)
etc/rc.d/rc.wireless (6)

62-69: Function renamed and enhanced with existence check

The carrier_up function has been renamed to carrier and improved to check for device existence before attempting to read carrier status. This change harmonizes with similar carrier detection functions in other network-related scripts.


93-94: Updated function call to use new carrier function

The code appropriately uses the renamed carrier function with its boolean return value.


107-107: Updated variable assignment to use carrier function

The code has been updated to use the new carrier function for status assignment.


188-188: Enhanced check in wifi_running function

The wifi_running function has been updated to include an existence check for the interface directory before reading carrier status, making it more robust.


215-220: Updated carrier checks in wifi_start

The code has been appropriately updated to use the new carrier function with its boolean return value.


286-290: Improved security protocol detection logic

The security protocol detection now uses regex pattern matching (=~ operator) instead of exact string equality checks, allowing for more flexible detection. This change helps address a regression error in security detection.

emhttp/plugins/dynamix/include/update.wireguard.php (2)

35-37: Added helper function to check port existence

New port() helper function to check for the existence of a network device.


53-54: Updated thisNet() function to use new helpers

The thisNet() function now uses the new helper functions for better device selection logic.

etc/rc.d/rc.docker (3)

39-46: Enhanced carrier function with polling mechanism

The carrier function has been improved to check for device existence and to actively poll for carrier status with retries, returning a boolean result.


51-51: Updated active port selection logic

The port selection logic now uses the boolean return value from the carrier function instead of string comparison, making the code more robust.


263-263: Updated conditional for carrier detection

Modified to use the boolean return from the carrier function rather than string comparison.

Comment thread emhttp/plugins/dynamix/include/update.wireguard.php Outdated
@bergware bergware marked this pull request as draft April 26, 2025 15:23
@bergware bergware changed the title Wireless: fix regression error in security detection Miscellaneous fixes Apr 26, 2025
@bergware bergware marked this pull request as ready for review April 26, 2025 17:16

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
emhttp/plugins/dynamix/include/NetworkInfo.php (1)

58-62: Improved bitrate parsing and normalization.

The updated code properly normalizes network bitrates by extracting numeric values and ensuring consistent formatting with appropriate units. This enhances reliability when parsing output from the iw wlan0 link command.

Consider extracting this parsing logic into a reusable function to avoid code duplication between rxrate and txrate processing:

57
    $rxrate  = explode(': ', $speed[3])[1];
-    $tmprate = explode(' ', $rxrate);
-    $rxrate  = intval($tmprate[0] ?? 0).' '.($tmprate[1] ?? 'Bit/s');
60
    $txrate  = explode(': ', $speed[4])[1];
-    $tmprate = explode(' ', $txrate);
-    $txrate  = intval($tmprate[0] ?? 0).' '.($tmprate[1] ?? 'Bit/s');
+    
+    // Helper function to normalize bitrate values
+    function normalizeBitrate($rate) {
+        $parts = explode(' ', $rate);
+        return intval($parts[0] ?? 0).' '.($parts[1] ?? 'Bit/s');
+    }
+    
+    $rxrate = normalizeBitrate($rxrate);
+    $txrate = normalizeBitrate($txrate);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 404b0da and 2c07d92.

📒 Files selected for processing (1)
  • emhttp/plugins/dynamix/include/NetworkInfo.php (1 hunks)

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
etc/rc.d/rc.wireless (1)

38-38: Fix the typo in "decprecated".

The word "deprecated" is misspelled as "decprecated" in the translation for WEP security type.

-    "WEP") echo "WEP (decprecated)" ;;
+    "WEP") echo "WEP (deprecated)" ;;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 7346aac and 2d2a3fc.

📒 Files selected for processing (3)
  • emhttp/plugins/dynamix/include/update.wireguard.php (3 hunks)
  • etc/rc.d/rc.docker (4 hunks)
  • etc/rc.d/rc.wireless (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • emhttp/plugins/dynamix/include/update.wireguard.php
🔇 Additional comments (14)
etc/rc.d/rc.wireless (7)

45-59: Good addition of security priority ranking.

The new priority function establishes a clear hierarchy for security protocols, which improves the automatic selection process by prioritizing more secure protocols (WPA3 Enterprise) over less secure ones.


80-87: Well-implemented carrier detection with retries.

The renamed and improved carrier function now properly checks for interface existence before attempting to read carrier status and implements a configurable retry mechanism. This makes network interface detection more robust.


175-175: Improved logging for wpa_configuration.

Adding the translated security type to the logs is a great improvement for troubleshooting.


181-182: Effective use of regex for protocol variants.

Using regex pattern matching (=~) instead of exact matching (==) is an excellent improvement that handles all protocol variants including roaming profiles with a single condition.

Also applies to: 196-198


190-195: Good support for Fast Transition (FT) protocols.

The addition of explicit support for Fast Transition protocols (FT/PSK, FT/SAE, FT/IEEE-802.1X) enhances roaming capabilities between access points in the same network.


201-202: Proper ieee80211w settings for different protocols.

The script correctly sets Management Frame Protection (MFP) levels based on security protocol:

  • Level 1 (optional) for WPA2 Enterprise
  • Level 2 (required) for WPA3 protocols that mandate stronger protection

295-305: Greatly improved security type handling.

The new approach for handling security types when "auto" is specified is more maintainable and flexible:

  1. It normalizes security type names (replacing spaces with hyphens)
  2. It tries security types in priority order (from most secure to least secure)
  3. It supports all protocol variants including roaming profiles
etc/rc.d/rc.docker (7)

39-46: Well-implemented carrier detection with retries.

The improved carrier function now checks for interface existence and implements a configurable retry mechanism with a default 10-second timeout. This makes network interface detection more robust.


48-53: Improved network interface selection logic.

The new docker_read_options function encapsulates network port detection in a more structured way, with the conditional statement using boolean returns from the carrier function instead of string comparisons. This is more reliable and consistent with the rest of the system.


75-87: Enhanced storage driver selection with XFS support.

The storage driver selection logic now explicitly handles XFS filesystems by setting the storage driver to overlay2, which is the recommended driver for this filesystem type.


89-97: Added configurable log rotation settings.

The addition of global Docker log rotation options helps prevent log files from consuming excessive disk space. Default values are sensibly set but can be overridden through configuration.


99-114: Proper MTU and IPv6 handling.

The code now:

  1. Adjusts Docker MTU to match the network interface when non-default
  2. Configures IPv6 for Docker containers when a default IPv6 route exists
  3. Sets up proper IPv6 NAT rules for container connectivity
  4. Disables IPv6 on docker0 interface when IPv6 is not available

This ensures containers have the correct network settings to match the host environment.


647-647: Properly refresh Docker options before service start.

The addition of explicit docker_read_options calls before starting or restarting Docker ensures that all configuration options and network settings are refreshed, leading to a more consistent and predictable behavior.

Also applies to: 667-667


43-43: ⚠️ Potential issue

Fix the brace expansion syntax in for loop.

The brace expansion syntax {1..$e} won't work as expected with variables. Bash doesn't perform variable substitution within brace expansion.

-  for n in {1..$e}; do
+  for ((n=1; n<=$e; n++)); do

Likely an incorrect or invalid review comment.

Comment thread etc/rc.d/rc.wireless Outdated

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
etc/rc.d/rc.docker (1)

53-53: Consider ordering wireless check by prioritizing more reliable interfaces

The wireless check happens after bridge/bond/ethernet interfaces, which is appropriate for most deployments. However, the line combines multiple operations (carrier check and assignment), which might be a bit hard to follow.

For clarity, consider splitting this into a separate conditional block:

-  [[ ! $(carrier $PORT) && $(carrier wlan0 1) ]] && PORT=wlan0
+  # Only use wireless if primary interface has no carrier
+  if [[ ! $(carrier $PORT) && $(carrier wlan0 1) ]]; then
+    PORT=wlan0
+  fi
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between e28a18f and ba23aa5.

📒 Files selected for processing (3)
  • emhttp/plugins/dynamix/include/update.wireguard.php (3 hunks)
  • etc/rc.d/rc.docker (4 hunks)
  • etc/rc.d/rc.wireless (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • etc/rc.d/rc.wireless
  • emhttp/plugins/dynamix/include/update.wireguard.php
🔇 Additional comments (5)
etc/rc.d/rc.docker (5)

38-47: Well-designed carrier function with proper error handling

The revised carrier function now includes several important improvements:

  • Checks if the interface exists before attempting to read its carrier status
  • Implements a retry loop with configurable timeout (defaulting to 10 seconds)
  • Returns boolean status (0 for success, 1 for failure) for proper error handling in calling code
  • Prevents unnecessary sleep when checking with e=1 (single attempt)

This change aligns with similar improvements in other network-related scripts, creating consistency across the system.


49-117: Good centralization of Docker configuration logic

The new docker_read_options function effectively centralizes configuration logic that was previously scattered throughout the code. This improves maintainability and ensures consistent behavior.

Key improvements:

  • Unified network port detection logic
  • Centralized Docker configuration reading/updating
  • Improved storage driver selection with explicit handling for xfs filesystems
  • Well-structured log rotation configuration
  • Proper IPv6 setup with NAT rules when applicable

The function properly handles various edge cases and provides clear, logical progression through each configuration step.


83-85: Appropriate addition of overlay2 support for xfs filesystem

The explicit handling of xfs filesystems using overlay2 storage driver is a good improvement that fills a previous gap in the storage driver selection logic.


266-266: Correct usage of the updated carrier function

This line properly leverages the new boolean-returning carrier function with a 1-second timeout parameter, replacing the previous string comparison method. The condition now checks if the interface has carrier before considering it for network configuration.


648-648: Good placement of docker_read_options function call

The addition of docker_read_options function calls at the beginning of both start and restart command cases ensures that Docker options and network port detection are refreshed before starting Docker services. This prevents potential issues with stale configuration or incorrect network interface detection.

Also applies to: 668-669

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