mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-08-30 22:08:49 +08:00
Compare commits
82 Commits
7123e88de6
...
8a848963aa
Author | SHA1 | Date | |
---|---|---|---|
![]() |
8a848963aa | ||
![]() |
52390aa929 | ||
![]() |
371672e356 | ||
![]() |
bab1141dd3 | ||
![]() |
d7867002c5 | ||
![]() |
a8bb3a76e8 | ||
![]() |
4bcfbf0ae3 | ||
![]() |
34dd12c7b2 | ||
![]() |
1c8fca95e6 | ||
![]() |
5a32303f91 | ||
![]() |
17f41d83f4 | ||
![]() |
5e0bc79706 | ||
![]() |
96a33b10c0 | ||
![]() |
204b174191 | ||
![]() |
ad79520c02 | ||
![]() |
86377d5996 | ||
![]() |
56887a3a08 | ||
![]() |
fcbef874e4 | ||
![]() |
fdd2d799f8 | ||
![]() |
fa9dad411e | ||
![]() |
4ec222a2ed | ||
![]() |
9cd7c54750 | ||
![]() |
3c70546d5f | ||
![]() |
64ee2927d7 | ||
![]() |
9a3196e320 | ||
![]() |
046fb6e21c | ||
![]() |
7e21c09f35 | ||
![]() |
ed14bbee92 | ||
![]() |
7a3ef2b07b | ||
![]() |
786e734a4b | ||
![]() |
aca6e3a1af | ||
![]() |
046308ac31 | ||
![]() |
312ef4e5f7 | ||
![]() |
45299d7305 | ||
![]() |
d807ee5011 | ||
![]() |
2a4e5ee729 | ||
![]() |
7bdd80f10a | ||
![]() |
d19d1a677a | ||
![]() |
b5e66b9bb9 | ||
![]() |
e0da41b22d | ||
![]() |
efd08f16b8 | ||
![]() |
c65b149103 | ||
![]() |
c3b7de77e8 | ||
![]() |
56c5f001c1 | ||
![]() |
63c702febd | ||
![]() |
163d689fb0 | ||
![]() |
9280872c5e | ||
![]() |
f504c7bb7c | ||
![]() |
50362ed07b | ||
![]() |
6012d1ce44 | ||
![]() |
110eb69384 | ||
![]() |
4f8f5d47cd | ||
![]() |
357d4a8c9d | ||
![]() |
029a273531 | ||
![]() |
02bc695619 | ||
![]() |
dffbd6861f | ||
![]() |
9b48db1be4 | ||
![]() |
cb9ada4ae3 | ||
![]() |
4e8024ea7d | ||
![]() |
c953f8c809 | ||
![]() |
db41803a1a | ||
![]() |
b202589222 | ||
![]() |
16d7d16919 | ||
![]() |
07eacfc580 | ||
![]() |
5a37104770 | ||
![]() |
9ebda6d366 | ||
![]() |
56f66ae026 | ||
![]() |
f45ecb3903 | ||
![]() |
b8c68e1896 | ||
![]() |
389479cb85 | ||
![]() |
4f2f890dfd | ||
![]() |
22b31c84e1 | ||
![]() |
1e64e92e4e | ||
![]() |
a0a40898bf | ||
![]() |
7d521ca78f | ||
![]() |
8efb0bab2a | ||
![]() |
8beec8dcc3 | ||
![]() |
4be6c8b180 | ||
![]() |
abff5b3705 | ||
![]() |
00562b5340 | ||
![]() |
ac844a672f | ||
![]() |
1a43ac8d30 |
@ -37,6 +37,12 @@ func (l *Listener) ListenUDP() (net.PacketConn, error) {
|
|||||||
return udpConn, err
|
return udpConn, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *Listener) DialContext(dialer net.Dialer, ctx context.Context, network string, address string) (net.Conn, error) {
|
||||||
|
return ListenNetworkNamespace[net.Conn](l.listenOptions.NetNs, func() (net.Conn, error) {
|
||||||
|
return dialer.DialContext(ctx, network, address)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (l *Listener) ListenPacket(listenConfig net.ListenConfig, ctx context.Context, network string, address string) (net.PacketConn, error) {
|
func (l *Listener) ListenPacket(listenConfig net.ListenConfig, ctx context.Context, network string, address string) (net.PacketConn, error) {
|
||||||
return ListenNetworkNamespace[net.PacketConn](l.listenOptions.NetNs, func() (net.PacketConn, error) {
|
return ListenNetworkNamespace[net.PacketConn](l.listenOptions.NetNs, func() (net.PacketConn, error) {
|
||||||
return listenConfig.ListenPacket(ctx, network, address)
|
return listenConfig.ListenPacket(ctx, network, address)
|
||||||
|
@ -232,10 +232,20 @@ func (c *Client) Exchange(ctx context.Context, transport adapter.DNSTransport, m
|
|||||||
record.Header().Ttl = timeToLive
|
record.Header().Ttl = timeToLive
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
response.Id = messageId
|
|
||||||
if !disableCache {
|
if !disableCache {
|
||||||
c.storeCache(transport, question, response, timeToLive)
|
c.storeCache(transport, question, response, timeToLive)
|
||||||
}
|
}
|
||||||
|
response.Id = messageId
|
||||||
|
requestEDNSOpt := message.IsEdns0()
|
||||||
|
responseEDNSOpt := response.IsEdns0()
|
||||||
|
if responseEDNSOpt != nil && (requestEDNSOpt == nil || requestEDNSOpt.Version() < responseEDNSOpt.Version()) {
|
||||||
|
response.Extra = common.Filter(response.Extra, func(it dns.RR) bool {
|
||||||
|
return it.Header().Rrtype != dns.TypeOPT
|
||||||
|
})
|
||||||
|
if requestEDNSOpt != nil {
|
||||||
|
response.SetEdns0(responseEDNSOpt.UDPSize(), responseEDNSOpt.Do())
|
||||||
|
}
|
||||||
|
}
|
||||||
logExchangedResponse(c.logger, ctx, response, timeToLive)
|
logExchangedResponse(c.logger, ctx, response, timeToLive)
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package option
|
package option
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/url"
|
||||||
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
C "github.com/sagernet/sing-box/constant"
|
C "github.com/sagernet/sing-box/constant"
|
||||||
@ -27,6 +29,18 @@ type _RuleSet struct {
|
|||||||
type RuleSet _RuleSet
|
type RuleSet _RuleSet
|
||||||
|
|
||||||
func (r RuleSet) MarshalJSON() ([]byte, error) {
|
func (r RuleSet) MarshalJSON() ([]byte, error) {
|
||||||
|
if r.Type != C.RuleSetTypeInline {
|
||||||
|
var defaultFormat string
|
||||||
|
switch r.Type {
|
||||||
|
case C.RuleSetTypeLocal:
|
||||||
|
defaultFormat = ruleSetDefaultFormat(r.LocalOptions.Path)
|
||||||
|
case C.RuleSetTypeRemote:
|
||||||
|
defaultFormat = ruleSetDefaultFormat(r.RemoteOptions.URL)
|
||||||
|
}
|
||||||
|
if r.Format == defaultFormat {
|
||||||
|
r.Format = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
var v any
|
var v any
|
||||||
switch r.Type {
|
switch r.Type {
|
||||||
case "", C.RuleSetTypeInline:
|
case "", C.RuleSetTypeInline:
|
||||||
@ -62,7 +76,19 @@ func (r *RuleSet) UnmarshalJSON(bytes []byte) error {
|
|||||||
default:
|
default:
|
||||||
return E.New("unknown rule-set type: " + r.Type)
|
return E.New("unknown rule-set type: " + r.Type)
|
||||||
}
|
}
|
||||||
|
err = badjson.UnmarshallExcluded(bytes, (*_RuleSet)(r), v)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if r.Type != C.RuleSetTypeInline {
|
if r.Type != C.RuleSetTypeInline {
|
||||||
|
if r.Format == "" {
|
||||||
|
switch r.Type {
|
||||||
|
case C.RuleSetTypeLocal:
|
||||||
|
r.Format = ruleSetDefaultFormat(r.LocalOptions.Path)
|
||||||
|
case C.RuleSetTypeRemote:
|
||||||
|
r.Format = ruleSetDefaultFormat(r.RemoteOptions.URL)
|
||||||
|
}
|
||||||
|
}
|
||||||
switch r.Format {
|
switch r.Format {
|
||||||
case "":
|
case "":
|
||||||
return E.New("missing format")
|
return E.New("missing format")
|
||||||
@ -73,13 +99,23 @@ func (r *RuleSet) UnmarshalJSON(bytes []byte) error {
|
|||||||
} else {
|
} else {
|
||||||
r.Format = ""
|
r.Format = ""
|
||||||
}
|
}
|
||||||
err = badjson.UnmarshallExcluded(bytes, (*_RuleSet)(r), v)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ruleSetDefaultFormat(path string) string {
|
||||||
|
if pathURL, err := url.Parse(path); err == nil {
|
||||||
|
path = pathURL.Path
|
||||||
|
}
|
||||||
|
switch filepath.Ext(path) {
|
||||||
|
case ".json":
|
||||||
|
return C.RuleSetFormatSource
|
||||||
|
case ".srs":
|
||||||
|
return C.RuleSetFormatBinary
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type LocalRuleSet struct {
|
type LocalRuleSet struct {
|
||||||
Path string `json:"path,omitempty"`
|
Path string `json:"path,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -154,10 +154,11 @@ func (w *tproxyPacketWriter) WritePacket(buffer *buf.Buffer, destination M.Socks
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var listenConfig net.ListenConfig
|
var dialer net.Dialer
|
||||||
listenConfig.Control = control.Append(listenConfig.Control, control.ReuseAddr())
|
dialer.LocalAddr = destination.UDPAddr()
|
||||||
listenConfig.Control = control.Append(listenConfig.Control, redir.TProxyWriteBack())
|
dialer.Control = control.Append(dialer.Control, control.ReuseAddr())
|
||||||
packetConn, err := w.listener.ListenPacket(listenConfig, w.ctx, "udp", destination.String())
|
dialer.Control = control.Append(dialer.Control, redir.TProxyWriteBack())
|
||||||
|
packetConn, err := w.listener.DialContext(dialer, w.ctx, "udp", w.source.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user