-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwan.nix
111 lines (102 loc) · 2.89 KB
/
wan.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
{ config, lib, ... }:
let
inherit (lib)
filter
mkIf
mkMerge
optionals
splitString
;
bogonNetworks = filter (s: s != "") (splitString "\n" (builtins.readFile ./bogon-networks.txt));
heCfg = config.router.heTunnelBroker;
wan6IsHurricaneElectric = heCfg.enable;
commonDHCP = {
UseDNS = false;
UseHostname = false;
};
wan = {
name = config.router.wanInterface;
DHCP = if wan6IsHurricaneElectric || !config.router.wanSupportsDHCPv6 then "ipv4" else "yes";
networkConfig = mkMerge [
{
LinkLocalAddressing = if config.router.wanSupportsDHCPv6 then "yes" else "no";
IPv6AcceptRA = if config.router.wanSupportsDHCPv6 then "yes" else "no";
# We use our own DNS config in this module, no need to accept search
# domain from ISP. This causes UseDomains=no to be set for all client
# protocols (DHCPv4, DHCPv6, IPv6RA, etc).
UseDomains = false;
}
(mkIf wan6IsHurricaneElectric {
Tunnel = config.systemd.network.netdevs."10-hurricane".netdevConfig.Name;
})
];
dhcpV4Config = mkMerge [
commonDHCP
(mkIf (config.time.timeZone != null) { UseTimezone = false; })
];
dhcpV6Config = (
mkIf config.router.wanSupportsDHCPv6 (mkMerge [
commonDHCP
{
PrefixDelegationHint = "::/${toString config.router.wan6PrefixHint}";
}
])
);
ipv6AcceptRAConfig = {
UseDNS = false;
};
linkConfig = {
RequiredForOnline = true;
RequiredFamilyForOnline =
if (wan6IsHurricaneElectric || !config.router.wanSupportsDHCPv6) then "ipv4" else "any";
};
routes = mkIf config.router.blockBogonNetworks (
map (Destination: {
inherit Destination;
Type = "unreachable";
}) bogonNetworks
);
};
hurricane = {
inherit (heCfg) name;
networkConfig = {
Address = heCfg.clientIPv6Address;
Gateway = heCfg.serverIPv6Address;
};
linkConfig.RequiredFamilyForOnline = "ipv6";
routes = mkIf config.router.blockBogonNetworks (
map (Destination: {
inherit Destination;
Type = "unreachable";
}) bogonNetworks
);
};
hurricaneNetdev = {
tunnelConfig.Remote = heCfg.serverIPv4Address;
netdevConfig = {
Name = heCfg.name;
Kind = "sit";
MTUBytes = toString heCfg.mtu;
};
tunnelConfig = {
Local = "any";
TTL = 255;
};
};
in
{
config = mkIf config.router.enable {
services.avahi.denyInterfaces =
[
config.systemd.network.networks."10-wan".name
]
++ optionals wan6IsHurricaneElectric [
config.systemd.network.networks."10-hurricane".name
];
systemd.network.networks = {
"10-wan" = wan;
"10-hurricane" = mkIf wan6IsHurricaneElectric hurricane;
};
systemd.network.netdevs."10-hurricane" = mkIf wan6IsHurricaneElectric hurricaneNetdev;
};
}