コード例 #1
0
ファイル: netutils.go プロジェクト: jojimt/netplugin
// SetBitsOutsideRange sets all IPs outside range as used
func SetBitsOutsideRange(ipAllocMap *bitset.BitSet, ipRange string, subnetLen uint) {
	var i uint32
	rangeMin, _ := ipv4ToUint32(getFirstAddrInRange(ipRange))
	rangeMax, _ := ipv4ToUint32(getLastAddrInRange(ipRange, subnetLen))
	firstAddr, _ := ipv4ToUint32(GetSubnetAddr(ipRange, subnetLen))
	lastAddr, _ := ipv4ToUint32(getLastAddrInSubnet(ipRange, subnetLen))

	// Set bits lower than rangeMin as used
	for i = 0; i < (rangeMin - firstAddr); i++ {
		ipAllocMap.Set(uint(i))
	}

	// Set bits greater than the rangeMax as used
	for i = ((rangeMin - firstAddr) + ((rangeMax - rangeMin) + 1)); i < (lastAddr - firstAddr); i++ {
		ipAllocMap.Set(uint(i))
	}
}
コード例 #2
0
ファイル: netutils.go プロジェクト: jojimt/netplugin
// InitSubnetBitset initializes a bit set with 2^(32 - subnetLen) bits
func InitSubnetBitset(b *bitset.BitSet, subnetLen uint) {
	maxSize := (1 << (32 - subnetLen)) - 1
	b.Set(uint(maxSize))
	b.Set(uint(0))
}