예제 #1
0
function createIPv4Prefix($range = '', $name = '', $is_connected = FALSE, $taglist = array(), $vlan_ck = NULL)
{
    // $range is in x.x.x.x/x format, split into ip/mask vars
    $rangeArray = explode('/', $range);
    if (count($rangeArray) != 2) {
        throw new InvalidRequestArgException('range', $range, 'Invalid IPv4 prefix');
    }
    $ip = $rangeArray[0];
    $mask = $rangeArray[1];
    $forbidden_ranges = array(constructIPRange("", 8), constructIPRange("ð", 4));
    $net = constructIPRange(ip4_parse($ip), $mask);
    foreach ($forbidden_ranges as $invalid_net) {
        if (IPNetContainsOrEqual($invalid_net, $net)) {
            throw new InvalidArgException('range', $range, 'Reserved IPv4 network');
        }
    }
    usePreparedInsertBlade('IPv4Network', array('ip' => ip4_bin2db($net['ip_bin']), 'mask' => $mask, 'name' => $name));
    $network_id = lastInsertID();
    if ($is_connected and $mask < 31) {
        updateV4Address($net['ip_bin'], 'network', 'yes');
        updateV4Address(ip_last($net), 'broadcast', 'yes');
    }
    produceTagsForNewRecord('ipv4net', $taglist, $network_id);
    if ($vlan_ck != NULL) {
        $ctx = getContext();
        fixContext(spotEntity('ipv4net', $network_id));
        if (permitted('ipv4net', '8021q', 'bind')) {
            commitSupplementVLANIPv4($vlan_ck, $network_id);
        }
        restoreContext($ctx);
    }
    return $network_id;
}
예제 #2
0
function iptree_embed(&$node, $pfx)
{
    $self = __FUNCTION__;
    // hit?
    if (0 == IPNetworkCmp($node, $pfx)) {
        $node = $pfx;
        return;
    }
    if ($node['mask'] == $pfx['mask']) {
        throw new RackTablesError('the recurring loop lost control', RackTablesError::INTERNAL);
    }
    // split?
    if (!isset($node['right'])) {
        $node['left'] = constructIPRange($node['ip_bin'], $node['mask'] + 1);
        $node['right'] = constructIPRange(ip_last($node), $node['mask'] + 1);
    }
    if (IPNetContainsOrEqual($node['left'], $pfx)) {
        $self($node['left'], $pfx);
    } elseif (IPNetContainsOrEqual($node['right'], $pfx)) {
        $self($node['right'], $pfx);
    } else {
        throw new RackTablesError('cannot decide between left and right', RackTablesError::INTERNAL);
    }
}