ippool

package
v0.0.0-...-1b709f2 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: BSD-3-Clause Imports: 22 Imported by: 0

Documentation

Overview

ippool implements IP address storage, creation, and retrieval for cmd/natc

Index

Constants

This section is empty.

Variables

View Source
var ErrNoIPsAvailable = errors.New("no IPs available")

Functions

This section is empty.

Types

type ClusterOpts

type ClusterOpts struct {
	Tag        string
	StateDir   string
	FollowOnly bool
}

type ConsensusIPPool

type ConsensusIPPool struct {
	IPSet *netipx.IPSet
	// contains filtered or unexported fields
}

ConsensusIPPool implements an IPPool that is distributed among members of a cluster for high availability. Writes are directed to a leader among the cluster and are slower than reads, reads are performed locally using information replicated from the leader. The cluster maintains consistency, reads can be stale and writes can be unavailable if sufficient cluster peers are unavailable.

func NewConsensusIPPool

func NewConsensusIPPool(ipSet *netipx.IPSet) *ConsensusIPPool

func (*ConsensusIPPool) Apply

func (ipp *ConsensusIPPool) Apply(lg *raft.Log) any

Apply is part of the raft.FSM interface. It takes an incoming log entry and applies it to the state.

func (*ConsensusIPPool) DeleteClusterServer

func (ipp *ConsensusIPPool) DeleteClusterServer(id raft.ServerID) (uint64, error)

DeleteClusterServer removes a server from the consensus implementation's cluster configuration

func (*ConsensusIPPool) DomainForIP

func (ipp *ConsensusIPPool) DomainForIP(from tailcfg.NodeID, addr netip.Addr, updatedAt time.Time) (string, bool)

DomainForIP looks up the domain associated with a tailcfg.NodeID and netip.Addr pair. If there is no association, the result is empty and ok is false.

func (*ConsensusIPPool) GetClusterConfiguration

func (ipp *ConsensusIPPool) GetClusterConfiguration() (raft.Configuration, error)

GetClusterConfiguration gets the consensus implementation's cluster configuration

func (*ConsensusIPPool) IPForDomain

func (ipp *ConsensusIPPool) IPForDomain(nid tailcfg.NodeID, domain string) (netip.Addr, error)

IPForDomain looks up or creates an IP address allocation for the tailcfg.NodeID and domain pair. If no address association is found, one is allocated from the range of free addresses for this tailcfg.NodeID. If no more address are available, an error is returned.

func (*ConsensusIPPool) Restore

func (ipp *ConsensusIPPool) Restore(rc io.ReadCloser) error

Restore is part of the raft.FSM interface. According to the docs it:

  • will not be called concurrently with any other command
  • the FSM must discard all previous state before restoring

func (*ConsensusIPPool) Snapshot

func (ipp *ConsensusIPPool) Snapshot() (raft.FSMSnapshot, error)

Snapshot is part of the raft.FSM interface. According to the docs it:

  • should return quickly
  • will not be called concurrently with Apply
  • the snapshot returned will have Persist called on it concurrently with Apply (so it should not contain pointers to the original data that's being mutated)

func (*ConsensusIPPool) StartConsensus

func (ipp *ConsensusIPPool) StartConsensus(ctx context.Context, ts *tsnet.Server, opts ClusterOpts) error

StartConsensus is part of the IPPool interface. It starts the raft background routines that handle consensus.

func (*ConsensusIPPool) StopConsensus

func (ipp *ConsensusIPPool) StopConsensus(ctx context.Context) error

StopConsensus is part of the IPPool interface. It stops the raft background routines that handle consensus.

type IPPool

type IPPool interface {
	// DomainForIP looks up the domain associated with a tailcfg.NodeID and netip.Addr pair.
	// If there is no association, the result is empty and ok is false.
	DomainForIP(tailcfg.NodeID, netip.Addr, time.Time) (string, bool)

	// IPForDomain looks up or creates an IP address allocation for the tailcfg.NodeID and domain pair.
	// If no address association is found, one is allocated from the range of free addresses for this tailcfg.NodeID.
	// If no more address are available, an error is returned.
	IPForDomain(tailcfg.NodeID, string) (netip.Addr, error)
}

IPPool allocates IPv4 addresses from a pool to DNS domains, on a per tailcfg.NodeID basis. For each tailcfg.NodeID, IPv4 addresses are associated with at most one DNS domain. Addresses may be reused across other tailcfg.NodeID's for the same or other domains.

type SingleMachineIPPool

type SingleMachineIPPool struct {
	IPSet *netipx.IPSet
	// contains filtered or unexported fields
}

func (*SingleMachineIPPool) DomainForIP

func (ipp *SingleMachineIPPool) DomainForIP(from tailcfg.NodeID, addr netip.Addr, _ time.Time) (string, bool)

func (*SingleMachineIPPool) IPForDomain

func (ipp *SingleMachineIPPool) IPForDomain(from tailcfg.NodeID, domain string) (netip.Addr, error)

Jump to

Keyboard shortcuts

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