Skip to content

Commit

Permalink
apply review comments
Browse files Browse the repository at this point in the history
Signed-off-by: NikitaSkrynnik <[email protected]>
  • Loading branch information
NikitaSkrynnik committed Aug 19, 2024
1 parent 8eb6043 commit 60f895d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package dualstackippool provides service for managing both ipv4 and ipv6 addresses
package dualstackippool
// Package dualstack provides tools for managing both ipv4 and ipv6 addresses
package dualstack

import (
"net"
Expand All @@ -25,22 +25,22 @@ import (
"github.com/networkservicemesh/sdk/pkg/tools/ippool"
)

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

// New instantiates a dualstack ip pool as red-black tree
func New() *DualStackIPPool {
pool := new(DualStackIPPool)
func New() *IPPool {
pool := new(IPPool)
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) {
func (p *IPPool) AddNetString(ipNetString string) {
_, ipNet, err := net.ParseCIDR(ipNetString)
if err != nil {
return
Expand All @@ -49,7 +49,7 @@ func (p *DualStackIPPool) AddNetString(ipNetString string) {
}

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

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

// Contains checks that pool contains ip
func (p *DualStackIPPool) Contains(ip net.IP) bool {
func (p *IPPool) 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) {
func (p *IPPool) PullIPString(in string) (*net.IPNet, error) {
ip, _, err := net.ParseCIDR(in)
if err != nil {
return nil, errors.Wrapf(err, "failed to parse %s as a CIDR", in)
Expand All @@ -80,7 +80,7 @@ func (p *DualStackIPPool) PullIPString(in string) (*net.IPNet, error) {
}

// PullIP - returns requested IP address from the pool
func (p *DualStackIPPool) PullIP(ip net.IP) (*net.IPNet, error) {
func (p *IPPool) PullIP(ip net.IP) (*net.IPNet, error) {
if ip.To4() != nil {
return p.IPv4IPPool.PullIP(ip)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package dualstackippool
package dualstack

import (
"testing"
Expand Down

0 comments on commit 60f895d

Please sign in to comment.