udp

package
v0.0.0-...-8ac4b46 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 20 Imported by: 6

Documentation

Index

Constants

View Source
const DumpUdp = true
View Source
const MaxPacketBufferSize = 9000

Variables

View Source
var TransparentUDPWriter ugate.UdpWriter

Capture return - sends packets back to client app. This is typically a netstack or TProxy

Functions

func FreeIdleSockets

func FreeIdleSockets(gw *UDPListener)

Called on the periodic cleanup thread (~60sec), or if too many sockets open. Will update udp stats. Default UDP timeout to 60 sec.

func ReadFromUDP

func ReadFromUDP(conn *net.UDPConn, b []byte) (int, *net.UDPAddr, *net.UDPAddr, error)

ReadFromUDP reads a UDP packet from c, copying the payload into b. It returns the number of bytes copied into b and the return address that was on the packet.

RequestInPipe-of-band data is also read in so that the original destination address can be identified and parsed.

func SetReceiveBuffer

func SetReceiveBuffer(c net.PacketConn, minSize int) error

func StartUDPTProxyListener6

func StartUDPTProxyListener6(port int) (*net.UDPConn, error)

Initialize a port as a TPROXY socket. This can be sent over UDS from the root, and used for UDP capture.

func UDPAccept

func UDPAccept(con *net.UDPConn, u func(ip net.IP, port uint16, ip2 net.IP, u uint16, bytes []byte))

Types

type OOBCapablePacketConn

type OOBCapablePacketConn interface {
	net.PacketConn
	SyscallConn() (syscall.RawConn, error)
	ReadMsgUDP(b, oob []byte) (n, oobn, flags int, addr *net.UDPAddr, err error)
	WriteMsgUDP(b, oob []byte, addr *net.UDPAddr) (n, oobn int, err error)
}

If the PacketConn passed to RoundTripStart or Listen satisfies this interface, quic-go will read the ECN bits from the IP header.

In this case, ReadMsgUDP() will be used instead of ReadFrom() to read packets.

type TProxyUDP

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

Handles UDP packets intercepted using TProxy. Can send packets preserving original IP/port.

func (*TProxyUDP) WriteTo

func (tudp *TProxyUDP) WriteTo(data []byte, dstAddr *net.UDPAddr, srcAddr *net.UDPAddr) (int, error)

UDP write with source address control.

type UDPListener

type UDPListener struct {
	ActiveUdp map[string]*UdpNat

	// UDP
	// Capture return - sends packets back to client app.
	// This is typically a netstack or TProxy
	TransparentUDPWriter ugate.UdpWriter

	// Timeout for UDP sockets. Default 60 sec.
	ConnTimeout time.Duration
	// contains filtered or unexported fields
}

func New

func (*UDPListener) Close

func (gw *UDPListener) Close() error

func (*UDPListener) HandleUdp

func (udpg *UDPListener) HandleUdp(dstAddr net.IP, dstPort uint16, localAddr net.IP, localPort uint16, data []byte)

HandleUDP is processing a captured UDP packet. It can be captured by iptables TPROXY or netstack TUN. Will create a NAT, using a local port as source and translating back.

func (*UDPListener) HttpUDPNat

func (udpg *UDPListener) HttpUDPNat(w http.ResponseWriter, r *http.Request)

func (*UDPListener) InitMux

func (udpg *UDPListener) InitMux(mux *http.ServeMux)

func (*UDPListener) Listener

func (udpg *UDPListener) Listener(lc *meshauth.PortListener)

Listener creates a regular UDP listener port

type UdpNat

type UdpNat struct {
	nio.Stats

	// External address - string
	Dest string
	// External address
	DestAddr *net.UDPAddr

	//util.Stream
	// bound to a local port (on the real network).
	UDP *net.UDPConn

	Closed bool

	// For captured traffic / NAT
	LocalIP   net.IP
	LocalPort int

	LastRemoteIP    net.IP
	LastsRemotePort uint16
	ReverseSrcAddr  *net.UDPAddr
}

Represents on UDP 'nat' connection or association.

Currently full cone, i.e. one local port per NAT - max 30k This should be sufficient for local capture and small p2p nets. In the mesh, UDP should be encapsulated in WebRTC or quic.

Jump to

Keyboard shortcuts

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