Skip to content

Commit 1377618

Browse files
Tom DNettotwitchyliquid64
Tom DNetto
authored andcommitted
tsnet: expose field to configure Wireguard port
Signed-off-by: Tom DNetto <[email protected]> Updates tailscale#1748
1 parent 8e84048 commit 1377618

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

cmd/sniproxy/sniproxy.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
var (
2828
ports = flag.String("ports", "443", "comma-separated list of ports to proxy")
29+
wgPort = flag.Int("wg-listen-port", 0, "UDP port to listen on for WireGuard and peer-to-peer traffic; 0 means automatically select")
2930
promoteHTTPS = flag.Bool("promote-https", true, "promote HTTP to HTTPS")
3031
)
3132

@@ -40,6 +41,7 @@ func main() {
4041
hostinfo.SetApp("sniproxy")
4142

4243
var s server
44+
s.ts.Port = uint16(*wgPort)
4345
defer s.ts.Close()
4446

4547
lc, err := s.ts.LocalClient()

tsnet/tsnet.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func inTest() bool { return flag.Lookup("test.v") != nil }
6161

6262
// Server is an embedded Tailscale server.
6363
//
64-
// Its exported fields may be changed until the first call to Listen.
64+
// Its exported fields may be changed until the first method call.
6565
type Server struct {
6666
// Dir specifies the name of the directory to use for
6767
// state. If empty, a directory is selected automatically
@@ -108,6 +108,11 @@ type Server struct {
108108
// If empty, the Tailscale default is used.
109109
ControlURL string
110110

111+
// Port is the UDP port to listen on for WireGuard and peer-to-peer
112+
// traffic. If zero, a port is automatically selected. Leave this
113+
// field at zero unless you know what you are doing.
114+
Port uint16
115+
111116
getCertForTesting func(*tls.ClientHelloInfo) (*tls.Certificate, error)
112117

113118
initOnce sync.Once
@@ -502,7 +507,7 @@ func (s *Server) start() (reterr error) {
502507
sys := new(tsd.System)
503508
s.dialer = &tsdial.Dialer{Logf: logf} // mutated below (before used)
504509
eng, err := wgengine.NewUserspaceEngine(logf, wgengine.Config{
505-
ListenPort: 0,
510+
ListenPort: s.Port,
506511
NetMon: s.netMon,
507512
Dialer: s.dialer,
508513
SetSubsystem: sys.Set,

0 commit comments

Comments
 (0)