mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-05-24 21:46:39 +00:00

New session manager leverages similar functionality that was previously provided with datagram v2, with the distinct difference that the sessions are registered via QUIC Datagrams and unregistered via timeouts only; the sessions will no longer attempt to unregister sessions remotely with the edge service. The Session Manager is shared across all QUIC connections that cloudflared uses to connect to the edge (typically 4). This will help cloudflared be able to monitor all sessions across the connections and help correlate in the future if sessions migrate across connections. The UDP payload size is still limited to 1280 bytes across all OS's. Any UDP packet that provides a payload size of greater than 1280 will cause cloudflared to report (as it currently does) a log error and drop the packet. Closes TUN-8667
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package ingress
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"net"
|
|
"net/netip"
|
|
)
|
|
|
|
type UDPProxy interface {
|
|
io.ReadWriteCloser
|
|
LocalAddr() net.Addr
|
|
}
|
|
|
|
type udpProxy struct {
|
|
*net.UDPConn
|
|
}
|
|
|
|
func DialUDP(dstIP net.IP, dstPort uint16) (UDPProxy, error) {
|
|
dstAddr := &net.UDPAddr{
|
|
IP: dstIP,
|
|
Port: int(dstPort),
|
|
}
|
|
|
|
// We use nil as local addr to force runtime to find the best suitable local address IP given the destination
|
|
// address as context.
|
|
udpConn, err := net.DialUDP("udp", nil, dstAddr)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("unable to create UDP proxy to origin (%v:%v): %w", dstIP, dstPort, err)
|
|
}
|
|
|
|
return &udpProxy{udpConn}, nil
|
|
}
|
|
|
|
func DialUDPAddrPort(dest netip.AddrPort) (*net.UDPConn, error) {
|
|
addr := net.UDPAddrFromAddrPort(dest)
|
|
|
|
// We use nil as local addr to force runtime to find the best suitable local address IP given the destination
|
|
// address as context.
|
|
udpConn, err := net.DialUDP("udp", nil, addr)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("unable to create UDP proxy to origin (%v:%v): %w", dest.Addr(), dest.Port(), err)
|
|
}
|
|
|
|
return udpConn, nil
|
|
}
|