osl

package
v28.0.0-rc.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2025 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Package osl describes structures and interfaces which abstract os entities

Index

Constants

View Source
const (
	// AdvertiseAddrNMsgsMin defines the minimum number of ARP/NA messages sent when an
	// interface is configured.
	// Zero can be used to disable unsolicited ARP/NA.
	AdvertiseAddrNMsgsMin = 0
	// AdvertiseAddrNMsgsMax defines the maximum number of ARP/NA messages sent when an
	// interface is configured. It's three, to match RFC-5227 Section 1.1
	//	// ("PROBE_NUM=3") and RFC-4861 MAX_NEIGHBOR_ADVERTISEMENT.
	AdvertiseAddrNMsgsMax = 3

	// AdvertiseAddrIntervalMin defines the minimum interval between ARP/NA messages
	// sent when an interface is configured. The min defined here is nonstandard,
	// RFC-5227 PROBE_MIN and the default for RetransTimer in RFC-4861 are one
	// second. But, faster resends may be useful in a bridge network (where packets
	// are not transmitted on a real network).
	AdvertiseAddrIntervalMin = 100 * time.Millisecond
	// AdvertiseAddrIntervalMax defines the maximum interval between ARP/NA messages
	// sent when an interface is configured. The max of 2s matches RFC-5227
	// PROBE_MAX.
	AdvertiseAddrIntervalMax = 2 * time.Second
)
View Source
const (
	// SandboxTypeIngress indicates that the sandbox is for the ingress
	SandboxTypeIngress = iota
	// SandboxTypeLoadBalancer indicates that the sandbox is a load balancer
	SandboxTypeLoadBalancer = iota
)

Variables

This section is empty.

Functions

func GenerateKey

func GenerateKey(containerID string) string

GenerateKey generates a sandbox key based on the passed container id.

func SetBasePath

func SetBasePath(path string)

SetBasePath sets the base url prefix for the ns path

Types

type Iface

type Iface struct {
	SrcName, DstPrefix, DstName string
}

type IfaceOption

type IfaceOption func(i *Interface) error

IfaceOption is a function option type to set interface options.

func WithAdvertiseAddrInterval

func WithAdvertiseAddrInterval(interval time.Duration) IfaceOption

WithAdvertiseAddrInterval sets the interval between unsolicited ARP/NA messages sent to advertise a network interface's addresses.

func WithAdvertiseAddrNMsgs

func WithAdvertiseAddrNMsgs(nMsgs int) IfaceOption

WithAdvertiseAddrNMsgs sets the number of unsolicited ARP/NA messages that will be sent to advertise a network interface's addresses.

func WithCreatedInContainer

func WithCreatedInContainer(cic bool) IfaceOption

WithCreatedInContainer can be used to say the network driver created the interface in the container's network namespace (and, therefore, it doesn't need to be moved into that namespace.)

func WithIPv4Address

func WithIPv4Address(addr *net.IPNet) IfaceOption

WithIPv4Address sets the IPv4 address of the interface.

func WithIPv6Address

func WithIPv6Address(addr *net.IPNet) IfaceOption

WithIPv6Address sets the IPv6 address of the interface.

func WithIsBridge

func WithIsBridge(isBridge bool) IfaceOption

WithIsBridge sets whether the interface is a bridge.

func WithLinkLocalAddresses

func WithLinkLocalAddresses(list []*net.IPNet) IfaceOption

WithLinkLocalAddresses set the link-local IP addresses of the interface.

func WithMACAddress

func WithMACAddress(mac net.HardwareAddr) IfaceOption

WithMACAddress sets the interface MAC-address.

func WithMaster

func WithMaster(name string) IfaceOption

WithMaster sets the master interface (if any) for this interface. The master interface name should refer to the srcName of a previously added interface of type bridge.

func WithRoutes

func WithRoutes(routes []*net.IPNet) IfaceOption

WithRoutes sets the interface routes.

func WithSysctls

func WithSysctls(sysctls []string) IfaceOption

WithSysctls sets the interface sysctls.

type Interface

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

Interface represents the settings and identity of a network device. It is used as a return type for Network.Link, and it is common practice for the caller to use this information when moving interface SrcName from host namespace to DstName in a different net namespace with the appropriate network settings.

func (*Interface) Address

func (i *Interface) Address() *net.IPNet

Address returns the IPv4 address for the interface.

func (*Interface) AddressIPv6

func (i *Interface) AddressIPv6() *net.IPNet

AddressIPv6 returns the IPv6 address for the interface.

func (*Interface) Bridge

