Documentation ¶
Overview ¶
Package fdbased provides the implemention of data-link layer endpoints backed by boundary-preserving file descriptors (e.g., TUN devices, seqpacket/datagram sockets).
FD based endpoints can be used in the networking stack by calling New() to create a new endpoint, and then passing it as an argument to Stack.CreateNIC().
Index ¶
- Constants
- Variables
- func New(opts *Options) (tcpip.LinkEndpointID, error)
- type InjectableEndpoint
- func (e *InjectableEndpoint) Attach(dispatcher stack.NetworkDispatcher)
- func (e *InjectableEndpoint) Capabilities() stack.LinkEndpointCapabilities
- func (e *InjectableEndpoint) GSOMaxSize() uint32
- func (e *InjectableEndpoint) Inject(protocol tcpip.NetworkProtocolNumber, vv buffer.VectorisedView)
- func (e *InjectableEndpoint) IsAttached() bool
- func (e *InjectableEndpoint) LinkAddress() tcpip.LinkAddress
- func (e *InjectableEndpoint) MTU() uint32
- func (e *InjectableEndpoint) MaxHeaderLength() uint16
- func (e *InjectableEndpoint) WritePacket(r *stack.Route, gso *stack.GSO, hdr buffer.Prependable, ...) *tcpip.Error
- func (e *InjectableEndpoint) WriteRawPacket(dest tcpip.Address, packet []byte) *tcpip.Error
- type Options
- type PacketDispatchMode
Constants ¶
const ( // MaxMsgsPerRecv is the maximum number of packets we want to retrieve // in a single RecvMMsg call. MaxMsgsPerRecv = 8 )
Variables ¶
var BufConfig = []int{128, 256, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768}
BufConfig defines the shape of the vectorised view used to read packets from the NIC.
Functions ¶
Types ¶
type InjectableEndpoint ¶
type InjectableEndpoint struct {
// contains filtered or unexported fields
}
InjectableEndpoint is an injectable fd-based endpoint. The endpoint writes to the FD, but does not read from it. All reads come from injected packets.
func NewInjectable ¶
func NewInjectable(fd int, mtu uint32, capabilities stack.LinkEndpointCapabilities) (tcpip.LinkEndpointID, *InjectableEndpoint)
NewInjectable creates a new fd-based InjectableEndpoint.
func (*InjectableEndpoint) Attach ¶
func (e *InjectableEndpoint) Attach(dispatcher stack.NetworkDispatcher)
Attach saves the stack network-layer dispatcher for use later when packets are injected.
func (*InjectableEndpoint) Capabilities ¶
func (e *InjectableEndpoint) Capabilities() stack.LinkEndpointCapabilities
Capabilities implements stack.LinkEndpoint.Capabilities.
func (*InjectableEndpoint) GSOMaxSize ¶
func (e *InjectableEndpoint) GSOMaxSize() uint32
GSOMaxSize returns the maximum GSO packet size.
func (*InjectableEndpoint) Inject ¶
func (e *InjectableEndpoint) Inject(protocol tcpip.NetworkProtocolNumber, vv buffer.VectorisedView)
Inject injects an inbound packet.
func (*InjectableEndpoint) IsAttached ¶
func (e *InjectableEndpoint) IsAttached() bool
IsAttached implements stack.LinkEndpoint.IsAttached.
func (*InjectableEndpoint) LinkAddress ¶
func (e *InjectableEndpoint) LinkAddress() tcpip.LinkAddress
LinkAddress returns the link address of this endpoint.
func (*InjectableEndpoint) MTU ¶
func (e *InjectableEndpoint) MTU() uint32
MTU implements stack.LinkEndpoint.MTU. It returns the value initialized during construction.
func (*InjectableEndpoint) MaxHeaderLength ¶
func (e *InjectableEndpoint) MaxHeaderLength() uint16
MaxHeaderLength returns the maximum size of the link-layer header.
func (*InjectableEndpoint) WritePacket ¶
func (e *InjectableEndpoint) WritePacket(r *stack.Route, gso *stack.GSO, hdr buffer.Prependable, payload buffer.VectorisedView, protocol tcpip.NetworkProtocolNumber) *tcpip.Error
WritePacket writes outbound packets to the file descriptor. If it is not currently writable, the packet is dropped.
type Options ¶
type Options struct { FD int MTU uint32 EthernetHeader bool ClosedFunc func(*tcpip.Error) Address tcpip.LinkAddress SaveRestore bool DisconnectOk bool GSOMaxSize uint32 PacketDispatchMode PacketDispatchMode TXChecksumOffload bool RXChecksumOffload bool }
Options specify the details about the fd-based endpoint to be created.
type PacketDispatchMode ¶
type PacketDispatchMode int
PacketDispatchMode are the various supported methods of receiving and dispatching packets from the underlying FD.
const ( // Readv is the default dispatch mode and is the least performant of the // dispatch options but the one that is supported by all underlying FD // types. Readv PacketDispatchMode = iota // RecvMMsg enables use of recvmmsg() syscall instead of readv() to // read inbound packets. This reduces # of syscalls needed to process // packets. // // NOTE: recvmmsg() is only supported for sockets, so if the underlying // FD is not a socket then the code will still fall back to the readv() // path. RecvMMsg // PacketMMap enables use of PACKET_RX_RING to receive packets from the // NIC. PacketMMap requires that the underlying FD be an AF_PACKET. The // primary use-case for this is runsc which uses an AF_PACKET FD to // receive packets from the veth device. PacketMMap )