resip

package
v3.0.0-rc67 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 28 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// AnnounceCount is the number of announces a start sends, every
	// AnnounceInterval, as "arping -U -c 3" does: a neighbor missing the one
	// a start used to send kept the address on the mac of the namespace it
	// left, until its probe of the entry failed.
	AnnounceCount    = 3
	AnnounceInterval = time.Second
)
View Source
const (
	// SourceRulePriority is the priority of the rules of the addresses,
	// before the lookup of the main table at 32766. A rule a user adds
	// with no priority lands before it, and wins. The rules of this
	// priority are om's: a rule of another priority, as one of an ip.rule
	// resource, is left alone.
	SourceRulePriority = 32000
)

Variables

View Source
var (
	KeywordWaitDNS = keywords.Keyword{
		Attr:      "WaitDNS",
		Converter: converters.Duration,
		Default:   "0",
		Example:   "10s",
		Option:    "wait_dns",
		Group:     GroupDNS.ID,
		Scopable:  true,
		Text:      keywords.NewText(fs, "text/kw/wait_dns"),
	}

	// GroupAddressing is the group of the keywords saying the address of
	// the ip drivers plumbing one on an interface, ip.host and ip.netns:
	// written in the configuration, or drawn from an om network. The two
	// ways are its strategies, as a configuration naming an address and a
	// network says two addresses for one resource.
	//
	// The netmask is the static way's, but a network does not exclude
	// it: the netmask a configuration sets overrides the one of the
	// network.
	GroupAddressing = keywords.Group{
		ID:    "addressing",
		Name:  "Addressing",
		Text:  keywords.NewText(fs, "text/group/addressing"),
		Order: 10,

		Required: true,
		Strategies: []keywords.Strategy{
			{
				ID:       "static",
				Name:     "Static address",
				Text:     keywords.NewText(fs, "text/strategy/addressing/static"),
				Uses:     []string{"name"},
				Excludes: []string{"network", "addr"},

				Requires: []string{"dev"},
			},
			{
				ID:       "ipam",
				Name:     "Address drawn from a network",
				Text:     keywords.NewText(fs, "text/strategy/addressing/ipam"),
				Uses:     []string{"network", "addr"},
				Excludes: []string{"name"},
			},
		},
	}

	// GroupDNS is the group of the keywords saying the records the cluster
	// DNS serves for the address of the ip drivers handing one to the
	// daemon, ip.host, ip.netns and ip.cni: the SRV records of the
	// services it exposes, the suffix of its name, and whether a start
	// waits for them.
	GroupDNS = keywords.Group{
		ID:    "dns",
		Name:  "DNS",
		Text:  keywords.NewText(fs, "text/group/dns"),
		Order: 40,
	}
)
View Source
var ErrAnnounceUnsupported = errors.New("not supported on this operating system")

ErrAnnounceUnsupported is the error of the senders of an operating system om does not announce an address on. An announce meeting it sends nothing more and warns, rather than fail the start of the address: the neighbors learn the address when they next resolve it.

View Source
var (
	ErrSourceTableInUse = errors.New("the table is used by routes of another card")
)

Functions

func AllocateDevLabel

func AllocateDevLabel(dev string) (string, error)

func IsAddr

func IsAddr(s string) bool

IsAddr reports whether a value is an address or a subnet, which is what the network keyword used to hold.

func NetworkNameservers

func NetworkNameservers(name string) []string

NetworkNameservers returns the nameservers the network named says are reachable from it, none when it names none, or is not an om network.

func NetworkRouteNeeded

func NetworkRouteNeeded(network, connected *net.IPNet, gateway net.IP) bool

NetworkRouteNeeded says the namespace needs a route to the network through the gateway: the connected route of the address covers a part of the network only, as the range of a node of a routed_bridge network does, and the gateway is in that connected route. A bridge or a lan network has its whole segment connected.

func PerInstance

func PerInstance(shared bool, obj any) bool

PerInstance says each instance draws an address of its own, which is the case of a resource not shared of a flex object: its instances run at once, and an address they all brought up would be one address on several nodes.

A failover object runs one instance at a time, which takes the address along when it moves. A shared resource of a flex object is one address for all its instances, should that be the point.

func ProvisionStarts

func ProvisionStarts(ctx context.Context, standby bool) bool

ProvisionStarts says whether the provision of an address starts it: on the placement leader, and on every node for a standby resource.

Off the leader, the provision of an instance stops what it started, the leader starting the instance. An address started there for that while is held by two nodes at once when it is not one of the node's own, as the one a lan network hands to the cluster, or one the configuration names: a duplicate on the segment, which an ipv6 node configuring it at the same time takes for an address in use, and never uses. Starting it serves nothing: an address drawn from a network is drawn whether it is up or not.

func SplitDevLabel

func SplitDevLabel(s string) (string, string)

func TableID

func TableID(ip net.IP) int

