unix

package
v0.0.0-...-ff2c174 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2021 License: Apache-2.0, MIT Imports: 28 Imported by: 0

Documentation

Overview

Package unix provides an implementation of the socket.Socket interface for the AF_UNIX protocol family.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(ctx context.Context, endpoint transport.Endpoint, stype linux.SockType) *fs.File

New creates a new unix socket.

func NewFileDescription

func NewFileDescription(ep transport.Endpoint, stype linux.SockType, flags uint32, mnt *vfs.Mount, d *vfs.Dentry, locks *vfs.FileLocks) (*vfs.FileDescription, error)

NewFileDescription creates and returns a socket file description corresponding to the given mount and dentry.

func NewSockfsFile

func NewSockfsFile(t *kernel.Task, ep transport.Endpoint, stype linux.SockType) (*vfs.FileDescription, *syserr.Error)

NewSockfsFile creates a new socket file in the global sockfs mount and returns a corresponding file description.

func NewWithDirent

func NewWithDirent(ctx context.Context, d *fs.Dirent, ep transport.Endpoint, stype linux.SockType, flags fs.FileFlags) *fs.File

NewWithDirent creates a new unix socket using an existing dirent.

Types

type EndpointReader

type EndpointReader struct {
	Ctx context.Context

	// Endpoint is the transport.Endpoint to read from.
	Endpoint transport.Endpoint

	// Creds indicates if credential control messages are requested.
	Creds bool

	// NumRights is the number of SCM_RIGHTS FDs requested.
	NumRights int

	// Peek indicates that the data should not be consumed from the
	// endpoint.
	Peek bool

	// MsgSize is the size of the message that was read from. For stream
	// sockets, it is the amount read.
	MsgSize int64

	// From, if not nil, will be set with the address read from.
	From *tcpip.FullAddress

	// Control contains the received control messages.
	Control transport.ControlMessages

	// ControlTrunc indicates that SCM_RIGHTS FDs were discarded based on
	// the value of NumRights.
	ControlTrunc bool
}

EndpointReader implements safemem.Reader that reads from a transport.Endpoint.

EndpointReader is not thread-safe.

func (*EndpointReader) ReadToBlocks

func (r *EndpointReader) ReadToBlocks(dsts safemem.BlockSeq) (uint64, error)

ReadToBlocks implements safemem.Reader.ReadToBlocks.

func (*EndpointReader) Truncate

func (r *EndpointReader) Truncate() error

Truncate calls RecvMsg on the endpoint without writing to a destination.

type EndpointWriter

type EndpointWriter struct {
	Ctx context.Context

	// Endpoint is the transport.Endpoint to write to.
	Endpoint transport.Endpoint

	// Control is the control messages to send.
	Control transport.ControlMessages

	// To is the endpoint to send to. May be nil.
	To transport.BoundEndpoint
}

EndpointWriter implements safemem.Writer that writes to a transport.Endpoint.

EndpointWriter is not thread-safe.

func (*EndpointWriter) WriteFromBlocks

func (w *EndpointWriter) WriteFromBlocks(srcs safemem.BlockSeq) (uint64, error)

WriteFromBlocks implements safemem.Writer.WriteFromBlocks.

type SocketOperations

type SocketOperations struct {
	fsutil.FilePipeSeek             `state:"nosave"`
	fsutil.FileNotDirReaddir        `state:"nosave"`
	fsutil.FileNoFsync              `state:"nosave"`
	fsutil.FileNoMMap               `state:"nosave"`
	fsutil.FileNoSplice             `state:"nosave"`
	fsutil.FileNoopFlush            `state:"nosave"`
	fsutil.FileUseInodeUnstableAttr `state:"nosave"`
	// contains filtered or unexported fields
}

SocketOperations is a Unix socket. It is similar to a netstack socket, except it is backed by a transport.Endpoint instead of a tcpip.Endpoint.

+stateify savable

func (*SocketOperations) Accept

func (s *SocketOperations) Accept(t *kernel.Task, peerRequested bool, flags int, blocking bool) (int32, linux.SockAddr, uint32, *syserr.Error)

Accept implements the linux syscall accept(2) for sockets backed by a transport.Endpoint.

func (*SocketOperations) Bind

func (s *SocketOperations) Bind(t *kernel.Task, sockaddr []byte) *syserr.Error

Bind implements the linux syscall bind(2) for unix sockets.

func (*SocketOperations) Connect

func (s *SocketOperations) Connect(t *kernel.Task, sockaddr []byte, blocking bool) *syserr.Error

Connect implements the linux syscall connect(2) for unix sockets.

func (*SocketOperations) ConnectedPasscred

func (s *SocketOperations) ConnectedPasscred() bool

ConnectedPasscred implements transport.Credentialer.ConnectedPasscred.

