genericitems

package
v0.0.0-...-a2e9de6 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// IPv4RouteTypename : typename for IPv4 route.
	// Not implemented in genericitems (implementation specific to network stack).
	IPv4RouteTypename = "IPv4Route"
	// IPv6RouteTypename : typename for IPv6 route.
	// Not implemented in genericitems (implementation specific to network stack).
	IPv6RouteTypename = "IPv6Route"
	// UnsupportedRouteTypename : typename which can be used for kinds of routes
	// not supported/expected by a particular implementation of NIReconciler.
	UnsupportedRouteTypename = "Unsupported-Route"
	// IPReserveTypename : typename for reserved IP address (for use with a bridge)
	IPReserveTypename = "IPReserve"
	// VIFTypename : typename for VIF.
	VIFTypename = "VIF"
	// UplinkTypename : typename for uplink interface.
	UplinkTypename = "Uplink"
	// HTTPServerTypename : typename for HTTP server.
	HTTPServerTypename = "HTTPServer"
	// DnsmasqTypename : typename for dnsmasq program (DNS and DHCP server).
	DnsmasqTypename = "Dnsmasq"
	// RadvdTypename : typename for radvd program (router advertisement daemon).
	RadvdTypename = "Radvd"
	// IPSetTypename : typename for Linux IP set (from netfilter).
	// Implemented in linuxitems.
	// Type definition is here because it is referenced by dnsmasq
	// (when used with Linux ipsets).
	IPSetTypename = "IPSet"
)

Variables

This section is empty.

Functions

func RegisterItems

func RegisterItems(log *base.LogObject, logger *logrus.Logger,
	registry *reconciler.DefaultRegistry) error

RegisterItems : register all configurators implemented by this package.

Types

type DHCPServer

type DHCPServer struct {
	// Subnet : network address + netmask (IPv4 or IPv6).
	Subnet *net.IPNet
	// AllOnesNetmask : if enabled, DHCP server will advertise netmask with all bits
	// set to one (e.g. /32 for IPv4) instead of using the actual netmask from Subnet.
	// This together with Classless routes (routing traffic for the actual Subnet)
	// can be used to force all traffic to go through the configured GatewayIP
	// (where ACLs could be applied).
	AllOnesNetmask bool
	// IPRange : a range of IP addresses to allocate from.
	// Not applicable for IPv6 (SLAAC is used instead).
	IPRange IPRange
	// GatewayIP : address of the default gateway to advertise (DHCP option 3).
	// Optional argument, leave empty to disable.
	GatewayIP net.IP
	// WithDefaultRoute : if enabled, default route is propagated to applications.
	WithDefaultRoute bool
	// DomainName : name of the domain assigned to the network.
	// It is propagated to clients using the DHCP option 15 (24 in DHCPv6).
	DomainName string
	// DNSServers : list of IP addresses of DNS servers to announce via DHCP option 6.
	// dnsmasq itself may or may not be part of this list. If empty, dnsmasq will not
	// announce itself as a DNS server!
	DNSServers []net.IP
	// NTP servers to announce via DHCP option 42 (56 in DHCPv6).
	NTPServers []net.IP
	// StaticEntries : list of MAC->(IP,hostname) entries statically configured
	// for the DHCP server.
	StaticEntries []MACToIP
	// PropagateRoutes : IP routes to propagate to applications using the DHCP option 121
	// (classless route option).
	PropagateRoutes []types.IPRoute
}

DHCPServer : part of the dnsmasq config specific to DHCP server.

func (DHCPServer) Equal

func (d DHCPServer) Equal(d2 DHCPServer, withStaticEntries bool) bool

Equal compares two DHCPServer instances

func (DHCPServer) String

func (d DHCPServer) String() string

String describes DHCPServer config.

type DNSServer

