mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 13:05:46 +00:00
wgengine/magicsock: add side-effect-free function for netcheck UDP sends (#13487)
Updates #13484 Updates tailscale/corp#17879 Signed-off-by: Jordan Whited <jordan@tailscale.com>
This commit is contained in:
parent
8012bb4216
commit
4084c6186d
@ -493,13 +493,7 @@ func NewConn(opts Options) (*Conn, error) {
|
|||||||
c.netChecker = &netcheck.Client{
|
c.netChecker = &netcheck.Client{
|
||||||
Logf: logger.WithPrefix(c.logf, "netcheck: "),
|
Logf: logger.WithPrefix(c.logf, "netcheck: "),
|
||||||
NetMon: c.netMon,
|
NetMon: c.netMon,
|
||||||
SendPacket: func(b []byte, ap netip.AddrPort) (int, error) {
|
SendPacket: c.sendUDPNetcheck,
|
||||||
ok, err := c.sendUDP(ap, b)
|
|
||||||
if !ok {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return len(b), err
|
|
||||||
},
|
|
||||||
SkipExternalNetwork: inTest(),
|
SkipExternalNetwork: inTest(),
|
||||||
PortMapper: c.portMapper,
|
PortMapper: c.portMapper,
|
||||||
UseDNSCache: true,
|
UseDNSCache: true,
|
||||||
@ -582,7 +576,7 @@ func (c *Conn) updateEndpoints(why string) {
|
|||||||
c.muCond.Broadcast()
|
c.muCond.Broadcast()
|
||||||
}()
|
}()
|
||||||
c.dlogf("[v1] magicsock: starting endpoint update (%s)", why)
|
c.dlogf("[v1] magicsock: starting endpoint update (%s)", why)
|
||||||
if c.noV4Send.Load() && runtime.GOOS != "js" {
|
if c.noV4Send.Load() && runtime.GOOS != "js" && !c.onlyTCP443.Load() {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
closed := c.closed
|
closed := c.closed
|
||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
@ -1175,6 +1169,24 @@ func (c *Conn) maybeRebindOnError(os string, err error) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sendUDPNetcheck sends b via UDP to addr. It is used exclusively by netcheck.
|
||||||
|
// It returns the number of bytes sent along with any error encountered. It
|
||||||
|
// returns errors.ErrUnsupported if the client is explicitly configured to only
|
||||||
|
// send data over TCP port 443 and/or we're running on wasm.
|
||||||
|
func (c *Conn) sendUDPNetcheck(b []byte, addr netip.AddrPort) (int, error) {
|
||||||
|
if c.onlyTCP443.Load() || runtime.GOOS == "js" {
|
||||||
|
return 0, errors.ErrUnsupported
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case addr.Addr().Is4():
|
||||||
|
return c.pconn4.WriteToUDPAddrPort(b, addr)
|
||||||
|
case addr.Addr().Is6():
|
||||||
|
return c.pconn6.WriteToUDPAddrPort(b, addr)
|
||||||
|
default:
|
||||||
|
panic("bogus sendUDPNetcheck addr type")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// sendUDP sends UDP packet b to addr.
|
// sendUDP sends UDP packet b to addr.
|
||||||
// See sendAddr's docs on the return value meanings.
|
// See sendAddr's docs on the return value meanings.
|
||||||
func (c *Conn) sendUDPStd(addr netip.AddrPort, b []byte) (sent bool, err error) {
|
func (c *Conn) sendUDPStd(addr netip.AddrPort, b []byte) (sent bool, err error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user