2025-01-06 12:32:13 -08:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
|
|
|
//go:build !plan9
|
|
|
|
|
|
|
|
package magicsock
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
2025-01-06 13:10:56 -08:00
|
|
|
// shouldRebind returns if the error is one that is known to be healed by a
|
|
|
|
// rebind, and if so also returns a resason string for the rebind.
|
|
|
|
func shouldRebind(err error) (ok bool, reason string) {
|
2025-01-06 12:32:13 -08:00
|
|
|
switch {
|
2025-01-06 13:10:56 -08:00
|
|
|
// EPIPE/ENOTCONN are common errors when a send fails due to a closed
|
|
|
|
// socket. There is some platform and version inconsistency in which
|
|
|
|
// error is returned, but the meaning is the same.
|
|
|
|
case errors.Is(err, syscall.EPIPE), errors.Is(err, syscall.ENOTCONN):
|
|
|
|
return true, "broken-pipe"
|
|
|
|
|
|
|
|
// EPERM is typically caused by EDR software, and has been observed to be
|
|
|
|
// transient, it seems that some versions of some EDR lose track of sockets
|
|
|
|
// at times, and return EPERM, but reconnects will establish appropriate
|
|
|
|
// rights associated with a new socket.
|
2025-01-06 12:32:13 -08:00
|
|
|
case errors.Is(err, syscall.EPERM):
|
2025-01-06 13:10:56 -08:00
|
|
|
return true, "operation-not-permitted"
|
2025-01-06 12:32:13 -08:00
|
|
|
}
|
2025-01-06 13:10:56 -08:00
|
|
|
return false, ""
|
2025-01-06 12:32:13 -08:00
|
|
|
}
|