Skip to content

Commit

Permalink
[tailscale1.20] 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
(cherry picked from commit cd7323c)
  • Loading branch information
josharian authored and bradfitz committed Jan 31, 2023
1 parent 4865b81 commit 8c9eff4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/net/tcpsock_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,29 @@ 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")
}

var ctrlCtxFn func(cxt context.Context, network, address string, c syscall.RawConn) error
if sl.ListenConfig.Control != nil {
ctrlCtxFn = func(cxt context.Context, network, address string, c syscall.RawConn) error {
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 @@ -217,6 +217,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")
}

var ctrlCtxFn func(cxt context.Context, network, address string, c syscall.RawConn) error
if sl.ListenConfig.Control != nil {
ctrlCtxFn = func(cxt context.Context, network, address string, c syscall.RawConn) error {
Expand Down

0 comments on commit 8c9eff4

Please sign in to comment.