rule: fix parsing zero priority rule

This commit is contained in:
Ronak Jain 2024-03-27 21:23:31 +00:00 committed by Alessandro Boch
parent f4e6e3d5d5
commit 578e95cc31
2 changed files with 42 additions and 0 deletions

View File

@ -221,6 +221,7 @@ func (h *Handle) RuleListFiltered(family int, filter *Rule, filterMask uint64) (
}
rule := NewRule()
rule.Priority = 0 // The default priority from kernel
rule.Invert = msg.Flags&FibRuleInvert > 0
rule.Family = int(msg.Family)

View File

@ -222,6 +222,47 @@ func runRuleListFiltered(t *testing.T, family int, srcNet, dstNet *net.IPNet) {
return rs, false
},
},
{
name: "returns one rule filtered by Priority(0) and Table",
ruleFilter: &Rule{Priority: 0, Table: 1},
filterMask: RT_FILTER_PRIORITY | RT_FILTER_TABLE,
preRun: func() *Rule {
r := NewRule()
r.Src = srcNet
r.Priority = 0
r.Family = family
r.Table = 1
RuleAdd(r)
return r
},
postRun: func(r *Rule) {
RuleDel(r)
},
setupWant: func(r *Rule) ([]Rule, bool) {
return []Rule{*r}, false
},
},
{
name: "returns one rule filtered by Priority preceding main-table rule",
ruleFilter: &Rule{Priority: 32765},
filterMask: RT_FILTER_PRIORITY,
preRun: func() *Rule {
r := NewRule()
r.Src = srcNet
r.Family = family
r.Table = 1
RuleAdd(r)
r.Priority = 32765 // Set priority for assertion
return r
},
postRun: func(r *Rule) {
RuleDel(r)
},
setupWant: func(r *Rule) ([]Rule, bool) {
return []Rule{*r}, false
},
},
{
name: "returns rules with specific priority",
ruleFilter: &Rule{Priority: 5},