Skip to content

Commit

Permalink
rule: fix parsing zero priority rule
Browse files Browse the repository at this point in the history
  • Loading branch information
jronak committed Apr 11, 2024
1 parent aafe841 commit d00eea0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions rule_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,26 @@ 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 rules with specific priority",
ruleFilter: &Rule{Priority: 5},
Expand Down

0 comments on commit d00eea0

Please sign in to comment.