nixos/tests/networking.nix: test the services.dhcpd4.machines option
This modifies the `router` to not give out a range of IP addresses but only give out a fixed address based on the MAC address using the `services.dhcpd4.machines` option. To get access to the MAC address the `qemuNicMac` function is defined and exported from `qemu-flags.nix`.
This commit is contained in:
parent
0410f5dff9
commit
e15815e885
|
@ -9,10 +9,11 @@ let
|
||||||
else pkgs.lib.toHex n);
|
else pkgs.lib.toHex n);
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
rec {
|
||||||
|
qemuNicMac = net: machine: "52:54:00:12:${zeroPad net}:${zeroPad machine}";
|
||||||
|
|
||||||
qemuNICFlags = nic: net: machine:
|
qemuNICFlags = nic: net: machine:
|
||||||
[ "-device virtio-net-pci,netdev=vlan${toString nic},mac=52:54:00:12:${zeroPad net}:${zeroPad machine}"
|
[ "-device virtio-net-pci,netdev=vlan${toString nic},mac=${qemuNicMac net machine}"
|
||||||
"-netdev vde,id=vlan${toString nic},sock=$QEMU_VDE_SOCKET_${toString net}"
|
"-netdev vde,id=vlan${toString nic},sock=$QEMU_VDE_SOCKET_${toString net}"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,9 @@ with import ../lib/testing-python.nix { inherit system pkgs; };
|
||||||
with pkgs.lib;
|
with pkgs.lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
router = { config, pkgs, ... }:
|
qemu-flags = import ../lib/qemu-flags.nix { inherit pkgs; };
|
||||||
|
|
||||||
|
router = { config, pkgs, lib, ... }:
|
||||||
with pkgs.lib;
|
with pkgs.lib;
|
||||||
let
|
let
|
||||||
vlanIfs = range 1 (length config.virtualisation.vlans);
|
vlanIfs = range 1 (length config.virtualisation.vlans);
|
||||||
|
@ -31,16 +33,19 @@ let
|
||||||
enable = true;
|
enable = true;
|
||||||
interfaces = map (n: "eth${toString n}") vlanIfs;
|
interfaces = map (n: "eth${toString n}") vlanIfs;
|
||||||
extraConfig = ''
|
extraConfig = ''
|
||||||
authoritative;
|
|
||||||
'' + flip concatMapStrings vlanIfs (n: ''
|
'' + flip concatMapStrings vlanIfs (n: ''
|
||||||
subnet 192.168.${toString n}.0 netmask 255.255.255.0 {
|
subnet 192.168.${toString n}.0 netmask 255.255.255.0 {
|
||||||
option routers 192.168.${toString n}.1;
|
option routers 192.168.${toString n}.1;
|
||||||
# XXX: technically it's _not guaranteed_ that IP addresses will be
|
|
||||||
# issued from the first item in range onwards! We assume that in
|
|
||||||
# our tests however.
|
|
||||||
range 192.168.${toString n}.2 192.168.${toString n}.254;
|
|
||||||
}
|
}
|
||||||
'');
|
'')
|
||||||
|
;
|
||||||
|
machines = lib.flip map vlanIfs (vlan:
|
||||||
|
{
|
||||||
|
hostName = "client${toString vlan}";
|
||||||
|
ethernetAddress = qemu-flags.qemuNicMac vlan 1;
|
||||||
|
ipAddress = "192.168.${toString vlan}.2";
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
services.radvd = {
|
services.radvd = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
Loading…
Reference in New Issue