Skip to content

Commit a49989e

Browse files
authored
Merge pull request #2 from rust-osdev/net-hdr_gso-enum
fix(net): make HdrGso an enum instead of a flag
2 parents d167e03 + bfd0526 commit a49989e

File tree

3 files changed

+58
-18
lines changed

3 files changed

+58
-18
lines changed

src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,15 @@ virtio_bitflags! {
163163
}
164164

165165
/// Virtio Device IDs
166+
///
167+
/// <div class="warning">
168+
///
169+
/// This enum is not ABI-compatible with it's corresponding field.
170+
/// Use [`Id::from`] for converting from an integer.
171+
///
172+
/// </div>
173+
///
174+
/// [`Id::from`]: Id#impl-From<u8>-for-Id
166175
#[derive(IntoPrimitive, FromPrimitive, PartialEq, Eq, Clone, Copy, Debug)]
167176
#[non_exhaustive]
168177
#[repr(u8)]

src/net.rs

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,41 @@ virtio_bitflags! {
7777
}
7878
}
7979

80-
virtio_bitflags! {
81-
/// Network Device Header GSO Type
82-
#[doc(alias = "VIRTIO_NET_HDR_GSO")]
83-
pub struct HdrGso: u8 {
84-
#[doc(alias = "VIRTIO_NET_HDR_GSO_NONE")]
85-
const NONE = 0;
80+
/// Network Device Header GSO Type
81+
///
82+
/// <div class="warning">
83+
///
84+
/// This enum is not ABI-compatible with it's corresponding field.
85+
/// Use [`HdrGso::from`] for converting from an integer.
86+
///
87+
/// </div>
88+
///
89+
/// [`HdrGso::from`]: HdrGso#impl-From<u8>-for-HdrGso
90+
#[doc(alias = "VIRTIO_NET_HDR_GSO")]
91+
#[derive(IntoPrimitive, FromPrimitive, PartialEq, Eq, Clone, Copy, Debug)]
92+
#[non_exhaustive]
93+
#[repr(u8)]
94+
pub enum HdrGso {
95+
#[doc(alias = "VIRTIO_NET_HDR_GSO_NONE")]
96+
None = 0,
8697

87-
#[doc(alias = "VIRTIO_NET_HDR_GSO_TCPV4")]
88-
const TCPV4 = 1;
98+
#[doc(alias = "VIRTIO_NET_HDR_GSO_TCPV4")]
99+
Tcpv4 = 1,
89100

90-
#[doc(alias = "VIRTIO_NET_HDR_GSO_UDP")]
91-
const UDP = 3;
101+
#[doc(alias = "VIRTIO_NET_HDR_GSO_UDP")]
102+
Udp = 3,
92103

93-
#[doc(alias = "VIRTIO_NET_HDR_GSO_TCPV6")]
94-
const TCPV6 = 4;
104+
#[doc(alias = "VIRTIO_NET_HDR_GSO_TCPV6")]
105+
Tcpv6 = 4,
95106

96-
#[doc(alias = "VIRTIO_NET_HDR_GSO_UDP_L4")]
97-
const UDP_L4 = 5;
107+
#[doc(alias = "VIRTIO_NET_HDR_GSO_UDP_L4")]
108+
UdpL4 = 5,
98109

99-
#[doc(alias = "VIRTIO_NET_HDR_GSO_ECN")]
100-
const ECN = 0x80;
101-
}
110+
#[doc(alias = "VIRTIO_NET_HDR_GSO_ECN")]
111+
Ecn = 0x80,
112+
113+
#[num_enum(catch_all)]
114+
Unknown(u8),
102115
}
103116

104117
/// Network Device Header
@@ -116,7 +129,7 @@ virtio_bitflags! {
116129
#[repr(C)]
117130
pub struct Hdr {
118131
pub flags: HdrF,
119-
pub gso_type: HdrGso,
132+
pub gso_type: u8,
120133
pub hdr_len: le16,
121134
pub gso_size: le16,
122135
pub csum_start: le16,
@@ -182,6 +195,15 @@ endian_bitflags! {
182195
}
183196

184197
/// Hash Report
198+
///
199+
/// <div class="warning">
200+
///
201+
/// This enum is not ABI-compatible with it's corresponding field.
202+
/// Use [`HashReport::from`] for converting from an integer.
203+
///
204+
/// </div>
205+
///
206+
/// [`HashReport::from`]: HashReport#impl-From<u16>-for-HashReport
185207
#[doc(alias = "VIRTIO_NET_HASH_REPORT")]
186208
#[derive(IntoPrimitive, FromPrimitive, PartialEq, Eq, Clone, Copy, Debug)]
187209
#[non_exhaustive]

src/pci.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,15 @@ impl CapData {
270270
}
271271

272272
/// PCI Capability Configuration Type
273+
///
274+
/// <div class="warning">
275+
///
276+
/// This enum is not ABI-compatible with it's corresponding field.
277+
/// Use [`CapCfgType::from`] for converting from an integer.
278+
///
279+
/// </div>
280+
///
281+
/// [`CapCfgType::from`]: CapCfgType#impl-From<u8>-for-CapCfgType
273282
#[doc(alias = "VIRTIO_PCI_CAP")]
274283
#[derive(IntoPrimitive, FromPrimitive, PartialEq, Eq, Clone, Copy, Debug)]
275284
#[non_exhaustive]

0 commit comments

Comments
 (0)