wgengine/netstack: start SOCKS5 server in netstack mode

Updates #707
Updates #504

Signed-off-by: Naman Sood <mail@nsood.in>
pull/1410/head
Naman Sood 4 years ago committed by Brad Fitzpatrick
parent fe16ef6812
commit fec9dcbda1

@ -96,6 +96,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
💣 tailscale.com/net/netstat from tailscale.com/ipn/ipnserver 💣 tailscale.com/net/netstat from tailscale.com/ipn/ipnserver
tailscale.com/net/packet from tailscale.com/wgengine+ tailscale.com/net/packet from tailscale.com/wgengine+
tailscale.com/net/portmapper from tailscale.com/net/netcheck+ tailscale.com/net/portmapper from tailscale.com/net/netcheck+
tailscale.com/net/socks5 from tailscale.com/wgengine/netstack
tailscale.com/net/stun from tailscale.com/net/netcheck+ tailscale.com/net/stun from tailscale.com/net/netcheck+
tailscale.com/net/tlsdial from tailscale.com/control/controlclient+ tailscale.com/net/tlsdial from tailscale.com/control/controlclient+
tailscale.com/net/tsaddr from tailscale.com/ipn/ipnlocal+ tailscale.com/net/tsaddr from tailscale.com/ipn/ipnlocal+

@ -14,6 +14,7 @@ import (
"fmt" "fmt"
"io" "io"
"log" "log"
"net"
"strings" "strings"
"gvisor.dev/gvisor/pkg/tcpip" "gvisor.dev/gvisor/pkg/tcpip"
@ -30,6 +31,7 @@ import (
"gvisor.dev/gvisor/pkg/waiter" "gvisor.dev/gvisor/pkg/waiter"
"inet.af/netaddr" "inet.af/netaddr"
"tailscale.com/net/packet" "tailscale.com/net/packet"
"tailscale.com/net/socks5"
"tailscale.com/types/logger" "tailscale.com/types/logger"
"tailscale.com/types/netmap" "tailscale.com/types/netmap"
"tailscale.com/wgengine" "tailscale.com/wgengine"
@ -113,6 +115,7 @@ func (ns *Impl) Start() error {
ns.ipstack.SetTransportProtocolHandler(udp.ProtocolNumber, udpFwd.HandlePacket) ns.ipstack.SetTransportProtocolHandler(udp.ProtocolNumber, udpFwd.HandlePacket)
go ns.injectOutbound() go ns.injectOutbound()
ns.tundev.PostFilterIn = ns.injectInbound ns.tundev.PostFilterIn = ns.injectInbound
go ns.socks5Server()
return nil return nil
} }
@ -282,6 +285,21 @@ func (ns *Impl) forwardTCP(client *gonet.TCPConn, wq *waiter.Queue, address stri
ns.logf("[v2] netstack: forwarder connection to %s closed", address) ns.logf("[v2] netstack: forwarder connection to %s closed", address)
} }
func (ns *Impl) socks5Server() {
ln, err := net.Listen("tcp", "localhost:1080")
if err != nil {
ns.logf("could not start SOCKS5 listener: %v", err)
return
}
srv := &socks5.Server{
Logf: ns.logf,
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
return ns.dialContextTCP(ctx, addr)
},
}
ns.logf("SOCKS5 server exited: %v", srv.Serve(ln))
}
func (ns *Impl) acceptUDP(r *udp.ForwarderRequest) { func (ns *Impl) acceptUDP(r *udp.ForwarderRequest) {
ns.logf("[v2] UDP ForwarderRequest: %v", r) ns.logf("[v2] UDP ForwarderRequest: %v", r)
var wq waiter.Queue var wq waiter.Queue

Loading…
Cancel
Save