type DNSServer struct {
	// ListenIP : IP address (assigned to Dnsmasq.ListenIf) on which the DNS server
	// should listen.
	ListenIP net.IP
	// UplinkIf : uplink interface used to contact UpstreamServers.
	// Optional argument, leave zero value for NI without uplink.
	UplinkIf NetworkIf
	// UpstreamServers : list of IP addresses of public DNS servers to forward
	// requests to (unless there is a static entry).
	UpstreamServers []net.IP
	// StaticEntries : list of hostname->IPs entries statically configured
	// for the DNS server.
	StaticEntries []HostnameToIPs
	// LinuxIPSets : netfilter ipsets which dnsmasq will automatically fill with
	// resolved IPs.
	// Feature specific to Linux network stack. In zedrouter used for ACLs with hostnames.
	// For different network stacks we are likely going to need to come up with a different
	// way of implementing hostname-referencing ACLs.
	LinuxIPSets []LinuxIPSet
}

DNSServer : part of the dnsmasq config specific to DNS server.

func (DNSServer) Equal

func (d DNSServer) Equal(d2 DNSServer, withStaticEntries bool) bool

Equal compares two DNSServer instances

func (DNSServer) String

func (d DNSServer) String() string

String describes DNSServer config.

type Dnsmasq

type Dnsmasq struct {
	// ForNI : UUID of the Network Instance for which this Dnsmasq instance is created.
	// Mostly used just to force re-start of Dnsmasq when one NI is being deleted
	// and subsequently another is created with the same ListenIf + DNS/DHCP parameters
	// (ForNI will differ in such case).
	ForNI uuid.UUID
	// ListenIf : interface on which dnsmasq should listen.
	ListenIf NetworkIf
	// DHCPServer : part of the dnsmasq config specific to DHCP server.
	DHCPServer DHCPServer
	// DNSServer : part of the dnsmasq config specific to DNS server.
	DNSServer DNSServer
}

