]> 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, 23 Sep 2024 11:09:41 +0000 (13:09 +0200)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
html/cgi-bin/ovpnmain.cgi

index 0a6b6e5fcf72e618ee24ae9c8c93eff0c5eaa1fb..7694642a8ecafd5eeebb25b6feb8b39090957953 100755 (executable)
@@ -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