fix(shitty-oob): Drop user vlans when no-uplink

This commit is contained in:
catvayor 2024-05-30 18:46:09 +02:00
parent 37a18c0347
commit dce439fcca
Signed by: lbailly
GPG key ID: CE3E645251AC63F3

View file

@ -37,16 +37,13 @@ let
}; };
mkUserVlan = mkUserVlan =
id: {
let vlan,
# 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) netIP,
vlan = 4094 - id; servIP,
prefix24nb = (id + 1) / 8; interfaceName,
prefix27nb = (id + 1 - prefix24nb * 8) * 32; ...
netIP = "10.0.${toString prefix24nb}.${toString prefix27nb}"; }:
servIP = "10.0.${toString prefix24nb}.${toString (prefix27nb + 1)}";
interfaceName = "vlan-user-${toString vlan}";
in
{ {
name = interfaceName; name = interfaceName;
value = { value = {
@ -87,6 +84,15 @@ let
}; };
}; };
userVlans = builtins.genList (id: rec {
vlan = 4094 - id;
prefix24nb = (id + 1) / 8;
prefix27nb = (id + 1 - prefix24nb * 8) * 32;
netIP = "10.0.${toString prefix24nb}.${toString prefix27nb}";
servIP = "10.0.${toString prefix24nb}.${toString (prefix27nb + 1)}";
interfaceName = "vlan-user-${toString vlan}";
}) 850;
vlans = { vlans = {
vlan-uplink-cri = { vlan-uplink-cri = {
Id = 223; Id = 223;
@ -119,7 +125,7 @@ let
extraNetwork.networkConfig.DHCPServer = "yes"; extraNetwork.networkConfig.DHCPServer = "yes";
}; };
} // builtins.listToAttrs (builtins.genList mkUserVlan 850); } // builtins.listToAttrs (map mkUserVlan userVlans);
in in
{ {
@ -187,6 +193,31 @@ in
}; };
systemd-networkd.serviceConfig.LimitNOFILE = 4096; systemd-networkd.serviceConfig.LimitNOFILE = 4096;
net-checker = {
path = [
pkgs.iputils
pkgs.systemd
];
script = ''
if ping -c 1 8.8.8.8 > /dev/null || ping -c 1 1.1.1.1 > /dev/null; then
${
lib.concatMapStringsSep "\n " ({ interfaceName, ... }: "networkctl up ${interfaceName}") userVlans
}
else
${
lib.concatMapStringsSep "\n " (
{ interfaceName, ... }: "networkctl down ${interfaceName}"
) userVlans
}
fi
'';
};
};
timers.net-checker = {
wantedBy = [ "timers.target" ];
timerConfig.OnCalendar = "*-*-* *:*:42";
}; };
}; };