1 {pkgs, lib, config, ...}:
2 let inherit (builtins) hasAttr;
3 inherit (config.services) shorewall shorewall6;
4 unlines = lib.concatStringsSep "\n";
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 ${builtins.readFile "${shorewall.package}/etc/shorewall/shorewall.conf"}
28 # DOC: shorewall-zones(5)
30 '' + unlines (lib.mapAttrsToList (zone: _: "${zone} ipv4") zones4);
32 # DOC: shorewall-interfaces(5)
34 '' + unlines (lib.mapAttrsToList (zone: {iface, ...}:
35 "${zone} ${iface} arp_filter,nosmurfs,routefilter,tcpflags") zones4);
37 # DOC: shorewall-policy(5)
39 '' + unlines (lib.mapAttrsToList (zone: _:
40 "${zone} all DROP none") zones4)
42 # XXX: the following policy must be last
46 # DOC: shorewall-rules(5)
52 + lib.optionalString (hasAttr "lan" zones4) ''
56 ACCEPT $FW lan:${zones4.lan.ipv4}/24
61 ACCEPT lan:${zones4.lan.ipv4}/24 $FW
63 + lib.optionalString (hasAttr "net" zones4) ''
88 #HTTPS(ACCEPT) net $FW
98 services.shorewall6 = {
101 "shorewall6.conf" = ''
102 ${builtins.readFile "${shorewall6.package}/etc/shorewall6/shorewall6.conf"}
110 # DOC: shorewall-zones(5)
112 '' + unlines (lib.mapAttrsToList (zone: _: "${zone} ipv6") zones6);
114 # DOC: shorewall-interfaces(5)
116 '' + unlines (lib.mapAttrsToList (zone: {iface, ...}:
117 "${zone} ${iface} nosmurfs,tcpflags") zones6);
119 # DOC: shorewall-policy(5)
121 '' + unlines (lib.mapAttrsToList (zone: _:
122 "${zone} all DROP none") zones6)
124 # XXX: the following policy must be last
128 # DOC: shorewall-rules(5)
134 + lib.optionalString (hasAttr "lan" zones6) ''
138 Ping(ACCEPT) $FW lan:fe80::/10
143 Ping(ACCEPT) lan:fe80::/10 $FW
144 SSH(ACCEPT) lan:fe80::/10 $FW
145 Git(ACCEPT) lan:fe80::/10 $FW