@@ -175,12 +175,34 @@ func (ln *TCPListener) file() (*os.File, error) {
175
175
return f , nil
176
176
}
177
177
178
+ // Tailscale addition: if TS_PANIC_ON_TEST_LISTEN_UNSPEC is set, panic
179
+ // if a listen tries to listen on all interfaces (for debugging Mac
180
+ // firewall dialogs in tests).
181
+ func panicOnUnspecListen (ip IP ) bool {
182
+ if ip != nil && ! ip .IsUnspecified () {
183
+ return false
184
+ }
185
+ v := os .Getenv ("TS_PANIC_ON_TEST_LISTEN_UNSPEC" )
186
+ if v == "" {
187
+ return false
188
+ }
189
+ switch v [0 ] {
190
+ case 't' , 'T' , '1' :
191
+ return true
192
+ }
193
+ return false
194
+ }
195
+
178
196
func (sl * sysListener ) listenTCP (ctx context.Context , laddr * TCPAddr ) (* TCPListener , error ) {
179
197
return sl .listenTCPProto (ctx , laddr , 0 )
180
198
}
181
199
182
200
func (sl * sysListener ) listenTCPProto (ctx context.Context , laddr * TCPAddr , proto int ) (* TCPListener , error ) {
183
- var ctrlCtxFn func (ctx context.Context , network , address string , c syscall.RawConn ) error
201
+ if panicOnUnspecListen (laddr .IP ) {
202
+ panic ("tailscale: can't listen on unspecified address in test" )
203
+ }
204
+
205
+ var ctrlCtxFn func (cxt context.Context , network , address string , c syscall.RawConn ) error
184
206
if sl .ListenConfig .Control != nil {
185
207
ctrlCtxFn = func (ctx context.Context , network , address string , c syscall.RawConn ) error {
186
208
return sl .ListenConfig .Control (network , address , c )
0 commit comments