github.com/rish1988/moby@v25.0.2+incompatible/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  // ErrInvalidMtu is returned when the user provided MTU is not valid.
    88  type ErrInvalidMtu int
    89  
    90  func (eim ErrInvalidMtu) Error() string {
    91  	return fmt.Sprintf("invalid MTU number: %d", int(eim))
    92  }
    93  
    94  // InvalidParameter denotes the type of this error
    95  func (eim ErrInvalidMtu) InvalidParameter() {}
    96  
    97  // ErrUnsupportedAddressType is returned when the specified address type is not supported.
    98  type ErrUnsupportedAddressType string
    99  
   100  func (uat ErrUnsupportedAddressType) Error() string {
   101  	return fmt.Sprintf("unsupported address type: %s", string(uat))
   102  }
   103  
   104  // InvalidParameter denotes the type of this error
   105  func (uat ErrUnsupportedAddressType) InvalidParameter() {}
   106  
   107  // InvalidNetworkIDError is returned when the passed
   108  // network id for an existing network is not a known id.
   109  type InvalidNetworkIDError string
   110  
   111  func (inie InvalidNetworkIDError) Error() string {
   112  	return fmt.Sprintf("invalid network id %s", string(inie))
   113  }
   114  
   115  // NotFound denotes the type of this error
   116  func (inie InvalidNetworkIDError) NotFound() {}
   117  
   118  // InvalidEndpointIDError is returned when the passed
   119  // endpoint id is not valid.
   120  type InvalidEndpointIDError string
   121  
   122  func (ieie InvalidEndpointIDError) Error() string {
   123  	return fmt.Sprintf("invalid endpoint id: %s", string(ieie))
   124  }
   125  
   126  // InvalidParameter denotes the type of this error
   127  func (ieie InvalidEndpointIDError) InvalidParameter() {}
   128  
   129  // EndpointNotFoundError is returned when the no endpoint
   130  // with the passed endpoint id is found.
   131  type EndpointNotFoundError string
   132  
   133  func (enfe EndpointNotFoundError) Error() string {
   134  	return fmt.Sprintf("endpoint not found: %s", string(enfe))
   135  }
   136  
   137  // NotFound denotes the type of this error
   138  func (enfe EndpointNotFoundError) NotFound() {}
   139  
   140  // NonDefaultBridgeExistError is returned when a non-default
   141  // bridge config is passed but it does not already exist.
   142  type NonDefaultBridgeExistError string
   143  
   144  func (ndbee NonDefaultBridgeExistError) Error() string {
   145  	return fmt.Sprintf("bridge device with non default name %s must be created manually", string(ndbee))
   146  }
   147  
   148  // Forbidden denotes the type of this error
   149  func (ndbee NonDefaultBridgeExistError) Forbidden() {}
   150  
   151  // NonDefaultBridgeNeedsIPError is returned when a non-default
   152  // bridge config is passed but it has no ip configured
   153  type NonDefaultBridgeNeedsIPError string
   154  
   155  func (ndbee NonDefaultBridgeNeedsIPError) Error() string {
   156  	return fmt.Sprintf("bridge device with non default name %s must have a valid IP address", string(ndbee))
   157  }
   158  
   159  // Forbidden denotes the type of this error
   160  func (ndbee NonDefaultBridgeNeedsIPError) Forbidden() {}
   161  
   162  // IPv4AddrAddError is returned when IPv4 address could not be added to the bridge.
   163  type IPv4AddrAddError struct {
   164  	IP  *net.IPNet
   165  	Err error
   166  }
   167  
   168  func (ipv4 *IPv4AddrAddError) Error() string {
   169  	return fmt.Sprintf("failed to add IPv4 address %s to bridge: %v", ipv4.IP, ipv4.Err)
   170  }
   171  
   172  // InternalError denotes the type of this error
   173  func (ipv4 *IPv4AddrAddError) InternalError() {}
   174  
   175  // IPv4AddrNoMatchError is returned when the bridge's IPv4 address does not match configured.
   176  type IPv4AddrNoMatchError struct {
   177  	IP    net.IP
   178  	CfgIP net.IP
   179  }
   180  
   181  func (ipv4 *IPv4AddrNoMatchError) Error() string {
   182  	return fmt.Sprintf("bridge IPv4 (%s) does not match requested configuration %s", ipv4.IP, ipv4.CfgIP)
   183  }
   184  
   185  // IPv6AddrNoMatchError is returned when the bridge's IPv6 address does not match configured.
   186  type IPv6AddrNoMatchError net.IPNet
   187  
   188  func (ipv6 *IPv6AddrNoMatchError) Error() string {
   189  	return fmt.Sprintf("bridge IPv6 addresses do not match the expected bridge configuration %s", (*net.IPNet)(ipv6).String())
   190  }