Skip to content

Comments

Reorganize the code for detail show#10

Merged
cathay4t merged 1 commit intorust-netlink:mainfrom
cathay4t:main
Feb 19, 2026
Merged

Reorganize the code for detail show#10
cathay4t merged 1 commit intorust-netlink:mainfrom
cathay4t:main

Conversation

@cathay4t
Copy link
Member

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @cathay4t, 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 focuses on enhancing the internal structure and maintainability of the network interface detail display functionality. By extracting interface-specific logic into new, dedicated modules, the changes improve code organization and prepare the codebase for easier expansion and maintenance of different network interface types. The core detail handling has been streamlined to leverage these new modular components.

Highlights

  • Code Reorganization: The logic for displaying network interface details has been significantly refactored, moving specific interface type details (like bridge and VLAN) into dedicated submodules for better modularity.
  • New Interface Detail Modules: New modules src/ip/link/ifaces/bridge.rs and src/ip/link/ifaces/vlan.rs were introduced to encapsulate the data structures and display logic for bridge and VLAN interface information, respectively.
  • Dependency Patching: The Cargo.toml file was updated to use patched versions of the rtnetlink and netlink-packet-route crates directly from their git repositories, likely to incorporate unreleased features or fixes.
  • Renamed Core Detail File: The file src/ip/link/link_details.rs was renamed to src/ip/link/detail.rs to reflect its updated role as a more generic detail handler.
Changelog
  • .gitignore
    • Added 'tags' to the ignore list.
  • .rustfmt.toml
    • Added new formatting rules for import grouping and granularity.
  • Cargo.toml
    • Removed explicit 'branch = "use_git"' from rtnetlink dependency.
    • Added patch entries for 'rtnetlink' and 'netlink-packet-route' to use their git repositories directly.
  • src/ip/link/ifaces/bridge.rs
    • Added new file defining CliLinkInfoDataBridge and CliLinkInfoDataBridgePort structs.
    • Implemented From and Display traits for bridge-specific link and port data.
    • Included constants for additional bridge NLA attributes.
  • src/ip/link/ifaces/mod.rs
    • Added new file to declare bridge and vlan as submodules.
  • src/ip/link/ifaces/vlan.rs
    • Added new file defining CliLinkInfoDataVlan struct.
    • Implemented From and Display traits for VLAN-specific link data.
  • src/ip/link/link_details.rs
    • Renamed to src/ip/link/detail.rs.
    • Removed CliLinkInfoCombined struct and its display implementation.
    • Refactored CliLinkInfoDetails to CliLinkInfoDetail, updating its internal structure to use the new CliLinkInfo and CliLinkInfoData enums.
    • Modified the new method to delegate parsing of link information to the new try_from implementations.
  • src/ip/link/link_info.rs
    • Removed redundant bridge ID formatting and VLAN flag constants.
    • Refactored CliLinkInfoData enum to delegate to new CliLinkInfoDataVlan and CliLinkInfoDataBridge types.
    • Introduced CliLinkInfo struct to combine link kind, data, port kind, and port data.
    • Implemented TryFrom and Display traits for CliLinkInfo, CliLinkInfoData, and CliLinkInfoPortData to handle conversions and formatting.
    • Removed CliLinkInfoKindNData struct and its related methods.
  • src/ip/link/mod.rs
    • Updated module declarations to include detail and ifaces, and removed link_details.
  • src/ip/link/show.rs
    • Updated imports to reflect the renaming of link_details to detail.
    • Modified CliLinkInfo struct to use CliLinkInfoDetail for its details field.
    • Adjusted parse_nl_msg_to_iface to instantiate CliLinkInfoDetail.
  • src/lib.rs
    • Refactored pub use self::{...} statement for improved readability.
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.

Signed-off-by: Gris Ge <fge@redhat.com>
@cathay4t cathay4t merged commit ff57b74 into rust-netlink:main Feb 19, 2026
2 of 3 checks passed
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 a significant and well-executed refactoring of the code for displaying link details. By moving interface-specific logic into a new ifaces module, the code is now much cleaner and easier to maintain. I've found a few issues in the new bridge.rs file, mainly related to data representation and formatting, including one that causes incorrect output for bridge IDs compared to iproute2.

Comment on lines +684 to +698
/// Format bridge ID to match iproute2's format:
/// Priority is 4 hex digits, MAC address bytes use minimal formatting (no
/// leading zeros for bytes < 0x10)
fn format_bridge_id(priority: u16, mac_bytes: [u8; 6]) -> String {
format!(
"{:04x}.{:x}:{:x}:{:x}:{:x}:{:x}:{:x}",
priority,
mac_bytes[0],
mac_bytes[1],
mac_bytes[2],
mac_bytes[3],
mac_bytes[4],
mac_bytes[5]
)
}

Choose a reason for hiding this comment

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

high

The format_bridge_id implementation and its documentation do not match the output of iproute2. iproute2 formats the bridge ID as priority.mac_address without colons in the MAC and with zero-padding for each byte (e.g., 8000.001122334455). The current implementation includes colons and does not pad all MAC address bytes, leading to incorrect output.

The documentation is also misleading regarding the formatting.

/// Format bridge ID to match iproute2's format: `8000.001122334455` where
/// `8000` is the priority and `001122334455` is the MAC address.
fn format_bridge_id(priority: u16, mac_bytes: [u8; 6]) -> String {
    format!(
        "{:04x}.{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}",
        priority,
        mac_bytes[0],
        mac_bytes[1],
        mac_bytes[2],
        mac_bytes[3],
        mac_bytes[4],
        mac_bytes[5]
    )
}

vlan_stats_enabled: Option<u8>,
#[serde(skip_serializing_if = "Option::is_none")]
vlan_stats_per_port: Option<u8>,
group_fwd_mask: String,

Choose a reason for hiding this comment

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

medium

The group_fwd_mask field is stored as a String and then parsed back to a number in the Display implementation. This is inefficient. It would be better to store it as a u16 and format it directly when displaying.

This would involve:

  1. Changing the field type to u16.
  2. Updating the from implementation to assign the u16 value directly.
  3. Updating the Display implementation to format the u16 value.
Suggested change
group_fwd_mask: String,
group_fwd_mask: u16,

Comment on lines +456 to +457
group_fwd_mask: String,
group_fwd_mask_str: String,

Choose a reason for hiding this comment

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

medium

The fields group_fwd_mask and group_fwd_mask_str are redundant and lead to confusing output. The Display implementation prints both a decimal and a hex representation with labels that are not user-friendly (group_fwd_mask_str).

To simplify and fix the output, I suggest storing only the raw u16 value and formatting it as hex for display. This will also improve the JSON output by serializing it as a number.

You would need to:

  1. Replace both fields with a single group_fwd_mask: u16.
  2. Update the from implementation to assign the u16 value.
  3. Update the Display implementation to print only one group_fwd_mask formatted as hex (e.g., group_fwd_mask {:#x}).
Suggested change
group_fwd_mask: String,
group_fwd_mask_str: String,
group_fwd_mask: u16,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant