Skip to content

Commit

Permalink
network: fix calculation of DHCP range for /16 networks
Browse files Browse the repository at this point in the history
When generating DHCP ranges for /16 networks, we are right at the limits
of what libvirt supports. We try to limit the number of hosts to at most
2^16-1 in case of large subnets.

However, the check was incorrect, as for a /16 network we would define the end
range as being .255.255, i.e. the broadcast address. So when we have a /16
network, we are still in the default case of having to decrement the "last" IP
by one.
  • Loading branch information
WanzenBug committed Oct 11, 2024
1 parent 627f7a8 commit 5276691
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/network_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func buildNetworkDHCP(ip net.IP, n *net.IPNet, dhcpMAC string, dhcpID uint, dhcp

prefix, hostBits := n.Mask.Size()
// libvirt does not support more than 2^16-1 hosts in the dhcp range
if hostBits-prefix >= 16 {
if hostBits-prefix > 16 {
end, _ = cidr.Host(n, 65535)
} else {
end = cidr.Dec(end)
Expand Down

0 comments on commit 5276691

Please sign in to comment.