From 37a46c9647ca9d0a51b0d27ed8d93ddd26e45e9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Mon, 23 Jun 2025 17:56:30 +0200 Subject: [PATCH 1/2] fix(net): make HdrGso an enum instead of a flag --- src/net.rs | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/net.rs b/src/net.rs index b5c7f63..2f5b31d 100644 --- a/src/net.rs +++ b/src/net.rs @@ -77,28 +77,32 @@ virtio_bitflags! { } } -virtio_bitflags! { - /// Network Device Header GSO Type - #[doc(alias = "VIRTIO_NET_HDR_GSO")] - pub struct HdrGso: u8 { - #[doc(alias = "VIRTIO_NET_HDR_GSO_NONE")] - const NONE = 0; +/// Network Device Header GSO Type +#[doc(alias = "VIRTIO_NET_HDR_GSO")] +#[derive(IntoPrimitive, FromPrimitive, PartialEq, Eq, Clone, Copy, Debug)] +#[non_exhaustive] +#[repr(u8)] +pub enum HdrGso { + #[doc(alias = "VIRTIO_NET_HDR_GSO_NONE")] + None = 0, - #[doc(alias = "VIRTIO_NET_HDR_GSO_TCPV4")] - const TCPV4 = 1; + #[doc(alias = "VIRTIO_NET_HDR_GSO_TCPV4")] + Tcpv4 = 1, - #[doc(alias = "VIRTIO_NET_HDR_GSO_UDP")] - const UDP = 3; + #[doc(alias = "VIRTIO_NET_HDR_GSO_UDP")] + Udp = 3, - #[doc(alias = "VIRTIO_NET_HDR_GSO_TCPV6")] - const TCPV6 = 4; + #[doc(alias = "VIRTIO_NET_HDR_GSO_TCPV6")] + Tcpv6 = 4, - #[doc(alias = "VIRTIO_NET_HDR_GSO_UDP_L4")] - const UDP_L4 = 5; + #[doc(alias = "VIRTIO_NET_HDR_GSO_UDP_L4")] + UdpL4 = 5, - #[doc(alias = "VIRTIO_NET_HDR_GSO_ECN")] - const ECN = 0x80; - } + #[doc(alias = "VIRTIO_NET_HDR_GSO_ECN")] + Ecn = 0x80, + + #[num_enum(catch_all)] + Unknown(u8), } /// Network Device Header @@ -116,7 +120,7 @@ virtio_bitflags! { #[repr(C)] pub struct Hdr { pub flags: HdrF, - pub gso_type: HdrGso, + pub gso_type: u8, pub hdr_len: le16, pub gso_size: le16, pub csum_start: le16, From bfd05263dd715304e4f7e178c3ff282a3e1c5b7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Tue, 24 Jun 2025 15:50:13 +0200 Subject: [PATCH 2/2] docs: add warnings to ABI-incompatible enums --- src/lib.rs | 9 +++++++++ src/net.rs | 18 ++++++++++++++++++ src/pci.rs | 9 +++++++++ 3 files changed, 36 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 3d7e335..6381523 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -163,6 +163,15 @@ virtio_bitflags! { } /// Virtio Device IDs +/// +///
+/// +/// This enum is not ABI-compatible with it's corresponding field. +/// Use [`Id::from`] for converting from an integer. +/// +///
+/// +/// [`Id::from`]: Id#impl-From-for-Id #[derive(IntoPrimitive, FromPrimitive, PartialEq, Eq, Clone, Copy, Debug)] #[non_exhaustive] #[repr(u8)] diff --git a/src/net.rs b/src/net.rs index 2f5b31d..d3d7c84 100644 --- a/src/net.rs +++ b/src/net.rs @@ -78,6 +78,15 @@ virtio_bitflags! { } /// Network Device Header GSO Type +/// +///
+/// +/// This enum is not ABI-compatible with it's corresponding field. +/// Use [`HdrGso::from`] for converting from an integer. +/// +///
+/// +/// [`HdrGso::from`]: HdrGso#impl-From-for-HdrGso #[doc(alias = "VIRTIO_NET_HDR_GSO")] #[derive(IntoPrimitive, FromPrimitive, PartialEq, Eq, Clone, Copy, Debug)] #[non_exhaustive] @@ -186,6 +195,15 @@ endian_bitflags! { } /// Hash Report +/// +///
+/// +/// This enum is not ABI-compatible with it's corresponding field. +/// Use [`HashReport::from`] for converting from an integer. +/// +///
+/// +/// [`HashReport::from`]: HashReport#impl-From-for-HashReport #[doc(alias = "VIRTIO_NET_HASH_REPORT")] #[derive(IntoPrimitive, FromPrimitive, PartialEq, Eq, Clone, Copy, Debug)] #[non_exhaustive] diff --git a/src/pci.rs b/src/pci.rs index eda4610..e48073a 100644 --- a/src/pci.rs +++ b/src/pci.rs @@ -270,6 +270,15 @@ impl CapData { } /// PCI Capability Configuration Type +/// +///
+/// +/// This enum is not ABI-compatible with it's corresponding field. +/// Use [`CapCfgType::from`] for converting from an integer. +/// +///
+/// +/// [`CapCfgType::from`]: CapCfgType#impl-From-for-CapCfgType #[doc(alias = "VIRTIO_PCI_CAP")] #[derive(IntoPrimitive, FromPrimitive, PartialEq, Eq, Clone, Copy, Debug)] #[non_exhaustive]