r2201 - further IPv4 hacking
authorDenis Ovsienko <infrastation@yandex.ru>
Tue, 9 Sep 2008 13:02:45 +0000 (13:02 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Tue, 9 Sep 2008 13:02:45 +0000 (13:02 +0000)
inc/database.php
inc/functions.php
inc/interface.php

index 474a60309a47427db11096f12df1b2110a442416..f3fb9de6afe77f91a1422267feed3190f7518af8 100644 (file)
@@ -1076,7 +1076,7 @@ function scanIPv4Spans ($spanlist)
 {
        $ret = array();
        foreach ($spanlist as $span)
 {
        $ret = array();
        foreach ($spanlist as $span)
-               foreach (scanIPv4Space ($span['u32_first'], $span['u32_last']) as $key => $val)
+               foreach (scanIPv4Space ($span['db_first'], $span['db_last']) as $key => $val)
                        $ret[$key] = $val;
        return $ret;
 }
                        $ret[$key] = $val;
        return $ret;
 }
@@ -1106,17 +1106,10 @@ function getIPv4NetworkInfo ($id = 0)
        return $ret;
 }
 
        return $ret;
 }
 
-function getIPv4Network ($id = 0)
+function loadIPv4AddrList (&$netinfo)
 {
 {
-       $ret = getIPv4NetworkInfo ($id);
-       if (!$ret)
-       {
-               showError ('Record not found', __FUNCTION__);
-               return NULL;
-       }
-       $ret['addrlist'] = scanIPv4Space ($ret['db_first'], $ret['db_last']);
-       markupIPv4AddrList ($ret['addrlist']);
-       return $ret;
+       loadOwnIPv4Addresses ($netinfo);
+       markupIPv4AddrList ($netinfo['addrlist']);
 }
 
 function getIPv4Address ($dottedquad = '')
 }
 
 function getIPv4Address ($dottedquad = '')
index 071ea8db236e256853d0578262ba877f3d1a6c04..87698b8e6eb84fb4279eca61f6ca7731076c9e72 100644 (file)
@@ -1516,20 +1516,29 @@ function treeApplyFunc (&$tree, $func)
 }
 
 
 }
 
 
-// Find node's own addresses. These are all addresses, which belong to the current prefix
-// exclusively.
-function countOwnIPv4Addresses (&$ipv4node)
+function countOwnIPv4Addresses (&$node)
 {
 {
-       if (empty ($ipv4node['kids']))
-               $ipv4node['addrc'] = count (scanIPv4Space ($ipv4node['db_first'], $ipv4node['db_last']));
+       $toscan = array();
+       if (empty ($node['kids']))
+               $toscan[] = $node;
        else
        else
-       {
-               $toscan = array();
-               foreach ($ipv4node['kids'] as $nested)
+               foreach ($node['kids'] as $nested)
                        if (!isset ($nested['id'])) // spare
                        if (!isset ($nested['id'])) // spare
-                               $toscan[] = array ('u32_first' => $nested['db_first'], 'u32_last' => $nested['db_last']);
-               $ipv4node['addrc'] = count (scanIPv4Spans ($toscan));
-       }
+                               $toscan[] = $nested;
+       $node['addrc'] = count (scanIPv4Spans ($toscan));
+}
+
+function loadOwnIPv4Addresses (&$node)
+{
+       $toscan = array();
+       if (empty ($node['kids']))
+               $toscan[] = $node;
+       else
+               foreach ($node['kids'] as $nested)
+                       if (!isset ($nested['id'])) // spare
+                               $toscan[] = $nested;
+       $node['addrlist'] = scanIPv4Spans ($toscan);
+       $node['addrc'] = count ($node['addrlist']);
 }
 
 ?>
 }
 
 ?>
index 33f25aaebc4cda0e8c150454b2fb3bc4a95f9791..954d919287640d8ef8cd8325e98fa8321836e15f 100644 (file)
@@ -854,6 +854,7 @@ function renderRackObject ($object_id = 0)
                        $secondclass = ($hl_ipv4_addr == $dottedquad) ? 'tdleft port_highlight' : 'tdleft';
                        $netid = getIPv4AddressNetworkId ($dottedquad);
                        $netinfo = getIPv4NetworkInfo ($netid);
                        $secondclass = ($hl_ipv4_addr == $dottedquad) ? 'tdleft port_highlight' : 'tdleft';
                        $netid = getIPv4AddressNetworkId ($dottedquad);
                        $netinfo = getIPv4NetworkInfo ($netid);
