From 6732106210fe87ecb497b86dfa7a451ead65cdb4 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Sat, 27 May 2023 15:09:22 +0200 Subject: [PATCH 1/2] network-interfaces-scripted: fix interface cleanup There is apparently a bug in the parser of iproute2 where the command `ip link show ` will not show the device but list all interfaces (equivalent to `ip link show`) if devname is equal to one of the flags of `ip-address(8)`. For example, `home`, or `optimistic`. This bug causes a false positive in the clean up command of the -netdev.service, the service fails and the interface is never configured. To avoid the bug we can simply use `ip link show dev `. --- nixos/modules/tasks/network-interfaces-scripted.nix | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nixos/modules/tasks/network-interfaces-scripted.nix b/nixos/modules/tasks/network-interfaces-scripted.nix index 843082ab858e..24f0c37acf90 100644 --- a/nixos/modules/tasks/network-interfaces-scripted.nix +++ b/nixos/modules/tasks/network-interfaces-scripted.nix @@ -293,7 +293,7 @@ let script = '' # Remove Dead Interfaces echo "Removing old bridge ${n}..." - ip link show "${n}" >/dev/null 2>&1 && ip link del "${n}" + ip link show dev "${n}" >/dev/null 2>&1 && ip link del "${n}" echo "Adding bridge ${n}..." ip link add name "${n}" type bridge @@ -459,7 +459,7 @@ let path = [ pkgs.iproute2 ]; script = '' # Remove Dead Interfaces - ip link show "${n}" >/dev/null 2>&1 && ip link delete "${n}" + ip link show dev "${n}" >/dev/null 2>&1 && ip link delete "${n}" ip link add link "${v.interface}" name "${n}" type macvlan \ ${optionalString (v.mode != null) "mode ${v.mode}"} ip link set "${n}" up @@ -517,7 +517,7 @@ let path = [ pkgs.iproute2 ]; script = '' # Remove Dead Interfaces - ip link show "${n}" >/dev/null 2>&1 && ip link delete "${n}" + ip link show dev "${n}" >/dev/null 2>&1 && ip link delete "${n}" ip link add name "${n}" type sit \ ${optionalString (v.remote != null) "remote \"${v.remote}\""} \ ${optionalString (v.local != null) "local \"${v.local}\""} \ @@ -551,7 +551,7 @@ let path = [ pkgs.iproute2 ]; script = '' # Remove Dead Interfaces - ip link show "${n}" >/dev/null 2>&1 && ip link delete "${n}" + ip link show dev "${n}" >/dev/null 2>&1 && ip link delete "${n}" ip link add name "${n}" type ${v.type} \ ${optionalString (v.remote != null) "remote \"${v.remote}\""} \ ${optionalString (v.local != null) "local \"${v.local}\""} \ @@ -579,7 +579,7 @@ let path = [ pkgs.iproute2 ]; script = '' # Remove Dead Interfaces - ip link show "${n}" >/dev/null 2>&1 && ip link delete "${n}" + ip link show dev "${n}" >/dev/null 2>&1 && ip link delete "${n}" ip link add link "${v.interface}" name "${n}" type vlan id "${toString v.id}" # We try to bring up the logical VLAN interface. If the master From ea0b4a694aeacc4d2f28a001af14c0e9d85fd7ee Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Sat, 27 May 2023 19:10:44 +0200 Subject: [PATCH 2/2] nixos/test/networking: test unusual interface names --- nixos/tests/networking.nix | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/nixos/tests/networking.nix b/nixos/tests/networking.nix index 99f0b6db32af..05fed0f4b473 100644 --- a/nixos/tests/networking.nix +++ b/nixos/tests/networking.nix @@ -998,6 +998,31 @@ let machine.fail("ip address show wlan0 | grep -q ${testMac}") ''; }; + naughtyInterfaceNames = let + ifnames = [ + # flags of ip-address + "home" "temporary" "optimistic" + "bridge_slave" "flush" + # flags of ip-route + "up" "type" "nomaster" "address" + # other + "very_loong_name" "lowerUpper" "-" + ]; + in { + name = "naughtyInterfaceNames"; + nodes.machine = { pkgs, ... }: { + networking.useNetworkd = networkd; + networking.bridges = listToAttrs + (flip map ifnames + (name: { inherit name; value.interfaces = []; })); + }; + testScript = '' + machine.start() + machine.wait_for_unit("network.target") + for ifname in ${builtins.toJSON ifnames}: + machine.wait_until_succeeds(f"ip link show dev '{ifname}' | grep -q '{ifname}'") + ''; + }; caseSensitiveRenaming = { name = "CaseSensitiveRenaming"; nodes.machine = { pkgs, ... }: {