Skip to content

Conversation

stephanreiter
Copy link

@stephanreiter stephanreiter commented Jun 26, 2025

When reading rules, makes sure to populate the type field of Rule.
Also adds a l3mdev flag to Rule, reads it and makes sure it is taken into account when comparing rules using Equal as introduced in #1095.

This fixes #1055

@stephanreiter
Copy link
Author

Let's try to get #1095 in first, then rebase.

@stephanreiter stephanreiter force-pushed the read-rule-type-and-l3mdev-flag branch 2 times, most recently from 19ea691 to 157d171 Compare June 29, 2025 10:47
@stephanreiter stephanreiter force-pushed the read-rule-type-and-l3mdev-flag branch from 157d171 to c3c34ed Compare July 22, 2025 19:58
This adds an implementation of Rule.Equal
(and RulePortRange.Equal, RuleUIDRange.Equal)
which allows us to compare two Rule objects.
@stephanreiter stephanreiter force-pushed the read-rule-type-and-l3mdev-flag branch 11 times, most recently from ffee0e5 to 05f86e1 Compare July 22, 2025 20:56
When reading rules, makes sure to populate the type field of Rule.
Note that an unspecified type is interpreted as UNICAST, for example,
when adding a rule. To make sure that a rule with unspecified type,
which was just added, compares equal to that rule being read back,
we we update Rule.Equal to treat unspecified and UNICAST types as equal.

Also adds a l3mdev flag to Rule, reads it when listing rules,
sets it when updating rules, and makes sure it is taken into
account when comparing rules using Equal as introduced in vishvananda#1095.
@stephanreiter stephanreiter force-pushed the read-rule-type-and-l3mdev-flag branch from 05f86e1 to 393298d Compare July 22, 2025 21:01
r.Invert == x.Invert &&
r.Tos == x.Tos &&
(r.Type == x.Type ||
(r.Type == 0 && x.Type == 1 || r.Type == 1 && x.Type == 0)) && // 1 is unix.RTN_UNICAST
Copy link
Author

Choose a reason for hiding this comment

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

Not so sure about this one. Without it, tests that create a rule, then read it back and compare with the struct used for creating the rule, need to be updated because currently Type is left unset in the struct and reads back as UNICAST. Maybe that's better? It seems though that when deleting a rule again, we want to have the Type cleared in the struct. Saw some test failures when keeping Type set to unicast.

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.

RuleListFiltered and RuleList always return rule.Type=0

2 participants