-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
385 lines (339 loc) · 15 KB
/
Makefile
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# See https://docs.opnsense.org/development/backend/templates.html
VENDOR := b4cksp4ce
APP := ip-forward
V2FLY_SERVICES := \
cisco \
dell \
discord \
facebook \
facebook-ads \
instagram \
instagram-ads \
intel \
intel-dev \
netflix \
notion \
openai \
qualcomm \
signal \
tailscale \
twitter \
x \
xai
-include local.conf.mk
WEB_SOURCES := \
share/antifilter-community.txt \
share/cloudflare-ips-v4 \
share/fz139-resolves.zip \
share/fz139-vigruzki.zip \
share/iana-tlds.txt \
share/public_suffix_list.dat \
share/tor-auth-dirs.inc \
share/tor-fallback-dirs.inc \
share/tor-microdesc \
share/v2fly-community.zip
SORT_U := LC_ALL=C sort --unique
.PHONY : all \
depends fetch build \
install \
install-mgmt \
install-unbound \
upgrade-unbound \
install-2tun \
up \
clean distclean \
deinstall
.PRECIOUS : $(WEB_SOURCES)
all : build
fetch : $(WEB_SOURCES)
build : fetch depends
install : build install-mgmt install-2tun
depends : \
/usr/local/bin/aggregate \
/usr/local/bin/jq \
/usr/local/bin/nping \
/bin/sh
up :
git pull --ff-only
clean :
git clean -dfx tmp var
distclean :
git clean -dfx -e local.conf.mk .
########################################################################
# Packages
/usr/local/bin/aggregate : /usr/local/etc/pkg/repos/ip-forward.conf
pkg install -y aggregate
/usr/local/bin/jq :
pkg install -y jq
/usr/local/bin/nping :
pkg install -y nmap
########################################################################
# Sources
share/iana-tlds.txt :
lib/dl https://data.iana.org/TLD/tlds-alpha-by-domain.txt $@
share/fz139-resolves.zip :
lib/dl https://github.com/fz139/blocked-domains-resolves/archive/refs/heads/main.zip $@
share/fz139-vigruzki.zip :
lib/dl https://github.com/fz139/vigruzki/archive/refs/heads/main.zip $@
share/public_suffix_list.dat :
lib/dl https://publicsuffix.org/list/public_suffix_list.dat $@
share/v2fly-community.zip :
lib/dl https://github.com/v2fly/domain-list-community/archive/refs/heads/master.zip $@
share/antifilter-community.txt :
lib/dl https://community.antifilter.download/list/domains.lst $@
share/tor-auth-dirs.inc :
lib/dl https://gitlab.torproject.org/tpo/core/tor/-/raw/main/src/app/config/auth_dirs.inc?inline=false $@
share/tor-fallback-dirs.inc :
lib/dl https://gitlab.torproject.org/tpo/core/tor/-/raw/main/src/app/config/fallback_dirs.inc?inline=false $@
share/tor-microdesc : share/tor-auth-dirs.inc
for endpoint in `sed -E '/^[[:space:]]+"[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[[:space:]]/ ! d; s,^[[:space:]]*",,; s,[[:space:]].*,,; s,:80,,' share/tor-auth-dirs.inc`; do \
lib/dl http://$${endpoint}/tor/status-vote/current/consensus-microdesc $@ && break; \
done
share/cloudflare-ips-v4 :
lib/dl https://www.cloudflare.com/ips-v4 $@
########################################################################
# IANA TLD list derivatives, see https://www.iana.org/domains/root/files
########################################################################
# @roscomnadzor's https://vigruzki.rkn.gov.ru derivatives
tmp/blocked-domains-resolves/rvzdata.json : share/fz139-resolves.zip
unzip -o -d tmp/ share/fz139-resolves.zip
touch -r tmp/blocked-domains-resolves/rvzdata.json share/fz139-resolves.zip
tmp/dump.json.gz : share/fz139-vigruzki.zip
unzip -p share/fz139-vigruzki.zip 'vigruzki-main/dump.xml.[0-9]*' \
| lib/vigruzki2js >tmp/dump.json
gzip -f tmp/dump.json
tmp/rvzdata.nxdomain : share/fz139-resolves.zip
unzip -p share/fz139-resolves.zip blocked-domains-resolves-main/rvzdata.json | jq -r '.list[] | select(.rc == "NXDOMAIN") | .d' | $(SORT_U) >$@
tmp/dns.fz139.gz : tmp/dump.json.gz share/iana-tlds.txt tmp/rvzdata.nxdomain share/public_suffix_list.dat
zcat tmp/dump.json.gz \
| jq -r '.domain[], .mask[]' \
| lib/sed-domain share/iana-tlds.txt \
| lib/grep-vFxf tmp/rvzdata.nxdomain \
| lib/psl-reg-domain share/public_suffix_list.dat \
| $(SORT_U) \
| gzip >$@
tmp/ipv4.fz139.gz : tmp/dump.json.gz
zcat tmp/dump.json.gz \
| jq -r '.ip4[], .net4[]' \
| $(SORT_U) --version-sort \
| gzip >$@
tmp/ipv6.fz139.gz : tmp/dump.json.gz
zcat tmp/dump.json.gz \
| jq -r '.ip6[], .net6[]' \
| $(SORT_U) --version-sort \
| gzip >$@
########################################################################
# v2fly, Project V derivatives
tmp/v2fly.includes :
echo $(V2FLY_SERVICES) | sed -E 's,[[:space:]]+,\n,g' | sed -E '/^$$/d; s/^/include:/' >$@
tmp/dns.v2fly.gz : share/v2fly-community.zip tmp/v2fly.includes share/iana-tlds.txt
unzip -p share/v2fly-community.zip `echo $(V2FLY_SERVICES) | sed -E 's,(^|[[:space:]]),&domain-list-community-master/data/,g'` \
| grep --invert-match --fixed-strings --line-regexp -f tmp/v2fly.includes \
| sed -E 's,^full:,,; s,[[:space:]]*[@#].*$$,,; /^[[:space:]]*$$/d' \
| lib/sed-domain share/iana-tlds.txt \
| gzip >$@
########################################################################
# Antifilter.Download, community edition derivatives
tmp/fz139-v2fly.regex : tmp/dns.v2fly.gz tmp/dns.fz139.gz
zcat tmp/dns.v2fly.gz tmp/dns.fz139.gz \
| sed -E 's,\.,\\.,g; s,^,\\(^\\|\\.\\),; s,$$,$$,' \
| $(SORT_U) >$@
tmp/antifilter-extra.txt : share/antifilter-community.txt tmp/fz139-v2fly.regex
rm -f tmp/fz139-v2fly.regex.*
split -d -l 10000 tmp/fz139-v2fly.regex tmp/fz139-v2fly.regex.
cp share/antifilter-community.txt tmp/antifilter-extra.txt
for fre in tmp/fz139-v2fly.regex.*; do \
grep --invert-match -f $${fre} tmp/antifilter-extra.txt >tmp/antifilter-extra.txt.next; \
rm -f $${fre}; \
mv tmp/antifilter-extra.txt.next tmp/antifilter-extra.txt; \
done
tmp/dns.antifilter.gz : tmp/antifilter-extra.txt share/public_suffix_list.dat
grep --invert-match -e '\.google\.com$$' tmp/antifilter-extra.txt \
| lib/psl-reg-domain share/public_suffix_list.dat \
| $(SORT_U) >tmp/dns.antifilter
grep -e '\.google\.com$$' tmp/antifilter-extra.txt >>tmp/dns.antifilter
gzip -f tmp/dns.antifilter
########################################################################
# Tor, The Onion Router network
tmp/ipv4.tor.gz : share/tor-auth-dirs.inc share/tor-fallback-dirs.inc share/tor-microdesc
sed -E '/^[[:space:]]+"[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[[:space:]]/ ! d; s,^[[:space:]]*",,; s,:.*,,' share/tor-auth-dirs.inc >tmp/ipv4.tor
sed -E '/^[[:space:]]+"[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+[[:space:]]/ ! d; s,^[[:space:]]*",,; s,[[:space:]].*,,' share/tor-fallback-dirs.inc >>tmp/ipv4.tor
awk '($$1 == "r") { print $$6 }' share/tor-microdesc >>tmp/ipv4.tor
gzip -f tmp/ipv4.tor
########################################################################
# Cloudflare. To ease ECH pain :-(
tmp/ipv4.cloudflare.gz : share/cloudflare-ips-v4
cp share/cloudflare-ips-v4 tmp/ipv4.cloudflare
gzip tmp/ipv4.cloudflare
########################################################################
# `build`
var/dns.gz : tmp/dns.fz139.gz tmp/dns.v2fly.gz tmp/dns.antifilter.gz share/iana-tlds.txt
zcat tmp/dns.fz139.gz tmp/dns.v2fly.gz tmp/dns.antifilter.gz \
| lib/sed-domain share/iana-tlds.txt \
| $(SORT_U) \
| gzip >$@
var/ipv4.gz : tmp/ipv4.fz139.gz tmp/ipv4.tor.gz tmp/ipv4.cloudflare.gz
zcat tmp/ipv4.fz139.gz tmp/ipv4.tor.gz tmp/ipv4.cloudflare.gz \
| lib/aggregate \
| $(SORT_U) --version-sort \
| gzip >$@
# It might be wrong for several reasons. Here is one of them: CNAMEs are chased by Unbound itself,
# asking the remote server for every name in the indirection chain.
var/unbound.opnsense.forward-to-dns2tun.conf.gz : var/dns.gz local.conf.mk
echo server: >var/unbound.opnsense.forward-to-dns2tun.conf
zcat var/dns.gz | sed 's/.*/ local-zone: "&." ipset/' >>var/unbound.opnsense.forward-to-dns2tun.conf
zcat var/dns.gz | sed 's/.*/forward-zone:\n name: "&."\n forward-addr: 127.4.5.1\n forward-no-cache: yes/' >>var/unbound.opnsense.forward-to-dns2tun.conf
gzip -f var/unbound.opnsense.forward-to-dns2tun.conf
var/unbound.rc.local-tlds-ipset.conf.gz : share/iana-tlds.txt
sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/; /^#/d; s/.*/local-zone: "&." ipset/' share/iana-tlds.txt \
| gzip >"$@"
build : var/unbound.opnsense.forward-to-dns2tun.conf.gz
build : var/unbound.rc.local-tlds-ipset.conf.gz
build : var/ipv4.gz
########################################################################
# `install-mgmt`
install-mgmt : \
/etc/cron.d/ip-forward-kludges \
/usr/local/etc/rc.syshook.d/monitor/25-wg-junk \
/usr/local/etc/rc.syshook.d/start/81-dpinger-kludge \
/usr/local/etc/rc.syshook.d/start/83-wg-kludge \
/usr/local/libexec/dpinger-kludge \
/usr/local/libexec/wg-kludge \
/usr/local/sbin/gw-status \
/usr/local/sbin/opnsense-api \
/usr/local/sbin/unbound-control-opnsense \
/usr/local/sbin/wg-junk
/etc/cron.d/ip-forward-kludges : share/cron /usr/local/libexec/wg-kludge /usr/local/libexec/dpinger-kludge
cp share/cron $@
/usr/local/etc/rc.syshook.d/monitor/25-wg-junk : bin/syshook-wg-junk /usr/local/sbin/wg-junk
cp bin/syshook-wg-junk $@
/usr/local/etc/rc.syshook.d/start/81-dpinger-kludge : bin/syshook-start-dpinger-kludge /usr/local/libexec/dpinger-kludge
cp bin/syshook-start-dpinger-kludge $@
/usr/local/etc/rc.syshook.d/start/83-wg-kludge : bin/syshook-start-wg-kludge /usr/local/libexec/wg-kludge
cp bin/syshook-start-wg-kludge $@
/usr/local/sbin/wg-junk : bin/wg-junk
cp bin/wg-junk $@
/usr/local/libexec/wg-kludge : bin/wg-kludge /usr/local/sbin/wg-junk
cp bin/wg-kludge $@
/usr/local/libexec/dpinger-kludge : bin/dpinger-kludge
cp bin/dpinger-kludge $@
/usr/local/sbin/gw-status : bin/gw-status
cp bin/gw-status $@
/usr/local/sbin/opnsense-api : bin/opnsense-api
cp bin/opnsense-api $@
/usr/local/sbin/unbound-control-opnsense : bin/unbound-control-opnsense
cp bin/unbound-control-opnsense $@
########################################################################
# `install-unbound`
install-unbound : \
/usr/local/etc/pkg/ip-forward.pub \
/usr/local/etc/pkg/repos/ip-forward.conf
pkg update
if ! pkg info unbound | grep -q 'IPSET\s*:\s*on\>'; then pkg upgrade -y --repository ip-forward unbound; fi
pkg lock -y unbound
upgrade-unbound :
pkg unlock -y unbound
pkg upgrade -y --repository ip-forward unbound
pkg lock -y unbound
/usr/local/etc/pkg/ip-forward.pub : share/pkg-ip-forward.pub
cp share/pkg-ip-forward.pub $@
/usr/local/etc/pkg/repos/ip-forward.conf : share/repos-ip-forward.conf /usr/local/etc/pkg/ip-forward.pub
cp share/repos-ip-forward.conf $@
########################################################################
# `install-vrrp`
install-vrrp : /boot/loader.conf \
/usr/local/etc/freevrrpd.conf \
/usr/local/etc/inc/system.inc \
/usr/local/etc/opnsense-beep.d/freevrrpd-master \
/usr/local/etc/rc.loader.d/25-freevrrpd \
/usr/local/etc/rc.syshook.d/start/90-freevrrpd \
/usr/local/etc/rc.syshook.d/stop/10-freevrrpd \
/usr/local/libexec/freevrrpd-backup \
/usr/local/libexec/freevrrpd-master \
/usr/local/sbin/freevrrpd \
/usr/local/sbin/opnsense-beep
VRRP_PRIORITY ?= 200 # not 255!
/boot/loader.conf : /usr/local/etc/rc.loader.d/25-freevrrpd
/usr/local/etc/rc.loader
/usr/local/etc/freevrrpd.conf : /usr/local/libexec/freevrrpd-backup /usr/local/libexec/freevrrpd-master share/freevrrpd.conf
sprg=`configctl interface address | jq -r '[.wan[] | select(.family == "inet")] | first | ("s/@@device@@/" + .device + "/; s/@@address@@/" + ((.address / ".")[0:3] | join(".")) + ".7/")'`; \
sed -E -e "$$sprg" -e "s/@@priority@@/$(VRRP_PRIORITY)/" <share/freevrrpd.conf >$@
/usr/local/etc/inc/system.inc : Makefile share/system.inc.patch
if grep -qF "'/sbin/kldload" $@; then patch -d / -p1 <share/system.inc.patch; fi
/usr/local/etc/opnsense-beep.d/freevrrpd-master : share/opnsense-beep.freevrrpd-master
cp share/opnsense-beep.freevrrpd-master $@
/usr/local/etc/rc.loader.d/25-freevrrpd : share/loader.freevrrpd
cp share/loader.freevrrpd $@
/usr/local/etc/rc.syshook.d/start/90-freevrrpd : bin/syshook-freevrrpd-start
cp bin/syshook-freevrrpd-start $@
/usr/local/etc/rc.syshook.d/stop/10-freevrrpd : bin/syshook-freevrrpd-stop
cp bin/syshook-freevrrpd-stop $@
/usr/local/libexec/freevrrpd-backup : bin/freevrrpd-backup
cp bin/freevrrpd-backup $@
/usr/local/libexec/freevrrpd-master : bin/freevrrpd-master /usr/local/etc/opnsense-beep.d/freevrrpd-master /usr/local/sbin/opnsense-beep
cp bin/freevrrpd-master $@
/usr/local/sbin/freevrrpd : /usr/local/etc/pkg/repos/ip-forward.conf
pkg install -y freevrrpd
/usr/local/sbin/opnsense-beep : share/opnsense-beep.patch
if ! grep -qF 'flock' $@; then patch -d / -p1 <share/opnsense-beep.patch; fi
########################################################################
# `install-2tun`
# /usr/local/opnsense/service/templates/$(VENDOR)/$(APP)/ can't handle large
# configuration file and OOMs. So, here is the hack.
install-2tun : build \
install-unbound \
/usr/local/sbin/unbound-control-dns2tun \
/usr/local/etc/rc.syshook.d/monitor/25-dns2tun \
/usr/local/etc/rc.syshook.d/start/85-dns2tun \
/usr/local/etc/rc.syshook.d/early/50-ip2tun \
/var/db/aliastables/ip2tun.gz \
/var/run/unbound-dns2tun.pid
make -j1 /var/run/unbound.pid
/usr/local/etc/rc.syshook.d/early/50-ip2tun
/usr/local/etc/rc.syshook.d/monitor/25-dns2tun : bin/syshook-dns2tun /usr/local/sbin/unbound-control-dns2tun
cp bin/syshook-dns2tun $@
/usr/local/etc/rc.syshook.d/start/85-dns2tun : bin/syshook-start-dns2tun
cp bin/syshook-start-dns2tun $@
/usr/local/sbin/unbound-control-dns2tun : bin/unbound-control-dns2tun
cp bin/unbound-control-dns2tun $@
/usr/local/etc/unbound/dns2tun.conf : share/unbound-dns2tun.conf
cp share/unbound-dns2tun.conf $@
/usr/local/etc/unbound/local-tlds-ipset.conf : var/unbound.rc.local-tlds-ipset.conf.gz
cp var/unbound.rc.local-tlds-ipset.conf.gz [email protected]
rm -f $@
gunzip [email protected]
/etc/rc.conf.d/unbound : share/unbound.rc
cp share/unbound.rc $@
/usr/local/etc/unbound/dns2tun/unbound_server.pem :
mkdir -p /usr/local/etc/unbound/dns2tun
unbound-control-setup -d /usr/local/etc/unbound/dns2tun
/var/run/unbound-dns2tun.pid : \
/etc/rc.conf.d/unbound \
/usr/local/etc/unbound/dns2tun.conf \
/usr/local/etc/unbound/dns2tun/unbound_server.pem \
/usr/local/etc/unbound/local-tlds-ipset.conf
service unbound restart
/usr/local/etc/rc.syshook.d/monitor/25-dns2tun
/usr/local/etc/unbound.opnsense.d/enable-dns2tun.conf : share/unbound.opnsense.enable-dns2tun.conf
cp share/unbound.opnsense.enable-dns2tun.conf $@
/usr/local/etc/unbound.opnsense.d/forward-to-dns2tun.conf : var/unbound.opnsense.forward-to-dns2tun.conf.gz
cp var/unbound.opnsense.forward-to-dns2tun.conf.gz [email protected]
rm -f $@
gunzip [email protected]
/var/run/unbound.pid : \
/usr/local/etc/unbound.opnsense.d/enable-dns2tun.conf \
/usr/local/etc/unbound.opnsense.d/forward-to-dns2tun.conf
pluginctl -s unbound restart
/usr/local/etc/rc.syshook.d/early/50-ip2tun : share/ip2tun
cp share/ip2tun $@
chmod 755 $@
/var/db/aliastables/ip2tun.gz : var/ipv4.gz
cp var/ipv4.gz $@
########################################################################
# `deinstall`
deinstall :
rm -f /usr/local/etc/unbound.opnsense.d/forward-to-dns2tun.conf
pluginctl -s unbound restart
service unbound stop
rm -f /usr/local/etc/unbound/dns2tun.conf /usr/local/etc/unbound/local-tlds-ipset.conf /etc/rc.conf.d/unbound
rm -f /var/db/aliastables/ip2tun.gz /usr/local/etc/rc.syshook.d/early/50-ip2tun