TableID is the routing table of the address: the address itself, as a number, for an ipv4 one, and a hash of it, its high bit set, for an ipv6 one. Unique per address, so two addresses sharing a card have a table each, found again from the address alone, and clear of the tables the kernel and the users name, all under 2^31 in practice for ipv6, and far above the small ones for ipv4.

func WaitDNSRecord

func WaitDNSRecord(ctx context.Context, timeout *time.Duration, name string, nameservers []string) error

Types

type Allocation

type Allocation struct {
	// Network is the value of the network keyword.
	Network string

	// Path and RID name the resource, which the address is reserved for.
	Path naming.Path
	RID  string

	Log *plog.Logger
	// contains filtered or unexported fields
}

Allocation is the address an ip resource draws from the om network its network keyword names.

func (*Allocation) Allocate

func (t *Allocation) Allocate(ctx context.Context) (net.IP, error)

Allocate reserves the address of the resource, and returns the one it already holds when it holds one.

func (*Allocation) Allocated

func (t *Allocation) Allocated() (net.IP, error)

Allocated returns the address reserved for the resource, nil when it has none. It never reserves one: reading a status must not take an address.

func (*Allocation) Allocator

func (t *Allocation) Allocator() (*ipam.T, error)

Allocator returns the allocator of the network the resource draws from, nil when it draws from none.

func (*Allocation) Free

func (t *Allocation) Free() error

Free releases the address of the resource.

func (*Allocation) Keep

func (t *Allocation) Keep(ip net.IP) error

Keep reserves again ip, the address the resource has configured on this node and could not give up for the one it drew, which is released. Unlike Reserve, it takes an address the ranges of the network no longer hold, as such an address is the one a resource is most often made to give up.

func (*Allocation) Key

func (t *Allocation) Key() string

Key names the reservation of the resource. An instance holds as many ip resources as it needs, several of them in one network, so the address belongs to the resource rather than to the object.

func (*Allocation) Redraw

func (t *Allocation) Redraw(ctx context.Context, previous net.IP) (net.IP, error)

Redraw releases the address the resource holds, previous, and reserves another one.

func (*Allocation) Reserve

func (t *Allocation) Reserve(ip net.IP) (net.IP, error)

Reserve records ip as the address of the resource on this node, the one its configuration says it drew on another node or earlier: the address is the resource's, whichever node drew it. A reservation of another address for the resource is released, and returned, for the resource to give it up on the node too: the addr keyword changed. An address another resource holds on this node is refused.

func (*Allocation) Resolve

func (t *Allocation) Resolve() (network.Networker, error)

Resolve returns the om network the network keyword names, nil when it names none.

The keyword used to hold the address of the network in dotted notation. A value that is still an address is therefore obsolete rather than wrong: it is reported and ignored. A value that is neither an address nor a network is a mistake worth stopping for, a renamed network or a typo.

type Announce

type Announce struct {
	Log *plog.Logger

	// Dev is the name of the card holding the addresses.
	Dev string

	// IPs are the addresses to announce. A loopback or a link local one
	// is not announced.
	IPs []net.IP

	// Count is the number of announces of each address, Interval apart.
	// A zero Count announces once.
	Count    int
	Interval time.Duration

	// In runs each round of announces in the network namespace of Dev.
	// A nil In runs them in the namespace of the caller.
	In func(func() error) error
}

Announce tells the neighbors of the link of Dev that its addresses are on the mac of Dev: a gratuitous arp for an ipv4 address, an unsolicited neighbor advertisement for an ipv6 one. Without it, the neighbors of an address moved to another node, or to a new card, keep sending to the mac it left until their cache entry expires.

func (Announce) Send

func (t Announce) Send() error

Send announces the addresses Count times, Interval apart, and stops on its first error. An operating system om does not announce on is warned of, and is not an error.

type Kept

type Kept struct {
	Path        naming.Path
	RID         string
	Network     string
	PerInstance bool
	Log         *plog.Logger
	// contains filtered or unexported fields
}

Kept is the address a resource draws from a network and keeps from a start to the next, until it is unprovisioned: the address is the service's, which its clients know it by.

The address of all the instances is recorded in the addr keyword of the configuration, which every node holds, whatever became of the node that drew it: a node the service fails over to after the others crashed reads it there, rather than draw again from a cluster that forgot them. The address of an instance, when each draws its own, is kept in the reservation store of its node.

func NewKept

func NewKept(p naming.Path, rid, network string, shared bool, obj any, log *plog.Logger) *Kept

NewKept returns the address a resource keeps. The object says whether each instance draws its own.

func (*Kept) AddrKey

func (t *Kept) AddrKey() key.T

AddrKey is where the address drawn is recorded: addr, the same on every node, or addr@<node>, the address root chose for this instance when each instance draws its own.

func (*Kept) Alloc

func (t *Kept) Alloc() *Allocation

Alloc returns the reservation of the address, the one of this instance when each instance draws its own, apart from the ones of the other nodes.

func (*Kept) Duplicates

func (t *Kept) Duplicates(ip net.IP) []string

Duplicates returns the resources of the other nodes the peer records say hold ip, the address of this one, as "<key> on <node>".