Dnsmasq : DNS and DHCP server (https://thekelleys.org.uk/dnsmasq/doc.html).

func (Dnsmasq) Dependencies

func (d Dnsmasq) Dependencies() (deps []dg.Dependency)

Dependencies returns:

  • the (downlink) interface and the IP on which the dnsmasq listens
  • the (uplink) interface used by dnsmasq to contact upstream DNS servers (if any)
  • every referenced ipset

func (Dnsmasq) Equal

func (d Dnsmasq) Equal(other dg.Item) bool

Equal compares two Dnsmasq instances

func (Dnsmasq) External

func (d Dnsmasq) External() bool

External returns false.

func (Dnsmasq) Label

func (d Dnsmasq) Label() string

Label for the dnsmasq instance.

func (Dnsmasq) Name

func (d Dnsmasq) Name() string

Name returns the interface name on which Dnsmasq listens. This ensures that there cannot be two different Dnsmasq instances that would attempt to listen on the same interface at the same time.

func (Dnsmasq) String

func (d Dnsmasq) String() string

String describes the dnsmasq instance.

func (Dnsmasq) Type

func (d Dnsmasq) Type() string

Type of the item.

type DnsmasqConfigurator

type DnsmasqConfigurator struct {
	Log    *base.LogObject
	Logger *logrus.Logger
}

DnsmasqConfigurator implements Configurator interface (libs/reconciler) for dnsmasq.

func (*DnsmasqConfigurator) Create

func (c *DnsmasqConfigurator) Create(ctx context.Context, item dg.Item) error

Create starts dnsmasq.

func (*DnsmasqConfigurator) CreateDHCPv4RangeConfig

func (c *DnsmasqConfigurator) CreateDHCPv4RangeConfig(start, end net.IP) (string, error)

CreateDHCPv4RangeConfig prepares a DHCPv4 range config line. The method is exported just to be exercised by unit tests.

func (*DnsmasqConfigurator) CreateDnsmasqConfig

func (c *DnsmasqConfigurator) CreateDnsmasqConfig(buffer io.Writer, dnsmasq Dnsmasq) error

CreateDnsmasqConfig builds configuration for dnsmasq and writes it to the given buffer. The method is exported just to be exercised by unit tests.

func (*DnsmasqConfigurator) Delete

func (c *DnsmasqConfigurator) Delete(ctx context.Context, item dg.Item) error

Delete stops dnsmasq.

func (*DnsmasqConfigurator) Modify

func (c *DnsmasqConfigurator) Modify(ctx context.Context, oldItem, newItem dg.Item) (err error)

Modify is able to update DHCP/DNS hosts files and apply the changes simply by sending the SIGHUP signal, i.e. without having to restart the dnsmasq process.

func (*DnsmasqConfigurator) NeedsRecreate

func (c *DnsmasqConfigurator) NeedsRecreate(oldItem, newItem dg.Item) (recreate bool)

NeedsRecreate returns false if only DHCP/DNS hosts files have changed.

type HTTPServer

type HTTPServer struct {
	// ForNI : UUID of the Network Instance for which this HTTP server is created.
	// Mostly used just to force re-start of the server when one NI is being deleted
	// and subsequently another is created with the same bridge interface name
	// and IP address. Since Handler is not comparable, ForNI will do the trick
	// to make the new HTTP server unequal to the previous one.
	ForNI uuid.UUID
	// ListenIP : IP address on which the server should listen.
	ListenIP net.IP
	// ListenIf : reference to interface which is expected to have ListenIP assigned.
	ListenIf NetworkIf
	// Port : port to listen for HTTP requests.
	Port uint16
	// Handler is used to respond to an HTTP request.
	Handler http.Handler
}

HTTPServer : HTTP server.

func (HTTPServer) Dependencies

func (s HTTPServer) Dependencies() (deps []dg.Dependency)

Dependencies returns the interface on which the HTTP server listens as the only dependency. It is assumed that if the interface is created, it has ListenIP assigned.

func (HTTPServer) Equal

func (s HTTPServer) Equal(other dg.Item) bool

Equal compares two HTTPServer instances However, only HTTP server addresses are compared, skipping Handler attributes This is because:

  • not possible to compare (interface)
  • HTTPServerConfigurator only cares about starting/stopping the HTTP server and the handlers can freely change without having to restart the server.

func (HTTPServer) External

func (s HTTPServer) External() bool

External returns false.

func (HTTPServer) Label

func (s HTTPServer) Label() string

Label for the HTTP server.

func (HTTPServer) Name

func (s HTTPServer) Name() string

Name returns the interface name and port on which the HTTP server listens. This ensures that there cannot be two different HTTP servers that would attempt to listen on the same interface and port at the same time.

func (HTTPServer) String

func (s HTTPServer) String() string

String describes the HTTP server.

func (HTTPServer) Type

func (s HTTPServer) Type() string

Type of the item.

type HTTPServerConfigurator

type HTTPServerConfigurator struct {
	Log    *base.LogObject
	Logger *logrus.Logger
	// contains filtered or unexported fields
}

HTTPServerConfigurator implements Configurator interface (libs/reconciler) for HTTPServer.

func (*HTTPServerConfigurator) Create

func (c *HTTPServerConfigurator) Create(ctx context.Context, item dg.Item) error

Create starts HTTP server. Create executes in the background and is done (from the Reconciler point of view) once net.Listen succeeds - however the same Go routine is used to run the HTTP server (and is stopped only later by Delete()).

func (*HTTPServerConfigurator) Delete

func (c *HTTPServerConfigurator) Delete(ctx context.Context, item dg.Item) error

Delete stops HTTP server.

func (*HTTPServerConfigurator) Modify

func (c *HTTPServerConfigurator) Modify(ctx context.Context, oldItem, newItem dg.Item) (err error)

Modify is not implemented.

func (*HTTPServerConfigurator) NeedsRecreate

func (c *HTTPServerConfigurator) NeedsRecreate(oldItem, newItem dg.Item) (recreate bool)

NeedsRecreate always returns true - Modify is not implemented.

type HostnameToIPs

type HostnameToIPs struct {
	Hostname string
	IPs      []net.IP
}

HostnameToIPs maps hostname to one or more IP addresses.

type IPRange

type IPRange struct {
	// FromIP : start of the range (includes the address itself).
	FromIP net.IP
	// ToIP : end of the range (includes the address itself).
	ToIP net.IP
}

IPRange : a range of IP addresses.

type IPReserve

type IPReserve struct {
	// AddrWithMask : IP address including mask of the subnet to which it belongs.
	AddrWithMask *net.IPNet
	// NetIf : network interface to which the IP address is assigned.
	NetIf NetworkIf
}

IPReserve : an item representing allocation and use of an IP address (for bridge). The purpose of this item is to ensure that the same IP address will not be used by multiple bridges at the same time (incl. inside intermediate reconciliation states). This works by having the bridge depending on the reservation and by requesting re-creation of IPReserve when it changes, thus triggering re-create of bridges and all higher-layers items that depend on it.

func (IPReserve) Dependencies

func (ip IPReserve) Dependencies() (deps []dg.Dependency)

Dependencies returns empty slice.

func (IPReserve) Equal

func (ip IPReserve) Equal(other dg.Item) bool

Equal compares two IP reservations.

func (IPReserve) External

func (ip IPReserve) External() bool

External returns false - not used for IPs assigned by NIM.

func (IPReserve) Label

func (ip IPReserve) Label() string

Label returns the IP address including the mask in the string format.

func (IPReserve) Name

func (ip IPReserve) Name() string

Name returns the IP address in the string format.

func (IPReserve) String

func (ip IPReserve) String() string

String describes IP reservation.

func (IPReserve) Type

func (ip IPReserve) Type() string

Type of the item.

type IPReserveConfigurator

type IPReserveConfigurator struct {
	Log *base.LogObject
}

IPReserveConfigurator implements Configurator interface (libs/reconciler) for IPReserve.

func (*IPReserveConfigurator) Create

func (c *IPReserveConfigurator) Create(ctx context.Context, item dg.Item) error

Create is NOOP - IPReserve is not an actual config item, it is used only for dependency purposes (to avoid duplicate use of the same IP address).

func (*IPReserveConfigurator) Delete

func (c *IPReserveConfigurator) Delete(ctx context.Context, item dg.Item) error

Delete is NOOP.

func (*IPReserveConfigurator) Modify

func (c *IPReserveConfigurator) Modify(ctx context.Context, oldItem, newItem dg.Item) (err error)

Modify is not implemented.

func (*IPReserveConfigurator) NeedsRecreate

func (c *IPReserveConfigurator) NeedsRecreate(oldItem, newItem dg.Item) (recreate bool)

NeedsRecreate returns true - change in IPReserve.NetIf usage intentionally triggers recreate which cascades to the bridge and other dependent higher-layer items.

type LinuxIPSet

type LinuxIPSet struct {
	// Domains : list of domains whose resolved IPs will be added to Sets.
	Domains []string
	// Sets : ipsets where IPs of Domains will be put into.
	Sets []string
}

LinuxIPSet : see https://www.netfilter.org/projects/ipset/index.html

type MACToIP

type MACToIP struct {
	MAC      net.HardwareAddr
	IP       net.IP
	Hostname string
}

MACToIP maps MAC address to IP address.

type NetworkIf

type NetworkIf struct {
	// IfName : name of the interface in the network stack.
	IfName string
	// ItemRef : reference to config item representing the interface.
	ItemRef dg.ItemRef
}

NetworkIf : network interface used by dnsmasq.

type NetworkIfWithIP

type NetworkIfWithIP interface {
	// GetAssignedIPs : return IP addresses with subnets currently assigned to the network
	// interface.
	GetAssignedIPs() []*net.IPNet
}

NetworkIfWithIP should be implemented by the item representing network interface on which dnsmasq is supposed to listen.

type Radvd

type Radvd struct {
	// ForNI : UUID of the Network Instance for which this radvd instance is created.
	// Mostly used just to force re-start of radvd when one NI is being deleted
	// and subsequently another is created for the same bridge interface name
	// (ForNI will differ in such case).
	ForNI uuid.UUID
	// ListenIf : interface on which radvd should listen.
	ListenIf NetworkIf
}

Radvd : router advertisement daemon (https://linux.die.net/man/5/radvd.conf).

func (Radvd) Dependencies

func (r Radvd) Dependencies() (deps []dg.Dependency)

Dependencies returns returns the interface on which radvd listens as the only dependency.

func (Radvd) Equal

func (r Radvd) Equal(other dg.Item) bool

Equal compares two Radvd instances

func (Radvd) External

func (r Radvd) External() bool

External returns false.

func (Radvd) Label

func (r Radvd) Label() string

Label for the radvd instance.

func (Radvd) Name

func (r Radvd) Name() string

Name returns the interface name on which radvd listens. This ensures that there cannot be two different radvd instances that would attempt to listen on the same interface at the same time.

func (Radvd) String

func (r Radvd) String() string

String describes the radvd instance.

func (Radvd) Type

func (r Radvd) Type() string

Type of the item.

type RadvdConfigurator

type RadvdConfigurator struct {
	Log *base.LogObject
}

RadvdConfigurator implements Configurator interface (libs/reconciler) for radvd.

func (*RadvdConfigurator) Create

func (c *RadvdConfigurator) Create(ctx context.Context, item dg.Item) error

Create starts radvd.

func (*RadvdConfigurator) Delete

func (c *RadvdConfigurator) Delete(ctx context.Context, item dg.Item) error

Delete stops radvd.

func (*RadvdConfigurator) Modify

func (c *RadvdConfigurator) Modify(ctx context.Context, oldItem, newItem dg.Item) (err error)

Modify is not implemented.

func (*RadvdConfigurator) NeedsRecreate

func (c *RadvdConfigurator) NeedsRecreate(oldItem, newItem dg.Item) (recreate bool)

NeedsRecreate always returns true - Modify is not implemented.

type Uplink struct {
	// IfName : name of the interface inside the network stack.
	IfName string
	// LogicalLabel used to reference this uplink interface.
	LogicalLabel string
	// MasterIfName : name of the master interface under which this Uplink is enslaved.
	// Only used for uplinks of L2 network instances.
	MasterIfName string
	// AdminUp is true if interface is administratively enabled.
	AdminUp bool
	// IPAddresses : IP addresses assigned to the uplink interface.
	IPAddresses []*net.IPNet
}

Uplink : uplink interface used by network instance for connectivity to outside networks.

func (Uplink) Dependencies

func (u Uplink) Dependencies() (deps []dg.Dependency)

Dependencies returns nothing (external item).

func (Uplink) Equal

func (u Uplink) Equal(other dg.Item) bool

Equal compares two Uplink instances.

func (Uplink) External

func (u Uplink) External() bool

External returns true - uplinks are physical interfaces, i.e. not created by zedrouter.

func (Uplink) GetAssignedIPs

func (u Uplink) GetAssignedIPs() []*net.IPNet

GetAssignedIPs returns IP addresses assigned to the uplink interface. The function is needed for the definition of dependencies for dnsmasq and HTTP server.

func (Uplink) Label

func (u Uplink) Label() string

Label returns the logical label.

func (Uplink) Name

func (u Uplink) Name() string

Name returns the physical interface name.

func (Uplink) String

func (u Uplink) String() string

String describes Uplink.

func (Uplink) Type

func (u Uplink) Type() string

Type of the item.

Jump to

Keyboard shortcuts

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