Documentation ¶
Overview ¶
Package hostinet implements AF_INET and AF_INET6 sockets using the host's network stack.
Index ¶
- Variables
- type AllowedSocketType
- type SockOpt
- type Socket
- func (s *Socket) Accept(t *kernel.Task, peerRequested bool, flags int, blocking bool) (int32, linux.SockAddr, uint32, *syserr.Error)
- func (s *Socket) Bind(_ *kernel.Task, sockaddr []byte) *syserr.Error
- func (s *Socket) Connect(t *kernel.Task, sockaddr []byte, blocking bool) *syserr.Error
- func (s *Socket) Epollable() bool
- func (s *Socket) EventRegister(e *waiter.Entry) error
- func (s *Socket) EventUnregister(e *waiter.Entry)
- func (s *Socket) GetPeerName(t *kernel.Task) (linux.SockAddr, uint32, *syserr.Error)
- func (s *Socket) GetSockName(t *kernel.Task) (linux.SockAddr, uint32, *syserr.Error)
- func (s *Socket) GetSockOpt(t *kernel.Task, level, name int, optValAddr hostarch.Addr, optLen int) (marshal.Marshallable, *syserr.Error)
- func (s *Socket) Ioctl(ctx context.Context, uio usermem.IO, sysno uintptr, args arch.SyscallArguments) (uintptr, error)
- func (s *Socket) Listen(_ *kernel.Task, backlog int) *syserr.Error
- func (s *Socket) PRead(ctx context.Context, dst usermem.IOSequence, offset int64, ...) (int64, error)
- func (s *Socket) PWrite(ctx context.Context, dst usermem.IOSequence, offset int64, ...) (int64, error)
- func (s *Socket) Read(ctx context.Context, dst usermem.IOSequence, opts vfs.ReadOptions) (int64, error)
- func (s *Socket) Readiness(mask waiter.EventMask) waiter.EventMask
- func (s *Socket) RecvMsg(t *kernel.Task, dst usermem.IOSequence, flags int, haveDeadline bool, ...) (int, int, linux.SockAddr, uint32, socket.ControlMessages, *syserr.Error)
- func (s *Socket) Release(ctx context.Context)
- func (s *Socket) SendMsg(t *kernel.Task, src usermem.IOSequence, to []byte, flags int, ...) (int, *syserr.Error)
- func (s *Socket) SetSockOpt(t *kernel.Task, level, name int, opt []byte) *syserr.Error
- func (s *Socket) Shutdown(_ *kernel.Task, how int) *syserr.Error
- func (s *Socket) State() uint32
- func (s *Socket) StateFields() []string
- func (s *Socket) StateLoad(stateSourceObject state.Source)
- func (s *Socket) StateSave(stateSinkObject state.Sink)
- func (s *Socket) StateTypeName() string
- func (s *Socket) Type() (family int, skType linux.SockType, protocol int)
- func (s *Socket) Write(ctx context.Context, src usermem.IOSequence, opts vfs.WriteOptions) (int64, error)
- type Stack
- func (*Stack) AddInterfaceAddr(idx int32, addr inet.InterfaceAddr) error
- func (*Stack) CleanupEndpoints() []stack.TransportEndpoint
- func (s *Stack) Configure(allowRawSockets bool) error
- func (*Stack) Destroy()
- func (s *Stack) GROTimeout(NICID int32) (time.Duration, error)
- func (s *Stack) InterfaceAddrs() map[int32][]inet.InterfaceAddr
- func (s *Stack) Interfaces() map[int32]inet.Interface
- func (*Stack) Pause()
- func (*Stack) PortRange() (uint16, uint16)
- func (*Stack) RegisteredEndpoints() []stack.TransportEndpoint
- func (*Stack) RemoveInterface(idx int32) error
- func (*Stack) RemoveInterfaceAddr(idx int32, addr inet.InterfaceAddr) error
- func (*Stack) RestoreCleanupEndpoints([]stack.TransportEndpoint)
- func (*Stack) Resume()
- func (s *Stack) RouteTable() []inet.Route
- func (*Stack) SetForwarding(tcpip.NetworkProtocolNumber, bool) error
- func (s *Stack) SetGROTimeout(NICID int32, timeout time.Duration) error
- func (*Stack) SetPortRange(uint16, uint16) error
- func (*Stack) SetTCPReceiveBufferSize(inet.TCPBufferSize) error
- func (*Stack) SetTCPRecovery(inet.TCPLossRecovery) error
- func (*Stack) SetTCPSACKEnabled(bool) error
- func (*Stack) SetTCPSendBufferSize(inet.TCPBufferSize) error
- func (s *Stack) Statistics(stat any, arg string) error
- func (s *Stack) SupportsIPv6() bool
- func (s *Stack) TCPReceiveBufferSize() (inet.TCPBufferSize, error)
- func (s *Stack) TCPRecovery() (inet.TCPLossRecovery, error)
- func (s *Stack) TCPSACKEnabled() (bool, error)
- func (s *Stack) TCPSendBufferSize() (inet.TCPBufferSize, error)
Constants ¶
This section is empty.
Variables ¶
var AllowAllProtocols = -1
AllowAllProtocols indicates that all protocols are allowed by the stack and in the syscall filters.
var AllowedRawSocketTypes = []AllowedSocketType{ {unix.AF_INET, unix.SOCK_RAW, unix.IPPROTO_RAW}, {unix.AF_INET, unix.SOCK_RAW, unix.IPPROTO_TCP}, {unix.AF_INET, unix.SOCK_RAW, unix.IPPROTO_UDP}, {unix.AF_INET, unix.SOCK_RAW, unix.IPPROTO_ICMP}, {unix.AF_INET6, unix.SOCK_RAW, unix.IPPROTO_RAW}, {unix.AF_INET6, unix.SOCK_RAW, unix.IPPROTO_TCP}, {unix.AF_INET6, unix.SOCK_RAW, unix.IPPROTO_UDP}, {unix.AF_INET6, unix.SOCK_RAW, unix.IPPROTO_ICMPV6}, {unix.AF_PACKET, unix.SOCK_DGRAM, AllowAllProtocols}, {unix.AF_PACKET, unix.SOCK_RAW, AllowAllProtocols}, }
AllowedRawSocketTypes are the socket types which are supported by hostinet with raw sockets enabled.
var AllowedSocketTypes = []AllowedSocketType{ {unix.AF_INET, unix.SOCK_STREAM, unix.IPPROTO_TCP}, {unix.AF_INET, unix.SOCK_DGRAM, unix.IPPROTO_UDP}, {unix.AF_INET, unix.SOCK_DGRAM, unix.IPPROTO_ICMP}, {unix.AF_INET6, unix.SOCK_STREAM, unix.IPPROTO_TCP}, {unix.AF_INET6, unix.SOCK_DGRAM, unix.IPPROTO_UDP}, {unix.AF_INET6, unix.SOCK_DGRAM, unix.IPPROTO_ICMPV6}, }
AllowedSocketTypes are the socket types which are supported by hostinet. These are used to validate the arguments to socket(), and also to generate syscall filters.
var SockOpts = []SockOpt{ {linux.SOL_IP, linux.IP_ADD_MEMBERSHIP, 0, false, true}, {linux.SOL_IP, linux.IP_DROP_MEMBERSHIP, 0, false, true}, {linux.SOL_IP, linux.IP_HDRINCL, sizeofInt32, true, true}, {linux.SOL_IP, linux.IP_MULTICAST_IF, uint64(linux.SizeOfInetAddr), true, true}, {linux.SOL_IP, linux.IP_MULTICAST_LOOP, 0, true, true}, {linux.SOL_IP, linux.IP_MULTICAST_TTL, 0, true, true}, {linux.SOL_IP, linux.IP_PKTINFO, sizeofInt32, true, true}, {linux.SOL_IP, linux.IP_RECVERR, sizeofInt32, true, true}, {linux.SOL_IP, linux.IP_RECVORIGDSTADDR, sizeofInt32, true, true}, {linux.SOL_IP, linux.IP_RECVTOS, sizeofInt32, true, true}, {linux.SOL_IP, linux.IP_RECVTTL, sizeofInt32, true, true}, {linux.SOL_IP, linux.IP_TOS, 0, true, true}, {linux.SOL_IP, linux.IP_TTL, sizeofInt32, true, true}, {linux.SOL_IPV6, linux.IPV6_CHECKSUM, sizeofInt32, true, true}, {linux.SOL_IPV6, linux.IPV6_MULTICAST_HOPS, sizeofInt32, true, true}, {linux.SOL_IPV6, linux.IPV6_RECVERR, sizeofInt32, true, true}, {linux.SOL_IPV6, linux.IPV6_RECVHOPLIMIT, sizeofInt32, true, true}, {linux.SOL_IPV6, linux.IPV6_RECVORIGDSTADDR, sizeofInt32, true, true}, {linux.SOL_IPV6, linux.IPV6_RECVPKTINFO, sizeofInt32, true, true}, {linux.SOL_IPV6, linux.IPV6_RECVTCLASS, sizeofInt32, true, true}, {linux.SOL_IPV6, linux.IPV6_TCLASS, sizeofInt32, true, true}, {linux.SOL_IPV6, linux.IPV6_UNICAST_HOPS, sizeofInt32, true, true}, {linux.SOL_IPV6, linux.IPV6_V6ONLY, sizeofInt32, true, true}, {linux.SOL_SOCKET, linux.SO_ACCEPTCONN, sizeofInt32, true, true}, {linux.SOL_SOCKET, linux.SO_BINDTODEVICE, 0, true, true}, {linux.SOL_SOCKET, linux.SO_BROADCAST, sizeofInt32, true, true}, {linux.SOL_SOCKET, linux.SO_ERROR, sizeofInt32, true, false}, {linux.SOL_SOCKET, linux.SO_KEEPALIVE, sizeofInt32, true, true}, {linux.SOL_SOCKET, linux.SO_LINGER, linux.SizeOfLinger, true, true}, {linux.SOL_SOCKET, linux.SO_NO_CHECK, sizeofInt32, true, true}, {linux.SOL_SOCKET, linux.SO_OOBINLINE, sizeofInt32, true, true}, {linux.SOL_SOCKET, linux.SO_PASSCRED, sizeofInt32, true, true}, {linux.SOL_SOCKET, linux.SO_RCVBUF, sizeofInt32, true, true}, {linux.SOL_SOCKET, linux.SO_RCVBUFFORCE, sizeofInt32, false, true}, {linux.SOL_SOCKET, linux.SO_RCVLOWAT, sizeofInt32, true, true}, {linux.SOL_SOCKET, linux.SO_REUSEADDR, sizeofInt32, true, true}, {linux.SOL_SOCKET, linux.SO_REUSEPORT, sizeofInt32, true, true}, {linux.SOL_SOCKET, linux.SO_SNDBUF, sizeofInt32, true, true}, {linux.SOL_SOCKET, linux.SO_TIMESTAMP, sizeofInt32, true, true}, {linux.SOL_TCP, linux.TCP_CONGESTION, 0, true, true}, {linux.SOL_TCP, linux.TCP_CORK, sizeofInt32, true, true}, {linux.SOL_TCP, linux.TCP_DEFER_ACCEPT, sizeofInt32, true, true}, {linux.SOL_TCP, linux.TCP_INFO, uint64(linux.SizeOfTCPInfo), true, false}, {linux.SOL_TCP, linux.TCP_INQ, sizeofInt32, true, true}, {linux.SOL_TCP, linux.TCP_KEEPCNT, sizeofInt32, true, true}, {linux.SOL_TCP, linux.TCP_KEEPIDLE, sizeofInt32, true, true}, {linux.SOL_TCP, linux.TCP_KEEPINTVL, sizeofInt32, true, true}, {linux.SOL_TCP, linux.TCP_LINGER2, sizeofInt32, true, true}, {linux.SOL_TCP, linux.TCP_MAXSEG, sizeofInt32, true, true}, {linux.SOL_TCP, linux.TCP_NODELAY, sizeofInt32, true, true}, {linux.SOL_TCP, linux.TCP_QUICKACK, sizeofInt32, true, true}, {linux.SOL_TCP, linux.TCP_SYNCNT, sizeofInt32, true, true}, {linux.SOL_TCP, linux.TCP_USER_TIMEOUT, sizeofInt32, true, true}, {linux.SOL_TCP, linux.TCP_WINDOW_CLAMP, sizeofInt32, true, true}, {linux.SOL_ICMPV6, linux.ICMPV6_FILTER, uint64(linux.SizeOfICMP6Filter), true, true}, }
SockOpts are the socket options supported by hostinet by making syscalls to the host.
Note the following socket options are supported but do not need syscalls to the host, so do not appear on this list:
- SO_TYPE, SO_PROTOCOL, SO_DOMAIN are handled at the syscall level in syscalls/sys_socket.go.
- SO_SNDTIMEOU, SO_RCVTIMEO are handled internally by setting the embedded socket.SendReceiveTimeout.
Functions ¶
This section is empty.
Types ¶
type AllowedSocketType ¶
type AllowedSocketType struct { Family int Type int // Protocol of AllowAllProtocols indicates that all protocols are // allowed. Protocol int }
AllowedSocketType is a tuple of socket family, type, and protocol.
type SockOpt ¶
type SockOpt struct { // Level the socket option applies to. Level uint64 // Name of the option. Name uint64 // Size of the parameter. A size of 0 indicates that any size is // allowed (used for string or other variable-length types). Size uint64 // Support getsockopt on this option. AllowGet bool // Support setsockopt on this option. AllowSet bool }
SockOpt is used to generate get/setsockopt handlers and filters.
type Socket ¶
type Socket struct { vfs.FileDescriptionDefaultImpl vfs.LockFD // We store metadata for hostinet sockets internally. Technically, we should // access metadata (e.g. through stat, chmod) on the host for correctness, // but this is not very useful for inet socket fds, which do not belong to a // concrete file anyway. vfs.DentryMetadataFileDescriptionImpl socket.SendReceiveTimeout // contains filtered or unexported fields }
Socket implements socket.Socket (and by extension, vfs.FileDescriptionImpl) for host sockets.
+stateify savable
func (*Socket) Accept ¶
func (s *Socket) Accept(t *kernel.Task, peerRequested bool, flags int, blocking bool) (int32, linux.SockAddr, uint32, *syserr.Error)
Accept implements socket.Socket.Accept.
func (*Socket) EventRegister ¶
EventRegister implements waiter.Waitable.EventRegister.
func (*Socket) EventUnregister ¶
EventUnregister implements waiter.Waitable.EventUnregister.
func (*Socket) GetPeerName ¶
GetPeerName implements socket.Socket.GetPeerName.
func (*Socket) GetSockName ¶
GetSockName implements socket.Socket.GetSockName.
func (*Socket) GetSockOpt ¶
func (s *Socket) GetSockOpt(t *kernel.Task, level, name int, optValAddr hostarch.Addr, optLen int) (marshal.Marshallable, *syserr.Error)
GetSockOpt implements socket.Socket.GetSockOpt.
func (*Socket) Ioctl ¶
func (s *Socket) Ioctl(ctx context.Context, uio usermem.IO, sysno uintptr, args arch.SyscallArguments) (uintptr, error)
Ioctl implements vfs.FileDescriptionImpl.
func (*Socket) PRead ¶
func (s *Socket) PRead(ctx context.Context, dst usermem.IOSequence, offset int64, opts vfs.ReadOptions) (int64, error)
PRead implements vfs.FileDescriptionImpl.PRead.
func (*Socket) PWrite ¶
func (s *Socket) PWrite(ctx context.Context, dst usermem.IOSequence, offset int64, opts vfs.WriteOptions) (int64, error)
PWrite implements vfs.FileDescriptionImpl.
func (*Socket) Read ¶
func (s *Socket) Read(ctx context.Context, dst usermem.IOSequence, opts vfs.ReadOptions) (int64, error)
Read implements vfs.FileDescriptionImpl.
func (*Socket) RecvMsg ¶
func (s *Socket) RecvMsg(t *kernel.Task, dst usermem.IOSequence, flags int, haveDeadline bool, deadline ktime.Time, senderRequested bool, controlLen uint64) (int, int, linux.SockAddr, uint32, socket.ControlMessages, *syserr.Error)
RecvMsg implements socket.Socket.RecvMsg.
func (*Socket) SendMsg ¶
func (s *Socket) SendMsg(t *kernel.Task, src usermem.IOSequence, to []byte, flags int, haveDeadline bool, deadline ktime.Time, controlMessages socket.ControlMessages) (int, *syserr.Error)
SendMsg implements socket.Socket.SendMsg.
func (*Socket) SetSockOpt ¶
SetSockOpt implements socket.Socket.SetSockOpt.
func (*Socket) StateFields ¶
func (*Socket) StateTypeName ¶
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack implements inet.Stack for host sockets.
func (*Stack) AddInterfaceAddr ¶
func (*Stack) AddInterfaceAddr(idx int32, addr inet.InterfaceAddr) error
AddInterfaceAddr implements inet.Stack.AddInterfaceAddr.
func (*Stack) CleanupEndpoints ¶
func (*Stack) CleanupEndpoints() []stack.TransportEndpoint
CleanupEndpoints implements inet.Stack.CleanupEndpoints.
func (*Stack) GROTimeout ¶
GROTimeout implements inet.Stack.GROTimeout.
func (*Stack) InterfaceAddrs ¶
func (s *Stack) InterfaceAddrs() map[int32][]inet.InterfaceAddr
InterfaceAddrs implements inet.Stack.InterfaceAddrs.
func (*Stack) Interfaces ¶
Interfaces implements inet.Stack.Interfaces.
func (*Stack) RegisteredEndpoints ¶
func (*Stack) RegisteredEndpoints() []stack.TransportEndpoint
RegisteredEndpoints implements inet.Stack.RegisteredEndpoints.
func (*Stack) RemoveInterface ¶
RemoveInterface implements inet.Stack.RemoveInterface.
func (*Stack) RemoveInterfaceAddr ¶
func (*Stack) RemoveInterfaceAddr(idx int32, addr inet.InterfaceAddr) error
RemoveInterfaceAddr implements inet.Stack.RemoveInterfaceAddr.
func (*Stack) RestoreCleanupEndpoints ¶
func (*Stack) RestoreCleanupEndpoints([]stack.TransportEndpoint)
RestoreCleanupEndpoints implements inet.Stack.RestoreCleanupEndpoints.
func (*Stack) RouteTable ¶
RouteTable implements inet.Stack.RouteTable.
func (*Stack) SetForwarding ¶
func (*Stack) SetForwarding(tcpip.NetworkProtocolNumber, bool) error
SetForwarding implements inet.Stack.SetForwarding.
func (*Stack) SetGROTimeout ¶
SetGROTimeout implements inet.Stack.SetGROTimeout.
func (*Stack) SetPortRange ¶
SetPortRange implements inet.Stack.SetPortRange.
func (*Stack) SetTCPReceiveBufferSize ¶
func (*Stack) SetTCPReceiveBufferSize(inet.TCPBufferSize) error
SetTCPReceiveBufferSize implements inet.Stack.SetTCPReceiveBufferSize.
func (*Stack) SetTCPRecovery ¶
func (*Stack) SetTCPRecovery(inet.TCPLossRecovery) error
SetTCPRecovery implements inet.Stack.SetTCPRecovery.
func (*Stack) SetTCPSACKEnabled ¶
SetTCPSACKEnabled implements inet.Stack.SetTCPSACKEnabled.
func (*Stack) SetTCPSendBufferSize ¶
func (*Stack) SetTCPSendBufferSize(inet.TCPBufferSize) error
SetTCPSendBufferSize implements inet.Stack.SetTCPSendBufferSize.
func (*Stack) Statistics ¶
Statistics implements inet.Stack.Statistics.
func (*Stack) SupportsIPv6 ¶
SupportsIPv6 implements inet.Stack.SupportsIPv6.
func (*Stack) TCPReceiveBufferSize ¶
func (s *Stack) TCPReceiveBufferSize() (inet.TCPBufferSize, error)
TCPReceiveBufferSize implements inet.Stack.TCPReceiveBufferSize.
func (*Stack) TCPRecovery ¶
func (s *Stack) TCPRecovery() (inet.TCPLossRecovery, error)
TCPRecovery implements inet.Stack.TCPRecovery.
func (*Stack) TCPSACKEnabled ¶
TCPSACKEnabled implements inet.Stack.TCPSACKEnabled.
func (*Stack) TCPSendBufferSize ¶
func (s *Stack) TCPSendBufferSize() (inet.TCPBufferSize, error)
TCPSendBufferSize implements inet.Stack.TCPSendBufferSize.