summaryrefslogtreecommitdiff
path: root/libpod/network/subnet.go
diff options
context:
space:
mode:
authorjortkoopmans <jort@jabo-solutions.eu>2020-11-25 18:26:22 +0100
committerjortkoopmans <jort@jabo-solutions.eu>2020-11-25 18:27:31 +0100
commit5cfbe0b78e3672dd67cd028b85d816fc19d6a614 (patch)
tree375fe5a96bca7d04154daf63ac9b644ebb1adc34 /libpod/network/subnet.go
parenta18365c908d45a8ee9348c5e32a240a7b9a4091b (diff)
downloadpodman-5cfbe0b78e3672dd67cd028b85d816fc19d6a614.tar.gz
podman-5cfbe0b78e3672dd67cd028b85d816fc19d6a614.tar.bz2
podman-5cfbe0b78e3672dd67cd028b85d816fc19d6a614.zip
squash
Signed-off-by: jortkoopmans <jort@jabo-solutions.eu>
Diffstat (limited to 'libpod/network/subnet.go')
-rw-r--r--libpod/network/subnet.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/libpod/network/subnet.go b/libpod/network/subnet.go
index 90f0cdfce..120038e57 100644
--- a/libpod/network/subnet.go
+++ b/libpod/network/subnet.go
@@ -54,14 +54,10 @@ func LastIPInSubnet(addr *net.IPNet) (net.IP, error) { //nolint:interfacer
ones, bits := cidr.Mask.Size()
if ones == bits {
- return FirstIPInSubnet(cidr)
+ return cidr.IP, nil
}
- hostStart := ones / 8
- // Handle the first host byte
- cidr.IP[hostStart] |= 0xff & cidr.Mask[hostStart]
- // Fill the rest with ones
- for i := hostStart; i < len(cidr.IP); i++ {
- cidr.IP[i] = 0xff
+ for i := range cidr.IP {
+ cidr.IP[i] = cidr.IP[i] | ^cidr.Mask[i]
}
return cidr.IP, nil
}
@@ -73,6 +69,10 @@ func FirstIPInSubnet(addr *net.IPNet) (net.IP, error) { //nolint:interfacer
if err != nil {
return nil, err
}
+ ones, bits := cidr.Mask.Size()
+ if ones == bits {
+ return cidr.IP, nil
+ }
cidr.IP[len(cidr.IP)-1]++
return cidr.IP, nil
}