2024-04-14 14:12:14 +02:00
|
|
|
{
|
2024-05-02 10:39:19 +02:00
|
|
|
pkgs,
|
2024-04-14 14:12:14 +02:00
|
|
|
lib,
|
|
|
|
meta,
|
|
|
|
name,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
|
2024-03-27 10:26:31 +01:00
|
|
|
let
|
2024-04-14 14:12:14 +02:00
|
|
|
inherit (lib) mapAttrs' nameValuePair;
|
|
|
|
|
|
|
|
uplink = {
|
|
|
|
ip = "10.120.33.250";
|
|
|
|
prefix = 30;
|
|
|
|
|
|
|
|
router = "10.120.33.249";
|
|
|
|
};
|
2024-03-27 15:38:46 +01:00
|
|
|
|
2024-04-14 14:12:14 +02:00
|
|
|
mkNetwork =
|
|
|
|
name:
|
|
|
|
{
|
|
|
|
address,
|
|
|
|
extraNetwork ? { },
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
nameValuePair "10-${name}" ({ inherit name address; } // extraNetwork);
|
2024-03-27 15:38:46 +01:00
|
|
|
|
2024-04-14 14:12:14 +02:00
|
|
|
mkNetdev =
|
|
|
|
name:
|
|
|
|
{ Id, ... }:
|
|
|
|
nameValuePair "10-${name}" {
|
|
|
|
netdevConfig = {
|
|
|
|
Name = name;
|
|
|
|
Kind = "vlan";
|
|
|
|
};
|
|
|
|
vlanConfig.Id = Id;
|
|
|
|
};
|
2024-03-27 15:38:46 +01:00
|
|
|
|
2024-04-15 09:34:13 +02:00
|
|
|
mkUserVlan =
|
|
|
|
id:
|
|
|
|
let
|
2024-04-18 11:41:37 +02:00
|
|
|
# on alloue 10.0.0.0/17 aux thurnés, avec un /27 chacun, on garde 10.0.0.0/27 pour nous (routeur et autres)
|
|
|
|
vlan = 4094 - id;
|
|
|
|
prefix24nb = (id + 1) / 8;
|
|
|
|
prefix27nb = (id + 1 - prefix24nb * 8) * 32;
|
2024-04-15 09:34:13 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
name = "vlan-user-${builtins.toString vlan}";
|
|
|
|
value = {
|
|
|
|
Id = vlan;
|
2024-04-25 18:41:10 +02:00
|
|
|
address = [ ];
|
|
|
|
extraNetwork = {
|
2024-05-02 10:39:19 +02:00
|
|
|
networkConfig = {
|
|
|
|
LinkLocalAddressing = "no";
|
|
|
|
};
|
|
|
|
linkConfig = {
|
|
|
|
Promiscuous = true;
|
2024-04-26 09:33:11 +02:00
|
|
|
};
|
2024-04-25 18:41:10 +02:00
|
|
|
addresses = [
|
|
|
|
{
|
|
|
|
addressConfig = {
|
|
|
|
Address = "10.0.${builtins.toString prefix24nb}.${builtins.toString (prefix27nb + 1)}/27";
|
|
|
|
AddPrefixRoute = false;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
routes = [
|
|
|
|
{
|
|
|
|
routeConfig = {
|
|
|
|
Destination = "10.0.${builtins.toString prefix24nb}.${builtins.toString prefix27nb}/27";
|
|
|
|
Table = "user";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
routingPolicyRules = [
|
|
|
|
{
|
|
|
|
routingPolicyRuleConfig = {
|
|
|
|
From = "10.0.${builtins.toString prefix24nb}.${builtins.toString prefix27nb}/27";
|
|
|
|
To = "10.0.0.0/27";
|
|
|
|
IncomingInterface = "vlan-user-${builtins.toString vlan}";
|
|
|
|
Table = "user";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2024-04-15 09:34:13 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-04-14 14:12:14 +02:00
|
|
|
vlans = {
|
|
|
|
vlan-uplink-cri = {
|
|
|
|
Id = 223;
|
|
|
|
address = with uplink; [ "${ip}/${builtins.toString prefix}" ];
|
2024-03-27 15:38:46 +01:00
|
|
|
|
2024-04-14 14:12:14 +02:00
|
|
|
extraNetwork.routes = [
|
|
|
|
{
|
|
|
|
routeConfig = {
|
|
|
|
# Get the public ip from the metadata
|
|
|
|
PreferredSource = builtins.head meta.network.${name}.addresses.ipv4;
|
|
|
|
Gateway = uplink.router;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
vlan-admin = {
|
|
|
|
Id = 3000;
|
|
|
|
address = [ "fd26:baf9:d250:8000::1/64" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
vlan-admin-ap = {
|
|
|
|
Id = 3001;
|
|
|
|
address = [ "fd26:baf9:d250:8010::1/60" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
vlan-apro = {
|
|
|
|
Id = 2000;
|
|
|
|
address = [ "10.0.255.1/24" ];
|
|
|
|
|
|
|
|
extraNetwork.networkConfig.DHCPServer = "yes";
|
|
|
|
};
|
2024-05-02 10:39:19 +02:00
|
|
|
} // builtins.listToAttrs (builtins.genList mkUserVlan 850); # 850 when we can
|
2024-03-27 10:26:31 +01:00
|
|
|
in
|
2024-04-14 14:12:14 +02:00
|
|
|
|
2024-03-27 10:26:31 +01:00
|
|
|
{
|
|
|
|
systemd.network = {
|
2024-04-25 18:41:10 +02:00
|
|
|
config.routeTables."user" = 1000;
|
2024-03-27 10:26:31 +01:00
|
|
|
networks = {
|
2024-04-25 18:41:10 +02:00
|
|
|
"10-lo" = {
|
|
|
|
name = "lo";
|
|
|
|
address = [
|
|
|
|
"::1/128"
|
|
|
|
"127.0.0.1/8"
|
|
|
|
"10.0.0.1/16"
|
|
|
|
];
|
|
|
|
routes = [
|
|
|
|
{
|
|
|
|
routeConfig = {
|
|
|
|
Destination = "10.0.0.0/27";
|
|
|
|
Table = "user";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
routingPolicyRules = [
|
|
|
|
{
|
|
|
|
routingPolicyRuleConfig = {
|
|
|
|
IncomingInterface = "lo";
|
|
|
|
Table = "user";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2024-03-27 15:38:46 +01:00
|
|
|
"10-enp67s0f0np0" = {
|
2024-03-27 10:26:31 +01:00
|
|
|
name = "enp67s0f0np0";
|
2024-05-02 10:39:19 +02:00
|
|
|
linkConfig.Promiscuous = true;
|
2024-03-27 10:26:31 +01:00
|
|
|
networkConfig = {
|
2024-04-14 14:12:14 +02:00
|
|
|
VLAN = builtins.attrNames vlans;
|
2024-03-27 10:26:31 +01:00
|
|
|
|
|
|
|
LinkLocalAddressing = false;
|
|
|
|
LLDP = false;
|
|
|
|
EmitLLDP = false;
|
|
|
|
IPv6AcceptRA = false;
|
|
|
|
IPv6SendRA = false;
|
|
|
|
};
|
|
|
|
};
|
2024-04-14 14:12:14 +02:00
|
|
|
} // (mapAttrs' mkNetwork vlans);
|
|
|
|
|
|
|
|
netdevs = mapAttrs' mkNetdev vlans;
|
2024-03-27 10:26:31 +01:00
|
|
|
};
|
2024-04-14 14:12:14 +02:00
|
|
|
|
2024-05-02 10:39:19 +02:00
|
|
|
systemd.services.ethtoolConfig = {
|
|
|
|
wantedBy = [ "systemd-networkd.service" ];
|
|
|
|
after = [ "sys-subsystem-net-devices-enp67s0f0np0.device" ];
|
|
|
|
bindsTo = [ "sys-subsystem-net-devices-enp67s0f0np0.device" ];
|
|
|
|
script = ''
|
|
|
|
${lib.getExe pkgs.ethtool} -K enp67s0f0np0 rxvlan off
|
|
|
|
${lib.getExe pkgs.ethtool} -K enp67s0f0np0 txvlan off
|
|
|
|
${lib.getExe pkgs.ethtool} -K enp67s0f0np0 rx-vlan-filter off
|
|
|
|
${lib.getExe pkgs.ethtool} -K enp67s0f0np0 rx-vlan-offload off
|
|
|
|
${lib.getExe pkgs.ethtool} -K enp67s0f0np0 tx-vlan-offload off
|
|
|
|
${lib.getExe pkgs.ethtool} -K enp67s0f0np0 tx-vlan-stag-hw-insert off
|
|
|
|
echo "Hardware for enp67s0f0np0 configured"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-04-08 16:01:29 +02:00
|
|
|
networking.firewall.allowedUDPPorts = [ 67 ];
|
2024-03-27 10:26:31 +01:00
|
|
|
}
|