github.com/metacubex/gvisor@v0.0.0-20240320004321-933faba989ec/pkg/tcpip/network/internal/ip/errors.go (about)

     1  // Copyright 2021 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package ip
    16  
    17  import (
    18  	"fmt"
    19  
    20  	"github.com/metacubex/gvisor/pkg/tcpip"
    21  )
    22  
    23  // ForwardingError represents an error that occurred while trying to forward
    24  // a packet.
    25  type ForwardingError interface {
    26  	isForwardingError()
    27  	fmt.Stringer
    28  }
    29  
    30  // ErrTTLExceeded indicates that the received packet's TTL has been exceeded.
    31  type ErrTTLExceeded struct{}
    32  
    33  func (*ErrTTLExceeded) isForwardingError() {}
    34  
    35  func (*ErrTTLExceeded) String() string { return "ttl exceeded" }
    36  
    37  // ErrOutgoingDeviceNoBufferSpace indicates that the outgoing device does not
    38  // have enough space to hold a buffer.
    39  type ErrOutgoingDeviceNoBufferSpace struct{}
    40  
    41  func (*ErrOutgoingDeviceNoBufferSpace) isForwardingError() {}
    42  
    43  func (*ErrOutgoingDeviceNoBufferSpace) String() string { return "no device buffer space" }
    44  
    45  // ErrParameterProblem indicates the received packet had a problem with an IP
    46  // parameter.
    47  type ErrParameterProblem struct{}
    48  
    49  func (*ErrParameterProblem) isForwardingError() {}
    50  
    51  func (*ErrParameterProblem) String() string { return "parameter problem" }
    52  
    53  // ErrInitializingSourceAddress indicates the received packet had a source
    54  // address that may only be used on the local network as part of initialization
    55  // work.
    56  type ErrInitializingSourceAddress struct{}
    57  
    58  func (*ErrInitializingSourceAddress) isForwardingError() {}
    59  
    60  func (*ErrInitializingSourceAddress) String() string { return "initializing source address" }
    61  
    62  // ErrLinkLocalSourceAddress indicates the received packet had a link-local
    63  // source address.
    64  type ErrLinkLocalSourceAddress struct{}
    65  
    66  func (*ErrLinkLocalSourceAddress) isForwardingError() {}
    67  
    68  func (*ErrLinkLocalSourceAddress) String() string { return "link local source address" }
    69  
    70  // ErrLinkLocalDestinationAddress indicates the received packet had a link-local
    71  // destination address.
    72  type ErrLinkLocalDestinationAddress struct{}
    73  
    74  func (*ErrLinkLocalDestinationAddress) isForwardingError() {}
    75  
    76  func (*ErrLinkLocalDestinationAddress) String() string { return "link local destination address" }
    77  
    78  // ErrHostUnreachable indicates that the destination host could not be reached.
    79  type ErrHostUnreachable struct{}
    80  
    81  func (*ErrHostUnreachable) isForwardingError() {}
    82  
    83  func (*ErrHostUnreachable) String() string { return "no route to host" }
    84  
    85  // ErrMessageTooLong indicates the packet was too big for the outgoing MTU.
    86  //
    87  // +stateify savable
    88  type ErrMessageTooLong struct{}
    89  
    90  func (*ErrMessageTooLong) isForwardingError() {}
    91  
    92  func (*ErrMessageTooLong) String() string { return "message too long" }
    93  
    94  // ErrNoMulticastPendingQueueBufferSpace indicates that a multicast packet
    95  // could not be added to the pending packet queue due to insufficient buffer
    96  // space.
    97  //
    98  // +stateify savable
    99  type ErrNoMulticastPendingQueueBufferSpace struct{}
   100  
   101  func (*ErrNoMulticastPendingQueueBufferSpace) isForwardingError() {}
   102  
   103  func (*ErrNoMulticastPendingQueueBufferSpace) String() string { return "no buffer space" }
   104  
   105  // ErrUnexpectedMulticastInputInterface indicates that the interface that the
   106  // packet arrived on did not match the routes expected input interface.
   107  type ErrUnexpectedMulticastInputInterface struct{}
   108  
   109  func (*ErrUnexpectedMulticastInputInterface) isForwardingError() {}
   110  
   111  func (*ErrUnexpectedMulticastInputInterface) String() string { return "unexpected input interface" }
   112  
   113  // ErrUnknownOutputEndpoint indicates that the output endpoint associated with
   114  // a route could not be found.
   115  type ErrUnknownOutputEndpoint struct{}
   116  
   117  func (*ErrUnknownOutputEndpoint) isForwardingError() {}
   118  
   119  func (*ErrUnknownOutputEndpoint) String() string { return "unknown endpoint" }
   120  
   121  // ErrOther indicates the packet coould not be forwarded for a reason
   122  // captured by the contained error.
   123  type ErrOther struct {
   124  	Err tcpip.Error
   125  }
   126  
   127  func (*ErrOther) isForwardingError() {}
   128  
   129  func (e *ErrOther) String() string { return fmt.Sprintf("other tcpip error: %s", e.Err) }