func (*SocketOperations) DecRef

func (s *SocketOperations) DecRef(ctx context.Context)

DecRef implements RefCounter.DecRef.

func (*SocketOperations) Endpoint

func (s *SocketOperations) Endpoint() transport.Endpoint

Endpoint extracts the transport.Endpoint.

func (*SocketOperations) EventRegister

func (s *SocketOperations) EventRegister(e *waiter.Entry, mask waiter.EventMask)

EventRegister implements waiter.Waitable.EventRegister.

func (*SocketOperations) EventUnregister

func (s *SocketOperations) EventUnregister(e *waiter.Entry)

EventUnregister implements waiter.Waitable.EventUnregister.

func (*SocketOperations) GetPeerName

func (s *SocketOperations) GetPeerName(t *kernel.Task) (linux.SockAddr, uint32, *syserr.Error)

GetPeerName implements the linux syscall getpeername(2) for sockets backed by a transport.Endpoint.

func (*SocketOperations) GetSockName

func (s *SocketOperations) GetSockName(t *kernel.Task) (linux.SockAddr, uint32, *syserr.Error)

GetSockName implements the linux syscall getsockname(2) for sockets backed by a transport.Endpoint.

func (*SocketOperations) GetSockOpt

func (s *SocketOperations) GetSockOpt(t *kernel.Task, level, name int, outPtr hostarch.Addr, outLen int) (marshal.Marshallable, *syserr.Error)

GetSockOpt implements the linux syscall getsockopt(2) for sockets backed by a transport.Endpoint.

func (*SocketOperations) IncRef

func (r *SocketOperations) IncRef()

IncRef implements refs.RefCounter.IncRef.

func (*SocketOperations) InitRefs

func (r *SocketOperations) InitRefs()

InitRefs initializes r with one reference and, if enabled, activates leak checking.

func (*SocketOperations) Ioctl

Ioctl implements fs.FileOperations.Ioctl.

func (*SocketOperations) LeakMessage

func (r *SocketOperations) LeakMessage() string

LeakMessage implements refsvfs2.CheckedObject.LeakMessage.

func (*SocketOperations) Listen

func (s *SocketOperations) Listen(t *kernel.Task, backlog int) *syserr.Error

Listen implements the linux syscall listen(2) for sockets backed by a transport.Endpoint.

func (*SocketOperations) LogRefs

func (r *SocketOperations) LogRefs() bool

LogRefs implements refsvfs2.CheckedObject.LogRefs.

func (*SocketOperations) Passcred

func (s *SocketOperations) Passcred() bool

Passcred implements transport.Credentialer.Passcred.

func (*SocketOperations) Read

func (s *SocketOperations) Read(ctx context.Context, _ *fs.File, dst usermem.IOSequence, _ int64) (int64, error)

Read implements fs.FileOperations.Read.

func (*SocketOperations) ReadRefs

func (r *SocketOperations) ReadRefs() int64

ReadRefs returns the current number of references. The returned count is inherently racy and is unsafe to use without external synchronization.

func (*SocketOperations) Readiness

func (s *SocketOperations) Readiness(mask waiter.EventMask) waiter.EventMask

Readiness implements waiter.Waitable.Readiness.

func (*SocketOperations) RecvMsg

func (s *SocketOperations) RecvMsg(t *kernel.Task, dst usermem.IOSequence, flags int, haveDeadline bool, deadline ktime.Time, senderRequested bool, controlDataLen uint64) (n int, msgFlags int, senderAddr linux.SockAddr, senderAddrLen uint32, controlMessages socket.ControlMessages, err *syserr.Error)

RecvMsg implements the linux syscall recvmsg(2) for sockets backed by a transport.Endpoint.

func (*SocketOperations) RefType

func (r *SocketOperations) RefType() string

RefType implements refsvfs2.CheckedObject.RefType.

func (*SocketOperations) Release

func (s *SocketOperations) Release(ctx context.Context)

Release implemements fs.FileOperations.Release.

func (*SocketOperations) SendMsg

func (s *SocketOperations) SendMsg(t *kernel.Task, src usermem.IOSequence, to []byte, flags int, haveDeadline bool, deadline ktime.Time, controlMessages socket.ControlMessages) (int, *syserr.Error)

SendMsg implements the linux syscall sendmsg(2) for unix sockets backed by a transport.Endpoint.

func (*SocketOperations) SetSockOpt

func (s *SocketOperations) SetSockOpt(t *kernel.Task, level int, name int, optVal []byte) *syserr.Error

SetSockOpt implements the linux syscall setsockopt(2) for sockets backed by a transport.Endpoint.

func (*SocketOperations) Shutdown

func (s *SocketOperations) Shutdown(t *kernel.Task, how int) *syserr.Error

Shutdown implements the linux syscall shutdown(2) for sockets backed by a transport.Endpoint.

