osl

package
v27.2.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package osl describes structures and interfaces which abstract os entities

Index

Constants

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 GC

func GC()

GC triggers garbage collection of namespace path right away and waits for it.

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 string
}

type IfaceOption

type IfaceOption func(i *Interface) error

IfaceOption is a function option type to set interface options.

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 name that will be assigned to the interface once moved inside a network namespace. When the caller passes in a DstName, it is only expected to pass a prefix. The name will be modified with an auto-generated suffix.

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 string, options ...IfaceOption) error

AddInterface adds an existing Interface to the sandbox. The operation will rename from the Interface SrcName to DstName as it moves, and reconfigure the interface according to the specified settings. The caller is expected to only provide a prefix for DstName. The AddInterface api will auto-generate an appropriate suffix for the DstName to disambiguate.

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) Restore

func (n *Namespace) Restore(interfaces map[Iface][]IfaceOption, routes []*types.StaticRoute, gw net.IP, gw6 net.IP) error

Restore restores the network namespace.

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) 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