wrong warning email about subnet utilization

  • Nobody/Anonymous

    IPPlan v6.00-BETA2

    This email looks like a bug to me. In the subnet overview the size of 256 is correctly computed, but in the mail it is 24 for a /24:

    Subject:  Subnet gets low
    Date: Mon, 9 Aug 2010 16:45:28 +0200
    X-Mailer: PHPMailer

    Subnet exdeeded 80% of utilization.
    Total addresses: 24
    Used addresses: 28 (including network and broadcast)
    Free addresses: -4
    Utilization: 116.666666667%

  • Keishava Arata

    Keishava Arata - 2010-08-13

    Browsed through the code.
    The field "subnetsize" is interpreted differently in different places

    Was about to file a bug and fix this in my own local build of ipplan

    diff -r ./contrib/ipplan-poller.php ../../ipplanv6/contrib/ipplan-poller.php
    $q= "SELECT baseindex FROM base WHERE customer=$cust AND INET_ATON(".$ds->qstr($ipaddr).") BETWEEN INET_ATON(baseaddr) AND INET_ATON(baseaddr)+POW(2,32-subnetsize)-1";

    If this interpretation is correct then the variable in the database should be named something like cidrmask.

    diff between beta2 and beta3 -
    <       insert($cstats,textbr(sprintf("Total addresses: 2 ^ %d",128 - $subnetsize)));
    >       insert($cstats,textbr(sprintf("Total addresses: 2 ^ %d",$subnetsize)));

    If we are dealing with network type 1, or ipv4,

    The number of total addresses should be more like 2^(32-$subnetsize).

    i.e. if the $subnetsize aka CIDR mask as per the create subnet form, variable contains 24, then there should be 24 bits for the network address, which leaves 32-24 = 8 bits for the host address so 2^(32-24) i.e. 2^8 or 256. Which should perhaps be the correct number of max hosts. (and then perhaps subtracting 2 more for the net address and the broadcast address which gives 254)

    When the warning mail is sent, the subnetsize value from the base table is assumed to be just what the name implies - subnetsize.

    possible fix;
    1. rename variable to cidrmask and fix calculation when sending error mail.
    2.  calculate acutal subnet size in terms of number of hosts, using the cidr mask value, when creating or modifying the subnet and let all other places in the code not have to do the size calculation.

  • Marco Carrera

    Marco Carrera - 2010-09-03

    I receive the same mail

    Please help me

  • Keishava Arata

    Keishava Arata - 2010-09-22

    dear carrera marco,

    sorry for the late reply but I havent been online here for a while.

    unless you have managed to fix this problem already, here is what I did -

    changing the following lines in the user/displaysubnet.php file should fix the problem for you.

    remove the lines prefixed with the "-" and add the lines with the "+".
    there is some un-necessary commented code in there that you may safely omit.

    hope this helps.

    diff --git a/user/displaysubnet.php b/user/displaysubnet.php
    index 86a4469..e79ebe7 100755
    --- a/user/displaysubnet.php
    +++ b/user/displaysubnet.php
    @@ -258,7 +258,11 @@ if ($_POST) {
                                 WHERE baseindex=$baseindex AND
                                 ipaddr!=".$ds->ds->qstr($baseaddr)." AND
                                 ipaddr!=".$ds->ds->qstr($ips[ $last_ip ]));
    -                    $utilization=($recs+2)/$maxcnt*100;
    +                   $max_assignable_addresses_in_subnet =  pow(2, 32 - $maxcnt) - 2;
    +                   //$recs = 
    +                    //$utilization=($recs+2)/$maxcnt*100;
    +                    $utilization=($recs/$max_assignable_addresses_in_subnet)*100;
                         // send en e-mail if threshold is exceeded
                         if (SUBNETTHRESHOLD != 0 and $utilization>SUBNETTHRESHOLD) {
    @@ -292,9 +296,9 @@ if ($_POST) {
                                 $mail->Subject = "[IPplan] Subnet ".$baseaddr."/".$maxcnt." gets low";
                                 $mail->Body="Subnet ".$baseaddr."/".$maxcnt." exdeeded ".SUBNETTHRESHOLD."% of utilization.\n";
    -                            $mail->Body.="Total addresses: $maxcnt\n";
    -                            $mail->Body.="Used addresses: ".($recs+2)." (including network and broadcast)\n";
    -                            $mail->Body.="Free addresses: ".($maxcnt-$recs-2)."\n";
    +                            $mail->Body.="Total addresses: $max_assignable_addresses_in_subnet";
    +                            $mail->Body.="Used addresses: ".($recs)."\n";
    +                            $mail->Body.="Free addresses: ".($max_assignable_addresses_in_subnet-$recs)."\n";
                                 $mail->Body.="Utilization: $utilization%\n";
                                 if(!@$mail->Send()) {
                                     $formerror .= my_("E-mail message was not sent")."\n";
  • Richard Ellerbrock

    Can you please send me a file attached patch for this code above. I cannot apply the patch.


Log in to post a comment.