wgengine/router/dns: remove unsafe endianness detection on Linux

This commit is contained in:
Brad Fitzpatrick
2020-12-21 13:11:09 -08:00
parent f9659323df
commit 15c064f76f
3 changed files with 6 additions and 22 deletions

View File

@ -10,30 +10,14 @@ import (
"bufio"
"bytes"
"context"
"encoding/binary"
"fmt"
"os"
"os/exec"
"unsafe"
"github.com/godbus/dbus/v5"
"tailscale.com/util/endian"
)
var nativeEndian binary.ByteOrder
func init() {
// TODO(dmytro): use DBus endianness flag when available.
// A more elegant way to do this is by looking at the first byte of a raw DBus message.
// However, that requires a change in godbus, which has slow maintainer response.
i := uint32(1)
p := unsafe.Pointer(&i)
if *(*byte)(p) == 1 {
nativeEndian = binary.LittleEndian
} else {
nativeEndian = binary.BigEndian
}
}
// isNMActive determines if NetworkManager is currently managing system DNS settings.
func isNMActive() bool {
// This is somewhat tricky because NetworkManager supports a number
@ -145,7 +129,7 @@ func (m nmManager) Up(config Config) error {
for _, ip := range config.Nameservers {
b := ip.As16()
if ip.Is4() {
dnsv4 = append(dnsv4, nativeEndian.Uint32(b[12:]))
dnsv4 = append(dnsv4, endian.Native.Uint32(b[12:]))
} else {
dnsv6 = append(dnsv6, b[:])
}