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 net enp1s0 arp_filter,nosmurfs,routefilter,tcpflags
35 maint enp2s0 arp_filter,nosmurfs,routefilter,tcpflags,dhcp
36 unused enp3s0 arp_filter,nosmurfs,routefilter,tcpflags
38 /* + unlinesAttrs (zone: {iface, ...}:
39 "${zone} ${iface} arp_filter,nosmurfs,routefilter,tcpflags") zones4
42 # DOC: shorewall-policy(5)
44 '' + unlinesAttrs (zone: _: "${zone} all DROP none") zones4
47 # XXX: the following policy must be last
51 # DOC: shorewall-rules(5)
57 + lib.optionalString (hasAttr "lan" zones4) ''
61 ACCEPT $FW lan:${zones4.lan.ipv4}/24
66 ACCEPT lan:${zones4.lan.ipv4}/24 $FW
68 + lib.optionalString (hasAttr "net" zones4) ''
93 #HTTPS(ACCEPT) net $FW
104 services.shorewall6 = {
107 "shorewall6.conf" = ''
108 ${readFile "${shorewall6.package}/etc-example/shorewall6/shorewall6.conf"}
116 # DOC: shorewall-zones(5)
118 '' + unlinesAttrs (zone: _: "${zone} ipv6") zones6;
120 # DOC: shorewall-interfaces(5)
122 '' + unlinesAttrs (zone: {iface, ...}: "${zone} ${iface} nosmurfs,tcpflags") zones6;
124 # DOC: shorewall-policy(5)
126 '' + unlinesAttrs (zone: _: "${zone} all DROP none") zones6
129 # XXX: the following policy must be last
133 # DOC: shorewall-rules(5)
139 + lib.optionalString (hasAttr "lan" zones6) ''
143 Ping(ACCEPT) $FW lan:fe80::/10
148 Ping(ACCEPT) lan:fe80::/10 $FW
149 SSH(ACCEPT) lan:fe80::/10 $FW
150 Git(ACCEPT) lan:fe80::/10 $FW