github.com/Heebron/moby@v0.0.0-20221111184709-6eab4f55faf7/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/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 // Key returns the path where the network namespace is mounted. 24 Key() string 25 26 // AddInterface adds 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 // SetGateway sets the default IPv4 gateway for the sandbox. 34 SetGateway(gw net.IP) error 35 36 // SetGatewayIPv6 sets the default IPv6 gateway for the sandbox. 37 SetGatewayIPv6(gw net.IP) error 38 39 // UnsetGateway the previously set default IPv4 gateway in the sandbox. 40 UnsetGateway() error 41 42 // UnsetGatewayIPv6 unsets 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 // AddStaticRoute adds a static route to the sandbox. 59 AddStaticRoute(*types.StaticRoute) error 60 61 // RemoveStaticRoute removes 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 // NeighborOptions returns an interface with methods to set neighbor options. 71 NeighborOptions() NeighborOptionSetter 72 73 // InterfaceOptions an interface with methods to set interface options. 74 InterfaceOptions() IfaceOptionSetter 75 76 // InvokeFunc invoke a function in the network namespace. 77 InvokeFunc(func()) error 78 79 // Info returns an interface with methods to get sandbox state. 80 Info() Info 81 82 // Destroy destroys the sandbox. 83 Destroy() error 84 85 // Restore restores the 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 // AddressIPv6 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 // Routes 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 // Interfaces returns 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 // Gateway returns the IPv4 gateway for the sandbox. 140 Gateway() net.IP 141 142 // GatewayIPv6 returns the IPv6 gateway for the sandbox. 143 GatewayIPv6() net.IP 144 145 // StaticRoutes returns additional static routes for the sandbox. Note that 146 // directly connected routes are stored on the particular interface they 147 // refer to. 148 StaticRoutes() []*types.StaticRoute 149 150 // TODO: Add ip tables etc. 151 } 152 153 // Interface represents the settings and identity of a network device. It is 154 // used as a return type for Network.Link, and it is common practice for the 155 // caller to use this information when moving interface SrcName from host 156 // namespace to DstName in a different net namespace with the appropriate 157 // network settings. 158 type Interface interface { 159 // SrcName returns the name of the interface in the origin network namespace. 160 SrcName() string 161 162 // DstName returns the name that will be assigned to the interface once 163 // moved inside a network namespace. When the caller passes in a DstName, 164 // it is only expected to pass a prefix. The name will be modified with an 165 // auto-generated suffix. 166 DstName() string 167 168 // Address returns the IPv4 address for the interface. 169 Address() *net.IPNet 170 171 // AddressIPv6 returns the IPv6 address for the interface. 172 AddressIPv6() *net.IPNet 173 174 // LinkLocalAddresses returns the link-local IP addresses assigned to the 175 // interface. 176 LinkLocalAddresses() []*net.IPNet 177 178 // Routes returns IP routes for the interface. 179 Routes() []*net.IPNet 180 181 // Bridge returns true if the interface is a bridge. 182 Bridge() bool 183 184 // Master returns the srcname of the master interface for this interface. 185 Master() string 186 187 // Remove an interface from the sandbox by renaming to original name 188 // and moving it out of the sandbox. 189 Remove() error 190 191 // Statistics returns the statistics for this interface 192 Statistics() (*types.InterfaceStatistics, error) 193 }