mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-11 21:27:31 +00:00
cmd/tailscale: add debug commands to break connections
For testing reconnects. Updates tailscale/corp#5761 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
99e06d3544
commit
92fc9a01fa
30
ipn/ipnlocal/breaktcp_darwin.go
Normal file
30
ipn/ipnlocal/breaktcp_darwin.go
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
package ipnlocal
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func init() {
|
||||
breakTCPConns = breakTCPConnsDarwin
|
||||
}
|
||||
|
||||
func breakTCPConnsDarwin() error {
|
||||
var matched int
|
||||
for fd := 0; fd < 1000; fd++ {
|
||||
_, err := unix.GetsockoptTCPConnectionInfo(fd, unix.IPPROTO_TCP, unix.TCP_CONNECTION_INFO)
|
||||
if err == nil {
|
||||
matched++
|
||||
err = unix.Close(fd)
|
||||
log.Printf("debug: closed TCP fd %v: %v", fd, err)
|
||||
}
|
||||
}
|
||||
if matched == 0 {
|
||||
log.Printf("debug: no TCP connections found")
|
||||
}
|
||||
return nil
|
||||
}
|
30
ipn/ipnlocal/breaktcp_linux.go
Normal file
30
ipn/ipnlocal/breaktcp_linux.go
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
package ipnlocal
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func init() {
|
||||
breakTCPConns = breakTCPConnsLinux
|
||||
}
|
||||
|
||||
func breakTCPConnsLinux() error {
|
||||
var matched int
|
||||
for fd := 0; fd < 1000; fd++ {
|
||||
_, err := unix.GetsockoptTCPInfo(fd, unix.IPPROTO_TCP, unix.TCP_INFO)
|
||||
if err == nil {
|
||||
matched++
|
||||
err = unix.Close(fd)
|
||||
log.Printf("debug: closed TCP fd %v: %v", fd, err)
|
||||
}
|
||||
}
|
||||
if matched == 0 {
|
||||
log.Printf("debug: no TCP connections found")
|
||||
}
|
||||
return nil
|
||||
}
|
@@ -5026,3 +5026,20 @@ func (b *LocalBackend) GetPeerEndpointChanges(ctx context.Context, ip netip.Addr
|
||||
}
|
||||
return chs, nil
|
||||
}
|
||||
|
||||
var breakTCPConns func() error
|
||||
|
||||
func (b *LocalBackend) DebugBreakTCPConns() error {
|
||||
if breakTCPConns == nil {
|
||||
return errors.New("TCP connection breaking not available on this platform")
|
||||
}
|
||||
return breakTCPConns()
|
||||
}
|
||||
|
||||
func (b *LocalBackend) DebugBreakDERPConns() error {
|
||||
mc, err := b.magicConn()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return mc.DebugBreakDERPConns()
|
||||
}
|
||||
|
@@ -559,7 +559,10 @@ func (h *Handler) serveDebug(w http.ResponseWriter, r *http.Request) {
|
||||
break
|
||||
}
|
||||
h.b.DebugNotify(n)
|
||||
|
||||
case "break-tcp-conns":
|
||||
err = h.b.DebugBreakTCPConns()
|
||||
case "break-derp-conns":
|
||||
err = h.b.DebugBreakDERPConns()
|
||||
case "":
|
||||
err = fmt.Errorf("missing parameter 'action'")
|
||||
default:
|
||||
|
Reference in New Issue
Block a user