-
-
Notifications
You must be signed in to change notification settings - Fork 186
/
libfirewall.tcl
executable file
·641 lines (558 loc) · 19.9 KB
/
libfirewall.tcl
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
#!/bin/tclsh
##
# @file setfirewall.tcl
# @brief Firewall-Konfiguration
##
##
# @const Firewall_CONFIG_FILE
# Konfigurationsdatei für die Firewall
##
set Firewall_CONFIG_FILE /etc/config/firewall.conf
##
# @const Firewall_SERVICES
# Enthält die verfügbaren Services und deren TCP-Ports
#
# Jeder Service kann als assoziatives Array mit den folgenden
# Elementen aufgefasst werden:
# PORTS : Liste der TCP-Portnummern des Services
# ACCESS: Zugriffsrechte für den Service:
# full : Vollzugriff; keine Einschränkungen
# restricted: Eingeschränkter Zugriff
# none : Kein Zugriff möglich
##
array set Firewall_SERVICES {}
set Firewall_SERVICES(XMLRPC) [list PORTS [list 2000 2001 2002 2010 9292 42000 42001 42010 49292] ACCESS none]
set Firewall_SERVICES(REGA) [list PORTS [list 8181 1999 48181 41999] ACCESS none]
set Firewall_SERVICES(NEOSERVER) [list PORTS [list 8088 9099 1901 1902 5987 10000 48899 49880] ACCESS none]
set Firewall_SERVICES(SNMP) [list PORTS [list 161] ACCESS none]
##
# @const Firewall_USER_PORTS
# Liste mit User-defined ports.
##
set Firewall_USER_PORTS {}
##
# @const Firewall_MODE_RESTRICTIVE
# Firewall Modus RESTRICTIVE. INPUT Policy DROP. Last Rule REJECTs all.
##
set Firewall_MODE_RESTRICTIVE "RESTRICTIVE"
## @const Firewall_MODE_MOST_OPEN
# Firewall Modus MOST_OPEN (Kompatibilitätsmodus). INPUT Policy ACCEPT
##
set Firewall_MODE_MOST_OPEN "MOST_OPEN"
##
# @var Firewall_MODE
# Firewall Modus. Werte duerfen RESTRICTIVE oder MOST_OPEN annehmen.
##
set Firewall_MODE $Firewall_MODE_RESTRICTIVE
##
# @var Firewall_LOG_ENABLED
# Aktiviert Logging über syslog, default ist 'aus'.
##
set Firewall_LOG_ENABLED 0
##
# @var Firewall_IPS
# IP-Adressen für den eingeschränkten Zugriff
#
# Beinhaltet eine Liste der IP-Adressen oder Addressgruppen, denen bei
# eingeschränktem Zugriff eine Verwendung des jeweiligen Serices noch erlaubt
# ist.
##
set Firewall_IPS [list 192.168.0.1 192.168.0.0/16 fc00::/7 fe80::/10]
#------------------------------------------------------------------------------
##
# @fn Firewall_setLoggingEnabled
# Aktiviert Logging über Syslog (1)
# oder deaktiviert Logging über Syslog (0)
#
##
proc Firewall_setLoggingEnabled { enabled } {
global Firewall_LOG_ENABLED
if { $enabled == 1 } {
set Firewall_LOG_ENABLED 1
} else {
set Firewall_LOG_ENABLED 0
}
}
##
# @fn loadConfiguration
# Lädt die Firwall-Einstellunfen aus der Konfigurationsdatei
##
proc Firewall_loadConfiguration { } {
global Firewall_CONFIG_FILE Firewall_SERVICES Firewall_IPS Firewall_MODE Firewall_USER_PORTS
array set config {}
array set section {}
set sectionName {}
set migrationPerformed 0
if { ![catch { set fd [open $Firewall_CONFIG_FILE r] }] } then {
catch {
while { ![eof $fd] } {
set line [string trimleft [gets $fd]]
if { "\#" != [string index $line 0] } then {
if { [regexp {\[([^\]]+)\]} $line dummy newSectionName] } then {
set config($sectionName) [array get section]
array_clear section
set sectionName $newSectionName
}
if { [regexp {([^=]+)=(.+)} $line dummy name value] } then {
set section([string trim $name]) [string trim $value]
}
}
}
set config($sectionName) [array get section]
array_clear section
}
close $fd
}
foreach sectionName [array names config] {
if { {} != $sectionName } then {
array set section $config($sectionName)
set ports [array_getValue section Ports]
set id [array_getValue section Id]
# Hinzufuegen von Ports, die oben definiert, jedoch nicht in der Config Datei stehen.
# (Migration etc.)
#puts "Search in $ports"
set service $Firewall_SERVICES($id)
set defaultServicePorts [lindex $service 1]
foreach p $defaultServicePorts {
#puts "Searching for $p"
if { [lsearch -exact $ports "$p"] == -1 } {
#puts "$p not in list appending"
lappend ports $p
#puts $ports
set migrationPerformed 1
}
}
#end of migration
set access [array_getValue section Access]
set Firewall_SERVICES($id) [list PORTS [lsort -integer $ports] ACCESS $access]
array_clear section
}
}
if { [info exists config()] } then {
array set emptySection $config()
set Firewall_IPS [array_getValue emptySection IPs]
set aModes [array_getValue emptySection MODE]
if { [string equal $aModes ""] == 0 } {
set Firewall_MODE $aModes
}
set userPorts [array_getValue emptySection USERPORTS]
if { [string equal $userPorts ""] == 0 } {
set Firewall_USER_PORTS $userPorts
}
}
if { $migrationPerformed == 1 } {
Firewall_saveConfiguration
}
}
##
# @fn saveConfiguration
# Speichert die Firewall-Einstellungen in der Konfigurationsdatei
##
proc Firewall_saveConfiguration {} {
global Firewall_CONFIG_FILE Firewall_SERVICES Firewall_IPS Firewall_MODE Firewall_USER_PORTS
set fd [open $Firewall_CONFIG_FILE w]
catch {
puts $fd "# Firewall Configuration file"
puts $fd "# created [clock format [clock seconds]]"
puts $fd "# This file was automatically gernerated"
puts $fd "# Please do not change anything"
puts $fd ""
puts $fd "MODE = $Firewall_MODE"
puts $fd ""
puts $fd "IPs = $Firewall_IPS"
puts $fd ""
if { [llength $Firewall_USER_PORTS] > 0 } {
puts -nonewline $fd "USERPORTS ="
foreach port $Firewall_USER_PORTS {
puts -nonewline $fd " $port"
}
}
puts $fd "\n"
foreach serviceName [array names Firewall_SERVICES] {
array set service $Firewall_SERVICES($serviceName)
puts $fd "\[SERVICE $serviceName\]"
puts $fd "Id = $serviceName"
puts $fd "Ports = $service(PORTS)"
puts $fd "Access = $service(ACCESS)"
puts $fd ""
}
}
close $fd
}
##
# @fn setFirewallMode
# Setzt die Firewall Modus Einstellung.
# Die Firewall kann im Modus "MOST_OPEN" (auch Kompatibilitätsmodus) oder im Modus "RESTRICTIVE" betrieben werden.
##
proc Firewall_setMode { modeName } {
global Firewall_MODE Firewall_MODE_RESTRICTIVE Firewall_MODE_MOST_OPEN
if {[string equal $modeName $Firewall_MODE_RESTRICTIVE] == 1} {
set Firewall_MODE $Firewall_MODE_RESTRICTIVE
#Firewall_saveConfiguration
} elseif {[string equal $modeName $Firewall_MODE_MOST_OPEN] == 1} {
set Firewall_MODE $Firewall_MODE_MOST_OPEN
#Firewall_saveConfiguration
} else {
puts "Firewall_setMode: Unsupported mode."
}
}
##
# @fn Firewall_set_service_access
# Setzt den ACCESS Modus 'accessLevel' (none/restricted/full) des Dienstes 'service'
# innerhalb der Liste Firewall_SERVICES
##
proc Firewall_set_service_access { service accessLevel } {
global Firewall_SERVICES
set serviceList [array get Firewall_SERVICES $service]
if { [llength serviceList ] > 0 && [ lindex serviceList 0 ] != "" } {
#write new value
set accessIndex [lsearch $Firewall_SERVICES($service) ACCESS]
set valueIndex [ expr { int($accessIndex + 1) } ]
set Firewall_SERVICES($service) [lreplace $Firewall_SERVICES($service) $valueIndex $valueIndex $accessLevel]
#puts "New value is"
#puts $Firewall_SERVICES($service)
} else {
puts "No such service $level"
return
}
}
##
# @fn Firewall_get_service_access
# Gibt den ACCESS Modus (none/restricted/full) des Dienstes 'service'
# innerhalb der Liste Firewall_SERVICES zurück
##
proc Firewall_get_service_access { service } {
global Firewall_SERVICES
set serviceList [array get Firewall_SERVICES $service]
if { [llength serviceList ] > 0 && [ lindex serviceList 0 ] != "" } {
#read value and return it
set accessIndex [lsearch $Firewall_SERVICES($service) ACCESS]
set valueIndex [ expr { int($accessIndex + 1) } ]
return [lindex $Firewall_SERVICES($service) $valueIndex ]
} else {
puts "No such service $level"
return ""
}
}
namespace eval FirewallInternal {}
##
# @fn sshEnabled
# Prüft, ob SSH aktiviert ist
##
proc FirewallInternal::sshEnabled {} {
set fx [ file exists "/etc/config/sshEnabled" ]
return $fx
}
##
# @fn sshEnabled
# Prüft, ob ip6tables vorhanden ist und ausgeführt werden kann
##
proc FirewallInternal::ip6Supported {} {
set a [ file exists "/proc/net/if_inet6" ]
set b [ expr [catch { exec which ip6tables } ] == 0 ? 1 : 0 ]
set r [ expr { $a && $b } ]
return $r
}
##
# @fn configureFirewallMostOpen
# Gibt 1 zurueck, wenn es sich um einen UDP Port handelt, ansonsten 0.
##
proc FirewallInternal::Firewall_isUdpPort { port } {
switch $port {
161 {
return 1
}
1901 {
return 1
}
1902 {
return 1
}
5987 {
return 1
}
10000 {
return 1
}
48899 {
return 1
}
49880 {
return 1
}
default {
return 0
}
}
}
##
# @fn configureFirewall
# Konfiguriert die Firewall
##
proc Firewall_configureFirewall { } {
global Firewall_SERVICES Firewall_IPS Firewall_MODE Firewall_MODE_RESTRICTIVE Firewall_MODE_MOST_OPEN
if { [string equal $Firewall_MODE $Firewall_MODE_MOST_OPEN] == 1 } {
FirewallInternal::Firewall_configureFirewallMostOpen
} else {
FirewallInternal::Firewall_configureFirewallRestrictive
}
}
##
# @fn configureFirewallMostOpen
# Konfiguriert die Firewall mit weniger restriktiven Einstellungen. (Kompatibilitätsmodus)
##
proc FirewallInternal::Firewall_configureFirewallMostOpen { } {
global Firewall_SERVICES Firewall_IPS Firewall_USER_PORTS
try_exec_cmd "/usr/sbin/iptables -F"
try_exec_cmd "/usr/sbin/iptables -P INPUT ACCEPT"
try_exec_cmd "/usr/sbin/iptables -A INPUT -i lo -j ACCEPT"
try_exec_cmd "/usr/sbin/iptables -A INPUT -p tcp --dport 8182 -j DROP"
try_exec_cmd "/usr/sbin/iptables -A INPUT -p tcp --dport 8183 -j DROP"
try_exec_cmd "/usr/sbin/ip6tables -F"
try_exec_cmd "/usr/sbin/ip6tables -P INPUT ACCEPT"
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -i lo -j ACCEPT"
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p tcp --dport 8182 -j DROP"
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p tcp --dport 8183 -j DROP"
if { [FirewallInternal::sshEnabled] == 1 } {
try_exec_cmd "/usr/sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT"
} else {
try_exec_cmd "/usr/sbin/iptables -A INPUT -p tcp --dport 22 -j DROP"
}
set has_ip6tables [FirewallInternal::ip6Supported]
# user defined ports (the only reason to do this is to enable the user to override settings for services)
foreach userport $Firewall_USER_PORTS {
try_exec_cmd "/usr/sbin/iptables -A INPUT -p tcp --dport $userport -j ACCEPT"
try_exec_cmd "/usr/sbin/iptables -A INPUT -p udp --dport $userport -j ACCEPT"
if { $has_ip6tables } {
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p tcp --dport $userport -j ACCEPT"
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p udp --dport $userport -j ACCEPT"
}
}
foreach serviceName [array names Firewall_SERVICES] {
array set service $Firewall_SERVICES($serviceName)
if { $service(ACCESS) == "restricted" } then {
foreach port $service(PORTS) {
set prot tcp
if { [ FirewallInternal::Firewall_isUdpPort $port ] } {
set prot udp
}
foreach ip $Firewall_IPS {
if { [regexp {:} $ip] } then {
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p $prot --dport $port -s $ip -j ACCEPT"
} else {
try_exec_cmd "/usr/sbin/iptables -A INPUT -p $prot --dport $port -s $ip -j ACCEPT"
}
}
}
}
if { $service(ACCESS) == "none" || $service(ACCESS) == "restricted"} then {
foreach port $service(PORTS) {
set prot tcp
if { [FirewallInternal::Firewall_isUdpPort $port] } {
set prot udp
}
try_exec_cmd "/usr/sbin/iptables -A INPUT -p $prot --dport $port -j DROP"
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p $prot --dport $port -j DROP"
}
}
#block internal ports
if { [string equal "XMLRPC" $serviceName] || [string equal "REGA" $serviceName] } {
foreach port $service(PORTS) {
if { $port < 30000 } {
try_exec_cmd "/usr/sbin/iptables -A INPUT -p tcp --dport 3$port -j DROP"
if {$has_ip6tables} {
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p tcp --dport 3$port -j DROP"
}
}
}
}
}
}
##
# @fn configureFirewallRestrictive
# Konfiguriert die Firewall mit restriktiveren Einstellungen.
##
proc FirewallInternal::Firewall_configureFirewallRestrictive { } {
global Firewall_SERVICES Firewall_IPS Firewall_USER_PORTS
# IPv4
# flush rules
try_exec_cmd "/usr/sbin/iptables -F"
# allow all loopback
try_exec_cmd "/usr/sbin/iptables -A INPUT -i lo -j ACCEPT"
# allow all established and related packets to pass
try_exec_cmd "/usr/sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT"
# tcp port for hmip wired gateways
try_exec_cmd "/usr/sbin/iptables -A INPUT -p tcp --dport 9293 -m state --state NEW -j ACCEPT"
# ssh
if { [FirewallInternal::sshEnabled] == 1 } {
try_exec_cmd "/usr/sbin/iptables -A INPUT -p tcp --dport 22 -m state --state NEW -j ACCEPT"
}
# http(s)
try_exec_cmd "/usr/sbin/iptables -A INPUT -p tcp --dport 80 -m state --state NEW -j ACCEPT"
try_exec_cmd "/usr/sbin/iptables -A INPUT -p tcp --dport 443 -m state --state NEW -j ACCEPT"
# udp port for eq3configd
try_exec_cmd "/usr/sbin/iptables -A INPUT -p udp --sport 43439 -j ACCEPT"
try_exec_cmd "/usr/sbin/iptables -A INPUT -p udp --dport 43439 -j ACCEPT"
try_exec_cmd "/usr/sbin/iptables -A INPUT -p udp --sport 23272 -j ACCEPT"
try_exec_cmd "/usr/sbin/iptables -A INPUT -p udp --dport 23272 -j ACCEPT"
# hmip drap
try_exec_cmd "/usr/sbin/iptables -A INPUT -p udp --dport 43438 -j ACCEPT"
# udp uPnP/ssdp port
try_exec_cmd "/usr/sbin/iptables -A INPUT -p udp --dport 1900 -j ACCEPT"
# IPv6
set has_ip6tables [FirewallInternal::ip6Supported]
#exec logger -t firewall -p user.info "has ip6 $has_ip6tables"
if { $has_ip6tables } {
# flush rules
try_exec_cmd "/usr/sbin/ip6tables -F"
# allow all loopback
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -i lo -j ACCEPT"
# allow all established and related packets to pass
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT"
# tcp port for hmip wired gateways
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p tcp --dport 9293 -m state --state NEW -j ACCEPT"
# ssh
if { [FirewallInternal::sshEnabled] == 1 } {
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p tcp --dport 22 -m state --state NEW -j ACCEPT"
}
# http(s)
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p tcp --dport 80 -m state --state NEW -j ACCEPT"
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p tcp --dport 443 -m state --state NEW -j ACCEPT"
# udp port for eq3configd
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p udp --sport 43439 -j ACCEPT"
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p udp --dport 43439 -j ACCEPT"
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p udp --sport 23272 -j ACCEPT"
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p udp --dport 23272 -j ACCEPT"
# hmip drap
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p udp --dport 43438 -j ACCEPT"
# udp uPnP/ssdp port
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p udp --dport 1900 -j ACCEPT"
}
# user defined ports
foreach userport $Firewall_USER_PORTS {
try_exec_cmd "/usr/sbin/iptables -A INPUT -p tcp --dport $userport -m state --state NEW -j ACCEPT"
try_exec_cmd "/usr/sbin/iptables -A INPUT -p udp --dport $userport -j ACCEPT"
if { $has_ip6tables } {
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p tcp --dport $userport -m state --state NEW -j ACCEPT"
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p udp --dport $userport -j ACCEPT"
}
}
# services ports
foreach serviceName [array names Firewall_SERVICES] {
array set service $Firewall_SERVICES($serviceName)
if { $service(ACCESS) == "restricted" } then {
foreach port $service(PORTS) {
set prot "tcp"
set options "-m state --state NEW"
if { [FirewallInternal::Firewall_isUdpPort $port] } {
set prot "udp"
set options ""
}
foreach ip $Firewall_IPS {
if { [ FirewallInternal::IsIPV4 $ip ] == 1 } then {
try_exec_cmd "/usr/sbin/iptables -A INPUT -p $prot --dport $port -s $ip $options -j ACCEPT"
} elseif { $has_ip6tables } {
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p $prot --dport $port -s $ip $options -j ACCEPT"
}
}
}
}
if { $service(ACCESS) == "full"} then {
foreach port $service(PORTS) {
set prot "tcp"
set options "-m state --state NEW"
if { [FirewallInternal::Firewall_isUdpPort $port] } {
set prot "udp"
set options ""
}
try_exec_cmd "/usr/sbin/iptables -A INPUT -p $prot --dport $port $options -j ACCEPT"
if { $has_ip6tables } {
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p $prot --dport $port $options -j ACCEPT"
}
}
}
}
# Allow some ICMPv6 types in the INPUT chain for local IPv6 Communication
if {$has_ip6tables} {
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p icmpv6 --icmpv6-type destination-unreachable -j ACCEPT"
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p icmpv6 --icmpv6-type packet-too-big -j ACCEPT"
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p icmpv6 --icmpv6-type time-exceeded -j ACCEPT"
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p icmpv6 --icmpv6-type parameter-problem -j ACCEPT"
}
# allow echo request
try_exec_cmd "/usr/sbin/iptables -A INPUT -p icmp --icmp-type echo-request -m state --state NEW -j ACCEPT"
if {$has_ip6tables} {
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p icmpv6 --icmpv6-type echo-request -m state --state NEW -m limit --limit 900/min -j ACCEPT"
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p icmpv6 --icmpv6-type echo-reply -m state --state NEW -m limit --limit 900/min -j ACCEPT"
}
# allow DHCPv6 / Router Advertisement and NDP but only if the hop limit field is 255
if {$has_ip6tables} {
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p icmpv6 --icmpv6-type router-advertisement -m hl --hl-eq 255 -j ACCEPT"
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p icmpv6 --icmpv6-type neighbor-advertisement -m hl --hl-eq 255 -j ACCEPT"
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p icmpv6 --icmpv6-type neighbor-solicitation -m hl --hl-eq 255 -j ACCEPT"
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -p icmpv6 --icmpv6-type redirect -m hl --hl-eq 255 -j ACCEPT"
}
# default INPUT policy DROP and last Rule REJECTS all (do this at very last step)
try_exec_cmd "/usr/sbin/iptables -P INPUT DROP"
try_exec_cmd "/usr/sbin/iptables -A INPUT -j REJECT"
if {$has_ip6tables} {
try_exec_cmd "/usr/sbin/ip6tables -P INPUT DROP"
try_exec_cmd "/usr/sbin/ip6tables -A INPUT -j REJECT"
}
}
##
# @fn exec_cmd
# Prüft ob es sich um eine IPv4 Adresse handelt. Gibt 1 zurück bei IPv4, ansonsten 0.
##
proc FirewallInternal::IsIPV4 { address } {
if { [string first "." $address] == -1 } {
return 0
} else {
return 1
}
}
##
# @fn exec_cmd
# Führt eine Kommandozeile aus
##
proc exec_cmd {cmdline} {
set fd [open "|$cmdline" r]
close $fd
}
##
# @fn exec_cmd
# Führt eine Kommandozeile aus
##
proc try_exec_cmd {cmdline} {
global Firewall_LOG_ENABLED
if { [ catch {
set fd [open "|$cmdline" r]
close $fd
} err ] } {
catch { close $fd }
if { $Firewall_LOG_ENABLED == 1 } {
catch { [exec logger -t firewall -p user.info $err] }
}
}
}
##
# @fn array_clear
# Löscht die Elemente in einem Array
##
proc array_clear {name} {
upvar $name arr
foreach key [array names arr] {
unset arr($key)
}
}
##
# @fn array_getValue
# Liefert einen Wert aus einem Array
# Ist der Wert nicht vorhanden, wird {} zurückgegeben
##
proc array_getValue { pArray name } {
upvar $pArray arr
set value {}
catch { set value $arr($name) }
return $value
}