func (*SocketOperations) State

func (s *SocketOperations) State() uint32

State implements socket.Socket.State.

func (*SocketOperations) StateFields

func (s *SocketOperations) StateFields() []string

func (*SocketOperations) StateLoad

func (s *SocketOperations) StateLoad(stateSourceObject state.Source)

+checklocksignore

func (*SocketOperations) StateSave

func (s *SocketOperations) StateSave(stateSinkObject state.Sink)

+checklocksignore

func (*SocketOperations) StateTypeName

func (s *SocketOperations) StateTypeName() string

func (*SocketOperations) TryIncRef

func (r *SocketOperations) TryIncRef() bool

TryIncRef implements refs.RefCounter.TryIncRef.

To do this safely without a loop, a speculative reference is first acquired on the object. This allows multiple concurrent TryIncRef calls to distinguish other TryIncRef calls from genuine references held.

func (*SocketOperations) Type

func (s *SocketOperations) Type() (family int, skType linux.SockType, protocol int)

Type implements socket.Socket.Type.

func (*SocketOperations) Write

func (s *SocketOperations) Write(ctx context.Context, _ *fs.File, src usermem.IOSequence, _ int64) (int64, error)

Write implements fs.FileOperations.Write.

type SocketVFS2

type SocketVFS2 struct {
	vfs.FileDescriptionDefaultImpl
	vfs.DentryMetadataFileDescriptionImpl
	vfs.LockFD
	// contains filtered or unexported fields
}

SocketVFS2 implements socket.SocketVFS2 (and by extension, vfs.FileDescriptionImpl) for Unix sockets.

+stateify savable

func (*SocketVFS2) Accept

func (s *SocketVFS2) Accept(t *kernel.Task, peerRequested bool, flags int, blocking bool) (int32, linux.SockAddr, uint32, *syserr.Error)

Accept implements the linux syscall accept(2) for sockets backed by a transport.Endpoint.

func (*SocketVFS2) Bind

func (s *SocketVFS2) Bind(t *kernel.Task, sockaddr []byte) *syserr.Error

Bind implements the linux syscall bind(2) for unix sockets.

func (*SocketVFS2) Connect

func (s *SocketVFS2) Connect(t *kernel.Task, sockaddr []byte, blocking bool) *syserr.Error

Connect implements the linux syscall connect(2) for unix sockets.

func (*SocketVFS2) ConnectedPasscred

func (s *SocketVFS2) ConnectedPasscred() bool

ConnectedPasscred implements transport.Credentialer.ConnectedPasscred.

func (*SocketVFS2) DecRef

func (s *SocketVFS2) DecRef(ctx context.Context)

DecRef implements RefCounter.DecRef.

func (*SocketVFS2) Endpoint

func (s *SocketVFS2) Endpoint() transport.Endpoint

Endpoint extracts the transport.Endpoint.

func (*SocketVFS2) EventRegister

func (s *SocketVFS2) EventRegister(e *waiter.Entry, mask waiter.EventMask)

EventRegister implements waiter.Waitable.EventRegister.

func (*SocketVFS2) EventUnregister

func (s *SocketVFS2) EventUnregister(e *waiter.Entry)

EventUnregister implements waiter.Waitable.EventUnregister.

func (*SocketVFS2) GetPeerName

func (s *SocketVFS2) GetPeerName(t *kernel.Task) (linux.SockAddr, uint32, *syserr.Error)

GetPeerName implements the linux syscall getpeername(2) for sockets backed by a transport.Endpoint.

func (*SocketVFS2) GetSockName

func (s *SocketVFS2) GetSockName(t *kernel.Task) (linux.SockAddr, uint32, *syserr.Error)

GetSockName implements the linux syscall getsockname(2) for sockets backed by a transport.Endpoint.

func (*SocketVFS2) GetSockOpt

func (s *SocketVFS2) GetSockOpt(t *kernel.Task, level, name int, outPtr hostarch.Addr, outLen int) (marshal.Marshallable, *syserr.Error)

GetSockOpt implements the linux syscall getsockopt(2) for sockets backed by a transport.Endpoint.

func (*SocketVFS2) IncRef

func (r *SocketVFS2) IncRef()

IncRef implements refs.RefCounter.IncRef.

func (*SocketVFS2) InitRefs

func (r *SocketVFS2) InitRefs()

InitRefs initializes r with one reference and, if enabled, activates leak checking.

func (*SocketVFS2) Ioctl

func (s *SocketVFS2) Ioctl(ctx context.Context, uio usermem.IO, args arch.SyscallArguments) (uintptr, error)

Ioctl implements vfs.FileDescriptionImpl.

func (*SocketVFS2) LeakMessage

func (r *SocketVFS2) LeakMessage() string

