errors.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. // +build linux
  2. package bridge
  3. import (
  4. "fmt"
  5. "net"
  6. )
  7. // ErrConfigExists error is returned when driver already has a config applied.
  8. type ErrConfigExists struct{}
  9. func (ece *ErrConfigExists) Error() string {
  10. return "configuration already exists, bridge configuration can be applied only once"
  11. }
  12. // Forbidden denotes the type of this error
  13. func (ece *ErrConfigExists) Forbidden() {}
  14. // ErrInvalidDriverConfig error is returned when Bridge Driver is passed an invalid config
  15. type ErrInvalidDriverConfig struct{}
  16. func (eidc *ErrInvalidDriverConfig) Error() string {
  17. return "Invalid configuration passed to Bridge Driver"
  18. }
  19. // BadRequest denotes the type of this error
  20. func (eidc *ErrInvalidDriverConfig) BadRequest() {}
  21. // ErrInvalidNetworkConfig error is returned when a network is created on a driver without valid config.
  22. type ErrInvalidNetworkConfig struct{}
  23. func (einc *ErrInvalidNetworkConfig) Error() string {
  24. return "trying to create a network on a driver without valid config"
  25. }
  26. // Forbidden denotes the type of this error
  27. func (einc *ErrInvalidNetworkConfig) Forbidden() {}
  28. // ErrInvalidContainerConfig error is returned when an endpoint create is attempted with an invalid configuration.
  29. type ErrInvalidContainerConfig struct{}
  30. func (eicc *ErrInvalidContainerConfig) Error() string {
  31. return "Error in joining a container due to invalid configuration"
  32. }
  33. // BadRequest denotes the type of this error
  34. func (eicc *ErrInvalidContainerConfig) BadRequest() {}
  35. // ErrInvalidEndpointConfig error is returned when an endpoint create is attempted with an invalid endpoint configuration.
  36. type ErrInvalidEndpointConfig struct{}
  37. func (eiec *ErrInvalidEndpointConfig) Error() string {
  38. return "trying to create an endpoint with an invalid endpoint configuration"
  39. }
  40. // BadRequest denotes the type of this error
  41. func (eiec *ErrInvalidEndpointConfig) BadRequest() {}
  42. // ErrNetworkExists error is returned when a network already exists and another network is created.
  43. type ErrNetworkExists struct{}
  44. func (ene *ErrNetworkExists) Error() string {
  45. return "network already exists, bridge can only have one network"
  46. }
  47. // Forbidden denotes the type of this error
  48. func (ene *ErrNetworkExists) Forbidden() {}
  49. // ErrIfaceName error is returned when a new name could not be generated.
  50. type ErrIfaceName struct{}
  51. func (ein *ErrIfaceName) Error() string {
  52. return "failed to find name for new interface"
  53. }
  54. // InternalError denotes the type of this error
  55. func (ein *ErrIfaceName) InternalError() {}
  56. // ErrNoIPAddr error is returned when bridge has no IPv4 address configured.
  57. type ErrNoIPAddr struct{}
  58. func (enip *ErrNoIPAddr) Error() string {
  59. return "bridge has no IPv4 address configured"
  60. }
  61. // InternalError denotes the type of this error
  62. func (enip *ErrNoIPAddr) InternalError() {}
  63. // ErrInvalidGateway is returned when the user provided default gateway (v4/v6) is not not valid.
  64. type ErrInvalidGateway struct{}
  65. func (eig *ErrInvalidGateway) Error() string {
  66. return "default gateway ip must be part of the network"
  67. }
  68. // BadRequest denotes the type of this error
  69. func (eig *ErrInvalidGateway) BadRequest() {}
  70. // ErrInvalidContainerSubnet is returned when the container subnet (FixedCIDR) is not valid.
  71. type ErrInvalidContainerSubnet struct{}
  72. func (eis *ErrInvalidContainerSubnet) Error() string {
  73. return "container subnet must be a subset of bridge network"
  74. }
  75. // BadRequest denotes the type of this error
  76. func (eis *ErrInvalidContainerSubnet) BadRequest() {}
  77. // ErrInvalidMtu is returned when the user provided MTU is not valid.
  78. type ErrInvalidMtu int
  79. func (eim ErrInvalidMtu) Error() string {
  80. return fmt.Sprintf("invalid MTU number: %d", int(eim))
  81. }
  82. // BadRequest denotes the type of this error
  83. func (eim ErrInvalidMtu) BadRequest() {}
  84. // ErrInvalidPort is returned when the container or host port specified in the port binding is not valid.
  85. type ErrInvalidPort string
  86. func (ip ErrInvalidPort) Error() string {
  87. return fmt.Sprintf("invalid transport port: %s", string(ip))
  88. }
  89. // BadRequest denotes the type of this error
  90. func (ip ErrInvalidPort) BadRequest() {}
  91. // ErrUnsupportedAddressType is returned when the specified address type is not supported.
  92. type ErrUnsupportedAddressType string
  93. func (uat ErrUnsupportedAddressType) Error() string {
  94. return fmt.Sprintf("unsupported address type: %s", string(uat))
  95. }
  96. // BadRequest denotes the type of this error
  97. func (uat ErrUnsupportedAddressType) BadRequest() {}
  98. // ErrInvalidAddressBinding is returned when the host address specified in the port binding is not valid.
  99. type ErrInvalidAddressBinding string
  100. func (iab ErrInvalidAddressBinding) Error() string {
  101. return fmt.Sprintf("invalid host address in port binding: %s", string(iab))
  102. }
  103. // BadRequest denotes the type of this error
  104. func (iab ErrInvalidAddressBinding) BadRequest() {}
  105. // ActiveEndpointsError is returned when there are
  106. // still active endpoints in the network being deleted.
  107. type ActiveEndpointsError string
  108. func (aee ActiveEndpointsError) Error() string {
  109. return fmt.Sprintf("network %s has active endpoint", string(aee))
  110. }
  111. // Forbidden denotes the type of this error
  112. func (aee ActiveEndpointsError) Forbidden() {}
  113. // InvalidNetworkIDError is returned when the passed
  114. // network id for an existing network is not a known id.
  115. type InvalidNetworkIDError string
  116. func (inie InvalidNetworkIDError) Error() string {
  117. return fmt.Sprintf("invalid network id %s", string(inie))
  118. }
  119. // NotFound denotes the type of this error
  120. func (inie InvalidNetworkIDError) NotFound() {}
  121. // InvalidEndpointIDError is returned when the passed
  122. // endpoint id is not valid.
  123. type InvalidEndpointIDError string
  124. func (ieie InvalidEndpointIDError) Error() string {
  125. return fmt.Sprintf("invalid endpoint id: %s", string(ieie))
  126. }
  127. // BadRequest denotes the type of this error
  128. func (ieie InvalidEndpointIDError) BadRequest() {}
  129. // InvalidSandboxIDError is returned when the passed
  130. // sandbox id is not valid.
  131. type InvalidSandboxIDError string
  132. func (isie InvalidSandboxIDError) Error() string {
  133. return fmt.Sprintf("invalid sandbox id: %s", string(isie))
  134. }
  135. // BadRequest denotes the type of this error
  136. func (isie InvalidSandboxIDError) BadRequest() {}
  137. // EndpointNotFoundError is returned when the no endpoint
  138. // with the passed endpoint id is found.
  139. type EndpointNotFoundError string
  140. func (enfe EndpointNotFoundError) Error() string {
  141. return fmt.Sprintf("endpoint not found: %s", string(enfe))
  142. }
  143. // NotFound denotes the type of this error
  144. func (enfe EndpointNotFoundError) NotFound() {}
  145. // NonDefaultBridgeExistError is returned when a non-default
  146. // bridge config is passed but it does not already exist.
  147. type NonDefaultBridgeExistError string
  148. func (ndbee NonDefaultBridgeExistError) Error() string {
  149. return fmt.Sprintf("bridge device with non default name %s must be created manually", string(ndbee))
  150. }
  151. // Forbidden denotes the type of this error
  152. func (ndbee NonDefaultBridgeExistError) Forbidden() {}
  153. // NonDefaultBridgeNeedsIPError is returned when a non-default
  154. // bridge config is passed but it has no ip configured
  155. type NonDefaultBridgeNeedsIPError string
  156. func (ndbee NonDefaultBridgeNeedsIPError) Error() string {
  157. return fmt.Sprintf("bridge device with non default name %s must have a valid IP address", string(ndbee))
  158. }
  159. // Forbidden denotes the type of this error
  160. func (ndbee NonDefaultBridgeNeedsIPError) Forbidden() {}
  161. // FixedCIDRv4Error is returned when fixed-cidrv4 configuration
  162. // failed.
  163. type FixedCIDRv4Error struct {
  164. Net *net.IPNet
  165. Subnet *net.IPNet
  166. Err error
  167. }
  168. func (fcv4 *FixedCIDRv4Error) Error() string {
  169. return fmt.Sprintf("setup FixedCIDRv4 failed for subnet %s in %s: %v", fcv4.Subnet, fcv4.Net, fcv4.Err)
  170. }
  171. // InternalError denotes the type of this error
  172. func (fcv4 *FixedCIDRv4Error) InternalError() {}
  173. // FixedCIDRv6Error is returned when fixed-cidrv6 configuration
  174. // failed.
  175. type FixedCIDRv6Error struct {
  176. Net *net.IPNet
  177. Err error
  178. }
  179. func (fcv6 *FixedCIDRv6Error) Error() string {
  180. return fmt.Sprintf("setup FixedCIDRv6 failed for subnet %s in %s: %v", fcv6.Net, fcv6.Net, fcv6.Err)
  181. }
  182. // InternalError denotes the type of this error
  183. func (fcv6 *FixedCIDRv6Error) InternalError() {}
  184. // IPTableCfgError is returned when an unexpected ip tables configuration is entered
  185. type IPTableCfgError string
  186. func (name IPTableCfgError) Error() string {
  187. return fmt.Sprintf("unexpected request to set IP tables for interface: %s", string(name))
  188. }
  189. // BadRequest denotes the type of this error
  190. func (name IPTableCfgError) BadRequest() {}
  191. // InvalidIPTablesCfgError is returned when an invalid ip tables configuration is entered
  192. type InvalidIPTablesCfgError string
  193. func (action InvalidIPTablesCfgError) Error() string {
  194. return fmt.Sprintf("Invalid IPTables action '%s'", string(action))
  195. }
  196. // BadRequest denotes the type of this error
  197. func (action InvalidIPTablesCfgError) BadRequest() {}
  198. // IPv4AddrRangeError is returned when a valid IP address range couldn't be found.
  199. type IPv4AddrRangeError string
  200. func (name IPv4AddrRangeError) Error() string {
  201. return fmt.Sprintf("can't find an address range for interface %q", string(name))
  202. }
  203. // BadRequest denotes the type of this error
  204. func (name IPv4AddrRangeError) BadRequest() {}
  205. // IPv4AddrAddError is returned when IPv4 address could not be added to the bridge.
  206. type IPv4AddrAddError struct {
  207. IP *net.IPNet
  208. Err error
  209. }
  210. func (ipv4 *IPv4AddrAddError) Error() string {
  211. return fmt.Sprintf("failed to add IPv4 address %s to bridge: %v", ipv4.IP, ipv4.Err)
  212. }
  213. // InternalError denotes the type of this error
  214. func (ipv4 *IPv4AddrAddError) InternalError() {}
  215. // IPv6AddrAddError is returned when IPv6 address could not be added to the bridge.
  216. type IPv6AddrAddError struct {
  217. IP *net.IPNet
  218. Err error
  219. }
  220. func (ipv6 *IPv6AddrAddError) Error() string {
  221. return fmt.Sprintf("failed to add IPv6 address %s to bridge: %v", ipv6.IP, ipv6.Err)
  222. }
  223. // InternalError denotes the type of this error
  224. func (ipv6 *IPv6AddrAddError) InternalError() {}
  225. // IPv4AddrNoMatchError is returned when the bridge's IPv4 address does not match configured.
  226. type IPv4AddrNoMatchError struct {
  227. IP net.IP
  228. CfgIP net.IP
  229. }
  230. func (ipv4 *IPv4AddrNoMatchError) Error() string {
  231. return fmt.Sprintf("bridge IPv4 (%s) does not match requested configuration %s", ipv4.IP, ipv4.CfgIP)
  232. }
  233. // BadRequest denotes the type of this error
  234. func (ipv4 *IPv4AddrNoMatchError) BadRequest() {}
  235. // IPv6AddrNoMatchError is returned when the bridge's IPv6 address does not match configured.
  236. type IPv6AddrNoMatchError net.IPNet
  237. func (ipv6 *IPv6AddrNoMatchError) Error() string {
  238. return fmt.Sprintf("bridge IPv6 addresses do not match the expected bridge configuration %s", (*net.IPNet)(ipv6).String())
  239. }
  240. // BadRequest denotes the type of this error
  241. func (ipv6 *IPv6AddrNoMatchError) BadRequest() {}
  242. // InvalidLinkIPAddrError is returned when a link is configured to a container with an invalid ip address
  243. type InvalidLinkIPAddrError string
  244. func (address InvalidLinkIPAddrError) Error() string {
  245. return fmt.Sprintf("Cannot link to a container with Invalid IP Address '%s'", string(address))
  246. }
  247. // BadRequest denotes the type of this error
  248. func (address InvalidLinkIPAddrError) BadRequest() {}