2022-03-22 18:13:17 +01:00
|
|
|
{ hostName, config, lib, ... }:
|
2021-05-31 00:06:56 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
hostConf = config.site.hosts.${hostName};
|
|
|
|
|
|
|
|
pppoeInterfaces =
|
|
|
|
lib.filterAttrs (_: { type, ... }: type == "pppoe")
|
|
|
|
hostConf.interfaces;
|
|
|
|
|
|
|
|
in lib.mkIf (pppoeInterfaces != {}) {
|
|
|
|
boot.postBootCommands = ''
|
|
|
|
if [ ! -c /dev/ppp ]; then
|
2021-05-31 00:41:38 +02:00
|
|
|
mknod -m 600 /dev/ppp c 108 0
|
2021-05-31 00:06:56 +02:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
2021-11-13 01:23:23 +01:00
|
|
|
environment.etc."ppp/pap-secrets".text = lib.concatMapStrings (ifName:
|
|
|
|
let
|
2021-11-13 03:23:45 +01:00
|
|
|
inherit (pppoeInterfaces.${ifName}.upstream) user password;
|
2021-11-13 01:23:23 +01:00
|
|
|
in ''
|
|
|
|
"${user}" * "${password}"
|
|
|
|
'') (builtins.attrNames pppoeInterfaces);
|
2021-05-31 00:06:56 +02:00
|
|
|
services.pppd = {
|
|
|
|
enable = true;
|
2021-11-13 03:23:45 +01:00
|
|
|
peers = builtins.mapAttrs (ifName: { upstream, ... }: {
|
2021-05-31 00:06:56 +02:00
|
|
|
enable = true;
|
|
|
|
autostart = true;
|
|
|
|
config = ''
|
|
|
|
plugin rp-pppoe.so
|
|
|
|
nic-${upstream.link}
|
|
|
|
ifname ${ifName}
|
|
|
|
# Login settings. (PAP)
|
2021-11-13 03:23:45 +01:00
|
|
|
name "${upstream.user}"
|
2021-05-31 00:06:56 +02:00
|
|
|
noauth
|
|
|
|
hide-password
|
|
|
|
# Connection settings.
|
|
|
|
persist
|
|
|
|
# Max connection attempts (0 = no limit)
|
|
|
|
maxfail 0
|
|
|
|
# Seconds between reconnection attempts
|
|
|
|
holdoff 1
|
|
|
|
|
|
|
|
# LCP settings.
|
|
|
|
lcp-echo-interval 5
|
|
|
|
lcp-echo-failure 6
|
|
|
|
|
|
|
|
# PPPoE compliant settings.
|
|
|
|
noaccomp
|
|
|
|
default-asyncmap
|
|
|
|
mtu 1492
|
|
|
|
# IP settings.
|
|
|
|
defaultroute
|
|
|
|
+ipv6
|
|
|
|
defaultroute6
|
|
|
|
# Increase debugging level
|
|
|
|
debug
|
|
|
|
'';
|
2021-05-31 00:41:38 +02:00
|
|
|
}) pppoeInterfaces;
|
2021-05-31 00:06:56 +02:00
|
|
|
};
|
|
|
|
|
2021-05-31 00:41:38 +02:00
|
|
|
systemd.network.networks =
|
|
|
|
builtins.foldl' (networks: ifName: let
|
|
|
|
iface = pppoeInterfaces.${ifName};
|
|
|
|
in networks // {
|
|
|
|
"${ifName}" = {
|
|
|
|
matchConfig.Name = "${ifName}";
|
|
|
|
networkConfig = {
|
|
|
|
DHCP = lib.mkOverride 900 "ipv6";
|
|
|
|
# accept config set by pppd
|
|
|
|
KeepConfiguration = "yes";
|
|
|
|
};
|
|
|
|
dhcpV6Config = {
|
|
|
|
RapidCommit = true;
|
|
|
|
ForceDHCPv6PDOtherInformation = true;
|
|
|
|
PrefixDelegationHint = "::/56";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
"${iface.upstream.link}".networkConfig = {
|
|
|
|
ConfigureWithoutCarrier = true;
|
|
|
|
LinkLocalAddressing = "no";
|
|
|
|
};
|
|
|
|
}) {} (builtins.attrNames pppoeInterfaces);
|
|
|
|
|
|
|
|
# TODO: needed?
|
|
|
|
networking.nat.extraCommands = ''
|
|
|
|
iptables -A FORWARD \
|
|
|
|
-p tcp --tcp-flags SYN,RST SYN \
|
|
|
|
-j TCPMSS --clamp-mss-to-pmtu
|
|
|
|
'';
|
|
|
|
|
2021-05-31 00:06:56 +02:00
|
|
|
}
|