ref

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2025 License: Apache-2.0 Imports: 9 Imported by: 1

README

IPREF reference

IPREF™ uses references which are opaque integers up to 128 bits in size. On 64 bit systems they're represented as a structure consisting of two 64 bit unsigned integers.

Documentation

Index

Constants

View Source
const (
	V1_SIG      = 0x11 // v1 signature
	V1_HDR_LEN  = 8
	V1_MARK_LEN = 4 + 4 // oid + mark
	// v1 header offsets
	V1_VER    = 0 // must be 0x11
	V1_CMD    = 1
	V1_PKTID  = 2
	V1_PKTLEN = 6
	// v1 mark offsets
	V1_OID  = 0
	V1_MARK = 4
	// v1 host data offsets
	V1_HOST_DATA_BATCHID = 0
	V1_HOST_DATA_COUNT   = 0
	V1_HOST_DATA_HASH    = 4
	V1_HOST_DATA_SOURCE  = 12
	// v1 save dnssource offsets
	V1_DNSSOURCE_MARK   = 4
	V1_DNSSOURCE_XMARK  = 4
	V1_DNSSOURCE_HASH   = 8
	V1_DNSSOURCE_SOURCE = 16
)
View Source
const (
	V1_NOOP           = 0
	V1_SET_AREC       = 1
	V1_SET_MARK       = 2
	V1_GET_REF        = 4
	V1_GET_EA         = 6
	V1_MC_GET_EA      = 7
	V1_SAVE_OID       = 8
	V1_SAVE_TIME_BASE = 9
	V1_RECOVER_EA     = 10
	V1_RECOVER_REF    = 11

	V1_MC_HOST_DATA      = 14
	V1_MC_HOST_DATA_HASH = 15
	V1_SAVE_DNSSOURCE    = 16
)
View Source
const (
	V1_DATA = 0x00
	V1_REQ  = 0x40
	V1_ACK  = 0x80
	V1_NACK = 0xC0
)
View Source
const (

	//V1_TYPE_NONE   = 0
	//V1_TYPE_AREC   = 1
	//V1_TYPE_IPV4   = 3
	V1_TYPE_STRING = 4
)

Variables

View Source
var UINT128_0 = Uint128FromUint64(0)
View Source
var UINT128_1 = Uint128FromUint64(1)
View Source
var UINT128_2_127 = UINT128_1.Lsh(127)
View Source
var UINT128_MAX = UINT128_0.Sub(UINT128_1)

Functions

func IPLenToVer

func IPLenToVer(l int) int

func IPPrefixesContain

func IPPrefixesContain(prefixes []IPPrefix, ip IP) bool

func IPVerToLen

func IPVerToLen(ver int) int

func RefPrefixesContain

func RefPrefixesContain(prefixes []RefPrefix, ref Ref) bool

Types

type AddrRec

type AddrRec struct {
	EA  IP
	IP  IP
	GW  IP
	Ref Ref
}

type IP

type IP netip.Addr // IPv4 or IPv6 address; Zone() must be ""

func IPBits

func IPBits(l, n int) IP

func IPFromSlice

func IPFromSlice(ip []byte) IP

The slice must be 4 or 16 bytes

func IPFromUint32

func IPFromUint32(ip uint32) IP

func IPFromUint128

func IPFromUint128(ip Uint128) IP

func IPFromUnixSockaddr

func IPFromUnixSockaddr(addr unix.Sockaddr) IP

func IPNum

func IPNum(l int, n uint32) IP

func IPZero

func IPZero(l int) IP

func MustParseIP

func MustParseIP(s string) IP

func ParseIP

func ParseIP(s string) (IP, error)

func (IP) Add

func (a IP) Add(b IP) IP

func (IP) And

func (a IP) And(b IP) IP

func (IP) As4In6

func (ip IP) As4In6() IP

func (IP) AsSlice

func (ip IP) AsSlice() []byte

func (IP) AsSlice4

func (ip IP) AsSlice4() []byte

func (IP) AsSlice6

func (ip IP) AsSlice6() []byte

func (IP) AsUint32

func (ip IP) AsUint32() uint32

func (IP) AsUint128

func (ip IP) AsUint128() Uint128

func (IP) AsUint128Cast

func (ip IP) AsUint128Cast() Uint128

