From d1af8aaf7eaaf52a148712eddaacc590b9619b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Thu, 16 Jul 2026 18:45:49 +0800 Subject: [PATCH] Fix lint errors --- gtcpip/header/ipv4.go | 11 +++++------ gtcpip/header/ipv6_extension_headers.go | 3 +-- gtcpip/header/ndp_options.go | 9 ++++----- internal/fdbased_darwin/endpoint.go | 3 +-- ping/cmsg_windows.go | 7 +++---- ping/socket_linux_unprivileged.go | 3 +-- 6 files changed, 15 insertions(+), 21 deletions(-) diff --git a/gtcpip/header/ipv4.go b/gtcpip/header/ipv4.go index d5ffbf1..3041eae 100644 --- a/gtcpip/header/ipv4.go +++ b/gtcpip/header/ipv4.go @@ -22,7 +22,6 @@ import ( "github.com/sagernet/sing-tun/gtcpip" "github.com/sagernet/sing-tun/gtcpip/checksum" - "github.com/sagernet/sing/common" ) // RFC 971 defines the fields of the IPv4 header on page 11 using the following @@ -335,7 +334,7 @@ func (b IPv4) FragmentOffset() uint16 { } func (b IPv4) FragmentOffsetDarwinRaw() uint16 { - return common.NativeEndian.Uint16(b[flagsFO:]) << 3 + return binary.NativeEndian.Uint16(b[flagsFO:]) << 3 } // TotalLength returns the "total length" field of the IPv4 header. @@ -344,7 +343,7 @@ func (b IPv4) TotalLength() uint16 { } func (b IPv4) TotalLengthDarwinRaw() uint16 { - return common.NativeEndian.Uint16(b[IPv4TotalLenOffset:]) + uint16(b.HeaderLength()) + return binary.NativeEndian.Uint16(b[IPv4TotalLenOffset:]) + uint16(b.HeaderLength()) } // Checksum returns the checksum field of the IPv4 header. @@ -441,7 +440,7 @@ func (b IPv4) SetTotalLength(totalLength uint16) { } func (b IPv4) SetTotalLengthDarwinRaw(totalLength uint16) { - common.NativeEndian.PutUint16(b[IPv4TotalLenOffset:], totalLength) + binary.NativeEndian.PutUint16(b[IPv4TotalLenOffset:], totalLength) } // SetChecksum sets the checksum field of the IPv4 header. @@ -458,7 +457,7 @@ func (b IPv4) SetFlagsFragmentOffset(flags uint8, offset uint16) { func (b IPv4) SetFlagsFragmentOffsetDarwinRaw(flags uint8, offset uint16) { v := (uint16(flags) << 13) | (offset >> 3) - common.NativeEndian.PutUint16(b[flagsFO:], v) + binary.NativeEndian.PutUint16(b[flagsFO:], v) } // SetID sets the identification field. @@ -1179,7 +1178,7 @@ func (s IPv4OptionsSerializer) Serialize(b []byte) uint8 { // header ends on a 32 bit boundary. The padding is zero. padded := padIPv4OptionsLength(total) b = b[:padded-total] - common.ClearArray(b) + clear(b) return padded } diff --git a/gtcpip/header/ipv6_extension_headers.go b/gtcpip/header/ipv6_extension_headers.go index 6c48b1b..1ab7c9d 100644 --- a/gtcpip/header/ipv6_extension_headers.go +++ b/gtcpip/header/ipv6_extension_headers.go @@ -21,7 +21,6 @@ import ( "math" "github.com/sagernet/sing-tun/gtcpip" - "github.com/sagernet/sing/common" ) // IPv6ExtensionHeaderIdentifier is an IPv6 extension header identifier. @@ -129,7 +128,7 @@ func padIPv6Option(b []byte) { b[ipv6ExtHdrOptionTypeOffset] = uint8(ipv6Pad1ExtHdrOptionIdentifier) default: // Pad with PadN. s := b[ipv6ExtHdrOptionPayloadOffset:] - common.ClearArray(s) + clear(s) b[ipv6ExtHdrOptionTypeOffset] = uint8(ipv6PadNExtHdrOptionIdentifier) b[ipv6ExtHdrOptionLengthOffset] = uint8(len(s)) } diff --git a/gtcpip/header/ndp_options.go b/gtcpip/header/ndp_options.go index c545120..ca1c6cb 100644 --- a/gtcpip/header/ndp_options.go +++ b/gtcpip/header/ndp_options.go @@ -24,7 +24,6 @@ import ( "time" "github.com/sagernet/sing-tun/gtcpip" - "github.com/sagernet/sing/common" ) // ndpOptionIdentifier is an NDP option type identifier. @@ -341,7 +340,7 @@ func (b NDPOptions) Serialize(s NDPOptionsSerializer) int { // Zero out remaining (padding) bytes, if any exists. if used+2 < l { - common.ClearArray(b[used+2 : l]) + clear(b[used+2 : l]) } b = b[l:] @@ -567,7 +566,7 @@ func (o NDPPrefixInformation) serializeInto(b []byte) int { // Zero out the Reserved2 field. reserved2 := b[ndpPrefixInformationReserved2Offset:][:ndpPrefixInformationReserved2Length] - common.ClearArray(reserved2) + clear(reserved2) return used } @@ -686,7 +685,7 @@ func (o NDPRecursiveDNSServer) serializeInto(b []byte) int { used := copy(b, o) // Zero out the reserved bytes that are before the Lifetime field. - common.ClearArray(b[0:ndpRecursiveDNSServerLifetimeOffset]) + clear(b[0:ndpRecursiveDNSServerLifetimeOffset]) return used } @@ -779,7 +778,7 @@ func (o NDPDNSSearchList) serializeInto(b []byte) int { used := copy(b, o) // Zero out the reserved bytes that are before the Lifetime field. - common.ClearArray(b[0:ndpDNSSearchListLifetimeOffset]) + clear(b[0:ndpDNSSearchListLifetimeOffset]) return used } diff --git a/internal/fdbased_darwin/endpoint.go b/internal/fdbased_darwin/endpoint.go index 05371e7..54766d7 100644 --- a/internal/fdbased_darwin/endpoint.go +++ b/internal/fdbased_darwin/endpoint.go @@ -50,7 +50,6 @@ import ( "github.com/sagernet/gvisor/pkg/tcpip/header" "github.com/sagernet/gvisor/pkg/tcpip/stack" rawfile "github.com/sagernet/sing-tun/internal/rawfile_darwin" - "github.com/sagernet/sing/common" "golang.org/x/sys/unix" ) @@ -301,7 +300,7 @@ func New(opts *Options) (stack.LinkEndpoint, error) { e.fds = append(e.fds, fdInfo{fd: fd, isSocket: true}) if opts.ProcessorsPerChannel == 0 { - opts.ProcessorsPerChannel = common.Max(1, runtime.GOMAXPROCS(0)/len(opts.FDs)) + opts.ProcessorsPerChannel = max(1, runtime.GOMAXPROCS(0)/len(opts.FDs)) } inboundDispatcher, err := newRecvMMsgDispatcher(fd, e, opts) diff --git a/ping/cmsg_windows.go b/ping/cmsg_windows.go index 07c322c..be5be9b 100644 --- a/ping/cmsg_windows.go +++ b/ping/cmsg_windows.go @@ -1,11 +1,10 @@ package ping import ( + "encoding/binary" "fmt" "unsafe" - "github.com/sagernet/sing/common" - "golang.org/x/net/ipv6" "golang.org/x/sys/windows" ) @@ -37,9 +36,9 @@ func parseIPv6ControlMessage(cmsg []byte) (*ipv6.ControlMessage, error) { } switch cmsghdr.Type { case IPV6_TCLASS: - controlMessage.TrafficClass = int(common.NativeEndian.Uint32(cmsg[alignedSizeofCmsghdr : alignedSizeofCmsghdr+4])) + controlMessage.TrafficClass = int(binary.NativeEndian.Uint32(cmsg[alignedSizeofCmsghdr : alignedSizeofCmsghdr+4])) case IPV6_HOPLIMIT: - controlMessage.HopLimit = int(common.NativeEndian.Uint32(cmsg[alignedSizeofCmsghdr : alignedSizeofCmsghdr+4])) + controlMessage.HopLimit = int(binary.NativeEndian.Uint32(cmsg[alignedSizeofCmsghdr : alignedSizeofCmsghdr+4])) } cmsg = cmsg[msgSize:] } diff --git a/ping/socket_linux_unprivileged.go b/ping/socket_linux_unprivileged.go index f709684..1ad1548 100644 --- a/ping/socket_linux_unprivileged.go +++ b/ping/socket_linux_unprivileged.go @@ -9,7 +9,6 @@ import ( "time" "github.com/sagernet/sing-tun/gtcpip/header" - "github.com/sagernet/sing/common" "github.com/sagernet/sing/common/buf" "github.com/sagernet/sing/common/control" M "github.com/sagernet/sing/common/metadata" @@ -175,7 +174,7 @@ func (c *UnprivilegedConn) Close() error { for _, conn := range c.mapping { _ = conn.Close() } - common.ClearMap(c.mapping) + clear(c.mapping) return nil }