1 {pkgs, lib, config, ...}:
2 let inherit (builtins) hasAttr readFile;
3 inherit (pkgs.lib) unlinesAttrs;
4 inherit (config.services) shorewall shorewall6;
5 zones4 = config.networking.zones;
6 zones6 = config.networking.zones;
9 #ACTION SOURCE DEST PROTO DEST SOURCE RATE USER/
10 # PORT(S) PORT(S) LIMIT GROUP
16 services.shorewall = {
20 ${readFile "${shorewall.package}/etc-example/shorewall/shorewall.conf"}
28 # DOC: shorewall-zones(5)
30 '' + unlinesAttrs (zone: _: "${zone} ipv4") zones4;
32 # DOC: shorewall-interfaces(5)
34 '' + unlinesAttrs (zone: {iface, ...}:
35 "${zone} ${iface} arp_filter,nosmurfs,routefilter,tcpflags") zones4;
37 # DOC: shorewall-policy(5)
39 '' + unlinesAttrs (zone: _: "${zone} all DROP none") zones4
41 # XXX: the following policy must be last
45 # DOC: shorewall-rules(5)
51 + lib.optionalString (hasAttr "lan" zones4) ''
55 ACCEPT $FW lan:${zones4.lan.ipv4}/24
60 ACCEPT lan:${zones4.lan.ipv4}/24 $FW
62 + lib.optionalString (hasAttr "net" zones4) ''
87 #HTTPS(ACCEPT) net $FW
97 services.shorewall6 = {
100 "shorewall6.conf" = ''
101 ${readFile "${shorewall6.package}/etc-example/shorewall6/shorewall6.conf"}
109 # DOC: shorewall-zones(5)
111 '' + unlinesAttrs (zone: _: "${zone} ipv6") zones6;
113 # DOC: shorewall-interfaces(5)
115 '' + unlinesAttrs (zone: {iface, ...}: "${zone} ${iface} nosmurfs,tcpflags") zones6;
117 # DOC: shorewall-policy(5)
119 '' + unlinesAttrs (zone: _: "${zone} all DROP none") zones6
121 # XXX: the following policy must be last
125 # DOC: shorewall-rules(5)
131 + lib.optionalString (hasAttr "lan" zones6) ''
135 Ping(ACCEPT) $FW lan:fe80::/10
140 Ping(ACCEPT) lan:fe80::/10 $FW
141 SSH(ACCEPT) lan:fe80::/10 $FW
142 Git(ACCEPT) lan:fe80::/10 $FW