fwhosts.cgi: Fix check to limit amount of ports in custom service groups.

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>
This commit is contained in:
Stefan Schantl
2021-07-15 12:07:37 +02:00
committed by Peter Müller
parent fe6b3e502b
commit 0341e11fe1

View 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;