git.iko.soy/typeable/nixpkgs
on master help sign in
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

commit052009bf2b6768c4cf171d94de4d75aee2b81492 authorMichele Guerini Rocco <rnhmjoj@users.noreply.github.com> dateThu 2 Sep 2021, 09:37 (5 years ago) parent98659898d3527a
2 files changed+24−6
nixos/modules/tasks/network-interfaces.nix+6−6 nixos/tests/networking.nix+18
nixos/modules/tasks/network-interfaces.nix+6−6
@@ -1296,14 +1296,14 @@ in
12961296 '';
12971297
12981298 # Udev script to execute for a new WLAN interface. The script configures the new WLAN interface.
1299− newInterfaceScript = device: new: pkgs.writeScript "udev-run-script-wlan-interfaces-${new._iName}.sh" ''
1299+ newInterfaceScript = new: pkgs.writeScript "udev-run-script-wlan-interfaces-${new._iName}.sh" ''
13001300 #!${pkgs.runtimeShell}
13011301 # Configure the new interface
13021302 ${pkgs.iw}/bin/iw dev ${new._iName} set type ${new.type}
1303− ${optionalString (new.type == "mesh" && new.meshID!=null) "${pkgs.iw}/bin/iw dev ${device} set meshid ${new.meshID}"}
1304− ${optionalString (new.type == "monitor" && new.flags!=null) "${pkgs.iw}/bin/iw dev ${device} set monitor ${new.flags}"}
1305− ${optionalString (new.type == "managed" && new.fourAddr!=null) "${pkgs.iw}/bin/iw dev ${device} set 4addr ${if new.fourAddr then "on" else "off"}"}
1306− ${optionalString (new.mac != null) "${pkgs.iproute2}/bin/ip link set dev ${device} address ${new.mac}"}
1303+ ${optionalString (new.type == "mesh" && new.meshID!=null) "${pkgs.iw}/bin/iw dev ${new._iName} set meshid ${new.meshID}"}
1304+ ${optionalString (new.type == "monitor" && new.flags!=null) "${pkgs.iw}/bin/iw dev ${new._iName} set monitor ${new.flags}"}
1305+ ${optionalString (new.type == "managed" && new.fourAddr!=null) "${pkgs.iw}/bin/iw dev ${new._iName} set 4addr ${if new.fourAddr then "on" else "off"}"}
1306+ ${optionalString (new.mac != null) "${pkgs.iproute2}/bin/ip link set dev ${new._iName} address ${new.mac}"}
13071307 '';
13081308
13091309 # Udev attributes for systemd to name the device and to create a .device target.
@@ -1318,7 +1318,7 @@ in
13181318 # It is important to have that rule first as overwriting the NAME attribute also prevents the
13191319 # next rules from matching.
13201320 ${flip (concatMapStringsSep "\n") (wlanListDeviceFirst device wlanDeviceInterfaces.${device}) (interface:
1321− ''ACTION=="add", SUBSYSTEM=="net", ENV{DEVTYPE}=="wlan", ENV{INTERFACE}=="${interface._iName}", ${systemdAttrs interface._iName}, RUN+="${newInterfaceScript device interface}"'')}
1321+ ''ACTION=="add", SUBSYSTEM=="net", ENV{DEVTYPE}=="wlan", ENV{INTERFACE}=="${interface._iName}", ${systemdAttrs interface._iName}, RUN+="${newInterfaceScript interface}"'')}
13221322
13231323 # Add the required, new WLAN interfaces to the default WLAN interface with the
13241324 # persistent, default name as assigned by udev.
nixos/tests/networking.nix+18
@@ -721,6 +721,24 @@ let
721721 assert "mtu 1442" in client.succeed("ip l show dummy0")
722722 '';
723723 };
724+ wlanInterface = let
725+ testMac = "06:00:00:00:02:00";
726+ in {
727+ name = "WlanInterface";
728+ machine = { pkgs, ... }: {
729+ boot.kernelModules = [ "mac80211_hwsim" ];
730+ networking.wlanInterfaces = {
731+ wlan0 = { device = "wlan0"; };
732+ wap0 = { device = "wlan0"; mac = testMac; };
733+ };
734+ };
735+ testScript = ''
736+ machine.start()
737+ machine.wait_for_unit("network.target")
738+ machine.wait_until_succeeds("ip address show wap0 | grep -q ${testMac}")
739+ machine.fail("ip address show wlan0 | grep -q ${testMac}")
740+ '';
741+ };
724742 };
725743
726744in mapAttrs (const (attrs: makeTest (attrs // {