Merge pull request #34442 from rnhmjoj/virtual
Fix virtualType for network-interfaces-scripted
This commit is contained in:
commit
57d72d4140
@ -230,9 +230,7 @@ let
|
||||
RemainAfterExit = true;
|
||||
};
|
||||
script = ''
|
||||
ip tuntap add dev "${i.name}" \
|
||||
${optionalString (i.virtualType != null) "mode ${i.virtualType}"} \
|
||||
user "${i.virtualOwner}"
|
||||
ip tuntap add dev "${i.name}" mode "${i.virtualType}" user "${i.virtualOwner}"
|
||||
'';
|
||||
postStop = ''
|
||||
ip link del ${i.name} || true
|
||||
|
@ -74,17 +74,13 @@ in
|
||||
networks."99-main" = genericNetwork mkDefault;
|
||||
}
|
||||
(mkMerge (flip map interfaces (i: {
|
||||
netdevs = mkIf i.virtual (
|
||||
let
|
||||
devType = if i.virtualType != null then i.virtualType
|
||||
else (if hasPrefix "tun" i.name then "tun" else "tap");
|
||||
in {
|
||||
netdevs = mkIf i.virtual ({
|
||||
"40-${i.name}" = {
|
||||
netdevConfig = {
|
||||
Name = i.name;
|
||||
Kind = devType;
|
||||
Kind = i.virtualType;
|
||||
};
|
||||
"${devType}Config" = optionalAttrs (i.virtualOwner != null) {
|
||||
"${i.virtualType}Config" = optionalAttrs (i.virtualOwner != null) {
|
||||
User = i.virtualOwner;
|
||||
};
|
||||
};
|
||||
|
@ -273,11 +273,13 @@ let
|
||||
};
|
||||
|
||||
virtualType = mkOption {
|
||||
default = null;
|
||||
type = with types; nullOr (enum [ "tun" "tap" ]);
|
||||
default = if hasPrefix "tun" name then "tun" else "tap";
|
||||
defaultText = literalExample ''if hasPrefix "tun" name then "tun" else "tap"'';
|
||||
type = with types; enum [ "tun" "tap" ];
|
||||
description = ''
|
||||
The explicit type of interface to create. Accepts tun or tap strings.
|
||||
Also accepts null to implicitly detect the type of device.
|
||||
The type of interface to create.
|
||||
The default is TUN for an interface name starting
|
||||
with "tun", otherwise TAP.
|
||||
'';
|
||||
};
|
||||
|
||||
|
@ -433,6 +433,49 @@ let
|
||||
$client2->succeed("ip addr show dev vlan >&2");
|
||||
'';
|
||||
};
|
||||
virtual = {
|
||||
name = "Virtual";
|
||||
machine = {
|
||||
networking.interfaces."tap0" = {
|
||||
ip4 = [ { address = "192.168.1.1"; prefixLength = 24; } ];
|
||||
ip6 = [ { address = "2001:1470:fffd:2096::"; prefixLength = 64; } ];
|
||||
virtual = true;
|
||||
};
|
||||
networking.interfaces."tun0" = {
|
||||
ip4 = [ { address = "192.168.1.2"; prefixLength = 24; } ];
|
||||
ip6 = [ { address = "2001:1470:fffd:2097::"; prefixLength = 64; } ];
|
||||
virtual = true;
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
my $targetList = <<'END';
|
||||
tap0: tap UNKNOWN_FLAGS:800 user 0
|
||||
tun0: tun UNKNOWN_FLAGS:800 user 0
|
||||
END
|
||||
|
||||
# Wait for networking to come up
|
||||
$machine->start;
|
||||
$machine->waitForUnit("network.target");
|
||||
|
||||
# Test interfaces set up
|
||||
my $list = $machine->succeed("ip tuntap list | sort");
|
||||
"$list" eq "$targetList" or die(
|
||||
"The list of virtual interfaces does not match the expected one:\n",
|
||||
"Result:\n", "$list\n",
|
||||
"Expected:\n", "$targetList\n"
|
||||
);
|
||||
|
||||
# Test interfaces clean up
|
||||
$machine->succeed("systemctl stop network-addresses-tap0");
|
||||
$machine->succeed("systemctl stop network-addresses-tun0");
|
||||
my $residue = $machine->succeed("ip tuntap list");
|
||||
$residue eq "" or die(
|
||||
"Some virtual interface has not been properly cleaned:\n",
|
||||
"$residue\n"
|
||||
);
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
in mapAttrs (const (attrs: makeTest (attrs // {
|
||||
|
Loading…
x
Reference in New Issue
Block a user