mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-08-30 22:08:49 +08:00
Compare commits
79 Commits
8a848963aa
...
7123e88de6
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7123e88de6 | ||
![]() |
6a0657ec4b | ||
![]() |
6b5d425e3b | ||
![]() |
ae5b299f3a | ||
![]() |
8ce567797c | ||
![]() |
c7139ba0dc | ||
![]() |
cd54e2a9aa | ||
![]() |
c92d1b3be5 | ||
![]() |
47372b0eeb | ||
![]() |
10a090d49c | ||
![]() |
366e6891d9 | ||
![]() |
24755924bd | ||
![]() |
69922d6273 | ||
![]() |
fbac783590 | ||
![]() |
80fe59cadc | ||
![]() |
65d6db9638 | ||
![]() |
c92b4eda1c | ||
![]() |
f787f569b6 | ||
![]() |
a83af4aed3 | ||
![]() |
211655a8f9 | ||
![]() |
9e572d52d1 | ||
![]() |
c3e060ef7c | ||
![]() |
8e242e4ede | ||
![]() |
a9a991d6bb | ||
![]() |
2e7e94a485 | ||
![]() |
01e35b74db | ||
![]() |
6c3aa066fb | ||
![]() |
23fbd49733 | ||
![]() |
2ecfacc70a | ||
![]() |
2d9063507d | ||
![]() |
1491e2644c | ||
![]() |
0957f5d839 | ||
![]() |
36622784cd | ||
![]() |
a341ea4293 | ||
![]() |
5a207a6b68 | ||
![]() |
2ebe64896f | ||
![]() |
d8bf75915b | ||
![]() |
460466e711 | ||
![]() |
319b70d029 | ||
![]() |
61d3dc9734 | ||
![]() |
e1325a3270 | ||
![]() |
95aa47aa1c | ||
![]() |
4d32f52c88 | ||
![]() |
fd3ecc53aa | ||
![]() |
b515fbbcef | ||
![]() |
ef2c6ea852 | ||
![]() |
e2780877e9 | ||
![]() |
42b072971c | ||
![]() |
12292ca177 | ||
![]() |
eb07c5a4a7 | ||
![]() |
16898cb10b | ||
![]() |
95956da914 | ||
![]() |
3ca344a3e2 | ||
![]() |
730a2a36eb | ||
![]() |
5b9241f79e | ||
![]() |
757e8ecd0b | ||
![]() |
a5fc910fe6 | ||
![]() |
7e6503c2ce | ||
![]() |
43c9a137b4 | ||
![]() |
a2d7039a8f | ||
![]() |
61ba43e2a3 | ||
![]() |
a50d467245 | ||
![]() |
e4714af97b | ||
![]() |
23a7950a9f | ||
![]() |
565a032131 | ||
![]() |
f5d27a8d97 | ||
![]() |
cd92db4589 | ||
![]() |
eb23610bff | ||
![]() |
c3f82168e3 | ||
![]() |
a119fff914 | ||
![]() |
80bf6405d3 | ||
![]() |
214c0fab9a | ||
![]() |
e00e472364 | ||
![]() |
9b695c656f | ||
![]() |
b2fb7789b6 | ||
![]() |
9733979663 | ||
![]() |
dbe95fa068 | ||
![]() |
84817d10fb | ||
![]() |
c8ea5f3170 |
@ -37,12 +37,6 @@ func (l *Listener) ListenUDP() (net.PacketConn, error) {
|
||||
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) {
|
||||
return ListenNetworkNamespace[net.PacketConn](l.listenOptions.NetNs, func() (net.PacketConn, error) {
|
||||
return listenConfig.ListenPacket(ctx, network, address)
|
||||
|
@ -232,20 +232,10 @@ func (c *Client) Exchange(ctx context.Context, transport adapter.DNSTransport, m
|
||||
record.Header().Ttl = timeToLive
|
||||
}
|
||||
}
|
||||
response.Id = messageId
|
||||
if !disableCache {
|
||||
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)
|
||||
return response, err
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
package option
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
@ -29,18 +27,6 @@ type _RuleSet struct {
|
||||
type RuleSet _RuleSet
|
||||
|
||||
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
|
||||
switch r.Type {
|
||||
case "", C.RuleSetTypeInline:
|
||||
@ -76,19 +62,7 @@ func (r *RuleSet) UnmarshalJSON(bytes []byte) error {
|
||||
default:
|
||||
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.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 {
|
||||
case "":
|
||||
return E.New("missing format")
|
||||
@ -99,23 +73,13 @@ func (r *RuleSet) UnmarshalJSON(bytes []byte) error {
|
||||
} else {
|
||||
r.Format = ""
|
||||
}
|
||||
err = badjson.UnmarshallExcluded(bytes, (*_RuleSet)(r), v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
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 {
|
||||
Path string `json:"path,omitempty"`
|
||||
}
|
||||
|
@ -154,11 +154,10 @@ func (w *tproxyPacketWriter) WritePacket(buffer *buf.Buffer, destination M.Socks
|
||||
return err
|
||||
}
|
||||
}
|
||||
var dialer net.Dialer
|
||||
dialer.LocalAddr = destination.UDPAddr()
|
||||
dialer.Control = control.Append(dialer.Control, control.ReuseAddr())
|
||||
dialer.Control = control.Append(dialer.Control, redir.TProxyWriteBack())
|
||||
packetConn, err := w.listener.DialContext(dialer, w.ctx, "udp", w.source.String())
|
||||
var listenConfig net.ListenConfig
|
||||
listenConfig.Control = control.Append(listenConfig.Control, control.ReuseAddr())
|
||||
listenConfig.Control = control.Append(listenConfig.Control, redir.TProxyWriteBack())
|
||||
packetConn, err := w.listener.ListenPacket(listenConfig, w.ctx, "udp", destination.String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user