@ -8,6 +8,7 @@ package magicsock
import (
import (
"log"
"log"
"net/netip"
"net/netip"
"strings"
"sync"
"sync"
"tailscale.com/envknob"
"tailscale.com/envknob"
@ -73,17 +74,24 @@ var (
// startup.
// startup.
func inTest ( ) bool { return envknob . Bool ( "IN_TS_TEST" ) }
func inTest ( ) bool { return envknob . Bool ( "IN_TS_TEST" ) }
// pretendpoint returns TS_DEBUG_PRETENDPOINT as an AddrPort, if set.
// pretendpoint s returns TS_DEBUG_PRETENDPOINT as [] AddrPort, if set.
// See https://github.com/tailscale/tailscale/issues/12578 and
// See https://github.com/tailscale/tailscale/issues/12578 and
// https://github.com/tailscale/tailscale/pull/12735.
// https://github.com/tailscale/tailscale/pull/12735.
var pretendpoint = sync . OnceValue ( func ( ) ( ap netip . AddrPort ) {
//
s := envknob . String ( "TS_DEBUG_PRETENDPOINT" )
// It can be between 0 and 3 comma-separated AddrPorts.
if s == "" {
var pretendpoints = sync . OnceValue ( func ( ) ( ret [ ] netip . AddrPort ) {
return
all := envknob . String ( "TS_DEBUG_PRETENDPOINT" )
}
const max = 3
ap , err := netip . ParseAddrPort ( s )
remain := all
if err != nil {
for remain != "" && len ( ret ) < max {
log . Printf ( "ignoring invalid TS_DEBUG_PRETENDPOINT %q: %v" , s , err )
var s string
s , remain , _ = strings . Cut ( remain , "," )
ap , err := netip . ParseAddrPort ( s )
if err != nil {
log . Printf ( "ignoring invalid AddrPort %q in TS_DEBUG_PRETENDPOINT %q: %v" , s , all , err )
continue
}
ret = append ( ret , ap )
}
}
return ap
return
} )
} )