ipmap

package
v0.0.0-...-7cc747a Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UndelegatedDomainsTrie = newUndelegatedDomainTrie()

Functions

func NewIPMap

func NewIPMap() *ipmap

func NewIPMapFor

func NewIPMapFor(r IPMapper) *ipmap

NewIPMapFor returns a fresh IPMap with r as its nameserver.

Types

type IPMap

type IPMap interface {
	IPMapper
	// Resolves hostOrIP and adds the resulting IPs to its IPSet.
	// hostOrIP may be host:port, or ip:port, or host, or ip.
	Add(hostOrIP string) *IPSet
	// Returns the IPSet for host, creating it if necessary, with
	// ips as its initial or appended contents.
	AddMany(host string, ips []netip.Addr) *IPSet
	// Get creates an IPSet for this hostname populated with the IPs
	// discovered by resolving it. Subsequent calls to Get return the
	// same IPSet. Never returns nil.
	// hostOrIP may be host:port, or ip:port, or host, or ip.
	Get(hostOrIP string) *IPSet
	// GetAny creates an IPSet for this hostname, which may be empty.
	// Subsequent calls to GetAny return the same IPSet. Never returns nil.
	// hostOrIP may be host:port, or ip:port, or host, or ip.
	GetAny(hostOrIP string) *IPSet
	// GetMany returns a list of sampled IPs from the ipmap cache.
	// ipver is one of "v4", "v6", or "" (for both).
	GetMany(n uint8, ipver string) []netip.Addr
	// MakeIPSet creates an IPSet for this hostname bootstrapped with given IPs
	// or IP:Ports. Subsequent calls to MakeIPSet return a new, overridden IPSet.
	// hostOrIP may be host:port, or ip:port, or host, or ip.
	MakeIPSet(hostOrIP string, ipps []string, typ IPSetType) *IPSet
	// Reverse lookup; returns hostnames for the given IP address.
	ReverseGet(ip netip.Addr) []string
	// ReverseGetMany returns a list of sampled hostnames from the ipmap cache.
	// ipver is one of "v4", "v6", or "" (for both).
	ReverseGetMany(n uint8, ipver string) []string
	// With sets the default resolver to use for hostname resolution.
	With(r IPMapper)
	// Clear removes all IPSets from the map.
	Clear()
}

IPMap maps hostnames to IPSets.

type IPMapper

type IPMapper interface {
	// Lookup resolves q over client-code preferred tid conveyed via
	// DNSOpts returned from DNSListener.OnQuery. As a special case, UID
	// may be protect.MyUid or core.UNKNOWN_UID_STR ("-1")
	// but otherwise it is usually a Linux user-id assigned to a process
	// which presumably is requesting this lookup. If tids is empty, either
	// dnsx.Default, and if that fails, dnsx.System or dnsx.Goos tids.
	Lookup(q []byte, uid string, tids ...string) ([]byte, error)
	// LookupNetIP is like Lookup but for hostname to IP addresses.
	LookupNetIP(ctx context.Context, network, host, uid string, tids ...string) ([]netip.Addr, error)
}

IPMapper is an interface for resolving hostnames to IP addresses. Capable of handling special internal hostnames, it is mostly used by firestack for its own use.

type IPSet

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

IPSet represents an unordered collection of IP addresses for a single host. One IP can be marked as confirmed to be working correctly.

func (*IPSet) Addrs

func (s *IPSet) Addrs() []netip.Addr

Addrs returns a copy of the IP set as a slice in random order. The slice is owned by the caller, but the elements are owned by the set.

func (*IPSet) Confirm

func (s *IPSet) Confirm(ip netip.Addr)

Confirm marks ip as the confirmed address. No-op if current confirmed IP is the same as ip. No-op if s is of type Protected and ip isn't in seed addrs. No-op if s is of type IPAddr.

func (*IPSet) Confirmed

func (s *IPSet) Confirmed() netip.Addr

Confirmed returns the confirmed IP address, or zeroaddr if there is no such address.

func (*IPSet) Disconfirm

func (s *IPSet) Disconfirm(ip netip.Addr) (done bool)

Disconfirm sets the confirmed address to zeroaddr if the current confirmed address is the provided ip.

func (*IPSet) Empty

func (s *IPSet) Empty() bool

Empty reports whether the set is empty.

func (*IPSet) OneIPOnly

func (s *IPSet) OneIPOnly() bool

func (*IPSet) Protected

func (s *IPSet) Protected() bool

func (*IPSet) Reset

func (s *IPSet) Reset() *IPSet

Reset clears existing IPs for Regular and Protected types, while it is a no-op for type IPAddr.

func (*IPSet) Seed

func (s *IPSet) Seed() []string

Returns bootstrap ips or ip:ports.

func (*IPSet) Size

func (s *IPSet) Size() uint32

type IPSetType

type IPSetType int

Type of IPSet.

const (
	Protected IPSetType = iota
	Regular
	IPAddr
	AutoType
)

func (IPSetType) String

func (h IPSetType) String() string