Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bad allocation of address space and IP address #189

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion poc-cb-net/cmd/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func assignIPAddressToHost(cidrBlock string, numberOfIPsAssigned uint32) (string

// Create IP address of type net.IP. IPv4 is 4 bytes, IPv6 is 16 bytes.
var ip = make(net.IP, 4)
if ipCandidate < lastIP-1 {
if ipCandidate < lastIP {
binary.BigEndian.PutUint32(ip, ipCandidate)
} else {
CBLogger.Error("This IP is out of range of the CLADNet")
Expand Down
2 changes: 1 addition & 1 deletion poc-cb-net/internal/network-helper/network-helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func GetAvailableIPv4PrivateAddressSpaces(strIPNets []string) *AvailableIPv4Priv
// Recommend an IPv4AddressSpace
numberOfHosts := len(strIPNets) + 2 // Network address and Broadcase address
fmt.Printf("NumberOfHosts: %v\n", numberOfHosts)
neededPrefix := 32 - int(math.Log2(float64(numberOfHosts)))
neededPrefix := 32 - int(math.Ceil(math.Log2(float64(numberOfHosts))))
fmt.Printf("NeededPrefix: %v\n", neededPrefix)
strIPNet, err := recommendAnIPv4AddressSpace(neededPrefix, availableIPv4PrivateAddressSpaces)
if err != nil {
Expand Down