From 30a511fe12dbd93110746841cd88f1f02b9f8dbd Mon Sep 17 00:00:00 2001 From: Till Maas Date: Tue, 15 Apr 2025 13:01:07 +0200 Subject: [PATCH 1/2] DO NOT MERGE: Demonstrate lacking test coverage To demonstrate that the current test strategy is lacking test coverage, break the MinMtu data type without breaking the existing test cases. --- src/link/attribute.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/link/attribute.rs b/src/link/attribute.rs index e546669c..2b2f0f47 100644 --- a/src/link/attribute.rs +++ b/src/link/attribute.rs @@ -158,7 +158,7 @@ pub enum LinkAttribute { GsoMaxSegs(u32), GsoMaxSize(u32), /// The minimum MTU for the device. - MinMtu(u32), + MinMtu(i32), /// The maximum MTU for the device. MaxMtu(u32), LinkNetNsId(i32), @@ -284,8 +284,11 @@ impl Nla for LinkAttribute { | Self::CarrierDownCount(value) | Self::GsoMaxSegs(value) | Self::GsoMaxSize(value) - | Self::MinMtu(value) - | Self::MaxMtu(value) => NativeEndian::write_u32(buffer, *value), + => NativeEndian::write_u32(buffer, *value), + + Self::MinMtu(value) => NativeEndian::write_i32(buffer, *value), + + Self::MaxMtu(value) => NativeEndian::write_u32(buffer, *value), Self::ExtMask(value) => NativeEndian::write_u32( buffer, @@ -598,7 +601,7 @@ impl<'a, T: AsRef<[u8]> + ?Sized> .context("invalid IFLA_GSO_MAX_SIZE value")?, ), IFLA_MIN_MTU => Self::MinMtu( - parse_u32(payload).context("invalid IFLA_MIN_MTU value")?, + parse_i32(payload).context("invalid IFLA_MIN_MTU value")?, ), IFLA_MAX_MTU => Self::MaxMtu( parse_u32(payload).context("invalid IFLA_MAX_MTU value")?, From bb938b624583a211f275ba48139715d9171f2e04 Mon Sep 17 00:00:00 2001 From: Till Maas Date: Tue, 15 Apr 2025 13:12:16 +0200 Subject: [PATCH 2/2] Example doc tests for MinMtu I was not able to execute them from the tests/ directory. They are executed with `cargo test --doc`. --- src/link/attribute.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/link/attribute.rs b/src/link/attribute.rs index 2b2f0f47..a43628d4 100644 --- a/src/link/attribute.rs +++ b/src/link/attribute.rs @@ -158,6 +158,21 @@ pub enum LinkAttribute { GsoMaxSegs(u32), GsoMaxSize(u32), /// The minimum MTU for the device. + ///``` + /// # use netlink_packet_route::link::LinkAttribute; + /// let _link_attribute: LinkAttribute = LinkAttribute::MinMtu(0); + /// let _link_attribute: LinkAttribute = LinkAttribute::MinMtu(0xffff_ffff); + ///``` + /// ```compile_fail + /// # use netlink_packet_route::link::LinkAttribute; + /// # fn test_min_mtu() {} + /// let _link_attribute: LinkAttribute = LinkAttribute::MinMtu(-1); + /// ``` + /// ```compile_fail + /// # use netlink_packet_route::link::LinkAttribute; + /// # fn test_min_mtu() {} + /// let _link_attribute: LinkAttribute = LinkAttribute::MinMtu(0x1_0000_0000); + /// ``` MinMtu(i32), /// The maximum MTU for the device. MaxMtu(u32),