2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2020 IPFire Team <info@ipfire.org> #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
23 use experimental
'smartmatch';
25 require '/var/ipfire/general-functions.pl';
26 require "${General::swroot}/lang.pl";
27 require "/usr/lib/firewall/firewall-lib.pl";
28 require "${General::swroot}/location-functions.pl";
30 # Set to one to enable debugging mode.
33 my $IPTABLES = "iptables --wait";
36 my $CHAIN_INPUT = "INPUTFW";
37 my $CHAIN_FORWARD = "FORWARDFW";
38 my $CHAIN_OUTPUT = "OUTGOINGFW";
39 my $CHAIN = $CHAIN_FORWARD;
40 my $CHAIN_NAT_SOURCE = "NAT_SOURCE";
41 my $CHAIN_NAT_DESTINATION = "NAT_DESTINATION";
42 my $CHAIN_MANGLE_NAT_DESTINATION_FIX = "NAT_DESTINATION";
43 my @VALID_CHAINS = ($CHAIN_INPUT, $CHAIN_FORWARD, $CHAIN_OUTPUT);
44 my @ANY_ADDRESSES = ("0.0.0.0/0.0.0.0", "0.0.0.0/0", "0/0");
46 my @PROTOCOLS = ("tcp", "udp", "icmp", "igmp", "ah", "esp", "gre", "ipv6", "ipip");
47 my @PROTOCOLS_WITH_PORTS = ("tcp", "udp");
49 my @VALID_TARGETS = ("ACCEPT", "DROP", "REJECT");
51 my @PRIVATE_NETWORKS = (
59 my $NAT_MASK = 0x0f000000;
63 my %defaultNetworks=();
67 my %configoutgoingfw=();
69 my %locationsettings = (
70 "LOCATIONBLOCK_ENABLED" => "off"
75 my $configfwdfw = "${General::swroot}/firewall/config";
76 my $configinput = "${General::swroot}/firewall/input";
77 my $configoutgoing = "${General::swroot}/firewall/outgoing";
78 my $p2pfile = "${General::swroot}/firewall/p2protocols";
79 my $locationfile = "${General::swroot}/firewall/locationblock";
80 my $configgrp = "${General::swroot}/fwhosts/customgroups";
81 my $netsettings = "${General::swroot}/ethernet/settings";
83 &General
::readhash
("${General::swroot}/firewall/settings", \
%fwdfwsettings);
84 &General
::readhash
("${General::swroot}/optionsfw/settings", \
%fwoptions);
85 &General
::readhash
("$netsettings", \
%defaultNetworks);
86 &General
::readhasharray
($configfwdfw, \
%configfwdfw);
87 &General
::readhasharray
($configinput, \
%configinputfw);
88 &General
::readhasharray
($configoutgoing, \
%configoutgoingfw);
89 &General
::readhasharray
($configgrp, \
%customgrp);
91 # Check if the location settings file exists
92 if (-e
"$locationfile") {
94 &General
::readhash
("$locationfile", \
%locationsettings);
97 # Get all available locations.
98 my @locations = &Location
::Functions
::get_locations
();
100 my @log_limit_options = &make_log_limit_options
();
102 my $POLICY_INPUT_ALLOWED = 0;
103 my $POLICY_FORWARD_ALLOWED = ($fwdfwsettings{"POLICY"} eq "MODE2");
104 my $POLICY_OUTPUT_ALLOWED = ($fwdfwsettings{"POLICY1"} eq "MODE2");
106 my $POLICY_INPUT_ACTION = $fwoptions{"FWPOLICY2"};
107 my $POLICY_FORWARD_ACTION = $fwoptions{"FWPOLICY"};
108 my $POLICY_OUTPUT_ACTION = $fwoptions{"FWPOLICY1"};
117 # Prepare firewall rules.
118 if (! -z
"${General::swroot}/firewall/input"){
119 &buildrules
(\
%configinputfw);
121 if (! -z
"${General::swroot}/firewall/outgoing"){
122 &buildrules
(\
%configoutgoingfw);
124 if (! -z
"${General::swroot}/firewall/config"){
125 &buildrules
(\
%configfwdfw);
128 # Load P2P block rules.
131 # Load Location block rules.
134 # Reload firewall policy.
135 run
("/usr/sbin/firewall-policy");
137 #Reload firewall.local if present
138 if ( -f
'/etc/sysconfig/firewall.local'){
139 run
("/etc/sysconfig/firewall.local reload");
144 # Executes or prints the given shell command.
153 print_error
("ERROR: $command");
161 print STDERR
"$message\n";
171 printf(" %2d: %s", $i++, $_);
179 return scalar @
$hash;
183 run
("$IPTABLES -F $CHAIN_INPUT");
184 run
("$IPTABLES -F $CHAIN_FORWARD");
185 run
("$IPTABLES -F $CHAIN_OUTPUT");
186 run
("$IPTABLES -t nat -F $CHAIN_NAT_SOURCE");
187 run
("$IPTABLES -t nat -F $CHAIN_NAT_DESTINATION");
188 run
("$IPTABLES -t mangle -F $CHAIN_MANGLE_NAT_DESTINATION_FIX");
194 # Search for targets that need to be specially handled when adding
195 # forwarding rules. Additional rules will automatically get inserted
196 # into the INPUT/OUTPUT chains for these targets.
197 my @special_input_targets = ();
198 if (!$POLICY_FORWARD_ALLOWED) {
199 push(@special_input_targets, "ACCEPT");
202 if ($POLICY_INPUT_ACTION eq "DROP") {
203 push(@special_input_targets, ("ACCEPT", "REJECT"));
204 } elsif ($POLICY_INPUT_ACTION eq "REJECT") {
205 push(@special_input_targets, ("ACCEPT", "DROP"));
208 my @special_output_targets = ();
209 if ($POLICY_OUTPUT_ALLOWED) {
210 push(@special_output_targets, ("DROP", "REJECT"));
212 push(@special_output_targets, "ACCEPT");
214 if ($POLICY_OUTPUT_ACTION eq "DROP") {
215 push(@special_output_targets, ("ACCEPT", "REJECT"));
216 } elsif ($POLICY_OUTPUT_ACTION eq "REJECT") {
217 push(@special_output_targets, ("ACCEPT", "DROP"));
221 foreach my $key (sort {$a <=> $b} keys %$hash) {
222 # Skip disabled rules.
223 next unless ($$hash{$key}[2] eq 'ON');
225 # Count number of elements in this line
226 my $elements = &count_elements
($$hash{$key});
229 print_rule
($$hash{$key});
232 # Check if the target is valid.
233 my $target = $$hash{$key}[0];
234 if (!$target ~~ @VALID_TARGETS) {
235 print_error
("Invalid target '$target' for rule $key");
239 # Check if the chain is valid.
240 my $chain = $$hash{$key}[1];
241 if (!$chain ~~ @VALID_CHAINS) {
242 print_error
("Invalid chain '$chain' in rule $key");
246 # Collect all sources.
247 my @sources = &fwlib
::get_addresses
($hash, $key, "src");
249 # Collect all destinations.
250 my @destinations = &fwlib
::get_addresses
($hash, $key, "tgt");
252 # True if the destination is the firewall itself.
253 my $destination_is_firewall = ($$hash{$key}[5] eq "ipfire");
255 # Check if logging should be enabled.
256 my $LOG = ($$hash{$key}[17] eq 'ON');
258 # Check if NAT is enabled and initialize variables, that we use for that.
259 my $NAT = ($$hash{$key}[28] eq 'ON');
262 $NAT_MODE = uc($$hash{$key}[31]);
265 # Set up time constraints.
266 my @time_options = ();
267 if ($$hash{$key}[18] eq 'ON') {
268 push(@time_options, ("-m", "time"));
270 # Select all days of the week this match is active.
272 if ($$hash{$key}[19] ne '') {
273 push (@weekdays, "Mon");
275 if ($$hash{$key}[20] ne '') {
276 push (@weekdays, "Tue");
278 if ($$hash{$key}[21] ne '') {
279 push (@weekdays, "Wed");
281 if ($$hash{$key}[22] ne '') {
282 push (@weekdays, "Thu");
284 if ($$hash{$key}[23] ne '') {
285 push (@weekdays, "Fri");
287 if ($$hash{$key}[24] ne '') {
288 push (@weekdays, "Sat");
290 if ($$hash{$key}[25] ne '') {
291 push (@weekdays, "Sun");
294 push(@time_options, ("--weekdays", join(",", @weekdays)));
297 # Convert start time.
298 my $time_start = &format_time
($$hash{$key}[26]);
300 push(@time_options, ("--timestart", $time_start));
304 my $time_stop = &format_time
($$hash{$key}[27]);
306 push(@time_options, ("--timestop", $time_stop));
310 # Concurrent connection limit
311 my @ratelimit_options = ();
313 if (($elements ge 34) && ($$hash{$key}[32] eq 'ON')) {
314 my $conn_limit = $$hash{$key}[33];
316 if ($conn_limit ge 1) {
317 push(@ratelimit_options, ("-m", "connlimit"));
319 # Use the the entire source IP address
320 push(@ratelimit_options, "--connlimit-saddr");
321 push(@ratelimit_options, ("--connlimit-mask", "32"));
324 push(@ratelimit_options, ("--connlimit-upto", $conn_limit));
329 if (($elements ge 37) && ($$hash{$key}[34] eq 'ON')) {
330 my $rate_limit = "$$hash{$key}[35]/$$hash{$key}[36]";
333 push(@ratelimit_options, ("-m", "limit"));
334 push(@ratelimit_options, ("--limit", $rate_limit));
338 # Check which protocols are used in this rule and so that we can
339 # later group rules by protocols.
340 my @protocols = &get_protocols
($hash, $key);
342 print_error
("Invalid protocol configuration for rule $key");
346 foreach my $protocol (@protocols) {
347 # Check if the given protocol is supported.
348 if (($protocol ne "all") && (!$protocol ~~ @PROTOCOLS)) {
349 print_error
("Protocol $protocol is not supported (rule $key)");
353 # Prepare protocol options (like ICMP types, ports, etc...).
354 my @protocol_options = &get_protocol_options
($hash, $key, $protocol, 0);
356 # Check if this protocol knows ports.
357 my $protocol_has_ports = ($protocol ~~ @PROTOCOLS_WITH_PORTS);
359 foreach my $src (@sources) {
360 # Skip invalid source.
361 next unless (defined $src);
365 my $source = @
$src[0];
366 if ($source ~~ @ANY_ADDRESSES) {
370 my $source_intf = @
$src[1];
372 foreach my $dst (@destinations) {
373 # Skip invalid rules.
374 next unless (defined $dst);
375 next if (!$dst || ($dst eq "none"));
377 # Sanitize destination.
378 my $destination = @
$dst[0];
379 if ($destination ~~ @ANY_ADDRESSES) {
383 my $destination_intf = @
$dst[1];
385 # Array with iptables arguments.
389 if ($protocol ne "all") {
390 push(@options, @protocol_options);
393 # Prepare source options.
394 my @source_options = ();
395 if ($source =~ /mac/) {
396 push(@source_options, $source);
397 } elsif ($source =~ /-m geoip/) {
398 push(@source_options, $source);
400 push(@source_options, ("-s", $source));
403 # Prepare destination options.
404 my @destination_options = ();
405 if ($destination =~ /-m geoip/) {
406 push(@destination_options, $destination);
407 } elsif ($destination) {
408 push(@destination_options, ("-d", $destination));
411 # Add source and destination interface to the filter rules.
412 # These are supposed to help filtering forged packets that originate
413 # from BLUE with an IP address from GREEN for instance.
414 my @source_intf_options = ();
416 push(@source_intf_options, ("-i", $source_intf));
419 my @destination_intf_options = ();
420 if ($destination_intf) {
421 push(@destination_intf_options, ("-o", $destination_intf));
424 # Add time constraint options.
425 push(@options, @time_options);
427 # Add ratelimiting option
428 push(@options, @ratelimit_options);
430 my $firewall_is_in_source_subnet = 1;
432 $firewall_is_in_source_subnet = &firewall_is_in_subnet
($source);
435 my $firewall_is_in_destination_subnet = 1;
437 $firewall_is_in_destination_subnet = &firewall_is_in_subnet
($destination);
442 my $nat_address = &fwlib
::get_nat_address
($$hash{$key}[29], $source);
444 # Skip NAT rules if the NAT address is unknown
445 # (i.e. no internet connection has been established, yet).
446 next unless ($nat_address);
449 if ($NAT_MODE eq "DNAT") {
450 my @nat_options = ();
451 if ($protocol ne "all") {
452 my @nat_protocol_options = &get_protocol_options
($hash, $key, $protocol, 1);
453 push(@nat_options, @nat_protocol_options);
457 push(@nat_options, @time_options);
459 # Determine if a REDIRECT rule should be created.
460 my $use_redirect = ($destination_is_firewall && !$destination && $protocol_has_ports);
462 # Make port-forwardings useable from the internal networks.
463 if (!$use_redirect) {
464 my @internal_addresses = &fwlib
::get_internal_firewall_ip_addresses
(1);
465 unless ($nat_address ~~ @internal_addresses) {
466 &add_dnat_mangle_rules
($nat_address, $source_intf, @nat_options);
470 # Add source options.
471 push(@nat_options, @source_options);
474 if (!$use_redirect) {
475 push(@nat_options, ("-d", $nat_address));
479 if ($protocol_has_ports) {
480 $dnat_port = &get_dnat_target_port
($hash, $key);
483 my @nat_action_options = ();
485 # Use iptables REDIRECT
487 push(@nat_action_options, ("-j", "REDIRECT"));
489 # Redirect to specified port if one has given.
491 push(@nat_action_options, ("--to-ports", $dnat_port));
496 if ($destination_is_firewall && !$destination) {
497 $destination = &fwlib
::get_external_address
();
499 next unless ($destination);
501 my ($dnat_address, $dnat_mask) = split("/", $destination);
502 @destination_options = ("-d", $dnat_address);
504 if ($protocol_has_ports) {
505 my $dnat_port = &get_dnat_target_port
($hash, $key);
508 $dnat_address .= ":$dnat_port";
512 push(@nat_action_options, ("-j", "DNAT", "--to-destination", $dnat_address));
516 run
("$IPTABLES -t nat -A $CHAIN_NAT_DESTINATION @nat_options @log_limit_options -j LOG --log-prefix 'DNAT '");
518 run
("$IPTABLES -t nat -A $CHAIN_NAT_DESTINATION @nat_options @nat_action_options");
521 } elsif ($NAT_MODE eq "SNAT") {
522 my @snat_options = ( "-m", "policy", "--dir", "out", "--pol", "none" );
523 my @nat_options = @options;
525 # Get addresses for the configured firewall interfaces.
526 my @local_addresses = &fwlib
::get_internal_firewall_ip_addresses
(1);
528 # Check if the nat_address is one of the local addresses.
529 foreach my $local_address (@local_addresses) {
530 if ($nat_address eq $local_address) {
531 # Clear SNAT options.
539 push(@nat_options, @destination_intf_options);
540 push(@nat_options, @source_options);
541 push(@nat_options, @destination_options);
544 run
("$IPTABLES -t nat -A $CHAIN_NAT_SOURCE @nat_options @snat_options @log_limit_options -j LOG --log-prefix 'SNAT '");
546 run
("$IPTABLES -t nat -A $CHAIN_NAT_SOURCE @nat_options @snat_options -j SNAT --to-source $nat_address");
550 push(@options, @source_options);
551 push(@options, @destination_options);
553 # Insert firewall rule.
555 run
("$IPTABLES -A $chain @options @source_intf_options @destination_intf_options @log_limit_options -j LOG --log-prefix '$chain '");
557 run
("$IPTABLES -A $chain @options @source_intf_options @destination_intf_options -j $target");
559 # Handle forwarding rules and add corresponding rules for firewall access.
560 if ($chain eq $CHAIN_FORWARD) {
561 # If the firewall is part of the destination subnet and access to the destination network
562 # is granted/forbidden for any network that the firewall itself is part of, we grant/forbid access
563 # for the firewall, too.
564 if ($firewall_is_in_destination_subnet && ($target ~~ @special_input_targets)) {
566 run
("$IPTABLES -A $CHAIN_INPUT @options @source_intf_options @log_limit_options -j LOG --log-prefix '$CHAIN_INPUT '");
568 run
("$IPTABLES -A $CHAIN_INPUT @options @source_intf_options -j $target");
572 if ($firewall_is_in_source_subnet && ($target ~~ @special_output_targets)) {
574 run
("$IPTABLES -A $CHAIN_OUTPUT @options @destination_intf_options @log_limit_options -j LOG --log-prefix '$CHAIN_OUTPUT '");
576 run
("$IPTABLES -A $CHAIN_OUTPUT @options @destination_intf_options -j $target");
585 # Formats the given timestamp into the iptables format which is "hh:mm" UTC.
589 # Convert the given time into minutes.
590 my $minutes = &time_convert_to_minutes
($val);
592 # Move the timestamp into UTC.
593 $minutes += &time_utc_offset
();
595 # Make sure $minutes is between 00:00 and 23:59.
600 if ($minutes > 1440) {
605 return sprintf("%02d:%02d", $minutes / 60, $minutes % 60);
608 # Calculates the offsets in minutes from the local timezone to UTC.
609 sub time_utc_offset
{
610 my @localtime = localtime(time);
611 my @gmtime = gmtime(time);
613 return ($gmtime[2] * 60 + $gmtime[1] % 60) - ($localtime[2] * 60 + $localtime[1] % 60);
616 # Takes a timestamp like "14:00" and converts it into minutes since midnight.
617 sub time_convert_to_minutes
{
618 my ($hrs, $min) = split(":", shift);
620 return ($hrs * 60) + $min;
624 open(FILE
, "<$p2pfile") or die "Unable to read $p2pfile";
626 foreach my $p2pentry (<FILE
>) {
627 my @p2pline = split(/\;/, $p2pentry);
628 next unless ($p2pline[2] eq "off");
630 push(@protocols, "--$p2pline[1]");
634 run
("$IPTABLES -F P2PBLOCK");
636 run
("$IPTABLES -A P2PBLOCK -m ipp2p @protocols -j DROP");
641 # Flush iptables chain.
642 run
("$IPTABLES -F LOCATIONBLOCK");
644 # If location blocking is not enabled, we are finished here.
645 if ($locationsettings{'LOCATIONBLOCK_ENABLED'} ne "on") {
646 # Exit submodule. Process remaining script.
650 # Only check the RED interface, which is ppp0 in case of RED_TYPE being
651 # set to "PPPOE", and red0 in case of RED_TYPE not being empty otherwise.
652 if ($defaultNetworks{'RED_TYPE'} eq "PPPOE") {
653 run
("$IPTABLES -A LOCATIONBLOCK ! -i ppp0 -j RETURN");
654 } elsif ($defaultNetworks{'RED_DEV'} ne "") {
655 run
("$IPTABLES -A LOCATIONBLOCK ! -i $defaultNetworks{'RED_DEV'} -j RETURN");
658 # Do not check any private address space
659 foreach my $network (@PRIVATE_NETWORKS) {
660 run
("$IPTABLES -A LOCATIONBLOCK -s $network -j RETURN");
663 # Loop through all supported locations and
664 # create iptables rules, if blocking for this country
666 foreach my $location (@locations) {
667 if(exists $locationsettings{$location} && $locationsettings{$location} eq "on") {
668 run
("$IPTABLES -A LOCATIONBLOCK -m geoip --src-cc $location -j DROP");
677 my $uses_source_ports = ($$hash{$key}[7] eq "ON");
678 my $uses_services = ($$hash{$key}[11] eq "ON");
682 # Rules which don't have source ports or services (like ICMP, ESP, ...).
683 if (!$uses_source_ports && !$uses_services) {
684 push(@protocols, $$hash{$key}[8]);
686 # Rules which either use ports or services.
687 } elsif ($uses_source_ports || $uses_services) {
688 # Check if service group or service
689 if ($$hash{$key}[14] eq 'cust_srv') {
690 push(@protocols, &fwlib
::get_srv_prot
($$hash{$key}[15]));
692 } elsif($$hash{$key}[14] eq 'cust_srvgrp'){
693 my $protos = &fwlib
::get_srvgrp_prot
($$hash{$key}[15]);
694 push(@protocols, split(",", $protos));
697 # Fetch the protocol for this rule.
698 my $protocol = lc($$hash{$key}[8]);
700 # Fetch source and destination ports for this rule.
701 my $source_ports = $$hash{$key}[10];
702 my $destination_ports = $$hash{$key}[15];
704 # Check if ports are set for protocols which do not support ports.
705 if (!($protocol ~~ @PROTOCOLS_WITH_PORTS) && ($source_ports || $destination_ports)) {
706 print_error
("$protocol does not support ports");
710 push(@protocols, $protocol);
714 # Remove all empty elements
715 @protocols = map { $_ ?
$_ : () } @protocols;
717 # If no protocol has been defined, we assume "all".
719 push(@protocols, "all");
722 # Make all protocol names lowercase.
723 @protocols = map { lc } @protocols;
728 sub get_protocol_options
{
731 my $protocol = shift;
732 my $nat_options_wanted = shift;
735 # Nothing to do if no protocol is specified.
736 if ($protocol eq "all") {
739 push(@options, ("-p", $protocol));
742 if ($protocol ~~ @PROTOCOLS_WITH_PORTS) {
743 # Process source ports.
744 my $use_src_ports = ($$hash{$key}[7] eq "ON");
745 my $src_ports = $$hash{$key}[10];
747 if ($use_src_ports && $src_ports) {
748 push(@options, &format_ports
($src_ports, "src"));
751 # Process destination ports.
752 my $use_dst_ports = ($$hash{$key}[11] eq "ON");
753 my $use_dnat = (($$hash{$key}[28] eq "ON") && ($$hash{$key}[31] eq "dnat"));
755 if ($use_dst_ports) {
756 my $dst_ports_mode = $$hash{$key}[14];
757 my $dst_ports = $$hash{$key}[15];
759 if (($dst_ports_mode eq "TGT_PORT") && $dst_ports) {
760 if ($nat_options_wanted && $use_dnat && $$hash{$key}[30]) {
761 $dst_ports = $$hash{$key}[30];
763 push(@options, &format_ports
($dst_ports, "dst"));
765 } elsif ($dst_ports_mode eq "cust_srv") {
766 if ($protocol eq "ICMP") {
767 push(@options, ("--icmp-type", &fwlib
::get_srv_port
($dst_ports, 3, "ICMP")));
769 $dst_ports = &fwlib
::get_srv_port
($dst_ports, 1, uc($protocol));
770 push(@options, &format_ports
($dst_ports, "dst"));
773 } elsif ($dst_ports_mode eq "cust_srvgrp") {
774 push(@options, &fwlib
::get_srvgrp_port
($dst_ports, uc($protocol)));
779 # Check if a single ICMP type is selected.
780 if ($protocol eq "icmp") {
781 my $icmp_type = $$hash{$key}[9];
783 if (($icmp_type ne "All ICMP-Types") && $icmp_type) {
784 push(@options, ("--icmp-type", $icmp_type));
796 if ($type eq "src") {
798 } elsif ($type eq "dst") {
804 if ($ports =~ /\|/) {
806 push(@options, ("-m", "multiport"));
810 push(@options, ($arg, $ports));
816 sub get_dnat_target_port
{
820 if ($$hash{$key}[14] eq "TGT_PORT") {
821 my $port = $$hash{$key}[15];
822 my $external_port = $$hash{$key}[30];
824 if ($external_port && ($port ne $external_port)) {
825 return $$hash{$key}[15];
830 sub add_dnat_mangle_rules
{
831 my $nat_address = shift;
832 my $interface = shift;
835 my $mark = 0x01000000;
836 foreach my $zone ("GREEN", "BLUE", "ORANGE") {
837 # Skip rule if not all required information exists.
838 next unless (exists $defaultNetworks{$zone . "_NETADDRESS"});
839 next unless (exists $defaultNetworks{$zone . "_NETMASK"});
841 next if ($interface && $interface ne $defaultNetworks{$zone . "_DEV"});
843 my @mangle_options = @options;
845 my $netaddress = $defaultNetworks{$zone . "_NETADDRESS"};
846 $netaddress .= "/" . $defaultNetworks{$zone . "_NETMASK"};
848 push(@mangle_options, ("-s", $netaddress, "-d", $nat_address));
849 push(@mangle_options, ("-j", "MARK", "--set-xmark", "$mark/$NAT_MASK"));
851 run
("$IPTABLES -t mangle -A $CHAIN_MANGLE_NAT_DESTINATION_FIX @mangle_options");
857 sub make_log_limit_options
{
858 my @options = ("-m", "limit");
860 # Maybe we should get this from the configuration.
863 # We limit log messages to $limit messages per second.
864 push(@options, ("--limit", "$limit/second"));
866 # And we allow bursts of 2x $limit.
867 push(@options, ("--limit-burst", $limit * 2));
872 sub firewall_is_in_subnet
{
875 # ORANGE is missing here, because nothing may ever access
876 # the firewall from this network.
877 my $address = &fwlib
::get_internal_firewall_ip_address
($subnet, 0);