From 8d3527aa887eb6ea4c0c2fc5a5cbe8cf0e81de2e Mon Sep 17 00:00:00 2001 From: John Whitman Date: Wed, 1 Sep 2021 21:46:26 -0400 Subject: [PATCH] nixos/network-interfaces: Fix wlan interface mac --- nixos/modules/tasks/network-interfaces.nix | 12 ++++++------ nixos/tests/networking.nix | 18 ++++++++++++++++++ 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 // {