package udp

import "gvisor.dev/gvisor/pkg/tcpip/transport/udp"

Package udp contains the implementation of the UDP transport protocol.

Index

Constants

const (
	// ProtocolNumber is the udp protocol number.
	ProtocolNumber = header.UDPProtocolNumber

	// MinBufferSize is the smallest size of a receive or send buffer.
	MinBufferSize = 4 << 10 // 4KiB bytes.

	// DefaultSendBufferSize is the default size of the send buffer for
	// an endpoint.
	DefaultSendBufferSize = 32 << 10 // 32KiB

	// DefaultReceiveBufferSize is the default size of the receive buffer
	// for an endpoint.
	DefaultReceiveBufferSize = 32 << 10 // 32KiB

	// MaxBufferSize is the largest size a receive/send buffer can grow to.
	MaxBufferSize = 4 << 20 // 4MiB
)

Functions

func NewProtocol

func NewProtocol(s *stack.Stack) stack.TransportProtocol

NewProtocol returns a UDP transport protocol.

Types

type Forwarder

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

Forwarder is a session request forwarder, which allows clients to decide what to do with a session request, for example: ignore it, or process it.

The canonical way of using it is to pass the Forwarder.HandlePacket function to stack.SetTransportProtocolHandler.

func NewForwarder

func NewForwarder(s *stack.Stack, handler ForwarderHandler) *Forwarder

NewForwarder allocates and initializes a new forwarder.

func (*Forwarder) HandlePacket

func (f *Forwarder) HandlePacket(id stack.TransportEndpointID, pkt *stack.PacketBuffer) bool

HandlePacket handles all packets.

This function is expected to be passed as an argument to the stack.SetTransportProtocolHandler function.

type ForwarderHandler

type ForwarderHandler func(*ForwarderRequest) (handled bool)

ForwarderHandler handles incoming requests. Returning true marks the request as handled, returning false marks the request as unhandled. Stack may send an ICMP port unreachable message for unhandled requests.

type ForwarderRequest

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

ForwarderRequest represents a session request received by the forwarder and passed to the client. Clients may optionally create an endpoint to represent it via CreateEndpoint.

func (*ForwarderRequest) CreateEndpoint

func (r *ForwarderRequest) CreateEndpoint(queue *waiter.Queue) (tcpip.Endpoint, tcpip.Error)

CreateEndpoint creates a connected UDP endpoint for the session request.

func (*ForwarderRequest) ID

ID returns the 4-tuple (src address, src port, dst address, dst port) that represents the session request.

Source Files

endpoint.go endpoint_state.go forwarder.go protocol.go

Version
v0.0.0-20250726022846-8a89a2fab4a2 (latest)
Published
Jul 26, 2025
Platform
linux/amd64
Imports
17 packages
Last checked
2 days ago

Tools for package owners.