sandbox.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package sandbox
  2. import (
  3. "net"
  4. "github.com/docker/libnetwork/types"
  5. )
  6. // Sandbox represents a network sandbox, identified by a specific key. It
  7. // holds a list of Interfaces, routes etc, and more can be added dynamically.
  8. type Sandbox interface {
  9. // The path where the network namespace is mounted.
  10. Key() string
  11. // Add an existing Interface to this sandbox. The operation will rename
  12. // from the Interface SrcName to DstName as it moves, and reconfigure the
  13. // interface according to the specified settings. The caller is expected
  14. // to only provide a prefix for DstName. The AddInterface api will auto-generate
  15. // an appropriate suffix for the DstName to disambiguate.
  16. AddInterface(SrcName string, DstPrefix string, options ...IfaceOption) error
  17. // Set default IPv4 gateway for the sandbox
  18. SetGateway(gw net.IP) error
  19. // Set default IPv6 gateway for the sandbox
  20. SetGatewayIPv6(gw net.IP) error
  21. // Unset the previously set default IPv4 gateway in the sandbox
  22. UnsetGateway() error
  23. // Unset the previously set default IPv6 gateway in the sandbox
  24. UnsetGatewayIPv6() error
  25. // Add a static route to the sandbox.
  26. AddStaticRoute(*types.StaticRoute) error
  27. // Remove a static route from the sandbox.
  28. RemoveStaticRoute(*types.StaticRoute) error
  29. // Returns an interface with methods to set interface options.
  30. InterfaceOptions() IfaceOptionSetter
  31. // Returns an interface with methods to get sandbox state.
  32. Info() Info
  33. // Destroy the sandbox
  34. Destroy() error
  35. }
  36. // IfaceOptionSetter interface defines the option setter methods for interface options.
  37. type IfaceOptionSetter interface {
  38. // Bridge returns an option setter to set if the interface is a bridge.
  39. Bridge(bool) IfaceOption
  40. // Address returns an option setter to set IPv4 address.
  41. Address(*net.IPNet) IfaceOption
  42. // Address returns an option setter to set IPv6 address.
  43. AddressIPv6(*net.IPNet) IfaceOption
  44. // Master returns an option setter to set the master interface if any for this
  45. // interface. The master interface name should refer to the srcname of a
  46. // previously added interface of type bridge.
  47. Master(string) IfaceOption
  48. // Address returns an option setter to set interface routes.
  49. Routes([]*net.IPNet) IfaceOption
  50. }
  51. // Info represents all possible information that
  52. // the driver wants to place in the sandbox which includes
  53. // interfaces, routes and gateway
  54. type Info interface {
  55. // The collection of Interface previously added with the AddInterface
  56. // method. Note that this doesn't incude network interfaces added in any
  57. // other way (such as the default loopback interface which are automatically
  58. // created on creation of a sandbox).
  59. Interfaces() []Interface
  60. // IPv4 gateway for the sandbox.
  61. Gateway() net.IP
  62. // IPv6 gateway for the sandbox.
  63. GatewayIPv6() net.IP
  64. // Additional static routes for the sandbox. (Note that directly
  65. // connected routes are stored on the particular interface they refer to.)
  66. StaticRoutes() []*types.StaticRoute
  67. // TODO: Add ip tables etc.
  68. }
  69. // Interface represents the settings and identity of a network device. It is
  70. // used as a return type for Network.Link, and it is common practice for the
  71. // caller to use this information when moving interface SrcName from host
  72. // namespace to DstName in a different net namespace with the appropriate
  73. // network settings.
  74. type Interface interface {
  75. // The name of the interface in the origin network namespace.
  76. SrcName() string
  77. // The name that will be assigned to the interface once moves inside a
  78. // network namespace. When the caller passes in a DstName, it is only
  79. // expected to pass a prefix. The name will modified with an appropriately
  80. // auto-generated suffix.
  81. DstName() string
  82. // IPv4 address for the interface.
  83. Address() *net.IPNet
  84. // IPv6 address for the interface.
  85. AddressIPv6() *net.IPNet
  86. // IP routes for the interface.
  87. Routes() []*net.IPNet
  88. // Bridge returns true if the interface is a bridge
  89. Bridge() bool
  90. // Master returns the srcname of the master interface for this interface.
  91. Master() string
  92. // Remove an interface from the sandbox by renaming to original name
  93. // and moving it out of the sandbox.
  94. Remove() error
  95. }