]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
BUG10615 part3: adapt rules.pl to use connectionlimit and ratelimit
authorAlexander Marx <amarx@ipfire.org>
Thu, 11 Sep 2014 12:01:28 +0000 (14:01 +0200)
committerAlexander Marx <amarx@ipfire.org>
Thu, 11 Sep 2014 13:06:26 +0000 (15:06 +0200)
config/firewall/rules.pl

index aa8870cdc488a47b123d0d794689573ec2f5b2d4..30d3a3c3db4724bcdc2f74d3a49bee878d8e4d9d 100755 (executable)
@@ -268,6 +268,33 @@ sub buildrules {
                        }
                }
 
+               # Concurrent connection limit
+               my @ratelimit_options = ();
+               if ($$hash{$key}[32] eq 'ON') {
+                       my $conn_limit = $$hash{$key}[33];
+
+                       if ($conn_limit ge 1) {
+                               push(@ratelimit_options, ("-m", "connlimit"));
+
+                               # Use the the entire source IP address
+                               push(@ratelimit_options, "--connlimit-saddr");
+                               push(@ratelimit_options, ("--connlimit-mask", "32"));
+
+                               # Apply the limit
+                               push(@ratelimit_options, ("--connlimit-upto", $conn_limit));
+                       }
+               }
+
+               # Ratelimit
+               if ($$hash{$key}[34] eq 'ON') {
+                       my $rate_limit = "$$hash{$key}[35]/$$hash{$key}[36]";
+
+                               if ($rate_limit) {
+                                       push(@ratelimit_options, ("-m", "limit"));
+                                       push(@ratelimit_options, ("--limit", $rate_limit));
+                               }
+               }
+
                # Check which protocols are used in this rule and so that we can
                # later group rules by protocols.
                my @protocols = &get_protocols($hash, $key);
@@ -336,6 +363,9 @@ sub buildrules {
                                        # Add time constraint options.
                                        push(@options, @time_options);
 
+                                       # Add ratelimiting option
+                                       push(@options, @ratelimit_options);
+
                                        my $firewall_is_in_source_subnet = 1;
                                        if ($source) {
                                                $firewall_is_in_source_subnet = &firewall_is_in_subnet($source);