Skip to content

Commit 57087c4

Browse files
committed
style: Format the files using rustfmt
1 parent 7be3b8e commit 57087c4

File tree

3 files changed

+78
-93
lines changed

3 files changed

+78
-93
lines changed

quinn-udp/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ impl EcnCodepoint {
239239
}
240240
}
241241

242-
243242
#[cfg(target_os = "linux")]
244243
#[repr(C)]
245244
#[derive(Clone, Copy, Debug)]
@@ -251,13 +250,13 @@ struct SockExtendedErr {
251250
ee_pad: u8,
252251
ee_info: u32,
253252
ee_data: u32,
254-
}
253+
}
255254

256255
#[cfg(target_os = "linux")]
257256
#[derive(Clone, Debug, Copy)]
258257
pub struct ICMPError {
259258
pub errno: u32,
260259
pub origin: u8,
261260
pub err_no: u8,
262-
pub code: u8
261+
pub code: u8,
263262
}

quinn-udp/src/unix.rs

Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -125,27 +125,18 @@ impl UdpSocketState {
125125
}
126126
}
127127

128-
129128
// Enable IP_RECVERR and IPV6_RECVERR for ICMP Errors
130129
#[cfg(target_os = "linux")]
131130
if is_ipv4 {
132-
if let Err(e) = set_socket_option(
133-
&*io,
134-
libc::IPPROTO_IP,
135-
libc::IP_RECVERR,
136-
OPTION_ON
137-
) {
131+
if let Err(e) = set_socket_option(&*io, libc::IPPROTO_IP, libc::IP_RECVERR, OPTION_ON) {
138132
crate::log::warn!("Failed to enable IP_RECVERR: {}", e);
139-
}
133+
}
140134
} else {
141-
if let Err(e) = set_socket_option(
142-
&*io,
143-
libc::IPPROTO_IPV6,
144-
libc::IPV6_RECVERR,
145-
OPTION_ON
146-
) {
135+
if let Err(e) =
136+
set_socket_option(&*io, libc::IPPROTO_IPV6, libc::IPV6_RECVERR, OPTION_ON)
137+
{
147138
crate::log::warn!("Failed to enable IPV6_RECVERR: {}", e);
148-
}
139+
}
149140
}
150141

151142
let mut may_fragment = false;
@@ -533,19 +524,22 @@ fn recv(io: SockRef<'_>, bufs: &mut [IoSliceMut<'_>], meta: &mut [RecvMeta]) ->
533524
use std::os::fd::AsFd;
534525
// Clear the error queue after processing normal packets
535526
while let Ok(Some((addr, err))) = recv_err(&io.as_fd()) {
536-
crate::log::debug!("ICMP error from {}: origin: {}, type: {}, code: {}, err_no: {} ",
537-
addr,
538-
err.ee_origin,
539-
err.ee_type,
540-
err.ee_code,
541-
err.ee_errno
542-
);
543-
match (err.ee_origin, err.ee_type, err.ee_code) {
544-
(libc::SO_EE_ORIGIN_ICMP, 3, 0) => crate::log::warn!("Network Unreachable: {}", addr),
545-
(libc::SO_EE_ORIGIN_ICMP, 3, 1) => crate::log::warn!("Host Unreachable: {}", addr),
546-
(libc::SO_EE_ORIGIN_ICMP, 3, 2) => crate::log::warn!("PORT Unreachable: {}", addr),
547-
(libc::SO_EE_ORIGIN_ICMP6, 1, 0) => crate::log::warn!("IPv6 Unreachable: {}", addr),
548-
_ => crate::log::warn!("Other ICMP error: {:?}", err)
527+
crate::log::debug!(
528+
"ICMP error from {}: origin: {}, type: {}, code: {}, err_no: {} ",
529+
addr,
530+
err.ee_origin,
531+
err.ee_type,
532+
err.ee_code,
533+
err.ee_errno
534+
);
535+
match (err.ee_origin, err.ee_type, err.ee_code) {
536+
(libc::SO_EE_ORIGIN_ICMP, 3, 0) => {
537+
crate::log::warn!("Network Unreachable: {}", addr)
538+
}
539+
(libc::SO_EE_ORIGIN_ICMP, 3, 1) => crate::log::warn!("Host Unreachable: {}", addr),
540+
(libc::SO_EE_ORIGIN_ICMP, 3, 2) => crate::log::warn!("PORT Unreachable: {}", addr),
541+
(libc::SO_EE_ORIGIN_ICMP6, 1, 0) => crate::log::warn!("IPv6 Unreachable: {}", addr),
542+
_ => crate::log::warn!("Other ICMP error: {:?}", err),
549543
};
550544
}
551545
}
@@ -845,7 +839,6 @@ fn decode_recv(
845839
})
846840
}
847841

