diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-11-23 19:34:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-23 19:34:41 +0100 |
commit | 4b9b3783c796333a9f0bb56f8a173941adf499d2 (patch) | |
tree | 462eea2d54fa05170647821e69c3ce60f8b3710e /libpod/network/subnet.go | |
parent | c61802e69b59642be5c28f640f722596dd04fe5f (diff) | |
parent | 70e7acdb23715298624d123f7cc7c9dbcdf0465c (diff) | |
download | podman-4b9b3783c796333a9f0bb56f8a173941adf499d2.tar.gz podman-4b9b3783c796333a9f0bb56f8a173941adf499d2.tar.bz2 podman-4b9b3783c796333a9f0bb56f8a173941adf499d2.zip |
Merge pull request #8451 from Luap99/fix-subnet-range
Fix ip-range for classless subnet masks
Diffstat (limited to 'libpod/network/subnet.go')
-rw-r--r-- | libpod/network/subnet.go | 14 |
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 } |