Documentation
¶
Overview ¶
Package iputils is small, allocation-aware helpers on top of net/netip for the patterns every service eventually re-implements: CIDR allowlists / denylists, classification (loopback, private, link-local), efficient many-prefix containment via a compiled Set.
Built on netip.Addr / netip.Prefix throughout — never the legacy net.IP. Set is the only stateful type; everything else is stateless functions.
Index ¶
- func Contains(prefix netip.Prefix, addr netip.Addr) bool
- func ContainsAny(prefixes []netip.Prefix, addr netip.Addr) bool
- func IsLinkLocal(addr netip.Addr) bool
- func IsLoopback(addr netip.Addr) bool
- func IsMulticast(addr netip.Addr) bool
- func IsPrivate(addr netip.Addr) bool
- func IsPublic(addr netip.Addr) bool
- func IsUnspecified(addr netip.Addr) bool
- func MustParseAddr(s string) netip.Addr
- func MustParsePrefix(s string) netip.Prefix
- func ParseAddr(s string) (netip.Addr, error)
- func ParsePrefix(s string) (netip.Prefix, error)
- type Set
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
Contains reports whether prefix contains addr. Cross-family inputs (an IPv4 addr against an IPv6 prefix or vice versa) return false.
func ContainsAny ¶
ContainsAny reports whether any prefix in prefixes contains addr. For repeated lookups over a large list prefer Set.
func IsLinkLocal ¶
IsLinkLocal reports whether addr is in 169.254.0.0/16 (v4) or fe80::/10 (v6).
func IsLoopback ¶
IsLoopback reports whether addr is in 127.0.0.0/8 (v4) or ::1 (v6).
func IsMulticast ¶
IsMulticast reports whether addr is multicast.
func IsPrivate ¶
IsPrivate reports whether addr is in any RFC1918 / RFC4193 range. netip itself ships IsPrivate() since 1.20; this wrapper exists for API symmetry and stable scope across Go versions.
func IsPublic ¶
IsPublic reports whether addr is routable on the public internet. (Not loopback, not link-local, not multicast, not unspecified, not private.)
func IsUnspecified ¶
IsUnspecified reports whether addr is 0.0.0.0 / ::.
func MustParseAddr ¶
MustParseAddr panics on error. For test fixtures and init-time constants only.
func MustParsePrefix ¶
MustParsePrefix panics on error. For test fixtures and init-time constants only.
Types ¶
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is a compiled multi-prefix container. Lookups are O(P) over the prefix count but with no allocations on the hot path; suitable for allowlist / denylist sizes up to a few thousand.