Skip to content

Add vxcan#152

Draft
romainreignier wants to merge 2 commits intorust-netlink:mainfrom
romainreignier:add_vxcan
Draft

Add vxcan#152
romainreignier wants to merge 2 commits intorust-netlink:mainfrom
romainreignier:add_vxcan

Conversation

@romainreignier
Copy link

Add vxcan based on veth implementation.

Needs a release of netlink-packet-route 0.29.0 after rust-netlink/netlink-packet-route#234 is merged.

So I did a separate commit to update the netlink-packet-route API to current main branch.

@gemini-code-assist
Copy link

Summary of Changes

Hello @romainreignier, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces the capability to create and manage virtual CAN interfaces, expanding the library's network interface management features. It includes the necessary data structures and builder patterns for vxcan links, along with an example to guide usage. Additionally, it updates a core dependency to leverage the latest upstream changes and incorporates minor API corrections for improved robustness and type safety.

Highlights

  • New Feature: VxCAN Interface Support: Added comprehensive support for creating and managing virtual CAN (Controller Area Network) interfaces, including a new LinkVxcan structure and builder methods.
  • Dependency Update: Updated the netlink-packet-route dependency to version 0.29, aligning with recent API changes in the upstream library.
  • Example for VxCAN: Included a new example (examples/create_vxcan.rs) demonstrating how to programmatically create a vxcan interface pair and bring them up.
  • API Refinements: Improved type safety for the ad_select attribute in bond interfaces by using BondAdSelect instead of u8, and corrected a typo in the neigh_vlan_suppress function for bridge ports.
Changelog
  • Cargo.toml
    • Updated netlink-packet-route dependency from version 0.28 to 0.29.
  • examples/create_vxcan.rs
    • Added a new example file to demonstrate the creation and configuration of vxcan interfaces.
  • src/lib.rs
    • Exported the new LinkVxcan structure from the link module.
  • src/link/bond.rs
    • Imported BondAdSelect and updated the ad_select method to use BondAdSelect instead of u8 for type safety.
  • src/link/bridge_port.rs
    • Corrected a typo in the neigh_vlan_suppress function, changing NeighVlanSupress to NeighVlanSuppress.
  • src/link/mod.rs
    • Added the vxcan module and re-exported LinkVxcan.
  • src/link/vxcan.rs
    • Added a new module implementing the LinkVxcan structure and its associated LinkMessageBuilder for virtual CAN interfaces.
Activity
  • The implementation of vxcan is based on the existing veth implementation.
  • This PR requires a release of netlink-packet-route 0.29.0 after rust-netlink/netlink-packet-route/pull/234 is merged.
  • A separate commit was made to update the netlink-packet-route API to align with the current main branch.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for vxcan interfaces, modeled after the existing veth implementation. The changes include updating the netlink-packet-route dependency, which brings in some related API improvements, and adding the LinkVxcan type with a corresponding example. The implementation is solid. I have one suggestion for the example code to improve its efficiency and fix a small typo.

Comment on lines 32 to 44
async fn set_link_up(handle: &Handle, name: String) -> Result<(), Error> {
let mut links = handle.link().get().match_name(name.clone()).execute();
if let Some(link) = links.try_next().await? {
handle
.link()
.set(LinkUnspec::new_with_index(link.header.index).up().build())
.execute()
.await?
} else {
println!("no link link {name} found");
}
Ok(())
}

Choose a reason for hiding this comment

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

medium

The set_link_up function takes name by value (String), which forces callers to clone the string. It then clones the string again internally. It would be more efficient to take a string slice (&str) to avoid these clones. This would require updating the call sites on lines 21 and 25 to pass references (e.g., set_link_up(&handle, &link_name)). Also, there is a typo in the println! message.

Suggested change
async fn set_link_up(handle: &Handle, name: String) -> Result<(), Error> {
let mut links = handle.link().get().match_name(name.clone()).execute();
if let Some(link) = links.try_next().await? {
handle
.link()
.set(LinkUnspec::new_with_index(link.header.index).up().build())
.execute()
.await?
} else {
println!("no link link {name} found");
}
Ok(())
}
async fn set_link_up(handle: &Handle, name: &str) -> Result<(), Error> {
let mut links = handle.link().get().match_name(name.to_string()).execute();
if let Some(link) = links.try_next().await? {
handle
.link()
.set(LinkUnspec::new_with_index(link.header.index).up().build())
.execute()
.await?
} else {
println!("no link {name} found");
}
Ok(())
}

Signed-off-by: Romain Reignier <romain.reignier@exail.com>
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.

1 participant