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

Publish NI routes in a deterministic and easy-to-read order #4298

Merged
merged 1 commit into from
Sep 27, 2024

Conversation

milan-zededa
Copy link
Contributor

First IPv4 routes will be listed, then IPv6 routes. Inside the set of routes of the same IP version, default routes appear first for clarity, followed by other routes ordered by prefix length, with more specific routes (longer prefixes) listed before broader ones. This is at least how Linux lists the routes of a routing table.

We also want to avoid returning <nil> as destination network for default routes, and instead show destination as 0.0.0.0/0 or ::/0

case generic.IPv4RouteTypename:
ipVer = types.AddressTypeIPV4
case generic.IPv6RouteTypename:
ipVer = types.AddressTypeIPV6
Copy link
Member

Choose a reason for hiding this comment

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

I see the Type() function may also return generic items.UnsupportedRouteTypename. Shouldn't we add it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We will leave the zero value types.AddressTypeNone in that case which is OK I think.

// first for clarity, followed by other routes ordered by prefix length,
// with more specific routes (longer prefixes) listed before broader ones.
// This is at least how Linux lists the routes of a routing table.
sort.Slice(routes, func(i, j int) bool {
Copy link
Member

Choose a reason for hiding this comment

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

The entire function is a good candidate for a Unit test, if you have time for that)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Working on it

Copy link
Member

Choose a reason for hiding this comment

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

Will you add it to this PR? Or we should not wait for it and it comes later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, added

Copy link
Member

Choose a reason for hiding this comment

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

cool, thanks!

Copy link
Member

@OhmSpectator OhmSpectator left a comment

Choose a reason for hiding this comment

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

Run Eden tests

@milan-zededa milan-zededa force-pushed the rt-table-improvements branch 2 times, most recently from 76de04f to 6ed060b Compare September 26, 2024 15:15
First IPv4 routes will be listed, then IPv6 routes.
Inside the set of routes of the same IP version, default routes appear
first for clarity, followed by other routes ordered by prefix length,
with more specific routes (longer prefixes) listed before broader ones.
This is at least how Linux lists the routes of a routing table.

We also want to avoid returning <nil> as destination network for default
routes, and instead show destination as 0.0.0.0/0 or ::/0

Signed-off-by: Milan Lenco <[email protected]>
@OhmSpectator OhmSpectator self-requested a review September 26, 2024 15:57
@eriknordmark eriknordmark merged commit a6136cf into lf-edge:master Sep 27, 2024
53 checks passed
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.

3 participants