func (i *Interface) Bridge() bool

Bridge returns true if the interface is a bridge.

func (*Interface) DstMaster

func (i *Interface) DstMaster() string

func (*Interface) DstName

func (i *Interface) DstName() string

DstName returns the final interface name in the target network namespace. It's generated based on the prefix passed to Namespace.AddInterface.

func (*Interface) LinkLocalAddresses

func (i *Interface) LinkLocalAddresses() []*net.IPNet

LinkLocalAddresses returns the link-local IP addresses assigned to the interface.

func (*Interface) MacAddress

func (i *Interface) MacAddress() net.HardwareAddr

func (*Interface) Remove

func (i *Interface) Remove() error

Remove an interface from the sandbox by renaming to original name and moving it out of the sandbox.

func (*Interface) Routes

func (i *Interface) Routes() []*net.IPNet

Routes returns IP routes for the interface.

func (*Interface) SrcName

func (i *Interface) SrcName() string

SrcName returns the name of the interface in the origin network namespace.

func (*Interface) Statistics

func (i *Interface) Statistics() (*types.InterfaceStatistics, error)

Statistics returns the sandbox's side veth interface statistics.

type Namespace

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

Namespace represents a network sandbox. It represents a Linux network namespace, and moves an interface into it when called on method AddInterface or sets the gateway etc. It holds a list of Interfaces, routes etc., and more can be added dynamically.

func GetSandboxForExternalKey

func GetSandboxForExternalKey(basePath string, key string) (*Namespace, error)

GetSandboxForExternalKey returns sandbox object for the supplied path

func NewSandbox

func NewSandbox(key string, osCreate, isRestore bool) (*Namespace, error)

NewSandbox provides a new Namespace instance created in an os specific way provided a key which uniquely identifies the sandbox.

func (*Namespace) AddAliasIP

func (n *Namespace) AddAliasIP(ifName string, ip *net.IPNet) error

AddAliasIP adds the passed IP address to the named interface

func (*Namespace) AddInterface

func (n *Namespace) AddInterface(ctx context.Context, srcName, dstPrefix, dstName string, options ...IfaceOption) error

AddInterface creates an Interface that represents an existing network interface (except for bridge interfaces, which are created here).

The network interface will be reconfigured according the options passed, and it'll be renamed from srcName into either dstName if it's not empty, or to an auto-generated dest name that combines the provided dstPrefix and a numeric suffix.

It's safe to call concurrently.

func (*Namespace) AddNeighbor

func (n *Namespace) AddNeighbor(dstIP net.IP, dstMac net.HardwareAddr, force bool, options ...NeighOption) error

AddNeighbor adds a neighbor entry into the sandbox.

func (*Namespace) AddStaticRoute

func (n *Namespace) AddStaticRoute(r *types.StaticRoute) error

AddStaticRoute adds a static route to the sandbox.

func (*Namespace) ApplyOSTweaks

func (n *Namespace) ApplyOSTweaks(types []SandboxType)

ApplyOSTweaks applies operating system specific knobs on the sandbox.

func (*Namespace) DeleteNeighbor

func (n *Namespace) DeleteNeighbor(dstIP net.IP, dstMac net.HardwareAddr) error

DeleteNeighbor deletes neighbor entry from the sandbox.

func (*Namespace) Destroy

func (n *Namespace) Destroy() error

Destroy destroys the sandbox.

func (*Namespace) DisableARPForVIP

func (n *Namespace) DisableARPForVIP(srcName string) (Err error)

DisableARPForVIP disables ARP replies and requests for VIP addresses on a particular interface.

func (*Namespace) Gateway

func (n *Namespace) Gateway() net.IP

Gateway returns the IPv4 gateway for the sandbox.

func (*Namespace) GatewayIPv6

func (n *Namespace) GatewayIPv6() net.IP

GatewayIPv6 returns the IPv6 gateway for the sandbox.

func (*Namespace) GetLoopbackIfaceName

func (n *Namespace) GetLoopbackIfaceName() string

GetLoopbackIfaceName returns the name of the loopback interface

func (*Namespace) IPv6LoEnabled

func (n *Namespace) IPv6LoEnabled() bool

IPv6LoEnabled returns true if the loopback interface had an IPv6 address when last checked. It's always checked on the first call, and by RefreshIPv6LoEnabled. ('::1' is assigned by the kernel if IPv6 is enabled.)

func (*Namespace) Interfaces

func (n *Namespace) Interfaces() []*Interface

