github.com/metacubex/gvisor@v0.0.0-20240320004321-933faba989ec/pkg/tcpip/link/rawfile/errors.go (about) 1 // Copyright 2018 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 //go:build linux 16 // +build linux 17 18 package rawfile 19 20 import ( 21 "golang.org/x/sys/unix" 22 "github.com/metacubex/gvisor/pkg/tcpip" 23 ) 24 25 const maxErrno = 134 26 27 // TranslateErrno translate an errno from the syscall package into a 28 // tcpip.Error. 29 // 30 // Valid, but unrecognized errnos will be translated to 31 // *tcpip.ErrInvalidEndpointState (EINVAL). 32 func TranslateErrno(e unix.Errno) tcpip.Error { 33 switch e { 34 case unix.EEXIST: 35 return &tcpip.ErrDuplicateAddress{} 36 case unix.ENETUNREACH: 37 return &tcpip.ErrHostUnreachable{} 38 case unix.EINVAL: 39 return &tcpip.ErrInvalidEndpointState{} 40 case unix.EALREADY: 41 return &tcpip.ErrAlreadyConnecting{} 42 case unix.EISCONN: 43 return &tcpip.ErrAlreadyConnected{} 44 case unix.EADDRINUSE: 45 return &tcpip.ErrPortInUse{} 46 case unix.EADDRNOTAVAIL: 47 return &tcpip.ErrBadLocalAddress{} 48 case unix.EPIPE: 49 return &tcpip.ErrClosedForSend{} 50 case unix.EWOULDBLOCK: 51 return &tcpip.ErrWouldBlock{} 52 case unix.ECONNREFUSED: 53 return &tcpip.ErrConnectionRefused{} 54 case unix.ETIMEDOUT: 55 return &tcpip.ErrTimeout{} 56 case unix.EINPROGRESS: 57 return &tcpip.ErrConnectStarted{} 58 case unix.EDESTADDRREQ: 59 return &tcpip.ErrDestinationRequired{} 60 case unix.ENOTSUP: 61 return &tcpip.ErrNotSupported{} 62 case unix.ENOTTY: 63 return &tcpip.ErrQueueSizeNotSupported{} 64 case unix.ENOTCONN: 65 return &tcpip.ErrNotConnected{} 66 case unix.ECONNRESET: 67 return &tcpip.ErrConnectionReset{} 68 case unix.ECONNABORTED: 69 return &tcpip.ErrConnectionAborted{} 70 case unix.EMSGSIZE: 71 return &tcpip.ErrMessageTooLong{} 72 case unix.ENOBUFS: 73 return &tcpip.ErrNoBufferSpace{} 74 default: 75 return &tcpip.ErrInvalidEndpointState{} 76 } 77 }