Skip to content

Commit a656ab0

Browse files
committed
iface: use reassembly timeout setting for both ipv4 and 6lowpan.
1 parent d13db8b commit a656ab0

File tree

5 files changed

+31
-65
lines changed

5 files changed

+31
-65
lines changed

src/iface/interface/ethernet.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,8 @@ impl InterfaceInner {
3434
EthernetProtocol::Ipv4 => {
3535
let ipv4_packet = check!(Ipv4Packet::new_checked(eth_frame.payload()));
3636

37-
self.process_ipv4(
38-
sockets,
39-
&ipv4_packet,
40-
#[cfg(feature = "proto-ipv4-fragmentation")]
41-
&mut fragments.assembler,
42-
)
43-
.map(EthernetPacket::Ip)
37+
self.process_ipv4(sockets, &ipv4_packet, fragments)
38+
.map(EthernetPacket::Ip)
4439
}
4540
#[cfg(feature = "proto-ipv6")]
4641
EthernetProtocol::Ipv6 => {

src/iface/interface/ipv4.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ use crate::socket::icmp;
77
use crate::socket::AnySocket;
88

99
use crate::phy::{Medium, TxToken};
10-
use crate::time::{Duration, Instant};
10+
use crate::time::Instant;
1111
use crate::wire::*;
1212

1313
impl InterfaceInner {
1414
pub(super) fn process_ipv4<'a, T: AsRef<[u8]> + ?Sized>(
1515
&mut self,
1616
sockets: &mut SocketSet,
1717
ipv4_packet: &Ipv4Packet<&'a T>,
18-
#[cfg(feature = "proto-ipv4-fragmentation")] assembler: &'a mut PacketAssemblerSet<FragKey>,
18+
frag: &'a mut FragmentsBuffer,
1919
) -> Option<IpPacket<'a>> {
2020
let ipv4_repr = check!(Ipv4Repr::parse(ipv4_packet, &self.caps.checksum));
2121
if !self.is_unicast_v4(ipv4_repr.src_addr) {
@@ -26,12 +26,10 @@ impl InterfaceInner {
2626

2727
#[cfg(feature = "proto-ipv4-fragmentation")]
2828
let ip_payload = {
29-
const REASSEMBLY_TIMEOUT: Duration = Duration::from_secs(90);
30-
3129
if ipv4_packet.more_frags() || ipv4_packet.frag_offset() != 0 {
3230
let key = FragKey::Ipv4(ipv4_packet.get_key());
3331

34-
let f = match assembler.get(&key, self.now + REASSEMBLY_TIMEOUT) {
32+
let f = match frag.assembler.get(&key, self.now + frag.reassembly_timeout) {
3533
Ok(f) => f,
3634
Err(_) => {
3735
net_debug!("No available packet assembler for fragmented packet");

src/iface/interface/mod.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ pub(crate) struct FragmentsBuffer {
6060
#[cfg(feature = "_proto-fragmentation")]
6161
pub(crate) assembler: PacketAssemblerSet<FragKey>,
6262

63-
#[cfg(feature = "proto-sixlowpan-fragmentation")]
64-
sixlowpan_reassembly_timeout: Duration,
63+
#[cfg(feature = "_proto-fragmentation")]
64+
reassembly_timeout: Duration,
6565
}
6666

6767
#[cfg(not(feature = "_proto-fragmentation"))]
@@ -538,8 +538,8 @@ impl Interface {
538538

539539
#[cfg(feature = "_proto-fragmentation")]
540540
assembler: PacketAssemblerSet::new(),
541-
#[cfg(feature = "proto-sixlowpan-fragmentation")]
542-
sixlowpan_reassembly_timeout: Duration::from_secs(60),
541+
#[cfg(feature = "_proto-fragmentation")]
542+
reassembly_timeout: Duration::from_secs(60),
543543
},
544544
fragmenter: Fragmenter::new(),
545545
inner: InterfaceInner {
@@ -703,22 +703,18 @@ impl Interface {
703703
}
704704

705705
/// Get the packet reassembly timeout.
706-
///
707-
/// Currently used only for 6LoWPAN, will be used for IPv4 in the future as well.
708-
#[cfg(feature = "proto-sixlowpan-fragmentation")]
706+
#[cfg(feature = "_proto-fragmentation")]
709707
pub fn reassembly_timeout(&self) -> Duration {
710-
self.fragments.sixlowpan_reassembly_timeout
708+
self.fragments.reassembly_timeout
711709
}
712710

713711
/// Set the packet reassembly timeout.
714-
///
715-
/// Currently used only for 6LoWPAN, will be used for IPv4 in the future as well.
716-
#[cfg(feature = "proto-sixlowpan-fragmentation")]
712+
#[cfg(feature = "_proto-fragmentation")]
717713
pub fn set_reassembly_timeout(&mut self, timeout: Duration) {
718714
if timeout > Duration::from_secs(60) {
719715
net_debug!("RFC 4944 specifies that the reassembly timeout MUST be set to a maximum of 60 seconds");
720716
}
721-
self.fragments.sixlowpan_reassembly_timeout = timeout;
717+
self.fragments.reassembly_timeout = timeout;
722718
}
723719

724720
/// Transmit packets queued in the given sockets, and receive packets queued
@@ -1288,19 +1284,14 @@ impl InterfaceInner {
12881284
&mut self,
12891285
sockets: &mut SocketSet,
12901286
ip_payload: &'frame T,
1291-
fragments: &'frame mut FragmentsBuffer,
1287+
frag: &'frame mut FragmentsBuffer,
12921288
) -> Option<IpPacket<'frame>> {
12931289
match IpVersion::of_packet(ip_payload.as_ref()) {
12941290
#[cfg(feature = "proto-ipv4")]
12951291
Ok(IpVersion::Ipv4) => {
12961292
let ipv4_packet = check!(Ipv4Packet::new_checked(ip_payload));
12971293

1298-
self.process_ipv4(
1299-
sockets,
1300-
&ipv4_packet,
1301-
#[cfg(feature = "proto-ipv4-fragmentation")]
1302-
&mut fragments.assembler,
1303-
)
1294+
self.process_ipv4(sockets, &ipv4_packet, frag)
13041295
}
13051296
#[cfg(feature = "proto-ipv6")]
13061297
Ok(IpVersion::Ipv6) => {

src/iface/interface/sixlowpan.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,7 @@ impl InterfaceInner {
107107
// This information is the total size of the packet when it is fully assmbled.
108108
// We also pass the header size, since this is needed when other fragments
109109
// (other than the first one) are added.
110-
let frag_slot = match f
111-
.assembler
112-
.get(&key, self.now + f.sixlowpan_reassembly_timeout)
113-
{
110+
let frag_slot = match f.assembler.get(&key, self.now + f.reassembly_timeout) {
114111
Ok(frag) => frag,
115112
Err(AssemblerFullError) => {
116113
net_debug!("No available packet assembler for fragmented packet");

src/iface/interface/tests.rs

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,9 @@ fn test_no_icmp_no_unicast_ipv4() {
168168
// broadcast address
169169

170170
assert_eq!(
171-
iface.inner.process_ipv4(
172-
&mut sockets,
173-
&frame,
174-
#[cfg(feature = "proto-ipv4-fragmentation")]
175-
&mut iface.fragments.assembler
176-
),
171+
iface
172+
.inner
173+
.process_ipv4(&mut sockets, &frame, &mut iface.fragments),
177174
None
178175
);
179176
}
@@ -254,12 +251,9 @@ fn test_icmp_error_no_payload() {
254251
// And we correctly handle no payload.
255252

256253
assert_eq!(
257-
iface.inner.process_ipv4(
258-
&mut sockets,
259-
&frame,
260-
#[cfg(feature = "proto-ipv4-fragmentation")]
261-
&mut iface.fragments.assembler
262-
),
254+
iface
255+
.inner
256+
.process_ipv4(&mut sockets, &frame, &mut iface.fragments),
263257
Some(expected_repr)
264258
);
265259
}
@@ -564,12 +558,9 @@ fn test_handle_ipv4_broadcast() {
564558
let expected_packet = IpPacket::Icmpv4((expected_ipv4_repr, expected_icmpv4_repr));
565559

566560
assert_eq!(
567-
iface.inner.process_ipv4(
568-
&mut sockets,
569-
&frame,
570-
#[cfg(feature = "proto-ipv4-fragmentation")]
571-
&mut iface.fragments.assembler
572-
),
561+
iface
562+
.inner
563+
.process_ipv4(&mut sockets, &frame, &mut iface.fragments),
573564
Some(expected_packet)
574565
);
575566
}
@@ -1268,12 +1259,9 @@ fn test_raw_socket_no_reply() {
12681259
};
12691260

12701261
assert_eq!(
1271-
iface.inner.process_ipv4(
1272-
&mut sockets,
1273-
&frame,
1274-
#[cfg(feature = "proto-ipv4-fragmentation")]
1275-
&mut iface.fragments.assembler
1276-
),
1262+
iface
1263+
.inner
1264+
.process_ipv4(&mut sockets, &frame, &mut iface.fragments),
12771265
None
12781266
);
12791267
}
@@ -1357,12 +1345,9 @@ fn test_raw_socket_with_udp_socket() {
13571345
};
13581346

13591347
assert_eq!(
1360-
iface.inner.process_ipv4(
1361-
&mut sockets,
1362-
&frame,
1363-
#[cfg(feature = "proto-ipv4-fragmentation")]
1364-
&mut iface.fragments.assembler
1365-
),
1348+
iface
1349+
.inner
1350+
.process_ipv4(&mut sockets, &frame, &mut iface.fragments),
13661351
None
13671352
);
13681353

0 commit comments

Comments
 (0)