Skip to content

Commit 02535a7

Browse files
bors[bot]thvdveld
andauthored
Merge #667
667: Change egress error handling r=Dirbaio a=thvdveld Previously, error handling was performed in the closure and after the closure as well. Now, error handling is performed in one place. Co-authored-by: Thibaut Vandervelden <thvdveld@vub.be>
2 parents edbcbff + 1f25195 commit 02535a7

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

src/iface/interface.rs

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,32 +1194,24 @@ impl<'a> Interface<'a> {
11941194
let mut neighbor_addr = None;
11951195
let mut respond = |inner: &mut InterfaceInner, response: IpPacket| {
11961196
neighbor_addr = Some(response.ip_repr().dst_addr());
1197-
match device.transmit().ok_or(Error::Exhausted) {
1198-
Ok(_t) => {
1199-
#[cfg(any(
1200-
feature = "proto-ipv4-fragmentation",
1201-
feature = "proto-sixlowpan-fragmentation"
1202-
))]
1203-
if let Err(e) = inner.dispatch_ip(_t, response, Some(_out_packets)) {
1204-
net_debug!("failed to dispatch IP: {}", e);
1205-
return Err(e);
1206-
}
1197+
let t = device.transmit().ok_or_else(|| {
1198+
net_debug!("failed to transmit IP: {}", Error::Exhausted);
1199+
Error::Exhausted
1200+
})?;
12071201

1208-
#[cfg(not(any(
1209-
feature = "proto-ipv4-fragmentation",
1210-
feature = "proto-sixlowpan-fragmentation"
1211-
)))]
1212-
if let Err(e) = inner.dispatch_ip(_t, response, None) {
1213-
net_debug!("failed to dispatch IP: {}", e);
1214-
return Err(e);
1215-
}
1216-
emitted_any = true;
1217-
}
1218-
Err(e) => {
1219-
net_debug!("failed to transmit IP: {}", e);
1220-
return Err(e);
1221-
}
1222-
}
1202+
#[cfg(any(
1203+
feature = "proto-ipv4-fragmentation",
1204+
feature = "proto-sixlowpan-fragmentation"
1205+
))]
1206+
inner.dispatch_ip(t, response, Some(_out_packets))?;
1207+
1208+
#[cfg(not(any(
1209+
feature = "proto-ipv4-fragmentation",
1210+
feature = "proto-sixlowpan-fragmentation"
1211+
)))]
1212+
inner.dispatch_ip(t, response, None)?;
1213+
1214+
emitted_any = true;
12231215

12241216
Ok(())
12251217
};

0 commit comments

Comments
 (0)