+                       loadIPv4AddrList ($netinfo);
                        echo "<tr class='${class}' valign=top><td class=tdleft>${alloc['osif']}</td><td class='${secondclass}'>";
                        echo "<a href='${root}?page=ipaddress&ip=" . $dottedquad . "&hl_object_id=${object_id}'>${dottedquad}</a>";
                        if (getConfigVar ('EXT_IPV4_VIEW') != 'yes')
                        echo "<tr class='${class}' valign=top><td class=tdleft>${alloc['osif']}</td><td class='${secondclass}'>";
                        echo "<a href='${root}?page=ipaddress&ip=" . $dottedquad . "&hl_object_id=${object_id}'>${dottedquad}</a>";
                        if (getConfigVar ('EXT_IPV4_VIEW') != 'yes')
@@ -875,9 +876,8 @@ function renderRackObject ($object_id = 0)
                                        printIPv4NetInfoTDs ($netinfo, $secondclass);
                                echo "<td class='${secondclass}'>";
                                // FIXME: These cals are really heavy, replace them with a more appropriate dedicated function.
                                        printIPv4NetInfoTDs ($netinfo, $secondclass);
                                echo "<td class='${secondclass}'>";
                                // FIXME: These cals are really heavy, replace them with a more appropriate dedicated function.
-                               $netdata = getIPv4Network ($netid);
                                $newline = '';
                                $newline = '';
