Skip to content

Commit

Permalink
rule: fix parsing zero priority rule
Browse files Browse the repository at this point in the history
jronak authored and aboch committed Apr 11, 2024

Verified

This commit was signed with the committer’s verified signature.
renovate-bot Mend Renovate
1 parent f4e6e3d commit 578e95c
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions rule_linux.go
Original file line number Diff line number Diff line change
@@ -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)
41 changes: 41 additions & 0 deletions rule_test.go
Original file line number Diff line number Diff line change
@@ -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},

0 comments on commit 578e95c

Please sign in to comment.