func (IP) AsUnixSockaddr

func (ip IP) AsUnixSockaddr() unix.Sockaddr

func (IP) ByteFromEnd

func (ip IP) ByteFromEnd(i int) byte

func (IP) Compare

func (a IP) Compare(b IP) int

func (IP) Is4

func (ip IP) Is4() bool

func (IP) Is4In6

func (ip IP) Is4In6() bool

func (IP) Is6

func (ip IP) Is6() bool

func (IP) IsGlobalUnicast

func (ip IP) IsGlobalUnicast() bool

func (IP) IsLinkLocal

func (ip IP) IsLinkLocal() bool

func (IP) IsZero

func (ip IP) IsZero() bool

Tests if the IP is equal to the zero-initialized value. This is distinct from the zero IP address (eg. 0.0.0.0 or ::).

func (IP) IsZeroAddr

func (ip IP) IsZeroAddr() bool

func (IP) Len

func (ip IP) Len() int

func (IP) Not

func (a IP) Not() IP

func (IP) Or

func (a IP) Or(b IP) IP

func (IP) String

func (ip IP) String() string

func (IP) Un4In6

func (ip IP) Un4In6() IP

func (IP) Ver

func (ip IP) Ver() int

func (IP) XOr

func (a IP) XOr(b IP) IP

type IPPrefix

type IPPrefix netip.Prefix // .Addr().Zone() must be "", and must be .Masked()

func IPPrefixAllVer

func IPPrefixAllVer(ipver int) IPPrefix

func IPPrefixComplete

func IPPrefixComplete(ipver int) IPPrefix

func IPPrefixFrom

func IPPrefixFrom(ip IP, bits int) IPPrefix

func IPPrefixSingle

func IPPrefixSingle(ip IP) IPPrefix

func MustParseIPPrefix

func MustParseIPPrefix(s string) IPPrefix

func ParseIPPrefix

func ParseIPPrefix(s string) (IPPrefix, error)

func (IPPrefix) Addr

func (p IPPrefix) Addr() IP

func (IPPrefix) Bits

func (p IPPrefix) Bits() int

func (IPPrefix) Contains

func (p IPPrefix) Contains(ip IP) bool

func (IPPrefix) SizeBits

func (p IPPrefix) SizeBits() int

func (IPPrefix) String

func (p IPPrefix) String() string

func (IPPrefix) Subnets

func (a IPPrefix) Subnets(l int) []IPPrefix

Returns the 2^l subnets of prefix length 'a.Bits() + l' within a, in order. If l is invalid, then nil is returned.

type IpRef

type IpRef struct {
	IP  IP
	Ref Ref
}

func MustParseIpRef

func MustParseIpRef(str string) IpRef

func ParseIpRef

func ParseIpRef(str string) (ipref IpRef, err error)

func (IpRef) String

func (ipref IpRef) String() string

type Ref

type Ref Uint128

The zero ref is Ref{}

func MustParseRef

func MustParseRef(str string) Ref

func ParseRef

func ParseRef(str string) (Ref, error)

func ParseRefInPrefix

func ParseRefInPrefix(str string) (Ref, error)

func RefFromBytesBE

func RefFromBytesBE(src []byte) Ref

func (Ref) AsSliceBE

func (ref Ref) AsSliceBE() []byte

func (Ref) IsZero

func (ref Ref) IsZero() bool

func (Ref) String

func (ref Ref) String() string

func (Ref) StringInPrefix

func (ref Ref) StringInPrefix() string

type RefPrefix

type RefPrefix struct {
	// contains filtered or unexported fields
}

The zero value is the prefix which contains all refs

func MustParseRefPrefix

func MustParseRefPrefix(s string) RefPrefix

func ParseRefPrefix

func ParseRefPrefix(s string) (RefPrefix, error)

func RefPrefixComplete

func RefPrefixComplete() RefPrefix

func RefPrefixFrom

func RefPrefixFrom(ref Ref, bits int) RefPrefix

func RefPrefixSingle

func RefPrefixSingle(ref Ref) RefPrefix

func (RefPrefix) Bits

func (p RefPrefix) Bits() int

func (RefPrefix) Contains

func (p RefPrefix) Contains(ref Ref) bool

func (RefPrefix) Ref

func (p RefPrefix) Ref() Ref

