mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-06-13 21:54:13 +08: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"`
|
GeoIP badoption.Listable[string] `json:"geoip,omitempty"`
|
||||||
IPCIDR badoption.Listable[string] `json:"ip_cidr,omitempty"`
|
IPCIDR badoption.Listable[string] `json:"ip_cidr,omitempty"`
|
||||||
IPIsPrivate bool `json:"ip_is_private,omitempty"`
|
IPIsPrivate bool `json:"ip_is_private,omitempty"`
|
||||||
|
IPAcceptAny bool `json:"ip_accept_any,omitempty"`
|
||||||
SourceIPCIDR badoption.Listable[string] `json:"source_ip_cidr,omitempty"`
|
SourceIPCIDR badoption.Listable[string] `json:"source_ip_cidr,omitempty"`
|
||||||
SourceIPIsPrivate bool `json:"source_ip_is_private,omitempty"`
|
SourceIPIsPrivate bool `json:"source_ip_is_private,omitempty"`
|
||||||
SourcePort badoption.Listable[uint16] `json:"source_port,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.destinationIPCIDRItems = append(rule.destinationIPCIDRItems, item)
|
||||||
rule.allItems = append(rule.allItems, 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 {
|
if len(options.SourcePort) > 0 {
|
||||||
item := NewPortItem(true, options.SourcePort)
|
item := NewPortItem(true, options.SourcePort)
|
||||||
rule.sourcePortItems = append(rule.sourcePortItems, item)
|
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…
x
Reference in New Issue
Block a user