github.com/jfrazelle/docker@v1.1.2-0.20210712172922-bf78e25fe508/libnetwork/drivers/bridge/errors.go (about)

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