Documentation ¶
Overview ¶
Package inet defines semantics for IP stacks.
Index ¶
- Constants
- type AbstractSocketNamespace
- type Interface
- type InterfaceAddr
- type InterfaceRequest
- type Namespace
- func (n *Namespace) AbstractSockets() *AbstractSocketNamespace
- func (n *Namespace) DecRef(ctx context.Context)
- func (n *Namespace) Destroy(ctx context.Context)
- func (n *Namespace) GetInode() *nsfs.Inode
- func (n *Namespace) IncRef()
- func (n *Namespace) IsRoot() bool
- func (n *Namespace) ResetStack()
- func (n *Namespace) RestoreRootStack(stack Stack)
- func (n *Namespace) SetInode(inode *nsfs.Inode)
- func (n *Namespace) Stack() Stack
- func (n *Namespace) Type() string
- func (n *Namespace) UserNamespace() *auth.UserNamespace
- type NamespaceByFD
- type NetworkStackCreator
- type Route
- type Stack
- type StatDev
- type StatSNMPICMP
- type StatSNMPICMPMSG
- type StatSNMPIP
- type StatSNMPTCP
- type StatSNMPUDP
- type StatSNMPUDPLite
- type TCPBufferSize
- type TCPLossRecovery
- type TestStack
- func (s *TestStack) AddInterfaceAddr(idx int32, addr InterfaceAddr) error
- func (s *TestStack) CleanupEndpoints() []stack.TransportEndpoint
- func (s *TestStack) Destroy()
- func (*TestStack) EnableSaveRestore() error
- func (*TestStack) GROTimeout(NICID int32) (time.Duration, error)
- func (s *TestStack) InterfaceAddrs() map[int32][]InterfaceAddr
- func (s *TestStack) Interfaces() map[int32]Interface
- func (*TestStack) IsSaveRestoreEnabled() bool
- func (s *TestStack) NewRoute(ctx context.Context, msg *nlmsg.Message) *syserr.Error
- func (s *TestStack) Pause()
- func (*TestStack) PortRange() (uint16, uint16)
- func (s *TestStack) RegisteredEndpoints() []stack.TransportEndpoint
- func (s *TestStack) RemoveInterface(idx int32) error
- func (s *TestStack) RemoveInterfaceAddr(idx int32, addr InterfaceAddr) error
- func (s *TestStack) RemoveRoute(ctx context.Context, msg *nlmsg.Message) *syserr.Error
- func (s *TestStack) ReplaceConfig(_ Stack)
- func (s *TestStack) Restore()
- func (s *TestStack) RestoreCleanupEndpoints([]stack.TransportEndpoint)
- func (s *TestStack) Resume()
- func (s *TestStack) RouteTable() []Route
- func (s *TestStack) SetForwarding(protocol tcpip.NetworkProtocolNumber, enable bool) error
- func (*TestStack) SetGROTimeout(NICID int32, timeout time.Duration) error
- func (s *TestStack) SetInterface(ctx context.Context, msg *nlmsg.Message) *syserr.Error
- func (*TestStack) SetPortRange(start uint16, end uint16) error
- func (s *TestStack) SetTCPReceiveBufferSize(size TCPBufferSize) error
- func (s *TestStack) SetTCPRecovery(recovery TCPLossRecovery) error
- func (s *TestStack) SetTCPSACKEnabled(enabled bool) error
- func (s *TestStack) SetTCPSendBufferSize(size TCPBufferSize) error
- func (s *TestStack) Statistics(stat any, arg string) error
- func (s *TestStack) SupportsIPv6() bool
- func (s *TestStack) TCPReceiveBufferSize() (TCPBufferSize, error)
- func (s *TestStack) TCPRecovery() (TCPLossRecovery, error)
- func (s *TestStack) TCPSACKEnabled() (bool, error)
- func (s *TestStack) TCPSendBufferSize() (TCPBufferSize, error)
- type VethPeerReq
Constants ¶
const ( // CtxStack is a Context.Value key for a network stack. CtxStack contextID = iota // CtxNamespaceByFD is a Context.Value key for NamespaceByFD. CtxNamespaceByFD )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AbstractSocketNamespace ¶
type AbstractSocketNamespace struct {
// contains filtered or unexported fields
}
AbstractSocketNamespace is used to implement the Linux abstract socket functionality.
+stateify savable
func (*AbstractSocketNamespace) Bind ¶
func (a *AbstractSocketNamespace) Bind(ctx context.Context, path string, ep transport.BoundEndpoint, socket refs.TryRefCounter) (string, *syserr.Error)
Bind binds the given socket.
When the last reference managed by socket is dropped, ep may be removed from the namespace.
func (*AbstractSocketNamespace) BoundEndpoint ¶
func (a *AbstractSocketNamespace) BoundEndpoint(name string) transport.BoundEndpoint
BoundEndpoint retrieves the endpoint bound to the given name. The return value is nil if no endpoint was bound.
func (*AbstractSocketNamespace) Remove ¶
func (a *AbstractSocketNamespace) Remove(name string, socket refs.TryRefCounter)
Remove removes the specified socket at name from the abstract socket namespace, if it has not yet been replaced.
type Interface ¶
type Interface struct { // DeviceType is the device type, a Linux ARPHRD_* constant. DeviceType uint16 // Flags is the device flags; see netdevice(7), under "Ioctls", // "SIOCGIFFLAGS, SIOCSIFFLAGS". Flags uint32 // Name is the device name. Name string // Addr is the hardware device address. Addr []byte // MTU is the maximum transmission unit. MTU uint32 // Features are the device features queried from the host at // stack creation time. These are immutable after startup. Features []linux.EthtoolGetFeaturesBlock }
Interface contains information about a network interface.
type InterfaceAddr ¶
type InterfaceAddr struct { // Family is the address family, a Linux AF_* constant. Family uint8 // PrefixLen is the address prefix length. PrefixLen uint8 // Flags is the address flags. Flags uint8 // Addr is the actual address. Addr []byte }
InterfaceAddr contains information about a network interface address.
type InterfaceRequest ¶
type InterfaceRequest struct { // Kind is the link type. Kind string // Name is the interface name. Name string // Addr is the hardware device address. Addr []byte // MTU is the maximum transmission unit. MTU uint32 // Data is link type specific device properties. Data any }
InterfaceRequest contains information about an adding interface.
type Namespace ¶
type Namespace struct {
// contains filtered or unexported fields
}
Namespace represents a network namespace. See network_namespaces(7).
+stateify savable
func NewNamespace ¶
func NewNamespace(root *Namespace, userNS *auth.UserNamespace) *Namespace
NewNamespace creates a new network namespace from the root.
func NewRootNamespace ¶
func NewRootNamespace(stack Stack, creator NetworkStackCreator, userNS *auth.UserNamespace) *Namespace
NewRootNamespace creates the root network namespace, with creator allowing new network namespaces to be created. If creator is nil, no networking will function if the network is namespaced.
func (*Namespace) AbstractSockets ¶
func (n *Namespace) AbstractSockets() *AbstractSocketNamespace
AbstractSockets returns AbstractSocketNamespace.
func (*Namespace) ResetStack ¶
func (n *Namespace) ResetStack()
ResetStack resets the stack in the network namespace to nil. This should only be called when restoring kernel.
func (*Namespace) RestoreRootStack ¶
RestoreRootStack restores the root network namespace with stack. This should only be called when restoring kernel.
func (*Namespace) Stack ¶
Stack returns the network stack of n. Stack may return nil if no network stack is configured.
func (*Namespace) UserNamespace ¶
func (n *Namespace) UserNamespace() *auth.UserNamespace
UserNamespace returns the user namespace associated with this namespace.
type NamespaceByFD ¶
NamespaceByFD returns the network namespace associated with the specified file descriptor.
func NamespaceByFDFromContext ¶
func NamespaceByFDFromContext(ctx context.Context) NamespaceByFD
NamespaceByFDFromContext returns NamespaceByFD to lookup the network namespace associated with the specified file descriptor.
type NetworkStackCreator ¶
type NetworkStackCreator interface { // CreateStack creates a new network stack for a network namespace. CreateStack() (Stack, error) }
NetworkStackCreator allows new instances of a network stack to be created. It is used by the kernel to create new network namespaces when requested.
type Route ¶
type Route struct { // Family is the address family, a Linux AF_* constant. Family uint8 // DstLen is the length of the destination address. DstLen uint8 // SrcLen is the length of the source address. SrcLen uint8 // TOS is the Type of Service filter. TOS uint8 // Table is the routing table ID. Table uint8 // Protocol is the route origin, a Linux RTPROT_* constant. Protocol uint8 // Scope is the distance to destination, a Linux RT_SCOPE_* constant. Scope uint8 // Type is the route origin, a Linux RTN_* constant. Type uint8 // Flags are route flags. See rtnetlink(7) under "rtm_flags". Flags uint32 // DstAddr is the route destination address (RTA_DST). DstAddr []byte // SrcAddr is the route source address (RTA_SRC). SrcAddr []byte // OutputInterface is the output interface index (RTA_OIF). OutputInterface int32 // GatewayAddr is the route gateway address (RTA_GATEWAY). GatewayAddr []byte }
Route contains information about a network route.
type Stack ¶
type Stack interface { // Interfaces returns all network interfaces as a mapping from interface // indexes to interface properties. Interface indices are strictly positive // integers. Interfaces() map[int32]Interface // RemoveInterface removes the specified network interface. RemoveInterface(idx int32) error // InterfaceAddrs returns all network interface addresses as a mapping from // interface indexes to a slice of associated interface address properties. InterfaceAddrs() map[int32][]InterfaceAddr // AddInterfaceAddr adds an address to the network interface identified by // idx. AddInterfaceAddr(idx int32, addr InterfaceAddr) error // SetInterface modifies or adds a new interface. SetInterface(ctx context.Context, msg *nlmsg.Message) *syserr.Error // RemoveInterfaceAddr removes an address from the network interface // identified by idx. RemoveInterfaceAddr(idx int32, addr InterfaceAddr) error // SupportsIPv6 returns true if the stack supports IPv6 connectivity. SupportsIPv6() bool // TCPReceiveBufferSize returns TCP receive buffer size settings. TCPReceiveBufferSize() (TCPBufferSize, error) // SetTCPReceiveBufferSize attempts to change TCP receive buffer size // settings. SetTCPReceiveBufferSize(size TCPBufferSize) error // TCPSendBufferSize returns TCP send buffer size settings. TCPSendBufferSize() (TCPBufferSize, error) // SetTCPSendBufferSize attempts to change TCP send buffer size settings. SetTCPSendBufferSize(size TCPBufferSize) error // TCPSACKEnabled returns true if RFC 2018 TCP Selective Acknowledgements // are enabled. TCPSACKEnabled() (bool, error) // SetTCPSACKEnabled attempts to change TCP selective acknowledgement // settings. SetTCPSACKEnabled(enabled bool) error // TCPRecovery returns the TCP loss detection algorithm. TCPRecovery() (TCPLossRecovery, error) // SetTCPRecovery attempts to change TCP loss detection algorithm. SetTCPRecovery(recovery TCPLossRecovery) error // Statistics reports stack statistics. Statistics(stat any, arg string) error // RouteTable returns the network stack's route table. RouteTable() []Route // RemoveRoute deletes the specified route. RemoveRoute(ctx context.Context, msg *nlmsg.Message) *syserr.Error // NewRoute adds the given route to the network stack's route table. NewRoute(ctx context.Context, msg *nlmsg.Message) *syserr.Error // Pause pauses the network stack before save. Pause() // Resume resumes the network stack after save. Resume() // Restore restarts the network stack after restore. Restore() // ReplaceConfig replaces the new network stack configuration to the // loaded or saved network stack after restore. // TODO(b/379115439): This method is a workaround to update netstack config // during restore. It should be removed after a new method is added to // extract the complete config from the spec and update it in the loaded // stack during restore. ReplaceConfig(st Stack) // Destroy the network stack. Destroy() // RegisteredEndpoints returns all endpoints which are currently registered. RegisteredEndpoints() []stack.TransportEndpoint // CleanupEndpoints returns endpoints currently in the cleanup state. CleanupEndpoints() []stack.TransportEndpoint // RestoreCleanupEndpoints adds endpoints to cleanup tracking. This is useful // for restoring a stack after a save. RestoreCleanupEndpoints([]stack.TransportEndpoint) // SetForwarding enables or disables packet forwarding between NICs. SetForwarding(protocol tcpip.NetworkProtocolNumber, enable bool) error // PortRange returns the UDP and TCP inclusive range of ephemeral ports // used in both IPv4 and IPv6. PortRange() (uint16, uint16) // SetPortRange sets the UDP and TCP IPv4 and IPv6 ephemeral port range // (inclusive). SetPortRange(start uint16, end uint16) error // EnableSaveRestore enables netstack s/r. EnableSaveRestore() error // IsSaveRestoreEnabled returns true when netstack s/r is enabled. IsSaveRestoreEnabled() bool }
Stack represents a TCP/IP stack.
func StackFromContext ¶
StackFromContext returns the network stack associated with ctx.
type StatDev ¶
type StatDev [16]uint64
StatDev describes one line of /proc/net/dev, i.e., stats for one network interface.
type StatSNMPICMP ¶
type StatSNMPICMP [27]uint64
StatSNMPICMP describes Icmp line of /proc/net/snmp.
type StatSNMPICMPMSG ¶
type StatSNMPICMPMSG [512]uint64
StatSNMPICMPMSG describes IcmpMsg line of /proc/net/snmp.
type StatSNMPUDPLite ¶
type StatSNMPUDPLite [8]uint64
StatSNMPUDPLite describes UdpLite line of /proc/net/snmp.
type TCPBufferSize ¶
type TCPBufferSize struct { // Min is the minimum size. Min int // Default is the default size. Default int // Max is the maximum size. Max int }
TCPBufferSize contains settings controlling TCP buffer sizing.
+stateify savable
type TCPLossRecovery ¶
type TCPLossRecovery int32
TCPLossRecovery indicates TCP loss detection and recovery methods to use.
const ( TCP_RACK_LOSS_DETECTION TCPLossRecovery = 1 << iota TCP_RACK_STATIC_REO_WND TCP_RACK_NO_DUPTHRESH )
Loss recovery constants from include/net/tcp.h which are used to set /proc/sys/net/ipv4/tcp_recovery.
type TestStack ¶
type TestStack struct { InterfacesMap map[int32]Interface InterfaceAddrsMap map[int32][]InterfaceAddr RouteList []Route SupportsIPv6Flag bool TCPRecvBufSize TCPBufferSize TCPSendBufSize TCPBufferSize TCPSACKFlag bool Recovery TCPLossRecovery IPForwarding bool }
TestStack is a dummy implementation of Stack for tests.
func NewTestStack ¶
func NewTestStack() *TestStack
NewTestStack returns a TestStack with no network interfaces. The value of all other options is unspecified; tests that rely on specific values must set them explicitly.
func (*TestStack) AddInterfaceAddr ¶
func (s *TestStack) AddInterfaceAddr(idx int32, addr InterfaceAddr) error
AddInterfaceAddr implements Stack.
func (*TestStack) CleanupEndpoints ¶
func (s *TestStack) CleanupEndpoints() []stack.TransportEndpoint
CleanupEndpoints implements Stack.
func (*TestStack) EnableSaveRestore ¶
EnableSaveRestore implements Stack.
func (*TestStack) GROTimeout ¶
GROTimeout implements Stack.
func (*TestStack) InterfaceAddrs ¶
func (s *TestStack) InterfaceAddrs() map[int32][]InterfaceAddr
InterfaceAddrs implements Stack.
func (*TestStack) Interfaces ¶
Interfaces implements Stack.
func (*TestStack) IsSaveRestoreEnabled ¶
IsSaveRestoreEnabled implements Stack.
func (*TestStack) RegisteredEndpoints ¶
func (s *TestStack) RegisteredEndpoints() []stack.TransportEndpoint
RegisteredEndpoints implements Stack.
func (*TestStack) RemoveInterface ¶
RemoveInterface implements Stack.
func (*TestStack) RemoveInterfaceAddr ¶
func (s *TestStack) RemoveInterfaceAddr(idx int32, addr InterfaceAddr) error
RemoveInterfaceAddr implements Stack.
func (*TestStack) RemoveRoute ¶
RemoveRoute implements Stack.
func (*TestStack) ReplaceConfig ¶
ReplaceConfig implements Stack.
func (*TestStack) RestoreCleanupEndpoints ¶
func (s *TestStack) RestoreCleanupEndpoints([]stack.TransportEndpoint)
RestoreCleanupEndpoints implements Stack.
func (*TestStack) RouteTable ¶
RouteTable implements Stack.
func (*TestStack) SetForwarding ¶
func (s *TestStack) SetForwarding(protocol tcpip.NetworkProtocolNumber, enable bool) error
SetForwarding implements Stack.
func (*TestStack) SetGROTimeout ¶
SetGROTimeout implements Stack.
func (*TestStack) SetInterface ¶
SetInterface implements Stack.
func (*TestStack) SetPortRange ¶
SetPortRange implements Stack.
func (*TestStack) SetTCPReceiveBufferSize ¶
func (s *TestStack) SetTCPReceiveBufferSize(size TCPBufferSize) error
SetTCPReceiveBufferSize implements Stack.
func (*TestStack) SetTCPRecovery ¶
func (s *TestStack) SetTCPRecovery(recovery TCPLossRecovery) error
SetTCPRecovery implements Stack.
func (*TestStack) SetTCPSACKEnabled ¶
SetTCPSACKEnabled implements Stack.
func (*TestStack) SetTCPSendBufferSize ¶
func (s *TestStack) SetTCPSendBufferSize(size TCPBufferSize) error
SetTCPSendBufferSize implements Stack.
func (*TestStack) Statistics ¶
Statistics implements Stack.
func (*TestStack) SupportsIPv6 ¶
SupportsIPv6 implements Stack.
func (*TestStack) TCPReceiveBufferSize ¶
func (s *TestStack) TCPReceiveBufferSize() (TCPBufferSize, error)
TCPReceiveBufferSize implements Stack.
func (*TestStack) TCPRecovery ¶
func (s *TestStack) TCPRecovery() (TCPLossRecovery, error)
TCPRecovery implements Stack.
func (*TestStack) TCPSACKEnabled ¶
TCPSACKEnabled implements Stack.
func (*TestStack) TCPSendBufferSize ¶
func (s *TestStack) TCPSendBufferSize() (TCPBufferSize, error)
TCPSendBufferSize implements Stack.
type VethPeerReq ¶
type VethPeerReq struct { // Req is information about the second end of the new veth pair. Req InterfaceRequest // Stack is the stack where the second end has to be added. Stack Stack }
VethPeerReq contains information about a second interface of a new veth pair.