]> git.ipfire.org Git - people/ms/ipfire-2.x.git/commitdiff
ovpnmain.cgi: Refactor ccdmaxclients()
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 20 Mar 2024 11:32:22 +0000 (12:32 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 2 Jun 2025 19:45:52 +0000 (19:45 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
html/cgi-bin/ovpnmain.cgi

index 51348d1693f22294accfe983d8ad3a3974ec1fe0..a3adc22c68e360d91edfaa0f9ad25ef5f074c41d 100644 (file)
@@ -504,20 +504,20 @@ sub modccdnet($$) {
        &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%conns);
 }
 
-sub ccdmaxclients
-{
-       my $ccdnetwork=$_[0];
-       my @octets=();
-       my @subnet=();
-       @octets=split("\/",$ccdnetwork);
-       @subnet= split /\./, &General::cidrtosub($octets[1]);
-       my ($a,$b,$c,$d,$e);
-       $a=256-$subnet[0];
-       $b=256-$subnet[1];
-       $c=256-$subnet[2];
-       $d=256-$subnet[3];
-       $e=($a*$b*$c*$d)/4;
-       return $e-1;
+sub ccdmaxclients($) {
+       my $network = shift;
+
+       # Fetch the prefix
+       my $prefix = &Network::get_prefix($network);
+
+       # Return undef on invalid input
+       if (!defined $prefix) {
+               return undef;
+       }
+
+       # We need four IP addresses for each client
+       # (and for some reason we are taking one away)
+       return (1 << (32 - $prefix)) / 4 - 1;
 }
 
 sub getccdadresses