Documentation ¶
Overview ¶
Package udp contains the implementation of the UDP transport protocol. To use it in the networking stack, this package must be added to the project, and activated on the stack by passing udp.NewProtocol() as one of the transport protocols when calling stack.New(). Then endpoints can be created by passing udp.ProtocolNumber as the transport protocol number when calling Stack.NewEndpoint().
Index ¶
Constants ¶
const ( // ProtocolNumber is the udp protocol number. ProtocolNumber = header.UDPProtocolNumber )
Variables ¶
This section is empty.
Functions ¶
func NewProtocol ¶
func NewProtocol() stack.TransportProtocol
NewProtocol returns a UDP transport protocol.
Types ¶
type EndpointState ¶
type EndpointState uint32
EndpointState represents the state of a UDP endpoint.
const ( StateInitial EndpointState = iota // 初始化 StateBound // 已绑定 StateConnected // 已连接 StateClosed // 已关闭 )
Endpoint states. Note that are represented in a netstack-specific manner and may not be meaningful externally. Specifically, they need to be translated to Linux's representation for these states if presented to userspace.
端点状态。 请注意,这些状态是以 netstack 特有的方式来表示的,在外部可能没有意义。 具体来说,如果向用户空间展示这些状态,需要翻译成 Linux 的表示方式。
func (EndpointState) String ¶
func (s EndpointState) String() string
String implements fmt.Stringer.String.
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 func(*ForwarderRequest)) *Forwarder
NewForwarder allocates and initializes a new forwarder.
func (*Forwarder) HandlePacket ¶
func (f *Forwarder) HandlePacket(r *stack.Route, id stack.TransportEndpointID, pkt tcpip.PacketBuffer) bool
HandlePacket handles all packets.
This function is expected to be passed as an argument to the stack.SetTransportProtocolHandler function.
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 ¶
CreateEndpoint creates a connected UDP endpoint for the session request.
func (*ForwarderRequest) ID ¶
func (r *ForwarderRequest) ID() stack.TransportEndpointID
ID returns the 4-tuple (src address, src port, dst address, dst port) that represents the session request.