Files
世界 52e72736ad route: simplify rule_set matching semantics
Since b0c6762bc, every rule inside a referenced rule-set was evaluated
as if merged into the outer rule, which required tracking per-branch
group states and let outer rules and rule-set rules satisfy each
other's grouped conditions in both directions.

Restrict merging to the only designed case: a rule-set containing
exactly one non-inverted default rule is merged into the outer rule as
before. Any other rule-set now matches as an ordinary condition of the
outer rule: it matches when any of its rules matches on its own, and
its rules no longer exchange grouped match state with the outer rule
in either direction. Multiple referenced rule-sets keep OR semantics.

Flat address rule-sets such as generated geosite/geoip sets contain a
single default rule, so their behavior is unchanged. The group-state
set machinery is replaced by a single required/satisfied mask pair.

Also update the route and DNS rule docs.
2026-07-23 14:16:55 +08:00

27 lines
529 B
Go

package rule
type ruleMatchState uint8
const (
ruleMatchSourceAddress ruleMatchState = 1 << iota
ruleMatchSourcePort
ruleMatchDestinationAddress
ruleMatchDestinationPort
)
type ruleGroupMatch struct {
required ruleMatchState
satisfied ruleMatchState
}
func (g ruleGroupMatch) done() bool {
return g.required&^g.satisfied == 0
}
func (g ruleGroupMatch) mergeWith(other ruleGroupMatch) ruleGroupMatch {
return ruleGroupMatch{
required: g.required | other.required,
satisfied: g.satisfied | other.satisfied,
}
}