-
Notifications
You must be signed in to change notification settings - Fork 0
/
rc.firewall
945 lines (939 loc) · 30.4 KB
/
rc.firewall
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
#!/bin/sh
# Suck in the configuration variables.
if [ -z "${source_rc_confs_defined}" ]; then
if [ -r /etc/defaults/rc.conf ]; then
. /etc/defaults/rc.conf
source_rc_confs
elif [ -r /etc/rc.conf ]; then
. /etc/rc.conf
fi
fi
. /etc/rc.subr
. /etc/network.subr
if [ -n "${1}" ]; then
firewall_type="${1}"
fi
if [ -z "${firewall_rc_config_load}" ]; then
load_rc_config ipfw
else
for i in ${firewall_rc_config_load}; do
load_rc_config $i
done
fi
afexists inet6
ipv6_available=$?
. /etc/rc.firewall.definitions
. /etc/rc.firewall.config
if [ x"${IPFW_LANS6}" == x"" ]; then
IPFW_LANS6=${IPFW_LANS}
fi
if [ x"${IPFW_WANS6}" == x"" ]; then
IPFW_WANS6=${IPFW_WANS}
fi
if [ x"${IPFW_LANS6_list}" == x"" ]; then
IPFW_LANS6_list=${IPFW_LANS_list}
fi
if [ x"${IPFW_WANS6_list}" == x"" ]; then
IPFW_WANS6_list=${IPFW_WANS_list}
fi
${fwcmd} -f flush > /dev/null 2> /dev/null
${fwcmd} set enable 0
if [ ${IPFW_multiwan} -eq 1 ]; then
for i in ${IPFW_WANS_list}; do
j="IPFW_oip${i}"
eval j="\$${j}"
if [ -n "${j}" ]; then
${fwcmd} set disable ${i} # WAN is online
else
${fwcmd} set enable ${i} # WAN is offline
fi
done
fi
prepare_tables
########################
### Loopback
########################
${fwcmd} add 1 ${IPFW_allow} all from any to any via lo0
${fwcmd} add ${IPFW_denylog} all from any to 127.0.0.0/8
${fwcmd} add ${IPFW_denylog} ip from 127.0.0.0/8 to any
if [ x"$ipv6_available" == x"0" ]; then
if [ x"$IPFW_LAN_6" == x"1" -o x"$IPFW_WAN_6" == x"1" ]; then
${fwcmd} add ${IPFW_denylog} all from any to ::1/128
${fwcmd} add ${IPFW_denylog} all from ::1/128 to any
fi
fi
########################
### Traffic identification
########################
${fwcmd} add skipto 1000 ip4 from any to any out
${fwcmd} add skipto 3000 ip4 from any to any in
if [ x"$ipv6_available" == x"0" ]; then
if [ x"$IPFW_LAN_6" == x"1" -o x"$IPFW_WAN_6" == x"1" ]; then
${fwcmd} add skipto 5000 ip6 from any to any out
${fwcmd} add skipto 7000 ip6 from any to any in
fi
fi
for i in ${IPFW_WANS_list}; do
j="IPFW_oip${i}"
eval j="\$${j}"
if [ -n "${j}" ]; then
j="IPFW_nat${i}"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_oif${i}"
eval k="\$${k}"
${fwcmd} nat ${i} config if ${k} ${j}
fi
fi
done
${fwcmd} add 999 skipto 65500 log all from any to any
########################
########################
# IPv4 Out
y=1000
for i in ${IPFW_LANS_list}; do
j="IPFW_iip${i}"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_iif${i}"
eval k="\$${k}"
l="IPFW_inet${i}"
eval l="\$${l}"
x=$(( 20000 + ( ( ${i} - 1 ) * 10 ) ))
${fwcmd} add ${y} skipto ${x} ip4 from ${j} to any via ${k} out
${fwcmd} add skipto ${x} ip4 from any to ${l} via ${k} out
${fwcmd} add skipto ${x} ip4 from any to 255.255.255.255 via ${k} out
fi
y=$(( ${y} + 5 )) # 5 rules max.
done
y=1100
for i in ${IPFW_WANS_list}; do
j="IPFW_oip${i}"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_oif${i}"
eval k="\$${k}"
x=$(( 45000 + ( ( ${i} - 1 ) * 10 ) ))
${fwcmd} add ${y} skipto ${x} ip4 from ${j} to any via ${k} out
for ii in ${IPFW_LANS_list}; do
jj="IPFW_iip${ii}"
eval jj="\$${jj}"
if [ -n "${jj}" ]; then
kk="IPFW_inet${ii}"
eval kk="\$${kk}"
${fwcmd} add skipto ${x} ip4 from ${kk} to any via ${k} out
fi
done
${fwcmd} add skipto ${x} ip4 from any to 255.255.255.255 via ${k} out
fi
y=$(( ${y} + 25 ))
done
y=1600
for i in ${IPFW_LANS_list}; do
j="IPFW_iip${i}"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_iif${i}"
eval k="\$${k}"
x=$(( 20000 + ( ( ${i} - 1 ) * 10 ) ))
${fwcmd} add ${y} skipto ${x} log ip4 from any to any via ${k} out
fi
y=$(( ${y} + 5 )) # 5 rules max.
done
y=1700
for i in ${IPFW_WANS_list}; do
j="IPFW_oip${i}"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_oif${i}"
eval k="\$${k}"
x=$(( 45000 + ( ( ${i} - 1 ) * 10 ) ))
for ii in ${IPFW_WANS_list}; do
if [ ! x"${j}" == x"${jj}" ]; then
jj="IPFW_oip${ii}"
eval jj="\$${jj}"
if [ -n "${jj}" ]; then
${fwcmd} add ${y} skipto ${x} ip4 from ${jj} to any via ${k} out
y=$(( ${y} + 1 ))
fi
fi
done
${fwcmd} add ${y} skipto ${x} log ip4 from any to any via ${k} out
y=$(( ${y} + 1 ))
fi
done
# IPv4 In
y=3000
for i in ${IPFW_LANS_list}; do
j="IPFW_iip${i}"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_iif${i}"
eval k="\$${k}"
l="IPFW_inet${i}"
eval l="\$${l}"
x=$(( 25000 + ( ( ${i} - 1 ) * 10 ) ))
${fwcmd} add ${y} skipto ${x} ip4 from any to ${j} via ${k} in
${fwcmd} add skipto ${x} ip4 from ${l} to any via ${k} in
${fwcmd} add skipto ${x} ip4 from any to 255.255.255.255 via ${k} in
fi
y=$(( ${y} + 5 )) # 5 rules max.
done
y=3100
for i in ${IPFW_WANS_list}; do
j="IPFW_oip${i}"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_oif${i}"
eval k="\$${k}"
l=$(( ${i} * 2 ))
x=$(( 40000 + ( ( ${i} - 1 ) * 10 ) ))
${fwcmd} add ${y} skipto ${x} ip4 from any to ${j} via ${k} in
for ii in ${IPFW_LANS_list}; do
jj="IPFW_iip${ii}"
eval jj="\$${jj}"
if [ -n "${jj}" ]; then
kk="IPFW_inet${ii}"
eval kk="\$${kk}"
${fwcmd} add skipto ${x} ip4 from any to ${kk} via ${k} in
fi
done
if [ x"${IPFW_DHCP}" == x"1" ]; then
${fwcmd} add skipto ${x} ip4 from 0.0.0.0 to 255.255.255.255 via ${k} in
fi
${fwcmd} add ${IPFW_deny} ip4 from any to 255.255.255.255 via ${k} in
fi
y=$(( ${y} + 25 ))
done
y=3600
for i in ${IPFW_LANS_list}; do
j="IPFW_iip${i}"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_iif${i}"
eval k="\$${k}"
x=$(( 25000 + ( ( ${i} - 1 ) * 10 ) ))
${fwcmd} add ${y} skipto ${x} log ip4 from any to any via ${k} in
fi
y=$(( ${y} + 5 )) # max. 5 rules
done
y=3700
for i in ${IPFW_WANS_list}; do
j="IPFW_oip${i}"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_oif${i}"
eval k="\$${k}"
x=$(( 40000 + ( ( ${i} - 1 ) * 10 ) ))
${fwcmd} add ${y} ${IPFW_deny} igmp from any to any via ${k} in
${fwcmd} add skipto ${x} log ip4 from any to any via ${k} in
fi
y=$(( ${y} + 5 )) # max. 5 rules
done
if [ x"$ipv6_available" == x"0" ]; then
# IPv6 Out
y=5000
for i in ${IPFW_LANS6_list}; do
j="IPFW_iip${i}_6"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_iif${i}"
eval k="\$${k}"
l="IPFW_inet${i}_6"
eval l="\$${l}"
x=$(( 10000 + ( ( ${i} - 1 ) * 10 ) ))
${fwcmd} add ${y} skipto ${x} ip6 from ${j} to any via ${k} out
${fwcmd} add skipto ${x} ip6 from any to ${l} via ${k} out
${fwcmd} add skipto ${x} ip6 from fe80::/10 546,547 to fe80::/10 546,547 via ${k} out
${fwcmd} add skipto ${x} ip6 from fe80::/10 521,546,547 to ff02::/16 521,546,547 via ${k} out
${fwcmd} add ${IPFW_deny} ip6 from fe80::/10 to ff02::/16 5355 via ${k} out
${fwcmd} add skipto ${x} ip6 from fe80::/10 to any via ${k} out
${fwcmd} add skipto ${x} ipv6-icmp from ::/128 to ff02::/16 via ${k} out
${fwcmd} add skipto ${x} ipv6-icmp from fe80::/10 to fe80::/10 via ${k} out
${fwcmd} add skipto ${x} ipv6-icmp from fe80::/10 to ff02::/16 via ${k} out
${fwcmd} add skipto ${x} ipv6-icmp from any to any icmp6types 1,2,128,129,135,136 via ${k} out
fi
y=$(( ${y} + 20 )) # 20 rules max.
done
y=5400
for i in ${IPFW_WANS6_list}; do
j="IPFW_oip${i}_6"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_oif${i}"
eval k="\$${k}"
x=$(( 35000 + ( ( ${i} - 1 ) * 10 ) ))
${fwcmd} add ${y} skipto ${x} ip6 from ${j} to any via ${k} out
for ii in ${IPFW_LANS6_list}; do
jj="IPFW_iip${ii}_6"
eval jj="\$${jj}"
if [ -n "${jj}" ]; then
kk="IPFW_inet${i}_6"
eval kk="\$${kk}"
${fwcmd} add skipto ${x} ip6 from ${kk} to any via ${k} out
fi
done
${fwcmd} add skipto ${x} ip6 from fe80::/10 546,547 to fe80::/10 546,547 via ${k} out
${fwcmd} add skipto ${x} ip6 from fe80::/10 521,546,547 to ff02::/16 521,546,547 via ${k} out
${fwcmd} add ${IPFW_deny} ip6 from fe80::/10 to ff02::/16 5355 via ${k} out
${fwcmd} add skipto ${x} ip6 from fe80::/10 to any via ${k} out
${fwcmd} add skipto ${x} ipv6-icmp from ::/128 to ff02::/16 via ${k} out
${fwcmd} add skipto ${x} ipv6-icmp from fe80::/10 to fe80::/10 via ${k} out
${fwcmd} add skipto ${x} ipv6-icmp from fe80::/10 to ff02::/16 via ${k} out
${fwcmd} add skipto ${x} ipv6-icmp from any to any icmp6types 1,2,128,129,135,136 via ${k} out
fi
y=$(( ${y} + 40 )) # 40 rules max.
done
y=6200
for i in ${IPFW_LANS6_list}; do
j="IPFW_iip${i}_6"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_iif${i}"
eval k="\$${k}"
x=$(( 10000 + ( ( ${i} - 1 ) * 10 ) ))
${fwcmd} add ${y} skipto ${x} log ip6 from any to any via ${k} out
${fwcmd} add skipto ${x} log ipv6-icmp from any to any via ${k} out
fi
y=$(( ${y} + 5 )) # 5 rules max.
done
y=6300
for i in ${IPFW_WANS6_list}; do
j="IPFW_oip${i}_6"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_oif${i}"
eval k="\$${k}"
x=$(( 35000 + ( ( ${i} - 1 ) * 10 ) ))
${fwcmd} add ${y} skipto ${x} log ip6 from any to any via ${k} out
${fwcmd} add skipto ${x} log ipv6-icmp from any to any via ${k} out
fi
y=$(( ${y} + 5 )) # 5 rules max.
done
# IPv6 In
y=7000
for i in ${IPFW_LANS6_list}; do
j="IPFW_iip${i}_6"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_iif${i}"
eval k="\$${k}"
l="IPFW_inet${i}_6"
eval l="\$${l}"
x=$(( 15000 + ( ( ${i} - 1 ) * 10 ) ))
${fwcmd} add ${y} skipto ${x} ip6 from any to ${j} via ${k} in
${fwcmd} add skipto ${x} ip6 from ${l} to any via ${k} in
${fwcmd} add skipto ${x} ip6 from fe80::/10 546,547 to fe80::/10 546,547 via ${k} in
${fwcmd} add skipto ${x} ip6 from fe80::/10 521,546,547 to ff02::/16 521,546,547 via ${k} in
${fwcmd} add ${IPFW_deny} ip6 from fe80::/10 to ff02::/16 5355 via ${k} in
${fwcmd} add skipto ${x} ip6 from fe80::/10 to any via ${k} in
${fwcmd} add skipto ${x} ipv6-icmp from ::/128 to ff02::/16 via ${k} in
${fwcmd} add skipto ${x} ipv6-icmp from fe80::/10 to fe80::/10 via ${k} in
${fwcmd} add skipto ${x} ipv6-icmp from fe80::/10 to ff02::/16 via ${k} in
${fwcmd} add skipto ${x} ipv6-icmp from any to any icmp6types 1,2,128,129,135,136 via ${k} in
fi
y=$(( ${y} + 20 )) # 20 rules max.
done
y=7400
for i in ${IPFW_WANS6_list}; do
j="IPFW_oip${i}_6"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_oif${i}"
eval k="\$${k}"
l="IPFW_onet${i}_6"
eval l="\$${l}"
x=$(( 30000 + ( ( ${i} - 1 ) * 10 ) ))
${fwcmd} add ${y} skipto ${x} ip6 from any to ${j} via ${k} in
${fwcmd} add skipto ${x} ip6 from ${l} to fe00::/4 via ${k} in
for ii in ${IPFW_LANS6_list}; do
jj="IPFW_iip${ii}_6"
eval jj="\$${jj}"
if [ -n "${jj}" ]; then
kk="IPFW_inet${i}_6"
eval kk="\$${kk}"
${fwcmd} add skipto ${x} ip6 from any to ${kk} via ${k} in
fi
done
${fwcmd} add skipto ${x} ip6 from fe80::/10 546,547 to fe80::/10 546,547 via ${k} in
${fwcmd} add skipto ${x} ip6 from fe80::/10 521,546,547 to ff02::/16 521,546,547 via ${k} in
${fwcmd} add ${IPFW_deny} ip6 from fe80::/10 to ff02::/16 5355 via ${k} in
${fwcmd} add skipto ${x} ip6 from fe80::/10 to any via ${k} in
${fwcmd} add skipto ${x} ipv6-icmp from ::/128 to ff02::/16 via ${k} in
${fwcmd} add skipto ${x} ipv6-icmp from fe80::/10 to fe80::/10 via ${k} in
${fwcmd} add skipto ${x} ipv6-icmp from fe80::/10 to ff02::/16 via ${k} in
${fwcmd} add skipto ${x} ipv6-icmp from any to any icmp6types 1,2,128,129,135,136 via ${k} in
fi
y=$(( ${y} + 40 )) # 40 rules max.
done
y=8200
for i in ${IPFW_LANS6_list}; do
j="IPFW_iip${i}_6"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_iif${i}"
eval k="\$${k}"
x=$(( 15000 + ( ( ${i} - 1 ) * 10 ) ))
${fwcmd} add ${y} skipto ${x} log ip6 from any to any via ${k} in
${fwcmd} add skipto ${x} log ipv6-icmp from any to any via ${k} in
fi
y=$(( ${y} + 5 )) # 5 rules max.
done
y=8300
for i in ${IPFW_WANS6_list}; do
j="IPFW_oip${i}_6"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_oif${i}"
eval k="\$${k}"
x=$(( 30000 + ( ( ${i} - 1 ) * 10 ) ))
${fwcmd} add ${y} skipto ${x} log ip6 from any to any via ${k} in
${fwcmd} add skipto ${x} log ipv6-icmp from any to any via ${k} in
fi
y=$(( ${y} + 5 )) # 5 rules max.
done
fi
${fwcmd} add 9999 skipto 65500 log all from any to any
########################
########################
########################
if [ "${IPFW_LAN_6}" == "1" ]; then
########################
# All LANs IPv6 out
y=10000
for i in ${IPFW_LANS6_list}; do
j="IPFW_iip${i}_6"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_iif${i}"
eval k="\$${k}"
${fwcmd} add ${y} count ip6 from any to any via ${k} out
if [ ! x"${IPFW_LANS6}" == x"${i}" ]; then
${fwcmd} add skipto 11000 all from any to any
fi
fi
y=$(( ${y} + 10 ))
done
${fwcmd} add 11000 ${IPFW_allow} ipv6-icmp from ::/128 to ff02::/16
${fwcmd} add ${IPFW_allow} ipv6-icmp from fe80::/10 to fe80::/10
${fwcmd} add ${IPFW_allow} ipv6-icmp from fe80::/10 to ff02::/16
${fwcmd} add ${IPFW_allow} ipv6-icmp from any to any icmp6types 1,2,128,129,135,136
${fwcmd} add ${IPFW_allowlog} ipv6-icmp from any to any
${fwcmd} add ${IPFW_allow} ip6 from fe80::/10 546,547 to fe80::/10 546,547
${fwcmd} add ${IPFW_allow} ip6 from fe80::/10 521,546,547 to ff02::/16 521,546,547
${fwcmd} add ${IPFW_allow} ip6 from table\(LOCAL_RANGES6\) to table\(LOCAL_RANGES6\)
${fwcmd} add ${IPFW_deny} ip6 from fe80::/10 to ff02::/16 5355
###
for ports in $(array_groupby "${IPFW_known_ports}" "20"); do
if [ -n "${ports}" ]; then
${fwcmd} add ${IPFW_allow} ip6 from any to any ${ports}
${fwcmd} add ${IPFW_allow} ip6 from any ${ports} to any
fi
done
###
${fwcmd} add 14900 ${IPFW_allowlog} tcp from any to any
${fwcmd} add ${IPFW_allowlog} udp from any to any
${fwcmd} add ${IPFW_allowlog} all from any to any
########################
# All LANs IPv6 in
y=15000
for i in ${IPFW_LANS6_list}; do
j="IPFW_iip${i}_6"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_iif${i}"
eval k="\$${k}"
${fwcmd} add ${y} count ip6 from any to any via ${k} in
if [ ! x"${IPFW_LANS6}" == x"${i}" ]; then
${fwcmd} add skipto 16000 all from any to any
fi
fi
y=$(( ${y} + 10 ))
done
${fwcmd} add 16000 ${IPFW_allow} ipv6-icmp from ::/128 to ff02::/16
${fwcmd} add ${IPFW_allow} ipv6-icmp from fe80::/10 to fe80::/10
${fwcmd} add ${IPFW_allow} ipv6-icmp from fe80::/10 to ff02::/16
${fwcmd} add ${IPFW_allow} ipv6-icmp from any to any icmp6types 1,2,128,129,135,136
${fwcmd} add ${IPFW_allowlog} ipv6-icmp from any to any
${fwcmd} add ${IPFW_allow} ip6 from fe80::/10 546,547 to fe80::/10 546,547
${fwcmd} add ${IPFW_allow} ip6 from fe80::/10 521,546,547 to ff02::/16 521,546,547
${fwcmd} add ${IPFW_allow} ip6 from table\(LOCAL_RANGES6\) to table\(LOCAL_RANGES6\)
${fwcmd} add ${IPFW_deny} ip6 from fe80::/10 to ff02::/16 5355
###
for ports in $(array_groupby "${IPFW_known_ports}" "20"); do
if [ -n "${ports}" ]; then
${fwcmd} add ${IPFW_allow} ip6 from any to any ${ports}
${fwcmd} add ${IPFW_allow} ip6 from any ${ports} to any
fi
done
###
${fwcmd} add 19900 ${IPFW_allowlog} tcp from any to any
${fwcmd} add ${IPFW_allowlog} udp from any to any
${fwcmd} add ${IPFW_allowlog} all from any to any
########################
fi
if [ "${IPFW_LAN_4}" == "1" ]; then
########################
# All LANs IPv4 out
y=20000
for i in ${IPFW_LANS_list}; do
j="IPFW_iip${i}"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_iif${i}"
eval k="\$${k}"
${fwcmd} add ${y} count ip4 from any to any via ${k} out
if [ ! x"${IPFW_LANS}" == x"${i}" ]; then
${fwcmd} add skipto 21000 all from any to any
fi
fi
y=$(( ${y} + 10 ))
done
${fwcmd} add 21000 ${IPFW_allow} icmp from any to any
${fwcmd} add ${IPFW_allow} ip4 from table\(LOCAL_RANGES\) to table\(LOCAL_RANGES\)
###
for ports in $(array_groupby "${IPFW_known_ports}" "20"); do
if [ -n "${ports}" ]; then
${fwcmd} add ${IPFW_allow} ip4 from any to any ${ports}
${fwcmd} add ${IPFW_allow} ip4 from any ${ports} to any
fi
done
###
${fwcmd} add 24900 ${IPFW_allowlog} tcp from any to any
${fwcmd} add ${IPFW_allowlog} udp from any to any
${fwcmd} add ${IPFW_allowlog} gre from any to any
${fwcmd} add ${IPFW_allowlog} igmp from any to any
${fwcmd} add ${IPFW_allowlog} l2tp from any to any
${fwcmd} add ${IPFW_allowlog} esp from any to any
${fwcmd} add ${IPFW_allowlog} ah from any to any
${fwcmd} add ${IPFW_allowlog} all from any to any
########################
# All LANs IPv4 in
y=25000
for i in ${IPFW_LANS_list}; do
j="IPFW_iip${i}"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_iif${i}"
eval k="\$${k}"
${fwcmd} add ${y} count ip4 from any to any via ${k} in
if [ ! x"${IPFW_LANS}" == x"${i}" ]; then
${fwcmd} add skipto 26000 all from any to any
fi
fi
y=$(( ${y} + 10 ))
done
${fwcmd} add 26000 ${IPFW_allow} icmp from any to any
${fwcmd} add ${IPFW_allow} ip4 from table\(LOCAL_RANGES\) to table\(LOCAL_RANGES\)
### MULTI ISP - WAN failover
if [ ${IPFW_multiwan} -eq 1 ]; then
for i in ${IPFW_WANS_list}; do
j="IPFW_oip${i}"
eval j="\$${j}"
if [ -n "${j}" ]; then
TEST="MWAN_PORTS${i}";
eval TEST="\$${TEST}"
if [ -n "${TEST}" ]; then
for ports in $(array_groupby "${TEST}" "20"); do
if [ -n "${ports}" ]; then
define_multiwan "port" "${ports}" "${i}"
fi
done
fi
fi
done
for i in ${IPFW_WANS_list}; do
j="IPFW_oip${i}"
eval j="\$${j}"
if [ -n "${j}" ]; then
TEST="MWAN_TABLES${i}";
eval TEST="\$${TEST}"
if [ -n "${TEST}" ]; then
for tables in $(array_groupby "${TEST}" "20"); do
if [ -n "${tables}" ]; then
define_multiwan "srchost" "${tables}" "${i}"
fi
done
fi
fi
done
for i in ${IPFW_WANS_list}; do
j="IPFW_oip${i}"
eval j="\$${j}"
if [ -n "${j}" ]; then
define_multiwan "srchost" "WAN${i}" "${i}"
k="IPFW_ofib${i}"
eval k="\$${k}"
l="IPFW_onet${i}"
eval l="\$${l}"
${fwcmd} add setfib ${k} all from any to ${l}
fi
done
fi
###
for ports in $(array_groupby "${IPFW_known_ports}" "20"); do
if [ -n "${ports}" ]; then
${fwcmd} add ${IPFW_allow} ip4 from any to any ${ports}
${fwcmd} add ${IPFW_allow} ip4 from any ${ports} to any
fi
done
###
${fwcmd} add 29900 ${IPFW_allowlog} tcp from any to any
${fwcmd} add ${IPFW_allowlog} udp from any to any
${fwcmd} add ${IPFW_allowlog} gre from any to any
${fwcmd} add ${IPFW_allowlog} igmp from any to any
${fwcmd} add ${IPFW_allowlog} l2tp from any to any
${fwcmd} add ${IPFW_allowlog} esp from any to any
${fwcmd} add ${IPFW_allowlog} ah from any to any
${fwcmd} add ${IPFW_allowlog} all from any to any
########################
fi
########################
########################
if [ "${IPFW_WAN_6}" == "1" ]; then
########################
# All WANs IPv6 in
y=30000
for i in ${IPFW_WANS6_list}; do
j="IPFW_oip${i}_6"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_oif${i}"
eval k="\$${k}"
${fwcmd} add ${y} count ip6 from any to any via ${k} in
if [ ! x"${IPFW_WANS6}" == x"${i}" ]; then
${fwcmd} add skipto 31000 all from any to any
fi
fi
y=$(( ${y} + 10 ))
done
${fwcmd} add 31000 ${IPFW_allow} ipv6-icmp from ::/128 to ff02::/16
${fwcmd} add ${IPFW_allow} ipv6-icmp from fe80::/10 to fe80::/10
${fwcmd} add ${IPFW_allow} ipv6-icmp from fe80::/10 to ff02::/16
${fwcmd} add ${IPFW_allow} ipv6-icmp from any to any icmp6types 1,2,128,129,135,136
${fwcmd} add ${IPFW_allowlog} ipv6-icmp from any to any
${fwcmd} add ${IPFW_allow} ip6 from fe80::/10 546,547 to fe80::/10 546,547
${fwcmd} add ${IPFW_allow} ip6 from fe80::/10 521,546,547 to ff02::/16 521,546,547
${fwcmd} add ${IPFW_deny} ip6 from fe80::/10 to ff02::/16 5355
${fwcmd} add ${IPFW_deny} ip6 from table\(BLACKLIST6\) to any
${fwcmd} add ${IPFW_deny} ip6 from table\(BLACKLIST_RMT6\) to any
${fwcmd} add ${IPFW_deny} ip6 from table\(BLACKLIST_IMP6\) to any
${fwcmd} add ${IPFW_deny} ip6 from table\(BLACKLIST_GEO6\) to any
${fwcmd} add ${IPFW_denylog} ip6 from table\(BLOCKED_RANGES6\) to any
# blocked WAN IN dstports (logging enabled)
block_dstports "in6log" "${IPFW_wan6_in_dstports}"
# replies to allowed WAN OUT dstports
for ports in $(array_groupby "${IPFW_wan6_out_allowed_udp}" "20"); do
if [ -n "${ports}" ]; then
${fwcmd} add ${IPFW_allow} udp from any ${ports} to table\(OUT_RANGES6\) ${IPFW_unprivports}
fi
done
for ports in $(array_groupby "${IPFW_wan6_out_allowed_tcp}" "20"); do
if [ -n "${ports}" ]; then
${fwcmd} add ${IPFW_allow} tcp from any ${ports} to table\(OUT_RANGES6\) ${IPFW_unprivports}
fi
done
# allowed WAN IN dstports
i=0
for protoport in ${PROTOPORT}; do
protoip6=$(array_get "${PROTOIP6}" "${i}")
if [ "${protoip6}" != "NONE" ]; then
protocol=$(array_get "${PROTOCOL}" "${i}")
protolog=$(array_get "${PROTOLOG}" "${i}")
protoaction=$(array_get "${PROTOACTION}" "${i}")
block_protocol "ipv6" "in" "${protoport}" "${protocol}" "${protolog}" "${protoip6}" "allow"
fi
i=$(( ${i} + 1 ))
done
###
for ports in $(array_groupby "${IPFW_known_ports}" "20"); do
if [ -n "${ports}" ]; then
${fwcmd} add ${IPFW_allow} ip6 from any to any ${ports}
${fwcmd} add ${IPFW_allow} ip6 from any ${ports} to any
fi
done
###
${fwcmd} add 34900 ${IPFW_allowlog} tcp from any to any
${fwcmd} add ${IPFW_allowlog} udp from any to any
${fwcmd} add ${IPFW_allowlog} all from any to any
########################
# All WANs IPv6 out
y=35000
for i in ${IPFW_WANS6_list}; do
j="IPFW_oip${i}_6"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_oif${i}"
eval k="\$${k}"
${fwcmd} add ${y} count ip6 from any to any via ${k} out
if [ ! x"${IPFW_WANS6}" == x"${i}" ]; then
${fwcmd} add skipto 36000 all from any to any
fi
fi
y=$(( ${y} + 10 ))
done
${fwcmd} add 36000 ${IPFW_allow} ipv6-icmp from ::/128 to ff02::/16
${fwcmd} add ${IPFW_allow} ipv6-icmp from fe80::/10 to fe80::/10
${fwcmd} add ${IPFW_allow} ipv6-icmp from fe80::/10 to ff02::/16
${fwcmd} add ${IPFW_allow} ipv6-icmp from any to any icmp6types 1,2,128,129,135,136
${fwcmd} add ${IPFW_allowlog} ipv6-icmp from any to any
${fwcmd} add ${IPFW_allow} ip6 from fe80::/10 546,547 to fe80::/10 546,547
${fwcmd} add ${IPFW_allow} ip6 from fe80::/10 521,546,547 to ff02::/16 521,546,547
${fwcmd} add ${IPFW_deny} ip6 from fe80::/10 to ff02::/16 5355
${fwcmd} add ${IPFW_deny} ip6 from any to table\(BLACKLIST6\)
${fwcmd} add ${IPFW_deny} ip6 from any to table\(BLACKLIST_RMT6\)
${fwcmd} add ${IPFW_deny} ip6 from any to table\(BLACKLIST_IMP6\)
${fwcmd} add ${IPFW_deny} ip6 from any to table\(BLACKLIST_GEO6\)
${fwcmd} add ${IPFW_denylog} ip6 from any to table\(BLOCKED_RANGES6\)
# blocked WAN OUT dstports (logging enabled)
block_dstports "out6log" "${IPFW_wan6_out_dstports}"
for table in ${BLOCK_TABLESRC_6}; do
if [ -n "${table}" ]; then
block_srchost "${table}"
fi
done
for table in ${BLOCK_TABLEDST_6}; do
if [ -n "${table}" ]; then
block_dsthost "${table}"
fi
done
# allowed WAN OUT dstports
for ports in $(array_groupby "${IPFW_wan6_out_allowed_udp}" "20"); do
if [ -n "${ports}" ]; then
${fwcmd} add ${IPFW_allow} udp from table\(OUT_RANGES6\) ${IPFW_unprivports} to any ${ports}
fi
done
for ports in $(array_groupby "${IPFW_wan6_out_allowed_tcp}" "20"); do
if [ -n "${ports}" ]; then
${fwcmd} add ${IPFW_allow} tcp from table\(OUT_RANGES6\) ${IPFW_unprivports} to any ${ports}
fi
done
# replies to allowed WAN IN dstports
i=0
for protoport in ${PROTOPORT}; do
protoip6=$(array_get "${PROTOIP6}" "${i}")
if [ "${protoip6}" != "NONE" ]; then
protoaction=$(array_get "${PROTOACTION}" "${i}")
if [ "${protoaction}" != "deny" ]; then
protocol=$(array_get "${PROTOCOL}" "${i}")
protolog=$(array_get "${PROTOLOG}" "${i}")
block_protocol "ipv6" "outreply" "${protoport}" "${protocol}" "${protolog}" "${protoip6}" "allow"
fi
fi
i=$(( ${i} + 1 ))
done
###
for ports in $(array_groupby "${IPFW_known_ports}" "20"); do
if [ -n "${ports}" ]; then
${fwcmd} add ${IPFW_allow} ip6 from any to any ${ports}
${fwcmd} add ${IPFW_allow} ip6 from any ${ports} to any
fi
done
###
${fwcmd} add 39900 ${IPFW_allowlog} tcp from any to any
${fwcmd} add ${IPFW_allowlog} udp from any to any
${fwcmd} add ${IPFW_allowlog} all from any to any
########################
fi
if [ "${IPFW_WAN_4}" == "1" ]; then
########################
# All WANs IPv4 in
y=40000
for i in ${IPFW_WANS_list}; do
j="IPFW_oip${i}"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_oif${i}"
eval k="\$${k}"
${fwcmd} add ${y} count ip4 from any to any via ${k} in
if [ ! x"${IPFW_WANS}" == x"${i}" ]; then
${fwcmd} add skipto 41000 all from any to any
fi
fi
y=$(( ${y} + 10 ))
done
${fwcmd} add 41000 ${IPFW_deny} ip4 from table\(BLACKLIST\) to any
${fwcmd} add ${IPFW_deny} ip4 from table\(BLACKLIST_RMT\) to any
${fwcmd} add ${IPFW_deny} ip4 from table\(BLACKLIST_IMP\) to any
${fwcmd} add ${IPFW_deny} ip4 from table\(BLACKLIST_GEO\) to any
${fwcmd} add ${IPFW_deny} igmp from any to any
${fwcmd} add ${IPFW_denylog} ip4 from table\(BLOCKED_RANGES\) to any
# blocked WAN IN dstports (logging enabled)
block_dstports "in4log" "${IPFW_wan4_in_dstports}"
# blocked WAN IN dstports
i=0
for protoport in ${PROTOPORT}; do
protoip4=$(array_get "${PROTOIP4}" "${i}")
if [ "${protoip4}" != "NONE" ]; then
protoaction=$(array_get "${PROTOACTION}" "${i}")
if [ "${protoaction}" = "deny" ]; then
protocol=$(array_get "${PROTOCOL}" "${i}")
protolog=$(array_get "${PROTOLOG}" "${i}")
block_protocol "ipv4" "in" "${protoport}" "${protocol}" "${protolog}" "${protoip4}" "deny"
fi
fi
i=$(( ${i} + 1 ))
done
i=0
for protoport in ${PROTOPORT}; do
protoip4=$(array_get "${PROTOIP4}" "${i}")
if [ "${protoip4}" != "NONE" ]; then
protoaction=$(array_get "${PROTOACTION}" "${i}")
if [ "${protoaction}" != "deny" ]; then
protocol=$(array_get "${PROTOCOL}" "${i}")
protolog=$(array_get "${PROTOLOG}" "${i}")
block_protocol "ipv4" "in" "${protoport}" "${protocol}" "${protolog}" "${protoip4}" "denyonly"
fi
fi
i=$(( ${i} + 1 ))
done
# NAT
for i in ${IPFW_WANS_list}; do
j="IPFW_nat${i}"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_oif${i}"
eval k="\$${k}"
${fwcmd} add nat ${i} ip4 from any to any via ${k}
fi
done
${fwcmd} add ${IPFW_allow} icmp from any to any
# replies to allowed WAN OUT dstports
for ports in $(array_groupby "${IPFW_wan4_out_allowed_udp}" "20"); do
if [ -n "${ports}" ]; then
${fwcmd} add ${IPFW_allow} udp from any ${ports} to table\(OUT_RANGES\) ${IPFW_unprivports}
fi
done
for ports in $(array_groupby "${IPFW_wan4_out_allowed_tcp}" "20"); do
if [ -n "${ports}" ]; then
${fwcmd} add ${IPFW_allow} tcp from any ${ports} to table\(OUT_RANGES\) ${IPFW_unprivports}
fi
done
# allowed WAN IN dstports
i=0
for protoport in ${PROTOPORT}; do
protoip4=$(array_get "${PROTOIP4}" "${i}")
if [ "${protoip4}" != "NONE" ]; then
protoaction=$(array_get "${PROTOACTION}" "${i}")
if [ "${protoaction}" != "deny" ]; then
protocol=$(array_get "${PROTOCOL}" "${i}")
protolog=$(array_get "${PROTOLOG}" "${i}")
block_protocol "ipv4" "in" "${protoport}" "${protocol}" "${protolog}" "${protoip4}" "nodeny"
fi
fi
i=$(( ${i} + 1 ))
done
###
for ports in $(array_groupby "${IPFW_known_ports}" "20"); do
if [ -n "${ports}" ]; then
${fwcmd} add ${IPFW_allow} ip4 from any to any ${ports}
${fwcmd} add ${IPFW_allow} ip4 from any ${ports} to any
fi
done
###
${fwcmd} add 44900 ${IPFW_allowlog} sctp from any to any
${fwcmd} add ${IPFW_allowlog} tcp from any to any
${fwcmd} add ${IPFW_allowlog} udp from any to any
${fwcmd} add ${IPFW_allowlog} all from any to any
########################
# All WANs IPv4 out
y=45000
for i in ${IPFW_WANS_list}; do
j="IPFW_oip${i}"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_oif${i}"
eval k="\$${k}"
${fwcmd} add ${y} count ip4 from any to any via ${k} out
if [ ! x"${IPFW_WANS}" == x"${i}" ]; then
${fwcmd} add skipto 46000 all from any to any
fi
fi
y=$(( ${y} + 10 ))
done
${fwcmd} add 46000 ${IPFW_deny} ip4 from any to table\(BLACKLIST\)
${fwcmd} add ${IPFW_deny} ip4 from any to table\(BLACKLIST_RMT\)
${fwcmd} add ${IPFW_deny} ip4 from any to table\(BLACKLIST_IMP\)
${fwcmd} add ${IPFW_deny} ip4 from any to table\(BLACKLIST_GEO\)
${fwcmd} add ${IPFW_deny} igmp from any to any
${fwcmd} add ${IPFW_denylog} ip4 from any to table\(BLOCKED_RANGES\)
# blocked WAN OUT dstports (logging enabled)
block_dstports "out4log" "${IPFW_wan4_out_dstports}"
for table in ${BLOCK_TABLESRC}; do
if [ -n "${table}" ]; then
block_srchost "${table}"
fi
done
for table in ${BLOCK_TABLEDST}; do
if [ -n "${table}" ]; then
block_dsthost "${table}"
fi
done
# blocked WAN OUT dstports
i=0
for protoport in ${PROTOPORT}; do
protoip4=$(array_get "${PROTOIP4}" "${i}")
if [ "${protoip4}" != "NONE" ]; then
protoaction=$(array_get "${PROTOACTION}" "${i}")
if [ "${protoaction}" != "deny" ]; then
protocol=$(array_get "${PROTOCOL}" "${i}")
protolog=$(array_get "${PROTOLOG}" "${i}")
block_protocol "ipv4" "outreply" "${protoport}" "${protocol}" "${protolog}" "${protoip4}" "denyonly"
fi
fi
i=$(( ${i} + 1 ))
done
# NAT
for i in ${IPFW_WANS_list}; do
j="IPFW_nat${i}"
eval j="\$${j}"
if [ -n "${j}" ]; then
k="IPFW_oif${i}"
eval k="\$${k}"
${fwcmd} add nat ${i} ip4 from any to any via ${k}
fi
done
${fwcmd} add ${IPFW_allow} icmp from any to any
# allowed WAN OUT dstports
for ports in $(array_groupby "${IPFW_wan4_out_allowed_udp}" "20"); do
if [ -n "${ports}" ]; then
${fwcmd} add ${IPFW_allow} udp from table\(OUT_RANGES\) ${IPFW_unprivports} to any ${ports}
fi
done
for ports in $(array_groupby "${IPFW_wan4_out_allowed_tcp}" "20"); do
if [ -n "${ports}" ]; then
${fwcmd} add ${IPFW_allow} tcp from table\(OUT_RANGES\) ${IPFW_unprivports} to any ${ports}
fi
done
# replies to allowed WAN IN dstports
i=0
for protoport in ${PROTOPORT}; do
protoip4=$(array_get "${PROTOIP4}" "${i}")
if [ "${protoip4}" != "NONE" ]; then
protoaction=$(array_get "${PROTOACTION}" "${i}")
if [ "${protoaction}" != "deny" ]; then
protocol=$(array_get "${PROTOCOL}" "${i}")
protolog=$(array_get "${PROTOLOG}" "${i}")
block_protocol "ipv4" "outreply" "${protoport}" "${protocol}" "${protolog}" "${protoip4}" "nodeny"
fi
fi
i=$(( ${i} + 1 ))
done
###
for ports in $(array_groupby "${IPFW_known_ports}" "20"); do
if [ -n "${ports}" ]; then
${fwcmd} add ${IPFW_allow} ip4 from any to any ${ports}
${fwcmd} add ${IPFW_allow} ip4 from any ${ports} to any
fi
done
###
${fwcmd} add 49900 ${IPFW_allowlog} tcp from any to any
${fwcmd} add ${IPFW_allowlog} sctp from any to any
${fwcmd} add ${IPFW_allowlog} udp from any to any
${fwcmd} add ${IPFW_allowlog} all from any to any
########################
fi
########################
# END
########################
${fwcmd} add 65500 ${IPFW_allowlog} ip from any to any