errors.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. // ErrIPFwdCfg is returned when ip forwarding setup is invoked when the configuration
  84. // not enabled.
  85. type ErrIPFwdCfg struct{}
  86. func (eipf *ErrIPFwdCfg) Error() string {
  87. return "unexpected request to enable IP Forwarding"
  88. }
  89. // BadRequest denotes the type of this error
  90. func (eipf *ErrIPFwdCfg) BadRequest() {}
  91. // ErrInvalidPort is returned when the container or host port specified in the port binding is not valid.
  92. type ErrInvalidPort string
  93. func (ip ErrInvalidPort) Error() string {
  94. return fmt.Sprintf("invalid transport port: %s", string(ip))
  95. }
  96. // BadRequest denotes the type of this error
  97. func (ip ErrInvalidPort) BadRequest() {}
  98. // ErrUnsupportedAddressType is returned when the specified address type is not supported.
  99. type ErrUnsupportedAddressType string
  100. func (uat ErrUnsupportedAddressType) Error() string {
  101. return fmt.Sprintf("unsupported address type: %s", string(uat))
  102. }
  103. // BadRequest denotes the type of this error
  104. func (uat ErrUnsupportedAddressType) BadRequest() {}
  105. // ErrInvalidAddressBinding is returned when the host address specified in the port binding is not valid.
  106. type ErrInvalidAddressBinding string
  107. func (iab ErrInvalidAddressBinding) Error() string {
  108. return fmt.Sprintf("invalid host address in port binding: %s", string(iab))
  109. }
  110. // BadRequest denotes the type of this error
  111. func (iab ErrInvalidAddressBinding) BadRequest() {}
  112. // ActiveEndpointsError is returned when there are
  113. // still active endpoints in the network being deleted.
  114. type ActiveEndpointsError string
  115. func (aee ActiveEndpointsError) Error() string {
  116. return fmt.Sprintf("network %s has active endpoint", string(aee))
  117. }
  118. // Forbidden denotes the type of this error
  119. func (aee ActiveEndpointsError) Forbidden() {}
  120. // InvalidNetworkIDError is returned when the passed
  121. // network id for an existing network is not a known id.
  122. type InvalidNetworkIDError string
  123. func (inie InvalidNetworkIDError) Error() string {
  124. return fmt.Sprintf("invalid network id %s", string(inie))
  125. }
  126. // NotFound denotes the type of this error
  127. func (inie InvalidNetworkIDError) NotFound() {}
  128. // InvalidEndpointIDError is returned when the passed
  129. // endpoint id is not valid.
  130. type InvalidEndpointIDError string
  131. func (ieie InvalidEndpointIDError) Error() string {
  132. return fmt.Sprintf("invalid endpoint id: %s", string(ieie))
  133. }
  134. // BadRequest denotes the type of this error
  135. func (ieie InvalidEndpointIDError) BadRequest() {}
  136. // InvalidSandboxIDError is returned when the passed
  137. // sandbox id is not valid.
  138. type InvalidSandboxIDError string
  139. func (isie InvalidSandboxIDError) Error() string {
  140. return fmt.Sprintf("invalid sanbox id: %s", string(isie))
  141. }
  142. // BadRequest denotes the type of this error
  143. func (isie InvalidSandboxIDError) BadRequest() {}
  144. // EndpointNotFoundError is returned when the no endpoint
  145. // with the passed endpoint id is found.
  146. type EndpointNotFoundError string
  147. func (enfe EndpointNotFoundError) Error() string {
  148. return fmt.Sprintf("endpoint not found: %s", string(enfe))
  149. }
  150. // NotFound denotes the type of this error
  151. func (enfe EndpointNotFoundError) NotFound() {}
  152. // NonDefaultBridgeExistError is returned when a non-default
  153. // bridge config is passed but it does not already exist.
  154. type NonDefaultBridgeExistError string
  155. func (ndbee NonDefaultBridgeExistError) Error() string {
  156. return fmt.Sprintf("bridge device with non default name %s must be created manually", string(ndbee))
  157. }
  158. // Forbidden denotes the type of this error
  159. func (ndbee NonDefaultBridgeExistError) Forbidden() {}
  160. // FixedCIDRv4Error is returned when fixed-cidrv4 configuration
  161. // failed.
  162. type FixedCIDRv4Error struct {
  163. Net *net.IPNet
  164. Subnet *net.IPNet
  165. Err error
  166. }
  167. func (fcv4 *FixedCIDRv4Error) Error() string {
  168. return fmt.Sprintf("setup FixedCIDRv4 failed for subnet %s in %s: %v", fcv4.Subnet, fcv4.Net, fcv4.Err)
  169. }
  170. // InternalError denotes the type of this error
  171. func (fcv4 *FixedCIDRv4Error) InternalError() {}
  172. // FixedCIDRv6Error is returned when fixed-cidrv6 configuration
  173. // failed.
  174. type FixedCIDRv6Error struct {
  175. Net *net.IPNet
  176. Err error
  177. }
  178. func (fcv6 *FixedCIDRv6Error) Error() string {
  179. return fmt.Sprintf("setup FixedCIDRv6 failed for subnet %s in %s: %v", fcv6.Net, fcv6.Net, fcv6.Err)
  180. }
  181. // InternalError denotes the type of this error
  182. func (fcv6 *FixedCIDRv6Error) InternalError() {}
  183. // IPTableCfgError is returned when an unexpected ip tables configuration is entered
  184. type IPTableCfgError string
  185. func (name IPTableCfgError) Error() string {
  186. return fmt.Sprintf("unexpected request to set IP tables for interface: %s", string(name))
  187. }
  188. // BadRequest denotes the type of this error
  189. func (name IPTableCfgError) BadRequest() {}
  190. // InvalidIPTablesCfgError is returned when an invalid ip tables configuration is entered
  191. type InvalidIPTablesCfgError string
  192. func (action InvalidIPTablesCfgError) Error() string {
  193. return fmt.Sprintf("Invalid IPTables action '%s'", string(action))
  194. }
  195. // BadRequest denotes the type of this error
  196. func (action InvalidIPTablesCfgError) BadRequest() {}
  197. // IPv4AddrRangeError is returned when a valid IP address range couldn't be found.
  198. type IPv4AddrRangeError string
  199. func (name IPv4AddrRangeError) Error() string {
  200. return fmt.Sprintf("can't find an address range for interface %q", string(name))
  201. }
  202. // BadRequest denotes the type of this error
  203. func (name IPv4AddrRangeError) BadRequest() {}
  204. // IPv4AddrAddError is returned when IPv4 address could not be added to the bridge.
  205. type IPv4AddrAddError struct {
  206. IP *net.IPNet
  207. Err error
  208. }
  209. func (ipv4 *IPv4AddrAddError) Error() string {
  210. return fmt.Sprintf("failed to add IPv4 address %s to bridge: %v", ipv4.IP, ipv4.Err)
  211. }
  212. // InternalError denotes the type of this error
  213. func (ipv4 *IPv4AddrAddError) InternalError() {}
  214. // IPv6AddrAddError is returned when IPv6 address could not be added to the bridge.
  215. type IPv6AddrAddError struct {
  216. IP *net.IPNet
  217. Err error
  218. }
  219. func (ipv6 *IPv6AddrAddError) Error() string {
  220. return fmt.Sprintf("failed to add IPv6 address %s to bridge: %v", ipv6.IP, ipv6.Err)
  221. }
  222. // InternalError denotes the type of this error
  223. func (ipv6 *IPv6AddrAddError) InternalError() {}
  224. // IPv4AddrNoMatchError is returned when the bridge's IPv4 address does not match configured.
  225. type IPv4AddrNoMatchError struct {
  226. IP net.IP
  227. CfgIP net.IP
  228. }
  229. func (ipv4 *IPv4AddrNoMatchError) Error() string {
  230. return fmt.Sprintf("bridge IPv4 (%s) does not match requested configuration %s", ipv4.IP, ipv4.CfgIP)
  231. }
  232. // BadRequest denotes the type of this error
  233. func (ipv4 *IPv4AddrNoMatchError) BadRequest() {}
  234. // IPv6AddrNoMatchError is returned when the bridge's IPv6 address does not match configured.
  235. type IPv6AddrNoMatchError net.IPNet
  236. func (ipv6 *IPv6AddrNoMatchError) Error() string {
  237. return fmt.Sprintf("bridge IPv6 addresses do not match the expected bridge configuration %s", (*net.IPNet)(ipv6).String())
  238. }
  239. // BadRequest denotes the type of this error
  240. func (ipv6 *IPv6AddrNoMatchError) BadRequest() {}
  241. // InvalidLinkIPAddrError is returned when a link is configured to a container with an invalid ip address
  242. type InvalidLinkIPAddrError string
  243. func (address InvalidLinkIPAddrError) Error() string {
  244. return fmt.Sprintf("Cannot link to a container with Invalid IP Address '%s'", string(address))
  245. }
  246. // BadRequest denotes the type of this error
  247. func (address InvalidLinkIPAddrError) BadRequest() {}