mirror of
https://github.com/slackhq/nebula.git
synced 2026-11-15 10:36:52 +01:00
smoke-extra / freebsd-amd64 (push) Failing after 25s
smoke-extra / linux-amd64-ipv6disable (push) Failing after 13s
smoke-extra / netbsd-amd64 (push) Failing after 11s
smoke-extra / openbsd-amd64 (push) Failing after 12s
smoke-extra / linux-386 (push) Failing after 14s
smoke / Run multi node smoke test (push) Failing after 1m43s
Build and test / Static checks (push) Successful in 2m25s
Build and test / Test linux (push) Failing after 1m28s
Build and test / Test linux-pkcs11 (push) Failing after 2m5s
Build and test / Test linux-boringcrypto (push) Failing after 2m56s
Build and test / Test linux-fips140 (push) Failing after 3m3s
Build and test / Cross-build linux-arm (push) Successful in 3m14s
Build and test / Cross-build linux-mips (push) Successful in 3m48s
Build and test / Cross-build linux-other (push) Successful in 3m13s
Build and test / Cross-build windows (push) Successful in 1m3s
Build and test / Cross-build freebsd (push) Successful in 1m34s
Build and test / Cross-build netbsd (push) Successful in 1m36s
Build and test / Cross-build openbsd (push) Successful in 1m37s
Build and test / Cross-build mobile (push) Successful in 3m33s
smoke / Run self traffic smoke test on macOS (push) Canceled after 0s
Build and test / Test macos (push) Canceled after 0s
Build and test / Test windows (push) Canceled after 0s
Build and test / CI status (push) Canceled after 0s
smoke-extra / Run windows smoke test (push) Canceled after 0s
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
//go:build (openbsd || netbsd) && !e2e_testing
|
|
|
|
package overlay
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"log/slog"
|
|
"os"
|
|
"regexp"
|
|
"runtime"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
var deviceNameRE = regexp.MustCompile(`^tun[0-9]+$`)
|
|
|
|
// tunDevNeedsRestart is true when tun.dev asks for a particular tun that isn't the running one. Anything else takes the
|
|
// first free one, and the one we have will do
|
|
func tunDevNeedsRestart(name, running string) bool {
|
|
return deviceNameRE.MatchString(name) && name != running
|
|
}
|
|
|
|
// openTun opens /dev/name, or the first /dev/tunN nothing else has open when name is empty or not tunN
|
|
func openTun(l *slog.Logger, name string) (int, string, error) {
|
|
if name != "" && !deviceNameRE.MatchString(name) {
|
|
// The name doesn't mean anything here, so like darwin a bad one isn't worth refusing to start over
|
|
l.Warn("interface name must be tun[0-9]+ on "+runtime.GOOS+", ignoring", "name", name)
|
|
name = ""
|
|
}
|
|
if name != "" {
|
|
fd, err := unix.Open("/dev/"+name, os.O_RDWR, 0)
|
|
return fd, name, err
|
|
}
|
|
for i := 0; ; i++ {
|
|
name = fmt.Sprintf("tun%d", i)
|
|
fd, err := unix.Open("/dev/"+name, os.O_RDWR, 0)
|
|
if err == nil {
|
|
return fd, name, nil
|
|
}
|
|
if !errors.Is(err, unix.EBUSY) {
|
|
return -1, "", fmt.Errorf("no free tun device, %s: %w", name, err)
|
|
}
|
|
}
|
|
}
|