derp: use new net/tcpinfo package

Updates #8413

Signed-off-by: Andrew Dunham <andrew@du.nham.ca>
Change-Id: I8bf8046517195a6d42cabb32d6ec7f1f79cef860
pull/8471/head
Andrew Dunham 1 year ago
parent d9eca20ee2
commit ab310a7f60

@ -118,6 +118,7 @@ tailscale.com/cmd/derper dependencies: (generated by github.com/tailscale/depawa
tailscale.com/net/packet from tailscale.com/wgengine/filter tailscale.com/net/packet from tailscale.com/wgengine/filter
tailscale.com/net/sockstats from tailscale.com/derp/derphttp tailscale.com/net/sockstats from tailscale.com/derp/derphttp
tailscale.com/net/stun from tailscale.com/cmd/derper tailscale.com/net/stun from tailscale.com/cmd/derper
L tailscale.com/net/tcpinfo from tailscale.com/derp
tailscale.com/net/tlsdial from tailscale.com/derp/derphttp tailscale.com/net/tlsdial from tailscale.com/derp/derphttp
tailscale.com/net/tsaddr from tailscale.com/ipn+ tailscale.com/net/tsaddr from tailscale.com/ipn+
💣 tailscale.com/net/tshttpproxy from tailscale.com/derp/derphttp+ 💣 tailscale.com/net/tshttpproxy from tailscale.com/derp/derphttp+

@ -109,6 +109,7 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep
tailscale.com/net/portmapper from tailscale.com/net/netcheck+ tailscale.com/net/portmapper from tailscale.com/net/netcheck+
tailscale.com/net/sockstats from tailscale.com/control/controlhttp+ tailscale.com/net/sockstats from tailscale.com/control/controlhttp+
tailscale.com/net/stun from tailscale.com/net/netcheck tailscale.com/net/stun from tailscale.com/net/netcheck
L tailscale.com/net/tcpinfo from tailscale.com/derp
tailscale.com/net/tlsdial from tailscale.com/derp/derphttp+ tailscale.com/net/tlsdial from tailscale.com/derp/derphttp+
tailscale.com/net/tsaddr from tailscale.com/net/interfaces+ tailscale.com/net/tsaddr from tailscale.com/net/interfaces+
💣 tailscale.com/net/tshttpproxy from tailscale.com/derp/derphttp+ 💣 tailscale.com/net/tshttpproxy from tailscale.com/derp/derphttp+

@ -276,6 +276,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
tailscale.com/net/socks5 from tailscale.com/cmd/tailscaled tailscale.com/net/socks5 from tailscale.com/cmd/tailscaled
tailscale.com/net/sockstats from tailscale.com/control/controlclient+ tailscale.com/net/sockstats from tailscale.com/control/controlclient+
tailscale.com/net/stun from tailscale.com/net/netcheck+ tailscale.com/net/stun from tailscale.com/net/netcheck+
L tailscale.com/net/tcpinfo from tailscale.com/derp
tailscale.com/net/tlsdial from tailscale.com/control/controlclient+ tailscale.com/net/tlsdial from tailscale.com/control/controlclient+
tailscale.com/net/tsaddr from tailscale.com/ipn+ tailscale.com/net/tsaddr from tailscale.com/ipn+
tailscale.com/net/tsdial from tailscale.com/control/controlclient+ tailscale.com/net/tsdial from tailscale.com/control/controlclient+

@ -9,19 +9,18 @@ import (
"net" "net"
"time" "time"
"golang.org/x/sys/unix" "tailscale.com/net/tcpinfo"
) )
func (c *sclient) statsLoop(ctx context.Context) error { func (c *sclient) statsLoop(ctx context.Context) error {
// If we can't get a TCP socket, then we can't send stats. // Get the RTT initially to verify it's supported.
tcpConn := c.tcpConn() conn := c.tcpConn()
if tcpConn == nil { if conn == nil {
c.s.tcpRtt.Add("non-tcp", 1) c.s.tcpRtt.Add("non-tcp", 1)
return nil return nil
} }
rawConn, err := tcpConn.SyscallConn() if _, err := tcpinfo.RTT(conn); err != nil {
if err != nil { c.logf("error fetching initial RTT: %v", err)
c.logf("error getting SyscallConn: %v", err)
c.s.tcpRtt.Add("error", 1) c.s.tcpRtt.Add("error", 1)
return nil return nil
} }
@ -31,23 +30,16 @@ func (c *sclient) statsLoop(ctx context.Context) error {
ticker := time.NewTicker(statsInterval) ticker := time.NewTicker(statsInterval)
defer ticker.Stop() defer ticker.Stop()
var (
tcpInfo *unix.TCPInfo
sysErr error
)
statsLoop: statsLoop:
for { for {
select { select {
case <-ticker.C: case <-ticker.C:
err = rawConn.Control(func(fd uintptr) { rtt, err := tcpinfo.RTT(conn)
tcpInfo, sysErr = unix.GetsockoptTCPInfo(int(fd), unix.IPPROTO_TCP, unix.TCP_INFO) if err != nil {
})
if err != nil || sysErr != nil {
continue statsLoop continue statsLoop
} }
// TODO(andrew): more metrics? // TODO(andrew): more metrics?
rtt := time.Duration(tcpInfo.Rtt) * time.Microsecond
c.s.tcpRtt.Add(durationToLabel(rtt), 1) c.s.tcpRtt.Add(durationToLabel(rtt), 1)
case <-ctx.Done(): case <-ctx.Done():

Loading…
Cancel
Save