Skip to content

Commit 578e95c

Browse files
jronakaboch
authored andcommitted
rule: fix parsing zero priority rule
1 parent f4e6e3d commit 578e95c

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

rule_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ func (h *Handle) RuleListFiltered(family int, filter *Rule, filterMask uint64) (
221221
}
222222

223223
rule := NewRule()
224+
rule.Priority = 0 // The default priority from kernel
224225

225226
rule.Invert = msg.Flags&FibRuleInvert > 0
226227
rule.Family = int(msg.Family)

rule_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,47 @@ func runRuleListFiltered(t *testing.T, family int, srcNet, dstNet *net.IPNet) {
222222
return rs, false
223223
},
224224
},
225+
{
226+
name: "returns one rule filtered by Priority(0) and Table",
227+
ruleFilter: &Rule{Priority: 0, Table: 1},
228+
filterMask: RT_FILTER_PRIORITY | RT_FILTER_TABLE,
229+
preRun: func() *Rule {
230+
r := NewRule()
231+
r.Src = srcNet
232+
r.Priority = 0
233+
r.Family = family
234+
r.Table = 1
235+
RuleAdd(r)
236+
return r
237+
},
238+
postRun: func(r *Rule) {
239+
RuleDel(r)
240+
},
241+
setupWant: func(r *Rule) ([]Rule, bool) {
242+
return []Rule{*r}, false
243+
},
244+
},
245+
{
246+
name: "returns one rule filtered by Priority preceding main-table rule",
247+
ruleFilter: &Rule{Priority: 32765},
248+
filterMask: RT_FILTER_PRIORITY,
249+
preRun: func() *Rule {
250+
r := NewRule()
251+
r.Src = srcNet
252+
r.Family = family
253+
r.Table = 1
254+
RuleAdd(r)
255+
256+
r.Priority = 32765 // Set priority for assertion
257+
return r
258+
},
259+
postRun: func(r *Rule) {
260+
RuleDel(r)
261+
},
262+
setupWant: func(r *Rule) ([]Rule, bool) {
263+
return []Rule{*r}, false
264+
},
265+
},
225266
{
226267
name: "returns rules with specific priority",
227268
ruleFilter: &Rule{Priority: 5},

0 commit comments

Comments
 (0)