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