mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-05 14:57:49 +00:00
hostinfo: add FreeBSD support.
Add specific handling for common appliances based on FreeBSD: - pfSense HostInfo: {"OS":"freebsd","OSVersion":"pfSense 2.5.2-RELEASE; version=12.2-STABLE" - OPNsense HostInfo: {"OS":"freebsd","OSVersion":"OPNsense 21.7.1 (amd64/OpenSSL); version=12.1-RELEASE-p19-HBSD" - TrueNAS HostInfo: {"OS":"freebsd","OSVersion":"TrueNAS-12.0-U5.1 (6c639bd48a); version=12.2-RELEASE-p9" - FreeNAS HostInfo: {"OS":"freebsd","OSVersion":"FreeNAS-11.3-U5 (2e4ded5a0a); version=11.3-RELEASE-p14", - regular FreeBSD HostInfo: {"OS":"freebsd","OSVersion":"FreeBSD; version=12.2-RELEASE" Signed-off-by: Denton Gentry <dgentry@tailscale.com>
This commit is contained in:
parent
5a58fd8933
commit
1d1efbb599
60
hostinfo/hostinfo_freebsd.go
Normal file
60
hostinfo/hostinfo_freebsd.go
Normal file
@ -0,0 +1,60 @@
|
||||
// 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.
|
||||
|
||||
//go:build freebsd
|
||||
// +build freebsd
|
||||
|
||||
package hostinfo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
"tailscale.com/version/distro"
|
||||
)
|
||||
|
||||
func init() {
|
||||
osVersion = osVersionFreebsd
|
||||
}
|
||||
|
||||
func osVersionFreebsd() string {
|
||||
un := unix.Utsname{}
|
||||
unix.Uname(&un)
|
||||
|
||||
var attrBuf strings.Builder
|
||||
attrBuf.WriteString("; version=")
|
||||
for _, b := range un.Release {
|
||||
if b == 0 {
|
||||
break
|
||||
}
|
||||
attrBuf.WriteByte(byte(b))
|
||||
}
|
||||
attr := attrBuf.String()
|
||||
|
||||
version := "FreeBSD"
|
||||
switch distro.Get() {
|
||||
case distro.Pfsense:
|
||||
b, _ := os.ReadFile("/etc/version")
|
||||
version = fmt.Sprintf("pfSense %s", b)
|
||||
case distro.OPNsense:
|
||||
b, err := exec.Command("opnsense-version").Output()
|
||||
if err == nil {
|
||||
version = string(b)
|
||||
} else {
|
||||
version = "OPNsense"
|
||||
}
|
||||
case distro.TrueNAS:
|
||||
b, err := os.ReadFile("/etc/version")
|
||||
if err == nil {
|
||||
version = string(b)
|
||||
} else {
|
||||
version = "TrueNAS"
|
||||
}
|
||||
}
|
||||
// the /etc/version files end in a newline
|
||||
return fmt.Sprintf("%s%s", strings.TrimSuffix(version, "\n"), attr)
|
||||
}
|
@ -19,6 +19,9 @@
|
||||
OpenWrt = Distro("openwrt")
|
||||
NixOS = Distro("nixos")
|
||||
QNAP = Distro("qnap")
|
||||
Pfsense = Distro("pfsense")
|
||||
OPNsense = Distro("opnsense")
|
||||
TrueNAS = Distro("truenas")
|
||||
)
|
||||
|
||||
// Get returns the current distro, or the empty string if unknown.
|
||||
@ -26,6 +29,9 @@ func Get() Distro {
|
||||
if runtime.GOOS == "linux" {
|
||||
return linuxDistro()
|
||||
}
|
||||
if runtime.GOOS == "freebsd" {
|
||||
return freebsdDistro()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -56,3 +62,15 @@ func linuxDistro() Distro {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func freebsdDistro() Distro {
|
||||
switch {
|
||||
case have("/etc/pfSense-rc"):
|
||||
return Pfsense
|
||||
case have("/usr/local/sbin/opnsense-shell"):
|
||||
return OPNsense
|
||||
case have("/usr/local/bin/freenas-debug"):
|
||||
return TrueNAS
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user