2024-01-28 10:48:13 +00:00
|
|
|
{ lib, config, machine, ... }:
|
2023-12-30 15:11:28 +00:00
|
|
|
let cfg = config.lab.networking;
|
|
|
|
in {
|
2024-01-31 20:58:23 +00:00
|
|
|
imports = [ ./dmz_services ];
|
2024-01-07 22:06:27 +00:00
|
|
|
|
2024-01-07 21:36:26 +00:00
|
|
|
options.lab.networking = {
|
2024-01-31 20:58:23 +00:00
|
|
|
dmz = {
|
|
|
|
allowConnectivity = lib.mkOption {
|
|
|
|
default = false;
|
|
|
|
type = lib.types.bool;
|
|
|
|
description = ''
|
|
|
|
Whether to allow networking on the DMZ bridge interface.
|
|
|
|
'';
|
|
|
|
};
|
2024-01-12 23:05:25 +00:00
|
|
|
|
2024-01-31 20:58:23 +00:00
|
|
|
bridgeName = lib.mkOption {
|
|
|
|
default = "bridgedmz";
|
|
|
|
type = lib.types.str;
|
|
|
|
description = ''
|
|
|
|
The name of the DMZ bridge.
|
|
|
|
'';
|
|
|
|
};
|
2024-01-12 23:05:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
mainNicNamePattern = lib.mkOption {
|
|
|
|
default = "en*";
|
|
|
|
type = lib.types.str;
|
|
|
|
description = ''
|
|
|
|
Pattern to match the name of this machine's main NIC.
|
|
|
|
'';
|
|
|
|
};
|
2023-12-30 14:20:16 +00:00
|
|
|
};
|
|
|
|
|
2023-12-30 15:11:28 +00:00
|
|
|
config = {
|
|
|
|
networking = {
|
2024-01-28 12:46:32 +00:00
|
|
|
domain = if machine.type == "physical" then "hyp" else "dmz";
|
2024-01-31 20:58:23 +00:00
|
|
|
nftables.enable = true;
|
2024-01-29 21:21:15 +00:00
|
|
|
useDHCP = false;
|
2024-01-28 10:48:13 +00:00
|
|
|
|
2024-01-12 21:31:15 +00:00
|
|
|
firewall = {
|
2024-01-31 20:58:23 +00:00
|
|
|
enable = true;
|
2024-01-12 21:31:15 +00:00
|
|
|
checkReversePath = false;
|
|
|
|
};
|
2023-12-30 15:11:28 +00:00
|
|
|
};
|
|
|
|
|
2024-01-28 10:48:13 +00:00
|
|
|
systemd.network = lib.mkIf (machine.type == "physical") {
|
2023-12-30 15:11:28 +00:00
|
|
|
enable = true;
|
2023-12-30 14:20:16 +00:00
|
|
|
|
2023-12-30 15:11:28 +00:00
|
|
|
netdevs = {
|
|
|
|
"20-vlandmz" = {
|
|
|
|
vlanConfig.Id = 30;
|
2023-12-30 14:20:16 +00:00
|
|
|
|
2023-12-30 15:11:28 +00:00
|
|
|
netdevConfig = {
|
|
|
|
Kind = "vlan";
|
|
|
|
Name = "vlandmz";
|
|
|
|
};
|
2023-12-30 14:20:16 +00:00
|
|
|
};
|
|
|
|
|
2023-12-30 15:11:28 +00:00
|
|
|
"20-bridgedmz" = {
|
|
|
|
netdevConfig = {
|
|
|
|
Kind = "bridge";
|
2024-01-31 20:58:23 +00:00
|
|
|
Name = cfg.dmz.bridgeName;
|
2023-12-30 15:11:28 +00:00
|
|
|
};
|
2023-12-30 14:20:16 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-12-30 15:11:28 +00:00
|
|
|
networks = {
|
|
|
|
"30-main-nic" = {
|
2024-01-12 23:05:25 +00:00
|
|
|
matchConfig.Name = cfg.mainNicNamePattern;
|
2023-12-30 15:11:28 +00:00
|
|
|
vlan = [ "vlandmz" ];
|
2023-12-30 14:20:16 +00:00
|
|
|
|
2023-12-30 15:11:28 +00:00
|
|
|
networkConfig = {
|
|
|
|
DHCP = "yes";
|
|
|
|
};
|
2023-12-30 14:20:16 +00:00
|
|
|
};
|
|
|
|
|
2023-12-30 15:11:28 +00:00
|
|
|
"40-vlandmz" = {
|
|
|
|
matchConfig.Name = "vlandmz";
|
|
|
|
linkConfig.RequiredForOnline = "enslaved";
|
2023-12-30 14:20:16 +00:00
|
|
|
|
2023-12-30 15:11:28 +00:00
|
|
|
networkConfig = {
|
|
|
|
IPv6AcceptRA = false;
|
|
|
|
LinkLocalAddressing = "no";
|
2024-01-31 20:58:23 +00:00
|
|
|
Bridge = cfg.dmz.bridgeName;
|
2023-12-30 15:11:28 +00:00
|
|
|
};
|
2023-12-30 14:20:16 +00:00
|
|
|
};
|
|
|
|
|
2023-12-30 15:11:28 +00:00
|
|
|
"40-bridgedmz" = {
|
2024-01-31 20:58:23 +00:00
|
|
|
matchConfig.Name = cfg.dmz.bridgeName;
|
2023-12-30 15:11:28 +00:00
|
|
|
linkConfig.RequiredForOnline = "carrier";
|
2023-12-30 14:20:16 +00:00
|
|
|
|
2023-12-30 15:11:28 +00:00
|
|
|
networkConfig = {
|
2024-01-31 20:58:23 +00:00
|
|
|
IPv6AcceptRA = cfg.dmz.allowConnectivity;
|
|
|
|
LinkLocalAddressing = if cfg.dmz.allowConnectivity then "ipv6" else "no";
|
|
|
|
DHCP = "yes";
|
2023-12-30 15:11:28 +00:00
|
|
|
};
|
2023-12-30 14:20:16 +00:00
|
|
|
};
|
2024-01-17 20:28:15 +00:00
|
|
|
|
|
|
|
"40-vms" = {
|
|
|
|
matchConfig.Name = "vm-*";
|
2024-01-31 20:58:23 +00:00
|
|
|
networkConfig.Bridge = cfg.dmz.bridgeName;
|
2024-01-17 20:28:15 +00:00
|
|
|
};
|
2023-12-30 14:20:16 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|