nixos-module/container/bird: rework radv router selection

This commit is contained in:
Astro 2022-10-23 01:16:18 +02:00
parent f5080ccf94
commit 13e0aa216e
7 changed files with 31 additions and 25 deletions

View File

@ -67,6 +67,7 @@
c3d2-gw3 = "172.22.99.4"; c3d2-gw3 = "172.22.99.4";
dn42 = "172.22.99.253"; dn42 = "172.22.99.253";
}; };
ipv6Router = "c3d2-gw3";
hosts6.dn42 = { hosts6.dn42 = {
bgp = "fd23:42:c3d2:523::c3d2:ff0b"; bgp = "fd23:42:c3d2:523::c3d2:ff0b";
c3d2-anon = "fd23:42:c3d2:523::c3d2:1"; c3d2-anon = "fd23:42:c3d2:523::c3d2:1";

View File

@ -4,6 +4,7 @@ let
in in
{ {
site.net.cluster = { site.net.cluster = {
ipv6Router = "cls-gw";
domainName = "cluster.zentralwerk.org"; domainName = "cluster.zentralwerk.org";
extraRecords = map (host: { extraRecords = map (host: {
data = "1 1 6789 ${host}"; data = "1 1 6789 ${host}";

View File

@ -1,6 +1,7 @@
{ {
site.net.flpk = { site.net.flpk = {
domainName = "flpk.zentralwerk.org"; domainName = "flpk.zentralwerk.org";
ipv6Router = "flpk-gw";
subnet4 = "45.158.40.160/27"; subnet4 = "45.158.40.160/27";
# we get a /56 # we get a /56
subnets6.flpk = "2a0f:5382:acab:1400::/64"; subnets6.flpk = "2a0f:5382:acab:1400::/64";

View File

@ -79,6 +79,7 @@
factorio = "172.20.73.73"; factorio = "172.20.73.73";
zengel = "172.20.73.74"; zengel = "172.20.73.74";
}; };
ipv6Router = "serv-gw";
subnets6.dn42 = "fd23:42:c3d2:582::/64"; subnets6.dn42 = "fd23:42:c3d2:582::/64";
subnets6.up4 = "2a00:8180:2c00:282::/64"; subnets6.up4 = "2a00:8180:2c00:282::/64";
hosts6.dn42 = { hosts6.dn42 = {

View File

@ -3,6 +3,7 @@
site.net.vpn = { site.net.vpn = {
vlan = null; vlan = null;
domainName = "core.zentralwerk.org"; domainName = "core.zentralwerk.org";
ipv6Router = "vpn-gw";
hosts4 = { hosts4 = {
vpn-gw = "172.20.76.225"; vpn-gw = "172.20.76.225";
}; };

View File

@ -158,6 +158,11 @@ let
type = with types; nullOr (submodule { options = dhcpOpts; }); type = with types; nullOr (submodule { options = dhcpOpts; });
default = null; default = null;
}; };
ipv6Router = mkOption {
description = "Who sends router advertisements?";
type = with types; nullOr str;
default = config.site.net.${name}.dhcp.router or null;
};
domainName = mkOption { domainName = mkOption {
description = "Domain name option"; description = "Domain name option";
type = types.str; type = types.str;

View File

@ -12,17 +12,11 @@ let
isUpstream = upstreamInterfaces != {}; isUpstream = upstreamInterfaces != {};
# Configuring a gateway? If so, this is the associated net. ipv6RouterNets = builtins.attrNames (
gatewayNet = lib.filterAttrs (net: { ipv6Router, ... }:
let ipv6Router == hostName
m = builtins.match "(.+)-gw" hostName; ) config.site.net
in if hostName == "c3d2-gw3" );
then "c3d2"
else if m == [ "cls" ]
then "cluster"
else if m == null
then null
else builtins.head m;
enumerate = n: list: enumerate = n: list:
if list == [] if list == []
@ -110,26 +104,28 @@ in
} }
''} ''}
${lib.optionalString (gatewayNet != null) '' ${lib.optionalString (ipv6RouterNets != []) ''
# Router advertisements # Router advertisements
protocol radv { protocol radv {
rdnss ${config.site.net.serv.hosts6.dn42.dnscache}; rdnss ${config.site.net.serv.hosts6.dn42.dnscache};
interface "${gatewayNet}" { ${lib.concatMapStrings (net:
min ra interval 10; interface "${net}" {
max ra interval 60; min ra interval 10;
max ra interval 60;
${builtins.concatStringsSep "\n" ( ${builtins.concatStringsSep "\n" (
map (subnet6: '' map (subnet6: ''
prefix ${subnet6} { prefix ${subnet6} {
preferred lifetime 600; preferred lifetime 600;
valid lifetime 1800; valid lifetime 1800;
}; };
'') (builtins.attrValues config.site.net.${gatewayNet}.subnets6) '') (builtins.attrValues config.site.net.${net}.subnets6)
)} )}
dnssl "${config.site.net.${gatewayNet}.domainName}"; dnssl "${config.site.net.${net}.domainName}";
}; };
) ipv6RouterNets}
} }
''} ''}