sandbox.go 6.4 KB

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