The address of a failover resource is the same on every node, a stopped instance reporting it too, which is no duplicate. Another resource holding it, or another instance of a resource drawing per instance, is: two halves of a cluster not hearing each other draw from the same range blind to each other, and the duplicate is for an administrator to clean up.

func (*Kept) HasOwnAddr

func (t *Kept) HasOwnAddr(obj any) bool

HasOwnAddr says the configuration records an address for this instance under its own key, rather than one the evaluation fell back on.

func (*Kept) Provisioned

func (t *Kept) Provisioned(addr string) (provisioned.T, error)

Provisioned says whether the resource keeps an address on this node, which its unprovision releases: the reservation of this node, or addr, the address of all the instances, recorded in the configuration every node holds. An instance of a failover object that never ran keeps addr all the same, and the unprovision of the leader is what removes it.

It is what a resource with no provisioned state cached yet is found in: a resource upgraded from an agent that had it n/a, or one created with its address. Its unprovision then clears the state on every instance, while addr is still recorded until the leader is done.

func (*Kept) Record

func (t *Kept) Record(ctx context.Context, previous, addr string) error

Record writes the address drawn from the network in the configuration of the object, which the daemon brings to the other nodes, and unsets the one recorded, previous, when addr is empty.

func (*Kept) Release

func (t *Kept) Release(ctx context.Context, addr string, leader bool) error

Release releases the reservation of this node, and, on the leader, removes from the configuration addr, the address of all the instances, once for all of them.

func (*Kept) Reserve

func (t *Kept) Reserve(ctx context.Context, addr string) (net.IP, net.IP, error)

Reserve returns the address of the resource, reserved on this node: addr, the one the configuration says it drew, or else one drawn now and written to the configuration. It also returns the address the resource gave up for it, nil when it gave none up: the one this node held for it before a redraw, or before addr was changed.

A configuration with no address while this node holds one for the resource had it unset, since om writes it as it draws and unsets it as it releases. Unsetting it is asking for another address, so the one held is given up rather than drawn again, which the draw would do, keyed as it is on the resource.

func (*Kept) Restore

func (t *Kept) Restore(ctx context.Context, previous, ip net.IP) error

Restore gives the resource back previous, the address it gave up for ip, which it could not take off the node: reserved again, and recorded again, so no other resource draws an address still configured. ip is released.

type SourceRoute

type SourceRoute struct {
	// Addr is the address, with the prefix of its connected route.
	Addr *net.IPNet

	// Dev is the name of the card holding the address in the
	// namespace.
	Dev string

	// Network is the om network the address is drawn from, nil when
	// unknown.
	Network *net.IPNet

	// Gateway is the gateway of the address, nil when none is known.
	Gateway net.IP

	// OnLink says the connected route of the address is removed, as
	// the del_net_route keyword of ip.netns asks: the gateway is
	// reached on the link.
	OnLink bool
}

SourceRoute is the policy routing of an address of a network namespace: the address answers by the gateway of its own network, whatever the default route of the namespace, which belongs to one address only. A namespace holding addresses of several networks had the replies of the others leave by that default route, out of an interface the requests did not come in by, and the strict reverse path filter of the node, or its forward chain, dropped them.

The rule "from <address> lookup <table>" sends what the address sends to a table of its own, holding the route to its network and a default route by its gateway. With no gateway known, the table holds no default route, and the lookup falls through to the main table, as before.

func (SourceRoute) Apply

func (t SourceRoute) Apply(netns ns.NetNS, log *plog.Logger) error

Apply sets the rule and the table of the address in the namespace, as "ip rule add from <address> lookup <table> priority 32000" and "ip route replace ... table <table>" do. A rule of the address to another table, as left by a former card, goes with its table.

func (SourceRoute) Check

func (t SourceRoute) Check(netns ns.NetNS) error

Check returns an error saying what is missing of the policy routing of the address: the rule, or the default route of its table.

func (SourceRoute) IPv6

func (t SourceRoute) IPv6() bool

IPv6 says the address is an ipv6 one.

func (SourceRoute) Remove

func (t SourceRoute) Remove(netns ns.NetNS, log *plog.Logger) error

Remove deletes the rules of the address of om's priority and the tables they name, as "ip rule del" and "ip route flush table" do. The kernel removes the routes of a card deleted, but not the rules, and not the routes of a card kept, as one shared by several addresses.

func (SourceRoute) Routes

func (t SourceRoute) Routes(table, linkIndex int) []netlink.Route

Routes returns the routes of the table of the address, the card of index linkIndex: the connected route of the address, unless removed, the route to its network when the connected route covers a part of it only, and the default route by its gateway, when known.

No route carries the address as its source: the table is looked up only for the packets that already carry it, by the rule of the address, so the source of a route would never be used. And the kernel refuses an ipv6 address as the source of a route while it is tentative, as it is right after it is added, until the duplicate address detection ends.

func (SourceRoute) Src

func (t SourceRoute) Src() *net.IPNet

Src is the source the rule of the address matches: the address alone.

Jump to

Keyboard shortcuts

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