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/fdbased | |
parent | e2599d556573b05eb3714c1e791fa29431dc3d3f (diff) | |
parent | a9441aea2780da8c93da1c73da860219f98438de (diff) |
Merge release-20210301.0-5-ga9441aea2 (automated)
Diffstat (limited to 'pkg/tcpip/link/fdbased')
-rw-r--r-- | pkg/tcpip/link/fdbased/endpoint.go | 17 | ||||
-rw-r--r-- | pkg/tcpip/link/fdbased/mmap.go | 3 | ||||
-rw-r--r-- | pkg/tcpip/link/fdbased/mmap_unsafe.go | 11 | ||||
-rw-r--r-- | pkg/tcpip/link/fdbased/packet_dispatchers.go | 15 |
4 files changed, 21 insertions, 25 deletions
diff --git a/pkg/tcpip/link/fdbased/endpoint.go b/pkg/tcpip/link/fdbased/endpoint.go index 0164d851b..72d3f70ac 100644 --- a/pkg/tcpip/link/fdbased/endpoint.go +++ b/pkg/tcpip/link/fdbased/endpoint.go @@ -41,7 +41,6 @@ package fdbased import ( "fmt" - "syscall" "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/binary" @@ -237,8 +236,8 @@ func New(opts *Options) (stack.LinkEndpoint, error) { // Create per channel dispatchers. for i := 0; i < len(e.fds); i++ { fd := e.fds[i] - if err := syscall.SetNonblock(fd, true); err != nil { - return nil, fmt.Errorf("syscall.SetNonblock(%v) failed: %v", fd, err) + if err := unix.SetNonblock(fd, true); err != nil { + return nil, fmt.Errorf("unix.SetNonblock(%v) failed: %v", fd, err) } isSocket, err := isSocketFD(fd) @@ -291,7 +290,7 @@ func createInboundDispatcher(e *endpoint, fd int, isSocket bool) (linkDispatcher // hard to test fragmentation reassembly code in Netstack. const fanoutType = unix.PACKET_FANOUT_HASH fanoutArg := fanoutID | fanoutType<<16 - if err := syscall.SetsockoptInt(fd, syscall.SOL_PACKET, unix.PACKET_FANOUT, fanoutArg); err != nil { + if err := unix.SetsockoptInt(fd, unix.SOL_PACKET, unix.PACKET_FANOUT, fanoutArg); err != nil { return nil, fmt.Errorf("failed to enable PACKET_FANOUT option: %v", err) } } @@ -316,11 +315,11 @@ func createInboundDispatcher(e *endpoint, fd int, isSocket bool) (linkDispatcher } func isSocketFD(fd int) (bool, error) { - var stat syscall.Stat_t - if err := syscall.Fstat(fd, &stat); err != nil { - return false, fmt.Errorf("syscall.Fstat(%v,...) failed: %v", fd, err) + var stat unix.Stat_t + if err := unix.Fstat(fd, &stat); err != nil { + return false, fmt.Errorf("unix.Fstat(%v,...) failed: %v", fd, err) } - return (stat.Mode & syscall.S_IFSOCK) == syscall.S_IFSOCK, nil + return (stat.Mode & unix.S_IFSOCK) == unix.S_IFSOCK, nil } // Attach launches the goroutine that reads packets from the file descriptor and @@ -614,7 +613,7 @@ func (e *InjectableEndpoint) InjectInbound(protocol tcpip.NetworkProtocolNumber, // NewInjectable creates a new fd-based InjectableEndpoint. func NewInjectable(fd int, mtu uint32, capabilities stack.LinkEndpointCapabilities) *InjectableEndpoint { - syscall.SetNonblock(fd, true) + unix.SetNonblock(fd, true) return &InjectableEndpoint{endpoint: endpoint{ fds: []int{fd}, diff --git a/pkg/tcpip/link/fdbased/mmap.go b/pkg/tcpip/link/fdbased/mmap.go index a2b63fe6b..5d698a5e9 100644 --- a/pkg/tcpip/link/fdbased/mmap.go +++ b/pkg/tcpip/link/fdbased/mmap.go @@ -19,7 +19,6 @@ package fdbased import ( "encoding/binary" "fmt" - "syscall" "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/tcpip" @@ -137,7 +136,7 @@ func (d *packetMMapDispatcher) readMMappedPacket() ([]byte, tcpip.Error) { Events: unix.POLLIN | unix.POLLERR, } if _, errno := rawfile.BlockingPoll(&event, 1, nil); errno != 0 { - if errno == syscall.EINTR { + if errno == unix.EINTR { continue } return nil, rawfile.TranslateErrno(errno) diff --git a/pkg/tcpip/link/fdbased/mmap_unsafe.go b/pkg/tcpip/link/fdbased/mmap_unsafe.go index 3894185ae..1293f68a2 100644 --- a/pkg/tcpip/link/fdbased/mmap_unsafe.go +++ b/pkg/tcpip/link/fdbased/mmap_unsafe.go @@ -19,14 +19,13 @@ package fdbased import ( "fmt" "sync/atomic" - "syscall" "unsafe" "golang.org/x/sys/unix" ) // tPacketHdrlen is the TPACKET_HDRLEN variable defined in <linux/if_packet.h>. -var tPacketHdrlen = tPacketAlign(unsafe.Sizeof(tPacketHdr{}) + unsafe.Sizeof(syscall.RawSockaddrLinklayer{})) +var tPacketHdrlen = tPacketAlign(unsafe.Sizeof(tPacketHdr{}) + unsafe.Sizeof(unix.RawSockaddrLinklayer{})) // tpStatus returns the frame status field. // The status is concurrently updated by the kernel as a result we must @@ -62,21 +61,21 @@ func newPacketMMapDispatcher(fd int, e *endpoint) (linkDispatcher, error) { tpFrameNR: uint32(tpFrameNR), } // Setup PACKET_RX_RING. - if err := setsockopt(d.fd, syscall.SOL_PACKET, syscall.PACKET_RX_RING, unsafe.Pointer(&tReq), unsafe.Sizeof(tReq)); err != nil { + if err := setsockopt(d.fd, unix.SOL_PACKET, unix.PACKET_RX_RING, unsafe.Pointer(&tReq), unsafe.Sizeof(tReq)); err != nil { return nil, fmt.Errorf("failed to enable PACKET_RX_RING: %v", err) } // Let's mmap the blocks. sz := tpBlockSize * tpBlockNR - buf, err := syscall.Mmap(d.fd, 0, sz, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_SHARED) + buf, err := unix.Mmap(d.fd, 0, sz, unix.PROT_READ|unix.PROT_WRITE, unix.MAP_SHARED) if err != nil { - return nil, fmt.Errorf("syscall.Mmap(...,0, %v, ...) failed = %v", sz, err) + return nil, fmt.Errorf("unix.Mmap(...,0, %v, ...) failed = %v", sz, err) } d.ringBuffer = buf return d, nil } func setsockopt(fd, level, name int, val unsafe.Pointer, vallen uintptr) error { - if _, _, errno := syscall.Syscall6(syscall.SYS_SETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(val), vallen, 0); errno != 0 { + if _, _, errno := unix.Syscall6(unix.SYS_SETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(val), vallen, 0); errno != 0 { return error(errno) } diff --git a/pkg/tcpip/link/fdbased/packet_dispatchers.go b/pkg/tcpip/link/fdbased/packet_dispatchers.go index ecae1ad2d..736871d1c 100644 --- a/pkg/tcpip/link/fdbased/packet_dispatchers.go +++ b/pkg/tcpip/link/fdbased/packet_dispatchers.go @@ -17,8 +17,7 @@ package fdbased import ( - "syscall" - + "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/tcpip" "gvisor.dev/gvisor/pkg/tcpip/buffer" "gvisor.dev/gvisor/pkg/tcpip/header" @@ -38,7 +37,7 @@ type iovecBuffer struct { // (skipsVnetHdr) then the first iovec points to a buffer for the vnet header // which is stripped before the views are passed up the stack for further // processing. - iovecs []syscall.Iovec + iovecs []unix.Iovec // sizes is an array of buffer sizes for the underlying views. sizes is // immutable. @@ -58,18 +57,18 @@ func newIovecBuffer(sizes []int, skipsVnetHdr bool) *iovecBuffer { if b.skipsVnetHdr { niov++ } - b.iovecs = make([]syscall.Iovec, niov) + b.iovecs = make([]unix.Iovec, niov) return b } -func (b *iovecBuffer) nextIovecs() []syscall.Iovec { +func (b *iovecBuffer) nextIovecs() []unix.Iovec { vnetHdrOff := 0 if b.skipsVnetHdr { var vnetHdr [virtioNetHdrSize]byte // The kernel adds virtioNetHdr before each packet, but // we don't use it, so so we allocate a buffer for it, // add it in iovecs but don't add it in a view. - b.iovecs[0] = syscall.Iovec{ + b.iovecs[0] = unix.Iovec{ Base: &vnetHdr[0], Len: uint64(virtioNetHdrSize), } @@ -81,7 +80,7 @@ func (b *iovecBuffer) nextIovecs() []syscall.Iovec { } v := buffer.NewView(b.sizes[i]) b.views[i] = v - b.iovecs[i+vnetHdrOff] = syscall.Iovec{ + b.iovecs[i+vnetHdrOff] = unix.Iovec{ Base: &v[0], Len: uint64(len(v)), } @@ -200,7 +199,7 @@ type recvMMsgDispatcher struct { // msgHdrs is an array of MMsgHdr objects where each MMsghdr is used to // reference an array of iovecs in the iovecs field defined above. This // array is passed as the parameter to recvmmsg call to retrieve - // potentially more than 1 packet per syscall. + // potentially more than 1 packet per unix. msgHdrs []rawfile.MMsgHdr } |