mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-24 12:19:07 +00:00
ipn/localapi: make tailscale debug derp STUNOnly-aware (#16927)
Fixes #16926 Signed-off-by: Jordan Whited <jordan@tailscale.com>
This commit is contained in:
@@ -228,55 +228,59 @@ func (h *Handler) serveDebugDERPRegion(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// Start by checking whether we can establish a HTTP connection
|
// Start by checking whether we can establish a HTTP connection
|
||||||
for _, derpNode := range reg.Nodes {
|
for _, derpNode := range reg.Nodes {
|
||||||
connSuccess := checkConn(derpNode)
|
if !derpNode.STUNOnly {
|
||||||
|
connSuccess := checkConn(derpNode)
|
||||||
|
|
||||||
// Verify that the /generate_204 endpoint works
|
// Verify that the /generate_204 endpoint works
|
||||||
captivePortalURL := fmt.Sprintf("http://%s/generate_204?t=%d", derpNode.HostName, time.Now().Unix())
|
captivePortalURL := fmt.Sprintf("http://%s/generate_204?t=%d", derpNode.HostName, time.Now().Unix())
|
||||||
req, err := http.NewRequest("GET", captivePortalURL, nil)
|
req, err := http.NewRequest("GET", captivePortalURL, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
st.Warnings = append(st.Warnings, fmt.Sprintf("Internal error creating request for captive portal check: %v", err))
|
st.Warnings = append(st.Warnings, fmt.Sprintf("Internal error creating request for captive portal check: %v", err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
req.Header.Set("Cache-Control", "no-cache, no-store, must-revalidate, no-transform, max-age=0")
|
req.Header.Set("Cache-Control", "no-cache, no-store, must-revalidate, no-transform, max-age=0")
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
st.Warnings = append(st.Warnings, fmt.Sprintf("Error making request to the captive portal check %q; is port 80 blocked?", captivePortalURL))
|
st.Warnings = append(st.Warnings, fmt.Sprintf("Error making request to the captive portal check %q; is port 80 blocked?", captivePortalURL))
|
||||||
} else {
|
} else {
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
if !connSuccess {
|
if !connSuccess {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
fakePrivKey := key.NewNode()
|
fakePrivKey := key.NewNode()
|
||||||
|
|
||||||
// Next, repeatedly get the server key to see if the node is
|
// Next, repeatedly get the server key to see if the node is
|
||||||
// behind a load balancer (incorrectly).
|
// behind a load balancer (incorrectly).
|
||||||
serverPubKeys := make(map[key.NodePublic]bool)
|
serverPubKeys := make(map[key.NodePublic]bool)
|
||||||
for i := range 5 {
|
for i := range 5 {
|
||||||
func() {
|
func() {
|
||||||
rc := derphttp.NewRegionClient(fakePrivKey, h.logf, h.b.NetMon(), func() *tailcfg.DERPRegion {
|
rc := derphttp.NewRegionClient(fakePrivKey, h.logf, h.b.NetMon(), func() *tailcfg.DERPRegion {
|
||||||
return &tailcfg.DERPRegion{
|
return &tailcfg.DERPRegion{
|
||||||
RegionID: reg.RegionID,
|
RegionID: reg.RegionID,
|
||||||
RegionCode: reg.RegionCode,
|
RegionCode: reg.RegionCode,
|
||||||
RegionName: reg.RegionName,
|
RegionName: reg.RegionName,
|
||||||
Nodes: []*tailcfg.DERPNode{derpNode},
|
Nodes: []*tailcfg.DERPNode{derpNode},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if err := rc.Connect(ctx); err != nil {
|
||||||
|
st.Errors = append(st.Errors, fmt.Sprintf("Error connecting to node %q @ try %d: %v", derpNode.HostName, i, err))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
})
|
|
||||||
if err := rc.Connect(ctx); err != nil {
|
|
||||||
st.Errors = append(st.Errors, fmt.Sprintf("Error connecting to node %q @ try %d: %v", derpNode.HostName, i, err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(serverPubKeys) == 0 {
|
if len(serverPubKeys) == 0 {
|
||||||
st.Info = append(st.Info, fmt.Sprintf("Successfully established a DERP connection with node %q", derpNode.HostName))
|
st.Info = append(st.Info, fmt.Sprintf("Successfully established a DERP connection with node %q", derpNode.HostName))
|
||||||
}
|
}
|
||||||
serverPubKeys[rc.ServerPublicKey()] = true
|
serverPubKeys[rc.ServerPublicKey()] = true
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
if len(serverPubKeys) > 1 {
|
if len(serverPubKeys) > 1 {
|
||||||
st.Errors = append(st.Errors, fmt.Sprintf("Received multiple server public keys (%d); is the DERP server behind a load balancer?", len(serverPubKeys)))
|
st.Errors = append(st.Errors, fmt.Sprintf("Received multiple server public keys (%d); is the DERP server behind a load balancer?", len(serverPubKeys)))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
st.Info = append(st.Info, fmt.Sprintf("Node %q is marked STUNOnly; skipped non-STUN checks", derpNode.HostName))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send a STUN query to this node to verify whether or not it
|
// Send a STUN query to this node to verify whether or not it
|
||||||
|
Reference in New Issue
Block a user