about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorMichele Guerini Rocco <rnhmjoj@users.noreply.github.com>2021-09-02 09:37:04 +0200
committerGitHub <noreply@github.com>2021-09-02 09:37:04 +0200
commit052009bf2b6768c4cf171d94de4d75aee2b81492 (patch)
treeb6b0bcb7b08b06c8d81189b7ed5019e735cb2e32 /nixos
parent98659898959e00c285ab1711739757b19154d158 (diff)
parent8d3527aa887eb6ea4c0c2fc5a5cbe8cf0e81de2e (diff)
downloadnixlib-052009bf2b6768c4cf171d94de4d75aee2b81492.tar
nixlib-052009bf2b6768c4cf171d94de4d75aee2b81492.tar.gz
nixlib-052009bf2b6768c4cf171d94de4d75aee2b81492.tar.bz2
nixlib-052009bf2b6768c4cf171d94de4d75aee2b81492.tar.lz
nixlib-052009bf2b6768c4cf171d94de4d75aee2b81492.tar.xz
nixlib-052009bf2b6768c4cf171d94de4d75aee2b81492.tar.zst
nixlib-052009bf2b6768c4cf171d94de4d75aee2b81492.zip
Merge pull request #135315 from johnjameswhitman/johnjameswhitman/fix-wlan-sub-interfaces
nixos/tasks/network-interfaces: Assign mac to new wlan interface instead of underlying one
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/tasks/network-interfaces.nix12
-rw-r--r--nixos/tests/networking.nix18
2 files changed, 24 insertions, 6 deletions
diff --git a/nixos/modules/tasks/network-interfaces.nix b/nixos/modules/tasks/network-interfaces.nix
index 879f077332e3..8f9c66b01572 100644
--- a/nixos/modules/tasks/network-interfaces.nix
+++ b/nixos/modules/tasks/network-interfaces.nix
@@ -1296,14 +1296,14 @@ in
             '';
 
             # Udev script to execute for a new WLAN interface. The script configures the new WLAN interface.
-            newInterfaceScript = device: new: pkgs.writeScript "udev-run-script-wlan-interfaces-${new._iName}.sh" ''
+            newInterfaceScript = new: pkgs.writeScript "udev-run-script-wlan-interfaces-${new._iName}.sh" ''
               #!${pkgs.runtimeShell}
               # Configure the new interface
               ${pkgs.iw}/bin/iw dev ${new._iName} set type ${new.type}
-              ${optionalString (new.type == "mesh" && new.meshID!=null) "${pkgs.iw}/bin/iw dev ${device} set meshid ${new.meshID}"}
-              ${optionalString (new.type == "monitor" && new.flags!=null) "${pkgs.iw}/bin/iw dev ${device} set monitor ${new.flags}"}
-              ${optionalString (new.type == "managed" && new.fourAddr!=null) "${pkgs.iw}/bin/iw dev ${device} set 4addr ${if new.fourAddr then "on" else "off"}"}
-              ${optionalString (new.mac != null) "${pkgs.iproute2}/bin/ip link set dev ${device} address ${new.mac}"}
+              ${optionalString (new.type == "mesh" && new.meshID!=null) "${pkgs.iw}/bin/iw dev ${new._iName} set meshid ${new.meshID}"}
+              ${optionalString (new.type == "monitor" && new.flags!=null) "${pkgs.iw}/bin/iw dev ${new._iName} set monitor ${new.flags}"}
+              ${optionalString (new.type == "managed" && new.fourAddr!=null) "${pkgs.iw}/bin/iw dev ${new._iName} set 4addr ${if new.fourAddr then "on" else "off"}"}
+              ${optionalString (new.mac != null) "${pkgs.iproute2}/bin/ip link set dev ${new._iName} address ${new.mac}"}
             '';
 
             # Udev attributes for systemd to name the device and to create a .device target.
@@ -1318,7 +1318,7 @@ in
             # It is important to have that rule first as overwriting the NAME attribute also prevents the
             # next rules from matching.
             ${flip (concatMapStringsSep "\n") (wlanListDeviceFirst device wlanDeviceInterfaces.${device}) (interface:
-            ''ACTION=="add", SUBSYSTEM=="net", ENV{DEVTYPE}=="wlan", ENV{INTERFACE}=="${interface._iName}", ${systemdAttrs interface._iName}, RUN+="${newInterfaceScript device interface}"'')}
+            ''ACTION=="add", SUBSYSTEM=="net", ENV{DEVTYPE}=="wlan", ENV{INTERFACE}=="${interface._iName}", ${systemdAttrs interface._iName}, RUN+="${newInterfaceScript interface}"'')}
 
             # Add the required, new WLAN interfaces to the default WLAN interface with the
             # persistent, default name as assigned by udev.
diff --git a/nixos/tests/networking.nix b/nixos/tests/networking.nix
index c8756207f27b..22f7ca5a9b82 100644
--- a/nixos/tests/networking.nix
+++ b/nixos/tests/networking.nix
@@ -721,6 +721,24 @@ let
         assert "mtu 1442" in client.succeed("ip l show dummy0")
       '';
     };
+    wlanInterface = let
+      testMac = "06:00:00:00:02:00";
+    in {
+      name = "WlanInterface";
+      machine = { pkgs, ... }: {
+        boot.kernelModules = [ "mac80211_hwsim" ];
+        networking.wlanInterfaces = {
+          wlan0 = { device = "wlan0"; };
+          wap0 = { device = "wlan0"; mac = testMac; };
+        };
+      };
+      testScript = ''
+        machine.start()
+        machine.wait_for_unit("network.target")
+        machine.wait_until_succeeds("ip address show wap0 | grep -q ${testMac}")
+        machine.fail("ip address show wlan0 | grep -q ${testMac}")
+      '';
+    };
   };
 
 in mapAttrs (const (attrs: makeTest (attrs // {