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

Commit 5a30e29

Browse files
committed
xxx
1 parent f21788d commit 5a30e29

File tree

3 files changed

+74
-35
lines changed

3 files changed

+74
-35
lines changed

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

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

3+
use core::net::{IpAddr, Ipv4Addr, Ipv6Addr};
34
use uefi::proto::network::pxe::{BaseCode, DhcpV4Packet, IpFilter, IpFilters, UdpOpFlags};
45
use uefi::proto::network::EfiIpAddr;
56
use uefi::{boot, CStr8};
@@ -27,7 +28,7 @@ pub fn test() {
2728
assert!(base_code.mode().dhcp_ack_received());
2829
let dhcp_ack: &DhcpV4Packet = base_code.mode().dhcp_ack().as_ref();
2930
let server_ip = dhcp_ack.bootp_si_addr;
30-
let server_ip = EfiIpAddr::new_v4(server_ip);
31+
let server_ip = IpAddr::V4(Ipv4Addr::from(server_ip));
3132

3233
const EXAMPLE_FILE_NAME: &[u8] = b"example-file.txt0円";
3334
const EXAMPLE_FILE_CONTENT: &[u8] = b"Hello world!";
@@ -75,7 +76,16 @@ pub fn test() {
7576

7677
let mut src_ip = server_ip;
7778
let mut src_port = EXAMPLE_SERVICE_PORT;
78-
let mut dest_ip = base_code.mode().station_ip();
79+
80+
// TODO add code to put this behind a type
81+
let mut dest_ip = if base_code.mode().using_ipv6() {
82+
IpAddr::V6(Ipv6Addr::from(base_code.mode().station_ip().octets()))
83+
} else {
84+
let octets: [u8; 4] = base_code.mode().station_ip().octets()[0..4]
85+
.try_into()
86+
.unwrap();
87+
IpAddr::V4(Ipv4Addr::from(octets))
88+
};
7989
let mut dest_port = write_src_port;
8090
let mut header = [0; 1];
8191
let mut received = [0; 4];

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

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use bitflags::bitflags;
1111
use core::fmt::{self, Debug, Display, Formatter};
1212
use core::iter::from_fn;
1313
use core::mem::MaybeUninit;
14+
use core::net::IpAddr;
1415
use core::ptr::{self, null, null_mut};
1516
use core::slice;
1617
use ptr_meta::Pointee;
@@ -65,9 +66,10 @@ impl BaseCode {
6566
}
6667

6768
/// Returns the size of a file located on a TFTP server.
68-
pub fn tftp_get_file_size(&mut self, server_ip: &EfiIpAddr, filename: &CStr8) -> Result<u64> {
69+
pub fn tftp_get_file_size(&mut self, server_ip: &IpAddr, filename: &CStr8) -> Result<u64> {
6970
let mut buffer_size = 0;
7071

72+
let server_ip = EfiIpAddr::from(server_ip);
7173
let status = unsafe {
7274
(self.0.mtftp)(
7375
&mut self.0,
@@ -88,7 +90,7 @@ impl BaseCode {
8890
/// Reads a file located on a TFTP server.
8991
pub fn tftp_read_file(
9092
&mut self,
91-
server_ip: &EfiIpAddr,
93+
server_ip: &IpAddr,
9294
filename: &CStr8,
9395
buffer: Option<&mut [u8]>,
9496
) -> Result<u64> {
@@ -98,7 +100,7 @@ impl BaseCode {
98100
} else {
99101
(null_mut(), 0, Boolean::TRUE)
100102
};
101-
103+
let server_ip = EfiIpAddr::from(server_ip);
102104
let status = unsafe {
103105
(self.0.mtftp)(
104106
&mut self.0,
@@ -119,7 +121,7 @@ impl BaseCode {
119121
/// Writes to a file located on a TFTP server.
120122
pub fn tftp_write_file(
121123
&mut self,
122-
server_ip: &EfiIpAddr,
124+
server_ip: &IpAddr,
123125
filename: &CStr8,
124126
overwrite: bool,
125127
buffer: &[u8],
@@ -135,7 +137,7 @@ impl BaseCode {
135137
overwrite.into(),
136138
&mut buffer_size,
137139
null(),
138-
server_ip.as_ptr(),
140+
EfiIpAddr::from(server_ip).as_ptr(),
139141
cstr8_to_ptr(filename),
140142
null(),
141143
Boolean::FALSE,
@@ -147,7 +149,7 @@ impl BaseCode {
147149
/// Reads a directory listing of a directory on a TFTP server.
148150
pub fn tftp_read_dir<'a>(
149151
&mut self,
150-
server_ip: &EfiIpAddr,
152+
server_ip: &IpAddr,
151153
directory_name: &CStr8,
152154
buffer: &'a mut [u8],
153155
) -> Result<impl Iterator<Item = core::result::Result<TftpFileInfo<'a>, ReadDirParseError>> + 'a>
@@ -163,7 +165,7 @@ impl BaseCode {
163165
Boolean::FALSE,
164166
&mut buffer_size,
165167
null(),
166-
server_ip.as_ptr(),
168+
EfiIpAddr::from(server_ip).as_ptr(),
167169
cstr8_to_ptr(directory_name),
168170
null(),
169171
Boolean::FALSE,
@@ -222,7 +224,7 @@ impl BaseCode {
222224
/// Returns the size of a file located on a MTFTP server.
223225
pub fn mtftp_get_file_size(
224226
&mut self,
225-
server_ip: &EfiIpAddr,
227+
server_ip: &IpAddr,
226228
filename: &CStr8,
227229
info: &MtftpInfo,
228230
) -> Result<u64> {
@@ -236,7 +238,7 @@ impl BaseCode {
236238
Boolean::FALSE,
237239
&mut buffer_size,
238240
null(),
239-
server_ip.as_ptr(),
241+
EfiIpAddr::from(server_ip).as_ptr(),
240242
cstr8_to_ptr(filename),
241243
info.as_raw_ptr(),
242244
Boolean::FALSE,
@@ -248,7 +250,7 @@ impl BaseCode {
248250
/// Reads a file located on a MTFTP server.
249251
pub fn mtftp_read_file(
250252
&mut self,
251-
server_ip: &EfiIpAddr,
253+
server_ip: &IpAddr,
252254
filename: &CStr8,
253255
buffer: Option<&mut [u8]>,
254256
info: &MtftpInfo,
@@ -268,7 +270,7 @@ impl BaseCode {
268270
Boolean::FALSE,
269271
&mut buffer_size,
270272
null(),
271-
server_ip.as_ptr(),
273+
EfiIpAddr::from(server_ip).as_ptr(),
272274
cstr8_to_ptr(filename),
273275
info.as_raw_ptr(),
274276
dont_use_buffer,
@@ -280,7 +282,7 @@ impl BaseCode {
280282
/// Reads a directory listing of a directory on a MTFTP server.
281283
pub fn mtftp_read_dir<'a>(
282284
&mut self,
283-
server_ip: &EfiIpAddr,
285+
server_ip: &IpAddr,
284286
buffer: &'a mut [u8],
285287
info: &MtftpInfo,
286288
) -> Result<impl Iterator<Item = core::result::Result<MtftpFileInfo<'a>, ReadDirParseError>> + 'a>
@@ -296,7 +298,7 @@ impl BaseCode {
296298
Boolean::FALSE,
297299
&mut buffer_size,
298300
null(),
299-
server_ip.as_ptr(),
301+
EfiIpAddr::from(server_ip).as_ptr(),
300302
null_mut(),
301303
info.as_raw_ptr(),
302304
Boolean::FALSE,
@@ -374,10 +376,10 @@ impl BaseCode {
374376
pub fn udp_write(
375377
&mut self,
376378
op_flags: UdpOpFlags,
377-
dest_ip: &EfiIpAddr,
379+
dest_ip: &IpAddr,
378380
dest_port: u16,
379-
gateway_ip: Option<&EfiIpAddr>,
380-
src_ip: Option<&EfiIpAddr>,
381+
gateway_ip: Option<&IpAddr>,
382+
src_ip: Option<&IpAddr>,
381383
src_port: Option<&mut u16>,
382384
header: Option<&[u8]>,
383385
buffer: &[u8],
@@ -390,14 +392,18 @@ impl BaseCode {
390392
(None, null())
391393
};
392394

395+
let gateway_ip = gateway_ip.map(EfiIpAddr::from);
396+
let src_ip = src_ip.map(EfiIpAddr::from);
397+
let dest_ip = EfiIpAddr::from(dest_ip);
398+
393399
unsafe {
394400
(self.0.udp_write)(
395401
&mut self.0,
396402
op_flags,
397403
dest_ip.as_ptr(),
398404
&dest_port,
399-
opt_ip_addr_to_ptr(gateway_ip),
400-
opt_ip_addr_to_ptr(src_ip),
405+
opt_ip_addr_to_ptr(gateway_ip.as_ref()),
406+
opt_ip_addr_to_ptr(src_ip.as_ref()),
401407
opt_mut_to_ptr(src_port),
402408
opt_ref_to_ptr(header_size),
403409
header_ptr,
@@ -413,9 +419,9 @@ impl BaseCode {
413419
pub fn udp_read(
414420
&mut self,
415421
op_flags: UdpOpFlags,
416-
dest_ip: Option<&mut EfiIpAddr>,
422+
mutdest_ip: Option<&mut IpAddr>,
417423
dest_port: Option<&mut u16>,
418-
src_ip: Option<&mut EfiIpAddr>,
424+
mutsrc_ip: Option<&mut IpAddr>,
419425
src_port: Option<&mut u16>,
420426
header: Option<&mut [u8]>,
421427
buffer: &mut [u8],
@@ -429,21 +435,40 @@ impl BaseCode {
429435
};
430436

431437
let mut buffer_size = buffer.len();
432-
438+
let mut dest_ip_efi = dest_ip.as_ref().map(|rf| **rf).map(EfiIpAddr::from);
439+
let mut src_ip_efi = src_ip.as_ref().map(|rf| **rf).map(EfiIpAddr::from);
433440
let status = unsafe {
434441
(self.0.udp_read)(
435442
&mut self.0,
436443
op_flags,
437-
opt_ip_addr_to_ptr_mut(dest_ip),
444+
opt_ip_addr_to_ptr_mut(dest_ip_efi.as_mut()),
438445
opt_mut_to_ptr(dest_port),
439-
opt_ip_addr_to_ptr_mut(src_ip),
446+
opt_ip_addr_to_ptr_mut(src_ip_efi.as_mut()),
440447
opt_mut_to_ptr(src_port),
441448
header_size,
442449
header_ptr,
443450
&mut buffer_size,
444451
buffer.as_mut_ptr().cast(),
445452
)
446453
};
454+
// Update input props
455+
if let Some(ip) = &mut dest_ip {
456+
let ip_efi = dest_ip_efi.unwrap();
457+
if ip.is_ipv4() {
458+
**ip = IpAddr::V4(unsafe { ip_efi.v4 })
459+
} else {
460+
**ip = IpAddr::V6(unsafe { ip_efi.v6 })
461+
}
462+
}
463+
if let Some(ip) = &mut src_ip {
464+
let ip_efi = src_ip_efi.unwrap();
465+
if ip.is_ipv4() {
466+
**ip = IpAddr::V4(unsafe { ip_efi.v4 })
467+
} else {
468+
**ip = IpAddr::V6(unsafe { ip_efi.v6 })
469+
}
470+
}
471+
447472
status.to_result_with_val(|| buffer_size)
448473
}
449474

@@ -455,7 +480,8 @@ impl BaseCode {
455480
}
456481

457482
/// Uses the ARP protocol to resolve a MAC address.
458-
pub fn arp(&mut self, ip_addr: &EfiIpAddr, mac_addr: Option<&mut EfiMacAddr>) -> Result {
483+
pub fn arp(&mut self, ip_addr: &IpAddr, mac_addr: Option<&mut EfiMacAddr>) -> Result {
484+
let ip_addr = EfiIpAddr::from(ip_addr);
459485
unsafe { (self.0.arp)(&mut self.0, ip_addr.as_ptr(), opt_mut_to_ptr(mac_addr)) }.to_result()
460486
}
461487

@@ -486,14 +512,16 @@ impl BaseCode {
486512
/// device.
487513
pub fn set_station_ip(
488514
&mut self,
489-
new_station_ip: Option<&EfiIpAddr>,
490-
new_subnet_mask: Option<&EfiIpAddr>,
515+
new_station_ip: Option<&IpAddr>,
516+
new_subnet_mask: Option<&IpAddr>,
491517
) -> Result {
518+
let new_station_ip = new_station_ip.map(EfiIpAddr::from);
519+
let new_subnet_mask = new_subnet_mask.map(EfiIpAddr::from);
492520
unsafe {
493521
(self.0.set_station_ip)(
494522
&mut self.0,
495-
opt_ip_addr_to_ptr(new_station_ip),
496-
opt_ip_addr_to_ptr(new_subnet_mask),
523+
opt_ip_addr_to_ptr(new_station_ip.as_ref()),
524+
opt_ip_addr_to_ptr(new_subnet_mask.as_ref()),
497525
)
498526
}
499527
.to_result()
@@ -711,16 +739,16 @@ impl Server {
711739
/// `None` only Boot Server replies with matching the IP address will be
712740
/// accepted.
713741
#[must_use]
714-
pub fn new(ty: u16, ip_addr: Option<EfiIpAddr>) -> Self {
742+
pub fn new(ty: u16, ip_addr: Option<IpAddr>) -> Self {
715743
Self {
716744
ty,
717745
accept_any_response: ip_addr.is_none(),
718746
_reserved: 0,
719-
ip_addr: ip_addr.unwrap_or(EfiIpAddr::from([0; 16])),
747+
ip_addr: ip_addr.map(Into::into).unwrap_or(EfiIpAddr::from([0; 16])),
720748
}
721749
}
722750

723-
/// Returns a `None` if the any response should be accepted or the IP
751+
/// Returns `None` if any response should be accepted, or otherwise the IP
724752
/// address of a Boot Server whose responses should be accepted.
725753
#[must_use]
726754
pub const fn ip_addr(&self) -> Option<&EfiIpAddr> {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::data_types::Event;
1414
use crate::proto::unsafe_protocol;
1515
use crate::{Result, StatusExt};
1616
use core::ffi::c_void;
17+
use core::net::IpAddr;
1718
use core::ptr;
1819
use core::ptr::NonNull;
1920
use uefi_raw::protocol::network::snp::SimpleNetworkProtocol;
@@ -127,13 +128,13 @@ impl SimpleNetwork {
127128
}
128129

129130
/// Convert a multicast IP address to a multicast HW MAC Address.
130-
pub fn mcast_ip_to_mac(&self, ipv6: bool, ip: EfiIpAddr) -> Result<EfiMacAddr> {
131+
pub fn mcast_ip_to_mac(&self, ipv6: bool, ip: IpAddr) -> Result<EfiMacAddr> {
131132
let mut mac_address = EfiMacAddr([0; 32]);
132133
let status = unsafe {
133134
(self.0.multicast_ip_to_mac)(
134135
&self.0,
135136
Boolean::from(ipv6),
136-
ip.as_ptr(),
137+
EfiIpAddr::from(ip).as_ptr(),
137138
&mut mac_address,
138139
)
139140
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /