function renderIPv6NetworkAddresses($netinfo) { global $pageno, $tabno, $aac_left; echo "<table class='widetable' border=0 cellspacing=0 cellpadding=5 align='center' width='100%'>\n"; echo "<tr><th>Address</th><th>Name</th><th>Comment</th><th>Allocation</th></tr>\n"; $hl_ip = NULL; if (isset($_REQUEST['hl_ip'])) { $hl_ip = ip6_parse($_REQUEST['hl_ip']); addAutoScrollScript('ip-' . ip6_format($hl_ip)); } $addresses = $netinfo['addrlist']; ksort($addresses); markupIPAddrList($addresses); // pager $maxperpage = getConfigVar('IPV4_ADDRS_PER_PAGE'); if (count($addresses) > $maxperpage && $maxperpage > 0) { $page = isset($_REQUEST['pg']) ? $_REQUEST['pg'] : (isset($hl_ip) ? getPageNumOfIPv6($addresses, $hl_ip, $maxperpage) : 0); $numpages = ceil(count($addresses) / $maxperpage); echo "<center><h3>{$numpages} pages:</h3>"; for ($i = 0; $i < $numpages; $i++) { if ($i == $page) { echo "<b>{$i}</b> "; } else { echo "<a href='" . makeHref(array('page' => $pageno, 'tab' => $tabno, 'id' => $netinfo['id'], 'pg' => $i)) . "'>{$i}</a> "; } } echo "</center>"; } $i = 0; $interruped = FALSE; $prev_ip = ip_prev($netinfo['ip_bin']); foreach ($addresses as $ip_bin => $addr) { if (isset($page)) { ++$i; if ($i <= $maxperpage * $page) { continue; } elseif ($i > $maxperpage * ($page + 1)) { $interruped = TRUE; break; } } if ($ip_bin != ip_next($prev_ip)) { renderSeparator(ip_next($prev_ip), ip_prev($ip_bin), $hl_ip); } $prev_ip = $ip_bin; // render IP change history $title = ''; $history_class = ''; if (isset($addr['last_log'])) { $title = ' title="' . htmlspecialchars($addr['last_log']['user'] . ', ' . formatAge($addr['last_log']['time']), ENT_QUOTES) . '"'; $history_class = 'hover-history underline'; } $tr_class = $addr['class'] . ' tdleft' . ($hl_ip === $ip_bin ? ' highlight' : ''); echo "<tr class='{$tr_class}'>"; echo "<td><a class='{$history_class}' {$title} name='ip-{$addr['ip']}' href='" . makeHref(array('page' => 'ipaddress', 'ip' => $addr['ip'])) . "'>{$addr['ip']}</a></td>"; $editable = empty($addr['allocs']) || !empty($addr['name']) && permitted('ipaddress', 'properties', 'editAddress') ? 'editable' : ''; echo "<td><span class='rsvtext {$editable} id-{$addr['ip']} op-upd-ip-name'>{$addr['name']}</span></td>"; echo "<td><span class='rsvtext {$editable} id-{$addr['ip']} op-upd-ip-comment'>{$addr['comment']}</span></td><td>"; $delim = ''; if ($addr['reserved'] == 'yes') { echo "<strong>RESERVED</strong> "; $delim = '; '; } foreach ($addr['allocs'] as $ref) { echo $delim . $aac_left[$ref['type']]; echo makeIPAllocLink($ip_bin, $ref, TRUE); $delim = '; '; } if ($delim != '') { $delim = '<br>'; } foreach ($addr['vslist'] as $vs_id) { $vs = spotEntity('ipv4vs', $vs_id); echo $delim . mkA("{$vs['name']}:{$vs['vport']}/{$vs['proto']}", 'ipv4vs', $vs['id']) . '→'; $delim = '<br>'; } foreach ($addr['vsglist'] as $vs_id) { $vs = spotEntity('ipvs', $vs_id); echo $delim . mkA($vs['name'], 'ipvs', $vs['id']) . '→'; $delim = '<br>'; } foreach ($addr['rsplist'] as $rsp_id) { $rsp = spotEntity('ipv4rspool', $rsp_id); echo "{$delim}→" . mkA($rsp['name'], 'ipv4rspool', $rsp['id']); $delim = '<br>'; } echo "</td></tr>\n"; } if (!$interruped) { renderSeparator(ip_next($prev_ip), ip_last($netinfo), $hl_ip); } if (isset($page)) { // bottom pager echo "<tr><td colspan=3>"; if ($page > 0) { echo "<a href='" . makeHref(array('page' => $pageno, 'tab' => $tabno, 'id' => $netinfo['id'], 'pg' => $page - 1)) . "'><< prev</a> "; } if ($page < $numpages - 1) { echo "<a href='" . makeHref(array('page' => $pageno, 'tab' => $tabno, 'id' => $netinfo['id'], 'pg' => $page + 1)) . "'>next >></a> "; } echo "</td></tr>"; } echo "</table>"; if (permitted(NULL, NULL, 'set_reserve_comment')) { addJS('js/inplace-edit.js'); } }
function fillIPSpareListBstr(&$net, $a, $b) { $len = strlen($a) * 8; while (0 >= strcmp($a, $b)) { $max_mask = 0; // the number of common binary bits in the major of $a and $b $xor = $a ^ $b; for ($i = 0; $i < strlen($xor); $i++) { $max_mask += 8; if ($xor[$i] != "") { $byte = ord($xor[$i]); do { $max_mask--; $byte >>= 1; } while ($byte != 0); break; } } for ($mask = $max_mask; $mask <= $len; $mask++) { $bmask = ip_mask($mask, $len == 128); $last_a = $a | ~$bmask; if ($a == ($a & $bmask) and 0 >= strcmp($last_a, $b)) { $net['spare_ranges'][$mask][] = $a; $a = ip_next($last_a); break; } } } }