refactor: remove unused StopOnFirstMatch field from MatchingConfig

Remove StopOnFirstMatch field that was defined but never used in the
actual matching logic.

The current implementation always evaluates all rule types and applies
a fixed precedence (Domain > MAC > Network), making the StopOnFirstMatch
field unnecessary.

Changes:
- Remove StopOnFirstMatch from MatchingConfig structs
- Update DefaultMatchingConfig() function
- Update all test cases and references
- Simplify configuration to only include Order field

This cleanup removes dead code and simplifies the configuration API
without changing any functional behavior.
This commit is contained in:
Cuong Manh Le
2025-10-09 19:12:06 +07:00
committed by Cuong Manh Le
parent 4c838f6a5e
commit 92f32ba16e
5 changed files with 8 additions and 17 deletions
-1
View File
@@ -394,7 +394,6 @@ func (p *prog) upstreamFor(ctx context.Context, defaultUpstreamNum string, lc *c
matchingConfig = &rulematcher.MatchingConfig{ matchingConfig = &rulematcher.MatchingConfig{
Order: order, Order: order,
StopOnFirstMatch: lc.Policy.Matching.StopOnFirstMatch,
} }
} }
-1
View File
@@ -171,7 +171,6 @@ func Test_prog_upstreamForWithCustomMatching(t *testing.T) {
}, },
Matching: &ctrld.MatchingConfig{ Matching: &ctrld.MatchingConfig{
Order: []string{"domain", "mac", "network"}, Order: []string{"domain", "mac", "network"},
StopOnFirstMatch: true,
}, },
} }
-1
View File
@@ -318,7 +318,6 @@ func (lc *ListenerConfig) IsDirectDnsListener() bool {
// MatchingConfig defines the configuration for rule matching behavior // MatchingConfig defines the configuration for rule matching behavior
type MatchingConfig struct { type MatchingConfig struct {
Order []string `mapstructure:"order" toml:"order,omitempty" json:"order" yaml:"order"` Order []string `mapstructure:"order" toml:"order,omitempty" json:"order" yaml:"order"`
StopOnFirstMatch bool `mapstructure:"stop_on_first_match" toml:"stop_on_first_match,omitempty" json:"stop_on_first_match" yaml:"stop_on_first_match"`
} }
// ListenerPolicyConfig specifies the policy rules for ctrld to filter incoming requests. // ListenerPolicyConfig specifies the policy rules for ctrld to filter incoming requests.
-4
View File
@@ -54,7 +54,6 @@ func TestMatchingEngine(t *testing.T) {
name: "Custom order - domain first", name: "Custom order - domain first",
config: &MatchingConfig{ config: &MatchingConfig{
Order: []RuleType{RuleTypeDomain, RuleTypeNetwork, RuleTypeMac}, Order: []RuleType{RuleTypeDomain, RuleTypeNetwork, RuleTypeMac},
StopOnFirstMatch: true,
}, },
request: &MatchRequest{ request: &MatchRequest{
SourceIP: net.ParseIP("192.168.0.1"), SourceIP: net.ParseIP("192.168.0.1"),
@@ -78,7 +77,6 @@ func TestMatchingEngine(t *testing.T) {
name: "Custom order - MAC first", name: "Custom order - MAC first",
config: &MatchingConfig{ config: &MatchingConfig{
Order: []RuleType{RuleTypeMac, RuleTypeNetwork, RuleTypeDomain}, Order: []RuleType{RuleTypeMac, RuleTypeNetwork, RuleTypeDomain},
StopOnFirstMatch: true,
}, },
request: &MatchRequest{ request: &MatchRequest{
SourceIP: net.ParseIP("192.168.0.1"), SourceIP: net.ParseIP("192.168.0.1"),
@@ -184,7 +182,6 @@ func TestDefaultMatchingConfig(t *testing.T) {
config := DefaultMatchingConfig() config := DefaultMatchingConfig()
assert.Equal(t, []RuleType{RuleTypeNetwork, RuleTypeMac, RuleTypeDomain}, config.Order) assert.Equal(t, []RuleType{RuleTypeNetwork, RuleTypeMac, RuleTypeDomain}, config.Order)
assert.True(t, config.StopOnFirstMatch)
} }
func TestMatchingEngineWithInvalidRuleType(t *testing.T) { func TestMatchingEngineWithInvalidRuleType(t *testing.T) {
@@ -202,7 +199,6 @@ func TestMatchingEngineWithInvalidRuleType(t *testing.T) {
config := &MatchingConfig{ config := &MatchingConfig{
Order: []RuleType{RuleType("invalid"), RuleTypeNetwork}, Order: []RuleType{RuleType("invalid"), RuleTypeNetwork},
StopOnFirstMatch: true,
} }
engine := NewMatchingEngine(config) engine := NewMatchingEngine(config)
-2
View File
@@ -42,7 +42,6 @@ type MatchResult struct {
// MatchingConfig defines the configuration for rule matching behavior // MatchingConfig defines the configuration for rule matching behavior
type MatchingConfig struct { type MatchingConfig struct {
Order []RuleType `json:"order" yaml:"order"` Order []RuleType `json:"order" yaml:"order"`
StopOnFirstMatch bool `json:"stop_on_first_match" yaml:"stop_on_first_match"`
} }
// DefaultMatchingConfig returns the default matching configuration // DefaultMatchingConfig returns the default matching configuration
@@ -50,6 +49,5 @@ type MatchingConfig struct {
func DefaultMatchingConfig() *MatchingConfig { func DefaultMatchingConfig() *MatchingConfig {
return &MatchingConfig{ return &MatchingConfig{
Order: []RuleType{RuleTypeNetwork, RuleTypeMac, RuleTypeDomain}, Order: []RuleType{RuleTypeNetwork, RuleTypeMac, RuleTypeDomain},
StopOnFirstMatch: true,
} }
} }