848-
849842
#[cfg(target_os = "linux")]
850843
fn recv_err(io: &impl AsRawFd) -> io::Result<Option<(SocketAddr, SockExtendedErr)>> {
851844
use std::mem;
@@ -860,7 +853,7 @@ fn recv_err(io: &impl AsRawFd) -> io::Result<Option<(SocketAddr, SockExtendedErr
860853
iov_len: 0,
861854
};
862855

863-
let mut addr_storage: libc::sockaddr_storage = unsafe { mem::zeroed() };
856+
let mut addr_storage: libc::sockaddr_storage = unsafe { mem::zeroed() };
864857

865858
// Have followed the previous declarations
866859
let mut hdr: libc::msghdr = unsafe { mem::zeroed() };
@@ -871,10 +864,7 @@ fn recv_err(io: &impl AsRawFd) -> io::Result<Option<(SocketAddr, SockExtendedErr
871864
hdr.msg_control = control.0.as_mut_ptr() as *mut _;
872865
hdr.msg_controllen = control.0.len() as _;
873866

874-
875-
let ret = unsafe {
876-
libc::recvmsg(fd, &mut hdr, libc::MSG_ERRQUEUE)
877-
};
867+
let ret = unsafe { libc::recvmsg(fd, &mut hdr, libc::MSG_ERRQUEUE) };
878868

879869
if ret < 0 {
880870
let err = io::Error::last_os_error();
@@ -885,19 +875,17 @@ fn recv_err(io: &impl AsRawFd) -> io::Result<Option<(SocketAddr, SockExtendedErr
885875
return Err(err);
886876
}
887877

888-
let mut cmsg_ptr = unsafe { libc::CMSG_FIRSTHDR(&hdr)};
878+
let mut cmsg_ptr = unsafe { libc::CMSG_FIRSTHDR(&hdr) };
889879

890880
while !cmsg_ptr.is_null() {
891881
let cmsg = unsafe { &*cmsg_ptr };
892-
882+
893883
const IP_RECVERR: libc::c_int = 11;
894884
const IPV6_RECVERR: libc::c_int = 25;
895-
896-
let is_ip_err = cmsg.cmsg_level == libc::IPPROTO_IP
897-
&& cmsg.cmsg_type == IP_RECVERR;
898-
let is_ipv6_err = cmsg.cmsg_level == libc::IPPROTO_IPV6
899-
&& cmsg.cmsg_type == IPV6_RECVERR;
900-
885+
886+
let is_ip_err = cmsg.cmsg_level == libc::IPPROTO_IP && cmsg.cmsg_type == IP_RECVERR;
887+
let is_ipv6_err = cmsg.cmsg_level == libc::IPPROTO_IPV6 && cmsg.cmsg_type == IPV6_RECVERR;
888+
901889
if is_ip_err || is_ipv6_err {
902890
let err_data = unsafe {
903891
let data_ptr = libc::CMSG_DATA(cmsg_ptr);
@@ -926,24 +914,21 @@ fn recv_err(io: &impl AsRawFd) -> io::Result<Option<(SocketAddr, SockExtendedErr
926914
_ => return Ok(None), // Unknown address family
927915
}
928916
};
929-
917+
930918
return Ok(Some((addr, *err_data)));
931919
}
932920

933-
cmsg_ptr = unsafe { libc::CMSG_NXTHDR(&hdr, cmsg_ptr)};
934-
921+
cmsg_ptr = unsafe { libc::CMSG_NXTHDR(&hdr, cmsg_ptr) };
935922
}
936923
Ok(None)
937924
}
938925

939-
940-
// I don't know about how other platforms handle this.
926+
// I don't know about how other platforms handle this.
941927
#[cfg(not(target_os = "linux"))]
942928
fn recv_error_queue(_io: &impl AsRawFd) -> io::Result<Option<(SocketAddr, ())>> {
943-
Ok(None)
929+
Ok(None)
944930
}
945931

946-
947932
#[cfg(not(apple_slow))]
948933
// Chosen somewhat arbitrarily; might benefit from additional tuning.
949934
pub(crate) const BATCH_SIZE: usize = 32;

quinn-udp/tests/tests.rs

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -375,47 +375,42 @@ fn ip_to_v6_mapped(x: IpAddr) -> IpAddr {
375375
fn test_ip_recverr() {
376376
use std::io::IoSliceMut;
377377
use std::time::Duration;
378-
378+
379379
let socket = socket2::Socket::new(
380380
socket2::Domain::IPV4,
381381
socket2::Type::DGRAM,
382382
Some(socket2::Protocol::UDP),
383383
)
384384
.expect("failed to create socket");
385-
385+
386386
// Bind to localhost
387387
let bind_addr = socket2::SockAddr::from(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 0));
388388
socket.bind(&bind_addr).expect("failed to bind");
389-
389+
390390
// Create UdpSocketState (this should enable IP_RECVERR)
391-
let state = UdpSocketState::new((&socket).into())
392-
.expect("failed to create UdpSocketState");
393-
391+
let state = UdpSocketState::new((&socket).into()).expect("failed to create UdpSocketState");
392+
394393
// Send to an unreachable address in the documentation range (192.0.2.0/24)
395-
let unreachable_addr = SocketAddr::V4(SocketAddrV4::new(
396-
Ipv4Addr::new(192, 0, 2, 1),
397-
12345,
398-
));
399-
394+
let unreachable_addr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(192, 0, 2, 1), 12345));
395+
400396
let transmit = Transmit {
401397
destination: unreachable_addr,
402398
ecn: None,
403399
contents: b"test packet to unreachable destination",
404400
segment_size: None,
405401
src_ip: None,
406402
};
407-
403+
408404
// Send the packet
409405
let state_result = state.try_send((&socket).into(), &transmit);
410406
assert!(state_result.is_err(), "Expected to fail to transmit");
411407

412-
413408
std::thread::sleep(Duration::from_millis(200));
414-
409+
415410
let mut buf = [0u8; 1500];
416411
let mut meta = RecvMeta::default();
417412
let mut received_icmp_error = false;
418-
413+
419414
for attempt in 0..5 {
420415
match state.recv(
421416
(&socket).into(),
@@ -426,9 +421,14 @@ fn test_ip_recverr() {
426421
println!("Attempt {}: Received {} messages", attempt, n);
427422
}
428423
Err(e) => {
429-
println!("Attempt {}: Received error: {} (kind: {:?}, raw: {:?})",
430-
attempt, e, e.kind(), e.raw_os_error());
431-
424+
println!(
425+
"Attempt {}: Received error: {} (kind: {:?}, raw: {:?})",
426+
attempt,
427+
e,
428+
e.kind(),
429+
e.raw_os_error()
430+
);
431+
432432
// Check if this is an ICMP-related error
433433
match e.raw_os_error() {
434434
Some(libc::EHOSTUNREACH) => {
@@ -457,7 +457,7 @@ fn test_ip_recverr() {
457457
}
458458
std::thread::sleep(Duration::from_millis(10));
459459
}
460-
460+
461461
if received_icmp_error {
462462
println!("IP_RECVERR is working! Received ICMP error.");
463463
} else {
@@ -470,50 +470,44 @@ fn test_ip_recverr() {
470470
fn test_ipv6_recverr() {
471471
use std::io::IoSliceMut;
472472
use std::time::Duration;
473-
473+
474474
let socket = socket2::Socket::new(
475475
socket2::Domain::IPV6,
476476
socket2::Type::DGRAM,
477477
Some(socket2::Protocol::UDP),
478478
)
479479
.expect("failed to create IPv6 socket");
480-
481-
let bind_addr = socket2::SockAddr::from(SocketAddrV6::new(
482-
Ipv6Addr::LOCALHOST,
483-
0,
484-
0,
485-
0,
486-
));
480+
481+
let bind_addr = socket2::SockAddr::from(SocketAddrV6::new(Ipv6Addr::LOCALHOST, 0, 0, 0));
487482
socket.bind(&bind_addr).expect("failed to bind");
488-
489-
let state = UdpSocketState::new((&socket).into())
490-
.expect("failed to create UdpSocketState");
491-
483+
484+
let state = UdpSocketState::new((&socket).into()).expect("failed to create UdpSocketState");
485+
492486
// Send to unreachable IPv6 address
493487
let unreachable_addr = SocketAddr::V6(SocketAddrV6::new(
494488
Ipv6Addr::new(0x2001, 0x0db8, 0, 0, 0, 0, 0, 1),
495489
12345,
496490
0,
497491
0,
498492
));
499-
493+
500494
let transmit = Transmit {
501495
destination: unreachable_addr,
502496
ecn: None,
503497
contents: b"test IPv6 packet",
504498
segment_size: None,
505499
src_ip: None,
506500
};
507-
501+
508502
let state_res = state.try_send((&socket).into(), &transmit);
509503
assert!(state_res.is_err(), "Expected to fail to transmit");
510-
504+
511505
std::thread::sleep(Duration::from_millis(200));
512-
506+
513507
let mut buf = [0u8; 1500];
514508
let mut meta = RecvMeta::default();
515509
let mut received_icmp_error = false;
516-
510+
517511
for attempt in 0..5 {
518512
match state.recv(
519513
(&socket).into(),
@@ -524,11 +518,18 @@ fn test_ipv6_recverr() {
524518
println!("Attempt {}: Received {} messages", attempt, n);
525519
}
526520
Err(e) => {
527-
println!("Attempt {}: Error: {} (raw: {:?})", attempt, e, e.raw_os_error());
528-
521+
println!(
522+
"Attempt {}: Error: {} (raw: {:?})",
523+
attempt,
524+
e,
525+
e.raw_os_error()
526+
);
527+
529528
match e.raw_os_error() {
530-
Some(libc::EHOSTUNREACH) | Some(libc::ENETUNREACH) |
531-
Some(libc::ECONNREFUSED) | Some(libc::ETIMEDOUT) => {
529+
Some(libc::EHOSTUNREACH)
530+
| Some(libc::ENETUNREACH)
531+
| Some(libc::ECONNREFUSED)
532+
| Some(libc::ETIMEDOUT) => {
532533
println!("✓ Received ICMPv6 error");
533534
received_icmp_error = true;
534535
break;
@@ -542,7 +543,7 @@ fn test_ipv6_recverr() {
542543
}
543544
std::thread::sleep(Duration::from_millis(10));
544545
}
545-
546+
546547
if received_icmp_error {
547548
println!("IPV6_RECVERR is working!");
548549
} else {

0 commit comments

Comments
 (0)