← Writing

Bield · 3 min read

Why Bield doesn't trust the first ping

Ping a quiet Tailscale peer and the answer comes back through DERP, even when the machine is direct. Here's how Bield works out the real path.

Ping a Tailscale peer once a minute, believe the first answer, and you'll decide almost every machine on your tailnet goes through DERP. Most of them don't.

Some background first. Tailscale tries to connect two machines directly over WireGuard. When a NAT or a firewall gets in the way, the traffic goes through a relay instead. Usually that's DERP, Tailscale's shared relay servers. Lately it can also be a peer relay, a machine of your own doing the same job. Bield shows which of the three each machine uses. On the Overview map a solid line is direct and a dashed one is relayed, with the round-trip time next to it.

To find out, Bield sends each online machine a disco ping once a minute. That's Tailscale's own path ping, the one tailscale ping uses, and the reply says how it travelled: straight from the machine, through a DERP region, or through a peer relay.

The first answer

When a connection has been quiet for a while, Tailscale lets the direct path go idle. The next packet goes through DERP while Tailscale finds the direct path again. A ping once a minute is always "the next packet", so nearly every reply came back through DERP.

tailscale ping already handles this. It just keeps pinging until a reply comes back some other way. Bield does the same now. If a reply comes through DERP, it sends up to four more, a second apart, and stops at the first one that doesn't. I didn't expect it to take that many. On a real tailnet, a peer relay path that had been idle for a minute answered three pings through DERP before the fourth came through the relay. And if a retry gets no reply at all, Bield keeps the DERP answer it already has, because that's still a true answer about how it got there.

Something else that surprised me: the tailscale netcheck you run in a terminal isn't in tailscaled's local API, so a program can't ask for it. Bield runs the same check inside its own process every ten minutes, with its node's DERP map, to know whether UDP gets out and which DERP region is nearest.

When to worry

A machine that's relayed now and then isn't news. A server that was direct all last week and has been going through DERP for five minutes might be. Maybe a firewall rule changed, or its public address did.

So Bield counts. Every reply through DERP or a peer relay adds one. A direct reply sets the count back to zero, and a ping with no reply leaves it where it was. When a machine goes offline the count starts over, because every new connection starts out relayed and that shouldn't count against it. Five in a row, for a machine that was direct sometime in the past week, opens an alert.

It's on for servers and off for everything else. A laptop on café Wi-Fi is relayed half the time, and I don't need a notification about it.

Peer relays

A peer relay is often faster than DERP, because you get to put it somewhere close. When Bield reaches machines through DERP, its Peer relay page suggests one of your machines for the job. It looks for one Bield reaches directly, preferably a server with a public address that hasn't just rebooted and isn't far from Bield. Then it gives you the command to run on that machine and the grant to add to your tailnet policy. Bield can't do either of those for you. bield relay prints the same thing in a terminal. On Headscale the page doesn't show up at all, since Headscale doesn't support peer relays in a release yet.

A side effect we didn't see coming: VS Code in the browser gives up after 10 seconds and says "The editor failed to load". Its first load is about 6 MB, and through a relay that can take longer than 10 seconds. Bield now gives it two minutes before it calls it a failure.

What Bield can't tell you is the part I'd most like to know. It only sees its own connections. It can tell you it reaches your NAS through DERP. It can't tell you whether your laptop does.

Get in touch

Tell us about one of our products, or about a project you have in mind.