Skip to content

Commit 3072149

Browse files
nicholasbishopphip1611
authored andcommitted
uefi: Make pxe::Mode an opaque struct
Methods are now provided to access mode data instead of direct field access. In a later PR, this will help with switching the public API to use `core::net::IpAddr`.
1 parent b6bdfaa commit 3072149

File tree

4 files changed

+209
-45
lines changed

4 files changed

+209
-45
lines changed

Diff for: uefi-test-runner/src/proto/network/pxe.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ pub fn test() {
2424
.dhcp(false)
2525
.expect("failed to complete a dhcpv4 handshake");
2626

27-
assert!(base_code.mode().dhcp_ack_received);
28-
let dhcp_ack: &DhcpV4Packet = base_code.mode().dhcp_ack.as_ref();
27+
assert!(base_code.mode().dhcp_ack_received());
28+
let dhcp_ack: &DhcpV4Packet = base_code.mode().dhcp_ack().as_ref();
2929
let server_ip = dhcp_ack.bootp_si_addr;
3030
let server_ip = IpAddress::new_v4(server_ip);
3131

@@ -75,7 +75,7 @@ pub fn test() {
7575

7676
let mut src_ip = server_ip;
7777
let mut src_port = EXAMPLE_SERVICE_PORT;
78-
let mut dest_ip = base_code.mode().station_ip;
78+
let mut dest_ip = base_code.mode().station_ip();
7979
let mut dest_port = write_src_port;
8080
let mut header = [0; 1];
8181
let mut received = [0; 4];

Diff for: uefi/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
- **Breaking:** The `pxe::BaseCode::tftp_read_dir` and
1313
`pxe::BaseCode::mtftp_read_dir` methods now take `&mut self` instead of
1414
`&self`.
15+
- **Breaking:** The `pxe::Mode` struct is now opaque. Use method calls to access
16+
mode data instead of direct field access.
1517
- `boot::memory_map()` will never return `Status::BUFFER_TOO_SMALL` from now on,
1618
as this is considered a hard internal error where users can't do anything
1719
about it anyway. It will panic instead.

Diff for: uefi/src/proto/network/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ impl IpAddress {
3434
Self(ip_addr)
3535
}
3636

37+
/// Construct from a `uefi_raw::IpAddress` union.
38+
///
39+
/// # Safety
40+
///
41+
/// `is_ipv6` must accurately reflect how the union was initialized.
42+
#[must_use]
43+
const unsafe fn from_raw(ip_addr: uefi_raw::IpAddress, is_ipv6: bool) -> Self {
44+
if is_ipv6 {
45+
Self::new_v6(unsafe { ip_addr.v6.0 })
46+
} else {
47+
Self::new_v4(unsafe { ip_addr.v4.0 })
48+
}
49+
}
50+
3751
#[must_use]
3852
const fn as_raw_ptr(&self) -> *const uefi_raw::IpAddress {
3953
// The uefi-raw type is defined differently, but the layout is

0 commit comments

Comments
 (0)