2018-04-27 17:37:02 +00:00
|
|
|
// Copyright 2018 Google Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package host
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"gvisor.googlesource.com/gvisor/pkg/fd"
|
2018-10-10 21:09:24 +00:00
|
|
|
"gvisor.googlesource.com/gvisor/pkg/log"
|
2018-04-27 17:37:02 +00:00
|
|
|
"gvisor.googlesource.com/gvisor/pkg/refs"
|
|
|
|
"gvisor.googlesource.com/gvisor/pkg/sentry/context"
|
|
|
|
"gvisor.googlesource.com/gvisor/pkg/sentry/fs"
|
|
|
|
"gvisor.googlesource.com/gvisor/pkg/sentry/socket/control"
|
|
|
|
unixsocket "gvisor.googlesource.com/gvisor/pkg/sentry/socket/unix"
|
2018-10-16 00:47:24 +00:00
|
|
|
"gvisor.googlesource.com/gvisor/pkg/sentry/uniqueid"
|
|
|
|
"gvisor.googlesource.com/gvisor/pkg/syserr"
|
2018-04-27 17:37:02 +00:00
|
|
|
"gvisor.googlesource.com/gvisor/pkg/syserror"
|
|
|
|
"gvisor.googlesource.com/gvisor/pkg/tcpip"
|
|
|
|
"gvisor.googlesource.com/gvisor/pkg/tcpip/link/rawfile"
|
|
|
|
"gvisor.googlesource.com/gvisor/pkg/tcpip/transport/unix"
|
|
|
|
"gvisor.googlesource.com/gvisor/pkg/unet"
|
|
|
|
"gvisor.googlesource.com/gvisor/pkg/waiter"
|
|
|
|
"gvisor.googlesource.com/gvisor/pkg/waiter/fdnotifier"
|
|
|
|
)
|
|
|
|
|
2018-10-10 21:09:24 +00:00
|
|
|
// maxSendBufferSize is the maximum host send buffer size allowed for endpoint.
|
|
|
|
//
|
|
|
|
// N.B. 8MB is the default maximum on Linux (2 * sysctl_wmem_max).
|
|
|
|
const maxSendBufferSize = 8 << 20
|
|
|
|
|
2018-04-27 17:37:02 +00:00
|
|
|
// newSocket allocates a new unix socket with host endpoint.
|
2018-10-16 00:47:24 +00:00
|
|
|
func newSocket(ctx context.Context, orgfd int, saveable bool) (*fs.File, error) {
|
|
|
|
ownedfd := orgfd
|
2018-04-27 17:37:02 +00:00
|
|
|
srfd := -1
|
|
|
|
if saveable {
|
|
|
|
var err error
|
2018-10-16 00:47:24 +00:00
|
|
|
ownedfd, err = syscall.Dup(orgfd)
|
2018-04-27 17:37:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-10-16 00:47:24 +00:00
|
|
|
srfd = orgfd
|
2018-04-27 17:37:02 +00:00
|
|
|
}
|
2018-10-16 00:47:24 +00:00
|
|
|
f := fd.New(ownedfd)
|
|
|
|
var q waiter.Queue
|
|
|
|
e, err := NewConnectedEndpoint(f, &q, "" /* path */)
|
2018-04-27 17:37:02 +00:00
|
|
|
if err != nil {
|
|
|
|
if saveable {
|
2018-10-16 00:47:24 +00:00
|
|
|
f.Close()
|
|
|
|
} else {
|
|
|
|
f.Release()
|
2018-04-27 17:37:02 +00:00
|
|
|
}
|
2018-10-16 00:47:24 +00:00
|
|
|
return nil, syserr.TranslateNetstackError(err).ToError()
|
2018-04-27 17:37:02 +00:00
|
|
|
}
|
2018-10-16 00:47:24 +00:00
|
|
|
|
|
|
|
e.srfd = srfd
|
|
|
|
e.Init()
|
|
|
|
|
|
|
|
ep := unix.NewExternal(e.stype, uniqueid.GlobalProviderFromContext(ctx), &q, e, e)
|
|
|
|
|
2018-04-27 17:37:02 +00:00
|
|
|
return unixsocket.New(ctx, ep), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewSocketWithDirent allocates a new unix socket with host endpoint.
|
|
|
|
//
|
|
|
|
// This is currently only used by unsaveable Gofer nodes.
|
|
|
|
//
|
|
|
|
// NewSocketWithDirent takes ownership of f on success.
|
|
|
|
func NewSocketWithDirent(ctx context.Context, d *fs.Dirent, f *fd.FD, flags fs.FileFlags) (*fs.File, error) {
|
2018-10-16 00:47:24 +00:00
|
|
|
f2 := fd.New(f.FD())
|
|
|
|
var q waiter.Queue
|
|
|
|
e, err := NewConnectedEndpoint(f2, &q, "" /* path */)
|
2018-04-27 17:37:02 +00:00
|
|
|
if err != nil {
|
2018-10-16 00:47:24 +00:00
|
|
|
f2.Release()
|
|
|
|
return nil, syserr.TranslateNetstackError(err).ToError()
|
2018-04-27 17:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Take ownship of the FD.
|
|
|
|
f.Release()
|
|
|
|
|
2018-10-16 00:47:24 +00:00
|
|
|
e.Init()
|
2018-04-27 17:37:02 +00:00
|
|
|
|
2018-10-16 00:47:24 +00:00
|
|
|
ep := unix.NewExternal(e.stype, uniqueid.GlobalProviderFromContext(ctx), &q, e, e)
|
2018-10-10 21:09:24 +00:00
|
|
|
|
2018-10-16 00:47:24 +00:00
|
|
|
return unixsocket.NewWithDirent(ctx, d, ep, flags), nil
|
2018-04-27 17:37:02 +00:00
|
|
|
}
|
|
|
|
|
2018-10-10 21:09:24 +00:00
|
|
|
func sendMsg(fd int, data [][]byte, controlMessages unix.ControlMessages, maxlen int, truncate bool) (uintptr, *tcpip.Error) {
|
2018-04-27 17:37:02 +00:00
|
|
|
if !controlMessages.Empty() {
|
|
|
|
return 0, tcpip.ErrInvalidEndpointState
|
|
|
|
}
|
2018-10-10 21:09:24 +00:00
|
|
|
n, totalLen, err := fdWriteVec(fd, data, maxlen, truncate)
|
|
|
|
if n < totalLen && err == nil {
|
|
|
|
// The host only returns a short write if it would otherwise
|
|
|
|
// block (and only for stream sockets).
|
|
|
|
err = syserror.EAGAIN
|
|
|
|
}
|
2018-04-27 17:37:02 +00:00
|
|
|
return n, translateError(err)
|
|
|
|
}
|
|
|
|
|
2018-10-10 21:09:24 +00:00
|
|
|
func recvMsg(fd int, data [][]byte, numRights uintptr, peek bool, addr *tcpip.FullAddress, maxlen int) (uintptr, uintptr, unix.ControlMessages, *tcpip.Error) {
|
2018-04-27 17:37:02 +00:00
|
|
|
var cm unet.ControlMessage
|
|
|
|
if numRights > 0 {
|
|
|
|
cm.EnableFDs(int(numRights))
|
|
|
|
}
|
2018-10-10 21:09:24 +00:00
|
|
|
rl, ml, cl, rerr := fdReadVec(fd, data, []byte(cm), peek, maxlen)
|
|
|
|
if rl == 0 && rerr != nil {
|
|
|
|
return 0, 0, unix.ControlMessages{}, translateError(rerr)
|
2018-04-27 17:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Trim the control data if we received less than the full amount.
|
|
|
|
if cl < uint64(len(cm)) {
|
|
|
|
cm = cm[:cl]
|
|
|
|
}
|
|
|
|
|
|
|
|
// Avoid extra allocations in the case where there isn't any control data.
|
|
|
|
if len(cm) == 0 {
|
2018-10-10 21:09:24 +00:00
|
|
|
return rl, ml, unix.ControlMessages{}, translateError(rerr)
|
2018-04-27 17:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fds, err := cm.ExtractFDs()
|
|
|
|
if err != nil {
|
|
|
|
return 0, 0, unix.ControlMessages{}, translateError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(fds) == 0 {
|
2018-10-10 21:09:24 +00:00
|
|
|
return rl, ml, unix.ControlMessages{}, translateError(rerr)
|
2018-04-27 17:37:02 +00:00
|
|
|
}
|
2018-10-10 21:09:24 +00:00
|
|
|
return rl, ml, control.New(nil, nil, newSCMRights(fds)), translateError(rerr)
|
2018-04-27 17:37:02 +00:00
|
|
|
}
|
|
|
|
|
2018-09-28 18:02:11 +00:00
|
|
|
// NewConnectedEndpoint creates a new ConnectedEndpoint backed by a host FD
|
|
|
|
// that will pretend to be bound at a given sentry path.
|
2018-05-16 20:06:23 +00:00
|
|
|
//
|
2018-09-28 18:02:11 +00:00
|
|
|
// The caller is responsible for calling Init(). Additionaly, Release needs to
|
|
|
|
// be called twice because host.ConnectedEndpoint is both a unix.Receiver and
|
|
|
|
// unix.ConnectedEndpoint.
|
2018-05-16 20:06:23 +00:00
|
|
|
func NewConnectedEndpoint(file *fd.FD, queue *waiter.Queue, path string) (*ConnectedEndpoint, *tcpip.Error) {
|
2018-10-16 00:47:24 +00:00
|
|
|
e := ConnectedEndpoint{
|
|
|
|
path: path,
|
|
|
|
queue: queue,
|
|
|
|
file: file,
|
|
|
|
srfd: -1,
|
2018-10-10 21:09:24 +00:00
|
|
|
}
|
|
|
|
|
2018-10-16 00:47:24 +00:00
|
|
|
if err := e.init(); err != nil {
|
|
|
|
return nil, err
|
2018-10-10 21:09:24 +00:00
|
|
|
}
|
2018-04-27 17:37:02 +00:00
|
|
|
|
|
|
|
// AtomicRefCounters start off with a single reference. We need two.
|
|
|
|
e.ref.IncRef()
|
|
|
|
|
2018-10-16 00:47:24 +00:00
|
|
|
return &e, nil
|
2018-05-16 20:06:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Init will do initialization required without holding other locks.
|
|
|
|
func (c *ConnectedEndpoint) Init() {
|
|
|
|
if err := fdnotifier.AddFD(int32(c.file.FD()), c.queue); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2018-04-27 17:37:02 +00:00
|
|
|
}
|
|
|
|
|
2018-05-16 20:06:23 +00:00
|
|
|
// ConnectedEndpoint is a host FD backed implementation of
|
2018-04-27 17:37:02 +00:00
|
|
|
// unix.ConnectedEndpoint and unix.Receiver.
|
|
|
|
//
|
2018-10-16 00:47:24 +00:00
|
|
|
// +stateify savable
|
2018-05-16 20:06:23 +00:00
|
|
|
type ConnectedEndpoint struct {
|
2018-04-27 17:37:02 +00:00
|
|
|
queue *waiter.Queue
|
|
|
|
path string
|
|
|
|
|
|
|
|
// ref keeps track of references to a connectedEndpoint.
|
|
|
|
ref refs.AtomicRefCount
|
|
|
|
|
|
|
|
// mu protects fd, readClosed and writeClosed.
|
2018-10-16 00:47:24 +00:00
|
|
|
mu sync.RWMutex `state:"nosave"`
|
2018-04-27 17:37:02 +00:00
|
|
|
|
|
|
|
// file is an *fd.FD containing the FD backing this endpoint. It must be
|
|
|
|
// set to nil if it has been closed.
|
2018-10-16 00:47:24 +00:00
|
|
|
file *fd.FD `state:"nosave"`
|
2018-04-27 17:37:02 +00:00
|
|
|
|
|
|
|
// readClosed is true if the FD has read shutdown or if it has been closed.
|
|
|
|
readClosed bool
|
|
|
|
|
|
|
|
// writeClosed is true if the FD has write shutdown or if it has been
|
|
|
|
// closed.
|
|
|
|
writeClosed bool
|
2018-10-10 21:09:24 +00:00
|
|
|
|
2018-10-16 00:47:24 +00:00
|
|
|
// If srfd >= 0, it is the host FD that file was imported from.
|
|
|
|
srfd int `state:"wait"`
|
|
|
|
|
2018-10-10 21:09:24 +00:00
|
|
|
// stype is the type of Unix socket.
|
|
|
|
stype unix.SockType
|
|
|
|
|
|
|
|
// sndbuf is the size of the send buffer.
|
|
|
|
//
|
|
|
|
// N.B. When this is smaller than the host size, we present it via
|
|
|
|
// GetSockOpt and message splitting/rejection in SendMsg, but do not
|
|
|
|
// prevent lots of small messages from filling the real send buffer
|
|
|
|
// size on the host.
|
2018-10-16 00:47:24 +00:00
|
|
|
sndbuf int `state:"nosave"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// init performs initialization required for creating new ConnectedEndpoints and
|
|
|
|
// for restoring them.
|
|
|
|
func (c *ConnectedEndpoint) init() *tcpip.Error {
|
|
|
|
family, err := syscall.GetsockoptInt(c.file.FD(), syscall.SOL_SOCKET, syscall.SO_DOMAIN)
|
|
|
|
if err != nil {
|
|
|
|
return translateError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if family != syscall.AF_UNIX {
|
|
|
|
// We only allow Unix sockets.
|
|
|
|
return tcpip.ErrInvalidEndpointState
|
|
|
|
}
|
|
|
|
|
|
|
|
stype, err := syscall.GetsockoptInt(c.file.FD(), syscall.SOL_SOCKET, syscall.SO_TYPE)
|
|
|
|
if err != nil {
|
|
|
|
return translateError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := syscall.SetNonblock(c.file.FD(), true); err != nil {
|
|
|
|
return translateError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
sndbuf, err := syscall.GetsockoptInt(c.file.FD(), syscall.SOL_SOCKET, syscall.SO_SNDBUF)
|
|
|
|
if err != nil {
|
|
|
|
return translateError(err)
|
|
|
|
}
|
|
|
|
if sndbuf > maxSendBufferSize {
|
|
|
|
log.Warningf("Socket send buffer too large: %d", sndbuf)
|
|
|
|
return tcpip.ErrInvalidEndpointState
|
|
|
|
}
|
|
|
|
|
|
|
|
c.stype = unix.SockType(stype)
|
|
|
|
c.sndbuf = sndbuf
|
|
|
|
|
|
|
|
return nil
|
2018-04-27 17:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Send implements unix.ConnectedEndpoint.Send.
|
2018-05-16 20:06:23 +00:00
|
|
|
func (c *ConnectedEndpoint) Send(data [][]byte, controlMessages unix.ControlMessages, from tcpip.FullAddress) (uintptr, bool, *tcpip.Error) {
|
2018-04-27 17:37:02 +00:00
|
|
|
c.mu.RLock()
|
|
|
|
defer c.mu.RUnlock()
|
|
|
|
if c.writeClosed {
|
|
|
|
return 0, false, tcpip.ErrClosedForSend
|
|
|
|
}
|
2018-10-10 21:09:24 +00:00
|
|
|
|
|
|
|
// Since stream sockets don't preserve message boundaries, we can write
|
|
|
|
// only as much of the message as fits in the send buffer.
|
|
|
|
truncate := c.stype == unix.SockStream
|
|
|
|
|
|
|
|
n, err := sendMsg(c.file.FD(), data, controlMessages, c.sndbuf, truncate)
|
2018-04-27 17:37:02 +00:00
|
|
|
// There is no need for the callee to call SendNotify because sendMsg uses
|
|
|
|
// the host's sendmsg(2) and the host kernel's queue.
|
|
|
|
return n, false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// SendNotify implements unix.ConnectedEndpoint.SendNotify.
|
2018-05-16 20:06:23 +00:00
|
|
|
func (c *ConnectedEndpoint) SendNotify() {}
|
2018-04-27 17:37:02 +00:00
|
|
|
|
|
|
|
// CloseSend implements unix.ConnectedEndpoint.CloseSend.
|
2018-05-16 20:06:23 +00:00
|
|
|
func (c *ConnectedEndpoint) CloseSend() {
|
2018-04-27 17:37:02 +00:00
|
|
|
c.mu.Lock()
|
|
|
|
c.writeClosed = true
|
|
|
|
c.mu.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
// CloseNotify implements unix.ConnectedEndpoint.CloseNotify.
|
2018-05-16 20:06:23 +00:00
|
|
|
func (c *ConnectedEndpoint) CloseNotify() {}
|
2018-04-27 17:37:02 +00:00
|
|
|
|
|
|
|
// Writable implements unix.ConnectedEndpoint.Writable.
|
2018-05-16 20:06:23 +00:00
|
|
|
func (c *ConnectedEndpoint) Writable() bool {
|
2018-04-27 17:37:02 +00:00
|
|
|
c.mu.RLock()
|
|
|
|
defer c.mu.RUnlock()
|
|
|
|
if c.writeClosed {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return fdnotifier.NonBlockingPoll(int32(c.file.FD()), waiter.EventOut)&waiter.EventOut != 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// Passcred implements unix.ConnectedEndpoint.Passcred.
|
2018-05-16 20:06:23 +00:00
|
|
|
func (c *ConnectedEndpoint) Passcred() bool {
|
2018-04-27 17:37:02 +00:00
|
|
|
// We don't support credential passing for host sockets.
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetLocalAddress implements unix.ConnectedEndpoint.GetLocalAddress.
|
2018-05-16 20:06:23 +00:00
|
|
|
func (c *ConnectedEndpoint) GetLocalAddress() (tcpip.FullAddress, *tcpip.Error) {
|
2018-04-27 17:37:02 +00:00
|
|
|
return tcpip.FullAddress{Addr: tcpip.Address(c.path)}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// EventUpdate implements unix.ConnectedEndpoint.EventUpdate.
|
2018-05-16 20:06:23 +00:00
|
|
|
func (c *ConnectedEndpoint) EventUpdate() {
|
2018-04-27 17:37:02 +00:00
|
|
|
c.mu.RLock()
|
|
|
|
defer c.mu.RUnlock()
|
|
|
|
if c.file.FD() != -1 {
|
|
|
|
fdnotifier.UpdateFD(int32(c.file.FD()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recv implements unix.Receiver.Recv.
|
2018-05-16 20:06:23 +00:00
|
|
|
func (c *ConnectedEndpoint) Recv(data [][]byte, creds bool, numRights uintptr, peek bool) (uintptr, uintptr, unix.ControlMessages, tcpip.FullAddress, bool, *tcpip.Error) {
|
2018-04-27 17:37:02 +00:00
|
|
|
c.mu.RLock()
|
|
|
|
defer c.mu.RUnlock()
|
|
|
|
if c.readClosed {
|
|
|
|
return 0, 0, unix.ControlMessages{}, tcpip.FullAddress{}, false, tcpip.ErrClosedForReceive
|
|
|
|
}
|
2018-10-10 21:09:24 +00:00
|
|
|
|
|
|
|
// N.B. Unix sockets don't have a receive buffer, the send buffer
|
|
|
|
// serves both purposes.
|
|
|
|
rl, ml, cm, err := recvMsg(c.file.FD(), data, numRights, peek, nil, c.sndbuf)
|
|
|
|
if rl > 0 && err == tcpip.ErrWouldBlock {
|
|
|
|
// Message did not fill buffer; that's fine, no need to block.
|
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
|
2018-04-27 17:37:02 +00:00
|
|
|
// There is no need for the callee to call RecvNotify because recvMsg uses
|
|
|
|
// the host's recvmsg(2) and the host kernel's queue.
|
|
|
|
return rl, ml, cm, tcpip.FullAddress{Addr: tcpip.Address(c.path)}, false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// close releases all resources related to the endpoint.
|
2018-05-16 20:06:23 +00:00
|
|
|
func (c *ConnectedEndpoint) close() {
|
2018-04-27 17:37:02 +00:00
|
|
|
fdnotifier.RemoveFD(int32(c.file.FD()))
|
|
|
|
c.file.Close()
|
|
|
|
c.file = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// RecvNotify implements unix.Receiver.RecvNotify.
|
2018-05-16 20:06:23 +00:00
|
|
|
func (c *ConnectedEndpoint) RecvNotify() {}
|
2018-04-27 17:37:02 +00:00
|
|
|
|
|
|
|
// CloseRecv implements unix.Receiver.CloseRecv.
|
2018-05-16 20:06:23 +00:00
|
|
|
func (c *ConnectedEndpoint) CloseRecv() {
|
2018-04-27 17:37:02 +00:00
|
|
|
c.mu.Lock()
|
|
|
|
c.readClosed = true
|
|
|
|
c.mu.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Readable implements unix.Receiver.Readable.
|
2018-05-16 20:06:23 +00:00
|
|
|
func (c *ConnectedEndpoint) Readable() bool {
|
2018-04-27 17:37:02 +00:00
|
|
|
c.mu.RLock()
|
|
|
|
defer c.mu.RUnlock()
|
|
|
|
if c.readClosed {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return fdnotifier.NonBlockingPoll(int32(c.file.FD()), waiter.EventIn)&waiter.EventIn != 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// SendQueuedSize implements unix.Receiver.SendQueuedSize.
|
2018-05-16 20:06:23 +00:00
|
|
|
func (c *ConnectedEndpoint) SendQueuedSize() int64 {
|
2018-04-27 17:37:02 +00:00
|
|
|
// SendQueuedSize isn't supported for host sockets because we don't allow the
|
|
|
|
// sentry to call ioctl(2).
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
// RecvQueuedSize implements unix.Receiver.RecvQueuedSize.
|
2018-05-16 20:06:23 +00:00
|
|
|
func (c *ConnectedEndpoint) RecvQueuedSize() int64 {
|
2018-04-27 17:37:02 +00:00
|
|
|
// RecvQueuedSize isn't supported for host sockets because we don't allow the
|
|
|
|
// sentry to call ioctl(2).
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
// SendMaxQueueSize implements unix.Receiver.SendMaxQueueSize.
|
2018-05-16 20:06:23 +00:00
|
|
|
func (c *ConnectedEndpoint) SendMaxQueueSize() int64 {
|
2018-10-10 21:09:24 +00:00
|
|
|
return int64(c.sndbuf)
|
2018-04-27 17:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RecvMaxQueueSize implements unix.Receiver.RecvMaxQueueSize.
|
2018-05-16 20:06:23 +00:00
|
|
|
func (c *ConnectedEndpoint) RecvMaxQueueSize() int64 {
|
2018-10-10 21:09:24 +00:00
|
|
|
// N.B. Unix sockets don't use the receive buffer. We'll claim it is
|
|
|
|
// the same size as the send buffer.
|
|
|
|
return int64(c.sndbuf)
|
2018-04-27 17:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Release implements unix.ConnectedEndpoint.Release and unix.Receiver.Release.
|
2018-05-16 20:06:23 +00:00
|
|
|
func (c *ConnectedEndpoint) Release() {
|
2018-04-27 17:37:02 +00:00
|
|
|
c.ref.DecRefWithDestructor(c.close)
|
|
|
|
}
|
|
|
|
|
|
|
|
func translateError(err error) *tcpip.Error {
|
|
|
|
if err == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return rawfile.TranslateErrno(err.(syscall.Errno))
|
|
|
|
}
|