mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-06-13 21:54:13 +08:00
Compare commits
42 Commits
c131c1bdca
...
7b7820a322
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7b7820a322 | ||
![]() |
c38d3fb3b5 | ||
![]() |
b440c3371a | ||
![]() |
228bdfa243 | ||
![]() |
c13762f2b7 | ||
![]() |
32b7fc91a5 | ||
![]() |
07859befcd | ||
![]() |
ebff681aa7 | ||
![]() |
011dd16efb | ||
![]() |
d32a9f0f7c | ||
![]() |
9295aba05a | ||
![]() |
8f0dc74b41 | ||
![]() |
07475132c0 | ||
![]() |
1c85682f36 | ||
![]() |
5b4dfea740 | ||
![]() |
e01712fd40 | ||
![]() |
0e98b5fe44 | ||
![]() |
b10037bb57 | ||
![]() |
50bacf545b | ||
![]() |
5489daf126 | ||
![]() |
b5f828ad84 | ||
![]() |
16f034037b | ||
![]() |
75f4a3d4a8 | ||
![]() |
69a6dc50f3 | ||
![]() |
40e24a440e | ||
![]() |
a4c3367c71 | ||
![]() |
abfebd1e96 | ||
![]() |
877988b3e9 | ||
![]() |
f7c1ebd56d | ||
![]() |
a407c03497 | ||
![]() |
474efa5585 | ||
![]() |
6225ea1980 | ||
![]() |
aa6b2404ab | ||
![]() |
4c59a3cf7c | ||
![]() |
9fd37c7b02 | ||
![]() |
b21a79bc12 | ||
![]() |
d7d87436d7 | ||
![]() |
4f735529e5 | ||
![]() |
bca4b38fce | ||
![]() |
a8a5ae2e77 | ||
![]() |
8929b4161d | ||
![]() |
6fb79d5d72 |
@ -103,14 +103,9 @@ func NewWithOptions(options Options) (N.Dialer, error) {
|
|||||||
resolveFallbackDelay = time.Duration(dialOptions.FallbackDelay)
|
resolveFallbackDelay = time.Duration(dialOptions.FallbackDelay)
|
||||||
} else if options.NewDialer {
|
} else if options.NewDialer {
|
||||||
return nil, E.New("missing domain resolver for domain server address")
|
return nil, E.New("missing domain resolver for domain server address")
|
||||||
} else {
|
|
||||||
transports := dnsTransport.Transports()
|
|
||||||
if len(transports) < 2 {
|
|
||||||
dnsQueryOptions.Transport = dnsTransport.Default()
|
|
||||||
} else {
|
} else {
|
||||||
deprecated.Report(options.Context, deprecated.OptionMissingDomainResolver)
|
deprecated.Report(options.Context, deprecated.OptionMissingDomainResolver)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
dialer = NewResolveDialer(
|
dialer = NewResolveDialer(
|
||||||
options.Context,
|
options.Context,
|
||||||
dialer,
|
dialer,
|
||||||
|
@ -4,15 +4,8 @@ icon: material/alert-decagram
|
|||||||
|
|
||||||
#### 1.12.0-alpha.16
|
#### 1.12.0-alpha.16
|
||||||
|
|
||||||
* Update `domain_resolver` behavior **1**
|
|
||||||
* Fixes and improvements
|
* Fixes and improvements
|
||||||
|
|
||||||
**1**:
|
|
||||||
|
|
||||||
`route.default_domain_resolver` or `outbound.domain_resolver` is now optional when only one DNS server is configured.
|
|
||||||
|
|
||||||
See [Dial Fields](/configuration/shared/dial/#domain_resolver).
|
|
||||||
|
|
||||||
### 1.11.5
|
### 1.11.5
|
||||||
|
|
||||||
* Fixes and improvements
|
* Fixes and improvements
|
||||||
|
@ -106,10 +106,6 @@ Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
|
|||||||
|
|
||||||
`outbound` DNS rule items are deprecated and will be removed in sing-box 1.14.0, so this item will be required for outbound/endpoints using domain name in server address since sing-box 1.14.0.
|
`outbound` DNS rule items are deprecated and will be removed in sing-box 1.14.0, so this item will be required for outbound/endpoints using domain name in server address since sing-box 1.14.0.
|
||||||
|
|
||||||
!!! info ""
|
|
||||||
|
|
||||||
`domain_resolver` or `route.default_domain_resolver` is optional when only one DNS server is configured.
|
|
||||||
|
|
||||||
Set domain resolver to use for resolving domain names.
|
Set domain resolver to use for resolving domain names.
|
||||||
|
|
||||||
This option uses the same format as the [route DNS rule action](/configuration/dns/rule_action/#route) without the `action` field.
|
This option uses the same format as the [route DNS rule action](/configuration/dns/rule_action/#route) without the `action` field.
|
||||||
|
@ -105,10 +105,6 @@ icon: material/new-box
|
|||||||
|
|
||||||
`outbound` DNS 规则项已弃用,且将在 sing-box 1.14.0 中被移除。因此,从 sing-box 1.14.0 版本开始,所有在服务器地址中使用域名的出站/端点均需配置此项。
|
`outbound` DNS 规则项已弃用,且将在 sing-box 1.14.0 中被移除。因此,从 sing-box 1.14.0 版本开始,所有在服务器地址中使用域名的出站/端点均需配置此项。
|
||||||
|
|
||||||
!!! info ""
|
|
||||||
|
|
||||||
当只有一个 DNS 服务器已配置时,`domain_resolver` 或 `route.default_domain_resolver` 是可选的。
|
|
||||||
|
|
||||||
用于设置解析域名的域名解析器。
|
用于设置解析域名的域名解析器。
|
||||||
|
|
||||||
此选项的格式与 [路由 DNS 规则动作](/configuration/dns/rule_action/#route) 相同,但不包含 `action` 字段。
|
此选项的格式与 [路由 DNS 规则动作](/configuration/dns/rule_action/#route) 相同,但不包含 `action` 字段。
|
||||||
|
@ -116,14 +116,7 @@ func (o *DomainResolveOptions) UnmarshalJSON(bytes []byte) error {
|
|||||||
o.Server = stringValue
|
o.Server = stringValue
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(bytes, (*_DomainResolveOptions)(o))
|
return json.Unmarshal(bytes, (*_DomainResolveOptions)(o))
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if o.Server == "" {
|
|
||||||
return E.New("empty domain_resolver.server")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *DialerOptions) TakeDialerOptions() DialerOptions {
|
func (o *DialerOptions) TakeDialerOptions() DialerOptions {
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"os"
|
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
@ -15,7 +14,6 @@ import (
|
|||||||
"github.com/sagernet/sing-box/common/tlsfragment"
|
"github.com/sagernet/sing-box/common/tlsfragment"
|
||||||
C "github.com/sagernet/sing-box/constant"
|
C "github.com/sagernet/sing-box/constant"
|
||||||
"github.com/sagernet/sing/common"
|
"github.com/sagernet/sing/common"
|
||||||
"github.com/sagernet/sing/common/buf"
|
|
||||||
"github.com/sagernet/sing/common/bufio"
|
"github.com/sagernet/sing/common/bufio"
|
||||||
"github.com/sagernet/sing/common/canceler"
|
"github.com/sagernet/sing/common/canceler"
|
||||||
E "github.com/sagernet/sing/common/exceptions"
|
E "github.com/sagernet/sing/common/exceptions"
|
||||||
@ -208,16 +206,14 @@ func (m *ConnectionManager) NewPacketConnection(ctx context.Context, this N.Dial
|
|||||||
go m.packetConnectionCopy(ctx, destination, conn, true, &done, onClose)
|
go m.packetConnectionCopy(ctx, destination, conn, true, &done, onClose)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *ConnectionManager) connectionCopy(ctx context.Context, source net.Conn, destination net.Conn, direction bool, done *atomic.Bool, onClose N.CloseHandlerFunc) {
|
func (m *ConnectionManager) connectionCopy(ctx context.Context, source io.Reader, destination io.Writer, direction bool, done *atomic.Bool, onClose N.CloseHandlerFunc) {
|
||||||
var (
|
originSource := source
|
||||||
sourceReader io.Reader = source
|
originDestination := destination
|
||||||
destinationWriter io.Writer = destination
|
|
||||||
)
|
|
||||||
var readCounters, writeCounters []N.CountFunc
|
var readCounters, writeCounters []N.CountFunc
|
||||||
for {
|
for {
|
||||||
sourceReader, readCounters = N.UnwrapCountReader(sourceReader, readCounters)
|
source, readCounters = N.UnwrapCountReader(source, readCounters)
|
||||||
destinationWriter, writeCounters = N.UnwrapCountWriter(destinationWriter, writeCounters)
|
destination, writeCounters = N.UnwrapCountWriter(destination, writeCounters)
|
||||||
if cachedSrc, isCached := sourceReader.(N.CachedReader); isCached {
|
if cachedSrc, isCached := source.(N.CachedReader); isCached {
|
||||||
cachedBuffer := cachedSrc.ReadCached()
|
cachedBuffer := cachedSrc.ReadCached()
|
||||||
if cachedBuffer != nil {
|
if cachedBuffer != nil {
|
||||||
dataLen := cachedBuffer.Len()
|
dataLen := cachedBuffer.Len()
|
||||||
@ -227,7 +223,7 @@ func (m *ConnectionManager) connectionCopy(ctx context.Context, source net.Conn,
|
|||||||
if done.Swap(true) {
|
if done.Swap(true) {
|
||||||
onClose(err)
|
onClose(err)
|
||||||
}
|
}
|
||||||
common.Close(source, destination)
|
common.Close(originSource, originDestination)
|
||||||
if !direction {
|
if !direction {
|
||||||
m.logger.ErrorContext(ctx, "connection upload payload: ", err)
|
m.logger.ErrorContext(ctx, "connection upload payload: ", err)
|
||||||
} else {
|
} else {
|
||||||
@ -246,13 +242,9 @@ func (m *ConnectionManager) connectionCopy(ctx context.Context, source net.Conn,
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if earlyConn, isEarlyConn := common.Cast[N.EarlyConn](destinationWriter); isEarlyConn && earlyConn.NeedHandshake() {
|
if earlyConn, isEarlyConn := common.Cast[N.EarlyConn](destination); isEarlyConn && earlyConn.NeedHandshake() {
|
||||||
err := m.connectionCopyEarly(source, destination)
|
_, err := destination.Write(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if done.Swap(true) {
|
|
||||||
onClose(err)
|
|
||||||
}
|
|
||||||
common.Close(source, destination)
|
|
||||||
if !direction {
|
if !direction {
|
||||||
m.logger.ErrorContext(ctx, "connection upload handshake: ", err)
|
m.logger.ErrorContext(ctx, "connection upload handshake: ", err)
|
||||||
} else {
|
} else {
|
||||||
@ -261,20 +253,20 @@ func (m *ConnectionManager) connectionCopy(ctx context.Context, source net.Conn,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_, err := bufio.CopyWithCounters(destination, sourceReader, source, readCounters, writeCounters)
|
_, err := bufio.CopyWithCounters(destination, source, originSource, readCounters, writeCounters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.Close(source, destination)
|
common.Close(originDestination)
|
||||||
} else if duplexDst, isDuplex := destination.(N.WriteCloser); isDuplex {
|
} else if duplexDst, isDuplex := destination.(N.WriteCloser); isDuplex {
|
||||||
err = duplexDst.CloseWrite()
|
err = duplexDst.CloseWrite()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.Close(source, destination)
|
common.Close(originSource, originDestination)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
destination.Close()
|
common.Close(originDestination)
|
||||||
}
|
}
|
||||||
if done.Swap(true) {
|
if done.Swap(true) {
|
||||||
onClose(err)
|
onClose(err)
|
||||||
common.Close(source, destination)
|
common.Close(originSource, originDestination)
|
||||||
}
|
}
|
||||||
if !direction {
|
if !direction {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -295,28 +287,6 @@ func (m *ConnectionManager) connectionCopy(ctx context.Context, source net.Conn,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *ConnectionManager) connectionCopyEarly(source net.Conn, destination io.Writer) error {
|
|
||||||
payload := buf.NewPacket()
|
|
||||||
defer payload.Release()
|
|
||||||
err := source.SetReadDeadline(time.Now().Add(C.ReadPayloadTimeout))
|
|
||||||
if err != nil {
|
|
||||||
if err == os.ErrInvalid {
|
|
||||||
return common.Error(destination.Write(nil))
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = payload.ReadOnceFrom(source)
|
|
||||||
if err != nil && !E.IsTimeout(err) {
|
|
||||||
return E.Cause(err, "read payload")
|
|
||||||
}
|
|
||||||
_ = source.SetReadDeadline(time.Time{})
|
|
||||||
_, err = destination.Write(payload.Bytes())
|
|
||||||
if err != nil {
|
|
||||||
return E.Cause(err, "write payload")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ConnectionManager) packetConnectionCopy(ctx context.Context, source N.PacketReader, destination N.PacketWriter, direction bool, done *atomic.Bool, onClose N.CloseHandlerFunc) {
|
func (m *ConnectionManager) packetConnectionCopy(ctx context.Context, source N.PacketReader, destination N.PacketWriter, direction bool, done *atomic.Bool, onClose N.CloseHandlerFunc) {
|
||||||
_, err := bufio.CopyPacket(destination, source)
|
_, err := bufio.CopyPacket(destination, source)
|
||||||
if !direction {
|
if !direction {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user