1
- use super :: check;
2
- use super :: icmp_reply_payload_len;
3
- use super :: InterfaceInner ;
4
- use super :: IpPacket ;
5
- use super :: PacketAssemblerSet ;
6
- use super :: SocketSet ;
7
-
8
- #[ cfg( feature = "medium-ethernet" ) ]
9
- use super :: EthernetPacket ;
10
-
11
- #[ cfg( feature = "proto-ipv4-fragmentation" ) ]
12
- use super :: Ipv4OutPacket ;
1
+ use super :: * ;
13
2
14
3
#[ cfg( feature = "socket-dhcpv4" ) ]
15
4
use crate :: socket:: dhcpv4;
@@ -18,16 +7,16 @@ use crate::socket::icmp;
18
7
use crate :: socket:: AnySocket ;
19
8
20
9
use crate :: phy:: { Medium , TxToken } ;
21
- use crate :: time:: { Duration , Instant } ;
10
+ use crate :: time:: Instant ;
22
11
use crate :: wire:: * ;
23
12
24
13
impl InterfaceInner {
25
- pub ( super ) fn process_ipv4 < ' output , ' payload : ' output , T : AsRef < [ u8 ] > + ?Sized > (
14
+ pub ( super ) fn process_ipv4 < ' a , T : AsRef < [ u8 ] > + ?Sized > (
26
15
& mut self ,
27
16
sockets : & mut SocketSet ,
28
- ipv4_packet : & Ipv4Packet < & ' payload T > ,
29
- _fragments : Option < & ' output mut PacketAssemblerSet < Ipv4FragKey > > ,
30
- ) -> Option < IpPacket < ' output > > {
17
+ ipv4_packet : & Ipv4Packet < & ' a T > ,
18
+ frag : & ' a mut FragmentsBuffer ,
19
+ ) -> Option < IpPacket < ' a > > {
31
20
let ipv4_repr = check ! ( Ipv4Repr :: parse( ipv4_packet, & self . caps. checksum) ) ;
32
21
if !self . is_unicast_v4 ( ipv4_repr. src_addr ) {
33
22
// Discard packets with non-unicast source addresses.
@@ -37,14 +26,10 @@ impl InterfaceInner {
37
26
38
27
#[ cfg( feature = "proto-ipv4-fragmentation" ) ]
39
28
let ip_payload = {
40
- const REASSEMBLY_TIMEOUT : Duration = Duration :: from_secs ( 90 ) ;
41
-
42
- let fragments = _fragments. unwrap ( ) ;
43
-
44
29
if ipv4_packet. more_frags ( ) || ipv4_packet. frag_offset ( ) != 0 {
45
- let key = ipv4_packet. get_key ( ) ;
30
+ let key = FragKey :: Ipv4 ( ipv4_packet. get_key ( ) ) ;
46
31
47
- let f = match fragments . get ( & key, self . now + REASSEMBLY_TIMEOUT ) {
32
+ let f = match frag . assembler . get ( & key, self . now + frag . reassembly_timeout ) {
48
33
Ok ( f) => f,
49
34
Err ( _) => {
50
35
net_debug ! ( "No available packet assembler for fragmented packet" ) ;
@@ -345,20 +330,16 @@ impl InterfaceInner {
345
330
}
346
331
347
332
#[ cfg( feature = "proto-ipv4-fragmentation" ) ]
348
- pub ( super ) fn dispatch_ipv4_out_packet < Tx : TxToken > (
349
- & mut self ,
350
- tx_token : Tx ,
351
- pkt : & mut Ipv4OutPacket ,
352
- ) {
333
+ pub ( super ) fn dispatch_ipv4_frag < Tx : TxToken > ( & mut self , tx_token : Tx , frag : & mut Fragmenter ) {
353
334
let caps = self . caps . clone ( ) ;
354
335
355
336
let mtu_max = self . ip_mtu ( ) ;
356
- let ip_len = ( pkt . packet_len - pkt . sent_bytes + pkt . repr . buffer_len ( ) ) . min ( mtu_max) ;
357
- let payload_len = ip_len - pkt . repr . buffer_len ( ) ;
337
+ let ip_len = ( frag . packet_len - frag . sent_bytes + frag . ipv4 . repr . buffer_len ( ) ) . min ( mtu_max) ;
338
+ let payload_len = ip_len - frag . ipv4 . repr . buffer_len ( ) ;
358
339
359
- let more_frags = ( pkt . packet_len - pkt . sent_bytes ) != payload_len;
360
- pkt . repr . payload_len = payload_len;
361
- pkt . sent_bytes += payload_len;
340
+ let more_frags = ( frag . packet_len - frag . sent_bytes ) != payload_len;
341
+ frag . ipv4 . repr . payload_len = payload_len;
342
+ frag . sent_bytes += payload_len;
362
343
363
344
let mut tx_len = ip_len;
364
345
#[ cfg( feature = "medium-ethernet" ) ]
@@ -373,7 +354,7 @@ impl InterfaceInner {
373
354
374
355
let src_addr = self . hardware_addr . unwrap ( ) . ethernet_or_panic ( ) ;
375
356
frame. set_src_addr ( src_addr) ;
376
- frame. set_dst_addr ( pkt . dst_hardware_addr ) ;
357
+ frame. set_dst_addr ( frag . ipv4 . dst_hardware_addr ) ;
377
358
378
359
match repr. version ( ) {
379
360
#[ cfg( feature = "proto-ipv4" ) ]
@@ -386,27 +367,29 @@ impl InterfaceInner {
386
367
tx_token. consume ( tx_len, |mut tx_buffer| {
387
368
#[ cfg( feature = "medium-ethernet" ) ]
388
369
if matches ! ( self . caps. medium, Medium :: Ethernet ) {
389
- emit_ethernet ( & IpRepr :: Ipv4 ( pkt . repr ) , tx_buffer) ;
370
+ emit_ethernet ( & IpRepr :: Ipv4 ( frag . ipv4 . repr ) , tx_buffer) ;
390
371
tx_buffer = & mut tx_buffer[ EthernetFrame :: < & [ u8 ] > :: header_len ( ) ..] ;
391
372
}
392
373
393
- let mut packet = Ipv4Packet :: new_unchecked ( & mut tx_buffer[ ..pkt. repr . buffer_len ( ) ] ) ;
394
- pkt. repr . emit ( & mut packet, & caps. checksum ) ;
395
- packet. set_ident ( pkt. ident ) ;
374
+ let mut packet =
375
+ Ipv4Packet :: new_unchecked ( & mut tx_buffer[ ..frag. ipv4 . repr . buffer_len ( ) ] ) ;
376
+ frag. ipv4 . repr . emit ( & mut packet, & caps. checksum ) ;
377
+ packet. set_ident ( frag. ipv4 . ident ) ;
396
378
packet. set_more_frags ( more_frags) ;
397
379
packet. set_dont_frag ( false ) ;
398
- packet. set_frag_offset ( pkt . frag_offset ) ;
380
+ packet. set_frag_offset ( frag . ipv4 . frag_offset ) ;
399
381
400
382
if caps. checksum . ipv4 . tx ( ) {
401
383
packet. fill_checksum ( ) ;
402
384
}
403
385
404
- tx_buffer[ pkt. repr . buffer_len ( ) ..] [ ..payload_len] . copy_from_slice (
405
- & pkt. buffer [ pkt. frag_offset as usize + pkt. repr . buffer_len ( ) ..] [ ..payload_len] ,
386
+ tx_buffer[ frag. ipv4 . repr . buffer_len ( ) ..] [ ..payload_len] . copy_from_slice (
387
+ & frag. buffer [ frag. ipv4 . frag_offset as usize + frag. ipv4 . repr . buffer_len ( ) ..]
388
+ [ ..payload_len] ,
406
389
) ;
407
390
408
391
// Update the frag offset for the next fragment.
409
- pkt . frag_offset += payload_len as u16 ;
392
+ frag . ipv4 . frag_offset += payload_len as u16 ;
410
393
} )
411
394
}
412
395
0 commit comments