github.com/pwn-term/docker@v0.0.0-20210616085119-6e977cce2565/libnetwork/drivers/bridge/errors.go (about)

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