Documentation
¶
Index ¶
- func AddrIPNet(addr netip.Addr) *net.IPNet
- func AddrNext(ip netip.Addr) netip.Addrdeprecated
- func AddrPrior(ip netip.Addr) netip.Addrdeprecated
- func ComparePrefix(a, b netip.Prefix) int
- func FromStdAddr(stdIP net.IP, port int, zone string) (_ netip.AddrPort, ok bool)
- func FromStdIP(std net.IP) (ip netip.Addr, ok bool)
- func FromStdIPNet(std *net.IPNet) (prefix netip.Prefix, ok bool)
- func FromStdIPRaw(std net.IP) (ip netip.Addr, ok bool)deprecated
- func MustFromStdIP(std net.IP) netip.Addr
- func ParsePrefixOrAddr(s string) (netip.Addr, error)
- func ParseSubnet(netStr string) (netip.Prefix, error)
- func PrefixIPNet(p netip.Prefix) *net.IPNet
- func PrefixLastIP(p netip.Prefix) netip.Addr
- type PoolIP
- func (s *PoolIP) Contains(ip netip.Addr) bool
- func (s *PoolIP) ContainsPrefix(p netip.Prefix) bool
- func (s *PoolIP) ContainsRange(r PoolRange) bool
- func (s *PoolIP) Equal(o *PoolIP) bool
- func (s *PoolIP) Overlaps(b *PoolIP) bool
- func (s *PoolIP) OverlapsPrefix(p netip.Prefix) bool
- func (s *PoolIP) OverlapsRange(r PoolRange) bool
- func (s *PoolIP) Prefixes() []netip.Prefix
- func (s *PoolIP) Ranges() []PoolRange
- func (s *PoolIP) RemoveFreePrefix(bitLen uint8) (p netip.Prefix, newSet *PoolIP, ok bool)
- type PoolIPBuilder
- func (s *PoolIPBuilder) Add(ip netip.Addr)
- func (s *PoolIPBuilder) AddPrefix(p netip.Prefix)
- func (s *PoolIPBuilder) AddPrefixParseSubnet(netStr string) error
- func (s *PoolIPBuilder) AddRange(r PoolRange)
- func (s *PoolIPBuilder) AddSet(b *PoolIP)
- func (s *PoolIPBuilder) Clone() *PoolIPBuilder
- func (s *PoolIPBuilder) Complement()
- func (s *PoolIPBuilder) Intersect(b *PoolIP)
- func (s *PoolIPBuilder) PoolIP() (*PoolIP, error)
- func (s *PoolIPBuilder) Remove(ip netip.Addr)
- func (s *PoolIPBuilder) RemovePrefix(p netip.Prefix)
- func (s *PoolIPBuilder) RemoveRange(r PoolRange)
- func (s *PoolIPBuilder) RemoveSet(b *PoolIP)
- type PoolRange
- func (r PoolRange) AppendPrefixes(dst []netip.Prefix) []netip.Prefix
- func (r PoolRange) AppendTo(b []byte) []byte
- func (r PoolRange) Contains(addr netip.Addr) bool
- func (r PoolRange) From() netip.Addr
- func (r PoolRange) IsValid() bool
- func (r PoolRange) IsZero() bool
- func (r PoolRange) MarshalText() ([]byte, error)
- func (r PoolRange) Overlaps(o PoolRange) bool
- func (r PoolRange) Prefix() (p netip.Prefix, ok bool)
- func (r PoolRange) Prefixes() []netip.Prefix
- func (r PoolRange) String() string
- func (r PoolRange) To() netip.Addr
- func (r *PoolRange) UnmarshalText(text []byte) error
- func (r PoolRange) Valid() booldeprecated
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddrIPNet ¶
AddrIPNet returns the net.IPNet representation of an netip.Addr with a mask corresponding to the addresses's bit length. The returned value is always non-nil. Any zone identifier is dropped in the conversion.
func ComparePrefix ¶
func FromStdAddr ¶
FromStdAddr maps the components of a standard library TCPAddr or UDPAddr into an IPPort.
func FromStdIP ¶
FromStdIP returns an IP from the standard library's IP type.
If std is invalid, ok is false.
FromStdIP implicitly unmaps IPv6-mapped IPv4 addresses. That is, if len(std) == 16 and contains an IPv4 address, only the IPv4 part is returned, without the IPv6 wrapper. This is the common form returned by the standard library's ParseIP: https://play.golang.org/p/qdjylUkKWxl. To convert a standard library IP without the implicit unmapping, use netip.AddrFromSlice.
func FromStdIPNet ¶
FromStdIPNet returns an netip.Prefix from the standard library's IPNet type. If std is invalid, ok is false.
func FromStdIPRaw
deprecated
FromStdIPRaw returns an IP from the standard library's IP type. If std is invalid, ok is false. Unlike FromStdIP, FromStdIPRaw does not do an implicit Unmap if len(std) == 16 and contains an IPv6-mapped IPv4 address.
Deprecated: use netip.AddrFromSlice instead.
func MustFromStdIP ¶
MustFromStdIP is like FromStdIP, but it panics if std is invalid.
func ParsePrefixOrAddr ¶
ParsePrefixOrAddr parses s as an IP address prefix or IP address. If s parses as an IP address prefix, its net/netip.Prefix.Addr is returned. The string s can be an IPv4 address ("192.0.2.1"), IPv6 address ("2001:db8::68"), IPv4 prefix ("192.0.2.1/32"), or IPv6 prefix ("2001:db:68/96").
func ParseSubnet ¶
ParseSubnet parses prefix from CIDR string or IPv4 as /32 | IPv6 as /128
func PrefixIPNet ¶
PrefixIPNet returns the net.IPNet representation of an netip.Prefix. The returned value is always non-nil. Any zone identifier is dropped in the conversion.
Types ¶
type PoolIP ¶
type PoolIP struct {
// contains filtered or unexported fields
}
PoolIP represents a set of IP addresses.
PoolIP is safe for concurrent use. The zero value is a valid value representing a set of no IPs. Use PoolIPBuilder to construct PoolIPs.
func (*PoolIP) Contains ¶
Contains reports whether ip is in s. If ip has an IPv6 zone, Contains returns false, because PoolIPs do not track zones.
func (*PoolIP) ContainsPrefix ¶
ContainsPrefix reports whether all IPs in p are in s.
func (*PoolIP) ContainsRange ¶
ContainsRange reports whether all IPs in r are in s.
func (*PoolIP) OverlapsPrefix ¶
OverlapsPrefix reports whether any IP in p is also in s.
func (*PoolIP) OverlapsRange ¶
OverlapsRange reports whether any IP in r is also in s.
func (*PoolIP) RemoveFreePrefix ¶
RemoveFreePrefix splits s into a Prefix of length bitLen and a new PoolIP with that prefix removed.
If no contiguous prefix of length bitLen exists in s, RemoveFreePrefix returns ok=false.
type PoolIPBuilder ¶
type PoolIPBuilder struct {
// contains filtered or unexported fields
}
func NewPoolIPBuilder ¶
func NewPoolIPBuilder() *PoolIPBuilder
func (*PoolIPBuilder) AddPrefix ¶
func (s *PoolIPBuilder) AddPrefix(p netip.Prefix)
AddPrefix adds all IPs in p to s.
func (*PoolIPBuilder) AddPrefixParseSubnet ¶
func (s *PoolIPBuilder) AddPrefixParseSubnet(netStr string) error
func (*PoolIPBuilder) AddRange ¶
func (s *PoolIPBuilder) AddRange(r PoolRange)
AddRange adds r to s. If r is not Valid, AddRange does nothing.
func (*PoolIPBuilder) AddSet ¶
func (s *PoolIPBuilder) AddSet(b *PoolIP)
AddSet adds all IPs in b to s.
func (*PoolIPBuilder) Clone ¶
func (s *PoolIPBuilder) Clone() *PoolIPBuilder
Clone returns a copy of s that shares no memory with s.
func (*PoolIPBuilder) Complement ¶
func (s *PoolIPBuilder) Complement()
Complement updates s to contain the complement of its current contents.
func (*PoolIPBuilder) Intersect ¶
func (s *PoolIPBuilder) Intersect(b *PoolIP)
Intersect updates s to the set intersection of s and b.
func (*PoolIPBuilder) PoolIP ¶
func (s *PoolIPBuilder) PoolIP() (*PoolIP, error)
PoolIP returns an immutable PoolIP representing the current state of s.
Most PoolIPBuilder methods do not return errors. Rather, the builder ignores any invalid inputs (such as an invalid IPPrefix), and accumulates a list of any such errors that it encountered.
PoolIP also reports any such accumulated errors. Even if the returned error is non-nil, the returned PoolIP is usable and contains all modifications made with valid inputs.
The builder remains usable after calling PoolIP. Calling PoolIP clears any accumulated errors.
func (*PoolIPBuilder) Remove ¶
func (s *PoolIPBuilder) Remove(ip netip.Addr)
Remove removes ip from s.
func (*PoolIPBuilder) RemovePrefix ¶
func (s *PoolIPBuilder) RemovePrefix(p netip.Prefix)
RemovePrefix removes all IPs in p from s.
func (*PoolIPBuilder) RemoveRange ¶
func (s *PoolIPBuilder) RemoveRange(r PoolRange)
RemoveRange removes all IPs in r from s.
func (*PoolIPBuilder) RemoveSet ¶
func (s *PoolIPBuilder) RemoveSet(b *PoolIP)
RemoveSet removes all IPs in o from s.
type PoolRange ¶
type PoolRange struct {
// contains filtered or unexported fields
}
PoolRange represents an inclusive range of IP addresses from the same address family.
The From and To IPs are inclusive bounds, with both included in the range.
To be valid, the From and To values must be non-zero, have matching address families (IPv4 vs IPv6), and From must be less than or equal to To. IPv6 zones are stripped out and ignored. An invalid range may be ignored.
func MustParsePoolRange ¶
MustParsePoolRange calls ParsePoolRange(s) and panics on error. It is intended for use in tests with hard-coded strings.
func ParsePoolRange ¶
ParsePoolRange parses a range out of two IPs separated by a hyphen.
It returns an error if the range is not valid.
func PoolRangeFrom ¶
PoolRangeFrom returns an PoolRange from from to to. It does not allocate.
func RangeOfPrefix ¶
RangeOfPrefix returns the inclusive range of IPs that p covers.
If p is zero or otherwise invalid, Range returns the zero value.
func (PoolRange) AppendPrefixes ¶
AppendPrefixes is an append version of PoolRange.Prefixes. It appends the netip.Prefix entries that cover r to dst.
func (PoolRange) AppendTo ¶
AppendTo appends a text encoding of r, as generated by MarshalText, to b and returns the extended buffer.
func (PoolRange) Contains ¶
Contains reports whether the range r includes addr.
An invalid range always reports false.
If ip has an IPv6 zone, Contains returns false, because IPPrefixes strip zones.
func (PoolRange) IsValid ¶
IsValid reports whether r.From() and r.To() are both non-zero and obey the documented requirements: address families match, and From is less than or equal to To.
func (PoolRange) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface, The encoding is the same as returned by String, with one exception: If ip is the zero value, the encoding is the empty string.
func (PoolRange) Overlaps ¶
Overlaps reports whether p and o overlap at all.
If p and o are of different address families or either are invalid, it reports false.
func (PoolRange) Prefix ¶
Prefix returns r as an IPPrefix, if it can be presented exactly as such. If r is not valid or is not exactly equal to one prefix, ok is false.
func (PoolRange) Prefixes ¶
Prefixes returns the set of IPPrefix entries that covers r.
If either of r's bounds are invalid, in the wrong order, or if they're of different address families, then Prefixes returns nil.
Prefixes necessarily allocates. See AppendPrefixes for a version that uses memory you provide.
func (PoolRange) String ¶
String returns a string representation of the range.
For a valid range, the form is "From-To" with a single hyphen separating the IPs, the same format recognized by ParsePoolRange.
func (*PoolRange) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface. The IP range is expected in a form accepted by ParsePoolRange. It returns an error if *r is not the PoolRange zero value.