Documentation
¶
Overview ¶
Package physnet connects VirtoMir to the physical network (D16, ADR-0075): SR-IOV virtual functions on the host's NICs, BGP (and EVPN for the VXLAN overlays) through FRR, IP address pools that hand machines fixed addresses, and dynamic DNS (RFC 2136 with TSIG) for them. Commands run through a Runner and sysfs through a root directory, so everything is tested without the hardware. SR-IOV and BGP are experimental: not tested on hardware.
Index ¶
- Variables
- func FRRConfig(c BGPConfig) (string, error)
- func Register(ctx context.Context, c DNSConfig, host string, ips []netip.Addr) error
- func ReverseName(ip netip.Addr) string
- func Unregister(ctx context.Context, c DNSConfig, host string, ips []netip.Addr) error
- type Allocation
- type BGPConfig
- type BGPNeighbor
- type BGPSession
- type DNSConfig
- type Exec
- type FRRStatus
- type IPPool
- type Released
- type Runner
- type SRIOV
- type SRIOVDevice
- type Shared
- type Store
- func (s *Store) Adopt(sh Shared) (bool, error)
- func (s *Store) Allocate(id string, a Allocation, want string) (Allocation, error)
- func (s *Store) BGP() BGPConfig
- func (s *Store) Check(id, ip string) (string, error)
- func (s *Store) Claim(id, ip, uuid string) error
- func (s *Store) CreatePool(p IPPool) (IPPool, error)
- func (s *Store) DNS() DNSConfig
- func (s *Store) DeletePool(id string) error
- func (s *Store) Pool(id string) (IPPool, bool)
- func (s *Store) Pools() []IPPool
- func (s *Store) Release(id, ip string) error
- func (s *Store) ReleaseVM(uuid string) ([]Released, error)
- func (s *Store) SetBGP(c BGPConfig) error
- func (s *Store) SetDNS(c DNSConfig) (DNSConfig, error)
- func (s *Store) Shared() Shared
- func (s *Store) UpdatePool(p IPPool) (IPPool, error)
- type VF
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalid = errors.New("invalid") ErrNotFound = errors.New("not found") ErrExists = errors.New("exists") ErrBusy = errors.New("in use") ErrConflict = errors.New("conflict") )
Errors for the API.
var FRRFile = "/etc/frr/virtomir-bgp.conf"
FRRFile is where the section is kept for people to read; FRR's own saved configuration holds it too after write memory.
var Host = SRIOV{Root: "/", RulesDir: "/etc/udev/rules.d"}
Host is the real host.
Functions ¶
func Register ¶
Register points host's name at ips (replacing what it had) and each address back at the name.
func ReverseName ¶
ReverseName is the PTR name of an address: 50.0.20.10.in-addr.arpa.
Types ¶
type Allocation ¶
type Allocation struct {
IP string `json:"ip"`
MAC string `json:"mac,omitempty"`
VMUUID string `json:"vmUuid,omitempty"`
VMName string `json:"vmName,omitempty"`
// Hostname is the machine's DNS name in the zone ("" = not registered).
Hostname string `json:"hostname,omitempty"`
Host string `json:"host,omitempty"` // the member the machine was created on
Created time.Time `json:"created"`
}
Allocation is an address a machine holds.
type BGPConfig ¶
type BGPConfig struct {
Enabled bool `json:"enabled"`
LocalAS uint32 `json:"localAs"`
RouterID string `json:"routerId"`
Neighbors []BGPNeighbor `json:"neighbors"`
// Announce are the networks this host announces (its NAT or routed subnets).
Announce []string `json:"announce"`
// EVPN announces the host's VXLAN overlays (advertise-all-vni), so leaf switches and
// other hosts learn where machines are instead of flooding.
EVPN bool `json:"evpn"`
// AppliedAS is the AS VirtoMir last configured, to remove that section on a change.
AppliedAS uint32 `json:"appliedAs,omitempty"`
}
BGPConfig is this host's BGP speaker.
type BGPNeighbor ¶
type BGPNeighbor struct {
Address string `json:"address"`
RemoteAS uint32 `json:"remoteAs"`
Description string `json:"description,omitempty"`
Password string `json:"password,omitempty"`
BFD bool `json:"bfd,omitempty"`
}
BGPNeighbor is a router this host peers with.
type BGPSession ¶
type BGPSession struct {
Address string `json:"address"`
RemoteAS uint32 `json:"remoteAs"`
Description string `json:"description,omitempty"`
State string `json:"state"` // Established, Active, Connect, Idle, …
Uptime string `json:"uptime,omitempty"`
Received int `json:"prefixesReceived"`
Sent int `json:"prefixesSent"`
Families []string `json:"families"` // ipv4Unicast, ipv6Unicast, l2VpnEvpn
}
BGPSession is a neighbor as FRR sees it.
type DNSConfig ¶
type DNSConfig struct {
Enabled bool `json:"enabled"`
Server string `json:"server"` // host or host:port of the primary server
Zone string `json:"zone"` // corp.example.
// ReverseZones get the PTR records: 20.10.in-addr.arpa., …; none = no PTR records.
ReverseZones []string `json:"reverseZones,omitempty"`
KeyName string `json:"keyName,omitempty"` // the TSIG key, e.g. virtomir.
Algorithm string `json:"algorithm,omitempty"` // hmac-sha256 (default), hmac-sha512 or hmac-md5
Secret string `json:"secret,omitempty"` // base64, as in the server's key file
TTL uint32 `json:"ttl,omitempty"`
}
DNSConfig is where updates go and how they are signed.
type FRRStatus ¶
type FRRStatus struct {
Installed bool `json:"installed"`
Version string `json:"version,omitempty"`
BGPD bool `json:"bgpd"`
}
FRRStatus says whether FRR runs here with bgpd.
type IPPool ¶
type IPPool struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Network string `json:"network,omitempty"` // the libvirt network machines join for it
CIDR string `json:"cidr"`
Gateway string `json:"gateway,omitempty"`
RangeStart string `json:"rangeStart"`
RangeEnd string `json:"rangeEnd"`
DNSServers []string `json:"dnsServers,omitempty"`
// Domain is the DNS search domain the machines get.
Domain string `json:"domain,omitempty"`
Reserved []string `json:"reserved,omitempty"`
Allocations []Allocation `json:"allocations"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
}
IPPool is a range of addresses of one network.
type Released ¶
type Released struct {
Pool string `json:"pool"`
Allocation
}
Released is an allocation that was given back, with its pool.
type SRIOV ¶
SRIOV reads the host's SR-IOV NICs from sysfs under root ("/" on a host) and the udev rules VirtoMir wrote in rulesDir.
func (SRIOV) Devices ¶
func (s SRIOV) Devices() ([]SRIOVDevice, error)
Devices lists the SR-IOV capable NICs.
type SRIOVDevice ¶
type SRIOVDevice struct {
Interface string `json:"interface"`
PCI string `json:"pci"`
Driver string `json:"driver"`
TotalVFs int `json:"totalVfs"`
CurrentVFs int `json:"currentVfs"`
VFs []VF `json:"vfs"`
// Persistent: a udev rule sets the VF count again at boot.
Persistent bool `json:"persistent"`
}
SRIOVDevice is an SR-IOV capable NIC.
type Shared ¶
type Shared struct {
}
Shared is what members exchange (newest version wins): the IP pools with their allocations and the dynamic DNS settings.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store keeps -state-dir/physnet.json.
func (*Store) Adopt ¶
Adopt takes over a member's shared state when it is newer; it reports whether it did.
func (*Store) Allocate ¶
func (s *Store) Allocate(id string, a Allocation, want string) (Allocation, error)
Allocate gives a machine an address of pool id: want if free, else the first free one. A machine that holds an address of the pool keeps it.
func (*Store) Claim ¶
Claim binds an address that was handed out before the machine existed to its UUID.
func (*Store) CreatePool ¶
CreatePool adds a pool; it must not overlap another pool's range.
func (*Store) DeletePool ¶
DeletePool removes a pool nobody holds addresses of.