Skip to content

Commit

Permalink
[tailscale1.18] net: add TS_PANIC_ON_TEST_LISTEN_UNSPEC env to panic …
Browse files Browse the repository at this point in the history
…on unspecified addr listens

For debugging Mac firewall dialog boxes blocking+failing tests.

Change-Id: Ic1a0cd51de7fe553de1c1c9333fa1cc75b8490f2
  • Loading branch information
josharian committed Feb 7, 2022
1 parent 07fb917 commit 212a90c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/net/tcpsock_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,28 @@ func (ln *TCPListener) file() (*os.File, error) {
return f, nil
}

// Tailscale addition: if TS_PANIC_ON_TEST_LISTEN_UNSPEC is set, panic
// if a listen tries to listen on all interfaces (for debugging Mac
// firewall dialogs in tests).
func panicOnUnspecListen(ip IP) bool {
if ip != nil && !ip.IsUnspecified() {
return false
}
v := os.Getenv("TS_PANIC_ON_TEST_LISTEN_UNSPEC")
if v == "" {
return false
}
switch v[0] {
case 't', 'T', '1':
return true
}
return false
}

func (sl *sysListener) listenTCP(ctx context.Context, laddr *TCPAddr) (*TCPListener, error) {
if panicOnUnspecListen(laddr.IP) {
panic("tailscale: can't listen on unspecified address in test")
}
fd, err := internetSocket(ctx, sl.network, laddr, nil, syscall.SOCK_STREAM, 0, "listen", sl.ListenConfig.Control)
if err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions src/net/udpsock_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ func (sd *sysDialer) dialUDP(ctx context.Context, laddr, raddr *UDPAddr) (*UDPCo
}

func (sl *sysListener) listenUDP(ctx context.Context, laddr *UDPAddr) (*UDPConn, error) {
if panicOnUnspecListen(laddr.IP) {
panic("tailscale: can't listen on unspecified address in test")
}

fd, err := internetSocket(ctx, sl.network, laddr, nil, syscall.SOCK_DGRAM, 0, "listen", sl.ListenConfig.Control)
if err != nil {
return nil, err
Expand Down

0 comments on commit 212a90c

Please sign in to comment.