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

Add a builder for route messages #57

Merged
merged 2 commits into from
May 30, 2024

Conversation

little-dude
Copy link
Contributor

@little-dude little-dude commented Mar 25, 2024

For both the RouteAddRequest and RouteDelRequest, we need to build
a route message. However only the former provides helper methods to do
so. Instead of duplicating code, create a separate builder, and use it for
both request types.

This MR also allows building route requests parametrized by IpAddr, in
addition to the existing Ipv4Addr and Ipv6Addr implementations.


This is a non-backward compatible change.

@little-dude little-dude requested a review from cathay4t March 25, 2024 10:02
little-dude added a commit to little-dude/rtnetlink that referenced this pull request Mar 25, 2024
Copy link
Member

@cathay4t cathay4t left a comment

Choose a reason for hiding this comment

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

Please also fix examples/add_route.rs

src/route/builder.rs Outdated Show resolved Hide resolved
@cathay4t
Copy link
Member

In general, I like the idea of XxxBuilder instead old on-line changes of message_mut().

@richardstephens
Copy link
Contributor

richardstephens commented Mar 30, 2024

Hi, I'm jumping into the discussion here on request of @cathay4t in response to my PR number #53 .

Our product uses rtnetlink quite extensively to configure the host's networking. In principle, I would much rather use Builder's that make the intent of the netlink command we issue clear from the code. However I've sturggled a bit with understanding how to achieve my desired results by reading the netlink documentation. My dev loop often involved strace'ing ip or bridge commands to find out what the netlink message I need looks like.

I'm also specifically concerned about the message header flags. In my PR, I was not able to achieve the desired result with a set link message - I needed to issue an 'add' link message with the correct flags even though I was updating an existing object. I'm not sure how to design a clean API for this other than by exposing API to manipulate the flags directly.

I'm happy to make another attempt at that PR in line with the builder approach, along with type-safe setters for the flags. What do you think?

@cathay4t
Copy link
Member

cathay4t commented Apr 1, 2024

Hi, I'm jumping into the discussion here on request of @cathay4t in response to my PR number #53 .

Our product uses rtnetlink quite extensively to configure the host's networking. In principle, I would much rather use Builder's that make the intent of the netlink command we issue clear from the code. However I've sturggled a bit with understanding how to achieve my desired results by reading the netlink documentation. My dev loop often involved strace'ing ip or bridge commands to find out what the netlink message I need looks like.

There is no good netlink document except kernel code. I also use strace -s 10000 for ip command initially, but will cross reference with kernel code.

I'm also specifically concerned about the message header flags. In my PR, I was not able to achieve the desired result with a set link message - I needed to issue an 'add' link message with the correct flags even though I was updating an existing object. I'm not sure how to design a clean API for this other than by exposing API to manipulate the flags directly.

I will tag new release to netlink-packit-route this week which will contain big changes(sorry) to flags.
Exposing a API at rtnetlink level for flags is simpler for this builder workflow now.

I'm happy to make another attempt at that PR in line with the builder approach, along with type-safe setters for the flags. What do you think?

Sure, but please wait netlink-packit-route 0.20.0 release.

If @little-dude does not have time to move this PR forward, I will append my patches to this PR to get it merged next week.

@cathay4t
Copy link
Member

cathay4t commented Apr 11, 2024

@little-dude Do you mind If pick up your work here?

@little-dude
Copy link
Contributor Author

little-dude commented Apr 12, 2024

I'll try to fix this up today @cathay4t. Sorry, it's still busy at work, and I'm working on netlink by spikes

@little-dude little-dude force-pushed the route-msg-builder branch 2 times, most recently from 55038f6 to ef77d05 Compare April 12, 2024 13:37
@little-dude
Copy link
Contributor Author

Done, @cathay4t

We currently have `RouteAddRequest<Ipv4Addr>` and
`RouteAddRequest<Ipv6Addr>`. But when working on codebases that mostly
deal with `IpAddr`, this is an inconvenient API because we have to
match on every address, and are forced to write the same code twice.

The new impl makes working with `IpAddr` much more convenient, with
the downside that the requests are validated at runtime instead of
compile time.
For both the `RouteAddRequest` and `RouteDelRequest`, we need to build
a route message. However only the former provides helper methods to do
so.

Instead of duplicating code, create a separate builder, and use it for
both request types.
@little-dude
Copy link
Contributor Author

Hello @cathay4t, would it be possible to get this merged within the next couple weeks by any chance?

@cathay4t
Copy link
Member

Please give me 2 days to review it.

@cathay4t cathay4t merged commit 24bf04f into rust-netlink:main May 30, 2024
3 checks passed
@cathay4t
Copy link
Member

LGTM. Merged. Thanks for the efforts!

@little-dude little-dude deleted the route-msg-builder branch June 2, 2024 11:30
@little-dude
Copy link
Contributor Author

Thanks @cathay4t !

@little-dude
Copy link
Contributor Author

@cathay4t would it be possible to make a release with these changes? I haven't done a release in a while, and with all the inter-dependencies between the crates I'm a bit scared of making one.

@little-dude
Copy link
Contributor Author

@cathay4t would you be able to make a release? If not I'll give it a try.

@cathay4t
Copy link
Member

cathay4t commented Jun 24, 2024

Can we use this builder to other component(addr, link, rule, rc)also before release?

And I am also considering to RouteGetRequest::new(handle: Handler, rt_msg: RouteMessage) also, to be consistent.

@cathay4t
Copy link
Member

I will create a PR tomorrow for expanding building to crate wide. After that, I can make a release.

Meanwhile, please also vote on #66

@little-dude
Copy link
Contributor Author

After that, I can make a release.

I just realized I'd also need a netlink-packet-route release to get rust-netlink/netlink-packet-route#98 if you don't mind

@cathay4t
Copy link
Member

netlink-packet-route 0.20.1 released.

Working on expanding the use of builder.

@little-dude
Copy link
Contributor Author

Thanks a ton @cathay4t !

@cathay4t
Copy link
Member

cathay4t commented Jul 5, 2024

I am currently work on creating builder for link:

https://github.com/cathay4t/rtnetlink/tree/link_builder

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