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-09-16 18:56:47 +07:00
committed by Cuong Manh Le
parent 4c838f6a5e
commit 92f32ba16e
5 changed files with 8 additions and 17 deletions

View File

@@ -393,8 +393,7 @@ func (p *prog) upstreamFor(ctx context.Context, defaultUpstreamNum string, lc *c
}
matchingConfig = &rulematcher.MatchingConfig{
Order: order,
StopOnFirstMatch: lc.Policy.Matching.StopOnFirstMatch,
Order: order,
}
}

View File

@@ -170,8 +170,7 @@ func Test_prog_upstreamForWithCustomMatching(t *testing.T) {
{"*.ru": []string{"upstream.1"}},
},
Matching: &ctrld.MatchingConfig{
Order: []string{"domain", "mac", "network"},
StopOnFirstMatch: true,
Order: []string{"domain", "mac", "network"},
},
}

View File

@@ -317,8 +317,7 @@ func (lc *ListenerConfig) IsDirectDnsListener() bool {
// MatchingConfig defines the configuration for rule matching behavior
type MatchingConfig struct {
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"`
Order []string `mapstructure:"order" toml:"order,omitempty" json:"order" yaml:"order"`
}
// ListenerPolicyConfig specifies the policy rules for ctrld to filter incoming requests.

View File

@@ -53,8 +53,7 @@ func TestMatchingEngine(t *testing.T) {
{
name: "Custom order - domain first",
config: &MatchingConfig{
Order: []RuleType{RuleTypeDomain, RuleTypeNetwork, RuleTypeMac},
StopOnFirstMatch: true,
Order: []RuleType{RuleTypeDomain, RuleTypeNetwork, RuleTypeMac},
},
request: &MatchRequest{
SourceIP: net.ParseIP("192.168.0.1"),
@@ -77,8 +76,7 @@ func TestMatchingEngine(t *testing.T) {
{
name: "Custom order - MAC first",
config: &MatchingConfig{
Order: []RuleType{RuleTypeMac, RuleTypeNetwork, RuleTypeDomain},
StopOnFirstMatch: true,
Order: []RuleType{RuleTypeMac, RuleTypeNetwork, RuleTypeDomain},
},
request: &MatchRequest{
SourceIP: net.ParseIP("192.168.0.1"),
@@ -184,7 +182,6 @@ func TestDefaultMatchingConfig(t *testing.T) {
config := DefaultMatchingConfig()
assert.Equal(t, []RuleType{RuleTypeNetwork, RuleTypeMac, RuleTypeDomain}, config.Order)
assert.True(t, config.StopOnFirstMatch)
}
func TestMatchingEngineWithInvalidRuleType(t *testing.T) {
@@ -201,8 +198,7 @@ func TestMatchingEngineWithInvalidRuleType(t *testing.T) {
}
config := &MatchingConfig{
Order: []RuleType{RuleType("invalid"), RuleTypeNetwork},
StopOnFirstMatch: true,
Order: []RuleType{RuleType("invalid"), RuleTypeNetwork},
}
engine := NewMatchingEngine(config)

View File

@@ -41,15 +41,13 @@ type MatchResult struct {
// MatchingConfig defines the configuration for rule matching behavior
type MatchingConfig struct {
Order []RuleType `json:"order" yaml:"order"`
StopOnFirstMatch bool `json:"stop_on_first_match" yaml:"stop_on_first_match"`
Order []RuleType `json:"order" yaml:"order"`
}
// DefaultMatchingConfig returns the default matching configuration
// This maintains backward compatibility with the current behavior
func DefaultMatchingConfig() *MatchingConfig {
return &MatchingConfig{
Order: []RuleType{RuleTypeNetwork, RuleTypeMac, RuleTypeDomain},
StopOnFirstMatch: true,
Order: []RuleType{RuleTypeNetwork, RuleTypeMac, RuleTypeDomain},
}
}