chore(all): use netip.Prefix for ip networks
- remove usage of `net.IPNet` - remove usage of `netaddr.IPPrefix`
This commit is contained in:
@@ -90,30 +90,6 @@ func CopyIP(original net.IP) (copied net.IP) {
|
||||
return copied
|
||||
}
|
||||
|
||||
func CopyIPNet(original net.IPNet) (copied net.IPNet) {
|
||||
if original.IP != nil {
|
||||
copied.IP = make(net.IP, len(original.IP))
|
||||
copy(copied.IP, original.IP)
|
||||
}
|
||||
|
||||
if original.Mask != nil {
|
||||
copied.Mask = make(net.IPMask, len(original.Mask))
|
||||
copy(copied.Mask, original.Mask)
|
||||
}
|
||||
|
||||
return copied
|
||||
}
|
||||
|
||||
func CopyIPNetPtr(original *net.IPNet) (copied *net.IPNet) {
|
||||
if original == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
copied = new(net.IPNet)
|
||||
*copied = CopyIPNet(*original)
|
||||
return copied
|
||||
}
|
||||
|
||||
func CopyNetipAddress(original netip.Addr) (copied netip.Addr) {
|
||||
// AsSlice creates a new byte slice so no need to copy the bytes.
|
||||
bytes := original.AsSlice()
|
||||
@@ -158,18 +134,6 @@ func CopyUint16Slice(original []uint16) (copied []uint16) {
|
||||
return copied
|
||||
}
|
||||
|
||||
func CopyIPNetSlice(original []net.IPNet) (copied []net.IPNet) {
|
||||
if original == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
copied = make([]net.IPNet, len(original))
|
||||
for i := range original {
|
||||
copied[i] = CopyIPNet(original[i])
|
||||
}
|
||||
return copied
|
||||
}
|
||||
|
||||
func CopyNetipPrefixesSlice(original []netip.Prefix) (copied []netip.Prefix) {
|
||||
if original == nil {
|
||||
return nil
|
||||
|
||||
@@ -187,32 +187,6 @@ func MergeUint16Slices(a, b []uint16) (result []uint16) {
|
||||
return result
|
||||
}
|
||||
|
||||
func MergeIPNetsSlices(a, b []net.IPNet) (result []net.IPNet) {
|
||||
if a == nil && b == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
seen := make(map[string]struct{}, len(a)+len(b))
|
||||
result = make([]net.IPNet, 0, len(a)+len(b))
|
||||
for _, ipNet := range a {
|
||||
key := ipNet.String()
|
||||
if _, ok := seen[key]; ok {
|
||||
continue // duplicate
|
||||
}
|
||||
result = append(result, ipNet)
|
||||
seen[key] = struct{}{}
|
||||
}
|
||||
for _, ipNet := range b {
|
||||
key := ipNet.String()
|
||||
if _, ok := seen[key]; ok {
|
||||
continue // duplicate
|
||||
}
|
||||
result = append(result, ipNet)
|
||||
seen[key] = struct{}{}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func MergeNetipAddressesSlices(a, b []netip.Addr) (result []netip.Addr) {
|
||||
if a == nil && b == nil {
|
||||
return nil
|
||||
|
||||
@@ -145,15 +145,6 @@ func OverrideWithUint16Slice(existing, other []uint16) (result []uint16) {
|
||||
return result
|
||||
}
|
||||
|
||||
func OverrideWithIPNetsSlice(existing, other []net.IPNet) (result []net.IPNet) {
|
||||
if other == nil {
|
||||
return existing
|
||||
}
|
||||
result = make([]net.IPNet, len(other))
|
||||
copy(result, other)
|
||||
return result
|
||||
}
|
||||
|
||||
func OverrideWithNetipAddressesSlice(existing, other []netip.Addr) (result []netip.Addr) {
|
||||
if other == nil {
|
||||
return existing
|
||||
|
||||
Reference in New Issue
Block a user