github.com/geofffranks/garden-linux@v0.0.0-20160715111146-26c893169cfa/network/errors.go (about)

     1  package network
     2  
     3  import (
     4  	"fmt"
     5  	"net"
     6  )
     7  
     8  // VethPairCreationError is returned if creating a virtual ethernet pair fails
     9  type VethPairCreationError struct {
    10  	Cause                         error
    11  	HostIfcName, ContainerIfcName string
    12  }
    13  
    14  func (err VethPairCreationError) Error() string {
    15  	return fmtErr("failed to create veth pair with host interface name '%s', container interface name '%s': %v", err.HostIfcName, err.ContainerIfcName, err.Cause)
    16  }
    17  
    18  // MTUError is returned if setting the Mtu on an interface fails
    19  type MTUError struct {
    20  	Cause error
    21  	Intf  *net.Interface
    22  	MTU   int
    23  }
    24  
    25  func (err MTUError) Error() string {
    26  	return fmtErr("failed to set interface '%v' mtu to %d", err.Intf, err.MTU, err.Cause)
    27  }
    28  
    29  type SetNsFailedError struct {
    30  	Cause error
    31  	Intf  *net.Interface
    32  	Pid   int
    33  }
    34  
    35  func (err SetNsFailedError) Error() string {
    36  	return fmtErr("failed to move interface %v in to pid namespace %d: %v", err.Intf, err.Pid, err.Cause)
    37  }
    38  
    39  // BridgeDetectionError is returned if an error occurs while creating a bridge
    40  type BridgeDetectionError struct {
    41  	Cause  error
    42  	Name   string
    43  	IP     net.IP
    44  	Subnet *net.IPNet
    45  }
    46  
    47  func (err BridgeDetectionError) Error() string {
    48  	return fmtErr("failed to find bridge with name '%s', IP '%s', subnet '%s': %v", err.Name, err.IP, err.Subnet, err.Cause)
    49  }
    50  
    51  // AddToBridgeError is returned if an error occurs while adding an interface to a bridge
    52  type AddToBridgeError struct {
    53  	Cause         error
    54  	Bridge, Slave *net.Interface
    55  }
    56  
    57  func (err AddToBridgeError) Error() string {
    58  	return fmtErr("failed to add slave %s to bridge %s: %v", err.Slave.Name, err.Bridge.Name, err.Cause)
    59  }
    60  
    61  // LinkUpError is returned if brinding an interface up fails
    62  type LinkUpError struct {
    63  	Cause error
    64  	Link  *net.Interface
    65  	Role  string
    66  }
    67  
    68  func (err LinkUpError) Error() string {
    69  	return fmtErr("failed to bring %s link %s up: %v", err.Role, err.Link.Name, err.Cause)
    70  }
    71  
    72  // FindLinkError is returned if an expected interface cannot be found inside the container
    73  type FindLinkError struct {
    74  	Cause error // may be nil if no error occurred other than the link not existing
    75  	Role  string
    76  	Name  string
    77  }
    78  
    79  func (err FindLinkError) Error() string {
    80  	return fmtErr("failed to find %s link with name %s", err.Role, err.Name)
    81  }
    82  
    83  // ConfigureLinkError is returned if configuring a link fails
    84  type ConfigureLinkError struct {
    85  	Cause          error
    86  	Role           string
    87  	Interface      *net.Interface
    88  	IntendedIP     net.IP
    89  	IntendedSubnet *net.IPNet
    90  }
    91  
    92  func (err ConfigureLinkError) Error() string {
    93  	return fmtErr("failed to configure %s link (%v) to IP %v, subnet %v", err.Role, err.Interface, err.IntendedIP, err.IntendedSubnet)
    94  }
    95  
    96  // ConfigureDefaultGWError is returned if the default gateway cannot be updated
    97  type ConfigureDefaultGWError struct {
    98  	Cause     error
    99  	Interface *net.Interface
   100  	IP        net.IP
   101  }
   102  
   103  func (err ConfigureDefaultGWError) Error() string {
   104  	return fmtErr("failed to set default gateway to IP %v via device %v", err.IP, err.Interface, err.Cause)
   105  }
   106  
   107  // DeleteLinkError is returned if an interface cannot be succesfully destroyed
   108  type DeleteLinkError struct {
   109  	Cause error
   110  	Role  string
   111  	Name  string
   112  }
   113  
   114  func (err DeleteLinkError) Error() string {
   115  	return fmtErr("failed to delete %s link named %s: %v", err.Role, err.Name, err.Cause)
   116  }
   117  
   118  func fmtErr(msg string, args ...interface{}) string {
   119  	return fmt.Sprintf("network: "+msg, args...)
   120  }