LeakMessage implements refsvfs2.CheckedObject.LeakMessage.

func (*SocketVFS2) Listen

func (s *SocketVFS2) Listen(t *kernel.Task, backlog int) *syserr.Error

Listen implements the linux syscall listen(2) for sockets backed by a transport.Endpoint.

func (*SocketVFS2) LogRefs

func (r *SocketVFS2) LogRefs() bool

LogRefs implements refsvfs2.CheckedObject.LogRefs.

func (*SocketVFS2) PRead

func (s *SocketVFS2) PRead(ctx context.Context, dst usermem.IOSequence, offset int64, opts vfs.ReadOptions) (int64, error)

PRead implements vfs.FileDescriptionImpl.

func (*SocketVFS2) PWrite

func (s *SocketVFS2) PWrite(ctx context.Context, src usermem.IOSequence, offset int64, opts vfs.WriteOptions) (int64, error)

PWrite implements vfs.FileDescriptionImpl.

func (*SocketVFS2) Passcred

func (s *SocketVFS2) Passcred() bool

Passcred implements transport.Credentialer.Passcred.

func (*SocketVFS2) Read

func (s *SocketVFS2) Read(ctx context.Context, dst usermem.IOSequence, opts vfs.ReadOptions) (int64, error)

Read implements vfs.FileDescriptionImpl.

func (*SocketVFS2) ReadRefs

func (r *SocketVFS2) ReadRefs() int64

ReadRefs returns the current number of references. The returned count is inherently racy and is unsafe to use without external synchronization.

func (*SocketVFS2) Readiness

func (s *SocketVFS2) Readiness(mask waiter.EventMask) waiter.EventMask

Readiness implements waiter.Waitable.Readiness.

func (*SocketVFS2) RecvMsg

func (s *SocketVFS2) RecvMsg(t *kernel.Task, dst usermem.IOSequence, flags int, haveDeadline bool, deadline ktime.Time, senderRequested bool, controlDataLen uint64) (n int, msgFlags int, senderAddr linux.SockAddr, senderAddrLen uint32, controlMessages socket.ControlMessages, err *syserr.Error)

RecvMsg implements the linux syscall recvmsg(2) for sockets backed by a transport.Endpoint.

func (*SocketVFS2) RefType

func (r *SocketVFS2) RefType() string

RefType implements refsvfs2.CheckedObject.RefType.

func (*SocketVFS2) Release

func (s *SocketVFS2) Release(ctx context.Context)

Release implements vfs.FileDescriptionImpl.Release.

func (*SocketVFS2) SendMsg

func (s *SocketVFS2) SendMsg(t *kernel.Task, src usermem.IOSequence, to []byte, flags int, haveDeadline bool, deadline ktime.Time, controlMessages socket.ControlMessages) (int, *syserr.Error)

SendMsg implements the linux syscall sendmsg(2) for unix sockets backed by a transport.Endpoint.

func (*SocketVFS2) SetSockOpt

func (s *SocketVFS2) SetSockOpt(t *kernel.Task, level int, name int, optVal []byte) *syserr.Error

SetSockOpt implements the linux syscall setsockopt(2) for sockets backed by a transport.Endpoint.

func (*SocketVFS2) Shutdown

func (s *SocketVFS2) Shutdown(t *kernel.Task, how int) *syserr.Error

Shutdown implements the linux syscall shutdown(2) for sockets backed by a transport.Endpoint.

func (*SocketVFS2) State

func (s *SocketVFS2) State() uint32

State implements socket.Socket.State.

func (*SocketVFS2) StateFields

func (s *SocketVFS2) StateFields() []string

func (*SocketVFS2) StateLoad

func (s *SocketVFS2) StateLoad(stateSourceObject state.Source)

+checklocksignore

func (*SocketVFS2) StateSave

func (s *SocketVFS2) StateSave(stateSinkObject state.Sink)

+checklocksignore

func (*SocketVFS2) StateTypeName

func (s *SocketVFS2) StateTypeName() string

func (*SocketVFS2) TryIncRef

func (r *SocketVFS2) TryIncRef() bool

TryIncRef implements refs.RefCounter.TryIncRef.

To do this safely without a loop, a speculative reference is first acquired on the object. This allows multiple concurrent TryIncRef calls to distinguish other TryIncRef calls from genuine references held.

func (*SocketVFS2) Type

func (s *SocketVFS2) Type() (family int, skType linux.SockType, protocol int)

Type implements socket.Socket.Type.

func (*SocketVFS2) Write

func (s *SocketVFS2) Write(ctx context.Context, src usermem.IOSequence, opts vfs.WriteOptions) (int64, error)

Write implements vfs.FileDescriptionImpl.

Directories

Path Synopsis
Package transport contains the implementation of Unix endpoints.
Package transport contains the implementation of Unix endpoints.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL