errors.go 10 KB

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