Skip to content

bond: align FromStr/Display strings with iproute2#264

Merged
cathay4t merged 2 commits into
rust-netlink:mainfrom
cathay4t:main
Jun 1, 2026
Merged

bond: align FromStr/Display strings with iproute2#264
cathay4t merged 2 commits into
rust-netlink:mainfrom
cathay4t:main

Conversation

@cathay4t

@cathay4t cathay4t commented Jun 1, 2026

Copy link
Copy Markdown
Member
  • Change BondXmitHashPolicy Display/FromStr strings to match iproute2:
    "layer34"->"layer3+4", "layer23"->"layer2+3", "encap23"->"encap2+3",
    "encap34"->"encap3+4", "vlan-src-mac"->"vlan+srcmac"
  • Add BOND_AD_ACTOR_PORT_PRIO constant and ActorPortPrio variant to
    BondAdSelect with Display/FromStr support

Unit tests for both BondXmitHashPolicy and BondAdSelect FromStr are
updated.

- Change BondXmitHashPolicy Display/FromStr strings to match iproute2:
  "layer34"->"layer3+4", "layer23"->"layer2+3", "encap23"->"encap2+3",
  "encap34"->"encap3+4", "vlan-src-mac"->"vlan+srcmac"
- Add BOND_AD_ACTOR_PORT_PRIO constant and ActorPortPrio variant to
  BondAdSelect with Display/FromStr support

Unit tests for both BondXmitHashPolicy and BondAdSelect FromStr are
updated.

Signed-off-by: Gris Ge <cnfourt@gmail.com>
@codecov

codecov Bot commented Jun 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.14%. Comparing base (1fb4bd7) to head (099ba90).
⚠️ Report is 48 commits behind head on main.

Files with missing lines Patch % Lines
src/link/link_info/bond.rs 50.00% 14 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #264      +/-   ##
==========================================
+ Coverage   68.10%   68.14%   +0.03%     
==========================================
  Files         144      146       +2     
  Lines       10103    10420     +317     
==========================================
+ Hits         6881     7101     +220     
- Misses       3222     3319      +97     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Copy link
Copy Markdown

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 updates the string representations of several BondXmitHashPolicy variants (e.g., changing "layer34" to "layer3+4") and adds support for the ActorPortPrio variant in the BondAdSelect enum. The review feedback recommends maintaining backward compatibility in FromStr parsing for the old BondXmitHashPolicy string formats to prevent breaking existing configurations, and suggests adding corresponding test assertions to verify this compatibility.

Comment on lines +458 to +462
"layer3+4" => Self::Layer34,
"layer2+3" => Self::Layer23,
"encap2+3" => Self::Encap23,
"encap3+4" => Self::Encap34,
"vlan+srcmac" => Self::VlanSrcMac,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

To prevent breaking backward compatibility for existing configurations or scripts that use the old string representations, it is highly recommended to continue supporting the old strings (layer34, layer23, encap23, encap34, and vlan-src-mac) in FromStr parsing, while using the new format for Display. Additionally, to adhere to the project's line length limits, use a block expression for the longer match arm.

            "layer3+4" | "layer34" => Self::Layer34,
            "layer2+3" | "layer23" => Self::Layer23,
            "encap2+3" | "encap23" => Self::Encap23,
            "encap3+4" | "encap34" => Self::Encap34,
            "vlan+srcmac" | "vlan-src-mac" => {
                Self::VlanSrcMac
            }
References
  1. Code formatting must adhere to the project's rustfmt configuration, especially the maximum line length. This may require using block expressions for what would otherwise be single-line match arms to stay within the configured limit. (link)
  2. When converting from a string slice (&str) to a type where the conversion can fail, implement std::str::FromStr instead of From<&str>.

Comment thread src/link/tests/bond.rs
Comment on lines +279 to 286
assert_eq!(BondXmitHashPolicy::Layer34, "layer3+4".parse().unwrap());
assert_eq!(BondXmitHashPolicy::Layer23, "layer2+3".parse().unwrap());
assert_eq!(BondXmitHashPolicy::Encap23, "encap2+3".parse().unwrap());
assert_eq!(BondXmitHashPolicy::Encap34, "encap3+4".parse().unwrap());
assert_eq!(
BondXmitHashPolicy::VlanSrcMac,
"vlan-src-mac".parse().unwrap()
"vlan+srcmac".parse().unwrap()
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Add assertions to verify that the old string representations are still parsed correctly for backward compatibility.

Suggested change
assert_eq!(BondXmitHashPolicy::Layer34, "layer3+4".parse().unwrap());
assert_eq!(BondXmitHashPolicy::Layer23, "layer2+3".parse().unwrap());
assert_eq!(BondXmitHashPolicy::Encap23, "encap2+3".parse().unwrap());
assert_eq!(BondXmitHashPolicy::Encap34, "encap3+4".parse().unwrap());
assert_eq!(
BondXmitHashPolicy::VlanSrcMac,
"vlan-src-mac".parse().unwrap()
"vlan+srcmac".parse().unwrap()
);
assert_eq!(BondXmitHashPolicy::Layer34, "layer3+4".parse().unwrap());
assert_eq!(BondXmitHashPolicy::Layer34, "layer34".parse().unwrap());
assert_eq!(BondXmitHashPolicy::Layer23, "layer2+3".parse().unwrap());
assert_eq!(BondXmitHashPolicy::Layer23, "layer23".parse().unwrap());
assert_eq!(BondXmitHashPolicy::Encap23, "encap2+3".parse().unwrap());
assert_eq!(BondXmitHashPolicy::Encap23, "encap23".parse().unwrap());
assert_eq!(BondXmitHashPolicy::Encap34, "encap3+4".parse().unwrap());
assert_eq!(BondXmitHashPolicy::Encap34, "encap34".parse().unwrap());
assert_eq!(
BondXmitHashPolicy::VlanSrcMac,
"vlan+srcmac".parse().unwrap()
);
assert_eq!(
BondXmitHashPolicy::VlanSrcMac,
"vlan-src-mac".parse().unwrap()
);

Add FromStr and Display trait implementations for BondLacpRate using
"slow"/"fast" strings.

Unit test included.

Signed-off-by: Gris Ge <cnfourt@gmail.com>
@cathay4t cathay4t merged commit afd072d into rust-netlink:main Jun 1, 2026
10 of 11 checks passed
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