Просмотр исходного кода

Make the packet fragmentation cache timeout user configurable

Benjamin Brittain 2 лет назад
Родитель
Сommit
68ebd6eb8c
1 измененных файлов с 21 добавлено и 5 удалено
  1. 21 5
      src/iface/interface.rs

+ 21 - 5
src/iface/interface.rs

@@ -27,7 +27,8 @@ pub(crate) struct FragmentsBuffer<'a> {
     ipv4_fragments: PacketAssemblerSet<'a, Ipv4FragKey>,
     #[cfg(feature = "proto-sixlowpan-fragmentation")]
     sixlowpan_fragments: PacketAssemblerSet<'a, SixlowpanFragKey>,
-
+    #[cfg(feature = "proto-sixlowpan-fragmentation")]
+    sixlowpan_fragments_cache_timeout: Duration,
     #[cfg(not(any(
         feature = "proto-ipv4-fragmentation",
         feature = "proto-sixlowpan-fragmentation"
@@ -199,6 +200,8 @@ pub struct InterfaceBuilder<'a> {
     #[cfg(feature = "proto-sixlowpan-fragmentation")]
     sixlowpan_fragments: Option<PacketAssemblerSet<'a, SixlowpanFragKey>>,
     #[cfg(feature = "proto-sixlowpan-fragmentation")]
+    sixlowpan_fragments_cache_timeout: Duration,
+    #[cfg(feature = "proto-sixlowpan-fragmentation")]
     sixlowpan_out_buffer: Option<ManagedSlice<'a, u8>>,
 }
 
@@ -266,6 +269,8 @@ let iface = builder.finalize(&mut device);
             #[cfg(feature = "proto-sixlowpan-fragmentation")]
             sixlowpan_fragments: None,
             #[cfg(feature = "proto-sixlowpan-fragmentation")]
+            sixlowpan_fragments_cache_timeout: Duration::from_secs(60),
+            #[cfg(feature = "proto-sixlowpan-fragmentation")]
             sixlowpan_out_buffer: None,
         }
     }
@@ -393,6 +398,12 @@ let iface = builder.finalize(&mut device);
         self
     }
 
+    #[cfg(feature = "proto-sixlowpan-fragmentation")]
+    pub fn sixlowpan_fragments_cache_timeout(mut self, sec: u64) -> Self {
+        self.sixlowpan_fragments_cache_timeout = Duration::from_secs(sec);
+        self
+    }
+
     #[cfg(feature = "proto-sixlowpan-fragmentation")]
     pub fn sixlowpan_out_packet_cache<T>(mut self, storage: T) -> Self
     where
@@ -493,6 +504,8 @@ let iface = builder.finalize(&mut device);
                 sixlowpan_fragments: self
                     .sixlowpan_fragments
                     .expect("Cache for incoming 6LoWPAN fragments is required"),
+                #[cfg(feature = "proto-sixlowpan-fragmentation")]
+                sixlowpan_fragments_cache_timeout: self.sixlowpan_fragments_cache_timeout,
 
                 #[cfg(not(any(
                     feature = "proto-ipv4-fragmentation",
@@ -1574,7 +1587,7 @@ impl<'a> InterfaceInner<'a> {
             Some(payload) => {
                 cfg_if::cfg_if! {
                     if #[cfg(feature = "proto-sixlowpan-fragmentation")] {
-                        self.process_sixlowpan(sockets, &ieee802154_repr, payload, Some(&mut _fragments.sixlowpan_fragments))
+                        self.process_sixlowpan(sockets, &ieee802154_repr, payload, Some((&mut _fragments.sixlowpan_fragments, _fragments.sixlowpan_fragments_cache_timeout)))
                     } else {
                         self.process_sixlowpan(sockets, &ieee802154_repr, payload, None)
                     }
@@ -1590,7 +1603,10 @@ impl<'a> InterfaceInner<'a> {
         sockets: &mut SocketSet,
         ieee802154_repr: &Ieee802154Repr,
         payload: &'payload T,
-        _fragments: Option<&'output mut PacketAssemblerSet<'a, SixlowpanFragKey>>,
+        _fragments: Option<(
+            &'output mut PacketAssemblerSet<'a, SixlowpanFragKey>,
+            Duration,
+        )>,
     ) -> Option<IpPacket<'output>> {
         let payload = match check!(SixlowpanPacket::dispatch(payload)) {
             #[cfg(not(feature = "proto-sixlowpan-fragmentation"))]
@@ -1600,7 +1616,7 @@ impl<'a> InterfaceInner<'a> {
             }
             #[cfg(feature = "proto-sixlowpan-fragmentation")]
             SixlowpanPacket::FragmentHeader => {
-                let fragments = _fragments.unwrap();
+                let (fragments, timeout) = _fragments.unwrap();
 
                 // We have a fragment header, which means we cannot process the 6LoWPAN packet,
                 // unless we have a complete one after processing this fragment.
@@ -1665,7 +1681,7 @@ impl<'a> InterfaceInner<'a> {
                             frag.datagram_size() as usize - uncompressed_header_size
                                 + compressed_header_size
                         ),
-                        self.now + Duration::from_secs(5),
+                        self.now + timeout,
                         -((uncompressed_header_size - compressed_header_size) as isize),
                     ));
                 }