func (RefPrefix) RefUint128

func (p RefPrefix) RefUint128() Uint128

func (RefPrefix) SizeBits

func (p RefPrefix) SizeBits() int

func (RefPrefix) String

func (p RefPrefix) String() string

type Uint128

type Uint128 struct {
	L, H uint64
}

func MustParseUint128

func MustParseUint128(s string, base int) Uint128

func ParseUint128

func ParseUint128(s string, base int) (Uint128, bool)

func Uint128FromBig

func Uint128FromBig(i *big.Int) (Uint128, bool)

func Uint128FromBytesBE

func Uint128FromBytesBE(src []byte) Uint128

func Uint128FromBytesLE

func Uint128FromBytesLE(src []byte) Uint128

func Uint128FromUint8

func Uint128FromUint8(x uint8) Uint128

func Uint128FromUint16

func Uint128FromUint16(x uint16) Uint128

func Uint128FromUint32

func Uint128FromUint32(x uint32) Uint128

func Uint128FromUint64

func Uint128FromUint64(x uint64) Uint128

func (Uint128) Add

func (x Uint128) Add(y Uint128) (z Uint128)

func (Uint128) AddCarry

func (x Uint128) AddCarry(y Uint128, cin uint64) (z Uint128, cout uint64)

func (Uint128) And

func (x Uint128) And(y Uint128) Uint128

func (Uint128) AndNot

func (x Uint128) AndNot(y Uint128) Uint128

func (Uint128) AsBytesBE

func (x Uint128) AsBytesBE() (dst [16]byte)

func (Uint128) AsBytesLE

func (x Uint128) AsBytesLE() (dst [16]byte)

func (Uint128) AsSliceBE

func (x Uint128) AsSliceBE() []byte

func (Uint128) AsSliceLE

func (x Uint128) AsSliceLE() []byte

func (Uint128) Big

func (x Uint128) Big() *big.Int

func (Uint128) Bit

func (x Uint128) Bit(n int) uint

func (Uint128) BitLen

func (x Uint128) BitLen() int

func (Uint128) Cmp

func (x Uint128) Cmp(y Uint128) int

func (Uint128) Compl

func (x Uint128) Compl() Uint128

func (Uint128) Format

func (x Uint128) Format(base int) string

func (Uint128) FormatHex

func (x Uint128) FormatHex() string

func (Uint128) Int

func (x Uint128) Int() int

func (Uint128) IntCheck

func (x Uint128) IntCheck() (int, bool)

func (Uint128) IsZero

func (x Uint128) IsZero() bool

func (Uint128) LeadingZeros

func (x Uint128) LeadingZeros() int

func (Uint128) Lsh

func (x Uint128) Lsh(n uint) Uint128

func (Uint128) Mul

func (x Uint128) Mul(y Uint128) (z Uint128)

func (Uint128) Or

func (x Uint128) Or(y Uint128) Uint128

func (Uint128) PutBytesBE

func (x Uint128) PutBytesBE(dst []byte)

func (Uint128) PutBytesLE

func (x Uint128) PutBytesLE(dst []byte)

func (Uint128) Rsh

func (x Uint128) Rsh(n uint) Uint128

func (Uint128) String

func (x Uint128) String() string

func (Uint128) Sub

func (x Uint128) Sub(y Uint128) (z Uint128)

func (Uint128) SubBorrow

func (x Uint128) SubBorrow(y Uint128, bin uint64) (z Uint128, bout uint64)

func (Uint128) TrailingZeros

func (x Uint128) TrailingZeros() int

func (Uint128) Uint8

func (x Uint128) Uint8() uint8

func (Uint128) Uint8Check

func (x Uint128) Uint8Check() (uint8, bool)

func (Uint128) Uint16

func (x Uint128) Uint16() uint16

func (Uint128) Uint16Check

func (x Uint128) Uint16Check() (uint16, bool)

func (Uint128) Uint32

func (x Uint128) Uint32() uint32

func (Uint128) Uint32Check

func (x Uint128) Uint32Check() (uint32, bool)

func (Uint128) Uint64

func (x Uint128) Uint64() uint64

func (Uint128) Uint64Check

func (x Uint128) Uint64Check() (uint64, bool)

func (Uint128) Xor

func (x Uint128) Xor(y Uint128) Uint128

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL