hostinet

package
v0.0.0-...-c27c9a0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: Apache-2.0, MIT Imports: 40 Imported by: 4

Documentation

Overview

Package hostinet implements AF_INET and AF_INET6 sockets using the host's network stack.

Index

Constants

This section is empty.

Variables

View Source
var AllowAllProtocols = -1

AllowAllProtocols indicates that all protocols are allowed by the stack and in the syscall filters.

AllowedRawSocketTypes are the socket types which are supported by hostinet with raw sockets enabled.

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.

View Source
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, 0, 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_MTU_DISCOVER, 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) Bind

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

Bind implements socket.Socket.Bind.

func (*Socket) Connect

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

Connect implements socket.Socket.Connect.

func (*Socket) Epollable

func (s *Socket) Epollable() bool

Epollable implements FileDescriptionImpl.Epollable.

func (*Socket) EventRegister

func (s *Socket) EventRegister(e *waiter.Entry) error

EventRegister implements waiter.Waitable.EventRegister.

func (*Socket) EventUnregister

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

EventUnregister implements waiter.Waitable.EventUnregister.

func (*Socket) GetPeerName

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

GetPeerName implements socket.Socket.GetPeerName.

func (*Socket) GetSockName

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

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) Listen

func (s *Socket) Listen(_ *kernel.Task, backlog int) *syserr.Error

Listen implements socket.Socket.Listen.

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) Readiness

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

Readiness implements waiter.Waitable.Readiness.

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) Release

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

Release implements vfs.FileDescriptionImpl.Release.

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

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

SetSockOpt implements socket.Socket.SetSockOpt.

func (*Socket) Shutdown

func (s *Socket) Shutdown(_ *kernel.Task, how int) *syserr.Error

Shutdown implements socket.Socket.Shutdown.

func (*Socket) State

func (s *Socket) State() uint32

State implements socket.Socket.State.

func (*Socket) Type

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

Type implements socket.Socket.Type.

func (*Socket) Write

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

Write implements vfs.FileDescriptionImpl.

type Stack

type Stack struct {
	// contains filtered or unexported fields
}

Stack implements inet.Stack for host sockets.

func NewStack

func NewStack() *Stack

NewStack returns an empty Stack containing no configuration.

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) Configure

func (s *Stack) Configure(allowRawSockets bool) error

Configure sets up the stack using the current state of the host network.

func (*Stack) Destroy

func (*Stack) Destroy()

Destroy implements inet.Stack.Destroy.

func (*Stack) EnableSaveRestore

func (*Stack) EnableSaveRestore() error

EnableSaveRestore implements inet.Stack.EnableSaveRestore.

func (*Stack) InterfaceAddrs

func (s *Stack) InterfaceAddrs() map[int32][]inet.InterfaceAddr

InterfaceAddrs implements inet.Stack.InterfaceAddrs.

func (*Stack) Interfaces

func (s *Stack) Interfaces() map[int32]inet.Interface

Interfaces implements inet.Stack.Interfaces.

func (*Stack) IsSaveRestoreEnabled

func (s *Stack) IsSaveRestoreEnabled() bool

IsSaveRestoreEnabled implements inet.Stack.IsSaveRestoreEnabled.

func (*Stack) NewRoute

func (*Stack) NewRoute(context.Context, *nlmsg.Message) *syserr.Error

NewRoute implements inet.Stack.NewRoute.

func (*Stack) Pause

func (*Stack) Pause()

Pause implements inet.Stack.Pause.

func (*Stack) PortRange

func (*Stack) PortRange() (uint16, uint16)

PortRange implements inet.Stack.PortRange.

func (*Stack) RegisteredEndpoints

func (*Stack) RegisteredEndpoints() []stack.TransportEndpoint

RegisteredEndpoints implements inet.Stack.RegisteredEndpoints.

func (*Stack) RemoveInterface

func (*Stack) RemoveInterface(idx int32) error

RemoveInterface implements inet.Stack.RemoveInterface.

func (*Stack) RemoveInterfaceAddr

func (*Stack) RemoveInterfaceAddr(idx int32, addr inet.InterfaceAddr) error

RemoveInterfaceAddr implements inet.Stack.RemoveInterfaceAddr.

func (*Stack) RemoveRoute

func (*Stack) RemoveRoute(context.Context, *nlmsg.Message) *syserr.Error

RemoveRoute implements inet.Stack.RemoveRoute.

func (*Stack) ReplaceConfig

func (s *Stack) ReplaceConfig(_ inet.Stack)

ReplaceConfig implements inet.Stack.ReplaceConfig.

func (*Stack) Restore

func (*Stack) Restore()

Restore implements inet.Stack.Restore.

func (*Stack) RestoreCleanupEndpoints

func (*Stack) RestoreCleanupEndpoints([]stack.TransportEndpoint)

RestoreCleanupEndpoints implements inet.Stack.RestoreCleanupEndpoints.

func (*Stack) Resume

func (*Stack) Resume()

Resume implements inet.Stack.Resume.

func (*Stack) RouteTable

func (s *Stack) RouteTable() []inet.Route

RouteTable implements inet.Stack.RouteTable.

func (*Stack) SetForwarding

func (*Stack) SetForwarding(tcpip.NetworkProtocolNumber, bool) error

SetForwarding implements inet.Stack.SetForwarding.

func (*Stack) SetInterface

func (s *Stack) SetInterface(ctx context.Context, msg *nlmsg.Message) *syserr.Error

SetInterface implements inet.Stack.SetInterface.

func (*Stack) SetPortRange

func (*Stack) SetPortRange(uint16, uint16) error

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

func (*Stack) SetTCPSACKEnabled(bool) error

SetTCPSACKEnabled implements inet.Stack.SetTCPSACKEnabled.

func (*Stack) SetTCPSendBufferSize

func (*Stack) SetTCPSendBufferSize(inet.TCPBufferSize) error

SetTCPSendBufferSize implements inet.Stack.SetTCPSendBufferSize.

func (*Stack) Statistics

func (s *Stack) Statistics(stat any, arg string) error

Statistics implements inet.Stack.Statistics.

func (*Stack) SupportsIPv6

func (s *Stack) SupportsIPv6() bool

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

func (s *Stack) TCPSACKEnabled() (bool, error)

TCPSACKEnabled implements inet.Stack.TCPSACKEnabled.

func (*Stack) TCPSendBufferSize

func (s *Stack) TCPSendBufferSize() (inet.TCPBufferSize, error)

TCPSendBufferSize implements inet.Stack.TCPSendBufferSize.

Jump to

Keyboard shortcuts

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