Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rule: fix parsing zero priority rule #962

Merged
merged 1 commit into from
Apr 11, 2024
Merged

Conversation

jronak
Copy link
Contributor

@jronak jronak commented Mar 27, 2024

Fixes #709 (see issue for repro)

This happens as the rule with priority=0 don't contain nl.FRA_PRIORITY attribute, which leaves the priority in the struct as -1 which was set by NewRule.

Wrote a test which fails before the fix:

--- FAIL: TestRuleListFiltered (0.01s)
    --- FAIL: TestRuleListFiltered/IPv4 (0.00s)
        --- FAIL: TestRuleListFiltered/IPv4/returns_rules_with_highest_priority (0.00s)
            rule_test.go:373: Expected len: 1, got: 0
    --- FAIL: TestRuleListFiltered/IPv6 (0.00s)
        --- FAIL: TestRuleListFiltered/IPv6/returns_rules_with_highest_priority (0.00s)
            rule_test.go:373: Expected len: 1, got: 0

@jronak jronak force-pushed the fix/rule-prio branch 2 times, most recently from 24401a1 to 37131be Compare March 27, 2024 23:19
rule_linux.go Outdated Show resolved Hide resolved
@@ -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},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, we should also test the situation where the rule priority is not specified by us when we program the kernel. That happens when we client uses the NewRule() method, and Priority is set to -1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated tests to add rule with priority unset, which results into rule creation with priority preceding main table (32766).

@aboch
Copy link
Collaborator

aboch commented Apr 10, 2024

@jronak

@aboch
Copy link
Collaborator

aboch commented Apr 11, 2024

Thanks. Please squash your two commits into one.

@jronak
Copy link
Contributor Author

jronak commented Apr 11, 2024

Squashed commits into one, thanks!

@aboch
Copy link
Collaborator

aboch commented Apr 11, 2024

LGTM

@aboch aboch merged commit 578e95c into vishvananda:main Apr 11, 2024
2 checks passed
@jronak jronak deleted the fix/rule-prio branch April 11, 2024 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ip-rule] priority 0 rule returned as -1
2 participants