summaryrefslogtreecommitdiff
path: root/libpod/network/internal/util/ip.go
diff options
context:
space:
mode:
authorPaul Holzinger <pholzing@redhat.com>2021-12-17 14:46:15 +0100
committerPaul Holzinger <pholzing@redhat.com>2022-01-12 17:07:30 +0100
commit495884b3195de482dc610a2a002db7e053188a32 (patch)
tree2a6f23db066cd52aa366991b0b34d7b919368ddc /libpod/network/internal/util/ip.go
parent2cdab5d53923784e72020d70ee9375518f19f9b6 (diff)
downloadpodman-495884b3195de482dc610a2a002db7e053188a32.tar.gz
podman-495884b3195de482dc610a2a002db7e053188a32.tar.bz2
podman-495884b3195de482dc610a2a002db7e053188a32.zip
use libnetwork from c/common
The libpod/network packages were moved to c/common so that buildah can use it as well. To prevent duplication use it in podman as well and remove it from here. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'libpod/network/internal/util/ip.go')
-rw-r--r--libpod/network/internal/util/ip.go70
1 files changed, 0 insertions, 70 deletions
diff --git a/libpod/network/internal/util/ip.go b/libpod/network/internal/util/ip.go
deleted file mode 100644
index 7fe35d3d4..000000000
--- a/libpod/network/internal/util/ip.go
+++ /dev/null
@@ -1,70 +0,0 @@
-package util
-
-import (
- "crypto/rand"
- "net"
-
- "github.com/pkg/errors"
-)
-
-func incByte(subnet *net.IPNet, idx int, shift uint) error {
- if idx < 0 {
- return errors.New("no more subnets left")
- }
- if subnet.IP[idx] == 255 {
- subnet.IP[idx] = 0
- return incByte(subnet, idx-1, 0)
- }
- subnet.IP[idx] += 1 << shift
- return nil
-}
-
-// NextSubnet returns subnet incremented by 1
-func NextSubnet(subnet *net.IPNet) (*net.IPNet, error) {
- newSubnet := &net.IPNet{
- IP: subnet.IP,
- Mask: subnet.Mask,
- }
- ones, bits := newSubnet.Mask.Size()
- if ones == 0 {
- return nil, errors.Errorf("%s has only one subnet", subnet.String())
- }
- zeroes := uint(bits - ones)
- shift := zeroes % 8
- idx := ones/8 - 1
- if idx < 0 {
- idx = 0
- }
- if err := incByte(newSubnet, idx, shift); err != nil {
- return nil, err
- }
- return newSubnet, nil
-}
-
-func NetworkIntersectsWithNetworks(n *net.IPNet, networklist []*net.IPNet) bool {
- for _, nw := range networklist {
- if networkIntersect(n, nw) {
- return true
- }
- }
- return false
-}
-
-func networkIntersect(n1, n2 *net.IPNet) bool {
- return n2.Contains(n1.IP) || n1.Contains(n2.IP)
-}
-
-// getRandomIPv6Subnet returns a random internal ipv6 subnet as described in RFC3879.
-func getRandomIPv6Subnet() (net.IPNet, error) {
- ip := make(net.IP, 8, net.IPv6len)
- // read 8 random bytes
- _, err := rand.Read(ip)
- if err != nil {
- return net.IPNet{}, nil
- }
- // first byte must be FD as per RFC3879
- ip[0] = 0xfd
- // add 8 zero bytes
- ip = append(ip, make([]byte, 8)...)
- return net.IPNet{IP: ip, Mask: net.CIDRMask(64, 128)}, nil
-}