-                               foreach (findRouters ($netdata['addrlist']) as $router)
+                               foreach (findRouters ($netinfo['addrlist']) as $router)
                                {
                                        if ($router['id'] == $object_id)
                                                continue;
                                {
                                        if ($router['id'] == $object_id)
                                                continue;
@@ -1168,6 +1168,7 @@ function renderIPv4ForObject ($object_id = 0)
                $class = $alloc['addrinfo']['class'];
                $netid = getIPv4AddressNetworkId ($dottedquad);
                $netinfo = getIPv4NetworkInfo ($netid);
                $class = $alloc['addrinfo']['class'];
                $netid = getIPv4AddressNetworkId ($dottedquad);
                $netinfo = getIPv4NetworkInfo ($netid);
+               loadIPv4AddrList ($netinfo);
                printOpFormIntro ('updIPv4Allocation', array ('ip' => $dottedquad));
                echo "<tr class='$class' valign=top><td><a href='${root}process.php?op=delIPv4Allocation&page=${pageno}&tab=${tabno}&ip=${dottedquad}&object_id=$object_id'>";
                printImageHREF ('delete', 'Delete this IPv4 address');
                printOpFormIntro ('updIPv4Allocation', array ('ip' => $dottedquad));
                echo "<tr class='$class' valign=top><td><a href='${root}process.php?op=delIPv4Allocation&page=${pageno}&tab=${tabno}&ip=${dottedquad}&object_id=$object_id'>";
                printImageHREF ('delete', 'Delete this IPv4 address');
@@ -1194,9 +1195,8 @@ function renderIPv4ForObject ($object_id = 0)
                                printIPv4NetInfoTDs ($netinfo);
                        echo "<td class='${secondclass}'>";
                        // FIXME: These cals are really heavy, replace them with a more appropriate dedicated function.
                                printIPv4NetInfoTDs ($netinfo);
                        echo "<td class='${secondclass}'>";
                        // FIXME: These cals are really heavy, replace them with a more appropriate dedicated function.
-                       $netdata = getIPv4Network ($netid);
                        $newline = '';
                        $newline = '';
-                       foreach (findRouters ($netdata['addrlist']) as $router)
+                       foreach (findRouters ($netinfo['addrlist']) as $router)
                        {
                                if ($router['id'] == $object_id)
                                        continue;
                        {
                                if ($router['id'] == $object_id)
                                        continue;
@@ -2009,26 +2009,25 @@ function renderIPv4SpaceRecords ($tree, $todo, $level = 0, &$tagcache = array())
        $doing = 1;
        foreach ($tree as $item)
        {
        $doing = 1;
        foreach ($tree as $item)
        {
+               $total = binInvMaskFromDec ($item['mask']) + 1;
                if (isset ($item['id']))
                {
                if (isset ($item['id']))
                {
-                       $netdata = getIPv4Network ($item['id']);
-                       $total = ($netdata['ip_bin'] | $netdata['mask_bin_inv']) - ($netdata['ip_bin'] & $netdata['mask_bin']) + 1;
-                       $used = count ($netdata['addrlist']);
+                       loadIPv4AddrList ($item);
+                       $used = $item['addrc'];
                        echo "<tr valign=top>";
                        $verge = ($doing == $todo ? 'L' : 'M') . ($item['kidc'] ? 'M' : 'T');
                        echo "<tr valign=top>";
                        $verge = ($doing == $todo ? 'L' : 'M') . ($item['kidc'] ? 'M' : 'T');
-                       printIPv4NetInfoTDs ($netdata, 'tdleft', $level, $verge);
+                       printIPv4NetInfoTDs ($item, 'tdleft', $level, $verge);
                        echo "<td class=tdcenter>";
                        renderProgressBar ($used/$total);
                        echo "<br><small>${used}/${total}</small></td>";
                        if (getConfigVar ('EXT_IPV4_VIEW') == 'yes')
                        echo "<td class=tdcenter>";
                        renderProgressBar ($used/$total);
                        echo "<br><small>${used}/${total}</small></td>";
                        if (getConfigVar ('EXT_IPV4_VIEW') == 'yes')
-                               printRoutersTD (findRouters ($netdata['addrlist']), $tagcache);
+                               printRoutersTD (findRouters ($item['addrlist']), $tagcache);
                        echo "</tr>";
                        $self ($item['kids'], $item['kidc'], $level + 1, $tagcache);
                }
                else
                {
                        $used = 0;
                        echo "</tr>";
                        $self ($item['kids'], $item['kidc'], $level + 1, $tagcache);
                }
                else
                {
                        $used = 0;
-                       $total = binInvMaskFromDec ($item['mask']) + 1;
                        echo "<tr valign=top>";
                        $verge = ($doing == $todo ? 'L' : 'M') . 'T';
                        printIPv4NetInfoTDs ($item, 'tdleft', $level, $verge);
                        echo "<tr valign=top>";
                        $verge = ($doing == $todo ? 'L' : 'M') . 'T';
                        printIPv4NetInfoTDs ($item, 'tdleft', $level, $verge);
@@ -2180,9 +2179,10 @@ function renderIPv4SpaceEditor ()
                echo "<tr><th>&nbsp;</th><th>prefix</th><th>name</th><th>&nbsp;</th></tr>";
                foreach ($addrspaceList as $iprange)
                {
                echo "<tr><th>&nbsp;</th><th>prefix</th><th>name</th><th>&nbsp;</th></tr>";
                foreach ($addrspaceList as $iprange)
                {
-                       $netdata = getIPv4Network ($iprange['id']);
+                       $netdata = getIPv4NetworkInfo ($iprange['id']);
+                       loadIPv4AddrList ($netdata);
                        $usedips = count ($netdata['addrlist']);
                        $usedips = count ($netdata['addrlist']);
-                       $totalips = ($netdata['ip_bin'] | $netdata['mask_bin_inv']) - ($netdata['ip_bin'] & $netdata['mask_bin']) + 1;
+                       $totalips = binInvMaskFromDec ($netdata['mask']) + 1;
                        echo "<form method=post action='${root}process.php?page=${pageno}&tab=${tabno}&op=updIPv4Prefix&id=${iprange['id']}'>";
                        echo '<tr valign=top><td>';
                        if ($usedips == 0)
                        echo "<form method=post action='${root}process.php?page=${pageno}&tab=${tabno}&op=updIPv4Prefix&id=${iprange['id']}'>";
                        echo '<tr valign=top><td>';
                        if ($usedips == 0)
@@ -2283,7 +2283,8 @@ function renderIPv4Network ($id)
        else
                $page=0;
 
        else
                $page=0;
 
-       $range = getIPv4Network ($id);
+       $range = getIPv4NetworkInfo ($id);
+       loadIPv4AddrList ($range);
        echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
        echo "<tr><td colspan=2 align=center><h1>${range['ip']}/${range['mask']}</h1><h2>${range['name']}</h2></td></tr>\n";
 
        echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
        echo "<tr><td colspan=2 align=center><h1>${range['ip']}/${range['mask']}</h1><h2>${range['name']}</h2></td></tr>\n";
 
@@ -2426,7 +2427,6 @@ function renderIPv4NetworkProperties ($id)
        echo "<tr><td colspan=2 class=tdcenter>";
        printImageHREF ('SAVE', 'Save changes', TRUE);
        echo "</td></form></tr></table>\n";
        echo "<tr><td colspan=2 class=tdcenter>";
        printImageHREF ('SAVE', 'Save changes', TRUE);
        echo "</td></form></tr></table>\n";
-
 }
 
 function renderIPv4Address ($dottedquad)
 }
 
 function renderIPv4Address ($dottedquad)
@@ -4573,7 +4573,8 @@ function renderLivePTR ($id = 0)
                $page=0;
        global $root, $pageno, $tabno;
        $maxperpage = getConfigVar ('IPV4_ADDRS_PER_PAGE');
                $page=0;
        global $root, $pageno, $tabno;
        $maxperpage = getConfigVar ('IPV4_ADDRS_PER_PAGE');
-       $range = getIPv4Network ($id);
+       $range = getIPv4NetworkInfo ($id);
+       loadIPv4AddrList ($range);
        echo "<center><h1>${range['ip']}/${range['mask']}</h1><h2>${range['name']}</h2></center>\n";
 
        echo "<table class=objview border=0 width='100%'><tr><td class=pcleft>";
        echo "<center><h1>${range['ip']}/${range['mask']}</h1><h2>${range['name']}</h2></center>\n";
 
        echo "<table class=objview border=0 width='100%'><tr><td class=pcleft>";