Skip to content

Commit

Permalink
all: use Go 1.21's binary.NativeEndian
Browse files Browse the repository at this point in the history
We still use josharian/native (hi @josharian!) via
netlink, but I also sent mdlayher/netlink#220

Updates #8632

Change-Id: I2eedcb7facb36ec894aee7f152c8a1f56d7fc8ba
Signed-off-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
bradfitz committed Jan 13, 2025
1 parent 69b9074 commit 7aa64f3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ require (
github.com/inetaf/tcpproxy v0.0.0-20240214030015-3ce58045626c
github.com/insomniacslk/dhcp v0.0.0-20231206064809-8c70d406f6d2
github.com/jellydator/ttlcache/v3 v3.1.0
github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86
github.com/jsimonetti/rtnetlink v1.4.0
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/klauspost/compress v1.17.11
Expand Down Expand Up @@ -152,6 +151,7 @@ require (
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd // indirect
github.com/gorilla/securecookie v1.1.2 // indirect
github.com/jjti/go-spancheck v0.5.3 // indirect
github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86 // indirect
github.com/karamaru-alpha/copyloopvar v1.0.8 // indirect
github.com/macabu/inamedparam v0.1.3 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions net/dns/nm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ package dns

import (
"context"
"encoding/binary"
"fmt"
"net"
"net/netip"
"sort"
"time"

"github.com/godbus/dbus/v5"
"github.com/josharian/native"
"tailscale.com/net/tsaddr"
"tailscale.com/util/dnsname"
)
Expand Down Expand Up @@ -137,7 +137,7 @@ func (m *nmManager) trySet(ctx context.Context, config OSConfig) error {
for _, ip := range config.Nameservers {
b := ip.As16()
if ip.Is4() {
dnsv4 = append(dnsv4, native.Endian.Uint32(b[12:]))
dnsv4 = append(dnsv4, binary.NativeEndian.Uint32(b[12:]))
} else {
dnsv6 = append(dnsv6, b[:])
}
Expand Down
9 changes: 4 additions & 5 deletions util/cstruct/cstruct.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
package cstruct

import (
"encoding/binary"
"errors"
"io"

"github.com/josharian/native"
)

// Size of a pointer-typed value, in bits
Expand Down Expand Up @@ -120,7 +119,7 @@ func (d *Decoder) Uint16() uint16 {
d.err = err
return 0
}
return native.Endian.Uint16(d.dbuf[0:2])
return binary.NativeEndian.Uint16(d.dbuf[0:2])
}

// Uint32 returns a uint32 decoded from the buffer.
Expand All @@ -133,7 +132,7 @@ func (d *Decoder) Uint32() uint32 {
d.err = err
return 0
}
return native.Endian.Uint32(d.dbuf[0:4])
return binary.NativeEndian.Uint32(d.dbuf[0:4])
}

// Uint64 returns a uint64 decoded from the buffer.
Expand All @@ -146,7 +145,7 @@ func (d *Decoder) Uint64() uint64 {
d.err = err
return 0
}
return native.Endian.Uint64(d.dbuf[0:8])
return binary.NativeEndian.Uint64(d.dbuf[0:8])
}

// Uintptr returns a uintptr decoded from the buffer.
Expand Down
6 changes: 3 additions & 3 deletions util/linuxfw/nftables.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ package linuxfw

import (
"cmp"
"encoding/binary"
"fmt"
"sort"
"strings"

"github.com/google/nftables"
"github.com/google/nftables/expr"
"github.com/google/nftables/xt"
"github.com/josharian/native"
"golang.org/x/sys/unix"
"tailscale.com/types/logger"
)
Expand Down Expand Up @@ -235,8 +235,8 @@ func printMatchInfo(name string, info xt.InfoAny) string {
break
}

pkttype := int(native.Endian.Uint32(data[0:4]))
invert := int(native.Endian.Uint32(data[4:8]))
pkttype := int(binary.NativeEndian.Uint32(data[0:4]))
invert := int(binary.NativeEndian.Uint32(data[4:8]))
var invertPrefix string
if invert != 0 {
invertPrefix = "!"
Expand Down

0 comments on commit 7aa64f3

Please sign in to comment.