tailscale/net/neterror/neterror_test.go
James Tucker 0b4d702a54
wgengine/magicsock: report health warnings when blocked by firewalls
macOS and Linux both return EPERM when sendto(2) is blocked by the
firewall. Sometimes these blocks and transient, in the case of a fault
between EDR software and a kernel, and at other times this may be a
persistent state.

Report a health warning for the state, and rebind only up to once every
15m in order to avoid excess workload.

Updates #11710
Updates #12891
Updates #13511

Signed-off-by: James Tucker <james@tailscale.com>
2024-09-25 16:44:05 -07:00

55 lines
898 B
Go

// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
package neterror
import (
"errors"
"net"
"os"
"syscall"
"testing"
)
func TestIsEPERM(t *testing.T) {
tests := []struct {
name string
err error
want bool
}{
{"nil", nil, false},
{"non-nil", errors.New("foo"), false},
{"eperm", syscall.EPERM, true},
{
name: "operror",
err: &net.OpError{
Op: "write",
Err: &os.SyscallError{
Syscall: "sendto",
Err: syscall.EPERM,
},
},
want: true,
},
{
name: "host_unreach",
err: &net.OpError{
Op: "write",
Err: &os.SyscallError{
Syscall: "sendto",
Err: syscall.EHOSTUNREACH,
},
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsEPERM(tt.err); got != tt.want {
t.Errorf("got = %v; want %v", got, tt.want)
}
})
}
}