Skip to content

Commit c191b12

Browse files
committed
[tailscale1.16] net: add TS_PANIC_ON_TEST_LISTEN_UNSPEC env to panic on unspecified addr listens
For debugging Mac firewall dialog boxes blocking+failing tests.
1 parent 171c592 commit c191b12

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/net/tcpsock_posix.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,28 @@ func (ln *TCPListener) file() (*os.File, error) {
164164
return f, nil
165165
}
166166

167+
// Tailscale addition: if TS_PANIC_ON_TEST_LISTEN_UNSPEC is set, panic
168+
// if a listen tries to listen on all interfaces (for debugging Mac
169+
// firewall dialogs in tests).
170+
func panicOnUnspecListen(ip IP) bool {
171+
if ip != nil && !ip.IsUnspecified() {
172+
return false
173+
}
174+
v := os.Getenv("TS_PANIC_ON_TEST_LISTEN_UNSPEC")
175+
if v == "" {
176+
return false
177+
}
178+
switch v[0] {
179+
case 't', 'T', '1':
180+
return true
181+
}
182+
return false
183+
}
184+
167185
func (sl *sysListener) listenTCP(ctx context.Context, laddr *TCPAddr) (*TCPListener, error) {
186+
if panicOnUnspecListen(laddr.IP) {
187+
panic("tailscale: can't listen on unspecified address in test")
188+
}
168189
fd, err := internetSocket(ctx, sl.network, laddr, nil, syscall.SOCK_STREAM, 0, "listen", sl.ListenConfig.Control)
169190
if err != nil {
170191
return nil, err

src/net/udpsock_posix.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ func (sd *sysDialer) dialUDP(ctx context.Context, laddr, raddr *UDPAddr) (*UDPCo
103103
}
104104

105105
func (sl *sysListener) listenUDP(ctx context.Context, laddr *UDPAddr) (*UDPConn, error) {
106+
if panicOnUnspecListen(laddr.IP) {
107+
panic("tailscale: can't listen on unspecified address in test")
108+
}
109+
106110
fd, err := internetSocket(ctx, sl.network, laddr, nil, syscall.SOCK_DGRAM, 0, "listen", sl.ListenConfig.Control)
107111
if err != nil {
108112
return nil, err

0 commit comments

Comments
 (0)