github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/libnetwork/osl/sandbox.go (about)

     1  // Package osl describes structures and interfaces which abstract os entities
     2  package osl
     3  
     4  import (
     5  	"net"
     6  
     7  	"github.com/docker/libnetwork/types"
     8  )
     9  
    10  // SandboxType specify the time of the sandbox, this can be used to apply special configs
    11  type SandboxType int
    12  
    13  const (
    14  	// SandboxTypeIngress indicates that the sandbox is for the ingress
    15  	SandboxTypeIngress = iota
    16  	// SandboxTypeLoadBalancer indicates that the sandbox is a load balancer
    17  	SandboxTypeLoadBalancer = iota
    18  )
    19  
    20  // Sandbox represents a network sandbox, identified by a specific key.  It
    21  // holds a list of Interfaces, routes etc, and more can be added dynamically.
    22  type Sandbox interface {
    23  	// The path where the network namespace is mounted.
    24  	Key() string
    25  
    26  	// Add an existing Interface to this sandbox. The operation will rename
    27  	// from the Interface SrcName to DstName as it moves, and reconfigure the
    28  	// interface according to the specified settings. The caller is expected
    29  	// to only provide a prefix for DstName. The AddInterface api will auto-generate
    30  	// an appropriate suffix for the DstName to disambiguate.
    31  	AddInterface(SrcName string, DstPrefix string, options ...IfaceOption) error
    32  
    33  	// Set default IPv4 gateway for the sandbox
    34  	SetGateway(gw net.IP) error
    35  
    36  	// Set default IPv6 gateway for the sandbox
    37  	SetGatewayIPv6(gw net.IP) error
    38  
    39  	// Unset the previously set default IPv4 gateway in the sandbox
    40  	UnsetGateway() error
    41  
    42  	// Unset the previously set default IPv6 gateway in the sandbox
    43  	UnsetGatewayIPv6() error
    44  
    45  	// GetLoopbackIfaceName returns the name of the loopback interface
    46  	GetLoopbackIfaceName() string
    47  
    48  	// AddAliasIP adds the passed IP address to the named interface
    49  	AddAliasIP(ifName string, ip *net.IPNet) error
    50  
    51  	// RemoveAliasIP removes the passed IP address from the named interface
    52  	RemoveAliasIP(ifName string, ip *net.IPNet) error
    53  
    54  	// DisableARPForVIP disables ARP replies and requests for VIP addresses
    55  	// on a particular interface
    56  	DisableARPForVIP(ifName string) error
    57  
    58  	// Add a static route to the sandbox.
    59  	AddStaticRoute(*types.StaticRoute) error
    60  
    61  	// Remove a static route from the sandbox.
    62  	RemoveStaticRoute(*types.StaticRoute) error
    63  
    64  	// AddNeighbor adds a neighbor entry into the sandbox.
    65  	AddNeighbor(dstIP net.IP, dstMac net.HardwareAddr, force bool, option ...NeighOption) error
    66  
    67  	// DeleteNeighbor deletes neighbor entry from the sandbox.
    68  	DeleteNeighbor(dstIP net.IP, dstMac net.HardwareAddr, osDelete bool) error
    69  
    70  	// Returns an interface with methods to set neighbor options.
    71  	NeighborOptions() NeighborOptionSetter
    72  
    73  	// Returns an interface with methods to set interface options.
    74  	InterfaceOptions() IfaceOptionSetter
    75  
    76  	//Invoke
    77  	InvokeFunc(func()) error
    78  
    79  	// Returns an interface with methods to get sandbox state.
    80  	Info() Info
    81  
    82  	// Destroy the sandbox
    83  	Destroy() error
    84  
    85  	// restore sandbox
    86  	Restore(ifsopt map[string][]IfaceOption, routes []*types.StaticRoute, gw net.IP, gw6 net.IP) error
    87  
    88  	// ApplyOSTweaks applies operating system specific knobs on the sandbox
    89  	ApplyOSTweaks([]SandboxType)
    90  }
    91  
    92  // NeighborOptionSetter interface defines the option setter methods for interface options
    93  type NeighborOptionSetter interface {
    94  	// LinkName returns an option setter to set the srcName of the link that should
    95  	// be used in the neighbor entry
    96  	LinkName(string) NeighOption
    97  
    98  	// Family returns an option setter to set the address family for the neighbor
    99  	// entry. eg. AF_BRIDGE
   100  	Family(int) NeighOption
   101  }
   102  
   103  // IfaceOptionSetter interface defines the option setter methods for interface options.
   104  type IfaceOptionSetter interface {
   105  	// Bridge returns an option setter to set if the interface is a bridge.
   106  	Bridge(bool) IfaceOption
   107  
   108  	// MacAddress returns an option setter to set the MAC address.
   109  	MacAddress(net.HardwareAddr) IfaceOption
   110  
   111  	// Address returns an option setter to set IPv4 address.
   112  	Address(*net.IPNet) IfaceOption
   113  
   114  	// Address returns an option setter to set IPv6 address.
   115  	AddressIPv6(*net.IPNet) IfaceOption
   116  
   117  	// LinkLocalAddresses returns an option setter to set the link-local IP addresses.
   118  	LinkLocalAddresses([]*net.IPNet) IfaceOption
   119  
   120  	// Master returns an option setter to set the master interface if any for this
   121  	// interface. The master interface name should refer to the srcname of a
   122  	// previously added interface of type bridge.
   123  	Master(string) IfaceOption
   124  
   125  	// Address returns an option setter to set interface routes.
   126  	Routes([]*net.IPNet) IfaceOption
   127  }
   128  
   129  // Info represents all possible information that
   130  // the driver wants to place in the sandbox which includes
   131  // interfaces, routes and gateway
   132  type Info interface {
   133  	// The collection of Interface previously added with the AddInterface
   134  	// method. Note that this doesn't include network interfaces added in any
   135  	// other way (such as the default loopback interface which is automatically
   136  	// created on creation of a sandbox).
   137  	Interfaces() []Interface
   138  
   139  	// IPv4 gateway for the sandbox.
   140  	Gateway() net.IP
   141  
   142  	// IPv6 gateway for the sandbox.
   143  	GatewayIPv6() net.IP
   144  
   145  	// Additional static routes for the sandbox.  (Note that directly
   146  	// connected routes are stored on the particular interface they refer to.)
   147  	StaticRoutes() []*types.StaticRoute
   148  
   149  	// TODO: Add ip tables etc.
   150  }
   151  
   152  // Interface represents the settings and identity of a network device. It is
   153  // used as a return type for Network.Link, and it is common practice for the
   154  // caller to use this information when moving interface SrcName from host
   155  // namespace to DstName in a different net namespace with the appropriate
   156  // network settings.
   157  type Interface interface {
   158  	// The name of the interface in the origin network namespace.
   159  	SrcName() string
   160  
   161  	// The name that will be assigned to the interface once moves inside a
   162  	// network namespace. When the caller passes in a DstName, it is only
   163  	// expected to pass a prefix. The name will modified with an appropriately
   164  	// auto-generated suffix.
   165  	DstName() string
   166  
   167  	// IPv4 address for the interface.
   168  	Address() *net.IPNet
   169  
   170  	// IPv6 address for the interface.
   171  	AddressIPv6() *net.IPNet
   172  
   173  	// LinkLocalAddresses returns the link-local IP addresses assigned to the interface.
   174  	LinkLocalAddresses() []*net.IPNet
   175  
   176  	// IP routes for the interface.
   177  	Routes() []*net.IPNet
   178  
   179  	// Bridge returns true if the interface is a bridge
   180  	Bridge() bool
   181  
   182  	// Master returns the srcname of the master interface for this interface.
   183  	Master() string
   184  
   185  	// Remove an interface from the sandbox by renaming to original name
   186  	// and moving it out of the sandbox.
   187  	Remove() error
   188  
   189  	// Statistics returns the statistics for this interface
   190  	Statistics() (*types.InterfaceStatistics, error)
   191  }