router/dns: detect host endianness for NetworkManager.

Signed-off-by: Dmytro Shynkevych <dmytro@tailscale.com>
pull/674/head
Dmytro Shynkevych 4 years ago
parent b97aac1718
commit 95a18f815c
No known key found for this signature in database
GPG Key ID: FF5E2F3DAD97EA23

@ -14,11 +14,25 @@ import (
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
"unsafe"
"github.com/godbus/dbus/v5" "github.com/godbus/dbus/v5"
) )
type nmConnectionSettings map[string]map[string]dbus.Variant 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. // isNMActive determines if NetworkManager is currently managing system DNS settings.
func isNMActive() bool { func isNMActive() bool {
@ -61,6 +75,8 @@ func newNMManager(mconfig ManagerConfig) managerImpl {
} }
} }
type nmConnectionSettings map[string]map[string]dbus.Variant
// Up implements managerImpl. // Up implements managerImpl.
func (m nmManager) Up(config Config) error { func (m nmManager) Up(config Config) error {
ctx, cancel := context.WithTimeout(context.Background(), reconfigTimeout) ctx, cancel := context.WithTimeout(context.Background(), reconfigTimeout)
@ -129,7 +145,7 @@ func (m nmManager) Up(config Config) error {
for _, ip := range config.Nameservers { for _, ip := range config.Nameservers {
b := ip.As16() b := ip.As16()
if ip.Is4() { if ip.Is4() {
dnsv4 = append(dnsv4, binary.LittleEndian.Uint32(b[12:])) dnsv4 = append(dnsv4, nativeEndian.Uint32(b[12:]))
} else { } else {
dnsv6 = append(dnsv6, b[:]) dnsv6 = append(dnsv6, b[:])
} }

Loading…
Cancel
Save