Skip to content

More networking fixes#2241

Merged
limetech merged 22 commits into
unraid:masterfrom
bergware:master
Jun 9, 2025
Merged

More networking fixes#2241
limetech merged 22 commits into
unraid:masterfrom
bergware:master

Conversation

@bergware

@bergware bergware commented Jun 9, 2025

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Introduced persistent tracking of network interface assignments for Docker networks, improving management and monitoring of interface states.
  • Bug Fixes

    • Prevented empty or invalid gateway route entries from being written to configuration files.
    • Improved logic for adding default gateway routes, ensuring consistent metric handling and precise route existence checks.
    • Enhanced interface monitoring to better manage IP assignments, including handling of deprecated IPv6 addresses and interface state changes.
    • Fixed gateway metric input handling in the network settings interface to reset metrics appropriately when gateways are disabled.
    • Updated gateway checkbox behavior to require both metric and gateway presence, improving accuracy in network configuration UI.

@coderabbitai

coderabbitai Bot commented Jun 9, 2025

Copy link
Copy Markdown
Contributor

"""

Walkthrough

The updates introduce persistent tracking of network interface assignments via a statics file and marker files, add new functions for managing these records, and refine logic for interface and gateway management. Several scripts are modified to ensure accurate address assignment, removal, and monitoring, particularly for shim and vhost interfaces. UI changes adjust gateway checkbox logic to depend on both metric and gateway presence.

Changes

File(s) Summary of Changes
etc/rc.d/rc.docker Added STA variable, new add_entry and del_entry functions for tracking assignments, removed ipv4_exist, and updated interface assignment/removal logic to maintain a persistent watch list with .down marker files.
etc/rc.d/rc.inet1 Improved gateway_up logic for default gateway route addition, handling metrics more robustly and refining route existence checks for both IPv4 and IPv6.
sbin/create_network_ini Changed gateway route recording to append only if route information is present, preventing empty or invalid gateway lines in the statics file for static IPv4 and IPv6 addresses on base and VLAN interfaces.
sbin/monitor_interface Modified monitoring to use base interface names, added checks for global primary IPs before adding default routes, improved IP assignment/removal logic, and handled .down marker files for shim and vhost interfaces accordingly.
emhttp/plugins/dynamix/Eth0.page Removed special case for eth0 gateway flags, always set gateway flags from input states, and reset metric inputs to zero when gateways are unchecked.
emhttp/plugins/dynamix/EthX.page Updated gateway checkbox logic to require both non-zero metric and non-empty gateway address for checking IPv4 and IPv6 gateway usage, applying to base and VLAN interfaces.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant rc.docker
    participant statics.ini
    participant Interface

    User->>rc.docker: Start/Stop Docker network
    rc.docker->>Interface: Assign/remove IP address
    rc.docker->>statics.ini: add_entry()/del_entry() (update watch list)
    rc.docker->>Interface: Add/remove default route
    rc.docker->>statics.ini: Update .down marker files as needed
Loading

Possibly related PRs

Suggested labels

7.2

Poem

🐇
A hop, a skip, a statics file,
New entries tracked in rabbit style.
Gateways checked with careful eyes,
Interfaces watched as time goes by.
With every leap, the routes align—
Network magic, by design!
🥕
"""


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f020c98 and bf4dd36.

