Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit86aa5ce

Browse files
committed
uefi: remove duplicated types, use uefi-raw's IpAddress
This does not use core::net::IpAddr in all possible public interfaces.Although there is opportunity for that, this commit only makes `uefi`compatible with the new `uefi-raw` type.
1 parent5ff3165 commit86aa5ce

File tree

9 files changed

+92
-184
lines changed

9 files changed

+92
-184
lines changed

‎uefi-test-runner/src/proto/network/pxe.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
22

33
use uefi::proto::network::pxe::{BaseCode,DhcpV4Packet,IpFilter,IpFilters,UdpOpFlags};
4-
use uefi::proto::network::IpAddress;
4+
use uefi::proto::network::EfiIpAddr;
55
use uefi::{boot,CStr8};
66

77
pubfntest(){
@@ -27,7 +27,7 @@ pub fn test() {
2727
assert!(base_code.mode().dhcp_ack_received());
2828
let dhcp_ack:&DhcpV4Packet = base_code.mode().dhcp_ack().as_ref();
2929
let server_ip = dhcp_ack.bootp_si_addr;
30-
let server_ip =IpAddress::new_v4(server_ip);
30+
let server_ip =EfiIpAddr::new_v4(server_ip);
3131

3232
constEXAMPLE_FILE_NAME:&[u8] =b"example-file.txt\0";
3333
constEXAMPLE_FILE_CONTENT:&[u8] =b"Hello world!";

‎uefi-test-runner/src/proto/network/snp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
22

33
use uefi::proto::network::snp::{InterruptStatus,ReceiveFlags,SimpleNetwork};
4-
use uefi::proto::network::MacAddress;
4+
use uefi::proto::network::EfiMacAddr;
55
use uefi::{boot,Status};
66

77
pubfntest(){
@@ -75,7 +75,7 @@ pub fn test() {
7575
\xa9\xe4\
7676
\x04\x01\x02\x03\x04";
7777

78-
let dest_addr =MacAddress([0xffu8;32]);
78+
let dest_addr =EfiMacAddr([0xffu8;32]);
7979
assert!(!simple_network
8080
.get_interrupt_status()
8181
.unwrap()

‎uefi/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
defaults to the recommended value of`MemoryType::LOADER_DATA`.
3030
-**Breaking:** Removed duplication in`DevicePathHeader`. Instead of public fields,
3131
there is now a public constructor combined with public getters.
32+
-**Breaking:** Removed type`IpAddress`. Instead, a new alias`EfiIpAddr` is
33+
exported which forwards to the new`IpAddress` type in`uefi-raw`. That type
34+
is tightly integrated with`core::net::{IpAddr, Ipv4Addr, Ipv6Addr}`.
35+
This simplifies working with IP addresses significantly.
36+
-**Breaking:** For consistency,`MacAddress` was renamed to`EfiMacAddr`.
3237
-`boot::memory_map()` will never return`Status::BUFFER_TOO_SMALL` from now on,
3338
as this is considered a hard internal error where users can't do anything
3439
about it anyway. It will panic instead.

‎uefi/src/proto/device_path/device_path_gen.rs

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

‎uefi/src/proto/network/ip4config2.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
use alloc::vec;
88
use alloc::vec::Vec;
99
use core::ffi::c_void;
10-
10+
use core::net::Ipv4Addr;
1111
use uefi::boot::ScopedProtocol;
1212
use uefi::prelude::*;
1313
use uefi::proto::unsafe_protocol;
1414
use uefi::{print, println};
1515
use uefi_raw::protocol::network::ip4_config2::{
1616
Ip4Config2DataType,Ip4Config2InterfaceInfo,Ip4Config2Policy,Ip4Config2Protocol,
1717
};
18-
use uefi_raw::Ipv4Address;
1918

2019
/// IP4 Config2 [`Protocol`]. Configure IPv4 networking.
2120
///
@@ -101,29 +100,19 @@ impl Ip4Config2 {
101100
})
102101
}
103102

104-
fnprint_info(info:&Ip4Config2InterfaceInfo){
105-
println!(
106-
"addr v4: {}.{}.{}.{}",
107-
info.station_addr.0[0],
108-
info.station_addr.0[1],
109-
info.station_addr.0[2],
110-
info.station_addr.0[3],
111-
);
112-
}
113-
114103
/// Bring up network interface. Does nothing in case the network
115104
/// is already set up. Otherwise turns on DHCP and waits until an
116105
/// IPv4 address has been assigned. Reports progress on the
117106
/// console if verbose is set to true. Returns TIMEOUT error in
118107
/// case DHCP configuration does not finish within 30 seconds.
119108
pubfnifup(&mutself,verbose:bool) -> uefi::Result<()>{
120-
let no_address =Ipv4Address::default();
109+
let no_address =Ipv4Addr::from_bits(0);
121110

122111
let info =self.get_interface_info()?;
123112
if info.station_addr != no_address{
124113
if verbose{
125114
print!("Network is already up: ");
126-
Self::print_info(&info);
115+
println!("addr v4: {}",info.station_addr);
127116
}
128117
returnOk(());
129118
}
@@ -142,7 +131,7 @@ impl Ip4Config2 {
142131
if info.station_addr != no_address{
143132
if verbose{
144133
print!(" OK: ");
145-
Self::print_info(&info);
134+
println!("addr v4: {}",info.station_addr);
146135
}
147136
returnOk(());
148137
}

‎uefi/src/proto/network/mod.rs

Lines changed: 6 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -3,101 +3,15 @@
33
//! Network access protocols.
44
//!
55
//! These protocols can be used to interact with network resources.
6+
//!
7+
//! To work with Mac and IP addresses, `uefi` uses with the types:
8+
//! - [`EfiIpAddr`] that is tightly integrated with the [`core::net::IpAddr`]
9+
//! type,
10+
//! - [`EfiMacAddr`]
611
712
pubmod http;
813
pubmod ip4config2;
914
pubmod pxe;
1015
pubmod snp;
1116

12-
pubuse 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-
pubstructIpAddress(pub[u8;16]);
20-
21-
implIpAddress{
22-
/// Construct a new IPv4 address.
23-
#[must_use]
24-
pubconstfnnew_v4(ip_addr:[u8;4]) ->Self{
25-
letmut 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-
pubconstfnnew_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-
constunsafefnfrom_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-
constfnas_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-
fnas_raw_ptr_mut(&mutself) ->*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-
implFrom<core::net::Ipv4Addr>forIpAddress{
69-
fnfrom(t: core::net::Ipv4Addr) ->Self{
70-
Self::new_v4(t.octets())
71-
}
72-
}
73-
74-
implFrom<IpAddress>for core::net::Ipv4Addr{
75-
fnfrom(IpAddress(o):IpAddress) ->Self{
76-
Self::from([o[0], o[1], o[2], o[3]])
77-
}
78-
}
79-
80-
implFrom<core::net::Ipv6Addr>forIpAddress{
81-
fnfrom(t: core::net::Ipv6Addr) ->Self{
82-
Self::new_v6(t.octets())
83-
}
84-
}
85-
86-
implFrom<IpAddress>for core::net::Ipv6Addr{
87-
fnfrom(value:IpAddress) ->Self{
88-
Self::from(value.0)
89-
}
90-
}
91-
92-
implFrom<core::net::IpAddr>forIpAddress{
93-
fnfrom(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.
17+
pubuse uefi_raw::{IpAddressasEfiIpAddr,MacAddressasEfiMacAddr};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp