mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-26 03:26:26 -08:00
feature/relayserver: report the bound UDP port in debug status
Report the actual IPv4 port when RelayServerPort is zero. This allows callers to construct an endpoint for a randomly assigned port. Test fixed, automatic, and stopped server configurations.
This commit is contained in:
1 parent
58f61fd003
commit
fd5fdf7334
4 files changed
+32
-5
No files matched your search
@@ -90,6 +90,7 @@ type relayServer interface {
|
||||
GetSessions() []status.ServerSession
|
||||
SetDERPMapView(tailcfg.DERPMapView)
|
||||
SetStaticAddrPorts(addrPorts views.Slice[netip.AddrPort])
|
||||
Port() uint16
|
||||
}
|
||||
|
||||
// extension is an [ipnext.Extension] managing the relay server on platforms
|
||||
@@ -266,7 +267,7 @@ func (e *extension) serverStatus() status.ServerStatus {
|
||||
if e.rs == nil {
|
||||
return st
|
||||
}
|
||||
st.UDPPort = new(*e.port)
|
||||
st.UDPPort = new(e.rs.Port())
|
||||
st.Sessions = e.rs.GetSessions()
|
||||
return st
|
||||
}
|
||||
@@ -21,6 +21,27 @@ import (
|
||||
"tailscale.com/types/views"
|
||||
)
|
||||
|
||||
func TestServerStatusPort(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
configured *uint16
|
||||
server relayServer
|
||||
want *uint16
|
||||
}{
|
||||
{name: "disabled"},
|
||||
{name: "not-running", configured: new(uint16(1234))},
|
||||
{name: "fixed", configured: new(uint16(1234)), server: &mockRelayServer{port: 1234}, want: new(uint16(1234))},
|
||||
{name: "automatic", configured: new(uint16(0)), server: &mockRelayServer{port: 5678}, want: new(uint16(5678))},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
e := &extension{port: tt.configured, rs: tt.server}
|
||||
if got := e.serverStatus().UDPPort; !reflect.DeepEqual(got, tt.want) {
|
||||
t.Fatalf("UDPPort = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_extension_profileStateChanged(t *testing.T) {
|
||||
prefsWithPortOne := ipn.Prefs{RelayServerPort: new(uint16(1))}
|
||||
prefsWithNilPort := ipn.Prefs{RelayServerPort: nil}
|
||||
@@ -246,6 +267,7 @@ func mockRelayServerNotZeroVal() *mockRelayServer {
|
||||
type mockRelayServer struct {
|
||||
set bool
|
||||
addrPorts views.Slice[netip.AddrPort]
|
||||
port uint16
|
||||
}
|
||||
|
||||
func (m *mockRelayServer) Close() error { return nil }
|
||||
@@ -254,6 +276,7 @@ func (m *mockRelayServer) AllocateEndpoint(_, _ key.DiscoPublic) (endpoint.Serve
|
||||
}
|
||||
func (m *mockRelayServer) GetSessions() []status.ServerSession { return nil }
|
||||
func (m *mockRelayServer) SetDERPMapView(tailcfg.DERPMapView) { return }
|
||||
func (m *mockRelayServer) Port() uint16 { return m.port }
|
||||
func (m *mockRelayServer) SetStaticAddrPorts(aps views.Slice[netip.AddrPort]) {
|
||||
m.addrPorts = aps
|
||||
}
|
||||
|
||||
@@ -1068,6 +1068,11 @@ func (e *serverEndpoint) extractClientInfo() [2]status.ClientInfo {
|
||||
return ret
|
||||
}
|
||||
|
||||
// Port returns the UDP port bound by the server's IPv4 sockets.
|
||||
func (s *Server) Port() uint16 {
|
||||
return s.uc4Port
|
||||
}
|
||||
|
||||
// GetSessions returns a slice of peer relay session statuses, with each
|
||||
// entry containing detailed info about the server and clients involved in
|
||||
// each session. This information is intended for debugging/status UX, and
|
||||
|
||||
@@ -12,10 +12,8 @@ import (
|
||||
// ServerStatus contains the listening UDP port and active sessions (if any) for
|
||||
// this node's peer relay server at a point in time.
|
||||
type ServerStatus struct {
|
||||
// UDPPort is the UDP port number that the peer relay server forwards over,
|
||||
// as configured by the user with 'tailscale set --relay-server-port=<PORT>'.
|
||||
// If the port has not been configured, UDPPort will be nil. A non-nil zero
|
||||
// value signifies the user has opted for a random unused port.
|
||||
// UDPPort is the server's bound IPv4 UDP port, or nil if it is not running.
|
||||
// If the configured port is zero, UDPPort reports the chosen port.
|
||||
UDPPort *uint16
|
||||
// Sessions is a slice of detailed status information about each peer
|
||||
// relay session that this node's peer relay server is involved with. It
|
||||
|
||||
Reference in new issue
Block a user