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