Menu

#130 subnetsize calculations incorrect.

closed
nobody
None
6
2010-11-07
2010-08-13
No

#
IPPlan v6.00-BETA2 In the subnet overview the size of 256 is correctly computed, but in the mail it is 24 for a /24: Subject: [IPplan] Subnet 10.10.100.0/24 gets low Date: Mon, 9 Aug 2010 16:45:28 +0200 X-Mailer: PHPMailer [version 1.73] Subnet 10.10.100.0/24 exdeeded 80% of utilization. Total addresses: 24 Used addresses: 28 (including network and broadcast) Free addresses: -4 Utilization: 116.666666667%
#

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 -
964c936
< 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. [imho, this should be the correct fix] 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.

Discussion

  • Keishava Arata

    Keishava Arata - 2010-08-17
    • priority: 5 --> 6
     
  • Richard Ellerbrock

    Too little information and submitter does not return emails.

     
  • Richard Ellerbrock

    • status: open --> closed
     

Log in to post a comment.