From 69925c51683f434a5b7277eef5afdd257f37500b Mon Sep 17 00:00:00 2001 From: Predrag Rogic Date: Sat, 27 Mar 2021 23:32:41 +0000 Subject: [PATCH] kvm2 driver: add static ip --- pkg/network/network.go | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/pkg/network/network.go b/pkg/network/network.go index 0d74ea1181ed..e8987ae9e3d5 100644 --- a/pkg/network/network.go +++ b/pkg/network/network.go @@ -264,37 +264,3 @@ func reserveSubnet(subnet string, period time.Duration) bool { reservedSubnets.Store(subnet, reservation{createdAt: time.Now()}) return true } - -// IncIP returns address calculated by adding (positive or negative) val to addr. -// If addr is not in CIDR format it will use its default mask and set "out-of-network" if calculated address doesn't belong to same network as addr. -func IncIP(addr string, val int) (calc string, oon bool, err error) { - ip, network, err := net.ParseCIDR(addr) - if err != nil { // addr not in CIDR format - use default mask for IP addr - ip = net.ParseIP(addr) - if ip == nil { - return "", false, fmt.Errorf("failed parsing address %s: %w", addr, err) - } - prefix, _ := ip.DefaultMask().Size() // assume default network mask - _, network, err = net.ParseCIDR(fmt.Sprintf("%s/%d", addr, prefix)) - if err != nil { - return "", false, fmt.Errorf("failed parsing CIDR %s/%d: %w", addr, prefix, err) - } - } - - ip0 := ip.To4() // convert to 4-byte representation - n0 := binary.BigEndian.Uint32(ip0) - - n1 := int(n0) + val - if n1 < 0 { - return "", true, fmt.Errorf("failed decrementing IP %s: value %d too big", addr, val) - } - - ip1 := make(net.IP, 4) - binary.BigEndian.PutUint32(ip1, uint32(n1)) - - if !network.Contains(ip1) { - return "", true, fmt.Errorf("failed incrementing IP %s: value %d too big (%s would cross network boundary)", addr, val, ip) - } - - return ip1.String(), false, nil -}