diff options
author | gVisor bot <gvisor-bot@google.com> | 2021-03-03 18:43:27 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-03-03 18:43:27 +0000 |
commit | aae5455fe381c4cbc956f61c971284ee05c52dfc (patch) | |
tree | 2b1cb0233968680dcd0374f20ee826cf311bda95 /pkg/tcpip/link/rawfile | |
parent | e2599d556573b05eb3714c1e791fa29431dc3d3f (diff) | |
parent | a9441aea2780da8c93da1c73da860219f98438de (diff) |
Merge release-20210301.0-5-ga9441aea2 (automated)
Diffstat (limited to 'pkg/tcpip/link/rawfile')
-rw-r--r-- | pkg/tcpip/link/rawfile/blockingpoll_noyield_unsafe.go | 7 | ||||
-rw-r--r-- | pkg/tcpip/link/rawfile/blockingpoll_yield_unsafe.go | 5 | ||||
-rw-r--r-- | pkg/tcpip/link/rawfile/errors.go | 45 | ||||
-rw-r--r-- | pkg/tcpip/link/rawfile/rawfile_unsafe.go | 33 |
4 files changed, 45 insertions, 45 deletions
diff --git a/pkg/tcpip/link/rawfile/blockingpoll_noyield_unsafe.go b/pkg/tcpip/link/rawfile/blockingpoll_noyield_unsafe.go index 621ab8d29..2206fe0e6 100644 --- a/pkg/tcpip/link/rawfile/blockingpoll_noyield_unsafe.go +++ b/pkg/tcpip/link/rawfile/blockingpoll_noyield_unsafe.go @@ -17,14 +17,15 @@ package rawfile import ( - "syscall" "unsafe" + + "golang.org/x/sys/unix" ) // BlockingPoll is just a stub function that forwards to the ppoll() system call // on non-amd64 and non-arm64 platforms. -func BlockingPoll(fds *PollEvent, nfds int, timeout *syscall.Timespec) (int, syscall.Errno) { - n, _, e := syscall.Syscall6(syscall.SYS_PPOLL, uintptr(unsafe.Pointer(fds)), +func BlockingPoll(fds *PollEvent, nfds int, timeout *unix.Timespec) (int, unix.Errno) { + n, _, e := unix.Syscall6(unix.SYS_PPOLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(unsafe.Pointer(timeout)), 0, 0, 0) return int(n), e diff --git a/pkg/tcpip/link/rawfile/blockingpoll_yield_unsafe.go b/pkg/tcpip/link/rawfile/blockingpoll_yield_unsafe.go index 7f238102e..5002245a1 100644 --- a/pkg/tcpip/link/rawfile/blockingpoll_yield_unsafe.go +++ b/pkg/tcpip/link/rawfile/blockingpoll_yield_unsafe.go @@ -21,8 +21,9 @@ package rawfile import ( - "syscall" _ "unsafe" // for go:linkname + + "golang.org/x/sys/unix" ) // BlockingPoll on amd64/arm64 makes the ppoll() syscall while calling the @@ -32,7 +33,7 @@ import ( // call. // //go:noescape -func BlockingPoll(fds *PollEvent, nfds int, timeout *syscall.Timespec) (int, syscall.Errno) +func BlockingPoll(fds *PollEvent, nfds int, timeout *unix.Timespec) (int, unix.Errno) // Use go:linkname to call into the runtime. As of Go 1.12 this has to // be done from Go code so that we make an ABIInternal call to an diff --git a/pkg/tcpip/link/rawfile/errors.go b/pkg/tcpip/link/rawfile/errors.go index 406b97709..9743e70ea 100644 --- a/pkg/tcpip/link/rawfile/errors.go +++ b/pkg/tcpip/link/rawfile/errors.go @@ -17,8 +17,7 @@ package rawfile import ( - "syscall" - + "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/tcpip" ) @@ -29,47 +28,47 @@ const maxErrno = 134 // // Valid, but unrecognized errnos will be translated to // *tcpip.ErrInvalidEndpointState (EINVAL). -func TranslateErrno(e syscall.Errno) tcpip.Error { +func TranslateErrno(e unix.Errno) tcpip.Error { switch e { - case syscall.EEXIST: + case unix.EEXIST: return &tcpip.ErrDuplicateAddress{} - case syscall.ENETUNREACH: + case unix.ENETUNREACH: return &tcpip.ErrNoRoute{} - case syscall.EINVAL: + case unix.EINVAL: return &tcpip.ErrInvalidEndpointState{} - case syscall.EALREADY: + case unix.EALREADY: return &tcpip.ErrAlreadyConnecting{} - case syscall.EISCONN: + case unix.EISCONN: return &tcpip.ErrAlreadyConnected{} - case syscall.EADDRINUSE: + case unix.EADDRINUSE: return &tcpip.ErrPortInUse{} - case syscall.EADDRNOTAVAIL: + case unix.EADDRNOTAVAIL: return &tcpip.ErrBadLocalAddress{} - case syscall.EPIPE: + case unix.EPIPE: return &tcpip.ErrClosedForSend{} - case syscall.EWOULDBLOCK: + case unix.EWOULDBLOCK: return &tcpip.ErrWouldBlock{} - case syscall.ECONNREFUSED: + case unix.ECONNREFUSED: return &tcpip.ErrConnectionRefused{} - case syscall.ETIMEDOUT: + case unix.ETIMEDOUT: return &tcpip.ErrTimeout{} - case syscall.EINPROGRESS: + case unix.EINPROGRESS: return &tcpip.ErrConnectStarted{} - case syscall.EDESTADDRREQ: + case unix.EDESTADDRREQ: return &tcpip.ErrDestinationRequired{} - case syscall.ENOTSUP: + case unix.ENOTSUP: return &tcpip.ErrNotSupported{} - case syscall.ENOTTY: + case unix.ENOTTY: return &tcpip.ErrQueueSizeNotSupported{} - case syscall.ENOTCONN: + case unix.ENOTCONN: return &tcpip.ErrNotConnected{} - case syscall.ECONNRESET: + case unix.ECONNRESET: return &tcpip.ErrConnectionReset{} - case syscall.ECONNABORTED: + case unix.ECONNABORTED: return &tcpip.ErrConnectionAborted{} - case syscall.EMSGSIZE: + case unix.EMSGSIZE: return &tcpip.ErrMessageTooLong{} - case syscall.ENOBUFS: + case unix.ENOBUFS: return &tcpip.ErrNoBufferSpace{} default: return &tcpip.ErrInvalidEndpointState{} diff --git a/pkg/tcpip/link/rawfile/rawfile_unsafe.go b/pkg/tcpip/link/rawfile/rawfile_unsafe.go index 06f3ee21e..ba92aedbc 100644 --- a/pkg/tcpip/link/rawfile/rawfile_unsafe.go +++ b/pkg/tcpip/link/rawfile/rawfile_unsafe.go @@ -19,7 +19,6 @@ package rawfile import ( - "syscall" "unsafe" "golang.org/x/sys/unix" @@ -28,12 +27,12 @@ import ( // GetMTU determines the MTU of a network interface device. func GetMTU(name string) (uint32, error) { - fd, err := syscall.Socket(syscall.AF_UNIX, syscall.SOCK_DGRAM, 0) + fd, err := unix.Socket(unix.AF_UNIX, unix.SOCK_DGRAM, 0) if err != nil { return 0, err } - defer syscall.Close(fd) + defer unix.Close(fd) var ifreq struct { name [16]byte @@ -42,7 +41,7 @@ func GetMTU(name string) (uint32, error) { } copy(ifreq.name[:], name) - _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), syscall.SIOCGIFMTU, uintptr(unsafe.Pointer(&ifreq))) + _, _, errno := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), unix.SIOCGIFMTU, uintptr(unsafe.Pointer(&ifreq))) if errno != 0 { return 0, errno } @@ -58,7 +57,7 @@ func NonBlockingWrite(fd int, buf []byte) tcpip.Error { ptr = unsafe.Pointer(&buf[0]) } - _, _, e := syscall.RawSyscall(syscall.SYS_WRITE, uintptr(fd), uintptr(ptr), uintptr(len(buf))) + _, _, e := unix.RawSyscall(unix.SYS_WRITE, uintptr(fd), uintptr(ptr), uintptr(len(buf))) if e != 0 { return TranslateErrno(e) } @@ -66,11 +65,11 @@ func NonBlockingWrite(fd int, buf []byte) tcpip.Error { return nil } -// NonBlockingWriteIovec writes iovec to a file descriptor in a single syscall. +// NonBlockingWriteIovec writes iovec to a file descriptor in a single unix. // It fails if partial data is written. -func NonBlockingWriteIovec(fd int, iovec []syscall.Iovec) tcpip.Error { +func NonBlockingWriteIovec(fd int, iovec []unix.Iovec) tcpip.Error { iovecLen := uintptr(len(iovec)) - _, _, e := syscall.RawSyscall(syscall.SYS_WRITEV, uintptr(fd), uintptr(unsafe.Pointer(&iovec[0])), iovecLen) + _, _, e := unix.RawSyscall(unix.SYS_WRITEV, uintptr(fd), uintptr(unsafe.Pointer(&iovec[0])), iovecLen) if e != 0 { return TranslateErrno(e) } @@ -79,7 +78,7 @@ func NonBlockingWriteIovec(fd int, iovec []syscall.Iovec) tcpip.Error { // NonBlockingSendMMsg sends multiple messages on a socket. func NonBlockingSendMMsg(fd int, msgHdrs []MMsgHdr) (int, tcpip.Error) { - n, _, e := syscall.RawSyscall6(unix.SYS_SENDMMSG, uintptr(fd), uintptr(unsafe.Pointer(&msgHdrs[0])), uintptr(len(msgHdrs)), syscall.MSG_DONTWAIT, 0, 0) + n, _, e := unix.RawSyscall6(unix.SYS_SENDMMSG, uintptr(fd), uintptr(unsafe.Pointer(&msgHdrs[0])), uintptr(len(msgHdrs)), unix.MSG_DONTWAIT, 0, 0) if e != 0 { return 0, TranslateErrno(e) } @@ -99,7 +98,7 @@ type PollEvent struct { // descriptor becomes readable. func BlockingRead(fd int, b []byte) (int, tcpip.Error) { for { - n, _, e := syscall.RawSyscall(syscall.SYS_READ, uintptr(fd), uintptr(unsafe.Pointer(&b[0])), uintptr(len(b))) + n, _, e := unix.RawSyscall(unix.SYS_READ, uintptr(fd), uintptr(unsafe.Pointer(&b[0])), uintptr(len(b))) if e == 0 { return int(n), nil } @@ -110,7 +109,7 @@ func BlockingRead(fd int, b []byte) (int, tcpip.Error) { } _, e = BlockingPoll(&event, 1, nil) - if e != 0 && e != syscall.EINTR { + if e != 0 && e != unix.EINTR { return 0, TranslateErrno(e) } } @@ -119,9 +118,9 @@ func BlockingRead(fd int, b []byte) (int, tcpip.Error) { // BlockingReadv reads from a file descriptor that is set up as non-blocking and // stores the data in a list of iovecs buffers. If no data is available, it will // block in a poll() syscall until the file descriptor becomes readable. -func BlockingReadv(fd int, iovecs []syscall.Iovec) (int, tcpip.Error) { +func BlockingReadv(fd int, iovecs []unix.Iovec) (int, tcpip.Error) { for { - n, _, e := syscall.RawSyscall(syscall.SYS_READV, uintptr(fd), uintptr(unsafe.Pointer(&iovecs[0])), uintptr(len(iovecs))) + n, _, e := unix.RawSyscall(unix.SYS_READV, uintptr(fd), uintptr(unsafe.Pointer(&iovecs[0])), uintptr(len(iovecs))) if e == 0 { return int(n), nil } @@ -132,7 +131,7 @@ func BlockingReadv(fd int, iovecs []syscall.Iovec) (int, tcpip.Error) { } _, e = BlockingPoll(&event, 1, nil) - if e != 0 && e != syscall.EINTR { + if e != 0 && e != unix.EINTR { return 0, TranslateErrno(e) } } @@ -140,7 +139,7 @@ func BlockingReadv(fd int, iovecs []syscall.Iovec) (int, tcpip.Error) { // MMsgHdr represents the mmsg_hdr structure required by recvmmsg() on linux. type MMsgHdr struct { - Msg syscall.Msghdr + Msg unix.Msghdr Len uint32 _ [4]byte } @@ -151,7 +150,7 @@ type MMsgHdr struct { // becomes readable. func BlockingRecvMMsg(fd int, msgHdrs []MMsgHdr) (int, tcpip.Error) { for { - n, _, e := syscall.RawSyscall6(syscall.SYS_RECVMMSG, uintptr(fd), uintptr(unsafe.Pointer(&msgHdrs[0])), uintptr(len(msgHdrs)), syscall.MSG_DONTWAIT, 0, 0) + n, _, e := unix.RawSyscall6(unix.SYS_RECVMMSG, uintptr(fd), uintptr(unsafe.Pointer(&msgHdrs[0])), uintptr(len(msgHdrs)), unix.MSG_DONTWAIT, 0, 0) if e == 0 { return int(n), nil } @@ -161,7 +160,7 @@ func BlockingRecvMMsg(fd int, msgHdrs []MMsgHdr) (int, tcpip.Error) { Events: 1, // POLLIN } - if _, e := BlockingPoll(&event, 1, nil); e != 0 && e != syscall.EINTR { + if _, e := BlockingPoll(&event, 1, nil); e != 0 && e != unix.EINTR { return 0, TranslateErrno(e) } } |