summaryrefslogtreecommitdiff
path: root/hosts/surtr/vpn/ruleset.nft
blob: 3cdb7a8a07f7dd4aa7549f6055da5f9c505bf786 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
define icmp_protos = {ipv6-icmp, icmp, igmp}

table arp filter {
  limit lim_arp {
    rate over 50 mbytes/second burst 50 mbytes
  }

  counter arp-rx {}
  counter arp-tx {}

  counter arp-ratelimit-rx {}
  counter arp-ratelimit-tx {}

  chain input {
    type filter hook input priority filter
    policy accept

    limit name lim_arp counter name arp-ratelimit-rx drop

    counter name arp-rx
  }

  chain output {
    type filter hook output priority filter
    policy accept

    limit name lim_arp counter name arp-ratelimit-tx drop

    counter name arp-tx
  }
}

table inet filter {
  limit lim_reject {
    rate over 1000/second burst 1000 packets
  }

  limit lim_icmp {
    rate over 50 mbytes/second burst 50 mbytes
  }

  counter invalid-fw {}
  counter fw-lo {}
  counter fw-vpn {}
  counter fw-upstream {}

  counter icmp-ratelimit-upstream-fw {}
  counter icmp-ratelimit-vpn-fw {}
  counter icmp-ratelimit-established-fw {}

  counter icmp-upstream-fw {}
  counter icmp-vpn-fw {}
  counter icmp-established-fw {}

  counter reject-ratelimit-fw {}
  counter reject-fw {}
  counter reject-tcp-fw {}
  counter reject-icmp-fw {}

  counter drop-fw {}

  counter invalid-rx {}

  counter rx-lo {}
  counter invalid-local4-rx {}
  counter invalid-local6-rx {}

  counter icmp-ratelimit-rx {}
  counter icmp-rx {}

  counter wg-rx {}

  counter established-rx {}

  counter reject-ratelimit-rx {}
  counter reject-rx {}
  counter reject-tcp-rx {}
  counter reject-icmp-rx {}

  counter drop-rx {}

  counter tx-lo {}

  counter icmp-ratelimit-tx {}
  counter icmp-tx {}

  counter wg-tx {}

  counter tx {}

  chain forward {
    type filter hook forward priority filter
    policy drop


    ct state invalid log level debug prefix "vpn: drop invalid forward: " counter name invalid-fw drop


    iifname lo counter name fw-lo accept

    meta l4proto $icmp_protos iifname upstream limit name lim_icmp counter name icmp-ratelimit-upstream-fw drop
    meta l4proto $icmp_protos iifname upstream counter name icmp-upstream-fw accept
    meta l4proto $icmp_protos iifname vpn limit name lim_icmp counter name icmp-ratelimit-vpn-fw drop
    meta l4proto $icmp_protos iifname vpn counter name icmp-vpn-fw accept
    meta l4proto $icmp_protos ct state {established, related} limit name lim_icmp counter name icmp-ratelimit-established-fw drop
    meta l4proto $icmp_protos ct state {established, related} counter name icmp-established-fw accept


    iifname upstream oifname vpn ct state {established, related} counter name fw-vpn accept
    iifname vpn oifname upstream counter name fw-upstream accept


    limit name lim_reject log level debug prefix "vpn: drop forward: " counter name reject-ratelimit-fw drop
    log level debug prefix "vpn: reject forward: " counter name reject-fw
    meta l4proto tcp ct state new counter name reject-tcp-fw reject with tcp reset
    ct state new counter name reject-icmp-fw reject


    counter name drop-fw
  }

  chain input {
    type filter hook input priority filter
    policy drop


    ct state invalid log level debug prefix "vpn: drop invalid input: " counter name invalid-rx drop
    

    iifname lo counter name rx-lo accept
    iif != lo ip daddr 127.0.0.1/8 counter name invalid-local4-rx reject
    iif != lo ip6 daddr ::1/128 counter name invalid-local6-rx reject

    meta l4proto $icmp_protos limit name lim_icmp counter name icmp-ratelimit-rx drop
    meta l4proto $icmp_protos counter name icmp-rx accept

    udp dport 51820 counter name wg-rx accept

    ct state {established, related} counter name established-rx accept


    limit name lim_reject log level debug prefix "vpn: drop input: " counter name reject-ratelimit-rx drop
    log level debug prefix "vpn: reject input: " counter name reject-rx
    meta l4proto tcp ct state new counter name reject-tcp-rx reject with tcp reset
    ct state new counter name reject-icmp-rx reject


    counter name drop-rx
  }

  chain output {
    type filter hook output priority filter
    policy accept


    oifname lo counter name tx-lo accept

    meta l4proto $icmp_protos limit name lim_icmp counter name icmp-ratelimit-tx drop
    meta l4proto $icmp_protos counter name icmp-tx accept


    udp sport 51820 counter name wg-tx
    

    counter name tx
  }
}

table inet nat {
  counter nat {}
  
  chain postrouting {
    type nat hook postrouting priority srcnat
    policy accept

    iifname vpn counter name nat masquerade
  }
}

table ip mss_clamp {
  counter mss-clamp {}

  chain postrouting {
    type filter hook postrouting priority mangle
    policy accept

    iifname vpn oifname upstream tcp flags & (syn|rst) == syn counter name mss-clamp tcp option maxseg size set rt mtu
  }
}