📒 Files selected for processing (1)
  • emhttp/plugins/dynamix/Eth0.page (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • emhttp/plugins/dynamix/Eth0.page

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @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

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

61-72: Well-designed persistent tracking mechanism

The add_entry and del_entry functions provide a clean interface for managing the watch list. The use of marker files (.down) effectively prevents race conditions with the monitoring script.

Consider adding file locking to prevent concurrent access issues:

 # add entry to watch list
 add_entry(){
   rm -f /var/tmp/${1%% *}.down
-  [[ -e $STA ]] && echo "$1" >>$STA
+  [[ -e $STA ]] && {
+    exec 200>>$STA
+    flock 200
+    echo "$1" >&200
+    exec 200>&-
+  }
 }

 # delete enty from watch list
 del_entry(){
   touch /var/tmp/$1.down
-  [[ -e $STA ]] && sed -i "/^$1 .*/d" $STA
+  [[ -e $STA ]] && {
+    exec 200>>$STA
+    flock 200
+    sed -i "/^$1 .*/d" $STA
+    exec 200>&-
+  }
   sleep 0.5
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 32ff144 and 76ac9bd.

📒 Files selected for processing (4)
  • etc/rc.d/rc.docker (5 hunks)
  • etc/rc.d/rc.inet1 (3 hunks)
  • sbin/create_network_ini (4 hunks)
  • sbin/monitor_interface (1 hunks)
🔇 Additional comments (6)
sbin/create_network_ini (1)

166-168: Good defensive programming practice!

The changes correctly prevent empty gateway route lines from being written to the statics file by checking if the route command output is non-empty before appending. This pattern is consistently applied across all gateway route handling (IPv4/IPv6, main/VLAN interfaces).

Also applies to: 191-193, 224-226, 250-252

sbin/monitor_interface (3)

61-61: Good optimization using base interface name

Using ${PORT%.*} strips VLAN suffixes, preventing redundant carrier state checks for multiple VLAN interfaces on the same physical interface.

Also applies to: 98-98


67-71: Excellent addition of IP presence checks before route creation

The changes correctly verify that a global primary IP address exists on the interface before attempting to add default gateway routes. The IPv6 check appropriately excludes deprecated addresses with the -deprecated flag.

Also applies to: 75-79


82-89:

Details

❓ Verification inconclusive

Integration with persistent tracking mechanism

The special handling for .down marker files integrates with the new watch list mechanism. However, there's a potential race condition between checking the file existence and the IP operations.

Consider adding error handling for the race condition:

-          if [[ -f /var/tmp/$PORT.down ]]; then
-            # Special treatment for shim and vhost interfaces
-            [[ -n $IPA ]] && ip addr del dev ${TASK[$i]}
-          else
-            # IP address not present? create it
-            [[ -z $IPA ]] && ip addr add dev ${TASK[$i]}
-          fi
+          if [[ -f /var/tmp/$PORT.down ]]; then
+            # Special treatment for shim and vhost interfaces
+            [[ -n $IPA ]] && ip addr del dev ${TASK[$i]} 2>/dev/null
+          else
+            # IP address not present? create it
+            [[ -z $IPA ]] && ip addr add dev ${TASK[$i]} 2>/dev/null || true
+          fi

Verify the timing between marker file creation and IP operations:


🏁 Script executed:

#!/bin/bash
# Check for any existing .down files and their timestamps
echo "=== Checking for .down marker files ==="
ls -la /var/tmp/*.down 2>/dev/null || echo "No .down files found"

# Check the statics.ini file for context
echo -e "\n=== Current statics.ini entries ==="
cat /var/local/emhttp/statics.ini 2>/dev/null | head -20 || echo "statics.ini not found"

Length of output: 300


Confirm concurrency safety for .down marker checks

  • File: sbin/monitor_interface lines 82–89
  • There’s a small window between testing -f /var/tmp/$PORT.down and running ip addr where another process could create/remove the marker, leading to unexpected failures or script exits.

Suggested mitigation (redirect errors and prevent set -e from exiting):

-          if [[ -f /var/tmp/$PORT.down ]]; then
-            [[ -n $IPA ]] && ip addr del dev ${TASK[$i]}
-          else
-            [[ -z $IPA ]] && ip addr add dev ${TASK[$i]}
-          fi
+          if [[ -f /var/tmp/$PORT.down ]]; then
+            [[ -n $IPA ]] && ip addr del dev ${TASK[$i]} 2>/dev/null || true
+          else
+            [[ -z $IPA ]] && ip addr add dev ${TASK[$i]} 2>/dev/null || true
+          fi

Optionally, wrap the marker-file check + IP command in a lock (e.g., flock) to serialize access and fully eliminate the race.

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

427-448: Consistent IP assignment handling with metric 0

The changes properly manage IP assignments for both shim and vhost interfaces, using metric 0 to ensure high priority. The conditional logic correctly handles the DOCKER_ALLOW_ACCESS setting.

Also applies to: 461-472


494-508: Proper cleanup sequence in network stop

Good practice to retrieve the IPv4 address before network removal, ensuring accurate cleanup of IP assignments from interfaces.

Comment thread etc/rc.d/rc.inet1 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)
emhttp/plugins/dynamix/Eth0.page (1)

213-214: LGTM! Gateway checkbox logic is now consistent across all interfaces.

The removal of the special case for eth0 index 0 and the direct reading of checkbox states improves consistency. The logic correctly resets metrics to '0' when gateway checkboxes are unchecked, which aligns with the broader network management improvements mentioned in the PR summary.

Consider adding existence checks for robustness:

-    var gw4 = $(form).find('input[name="USE_GW4:'+i+'"]').prop('checked');
-    if (!gw4) $(form).find('input[name="METRIC:'+i+'"]').val('0');
+    var gw4Element = $(form).find('input[name="USE_GW4:'+i+'"]');
+    var gw4 = gw4Element.length ? gw4Element.prop('checked') : false;
+    if (!gw4) $(form).find('input[name="METRIC:'+i+'"]').val('0');

And similarly for the IPv6 section.

Also applies to: 223-224

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2dce3bf and fab0b32.

📒 Files selected for processing (2)
  • emhttp/plugins/dynamix/Eth0.page (1 hunks)
  • sbin/monitor_interface (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • sbin/monitor_interface

@bergware bergware marked this pull request as draft June 9, 2025 06:50

@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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 691bd0f and 8f054ce.

📒 Files selected for processing (2)
  • emhttp/plugins/dynamix/Eth0.page (3 hunks)
  • emhttp/plugins/dynamix/EthX.page (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • emhttp/plugins/dynamix/Eth0.page
🔇 Additional comments (2)
emhttp/plugins/dynamix/EthX.page (2)

285-285: LGTM! IPv4 VLAN gateway checkbox logic is correct.

The variable references and logical conditions are properly implemented for VLAN interfaces. The checkbox will only be checked when both metric is non-zero and gateway is specified.


314-314: LGTM! IPv6 VLAN gateway checkbox logic is correct.

The variable references and logical conditions are properly implemented for VLAN interfaces. The checkbox will only be checked when both metric is non-zero and gateway is specified.

Comment thread emhttp/plugins/dynamix/EthX.page Outdated
Comment thread emhttp/plugins/dynamix/EthX.page 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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8f054ce and 354c2cb.

📒 Files selected for processing (1)
  • sbin/monitor_interface (3 hunks)
🔇 Additional comments (4)
sbin/monitor_interface (4)

21-23: Good generalization of interface checking

Replacing the specific wlan function with a generic port function improves code reusability and allows monitoring of any interface type, not just wireless interfaces.


62-62: Correct handling of VLAN interfaces

The change to use ${PORT%.*} properly handles VLAN interfaces by checking the carrier state of the base interface. This is correct since VLAN interfaces inherit their physical state from the parent interface.

Also applies to: 89-89


65-76: Improved gateway route management

The enhanced gateway handling for both IPv4 and IPv6 adds important safeguards:

  • Only adds routes when interface is up
  • Verifies primary IP address exists
  • Prevents duplicate default routes
  • IPv6 correctly filters deprecated addresses

These changes prevent routing issues when interfaces are in transitional states.


79-87: Clear state-based IP address management

The explicit state handling improves clarity:

  • Interface down: removes IP address if present
  • Interface up: adds IP address if missing (unless /var/tmp/$PORT.down exists)

The .down marker file provides manual control to prevent IP assignment on specific interfaces.

Comment thread sbin/monitor_interface Outdated
@bergware bergware marked this pull request as ready for review June 9, 2025 09:37
@ljm42 ljm42 added the 7.2 label Jun 9, 2025
@limetech limetech merged commit 5121d56 into unraid:master Jun 9, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants