From afc2f509a466d6534fe15f98dd36f988b1ea4b3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sat, 16 Jul 2022 21:49:54 +0800 Subject: [PATCH] Minor fixes --- common/dialer/auto_linux.go | 23 --------- common/dialer/auto_other.go | 12 ----- common/dialer/auto_windows.go | 68 -------------------------- common/sniff/stun_test.go | 1 + docs/configuration/inbound/redirect.md | 10 +--- 5 files changed, 3 insertions(+), 111 deletions(-) delete mode 100644 common/dialer/auto_linux.go delete mode 100644 common/dialer/auto_other.go delete mode 100644 common/dialer/auto_windows.go diff --git a/common/dialer/auto_linux.go b/common/dialer/auto_linux.go deleted file mode 100644 index 938e7225..00000000 --- a/common/dialer/auto_linux.go +++ /dev/null @@ -1,23 +0,0 @@ -package dialer - -import ( - "syscall" - - "github.com/sagernet/sing-box/adapter" - "github.com/sagernet/sing/common/control" - E "github.com/sagernet/sing/common/exceptions" -) - -func BindToInterface(router adapter.Router) control.Func { - return func(network, address string, conn syscall.RawConn) error { - interfaceName := router.AutoDetectInterfaceName() - if interfaceName == "" { - return nil - } - var innerErr error - err := conn.Control(func(fd uintptr) { - innerErr = syscall.BindToDevice(int(fd), interfaceName) - }) - return E.Errors(innerErr, err) - } -} diff --git a/common/dialer/auto_other.go b/common/dialer/auto_other.go deleted file mode 100644 index 96dc1f22..00000000 --- a/common/dialer/auto_other.go +++ /dev/null @@ -1,12 +0,0 @@ -//go:build !linux && !windows - -package dialer - -import ( - "github.com/sagernet/sing-box/adapter" - "github.com/sagernet/sing/common/control" -) - -func BindToInterface(router adapter.Router) control.Func { - return nil -} diff --git a/common/dialer/auto_windows.go b/common/dialer/auto_windows.go deleted file mode 100644 index fe29f0b5..00000000 --- a/common/dialer/auto_windows.go +++ /dev/null @@ -1,68 +0,0 @@ -package dialer - -import ( - "encoding/binary" - "net" - "net/netip" - "syscall" - "unsafe" - - "github.com/sagernet/sing-box/adapter" - "github.com/sagernet/sing/common/control" - E "github.com/sagernet/sing/common/exceptions" - - "golang.org/x/sys/windows" -) - -const ( - IP_UNICAST_IF = 31 - IPV6_UNICAST_IF = 31 -) - -func bind4(handle windows.Handle, ifaceIdx int) error { - var bytes [4]byte - binary.BigEndian.PutUint32(bytes[:], uint32(ifaceIdx)) - idx := *(*uint32)(unsafe.Pointer(&bytes[0])) - return windows.SetsockoptInt(handle, windows.IPPROTO_IP, IP_UNICAST_IF, int(idx)) -} - -func bind6(handle windows.Handle, ifaceIdx int) error { - return windows.SetsockoptInt(handle, windows.IPPROTO_IPV6, IPV6_UNICAST_IF, int(ifaceIdx)) -} - -func BindToInterface(router adapter.Router) control.Func { - return func(network, address string, conn syscall.RawConn) error { - interfaceName := router.AutoDetectInterfaceName() - if interfaceName == "" { - return nil - } - ipStr, _, err := net.SplitHostPort(address) - if err == nil { - if ip, err := netip.ParseAddr(ipStr); err == nil && !ip.IsGlobalUnicast() { - return err - } - } - var innerErr error - err = conn.Control(func(fd uintptr) { - handle := windows.Handle(fd) - // handle ip empty, e.g. net.Listen("udp", ":0") - if ipStr == "" { - innerErr = bind4(handle, router.AutoDetectInterfaceIndex()) - if innerErr != nil { - return - } - // try bind ipv6, if failed, ignore. it's a workaround for windows disable interface ipv6 - bind6(handle, router.AutoDetectInterfaceIndex()) - return - } - - switch network { - case "tcp4", "udp4", "ip4": - innerErr = bind4(handle, router.AutoDetectInterfaceIndex()) - case "tcp6", "udp6": - innerErr = bind6(handle, router.AutoDetectInterfaceIndex()) - } - }) - return E.Errors(innerErr, err) - } -} diff --git a/common/sniff/stun_test.go b/common/sniff/stun_test.go index 5fd9a18d..6da89162 100644 --- a/common/sniff/stun_test.go +++ b/common/sniff/stun_test.go @@ -12,6 +12,7 @@ import ( ) func TestSniffSTUN(t *testing.T) { + t.Parallel() packet, err := hex.DecodeString("000100002112a44224b1a025d0c180c484341306") require.NoError(t, err) metadata, err := sniff.STUNMessage(context.Background(), packet) diff --git a/docs/configuration/inbound/redirect.md b/docs/configuration/inbound/redirect.md index 6f7d78a6..7b1c8202 100644 --- a/docs/configuration/inbound/redirect.md +++ b/docs/configuration/inbound/redirect.md @@ -8,13 +8,11 @@ { "type": "redirect", "tag": "redirect-in", - "listen": "::", "listen_port": 5353, "sniff": false, "sniff_override_destination": false, - "domain_strategy": "prefer_ipv6", - "udp_timeout": 300 + "domain_strategy": "prefer_ipv6" } ] } @@ -54,8 +52,4 @@ One of `prefer_ipv4` `prefer_ipv6` `ipv4_only` `ipv6_only`. If set, the requested domain name will be resolved to IP before routing. -If `sniff_override_destination` is in effect, its value will be taken as a fallback. - -#### udp_timeout - -UDP NAT expiration time in seconds, default is 300 (5 minutes). \ No newline at end of file +If `sniff_override_destination` is in effect, its value will be taken as a fallback. \ No newline at end of file