Documentation
¶
Overview ¶
Package osl describes structures and interfaces which abstract os entities
Index ¶
- Constants
- func GenerateKey(containerID string) string
- func SetBasePath(path string)
- type Iface
- type IfaceOption
- func WithAdvertiseAddrInterval(interval time.Duration) IfaceOption
- func WithAdvertiseAddrNMsgs(nMsgs int) IfaceOption
- func WithCreatedInContainer(cic bool) IfaceOption
- func WithIPv4Address(addr *net.IPNet) IfaceOption
- func WithIPv6Address(addr *net.IPNet) IfaceOption
- func WithIsBridge(isBridge bool) IfaceOption
- func WithLinkLocalAddresses(list []*net.IPNet) IfaceOption
- func WithMACAddress(mac net.HardwareAddr) IfaceOption
- func WithMaster(name string) IfaceOption
- func WithRoutes(routes []*net.IPNet) IfaceOption
- func WithSysctls(sysctls []string) IfaceOption
- type Interface
- func (i *Interface) Address() *net.IPNet
- func (i *Interface) AddressIPv6() *net.IPNet
- func (i *Interface) Bridge() bool
- func (i *Interface) DstMaster() string
- func (i *Interface) DstName() string
- func (i *Interface) LinkLocalAddresses() []*net.IPNet
- func (i *Interface) MacAddress() net.HardwareAddr
- func (i *Interface) Remove() error
- func (i *Interface) Routes() []*net.IPNet
- func (i *Interface) SrcName() string
- func (i *Interface) Statistics() (*types.InterfaceStatistics, error)
- type Namespace
- func (n *Namespace) AddAliasIP(ifName string, ip *net.IPNet) error
- func (n *Namespace) AddInterface(ctx context.Context, srcName, dstPrefix, dstName string, ...) error
- func (n *Namespace) AddNeighbor(dstIP net.IP, dstMac net.HardwareAddr, force bool, options ...NeighOption) error
- func (n *Namespace) AddStaticRoute(r *types.StaticRoute) error
- func (n *Namespace) ApplyOSTweaks(types []SandboxType)
- func (n *Namespace) DeleteNeighbor(dstIP net.IP, dstMac net.HardwareAddr) error
- func (n *Namespace) Destroy() error
- func (n *Namespace) DisableARPForVIP(srcName string) (Err error)
- func (n *Namespace) Gateway() net.IP
- func (n *Namespace) GatewayIPv6() net.IP
- func (n *Namespace) GetLoopbackIfaceName() string
- func (n *Namespace) IPv6LoEnabled() bool
- func (n *Namespace) Interfaces() []*Interface
- func (n *Namespace) InvokeFunc(f func()) error
- func (n *Namespace) Key() string
- func (n *Namespace) RefreshIPv6LoEnabled()
- func (n *Namespace) RemoveAliasIP(ifName string, ip *net.IPNet) error
- func (n *Namespace) RemoveInterface(i *Interface) error
- func (n *Namespace) RemoveStaticRoute(r *types.StaticRoute) error
- func (n *Namespace) RestoreGateway(ipv4 bool, gw net.IP, srcName string)
- func (n *Namespace) RestoreInterfaces(interfaces map[Iface][]IfaceOption) error
- func (n *Namespace) RestoreRoutes(routes []*types.StaticRoute)
- func (n *Namespace) SetDefaultRouteIPv4(srcName string) error
- func (n *Namespace) SetDefaultRouteIPv6(srcName string) error
- func (n *Namespace) SetGateway(gw net.IP) error
- func (n *Namespace) SetGatewayIPv6(gwv6 net.IP) error
- func (n *Namespace) StaticRoutes() []*types.StaticRoute
- func (n *Namespace) UnsetDefaultRouteIPv4() error
- func (n *Namespace) UnsetDefaultRouteIPv6() error
- func (n *Namespace) UnsetGateway() error
- func (n *Namespace) UnsetGatewayIPv6() error
- type NeighOption
- type NeighborSearchError
- type SandboxType
Constants ¶
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 )
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 ¶
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 IfaceOption ¶
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) AddressIPv6 ¶
AddressIPv6 returns the IPv6 address for the interface.
func (*Interface) DstName ¶
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 ¶
LinkLocalAddresses returns the link-local IP addresses assigned to the interface.
func (*Interface) MacAddress ¶
func (i *Interface) MacAddress() net.HardwareAddr
func (*Interface) Remove ¶
Remove an interface from the sandbox by renaming to original name and moving it out of the sandbox.
func (*Interface) SrcName ¶
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 ¶
GetSandboxForExternalKey returns sandbox object for the supplied path
func NewSandbox ¶
NewSandbox provides a new Namespace instance created in an os specific way provided a key which uniquely identifies the sandbox.
func (*Namespace) AddAliasIP ¶
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 ¶
DeleteNeighbor deletes neighbor entry from the sandbox.
func (*Namespace) DisableARPForVIP ¶
DisableARPForVIP disables ARP replies and requests for VIP addresses on a particular interface.
func (*Namespace) GatewayIPv6 ¶
GatewayIPv6 returns the IPv6 gateway for the sandbox.
func (*Namespace) GetLoopbackIfaceName ¶
GetLoopbackIfaceName returns the name of the loopback interface
func (*Namespace) IPv6LoEnabled ¶
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 ¶
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 ¶
InvokeFunc invoke a function in the network namespace.
func (*Namespace) RefreshIPv6LoEnabled ¶
func (n *Namespace) RefreshIPv6LoEnabled()
RefreshIPv6LoEnabled refreshes the cached result returned by IPv6LoEnabled.
func (*Namespace) RemoveAliasIP ¶
RemoveAliasIP removes the passed IP address from the named interface
func (*Namespace) RemoveInterface ¶
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 (*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 ¶
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 ¶
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 ¶
SetGateway sets the default IPv4 gateway for the sandbox. It is a no-op if the given gateway is empty.
func (*Namespace) SetGatewayIPv6 ¶
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 ¶
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 ¶
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 ¶
UnsetGateway the previously set default IPv4 gateway in the sandbox. It is a no-op if no gateway was set.
func (*Namespace) UnsetGatewayIPv6 ¶
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