mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
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.
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package rulematcher
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
|
|
"github.com/Control-D-Inc/ctrld"
|
|
)
|
|
|
|
// RuleType represents the type of rule being matched
|
|
type RuleType string
|
|
|
|
const (
|
|
RuleTypeNetwork RuleType = "network"
|
|
RuleTypeMac RuleType = "mac"
|
|
RuleTypeDomain RuleType = "domain"
|
|
)
|
|
|
|
// RuleMatcher defines the interface for matching different types of rules
|
|
type RuleMatcher interface {
|
|
Match(ctx context.Context, request *MatchRequest) *MatchResult
|
|
Type() RuleType
|
|
}
|
|
|
|
// MatchRequest contains all the information needed for rule matching
|
|
type MatchRequest struct {
|
|
SourceIP net.IP
|
|
SourceMac string
|
|
Domain string
|
|
Policy *ctrld.ListenerPolicyConfig
|
|
Config *ctrld.Config
|
|
}
|
|
|
|
// MatchResult represents the result of a rule matching operation
|
|
type MatchResult struct {
|
|
Matched bool
|
|
Targets []string
|
|
MatchedRule string
|
|
RuleType RuleType
|
|
}
|
|
|
|
// MatchingConfig defines the configuration for rule matching behavior
|
|
type MatchingConfig struct {
|
|
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},
|
|
}
|
|
}
|