From c4d9be9e0d94cff5ea5e73dce9c6a2d8ed73b081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sun, 14 Jan 2024 13:01:57 +0800 Subject: [PATCH] Fix rule match --- common/srs/binary.go | 2 +- route/rule_abstract.go | 6 +++--- route/rule_default.go | 2 +- route/rule_dns.go | 2 +- route/rule_headless.go | 2 +- route/rule_item_cidr.go | 8 ++++---- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/common/srs/binary.go b/common/srs/binary.go index 8d10e346..faf4cd17 100644 --- a/common/srs/binary.go +++ b/common/srs/binary.go @@ -253,7 +253,7 @@ func writeDefaultRule(writer io.Writer, rule option.DefaultHeadlessRule) error { if len(rule.SourceIPCIDR) > 0 { err = writeRuleItemCIDR(writer, ruleItemSourceIPCIDR, rule.SourceIPCIDR) if err != nil { - return E.Cause(err, "source_ipcidr") + return E.Cause(err, "source_ip_cidr") } } if len(rule.IPCIDR) > 0 { diff --git a/route/rule_abstract.go b/route/rule_abstract.go index 7a4a759e..6decb9f3 100644 --- a/route/rule_abstract.go +++ b/route/rule_abstract.go @@ -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 { if item.Match(metadata) { 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 { if item.Match(metadata) { 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 { if item.Match(metadata) { metadata.DestinationPortMatch = true diff --git a/route/rule_default.go b/route/rule_default.go index 1a190ce0..d2227bb3 100644 --- a/route/rule_default.go +++ b/route/rule_default.go @@ -115,7 +115,7 @@ func NewDefaultRule(router adapter.Router, logger log.ContextLogger, options opt if len(options.SourceIPCIDR) > 0 { item, err := NewIPCIDRItem(true, options.SourceIPCIDR) 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.allItems = append(rule.allItems, item) diff --git a/route/rule_dns.go b/route/rule_dns.go index 1f55d50e..c43f6290 100644 --- a/route/rule_dns.go +++ b/route/rule_dns.go @@ -114,7 +114,7 @@ func NewDefaultDNSRule(router adapter.Router, logger log.ContextLogger, options if len(options.SourceIPCIDR) > 0 { item, err := NewIPCIDRItem(true, options.SourceIPCIDR) 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.allItems = append(rule.allItems, item) diff --git a/route/rule_headless.go b/route/rule_headless.go index 9df2ee30..82c07d31 100644 --- a/route/rule_headless.go +++ b/route/rule_headless.go @@ -66,7 +66,7 @@ func NewDefaultHeadlessRule(router adapter.Router, options option.DefaultHeadles if len(options.SourceIPCIDR) > 0 { item, err := NewIPCIDRItem(true, options.SourceIPCIDR) 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.allItems = append(rule.allItems, item) diff --git a/route/rule_item_cidr.go b/route/rule_item_cidr.go index e17d87de..0e15e674 100644 --- a/route/rule_item_cidr.go +++ b/route/rule_item_cidr.go @@ -35,9 +35,9 @@ func NewIPCIDRItem(isSource bool, prefixStrings []string) (*IPCIDRItem, error) { } var description string if isSource { - description = "source_ipcidr=" + description = "source_ip_cidr=" } else { - description = "ipcidr=" + description = "ip_cidr=" } if dLen := len(prefixStrings); dLen == 1 { description += prefixStrings[0] @@ -60,9 +60,9 @@ func NewIPCIDRItem(isSource bool, prefixStrings []string) (*IPCIDRItem, error) { func NewRawIPCIDRItem(isSource bool, ipSet *netipx.IPSet) *IPCIDRItem { var description string if isSource { - description = "source_ipcidr=" + description = "source_ip_cidr=" } else { - description = "ipcidr=" + description = "ip_cidr=" } description += "" return &IPCIDRItem{