Skip to content

Commit f0e2871

Browse files
committed
uefi: remove type duplication + update documentation
1 parent cbc9664 commit f0e2871

File tree

3 files changed

+14
-95
lines changed

3 files changed

+14
-95
lines changed

uefi/src/proto/device_path/device_path_gen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ use crate::polyfill::maybe_uninit_slice_as_mut_ptr;
1414
use crate::proto::device_path::{
1515
self, DevicePathHeader, DevicePathNode, DeviceSubType, DeviceType, NodeConversionError,
1616
};
17-
use crate::proto::network::IpAddress;
1817
use crate::{Guid, guid};
1918
use bitflags::bitflags;
2019
use core::ptr::addr_of;
2120
use core::{fmt, slice};
2221
use ptr_meta::Pointee;
22+
use uefi_raw::IpAddress;
2323
/// Device path nodes for [`DeviceType::END`].
2424
pub mod end {
2525
use super::*;

uefi/src/proto/network/mod.rs

Lines changed: 12 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -3,101 +3,20 @@
33
//! Network access protocols.
44
//!
55
//! These protocols can be used to interact with network resources.
6+
//!
7+
//! All high-level wrappers will accept [`core::net`] types:
8+
//! - [`IpAddr`]
9+
//! - [`Ipv4Addr`]
10+
//! - [`Ipv6Addr`]
11+
//!
12+
//! The only exception is [`uefi_raw::MacAddress`] which doesn't have a
13+
//! corresponding type in the standard library.
14+
//!
15+
//! [`IpAddr`]: core::net::IpAddr
16+
//! [`Ipv4Addr`]: core::net::Ipv4Addr
17+
//! [`Ipv6Addr`]: core::net::Ipv6Addr
618
719
pub mod http;
820
pub mod ip4config2;
921
pub mod pxe;
1022
pub mod snp;
11-
12-
pub use uefi_raw::MacAddress;
13-
14-
/// Represents an IPv4/v6 address.
15-
///
16-
/// Corresponds to the `EFI_IP_ADDRESS` type in the C API.
17-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
18-
#[repr(C, align(4))]
19-
pub struct IpAddress(pub [u8; 16]);
20-
21-
impl IpAddress {
22-
/// Construct a new IPv4 address.
23-
#[must_use]
24-
pub const fn new_v4(ip_addr: [u8; 4]) -> Self {
25-
let mut buffer = [0; 16];
26-
buffer[0] = ip_addr[0];
27-
buffer[1] = ip_addr[1];
28-
buffer[2] = ip_addr[2];
29-
buffer[3] = ip_addr[3];
30-
Self(buffer)
31-
}
32-
33-
/// Construct a new IPv6 address.
34-
#[must_use]
35-
pub const fn new_v6(ip_addr: [u8; 16]) -> Self {
36-
Self(ip_addr)
37-
}
38-
39-
/// Construct from a `uefi_raw::IpAddress` union.
40-
///
41-
/// # Safety
42-
///
43-
/// `is_ipv6` must accurately reflect how the union was initialized.
44-
#[must_use]
45-
const unsafe fn from_raw(ip_addr: uefi_raw::IpAddress, is_ipv6: bool) -> Self {
46-
if is_ipv6 {
47-
Self::new_v6(unsafe { ip_addr.v6.0 })
48-
} else {
49-
Self::new_v4(unsafe { ip_addr.v4.0 })
50-
}
51-
}
52-
53-
#[must_use]
54-
const fn as_raw_ptr(&self) -> *const uefi_raw::IpAddress {
55-
// The uefi-raw type is defined differently, but the layout is
56-
// compatible.
57-
self.0.as_ptr().cast()
58-
}
59-
60-
#[must_use]
61-
const fn as_raw_ptr_mut(&mut self) -> *mut uefi_raw::IpAddress {
62-
// The uefi-raw type is defined differently, but the layout is
63-
// compatible.
64-
self.0.as_mut_ptr().cast()
65-
}
66-
}
67-
68-
impl From<core::net::Ipv4Addr> for IpAddress {
69-
fn from(t: core::net::Ipv4Addr) -> Self {
70-
Self::new_v4(t.octets())
71-
}
72-
}
73-
74-
impl From<IpAddress> for core::net::Ipv4Addr {
75-
fn from(IpAddress(o): IpAddress) -> Self {
76-
Self::from([o[0], o[1], o[2], o[3]])
77-
}
78-
}
79-
80-
impl From<core::net::Ipv6Addr> for IpAddress {
81-
fn from(t: core::net::Ipv6Addr) -> Self {
82-
Self::new_v6(t.octets())
83-
}
84-
}
85-
86-
impl From<IpAddress> for core::net::Ipv6Addr {
87-
fn from(value: IpAddress) -> Self {
88-
Self::from(value.0)
89-
}
90-
}
91-
92-
impl From<core::net::IpAddr> for IpAddress {
93-
fn from(t: core::net::IpAddr) -> Self {
94-
match t {
95-
core::net::IpAddr::V4(a) => a.into(),
96-
core::net::IpAddr::V6(a) => a.into(),
97-
}
98-
}
99-
}
100-
101-
// NOTE: We cannot impl From<IpAddress> for core::net::IpAddr
102-
// because IpAddress is a raw union, with nothing indicating
103-
// whether it should be considered v4 or v6.

xtask/src/device_path/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ fn gen_uefi_code_as_string(groups: &[NodeGroup]) -> Result<String> {
7979
self, DevicePathHeader, DevicePathNode, DeviceSubType, DeviceType,
8080
NodeConversionError,
8181
};
82-
use crate::proto::network::IpAddress;
8382
use crate::mem::memory_map::MemoryType;
8483
use core::ptr::addr_of;
8584
use core::{fmt, slice};
8685
use ptr_meta::Pointee;
86+
use uefi_raw::IpAddress;
8787

8888
#(#packed_modules)*
8989

0 commit comments

Comments
 (0)