2015-09-02 19:42:01 -04:00
|
|
|
// Package osl describes structures and interfaces which abstract os entities
|
|
|
|
package osl
|
2015-05-06 20:09:12 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
|
2015-05-23 02:00:03 -04:00
|
|
|
"github.com/docker/libnetwork/types"
|
2015-05-06 20:09:12 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// Sandbox represents a network sandbox, identified by a specific key. It
|
|
|
|
// holds a list of Interfaces, routes etc, and more can be added dynamically.
|
|
|
|
type Sandbox interface {
|
|
|
|
// The path where the network namespace is mounted.
|
|
|
|
Key() string
|
|
|
|
|
|
|
|
// Add an existing Interface to this sandbox. The operation will rename
|
|
|
|
// from the Interface SrcName to DstName as it moves, and reconfigure the
|
2015-05-23 02:00:03 -04:00
|
|
|
// 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.
|
2015-06-12 16:51:57 -04:00
|
|
|
AddInterface(SrcName string, DstPrefix string, options ...IfaceOption) error
|
2015-05-06 20:09:12 -04:00
|
|
|
|
|
|
|
// Set default IPv4 gateway for the sandbox
|
|
|
|
SetGateway(gw net.IP) error
|
|
|
|
|
|
|
|
// Set default IPv6 gateway for the sandbox
|
|
|
|
SetGatewayIPv6(gw net.IP) error
|
|
|
|
|
2015-06-12 16:51:57 -04:00
|
|
|
// Unset the previously set default IPv4 gateway in the sandbox
|
|
|
|
UnsetGateway() error
|
|
|
|
|
|
|
|
// Unset the previously set default IPv6 gateway in the sandbox
|
|
|
|
UnsetGatewayIPv6() error
|
|
|
|
|
|
|
|
// Add a static route to the sandbox.
|
|
|
|
AddStaticRoute(*types.StaticRoute) error
|
|
|
|
|
|
|
|
// Remove a static route from the sandbox.
|
|
|
|
RemoveStaticRoute(*types.StaticRoute) error
|
|
|
|
|
2015-06-20 20:08:36 -04:00
|
|
|
// AddNeighbor adds a neighbor entry into the sandbox.
|
|
|
|
AddNeighbor(dstIP net.IP, dstMac net.HardwareAddr, option ...NeighOption) error
|
|
|
|
|
|
|
|
// DeleteNeighbor deletes neighbor entry from the sandbox.
|
2016-09-20 21:21:19 -04:00
|
|
|
DeleteNeighbor(dstIP net.IP, dstMac net.HardwareAddr, osDelete bool) error
|
2015-06-20 20:08:36 -04:00
|
|
|
|
|
|
|
// Returns an interface with methods to set neighbor options.
|
|
|
|
NeighborOptions() NeighborOptionSetter
|
|
|
|
|
2015-06-12 16:51:57 -04:00
|
|
|
// Returns an interface with methods to set interface options.
|
|
|
|
InterfaceOptions() IfaceOptionSetter
|
|
|
|
|
2015-06-20 20:08:36 -04:00
|
|
|
//Invoke
|
|
|
|
InvokeFunc(func()) error
|
|
|
|
|
2015-06-12 16:51:57 -04:00
|
|
|
// Returns an interface with methods to get sandbox state.
|
|
|
|
Info() Info
|
|
|
|
|
2015-05-06 20:09:12 -04:00
|
|
|
// Destroy the sandbox
|
|
|
|
Destroy() error
|
2016-06-14 16:45:24 -04:00
|
|
|
|
|
|
|
// restore sandbox
|
|
|
|
Restore(ifsopt map[string][]IfaceOption, routes []*types.StaticRoute, gw net.IP, gw6 net.IP) error
|
2015-05-06 20:09:12 -04:00
|
|
|
}
|
|
|
|
|
2016-06-07 17:28:28 -04:00
|
|
|
// NeighborOptionSetter interface defines the option setter methods for interface options
|
2015-06-20 20:08:36 -04:00
|
|
|
type NeighborOptionSetter interface {
|
|
|
|
// LinkName returns an option setter to set the srcName of the link that should
|
|
|
|
// be used in the neighbor entry
|
|
|
|
LinkName(string) NeighOption
|
|
|
|
|
|
|
|
// Family returns an option setter to set the address family for the neighbor
|
|
|
|
// entry. eg. AF_BRIDGE
|
|
|
|
Family(int) NeighOption
|
|
|
|
}
|
|
|
|
|
2015-06-12 16:51:57 -04:00
|
|
|
// IfaceOptionSetter interface defines the option setter methods for interface options.
|
|
|
|
type IfaceOptionSetter interface {
|
|
|
|
// Bridge returns an option setter to set if the interface is a bridge.
|
|
|
|
Bridge(bool) IfaceOption
|
|
|
|
|
2016-03-08 21:47:02 -05:00
|
|
|
// MacAddress returns an option setter to set the MAC address.
|
|
|
|
MacAddress(net.HardwareAddr) IfaceOption
|
|
|
|
|
2015-06-12 16:51:57 -04:00
|
|
|
// Address returns an option setter to set IPv4 address.
|
|
|
|
Address(*net.IPNet) IfaceOption
|
|
|
|
|
|
|
|
// Address returns an option setter to set IPv6 address.
|
|
|
|
AddressIPv6(*net.IPNet) IfaceOption
|
|
|
|
|
2016-06-07 17:28:28 -04:00
|
|
|
// LinkLocalAddresses returns an option setter to set the link-local IP addresses.
|
|
|
|
LinkLocalAddresses([]*net.IPNet) IfaceOption
|
|
|
|
|
2016-11-21 14:44:58 -05:00
|
|
|
// IPAliases returns an option setter to set IP address Aliases
|
|
|
|
IPAliases([]*net.IPNet) IfaceOption
|
|
|
|
|
2015-06-12 16:51:57 -04:00
|
|
|
// Master returns an option setter to set 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.
|
|
|
|
Master(string) IfaceOption
|
|
|
|
|
|
|
|
// Address returns an option setter to set interface routes.
|
|
|
|
Routes([]*net.IPNet) IfaceOption
|
|
|
|
}
|
|
|
|
|
2015-05-06 20:09:12 -04:00
|
|
|
// Info represents all possible information that
|
|
|
|
// the driver wants to place in the sandbox which includes
|
|
|
|
// interfaces, routes and gateway
|
2015-06-12 16:51:57 -04:00
|
|
|
type Info interface {
|
|
|
|
// The collection of Interface previously added with the AddInterface
|
2016-06-07 17:28:28 -04:00
|
|
|
// method. Note that this doesn't include network interfaces added in any
|
|
|
|
// other way (such as the default loopback interface which is automatically
|
2015-06-12 16:51:57 -04:00
|
|
|
// created on creation of a sandbox).
|
|
|
|
Interfaces() []Interface
|
2015-05-06 20:09:12 -04:00
|
|
|
|
|
|
|
// IPv4 gateway for the sandbox.
|
2015-06-12 16:51:57 -04:00
|
|
|
Gateway() net.IP
|
2015-05-06 20:09:12 -04:00
|
|
|
|
|
|
|
// IPv6 gateway for the sandbox.
|
2015-06-12 16:51:57 -04:00
|
|
|
GatewayIPv6() net.IP
|
|
|
|
|
|
|
|
// Additional static routes for the sandbox. (Note that directly
|
|
|
|
// connected routes are stored on the particular interface they refer to.)
|
|
|
|
StaticRoutes() []*types.StaticRoute
|
2015-05-06 20:09:12 -04:00
|
|
|
|
2015-06-12 16:51:57 -04:00
|
|
|
// TODO: Add ip tables etc.
|
2015-05-06 20:09:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2015-06-12 16:51:57 -04:00
|
|
|
type Interface interface {
|
2015-05-06 20:09:12 -04:00
|
|
|
// The name of the interface in the origin network namespace.
|
2015-06-12 16:51:57 -04:00
|
|
|
SrcName() string
|
2015-05-06 20:09:12 -04:00
|
|
|
|
|
|
|
// The name that will be assigned to the interface once moves inside a
|
2015-05-23 02:00:03 -04:00
|
|
|
// network namespace. When the caller passes in a DstName, it is only
|
|
|
|
// expected to pass a prefix. The name will modified with an appropriately
|
|
|
|
// auto-generated suffix.
|
2015-06-12 16:51:57 -04:00
|
|
|
DstName() string
|
2015-05-06 20:09:12 -04:00
|
|
|
|
|
|
|
// IPv4 address for the interface.
|
2015-06-12 16:51:57 -04:00
|
|
|
Address() *net.IPNet
|
2015-05-06 20:09:12 -04:00
|
|
|
|
|
|
|
// IPv6 address for the interface.
|
2015-06-12 16:51:57 -04:00
|
|
|
AddressIPv6() *net.IPNet
|
2015-05-06 20:09:12 -04:00
|
|
|
|
2016-06-07 17:28:28 -04:00
|
|
|
// LinkLocalAddresses returns the link-local IP addresses assigned to the interface.
|
|
|
|
LinkLocalAddresses() []*net.IPNet
|
|
|
|
|
2016-11-21 14:44:58 -05:00
|
|
|
// IPAliases returns the IP address aliases assigned to the interface.
|
|
|
|
IPAliases() []*net.IPNet
|
|
|
|
|
2015-06-12 16:51:57 -04:00
|
|
|
// IP routes for the interface.
|
|
|
|
Routes() []*net.IPNet
|
2015-05-06 20:09:12 -04:00
|
|
|
|
2015-06-12 16:51:57 -04:00
|
|
|
// Bridge returns true if the interface is a bridge
|
|
|
|
Bridge() bool
|
2015-05-06 20:09:12 -04:00
|
|
|
|
2015-06-12 16:51:57 -04:00
|
|
|
// Master returns the srcname of the master interface for this interface.
|
|
|
|
Master() string
|
2015-05-06 20:09:12 -04:00
|
|
|
|
2015-06-12 16:51:57 -04:00
|
|
|
// Remove an interface from the sandbox by renaming to original name
|
|
|
|
// and moving it out of the sandbox.
|
|
|
|
Remove() error
|
2015-06-30 17:16:16 -04:00
|
|
|
|
|
|
|
// Statistics returns the statistics for this interface
|
2015-10-04 23:02:02 -04:00
|
|
|
Statistics() (*types.InterfaceStatistics, error)
|
2015-05-06 20:09:12 -04:00
|
|
|
}
|