1 { pkgs, lib, config, machines, ... }:
3 inherit (builtins) hasAttr readFile;
4 inherit (pkgs.lib) unlinesAttrs;
5 inherit (config.users) users groups;
8 networking.firewall.enable = false;
9 security.lockKernelModules = false;
10 systemd.services.disable-kernel-module-loading.after = [ "nftables.service" ];
11 # echo -e "$(nix eval machines.losurdo.config.networking.nftables.ruleset)"
13 systemd.services.nftables.serviceConfig.TimeoutStartSec = "20";
14 networking.nftables = {
16 ruleset = lib.mkBefore ''
19 #udp dport mdns ip6 daddr ff02::fb counter accept comment "Accept mDNS"
20 #udp dport mdns ip daddr 224.0.0.251 counter accept comment "Accept mDNS"
22 # Some .nix append rules here with: add rule inet filter net2fw ...
25 ip daddr ${machines.losurdo.extraArgs.ipv4} counter accept comment "losurdo"
26 ip daddr ${machines.mermet.extraArgs.ipv4} counter accept comment "mermet"
27 ip daddr 224.0.0.0/4 udp dport 1900 counter accept comment "UPnP"
28 tcp dport {80,443} counter accept comment "HTTP"
29 udp dport 123 skuid ${users.systemd-timesync.name} counter accept comment "NTP"
30 tcp dport 9418 counter accept comment "Git"
32 # Some .nix append rules here with: add rule inet filter fw2net ...
35 # Some .nix append rules here with: add rule inet filter intra2fw ...
38 # Some .nix append rules here with: add rule inet filter fw2intra ...
41 # Some .nix append rules here with: add rule inet filter fwd-intra ...
45 type filter hook input priority 0
51 ip protocol icmp icmp type echo-request limit rate over 10/second burst 4 packets log level warn prefix "net2fw: ping flood: " counter drop
52 ip6 nexthdr icmpv6 icmpv6 type echo-request limit rate over 10/second burst 4 packets log level warn prefix "net2fw: ping flood: " counter drop
54 # accept traffic already established
55 ct state {established, related} accept
59 tcp dport 22 counter accept comment "SSH"
60 udp dport 60000-61000 counter accept comment "Mosh"
63 ip protocol icmp icmp type { echo-request, destination-unreachable, router-solicitation, router-advertisement, time-exceeded, parameter-problem } counter accept
65 ip6 nexthdr icmpv6 icmpv6 type echo-request counter accept
66 ip6 nexthdr icmpv6 icmpv6 type nd-neighbor-solicit counter accept
67 ip6 nexthdr icmpv6 icmpv6 type nd-neighbor-advert counter accept
68 ip6 nexthdr icmpv6 icmpv6 type nd-router-solicit counter accept
69 ip6 nexthdr icmpv6 icmpv6 type nd-router-advert counter accept
70 ip6 nexthdr icmpv6 icmpv6 type mld-listener-query counter accept
71 ip6 nexthdr icmpv6 icmpv6 type mld-listener-report counter accept
72 ip6 nexthdr icmpv6 icmpv6 type mld-listener-reduction counter accept
73 ip6 nexthdr icmpv6 icmpv6 type destination-unreachable counter accept
74 ip6 nexthdr icmpv6 icmpv6 type packet-too-big counter accept
75 ip6 nexthdr icmpv6 icmpv6 type time-exceeded counter accept
76 ip6 nexthdr icmpv6 icmpv6 type parameter-problem counter accept
77 ip6 nexthdr icmpv6 icmpv6 type ind-neighbor-solicit counter accept
78 ip6 nexthdr icmpv6 icmpv6 type ind-neighbor-advert counter accept
79 ip6 nexthdr icmpv6 icmpv6 type mld2-listener-report counter accept
80 ip6 nexthdr icmpv6 log level info prefix "net2fw: icmpv6: " counter accept
81 #ip6 nexthdr icmpv6 icmpv6 type { echo-request, nd-neighbor-solicit, nd-neighbor-advert, nd-router-solicit, nd-router-advert, mld-listener-query, mld-listener-report, mld-listener-reduction, destination-unreachable, packet-too-big, time-exceeded, parameter-problem, ind-neighbor-solicit, ind-neighbor-advert, mld2-listener-report } counter accept
83 # Some .nix append gotos here with: add rule inet filter input iffname ... goto ...
86 type filter hook output priority 0
91 ct state {related,established} accept
95 ip protocol icmp counter accept
96 ip6 nexthdr icmpv6 counter accept
98 tcp dport 22 counter accept comment "SSH"
100 # Some .nix append gotos here with: add rule inet filter output oifname ... goto ...
103 type filter hook forward priority 0