Skip to content

Commit

Permalink
fix go linter issues
Browse files Browse the repository at this point in the history
Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com>
  • Loading branch information
NikitaSkrynnik committed Aug 19, 2024
1 parent 3330ebc commit 8eb6043
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/tools/dualstackippool/ippool.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,26 @@ package dualstackippool
import (
"net"

"github.com/networkservicemesh/sdk/pkg/tools/ippool"
"github.com/pkg/errors"

"github.com/networkservicemesh/sdk/pkg/tools/ippool"
)

// DualStackIPPool holds available IPv4 and IPv6 addresses in the structure of red-black tree
type DualStackIPPool struct {
IPv4IPPool *ippool.IPPool
IPv6IPPool *ippool.IPPool
}

// New instantiates a dualstack ip pool as red-black tree
func New() *DualStackIPPool {
pool := new(DualStackIPPool)
pool.IPv4IPPool = ippool.New(net.IPv4len)
pool.IPv6IPPool = ippool.New(net.IPv6len)
return pool
}

// AddNetString - adds ip addresses from network to the pool by string value
func (p *DualStackIPPool) AddNetString(ipNetString string) {
_, ipNet, err := net.ParseCIDR(ipNetString)
if err != nil {
Expand All @@ -44,6 +48,7 @@ func (p *DualStackIPPool) AddNetString(ipNetString string) {
p.AddNet(ipNet)
}

// AddNet - adds ip addresses from network to the pool
func (p *DualStackIPPool) AddNet(ipNet *net.IPNet) {
if ipNet.IP.To4() != nil {
p.IPv4IPPool.AddNet(ipNet)
Expand All @@ -52,17 +57,20 @@ func (p *DualStackIPPool) AddNet(ipNet *net.IPNet) {
p.IPv6IPPool.AddNet(ipNet)
}

// ContainsString parses ip string and checks that pool contains ip
func (p *DualStackIPPool) ContainsString(in string) bool {
return p.Contains(net.ParseIP(in))
}

// Contains checks that pool contains ip
func (p *DualStackIPPool) Contains(ip net.IP) bool {
if ip.To4() != nil {
return p.IPv4IPPool.Contains(ip)
}
return p.IPv6IPPool.Contains(ip)
}

// PullIPString - returns requested IP address from the pool by string
func (p *DualStackIPPool) PullIPString(in string) (*net.IPNet, error) {
ip, _, err := net.ParseCIDR(in)
if err != nil {
Expand All @@ -71,6 +79,7 @@ func (p *DualStackIPPool) PullIPString(in string) (*net.IPNet, error) {
return p.PullIP(ip)
}

// PullIP - returns requested IP address from the pool
func (p *DualStackIPPool) PullIP(ip net.IP) (*net.IPNet, error) {
if ip.To4() != nil {
return p.IPv4IPPool.PullIP(ip)
Expand Down

0 comments on commit 8eb6043

Please sign in to comment.