]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
fwhosts.cgi: Fix check to limit amount of ports in custom service groups.
authorStefan Schantl <stefan.schantl@ipfire.org>
Thu, 15 Jul 2021 10:07:37 +0000 (12:07 +0200)
committerPeter Müller <peter.mueller@ipfire.org>
Fri, 19 Nov 2021 06:13:42 +0000 (07:13 +0100)
iptables multiport only supports up to 15 elements for each protocol (TCP or UDP).
That can be single ports or portranges (they count doubble).

This commit extends the check to calculate the amount of used TCP and/or
UDP ports of all existing entries in a group, by increasing the amount
for the service which should be added.

If the amount of ports for TCP or UDP ports become greater than the
limit of 15 the error message will be displayed.

Fixes #11323.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Reviewed-by: Michael Tremer <michael.tremer@ipfire.org>
Reviewed-by: Bernhard Bitsch <bbitsch@ipfire.org>
html/cgi-bin/fwhosts.cgi

index 0da771a5a3fac5e56ade8a4d95d331823a9a53eb..c66e3002a3097818852e11aeabf92e739824f304 100644 (file)
@@ -818,10 +818,28 @@ if ($fwhostsettings{'ACTION'} eq 'saveservicegrp')
                        }
                }
        }
-       if ($tcpcounter > 14){
+
+       # Loop through the hash of configured services.
+       foreach my $key (keys %customservice) {
+               # Assign nice human-readable values.
+               my $service_name = $customservice{$key}[0];
+               my $service_port = $customservice{$key}[1];
+               my $service_proto = $customservice{$key}[2];
+
+               # Skip services unless the processed one has found.
+               next unless $service_name eq $fwhostsettings{'CUST_SRV'};
+
+               # Increase the counters.
+               $tcpcounter++ if $service_proto eq 'TCP';
+               $tcpcounter++ if $service_proto eq 'TCP' && $service_port =~ m/:/i;
+               $udpcounter++ if $service_proto eq 'UDP';
+               $udpcounter++ if $service_proto eq 'UDP' && $service_port =~ m/:/i;
+       }
+
+       if ($tcpcounter > 15) {
                $errormessage=$Lang::tr{'fwhost err maxservicetcp'};
        }
-       if ($udpcounter > 14){
+       if ($udpcounter > 15) {
                $errormessage=$Lang::tr{'fwhost err maxserviceudp'};
        }
        $tcpcounter=0;