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");
190 # Flush LOCATIONBLOCK chain.
191 run
("$IPTABLES -F LOCATIONBLOCK");
197 # Search for targets that need to be specially handled when adding
198 # forwarding rules. Additional rules will automatically get inserted
199 # into the INPUT/OUTPUT chains for these targets.
200 my @special_input_targets = ();
201 if (!$POLICY_FORWARD_ALLOWED) {
202 push(@special_input_targets, "ACCEPT");
205 if ($POLICY_INPUT_ACTION eq "DROP") {
206 push(@special_input_targets, ("ACCEPT", "REJECT"));
207 } elsif ($POLICY_INPUT_ACTION eq "REJECT") {
208 push(@special_input_targets, ("ACCEPT", "DROP"));
211 my @special_output_targets = ();
212 if ($POLICY_OUTPUT_ALLOWED) {
213 push(@special_output_targets, ("DROP", "REJECT"));
215 push(@special_output_targets, "ACCEPT");
217 if ($POLICY_OUTPUT_ACTION eq "DROP") {
218 push(@special_output_targets, ("ACCEPT", "REJECT"));
219 } elsif ($POLICY_OUTPUT_ACTION eq "REJECT") {
220 push(@special_output_targets, ("ACCEPT", "DROP"));
224 foreach my $key (sort {$a <=> $b} keys %$hash) {
225 # Skip disabled rules.
226 next unless ($$hash{$key}[2] eq 'ON');
228 # Count number of elements in this line
229 my $elements = &count_elements
($$hash{$key});
232 print_rule
($$hash{$key});
235 # Check if the target is valid.
236 my $target = $$hash{$key}[0];
237 if (!$target ~~ @VALID_TARGETS) {
238 print_error
("Invalid target '$target' for rule $key");
242 # Check if the chain is valid.
243 my $chain = $$hash{$key}[1];
244 if (!$chain ~~ @VALID_CHAINS) {
245 print_error
("Invalid chain '$chain' in rule $key");
249 # Collect all sources.
250 my @sources = &fwlib
::get_addresses
($hash, $key, "src");
252 # Collect all destinations.
253 my @destinations = &fwlib
::get_addresses
($hash, $key, "tgt");
255 # True if the destination is the firewall itself.
256 my $destination_is_firewall = ($$hash{$key}[5] eq "ipfire");
258 # Check if logging should be enabled.
259 my $LOG = ($$hash{$key}[17] eq 'ON');
261 # Check if NAT is enabled and initialize variables, that we use for that.
262 my $NAT = ($$hash{$key}[28] eq 'ON');
265 $NAT_MODE = uc($$hash{$key}[31]);
268 # Set up time constraints.
269 my @time_options = ();
270 if ($$hash{$key}[18] eq 'ON') {
271 push(@time_options, ("-m", "time"));
273 # Select all days of the week this match is active.
275 if ($$hash{$key}[19] ne '') {
276 push (@weekdays, "Mon");
278 if ($$hash{$key}[20] ne '') {
279 push (@weekdays, "Tue");
281 if ($$hash{$key}[21] ne '') {
282 push (@weekdays, "Wed");
284 if ($$hash{$key}[22] ne '') {
285 push (@weekdays, "Thu");
287 if ($$hash{$key}[23] ne '') {
288 push (@weekdays, "Fri");
290 if ($$hash{$key}[24] ne '') {
291 push (@weekdays, "Sat");
293 if ($$hash{$key}[25] ne '') {
294 push (@weekdays, "Sun");
297 push(@time_options, ("--weekdays", join(",", @weekdays)));
300 # Convert start time.
301 my $time_start = &format_time
($$hash{$key}[26]);
303 push(@time_options, ("--timestart", $time_start));
307 my $time_stop = &format_time
($$hash{$key}[27]);
309 push(@time_options, ("--timestop", $time_stop));
313 # Concurrent connection limit
314 my @ratelimit_options = ();
316 if (($elements ge 34) && ($$hash{$key}[32] eq 'ON')) {
317 my $conn_limit = $$hash{$key}[33];
319 if ($conn_limit ge 1) {
320 push(@ratelimit_options, ("-m", "connlimit"));
322 # Use the the entire source IP address
323 push(@ratelimit_options, "--connlimit-saddr");
324 push(@ratelimit_options, ("--connlimit-mask", "32"));
327 push(@ratelimit_options, ("--connlimit-upto", $conn_limit));
332 if (($elements ge 37) && ($$hash{$key}[34] eq 'ON')) {
333 my $rate_limit = "$$hash{$key}[35]/$$hash{$key}[36]";
336 push(@ratelimit_options, ("-m", "limit"));
337 push(@ratelimit_options, ("--limit", $rate_limit));
341 # Check which protocols are used in this rule and so that we can
342 # later group rules by protocols.
343 my @protocols = &get_protocols
($hash, $key);
345 print_error
("Invalid protocol configuration for rule $key");
349 foreach my $protocol (@protocols) {
350 # Check if the given protocol is supported.
351 if (($protocol ne "all") && (!$protocol ~~ @PROTOCOLS)) {
352 print_error
("Protocol $protocol is not supported (rule $key)");
356 # Prepare protocol options (like ICMP types, ports, etc...).
357 my @protocol_options = &get_protocol_options
($hash, $key, $protocol, 0);
359 # Check if this protocol knows ports.
360 my $protocol_has_ports = ($protocol ~~ @PROTOCOLS_WITH_PORTS);
362 foreach my $src (@sources) {
363 # Skip invalid source.
364 next unless (defined $src);
368 my $source = @
$src[0];
369 if ($source ~~ @ANY_ADDRESSES) {
373 my $source_intf = @
$src[1];
375 foreach my $dst (@destinations) {
376 # Skip invalid rules.
377 next unless (defined $dst);
378 next if (!$dst || ($dst eq "none"));
380 # Sanitize destination.
381 my $destination = @
$dst[0];
382 if ($destination ~~ @ANY_ADDRESSES) {
386 my $destination_intf = @
$dst[1];
388 # Array with iptables arguments.
392 if ($protocol ne "all") {
393 push(@options, @protocol_options);
396 # Prepare source options.
397 my @source_options = ();
398 if ($source =~ /mac/) {
399 push(@source_options, $source);
400 } elsif ($source =~ /-m geoip/) {
401 push(@source_options, $source);
403 push(@source_options, ("-s", $source));
406 # Prepare destination options.
407 my @destination_options = ();
408 if ($destination =~ /-m geoip/) {
409 push(@destination_options, $destination);
410 } elsif ($destination) {
411 push(@destination_options, ("-d", $destination));
414 # Add source and destination interface to the filter rules.
415 # These are supposed to help filtering forged packets that originate
416 # from BLUE with an IP address from GREEN for instance.
417 my @source_intf_options = ();
419 push(@source_intf_options, ("-i", $source_intf));
422 my @destination_intf_options = ();
423 if ($destination_intf) {
424 push(@destination_intf_options, ("-o", $destination_intf));
427 # Add time constraint options.
428 push(@options, @time_options);
430 # Add ratelimiting option
431 push(@options, @ratelimit_options);
433 my $firewall_is_in_source_subnet = 1;
435 $firewall_is_in_source_subnet = &firewall_is_in_subnet
($source);
438 my $firewall_is_in_destination_subnet = 1;
440 $firewall_is_in_destination_subnet = &firewall_is_in_subnet
($destination);
445 my $nat_address = &fwlib
::get_nat_address
($$hash{$key}[29], $source);
447 # Skip NAT rules if the NAT address is unknown
448 # (i.e. no internet connection has been established, yet).
449 next unless ($nat_address);
452 if ($NAT_MODE eq "DNAT") {
453 my @nat_options = ();
454 if ($protocol ne "all") {
455 my @nat_protocol_options = &get_protocol_options
($hash, $key, $protocol, 1);
456 push(@nat_options, @nat_protocol_options);
460 push(@nat_options, @time_options);
462 # Determine if a REDIRECT rule should be created.
463 my $use_redirect = ($destination_is_firewall && !$destination && $protocol_has_ports);
465 # Make port-forwardings useable from the internal networks.
466 if (!$use_redirect) {
467 my @internal_addresses = &fwlib
::get_internal_firewall_ip_addresses
(1);
468 unless ($nat_address ~~ @internal_addresses) {
469 &add_dnat_mangle_rules
($nat_address, $source_intf, @nat_options);
473 # Add source options.
474 push(@nat_options, @source_options);
477 if (!$use_redirect) {
478 push(@nat_options, ("-d", $nat_address));
482 if ($protocol_has_ports) {
483 $dnat_port = &get_dnat_target_port
($hash, $key);
486 my @nat_action_options = ();
488 # Use iptables REDIRECT
490 push(@nat_action_options, ("-j", "REDIRECT"));
492 # Redirect to specified port if one has given.
494 push(@nat_action_options, ("--to-ports", $dnat_port));
499 if ($destination_is_firewall && !$destination) {
500 $destination = &fwlib
::get_external_address
();
502 next unless ($destination);
504 my ($dnat_address, $dnat_mask) = split("/", $destination);
505 @destination_options = ("-d", $dnat_address);
507 if ($protocol_has_ports) {
508 my $dnat_port = &get_dnat_target_port
($hash, $key);
511 $dnat_address .= ":$dnat_port";
515 push(@nat_action_options, ("-j", "DNAT", "--to-destination", $dnat_address));
519 run
("$IPTABLES -t nat -A $CHAIN_NAT_DESTINATION @nat_options @log_limit_options -j LOG --log-prefix 'DNAT '");
521 run
("$IPTABLES -t nat -A $CHAIN_NAT_DESTINATION @nat_options @nat_action_options");
524 } elsif ($NAT_MODE eq "SNAT") {
525 my @snat_options = ( "-m", "policy", "--dir", "out", "--pol", "none" );
526 my @nat_options = @options;
528 # Get addresses for the configured firewall interfaces.
529 my @local_addresses = &fwlib
::get_internal_firewall_ip_addresses
(1);
531 # Check if the nat_address is one of the local addresses.
532 foreach my $local_address (@local_addresses) {
533 if ($nat_address eq $local_address) {
534 # Clear SNAT options.
542 push(@nat_options, @destination_intf_options);
543 push(@nat_options, @source_options);
544 push(@nat_options, @destination_options);
547 run
("$IPTABLES -t nat -A $CHAIN_NAT_SOURCE @nat_options @snat_options @log_limit_options -j LOG --log-prefix 'SNAT '");
549 run
("$IPTABLES -t nat -A $CHAIN_NAT_SOURCE @nat_options @snat_options -j SNAT --to-source $nat_address");
553 push(@options, @source_options);
554 push(@options, @destination_options);
556 # Insert firewall rule.
558 run
("$IPTABLES -A $chain @options @source_intf_options @destination_intf_options @log_limit_options -j LOG --log-prefix '$chain '");
560 run
("$IPTABLES -A $chain @options @source_intf_options @destination_intf_options -j $target");
562 # Handle forwarding rules and add corresponding rules for firewall access.
563 if ($chain eq $CHAIN_FORWARD) {
564 # If the firewall is part of the destination subnet and access to the destination network
565 # is granted/forbidden for any network that the firewall itself is part of, we grant/forbid access
566 # for the firewall, too.
567 if ($firewall_is_in_destination_subnet && ($target ~~ @special_input_targets)) {
569 run
("$IPTABLES -A $CHAIN_INPUT @options @source_intf_options @log_limit_options -j LOG --log-prefix '$CHAIN_INPUT '");
571 run
("$IPTABLES -A $CHAIN_INPUT @options @source_intf_options -j $target");
575 if ($firewall_is_in_source_subnet && ($target ~~ @special_output_targets)) {
577 run
("$IPTABLES -A $CHAIN_OUTPUT @options @destination_intf_options @log_limit_options -j LOG --log-prefix '$CHAIN_OUTPUT '");
579 run
("$IPTABLES -A $CHAIN_OUTPUT @options @destination_intf_options -j $target");
588 # Formats the given timestamp into the iptables format which is "hh:mm" UTC.
592 # Convert the given time into minutes.
593 my $minutes = &time_convert_to_minutes
($val);
595 # Move the timestamp into UTC.
596 $minutes += &time_utc_offset
();
598 # Make sure $minutes is between 00:00 and 23:59.
603 if ($minutes > 1440) {
608 return sprintf("%02d:%02d", $minutes / 60, $minutes % 60);
611 # Calculates the offsets in minutes from the local timezone to UTC.
612 sub time_utc_offset
{
613 my @localtime = localtime(time);
614 my @gmtime = gmtime(time);
616 return ($gmtime[2] * 60 + $gmtime[1] % 60) - ($localtime[2] * 60 + $localtime[1] % 60);
619 # Takes a timestamp like "14:00" and converts it into minutes since midnight.
620 sub time_convert_to_minutes
{
621 my ($hrs, $min) = split(":", shift);
623 return ($hrs * 60) + $min;
627 open(FILE
, "<$p2pfile") or die "Unable to read $p2pfile";
629 foreach my $p2pentry (<FILE
>) {
630 my @p2pline = split(/\;/, $p2pentry);
631 next unless ($p2pline[2] eq "off");
633 push(@protocols, "--$p2pline[1]");
637 run
("$IPTABLES -F P2PBLOCK");
639 run
("$IPTABLES -A P2PBLOCK -m ipp2p @protocols -j DROP");
644 # The LOCATIONBLOCK chain now gets flushed by the flush() function.
646 # If location blocking is not enabled, we are finished here.
647 if ($locationsettings{'LOCATIONBLOCK_ENABLED'} ne "on") {
648 # Exit submodule. Process remaining script.
652 # Only check the RED interface, which is ppp0 in case of RED_TYPE being
653 # set to "PPPOE", and red0 in case of RED_TYPE not being empty otherwise.
654 if ($defaultNetworks{'RED_TYPE'} eq "PPPOE") {
655 run
("$IPTABLES -A LOCATIONBLOCK ! -i ppp0 -j RETURN");
656 } elsif ($defaultNetworks{'RED_DEV'} ne "") {
657 run
("$IPTABLES -A LOCATIONBLOCK ! -i $defaultNetworks{'RED_DEV'} -j RETURN");
660 # Do not check any private address space
661 foreach my $network (@PRIVATE_NETWORKS) {
662 run
("$IPTABLES -A LOCATIONBLOCK -s $network -j RETURN");
665 # Loop through all supported locations and
666 # create iptables rules, if blocking for this country
668 foreach my $location (@locations) {
669 if(exists $locationsettings{$location} && $locationsettings{$location} eq "on") {
670 run
("$IPTABLES -A LOCATIONBLOCK -m geoip --src-cc $location -j DROP");
679 my $uses_source_ports = ($$hash{$key}[7] eq "ON");
680 my $uses_services = ($$hash{$key}[11] eq "ON");
684 # Rules which don't have source ports or services (like ICMP, ESP, ...).
685 if (!$uses_source_ports && !$uses_services) {
686 push(@protocols, $$hash{$key}[8]);
688 # Rules which either use ports or services.
689 } elsif ($uses_source_ports || $uses_services) {
690 # Check if service group or service
691 if ($$hash{$key}[14] eq 'cust_srv') {
692 push(@protocols, &fwlib
::get_srv_prot
($$hash{$key}[15]));
694 } elsif($$hash{$key}[14] eq 'cust_srvgrp'){
695 my $protos = &fwlib
::get_srvgrp_prot
($$hash{$key}[15]);
696 push(@protocols, split(",", $protos));
699 # Fetch the protocol for this rule.
700 my $protocol = lc($$hash{$key}[8]);
702 # Fetch source and destination ports for this rule.
703 my $source_ports = $$hash{$key}[10];
704 my $destination_ports = $$hash{$key}[15];
706 # Check if ports are set for protocols which do not support ports.
707 if (!($protocol ~~ @PROTOCOLS_WITH_PORTS) && ($source_ports || $destination_ports)) {
708 print_error
("$protocol does not support ports");
712 push(@protocols, $protocol);
716 # Remove all empty elements
717 @protocols = map { $_ ?
$_ : () } @protocols;
719 # If no protocol has been defined, we assume "all".
721 push(@protocols, "all");
724 # Make all protocol names lowercase.
725 @protocols = map { lc } @protocols;
730 sub get_protocol_options
{
733 my $protocol = shift;
734 my $nat_options_wanted = shift;
737 # Nothing to do if no protocol is specified.
738 if ($protocol eq "all") {
741 push(@options, ("-p", $protocol));
744 if ($protocol ~~ @PROTOCOLS_WITH_PORTS) {
745 # Process source ports.
746 my $use_src_ports = ($$hash{$key}[7] eq "ON");
747 my $src_ports = $$hash{$key}[10];
749 if ($use_src_ports && $src_ports) {
750 push(@options, &format_ports
($src_ports, "src"));
753 # Process destination ports.
754 my $use_dst_ports = ($$hash{$key}[11] eq "ON");
755 my $use_dnat = (($$hash{$key}[28] eq "ON") && ($$hash{$key}[31] eq "dnat"));
757 if ($use_dst_ports) {
758 my $dst_ports_mode = $$hash{$key}[14];
759 my $dst_ports = $$hash{$key}[15];
761 if (($dst_ports_mode eq "TGT_PORT") && $dst_ports) {
762 if ($nat_options_wanted && $use_dnat && $$hash{$key}[30]) {
763 $dst_ports = $$hash{$key}[30];
765 push(@options, &format_ports
($dst_ports, "dst"));
767 } elsif ($dst_ports_mode eq "cust_srv") {
768 if ($protocol eq "ICMP") {
769 push(@options, ("--icmp-type", &fwlib
::get_srv_port
($dst_ports, 3, "ICMP")));
771 $dst_ports = &fwlib
::get_srv_port
($dst_ports, 1, uc($protocol));
772 push(@options, &format_ports
($dst_ports, "dst"));
775 } elsif ($dst_ports_mode eq "cust_srvgrp") {
776 push(@options, &fwlib
::get_srvgrp_port
($dst_ports, uc($protocol)));
781 # Check if a single ICMP type is selected.
782 if ($protocol eq "icmp") {
783 my $icmp_type = $$hash{$key}[9];
785 if (($icmp_type ne "All ICMP-Types") && $icmp_type) {
786 push(@options, ("--icmp-type", $icmp_type));
798 if ($type eq "src") {
800 } elsif ($type eq "dst") {
806 if ($ports =~ /\|/) {
808 push(@options, ("-m", "multiport"));
812 push(@options, ($arg, $ports));
818 sub get_dnat_target_port
{
822 if ($$hash{$key}[14] eq "TGT_PORT") {
823 my $port = $$hash{$key}[15];
824 my $external_port = $$hash{$key}[30];
826 if ($external_port && ($port ne $external_port)) {
827 return $$hash{$key}[15];
832 sub add_dnat_mangle_rules
{
833 my $nat_address = shift;
834 my $interface = shift;
837 my $mark = 0x01000000;
838 foreach my $zone ("GREEN", "BLUE", "ORANGE") {
839 # Skip rule if not all required information exists.
840 next unless (exists $defaultNetworks{$zone . "_NETADDRESS"});
841 next unless (exists $defaultNetworks{$zone . "_NETMASK"});
843 next if ($interface && $interface ne $defaultNetworks{$zone . "_DEV"});
845 my @mangle_options = @options;
847 my $netaddress = $defaultNetworks{$zone . "_NETADDRESS"};
848 $netaddress .= "/" . $defaultNetworks{$zone . "_NETMASK"};
850 push(@mangle_options, ("-s", $netaddress, "-d", $nat_address));
851 push(@mangle_options, ("-j", "MARK", "--set-xmark", "$mark/$NAT_MASK"));
853 run
("$IPTABLES -t mangle -A $CHAIN_MANGLE_NAT_DESTINATION_FIX @mangle_options");
859 sub make_log_limit_options
{
860 my @options = ("-m", "limit");
862 # Maybe we should get this from the configuration.
865 # We limit log messages to $limit messages per second.
866 push(@options, ("--limit", "$limit/second"));
868 # And we allow bursts of 2x $limit.
869 push(@options, ("--limit-burst", $limit * 2));
874 sub firewall_is_in_subnet
{
877 # ORANGE is missing here, because nothing may ever access
878 # the firewall from this network.
879 my $address = &fwlib
::get_internal_firewall_ip_address
($subnet, 0);