Fix rule match

This commit is contained in:
世界 2024-01-14 13:01:57 +08:00
parent f31c604b3d
commit c4d9be9e0d
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
6 changed files with 11 additions and 11 deletions

View File

@ -253,7 +253,7 @@ func writeDefaultRule(writer io.Writer, rule option.DefaultHeadlessRule) error {
if len(rule.SourceIPCIDR) > 0 { if len(rule.SourceIPCIDR) > 0 {
err = writeRuleItemCIDR(writer, ruleItemSourceIPCIDR, rule.SourceIPCIDR) err = writeRuleItemCIDR(writer, ruleItemSourceIPCIDR, rule.SourceIPCIDR)
if err != nil { if err != nil {
return E.Cause(err, "source_ipcidr") return E.Cause(err, "source_ip_cidr")
} }
} }
if len(rule.IPCIDR) > 0 { if len(rule.IPCIDR) > 0 {

View File

@ -72,7 +72,7 @@ func (r *abstractDefaultRule) Match(metadata *adapter.InboundContext) bool {
} }
} }
if len(r.sourcePortItems) > 0 && !metadata.SourceAddressMatch { if len(r.sourcePortItems) > 0 && !metadata.SourcePortMatch {
for _, item := range r.sourcePortItems { for _, item := range r.sourcePortItems {
if item.Match(metadata) { if item.Match(metadata) {
metadata.SourcePortMatch = true metadata.SourcePortMatch = true
@ -81,7 +81,7 @@ func (r *abstractDefaultRule) Match(metadata *adapter.InboundContext) bool {
} }
} }
if len(r.destinationAddressItems) > 0 && !metadata.SourceAddressMatch { if len(r.destinationAddressItems) > 0 && !metadata.DestinationAddressMatch {
for _, item := range r.destinationAddressItems { for _, item := range r.destinationAddressItems {
if item.Match(metadata) { if item.Match(metadata) {
metadata.DestinationAddressMatch = true metadata.DestinationAddressMatch = true
@ -90,7 +90,7 @@ func (r *abstractDefaultRule) Match(metadata *adapter.InboundContext) bool {
} }
} }
if len(r.destinationPortItems) > 0 && !metadata.SourceAddressMatch { if len(r.destinationPortItems) > 0 && !metadata.DestinationPortMatch {
for _, item := range r.destinationPortItems { for _, item := range r.destinationPortItems {
if item.Match(metadata) { if item.Match(metadata) {
metadata.DestinationPortMatch = true metadata.DestinationPortMatch = true

View File

@ -115,7 +115,7 @@ func NewDefaultRule(router adapter.Router, logger log.ContextLogger, options opt
if len(options.SourceIPCIDR) > 0 { if len(options.SourceIPCIDR) > 0 {
item, err := NewIPCIDRItem(true, options.SourceIPCIDR) item, err := NewIPCIDRItem(true, options.SourceIPCIDR)
if err != nil { if err != nil {
return nil, E.Cause(err, "source_ipcidr") return nil, E.Cause(err, "source_ip_cidr")
} }
rule.sourceAddressItems = append(rule.sourceAddressItems, item) rule.sourceAddressItems = append(rule.sourceAddressItems, item)
rule.allItems = append(rule.allItems, item) rule.allItems = append(rule.allItems, item)

View File

@ -114,7 +114,7 @@ func NewDefaultDNSRule(router adapter.Router, logger log.ContextLogger, options
if len(options.SourceIPCIDR) > 0 { if len(options.SourceIPCIDR) > 0 {
item, err := NewIPCIDRItem(true, options.SourceIPCIDR) item, err := NewIPCIDRItem(true, options.SourceIPCIDR)
if err != nil { if err != nil {
return nil, E.Cause(err, "source_ipcidr") return nil, E.Cause(err, "source_ip_cidr")
} }
rule.sourceAddressItems = append(rule.sourceAddressItems, item) rule.sourceAddressItems = append(rule.sourceAddressItems, item)
rule.allItems = append(rule.allItems, item) rule.allItems = append(rule.allItems, item)

View File

@ -66,7 +66,7 @@ func NewDefaultHeadlessRule(router adapter.Router, options option.DefaultHeadles
if len(options.SourceIPCIDR) > 0 { if len(options.SourceIPCIDR) > 0 {
item, err := NewIPCIDRItem(true, options.SourceIPCIDR) item, err := NewIPCIDRItem(true, options.SourceIPCIDR)
if err != nil { if err != nil {
return nil, E.Cause(err, "source_ipcidr") return nil, E.Cause(err, "source_ip_cidr")
} }
rule.sourceAddressItems = append(rule.sourceAddressItems, item) rule.sourceAddressItems = append(rule.sourceAddressItems, item)
rule.allItems = append(rule.allItems, item) rule.allItems = append(rule.allItems, item)

View File

@ -35,9 +35,9 @@ func NewIPCIDRItem(isSource bool, prefixStrings []string) (*IPCIDRItem, error) {
} }
var description string var description string
if isSource { if isSource {
description = "source_ipcidr=" description = "source_ip_cidr="
} else { } else {
description = "ipcidr=" description = "ip_cidr="
} }
if dLen := len(prefixStrings); dLen == 1 { if dLen := len(prefixStrings); dLen == 1 {
description += prefixStrings[0] description += prefixStrings[0]
@ -60,9 +60,9 @@ func NewIPCIDRItem(isSource bool, prefixStrings []string) (*IPCIDRItem, error) {
func NewRawIPCIDRItem(isSource bool, ipSet *netipx.IPSet) *IPCIDRItem { func NewRawIPCIDRItem(isSource bool, ipSet *netipx.IPSet) *IPCIDRItem {
var description string var description string
if isSource { if isSource {
description = "source_ipcidr=" description = "source_ip_cidr="
} else { } else {
description = "ipcidr=" description = "ip_cidr="
} }
description += "<binary>" description += "<binary>"
return &IPCIDRItem{ return &IPCIDRItem{