Skip to content

Commit 60d19fa

Browse files
committed
all: use Go 1.21's binary.NativeEndian
We still use josharian/native (hi @josharian!) via netlink, but I also sent mdlayher/netlink#220 Updates tailscale#8632 Change-Id: I2eedcb7facb36ec894aee7f152c8a1f56d7fc8ba Signed-off-by: Brad Fitzpatrick <[email protected]>
1 parent 69b9074 commit 60d19fa

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ require (
5252
github.com/inetaf/tcpproxy v0.0.0-20240214030015-3ce58045626c
5353
github.com/insomniacslk/dhcp v0.0.0-20231206064809-8c70d406f6d2
5454
github.com/jellydator/ttlcache/v3 v3.1.0
55-
github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86
5655
github.com/jsimonetti/rtnetlink v1.4.0
5756
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
5857
github.com/klauspost/compress v1.17.11
@@ -152,6 +151,7 @@ require (
152151
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd // indirect
153152
github.com/gorilla/securecookie v1.1.2 // indirect
154153
github.com/jjti/go-spancheck v0.5.3 // indirect
154+
github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86 // indirect
155155
github.com/karamaru-alpha/copyloopvar v1.0.8 // indirect
156156
github.com/macabu/inamedparam v0.1.3 // indirect
157157
github.com/moby/docker-image-spec v1.3.1 // indirect

net/dns/nm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ package dns
77

88
import (
99
"context"
10+
"encoding/binary"
1011
"fmt"
1112
"net"
1213
"net/netip"
1314
"sort"
1415
"time"
1516

1617
"github.com/godbus/dbus/v5"
17-
"github.com/josharian/native"
1818
"tailscale.com/net/tsaddr"
1919
"tailscale.com/util/dnsname"
2020
)
@@ -137,7 +137,7 @@ func (m *nmManager) trySet(ctx context.Context, config OSConfig) error {
137137
for _, ip := range config.Nameservers {
138138
b := ip.As16()
139139
if ip.Is4() {
140-
dnsv4 = append(dnsv4, native.Endian.Uint32(b[12:]))
140+
dnsv4 = append(dnsv4, binary.NativeEndian.Uint32(b[12:]))
141141
} else {
142142
dnsv6 = append(dnsv6, b[:])
143143
}

util/cstruct/cstruct.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
package cstruct
77

88
import (
9+
"encoding/binary"
910
"errors"
1011
"io"
11-
12-
"github.com/josharian/native"
1312
)
1413

1514
// Size of a pointer-typed value, in bits
@@ -120,7 +119,7 @@ func (d *Decoder) Uint16() uint16 {
120119
d.err = err
121120
return 0
122121
}
123-
return native.Endian.Uint16(d.dbuf[0:2])
122+
return binary.NativeEndian.Uint16(d.dbuf[0:2])
124123
}
125124

126125
// Uint32 returns a uint32 decoded from the buffer.
@@ -133,7 +132,7 @@ func (d *Decoder) Uint32() uint32 {
133132
d.err = err
134133
return 0
135134
}
136-
return native.Endian.Uint32(d.dbuf[0:4])
135+
return binary.NativeEndian.Uint32(d.dbuf[0:4])
137136
}
138137

139138
// Uint64 returns a uint64 decoded from the buffer.
@@ -146,7 +145,7 @@ func (d *Decoder) Uint64() uint64 {
146145
d.err = err
147146
return 0
148147
}
149-
return native.Endian.Uint64(d.dbuf[0:8])
148+
return binary.NativeEndian.Uint64(d.dbuf[0:8])
150149
}
151150

152151
// Uintptr returns a uintptr decoded from the buffer.

util/linuxfw/nftables.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ package linuxfw
88

99
import (
1010
"cmp"
11+
"encoding/binary"
1112
"fmt"
1213
"sort"
1314
"strings"
1415

1516
"github.com/google/nftables"
1617
"github.com/google/nftables/expr"
1718
"github.com/google/nftables/xt"
18-
"github.com/josharian/native"
1919
"golang.org/x/sys/unix"
2020
"tailscale.com/types/logger"
2121
)
@@ -235,8 +235,8 @@ func printMatchInfo(name string, info xt.InfoAny) string {
235235
break
236236
}
237237

238-
pkttype := int(native.Endian.Uint32(data[0:4]))
239-
invert := int(native.Endian.Uint32(data[4:8]))
238+
pkttype := int(binary.NativeEndian.Uint32(data[0:4]))
239+
invert := int(binary.NativeEndian.Uint32(data[4:8]))
240240
var invertPrefix string
241241
if invert != 0 {
242242
invertPrefix = "!"

0 commit comments

Comments
 (0)