Documentation ¶
Overview ¶
Package socket provides the interfaces that need to be provided by socket implementations and providers, as well as per family demultiplexing of socket creation.
Index ¶
- func AddressAndFamily(addr []byte) (tcpip.FullAddress, uint16, *syserr.Error)
- func BytesToIPAddress(addr []byte) tcpip.Address
- func ConvertAddress(family int, addr tcpip.FullAddress) (linux.SockAddr, uint32)
- func GetSockOptEmitUnimplementedEvent(t *kernel.Task, name int)
- func Htons(v uint16) uint16
- func New(t *kernel.Task, family int, stype linux.SockType, protocol int) (*fs.File, *syserr.Error)
- func NewDirent(ctx context.Context, d *device.Device) *fs.Dirent
- func NewVFS2(t *kernel.Task, family int, stype linux.SockType, protocol int) (*vfs.FileDescription, *syserr.Error)
- func Ntohs(v uint16) uint16
- func Pair(t *kernel.Task, family int, stype linux.SockType, protocol int) (*fs.File, *fs.File, *syserr.Error)
- func PairVFS2(t *kernel.Task, family int, stype linux.SockType, protocol int) (*vfs.FileDescription, *vfs.FileDescription, *syserr.Error)
- func RegisterProvider(family int, provider Provider)
- func RegisterProviderVFS2(family int, provider ProviderVFS2)
- func SetSockOptEmitUnimplementedEvent(t *kernel.Task, name int)
- func UnmarshalSockAddr(family int, data []byte) linux.SockAddr
- type ControlMessages
- type IPControlMessages
- type Provider
- type ProviderVFS2
- type SendReceiveTimeout
- func (to *SendReceiveTimeout) RecvTimeout() int64
- func (to *SendReceiveTimeout) SendTimeout() int64
- func (to *SendReceiveTimeout) SetRecvTimeout(nanoseconds int64)
- func (to *SendReceiveTimeout) SetSendTimeout(nanoseconds int64)
- func (to *SendReceiveTimeout) StateFields() []string
- func (to *SendReceiveTimeout) StateLoad(stateSourceObject state.Source)
- func (to *SendReceiveTimeout) StateSave(stateSinkObject state.Sink)
- func (to *SendReceiveTimeout) StateTypeName() string
- type Socket
- type SocketOps
- type SocketVFS2
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddressAndFamily ¶
AddressAndFamily reads an sockaddr struct from the given address and converts it to the FullAddress format. It supports AF_UNIX, AF_INET, AF_INET6, and AF_PACKET addresses.
AddressAndFamily returns an address and its family.
func BytesToIPAddress ¶
BytesToIPAddress converts an IPv4 or IPv6 address from the user to the netstack representation taking any addresses into account.
func ConvertAddress ¶
ConvertAddress converts the given address to a native format.
func GetSockOptEmitUnimplementedEvent ¶
GetSockOptEmitUnimplementedEvent emits unimplemented event if name is valid. It contains names that are valid for GetSockOpt when level is SOL_SOCKET.
func Htons ¶
Htons converts a 16-bit number from host byte order to network byte order. It assumes that the host is little endian.
func NewVFS2 ¶
func NewVFS2(t *kernel.Task, family int, stype linux.SockType, protocol int) (*vfs.FileDescription, *syserr.Error)
NewVFS2 creates a new socket with the given family, type and protocol.
func Ntohs ¶
Ntohs converts a 16-bit number from network byte order to host byte order. It assumes that the host is little endian.
func Pair ¶
func Pair(t *kernel.Task, family int, stype linux.SockType, protocol int) (*fs.File, *fs.File, *syserr.Error)
Pair creates a new connected socket pair with the given family, type and protocol.
func PairVFS2 ¶
func PairVFS2(t *kernel.Task, family int, stype linux.SockType, protocol int) (*vfs.FileDescription, *vfs.FileDescription, *syserr.Error)
PairVFS2 creates a new connected socket pair with the given family, type and protocol.
func RegisterProvider ¶
RegisterProvider registers the provider of a given address family so that sockets of that type can be created via socket() and/or socketpair() syscalls.
This should only be called during the initialization of the address family.
func RegisterProviderVFS2 ¶
func RegisterProviderVFS2(family int, provider ProviderVFS2)
RegisterProviderVFS2 registers the provider of a given address family so that sockets of that type can be created via socket() and/or socketpair() syscalls.
This should only be called during the initialization of the address family.
func SetSockOptEmitUnimplementedEvent ¶
SetSockOptEmitUnimplementedEvent emits unimplemented event if name is valid. It contains names that are valid for SetSockOpt when level is SOL_SOCKET.
Types ¶
type ControlMessages ¶
type ControlMessages struct { Unix transport.ControlMessages IP IPControlMessages }
ControlMessages represents the union of unix control messages and tcpip control messages.
func (*ControlMessages) Release ¶
func (c *ControlMessages) Release(ctx context.Context)
Release releases Unix domain socket credentials and rights.
type IPControlMessages ¶
type IPControlMessages struct { // HasTimestamp indicates whether Timestamp is valid/set. HasTimestamp bool // Timestamp is the time (in ns) that the last packet used to create // the read data was received. Timestamp int64 // HasInq indicates whether Inq is valid/set. HasInq bool // Inq is the number of bytes ready to be received. Inq int32 // HasTOS indicates whether Tos is valid/set. HasTOS bool // TOS is the IPv4 type of service of the associated packet. TOS uint8 // HasTClass indicates whether TClass is valid/set. HasTClass bool // TClass is the IPv6 traffic class of the associated packet. TClass uint32 // HasIPPacketInfo indicates whether PacketInfo is set. HasIPPacketInfo bool // PacketInfo holds interface and address data on an incoming packet. PacketInfo linux.ControlMessageIPPacketInfo // OriginalDestinationAddress holds the original destination address // and port of the incoming packet. OriginalDstAddress linux.SockAddr // SockErr is the dequeued socket error on recvmsg(MSG_ERRQUEUE). SockErr linux.SockErrCMsg }
IPControlMessages contains socket control messages for IP sockets. This can contain Linux specific structures unlike tcpip.ControlMessages.
+stateify savable
func NewIPControlMessages ¶
func NewIPControlMessages(family int, cmgs tcpip.ControlMessages) IPControlMessages
NewIPControlMessages converts the tcpip ControlMessgaes (which does not have Linux specific format) to Linux format.
func (*IPControlMessages) StateFields ¶
func (i *IPControlMessages) StateFields() []string
func (*IPControlMessages) StateLoad ¶
func (i *IPControlMessages) StateLoad(stateSourceObject state.Source)
func (*IPControlMessages) StateSave ¶
func (i *IPControlMessages) StateSave(stateSinkObject state.Sink)
func (*IPControlMessages) StateTypeName ¶
func (i *IPControlMessages) StateTypeName() string
type Provider ¶
type Provider interface { // Socket creates a new socket. // // If a nil Socket _and_ a nil error is returned, it means that the // protocol is not supported. A non-nil error should only be returned // if the protocol is supported, but an error occurs during creation. Socket(t *kernel.Task, stype linux.SockType, protocol int) (*fs.File, *syserr.Error) // Pair creates a pair of connected sockets. // // See Socket for error information. Pair(t *kernel.Task, stype linux.SockType, protocol int) (*fs.File, *fs.File, *syserr.Error) }
Provider is the interface implemented by providers of sockets for specific address families (e.g., AF_INET).
type ProviderVFS2 ¶
type ProviderVFS2 interface { // Socket creates a new socket. // // If a nil Socket _and_ a nil error is returned, it means that the // protocol is not supported. A non-nil error should only be returned // if the protocol is supported, but an error occurs during creation. Socket(t *kernel.Task, stype linux.SockType, protocol int) (*vfs.FileDescription, *syserr.Error) // Pair creates a pair of connected sockets. // // See Socket for error information. Pair(t *kernel.Task, stype linux.SockType, protocol int) (*vfs.FileDescription, *vfs.FileDescription, *syserr.Error) }
ProviderVFS2 is the vfs2 interface implemented by providers of sockets for specific address families (e.g., AF_INET).
type SendReceiveTimeout ¶
type SendReceiveTimeout struct {
// contains filtered or unexported fields
}
SendReceiveTimeout stores timeouts for send and receive calls.
It is meant to be embedded into Socket implementations to help satisfy the interface.
Care must be taken when copying SendReceiveTimeout as it contains atomic variables.
+stateify savable
func (*SendReceiveTimeout) RecvTimeout ¶
func (to *SendReceiveTimeout) RecvTimeout() int64
RecvTimeout implements Socket.RecvTimeout.
func (*SendReceiveTimeout) SendTimeout ¶
func (to *SendReceiveTimeout) SendTimeout() int64
SendTimeout implements Socket.SendTimeout.
func (*SendReceiveTimeout) SetRecvTimeout ¶
func (to *SendReceiveTimeout) SetRecvTimeout(nanoseconds int64)
SetRecvTimeout implements Socket.SetRecvTimeout.
func (*SendReceiveTimeout) SetSendTimeout ¶
func (to *SendReceiveTimeout) SetSendTimeout(nanoseconds int64)
SetSendTimeout implements Socket.SetSendTimeout.
func (*SendReceiveTimeout) StateFields ¶
func (to *SendReceiveTimeout) StateFields() []string
func (*SendReceiveTimeout) StateLoad ¶
func (to *SendReceiveTimeout) StateLoad(stateSourceObject state.Source)
func (*SendReceiveTimeout) StateSave ¶
func (to *SendReceiveTimeout) StateSave(stateSinkObject state.Sink)
func (*SendReceiveTimeout) StateTypeName ¶
func (to *SendReceiveTimeout) StateTypeName() string
type Socket ¶
type Socket interface { fs.FileOperations SocketOps }
Socket is an interface combining fs.FileOperations and SocketOps, representing a VFS1 socket file.
type SocketOps ¶
type SocketOps interface { // Connect implements the connect(2) linux syscall. Connect(t *kernel.Task, sockaddr []byte, blocking bool) *syserr.Error // Accept implements the accept4(2) linux syscall. // Returns fd, real peer address length and error. Real peer address // length is only set if len(peer) > 0. Accept(t *kernel.Task, peerRequested bool, flags int, blocking bool) (int32, linux.SockAddr, uint32, *syserr.Error) // Bind implements the bind(2) linux syscall. Bind(t *kernel.Task, sockaddr []byte) *syserr.Error // Listen implements the listen(2) linux syscall. Listen(t *kernel.Task, backlog int) *syserr.Error // Shutdown implements the shutdown(2) linux syscall. Shutdown(t *kernel.Task, how int) *syserr.Error // GetSockOpt implements the getsockopt(2) linux syscall. GetSockOpt(t *kernel.Task, level int, name int, outPtr usermem.Addr, outLen int) (marshal.Marshallable, *syserr.Error) // SetSockOpt implements the setsockopt(2) linux syscall. SetSockOpt(t *kernel.Task, level int, name int, opt []byte) *syserr.Error // GetSockName implements the getsockname(2) linux syscall. // // addrLen is the address length to be returned to the application, not // necessarily the actual length of the address. GetSockName(t *kernel.Task) (addr linux.SockAddr, addrLen uint32, err *syserr.Error) // GetPeerName implements the getpeername(2) linux syscall. // // addrLen is the address length to be returned to the application, not // necessarily the actual length of the address. GetPeerName(t *kernel.Task) (addr linux.SockAddr, addrLen uint32, err *syserr.Error) // RecvMsg implements the recvmsg(2) linux syscall. // // senderAddrLen is the address length to be returned to the application, // not necessarily the actual length of the address. // // flags control how RecvMsg should be completed. msgFlags indicate how // the RecvMsg call was completed. Note that control message truncation // may still be required even if the MSG_CTRUNC bit is not set in // msgFlags. In that case, the caller should set MSG_CTRUNC appropriately. // // If err != nil, the recv was not successful. 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 ControlMessages, err *syserr.Error) // SendMsg implements the sendmsg(2) linux syscall. SendMsg does not take // ownership of the ControlMessage on error. // // If n > 0, err will either be nil or an error from t.Block. SendMsg(t *kernel.Task, src usermem.IOSequence, to []byte, flags int, haveDeadline bool, deadline ktime.Time, controlMessages ControlMessages) (n int, err *syserr.Error) // SetRecvTimeout sets the timeout (in ns) for recv operations. Zero means // no timeout, and negative means DONTWAIT. SetRecvTimeout(nanoseconds int64) // RecvTimeout gets the current timeout (in ns) for recv operations. Zero // means no timeout, and negative means DONTWAIT. RecvTimeout() int64 // SetSendTimeout sets the timeout (in ns) for send operations. Zero means // no timeout, and negative means DONTWAIT. SetSendTimeout(nanoseconds int64) // SendTimeout gets the current timeout (in ns) for send operations. Zero // means no timeout, and negative means DONTWAIT. SendTimeout() int64 // State returns the current state of the socket, as represented by Linux in // procfs. The returned state value is protocol-specific. State() uint32 // Type returns the family, socket type and protocol of the socket. Type() (family int, skType linux.SockType, protocol int) }
SocketOps is the interface containing socket syscalls used by the syscall layer to redirect them to the appropriate implementation.
It is implemented by both Socket and SocketVFS2.
type SocketVFS2 ¶
type SocketVFS2 interface { vfs.FileDescriptionImpl SocketOps }
SocketVFS2 is an interface combining vfs.FileDescription and SocketOps, representing a VFS2 socket file.
Directories ¶
Path | Synopsis |
---|---|
Package control provides internal representations of socket control messages.
|
Package control provides internal representations of socket control messages. |
Package hostinet implements AF_INET and AF_INET6 sockets using the host's network stack.
|
Package hostinet implements AF_INET and AF_INET6 sockets using the host's network stack. |
Package netfilter helps the sentry interact with netstack's netfilter capabilities.
|
Package netfilter helps the sentry interact with netstack's netfilter capabilities. |
Package netlink provides core functionality for netlink sockets.
|
Package netlink provides core functionality for netlink sockets. |
port
Package port provides port ID allocation for netlink sockets.
|
Package port provides port ID allocation for netlink sockets. |
route
Package route provides a NETLINK_ROUTE socket protocol.
|
Package route provides a NETLINK_ROUTE socket protocol. |
uevent
Package uevent provides a NETLINK_KOBJECT_UEVENT socket protocol.
|
Package uevent provides a NETLINK_KOBJECT_UEVENT socket protocol. |
Package netstack provides an implementation of the socket.Socket interface that is backed by a tcpip.Endpoint.
|
Package netstack provides an implementation of the socket.Socket interface that is backed by a tcpip.Endpoint. |
Package unix provides an implementation of the socket.Socket interface for the AF_UNIX protocol family.
|
Package unix provides an implementation of the socket.Socket interface for the AF_UNIX protocol family. |
transport
Package transport contains the implementation of Unix endpoints.
|
Package transport contains the implementation of Unix endpoints. |