mirror of
https://github.com/tailscale/tailscale.git
synced 2025-05-07 08:07:16 +00:00
net/{neterror,dns/resolver}: move PacketWasTruncated to neterror from DNS code
And delete the unused code in net/dns/resolver/neterr_*.go. Change-Id: Ibe62c486bacce2733eb9968c96a98cbbdb2758bd Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
dd45bba76b
commit
2513d2d728
@ -25,6 +25,7 @@ import (
|
|||||||
dns "golang.org/x/net/dns/dnsmessage"
|
dns "golang.org/x/net/dns/dnsmessage"
|
||||||
"inet.af/netaddr"
|
"inet.af/netaddr"
|
||||||
"tailscale.com/hostinfo"
|
"tailscale.com/hostinfo"
|
||||||
|
"tailscale.com/net/neterror"
|
||||||
"tailscale.com/net/netns"
|
"tailscale.com/net/netns"
|
||||||
"tailscale.com/net/tsdial"
|
"tailscale.com/net/tsdial"
|
||||||
"tailscale.com/types/dnstype"
|
"tailscale.com/types/dnstype"
|
||||||
@ -482,7 +483,7 @@ func (f *forwarder) send(ctx context.Context, fq *forwardQuery, rr resolverAndDe
|
|||||||
if err := ctx.Err(); err != nil {
|
if err := ctx.Err(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if packetWasTruncated(err) {
|
if neterror.PacketWasTruncated(err) {
|
||||||
err = nil
|
err = nil
|
||||||
} else {
|
} else {
|
||||||
metricDNSFwdUDPErrorRead.Add(1)
|
metricDNSFwdUDPErrorRead.Add(1)
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package resolver
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Avoid allocation when calling errors.Is below
|
|
||||||
// by converting syscall.Errno to error here.
|
|
||||||
var (
|
|
||||||
networkDown error = syscall.ENETDOWN
|
|
||||||
networkUnreachable error = syscall.ENETUNREACH
|
|
||||||
)
|
|
||||||
|
|
||||||
func networkIsDown(err error) bool {
|
|
||||||
return errors.Is(err, networkDown)
|
|
||||||
}
|
|
||||||
|
|
||||||
func networkIsUnreachable(err error) bool {
|
|
||||||
return errors.Is(err, networkUnreachable)
|
|
||||||
}
|
|
||||||
|
|
||||||
// packetWasTruncated returns true if err indicates truncation but the RecvFrom
|
|
||||||
// that generated err was otherwise successful. It always returns false on this
|
|
||||||
// platform.
|
|
||||||
func packetWasTruncated(err error) bool { return false }
|
|
@ -1,16 +0,0 @@
|
|||||||
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
//go:build !darwin && !windows
|
|
||||||
// +build !darwin,!windows
|
|
||||||
|
|
||||||
package resolver
|
|
||||||
|
|
||||||
func networkIsDown(err error) bool { return false }
|
|
||||||
func networkIsUnreachable(err error) bool { return false }
|
|
||||||
|
|
||||||
// packetWasTruncated returns true if err indicates truncation but the RecvFrom
|
|
||||||
// that generated err was otherwise successful. It always returns false on this
|
|
||||||
// platform.
|
|
||||||
func packetWasTruncated(err error) bool { return false }
|
|
@ -1,43 +0,0 @@
|
|||||||
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package resolver
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"net"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"golang.org/x/sys/windows"
|
|
||||||
)
|
|
||||||
|
|
||||||
func networkIsDown(err error) bool {
|
|
||||||
if oe, ok := err.(*net.OpError); ok && oe.Op == "write" {
|
|
||||||
if se, ok := oe.Err.(*os.SyscallError); ok {
|
|
||||||
if se.Syscall == "wsasendto" && se.Err == windows.WSAENETUNREACH {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func networkIsUnreachable(err error) bool {
|
|
||||||
// TODO(bradfitz,josharian): something here? what is the
|
|
||||||
// difference between down and unreachable? Add comments.
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// packetWasTruncated returns true if err indicates truncation but the RecvFrom
|
|
||||||
// that generated err was otherwise successful. On Windows, Go's UDP RecvFrom
|
|
||||||
// calls WSARecvFrom which returns the WSAEMSGSIZE error code when the received
|
|
||||||
// datagram is larger than the provided buffer. When that happens, both a valid
|
|
||||||
// size and an error are returned (as per the partial fix for golang/go#14074).
|
|
||||||
// If the WSAEMSGSIZE error is returned, then we ignore the error to get
|
|
||||||
// semantics similar to the POSIX operating systems. One caveat is that it
|
|
||||||
// appears that the source address is not returned when WSAEMSGSIZE occurs, but
|
|
||||||
// we do not currently look at the source address.
|
|
||||||
func packetWasTruncated(err error) bool {
|
|
||||||
return errors.Is(err, windows.WSAEMSGSIZE)
|
|
||||||
}
|
|
@ -40,3 +40,21 @@ func TreatAsLostUDP(err error) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var packetWasTruncated func(error) bool // non-nil on Windows at least
|
||||||
|
|
||||||
|
// PacketWasTruncated reports whether err indicates truncation but the RecvFrom
|
||||||
|
// that generated err was otherwise successful. On Windows, Go's UDP RecvFrom
|
||||||
|
// calls WSARecvFrom which returns the WSAEMSGSIZE error code when the received
|
||||||
|
// datagram is larger than the provided buffer. When that happens, both a valid
|
||||||
|
// size and an error are returned (as per the partial fix for golang/go#14074).
|
||||||
|
// If the WSAEMSGSIZE error is returned, then we ignore the error to get
|
||||||
|
// semantics similar to the POSIX operating systems. One caveat is that it
|
||||||
|
// appears that the source address is not returned when WSAEMSGSIZE occurs, but
|
||||||
|
// we do not currently look at the source address.
|
||||||
|
func PacketWasTruncated(err error) bool {
|
||||||
|
if packetWasTruncated == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return packetWasTruncated(err)
|
||||||
|
}
|
||||||
|
17
net/neterror/neterror_windows.go
Normal file
17
net/neterror/neterror_windows.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package neterror
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
packetWasTruncated = func(err error) bool {
|
||||||
|
return errors.Is(err, windows.WSAEMSGSIZE)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user