summaryrefslogtreecommitdiffhomepage
path: root/wgengine/netstack/netstack.go
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@tailscale.com>2021-06-23 22:09:31 -0700
committerBrad Fitzpatrick <bradfitz@tailscale.com>2021-06-23 22:12:17 -0700
commitb92e2ebd24a5c33859ef2ba85cc554cc64a22a53 (patch)
tree048dc5df6ccbd8482af78e5427438114b8290494 /wgengine/netstack/netstack.go
parent3d777c13b038a1452fdf839104328371bf637982 (diff)
downloadtailscale-b92e2ebd24a5c33859ef2ba85cc554cc64a22a53.tar.xz
tailscale-b92e2ebd24a5c33859ef2ba85cc554cc64a22a53.zip
wgengine/netstack: add Impl.DialContextUDP
Unused so far, but eventually we'll want this for SOCKS5 UDP binds (we currently only do TCP with SOCKS5), and also for #2102 for forwarding MagicDNS upstream to Tailscale IPs over netstack. Updates #2102 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Diffstat (limited to 'wgengine/netstack/netstack.go')
-rw-r--r--wgengine/netstack/netstack.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/wgengine/netstack/netstack.go b/wgengine/netstack/netstack.go
index f587755ff..47103b9ce 100644
--- a/wgengine/netstack/netstack.go
+++ b/wgengine/netstack/netstack.go
@@ -362,6 +362,30 @@ func (ns *Impl) DialContextTCP(ctx context.Context, addr string) (*gonet.TCPConn
return gonet.DialContextTCP(ctx, ns.ipstack, remoteAddress, ipType)
}
+func (ns *Impl) DialContextUDP(ctx context.Context, addr string) (*gonet.UDPConn, error) {
+ ns.mu.Lock()
+ dnsMap := ns.dns
+ ns.mu.Unlock()
+
+ remoteIPPort, err := dnsMap.Resolve(ctx, addr)
+ if err != nil {
+ return nil, err
+ }
+ remoteAddress := &tcpip.FullAddress{
+ NIC: nicID,
+ Addr: tcpip.Address(remoteIPPort.IP().IPAddr().IP),
+ Port: remoteIPPort.Port(),
+ }
+ var ipType tcpip.NetworkProtocolNumber
+ if remoteIPPort.IP().Is4() {
+ ipType = ipv4.ProtocolNumber
+ } else {
+ ipType = ipv6.ProtocolNumber
+ }
+
+ return gonet.DialUDP(ns.ipstack, nil, remoteAddress, ipType)
+}
+
func (ns *Impl) injectOutbound() {
for {
packetInfo, ok := ns.linkEP.ReadContext(context.Background())