refactor: Outbound domain resolver

This commit is contained in:
世界
2025-01-12 12:45:27 +08:00
parent eae2631208
commit 63ef6f972f
25 changed files with 93 additions and 36 deletions

View File

@@ -49,7 +49,7 @@ func NewRuleAction(ctx context.Context, logger logger.ContextLogger, action opti
UDPTimeout: time.Duration(action.RouteOptionsOptions.UDPTimeout),
}, nil
case C.RuleActionTypeDirect:
directDialer, err := dialer.New(ctx, option.DialerOptions(action.DirectOptions))
directDialer, err := dialer.New(ctx, option.DialerOptions(action.DirectOptions), false)
if err != nil {
return nil, err
}

View File

@@ -205,7 +205,7 @@ func NewDefaultDNSRule(ctx context.Context, logger log.ContextLogger, options op
rule.allItems = append(rule.allItems, item)
}
if len(options.Outbound) > 0 {
item := NewOutboundRule(options.Outbound)
item := NewOutboundRule(ctx, options.Outbound)
rule.items = append(rule.items, item)
rule.allItems = append(rule.allItems, item)
}

View File

@@ -1,9 +1,11 @@
package rule
import (
"context"
"strings"
"github.com/sagernet/sing-box/adapter"
"github.com/sagernet/sing-box/experimental/deprecated"
F "github.com/sagernet/sing/common/format"
)
@@ -15,7 +17,8 @@ type OutboundItem struct {
matchAny bool
}
func NewOutboundRule(outbounds []string) *OutboundItem {
func NewOutboundRule(ctx context.Context, outbounds []string) *OutboundItem {
deprecated.Report(ctx, deprecated.OptionOutboundDNSRuleItem)
rule := &OutboundItem{outbounds: outbounds, outboundMap: make(map[string]bool)}
for _, outbound := range outbounds {
if outbound == "any" {
@@ -28,8 +31,8 @@ func NewOutboundRule(outbounds []string) *OutboundItem {
}
func (r *OutboundItem) Match(metadata *adapter.InboundContext) bool {
if r.matchAny && metadata.Outbound != "" {
return true
if r.matchAny {
return metadata.Outbound != ""
}
return r.outboundMap[metadata.Outbound]
}