feat: RULE-SET in rules support ,src option

should only be used with `ipcidr` behavior
This commit is contained in:
wwqgtxx
2024-08-29 23:49:16 +08:00
parent a96f72ade4
commit 763a127287
5 changed files with 29 additions and 10 deletions

View File

@@ -12,6 +12,7 @@ type RuleSet struct {
*common.Base
ruleProviderName string
adapter string
isSrc bool
noResolveIP bool
shouldFindProcess bool
}
@@ -32,6 +33,10 @@ func (rs *RuleSet) RuleType() C.RuleType {
func (rs *RuleSet) Match(metadata *C.Metadata) (bool, string) {
if provider, ok := rs.getProvider(); ok {
if rs.isSrc {
metadata.SwapSrcDst()
defer metadata.SwapSrcDst()
}
return provider.Match(metadata), rs.adapter
}
return false, ""
@@ -76,11 +81,12 @@ func (rs *RuleSet) getProvider() (P.RuleProvider, bool) {
return pp, ok
}
func NewRuleSet(ruleProviderName string, adapter string, noResolveIP bool) (*RuleSet, error) {
func NewRuleSet(ruleProviderName string, adapter string, isSrc bool, noResolveIP bool) (*RuleSet, error) {
rs := &RuleSet{
Base: &common.Base{},
ruleProviderName: ruleProviderName,
adapter: adapter,
isSrc: isSrc,
noResolveIP: noResolveIP,
}
return rs, nil