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;
10 services.shorewall = {
14 ${builtins.readFile "${shorewall.package}/etc/shorewall/shorewall.conf"}
22 # DOC: shorewall-zones(5)
24 '' + unlines (lib.mapAttrsToList (zone: _: "${zone} ipv4") zones4);
26 # DOC: shorewall-interfaces(5)
28 '' + unlines (lib.mapAttrsToList (zone: {iface, ...}:
29 "${zone} ${iface} arp_filter,nosmurfs,routefilter,tcpflags") zones4);
31 # DOC: shorewall-policy(5)
33 '' + unlines (lib.mapAttrsToList (zone: _:
34 "${zone} all DROP none") zones4)
36 # XXX: the following policy must be last
40 # DOC: shorewall-rules(5)
46 + lib.optionalString (hasAttr "lan" zones4) ''
50 ACCEPT $FW lan:${config.networking.zones.lan.ipv4}/24
55 ACCEPT lan:${config.networking.zones.lan.ipv4}/24 $FW
57 + lib.optionalString (hasAttr "net" zones4) ''
82 #HTTPS(ACCEPT) net $FW
91 #ACTION SOURCE DEST PROTO DEST SOURCE RATE USER/
92 # PORT(S) PORT(S) LIMIT GROUP
97 services.shorewall6 = {
100 "shorewall6.conf" = ''
101 ${builtins.readFile "${shorewall6.package}/etc/shorewall6/shorewall6.conf"}
109 # DOC: shorewall-zones(5)
111 '' + unlines (lib.mapAttrsToList (zone: _: "${zone} ipv6") zones6);
113 # DOC: shorewall-interfaces(5)
115 '' + unlines (lib.mapAttrsToList (zone: {iface, ...}:
116 "${zone} ${iface} nosmurfs,tcpflags") zones6);
118 # DOC: shorewall-policy(5)
120 '' + unlines (lib.mapAttrsToList (zone: _:
121 "${zone} all DROP none") zones6)
123 # XXX: the following policy must be last
127 # DOC: shorewall-rules(5)
133 + lib.optionalString (hasAttr "lan" zones6) ''
137 Ping(ACCEPT) $FW lan:fe80::/10
142 Ping(ACCEPT) lan:fe80::/10 $FW