Interfaces returns the collection of Interface previously added with the AddInterface method. Note that this doesn't include network interfaces added in any other way (such as the default loopback interface which is automatically created on creation of a sandbox).

func (*Namespace) InvokeFunc

func (n *Namespace) InvokeFunc(f func()) error

InvokeFunc invoke a function in the network namespace.

func (*Namespace) Key

func (n *Namespace) Key() string

Key returns the path where the network namespace is mounted.

func (*Namespace) RefreshIPv6LoEnabled

func (n *Namespace) RefreshIPv6LoEnabled()

RefreshIPv6LoEnabled refreshes the cached result returned by IPv6LoEnabled.

func (*Namespace) RemoveAliasIP

func (n *Namespace) RemoveAliasIP(ifName string, ip *net.IPNet) error

RemoveAliasIP removes the passed IP address from the named interface

func (*Namespace) RemoveInterface

func (n *Namespace) RemoveInterface(i *Interface) error

RemoveInterface removes an interface from the namespace by renaming to original name and moving it out of the sandbox.

func (*Namespace) RemoveStaticRoute

func (n *Namespace) RemoveStaticRoute(r *types.StaticRoute) error

RemoveStaticRoute removes a static route from the sandbox.

func (*Namespace) RestoreGateway

func (n *Namespace) RestoreGateway(ipv4 bool, gw net.IP, srcName string)

func (*Namespace) RestoreInterfaces

func (n *Namespace) RestoreInterfaces(interfaces map[Iface][]IfaceOption) error

RestoreInterfaces restores the network namespace's interfaces.

func (*Namespace) RestoreRoutes

func (n *Namespace) RestoreRoutes(routes []*types.StaticRoute)

func (*Namespace) SetDefaultRouteIPv4

func (n *Namespace) SetDefaultRouteIPv4(srcName string) error

SetDefaultRouteIPv4 sets up a connected route to 0.0.0.0 via the Interface with srcName, if that Interface has a route to 0.0.0.0. Otherwise, it returns an error.

func (*Namespace) SetDefaultRouteIPv6

func (n *Namespace) SetDefaultRouteIPv6(srcName string) error

SetDefaultRouteIPv6 sets up a connected route to [::] via the Interface with srcName, if that Interface has a route to [::]. Otherwise, it returns an error.

func (*Namespace) SetGateway

func (n *Namespace) SetGateway(gw net.IP) error

SetGateway sets the default IPv4 gateway for the sandbox. It is a no-op if the given gateway is empty.

func (*Namespace) SetGatewayIPv6

func (n *Namespace) SetGatewayIPv6(gwv6 net.IP) error

SetGatewayIPv6 sets the default IPv6 gateway for the sandbox. It is a no-op if the given gateway is empty.

func (*Namespace) StaticRoutes

func (n *Namespace) StaticRoutes() []*types.StaticRoute

StaticRoutes returns additional static routes for the sandbox. Note that directly connected routes are stored on the particular interface they refer to.

func (*Namespace) UnsetDefaultRouteIPv4

func (n *Namespace) UnsetDefaultRouteIPv4() error

UnsetDefaultRouteIPv4 unsets the previously set default IPv4 default route in the sandbox. It is a no-op if no gateway was set.

func (*Namespace) UnsetDefaultRouteIPv6

func (n *Namespace) UnsetDefaultRouteIPv6() error

UnsetDefaultRouteIPv6 unsets the previously set default IPv6 default route in the sandbox. It is a no-op if no gateway was set.

func (*Namespace) UnsetGateway

func (n *Namespace) UnsetGateway() error

UnsetGateway the previously set default IPv4 gateway in the sandbox. It is a no-op if no gateway was set.

func (*Namespace) UnsetGatewayIPv6

func (n *Namespace) UnsetGatewayIPv6() error

UnsetGatewayIPv6 unsets the previously set default IPv6 gateway in the sandbox. It is a no-op if no gateway was set.

type NeighOption

type NeighOption func(nh *neigh)

NeighOption is a function option type to set neighbor options.

func WithFamily

func WithFamily(family int) NeighOption

WithFamily sets the address-family for the neighbor entry. e.g. syscall.AF_BRIDGE.

func WithLinkName

func WithLinkName(name string) NeighOption

WithLinkName sets the srcName of the link to use in the neighbor entry.

type NeighborSearchError

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

NeighborSearchError indicates that the neighbor is already present

func (NeighborSearchError) Error

func (n NeighborSearchError) Error() string

type SandboxType

type SandboxType int

SandboxType specify the time of the sandbox, this can be used to apply special configs

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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