Skip to content

Commit c0760b4

Browse files
committed
uefi: document udp_read of PXE protocol + improve test
1 parent f2f6abf commit c0760b4

File tree

2 files changed

+40
-5
lines changed
  • uefi-test-runner/src/proto/network
  • uefi/src/proto/network

2 files changed

+40
-5
lines changed

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ pub fn test() {
7676

7777
info!("Reading UDP packet from example service");
7878

79-
let mut src_ip = server_ip;
80-
let mut src_port = EXAMPLE_SERVICE_PORT;
81-
let mut dest_ip = base_code.mode().station_ip();
82-
let mut dest_port = write_src_port;
79+
// Used as buffers
80+
let mut src_ip = IpAddress::new_v4([0; 4]);
81+
let mut src_port = 0;
82+
let mut dest_ip = IpAddress::new_v4([0; 4]);
83+
let mut dest_port = 0;
8384
let mut header = [0; 1];
8485
let mut received = [0; 4];
8586

@@ -88,7 +89,12 @@ pub fn test() {
8889
let mut read_result = Ok(0);
8990
for i in 0..5 {
9091
read_result = base_code.udp_read(
91-
UdpOpFlags::USE_FILTER,
92+
// We expect exactly one packet but accept all to catch
93+
// unexpected network traffic.
94+
UdpOpFlags::ANY_SRC_PORT
95+
| UdpOpFlags::ANY_SRC_IP
96+
| UdpOpFlags::ANY_DEST_PORT
97+
| UdpOpFlags::ANY_DEST_IP,
9298
Some(&mut dest_ip),
9399
Some(&mut dest_port),
94100
Some(&mut src_ip),
@@ -104,6 +110,14 @@ pub fn test() {
104110
}
105111
read_result.unwrap();
106112

113+
// Check that we indeed received the expected packet.
114+
assert_eq!(dest_ip, base_code.mode().station_ip());
115+
assert_eq!(src_ip, server_ip);
116+
assert_eq!(src_port, EXAMPLE_SERVICE_PORT);
117+
// We don't know the dst port here, as it is dynamically handled
118+
// by QEMU/the NIC.
119+
debug!("dest UDP port: {dest_port}");
120+
107121
// Check the header.
108122
assert_eq!(header[0] as usize, payload.len());
109123
// Check that we receive the reversed payload.

uefi/src/proto/network/pxe.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,27 @@ impl BaseCode {
411411
}
412412

413413
/// Reads a UDP packet from the network interface.
414+
///
415+
/// # Arguments
416+
/// - `op_flags`: [`UdpOpFlags`] specifying the behavior of the function
417+
/// - `dest_ip`: The behavior depends on whether
418+
/// [`UdpOpFlags::ANY_DEST_IP`] is set. If it not set, packets must match
419+
/// the specified IP. Otherwise, the corresponding IP is written into the
420+
/// provided buffer.
421+
/// - `dest_port`: The behavior depends on whether
422+
/// [`UdpOpFlags::ANY_DEST_PORT`] is set. If it not set, packets must match
423+
/// the specified port. Otherwise, the corresponding port is written into
424+
/// the provided buffer.
425+
/// - `src_ip`: The behavior depends on whether
426+
/// [`UdpOpFlags::ANY_SRC_IP`] is set. If it not set, packets must match
427+
/// the specified IP. Otherwise, the corresponding IP is written into the
428+
/// provided buffer.
429+
/// - `src_port`: The behavior depends on whether
430+
/// [`UdpOpFlags::ANY_SRC_PORT`] is set. If it not set, packets must match
431+
/// the specified port. Otherwise, the corresponding port is written into
432+
/// the provided buffer.
433+
/// - `header`: Optional header of the data inside `buffer`.
434+
/// - `buffer`: Buffer for the UDP packet's content.
414435
#[allow(clippy::too_many_arguments)]
415436
pub fn udp_read(
416437
&mut self,

0 commit comments

Comments
 (0)