github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/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/SagerNet/gvisor/pkg/tcpip"
    21  )
    22  
    23  // ForwardingError represents an error that occured 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  // ErrParameterProblem indicates the received packet had a problem with an IP
    38  // parameter.
    39  type ErrParameterProblem struct{}
    40  
    41  func (*ErrParameterProblem) isForwardingError() {}
    42  
    43  func (*ErrParameterProblem) String() string { return "parameter problem" }
    44  
    45  // ErrLinkLocalSourceAddress indicates the received packet had a link-local
    46  // source address.
    47  type ErrLinkLocalSourceAddress struct{}
    48  
    49  func (*ErrLinkLocalSourceAddress) isForwardingError() {}
    50  
    51  func (*ErrLinkLocalSourceAddress) String() string { return "link local destination address" }
    52  
    53  // ErrLinkLocalDestinationAddress indicates the received packet had a link-local
    54  // destination address.
    55  type ErrLinkLocalDestinationAddress struct{}
    56  
    57  func (*ErrLinkLocalDestinationAddress) isForwardingError() {}
    58  
    59  func (*ErrLinkLocalDestinationAddress) String() string { return "link local destination address" }
    60  
    61  // ErrNoRoute indicates that a route for the received packet couldn't be found.
    62  type ErrNoRoute struct{}
    63  
    64  func (*ErrNoRoute) isForwardingError() {}
    65  
    66  func (*ErrNoRoute) String() string { return "no route" }
    67  
    68  // ErrMessageTooLong indicates the packet was too big for the outgoing MTU.
    69  //
    70  // +stateify savable
    71  type ErrMessageTooLong struct{}
    72  
    73  func (*ErrMessageTooLong) isForwardingError() {}
    74  
    75  func (*ErrMessageTooLong) String() string { return "message too long" }
    76  
    77  // ErrOther indicates the packet coould not be forwarded for a reason
    78  // captured by the contained error.
    79  type ErrOther struct {
    80  	Err tcpip.Error
    81  }
    82  
    83  func (*ErrOther) isForwardingError() {}
    84  
    85  func (e *ErrOther) String() string { return fmt.Sprintf("other tcpip error: %s", e.Err) }