Documentation ¶
Overview ¶
The ip package contains yet another IP address (and CIDR) type :-). The types differ from the ones in the net package in that they are backed by fixed-sized arrays of the appropriate size. The key advantage of using a fixed-size array is that it makes the types hashable so they can be used as map keys. In addition, they can be converted to net.IP by slicing.
Index ¶
- Constants
- Variables
- func IPNetsEqual(net1, net2 *net.IPNet) bool
- type Addr
- type CIDR
- func CIDRFromAddrAndPrefix(addr Addr, prefixLen int) CIDR
- func CIDRFromCalicoNet(ipNet calinet.IPNet) CIDR
- func CIDRFromIPNet(ipNet *net.IPNet) CIDR
- func CIDRFromNetIP(netIP net.IP) CIDR
- func CIDRFromString(cidrStr string) (CIDR, error)
- func CommonPrefix(a, b CIDR) CIDR
- func MustParseCIDROrIP(s string) CIDR
- func ParseCIDROrIP(s string) (CIDR, error)
- type CIDRNode
- type CIDRTrie
- func (t *CIDRTrie) CoveredBy(cidr CIDR) bool
- func (t *CIDRTrie) Covers(cidr CIDR) bool
- func (t *CIDRTrie) Delete(cidr CIDR)
- func (t *CIDRTrie) Get(cidr CIDR) interface{}
- func (t *CIDRTrie) Intersects(cidr CIDR) bool
- func (t *CIDRTrie) LPM(cidr CIDR) (CIDR, interface{})
- func (t *CIDRTrie) LookupPath(buffer []CIDRTrieEntry, cidr CIDR) []CIDRTrieEntry
- func (t *CIDRTrie) ToSlice() []CIDRTrieEntry
- func (t *CIDRTrie) Update(cidr CIDR, value interface{})
- func (t *CIDRTrie) Visit(f func(cidr CIDR, data interface{}) bool)
- type CIDRTrieEntry
- type V4Addr
- type V4CIDR
- type V6Addr
- type V6CIDR
Constants ¶
const ( IPv4SizeDword = 1 IPv6SizeDword = 4 )
Variables ¶
var ErrInvalidIP = errors.New("Failed to parse IP address")
Functions ¶
func IPNetsEqual ¶
Types ¶
type Addr ¶
type Addr interface { // Version returns the IP version; 4 or 6. Version() uint8 // AsNetIP returns a net.IP, which is backed by/shares storage with // this object. AsNetIP() net.IP AsCalicoNetIP() calinet.IP AsCIDR() CIDR String() string NthBit(uint) int }
Addr represents either an IPv4 or IPv6 IP address.
func FromCalicoIP ¶
func FromString ¶
type CIDR ¶
type CIDR interface { Version() uint8 Addr() Addr Prefix() uint8 String() string ToIPNet() net.IPNet Contains(addr Addr) bool }
func CIDRFromAddrAndPrefix ¶
CIDRFromAddrAndPrefix.
func CIDRFromCalicoNet ¶
func CIDRFromIPNet ¶
func CIDRFromNetIP ¶
CIDRFromNetIP converts the given IP into our CIDR representation as a /32 or /128.
func CIDRFromString ¶
func CommonPrefix ¶
func MustParseCIDROrIP ¶
MustParseCIDROrIP parses the given IP address or CIDR, treating IP addresses as "full length" CIDRs. For example, "10.0.0.1" is treated as "10.0.0.1/32". It panics on failure.
func ParseCIDROrIP ¶
ParseCIDROrIP parses the given IP address or CIDR, treating IP addresses as "full length" CIDRs. For example, "10.0.0.1" is treated as "10.0.0.1/32".
type CIDRTrie ¶
type CIDRTrie struct {
// contains filtered or unexported fields
}
func NewCIDRTrie ¶
func NewCIDRTrie() *CIDRTrie
func (*CIDRTrie) Intersects ¶
func (*CIDRTrie) LookupPath ¶
func (t *CIDRTrie) LookupPath(buffer []CIDRTrieEntry, cidr CIDR) []CIDRTrieEntry
LookupPath looks up the given CIDR in the trie. It returns a slice containing a CIDRTrieEntry for each CIDR in the trie that encloses the given CIDR. If buffer is non-nil, then it is used to store the entries; if it is too short append() is used to extend it and the updated slice is returned.
If the CIDR is not in the trie then an empty slice is returned.
func (*CIDRTrie) ToSlice ¶
func (t *CIDRTrie) ToSlice() []CIDRTrieEntry
type CIDRTrieEntry ¶
type CIDRTrieEntry struct { CIDR CIDR Data interface{} }
type V4CIDR ¶
type V4CIDR struct {
// contains filtered or unexported fields
}
func V4CommonPrefix ¶
func (V4CIDR) ContainsV4 ¶
type V6Addr ¶
type V6Addr [16]byte
func (V6Addr) AsCalicoNetIP ¶
func (V6Addr) AsUint64Pair ¶
AsUint64Pair returns a pair of uint64 representing a V6Addr as there is no native 128 bit uint type in go.
type V6CIDR ¶
type V6CIDR struct {
// contains filtered or unexported fields
}