Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/51068.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Made network.managed stop reporting changes when there are none.
30 changes: 8 additions & 22 deletions salt/states/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,30 +621,16 @@ def managed(name, enabled=True, **kwargs):

# Bring up/shutdown interface
try:
# Get Interface current status
# Get Interfaces information
interfaces = salt.utils.network.interfaces()
interface_status = False
if name in interfaces:
interface_status = interfaces[name].get("up")

# Check the interface current status
if name.split(":")[0] in interfaces:
interface_status = interfaces[name.split(":")[0]].get("up")
else:
for iface in interfaces:
Comment thread
lvinagre marked this conversation as resolved.
if "secondary" in interfaces[iface]:
for second in interfaces[iface]["secondary"]:
if second.get("label", "") == name:
interface_status = True
if iface == "lo":
if "inet" in interfaces[iface]:
inet_data = interfaces[iface]["inet"]
if len(inet_data) > 1:
for data in inet_data:
if data.get("label", "") == name:
interface_status = True
if "inet6" in interfaces[iface]:
inet6_data = interfaces[iface]["inet6"]
if len(inet6_data) > 1:
for data in inet6_data:
if data.get("label", "") == name:
interface_status = True
interface_status = False

# Handle interface as desired

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.

Unconditionally splitting the interface string on a colon breaks support for complex interface naming conventions (like VLAN tags and sub-interfaces) and incorrectly conflates a parent interface's status with its un-validated alias configurations.

By completely deleting that section and substituting the raw split(":"), the code now blindly conflates the parent interface's operational status with the status of the alias itself. If the parent interface (eth0) is up, Salt will now automatically assume the alias (eth0:1) is up and up-to-date—even if the virtual IP allocation for that alias completely failed to bind on the host.

That deleted code was the only mechanism verifying that the specific label (second.get("label") == name) was genuinely active in the system's runtime network state.

Instead of an unconditional split(":"), Salt should use a targeted regex match to separate a true legacy sub-interface/alias label from a standard interface name. Then, it needs to query the actual nested secondary data structure to confirm that the specific virtual label is bound and active.

    # Bring up/shutdown interface
    try:
        # Get Interfaces information
        interfaces = salt.utils.network.interfaces()
        interface_status = False

        # 1. Check if the exact interface name exists directly
        if name in interfaces:
            interface_status = interfaces[name].get("up", False)
        
        # 2. Safely check for legacy alias structures (e.g., eth0:1, bond0:vlan1)
        else:
            import re
            # Match standard interface naming followed by a numeric or label alias
            match = re.match(r"^([a-zA-Z0-9.\-_]+):([a-zA-Z0-9_\-]+)$", name)
            if match:
                parent_iface = match.group(1)
                if parent_iface in interfaces:
                    # Look for the explicit alias label in the secondary IP data structures
                    for family in ("secondary", "inet", "inet6"):
                        if family in interfaces[parent_iface]:
                            for data in interfaces[parent_iface][family]:
                                if data.get("label") == name:
                                    interface_status = True
                                    break
                        if interface_status:
                            break

        interface_status = interface_status or False

        # Handle interface as desired
        if enabled:

if enabled:
if "noifupdown" not in kwargs:
if interface_status:
Expand Down
76 changes: 0 additions & 76 deletions tests/integration/states/test_network.py

This file was deleted.

Loading
Loading