mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-02-06 00:10:38 +00:00
Add ip_accept_any
DNS rule action
This commit is contained in:
parent
1947a90878
commit
1c56213cbe
|
@ -83,6 +83,7 @@ type RawDefaultDNSRule struct {
|
|||
GeoIP badoption.Listable[string] `json:"geoip,omitempty"`
|
||||
IPCIDR badoption.Listable[string] `json:"ip_cidr,omitempty"`
|
||||
IPIsPrivate bool `json:"ip_is_private,omitempty"`
|
||||
IPAcceptAny bool `json:"ip_accept_any,omitempty"`
|
||||
SourceIPCIDR badoption.Listable[string] `json:"source_ip_cidr,omitempty"`
|
||||
SourceIPIsPrivate bool `json:"source_ip_is_private,omitempty"`
|
||||
SourcePort badoption.Listable[uint16] `json:"source_port,omitempty"`
|
||||
|
|
|
@ -145,6 +145,11 @@ func NewDefaultDNSRule(ctx context.Context, logger log.ContextLogger, options op
|
|||
rule.destinationIPCIDRItems = append(rule.destinationIPCIDRItems, item)
|
||||
rule.allItems = append(rule.allItems, item)
|
||||
}
|
||||
if options.IPAcceptAny {
|
||||
item := NewIPAcceptAnyItem()
|
||||
rule.destinationIPCIDRItems = append(rule.destinationIPCIDRItems, item)
|
||||
rule.allItems = append(rule.allItems, item)
|
||||
}
|
||||
if len(options.SourcePort) > 0 {
|
||||
item := NewPortItem(true, options.SourcePort)
|
||||
rule.sourcePortItems = append(rule.sourcePortItems, item)
|
||||
|
|
21
route/rule/rule_item_ip_accept_any.go
Normal file
21
route/rule/rule_item_ip_accept_any.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package rule
|
||||
|
||||
import (
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
)
|
||||
|
||||
var _ RuleItem = (*IPAcceptAnyItem)(nil)
|
||||
|
||||
type IPAcceptAnyItem struct{}
|
||||
|
||||
func NewIPAcceptAnyItem() *IPAcceptAnyItem {
|
||||
return &IPAcceptAnyItem{}
|
||||
}
|
||||
|
||||
func (r *IPAcceptAnyItem) Match(metadata *adapter.InboundContext) bool {
|
||||
return len(metadata.DestinationAddresses) > 0
|
||||
}
|
||||
|
||||
func (r *IPAcceptAnyItem) String() string {
|
||||
return "ip_accept_any=true"
|
||||
}
|
Loading…
Reference in a new issue