2 IP6 internal functions to process the incoming packets.
4 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 Create an empty assemble entry for the packet identified by
20 (Dst, Src, Id). The default life for the packet is 60 seconds.
22 @param[in] Dst The destination address.
23 @param[in] Src The source address.
24 @param[in] Id The ID field in the IP header.
26 @return NULL if failed to allocate memory for the entry. Otherwise,
27 the pointer to the just created reassemble entry.
31 Ip6CreateAssembleEntry (
32 IN EFI_IPv6_ADDRESS
*Dst
,
33 IN EFI_IPv6_ADDRESS
*Src
,
37 IP6_ASSEMBLE_ENTRY
*Assemble
;
39 Assemble
= AllocatePool (sizeof (IP6_ASSEMBLE_ENTRY
));
40 if (Assemble
== NULL
) {
44 IP6_COPY_ADDRESS (&Assemble
->Dst
, Dst
);
45 IP6_COPY_ADDRESS (&Assemble
->Src
, Src
);
46 InitializeListHead (&Assemble
->Fragments
);
49 Assemble
->Life
= IP6_FRAGMENT_LIFE
+ 1;
51 Assemble
->TotalLen
= 0;
53 Assemble
->Head
= NULL
;
54 Assemble
->Info
= NULL
;
55 Assemble
->Packet
= NULL
;
61 Release all the fragments of a packet, then free the assemble entry.
63 @param[in] Assemble The assemble entry to free.
67 Ip6FreeAssembleEntry (
68 IN IP6_ASSEMBLE_ENTRY
*Assemble
75 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &Assemble
->Fragments
) {
76 Fragment
= NET_LIST_USER_STRUCT (Entry
, NET_BUF
, List
);
78 RemoveEntryList (Entry
);
79 NetbufFree (Fragment
);
82 if (Assemble
->Packet
!= NULL
) {
83 NetbufFree (Assemble
->Packet
);
90 Release all the fragments of the packet. This is the callback for
91 the assembled packet's OnFree. It will free the assemble entry,
92 which in turn frees all the fragments of the packet.
94 @param[in] Arg The assemble entry to free.
103 Ip6FreeAssembleEntry ((IP6_ASSEMBLE_ENTRY
*) Arg
);
107 Trim the packet to fit in [Start, End), and update per the
110 @param[in, out] Packet Packet to trim.
111 @param[in] Start The sequence of the first byte to fit in.
112 @param[in] End One beyond the sequence of last byte to fit in.
117 IN OUT NET_BUF
*Packet
,
125 Info
= IP6_GET_CLIP_INFO (Packet
);
127 ASSERT (Info
->Start
+ Info
->Length
== Info
->End
);
128 ASSERT ((Info
->Start
< End
) && (Start
< Info
->End
));
130 if (Info
->Start
< Start
) {
131 Len
= Start
- Info
->Start
;
133 NetbufTrim (Packet
, (UINT32
) Len
, NET_BUF_HEAD
);
134 Info
->Start
= (UINT32
) Start
;
135 Info
->Length
-= (UINT32
) Len
;
138 if (End
< Info
->End
) {
139 Len
= End
- Info
->End
;
141 NetbufTrim (Packet
, (UINT32
) Len
, NET_BUF_TAIL
);
142 Info
->End
= (UINT32
) End
;
143 Info
->Length
-= (UINT32
) Len
;
148 Reassemble the IP fragments. If all the fragments of the packet
149 have been received, it will wrap the packet in a net buffer then
150 return it to caller. If the packet can't be assembled, NULL is
153 @param[in, out] Table The assemble table used. A new assemble entry will be created
154 if the Packet is from a new chain of fragments.
155 @param[in] Packet The fragment to assemble. It might be freed if the fragment
156 can't be re-assembled.
158 @return NULL if the packet can't be reassembled. The pointer to the just assembled
159 packet if all the fragments of the packet have arrived.
164 IN OUT IP6_ASSEMBLE_TABLE
*Table
,
168 EFI_IP6_HEADER
*Head
;
171 IP6_ASSEMBLE_ENTRY
*Assemble
;
172 IP6_ASSEMBLE_ENTRY
*Entry
;
173 LIST_ENTRY
*ListHead
;
182 UINT16 UnFragmentLen
;
185 Head
= Packet
->Ip
.Ip6
;
186 This
= IP6_GET_CLIP_INFO (Packet
);
188 ASSERT (Head
!= NULL
);
191 // Find the corresponding assemble entry by (Dst, Src, Id)
194 Index
= IP6_ASSEMBLE_HASH (&Head
->DestinationAddress
, &Head
->SourceAddress
, This
->Id
);
196 NET_LIST_FOR_EACH (Cur
, &Table
->Bucket
[Index
]) {
197 Entry
= NET_LIST_USER_STRUCT (Cur
, IP6_ASSEMBLE_ENTRY
, Link
);
199 if (Entry
->Id
== This
->Id
&&
200 EFI_IP6_EQUAL (&Entry
->Src
, &Head
->SourceAddress
) &&
201 EFI_IP6_EQUAL (&Entry
->Dst
, &Head
->DestinationAddress
)
209 // Create a new entry if can not find an existing one, insert it to assemble table
211 if (Assemble
== NULL
) {
212 Assemble
= Ip6CreateAssembleEntry (
213 &Head
->DestinationAddress
,
214 &Head
->SourceAddress
,
218 if (Assemble
== NULL
) {
222 InsertHeadList (&Table
->Bucket
[Index
], &Assemble
->Link
);
226 // Find the point to insert the packet: before the first
227 // fragment with THIS.Start < CUR.Start. the previous one
228 // has PREV.Start <= THIS.Start < CUR.Start.
230 ListHead
= &Assemble
->Fragments
;
232 NET_LIST_FOR_EACH (Cur
, ListHead
) {
233 Fragment
= NET_LIST_USER_STRUCT (Cur
, NET_BUF
, List
);
235 if (This
->Start
< IP6_GET_CLIP_INFO (Fragment
)->Start
) {
241 // Check whether the current fragment overlaps with the previous one.
242 // It holds that: PREV.Start <= THIS.Start < THIS.End. Only need to
243 // check whether THIS.Start < PREV.End for overlap. If two fragments
244 // overlaps, trim the overlapped part off THIS fragment.
246 if ((Prev
= Cur
->BackLink
) != ListHead
) {
247 Fragment
= NET_LIST_USER_STRUCT (Prev
, NET_BUF
, List
);
248 Node
= IP6_GET_CLIP_INFO (Fragment
);
250 if (This
->Start
< Node
->End
) {
251 if (This
->End
<= Node
->End
) {
256 // Trim the previous fragment from tail.
258 Ip6TrimPacket (Fragment
, Node
->Start
, This
->Start
);
263 // Insert the fragment into the packet. The fragment may be removed
264 // from the list by the following checks.
266 NetListInsertBefore (Cur
, &Packet
->List
);
269 // Check the packets after the insert point. It holds that:
270 // THIS.Start <= NODE.Start < NODE.End. The equality holds
271 // if PREV and NEXT are continuous. THIS fragment may fill
272 // several holes. Remove the completely overlapped fragments
274 while (Cur
!= ListHead
) {
275 Fragment
= NET_LIST_USER_STRUCT (Cur
, NET_BUF
, List
);
276 Node
= IP6_GET_CLIP_INFO (Fragment
);
279 // Remove fragments completely overlapped by this fragment
281 if (Node
->End
<= This
->End
) {
282 Cur
= Cur
->ForwardLink
;
284 RemoveEntryList (&Fragment
->List
);
285 Assemble
->CurLen
-= Node
->Length
;
287 NetbufFree (Fragment
);
292 // The conditions are: THIS.Start <= NODE.Start, and THIS.End <
293 // NODE.End. Two fragments overlaps if NODE.Start < THIS.End.
294 // If two fragments start at the same offset, remove THIS fragment
295 // because ((THIS.Start == NODE.Start) && (THIS.End < NODE.End)).
297 if (Node
->Start
< This
->End
) {
298 if (This
->Start
== Node
->Start
) {
299 RemoveEntryList (&Packet
->List
);
303 Ip6TrimPacket (Packet
, This
->Start
, Node
->Start
);
310 // Update the assemble info: increase the current length. If it is
311 // the frist fragment, update the packet's IP head and per packet
312 // info. If it is the last fragment, update the total length.
314 Assemble
->CurLen
+= This
->Length
;
316 if (This
->Start
== 0) {
318 // Once the first fragment is enqueued, it can't be removed
319 // from the fragment list. So, Assemble->Head always point
320 // to valid memory area.
322 if ((Assemble
->Head
!= NULL
) || (Assemble
->Packet
!= NULL
)) {
327 // Backup the first fragment in case the reasembly of that packet fail.
329 Duplicate
= NetbufDuplicate (Packet
, NULL
, sizeof (EFI_IP6_HEADER
));
330 if (Duplicate
== NULL
) {
335 // Revert IP head to network order.
337 DupHead
= NetbufGetByte (Duplicate
, 0, NULL
);
338 ASSERT (DupHead
!= NULL
);
339 Duplicate
->Ip
.Ip6
= Ip6NtohHead ((EFI_IP6_HEADER
*) DupHead
);
340 Assemble
->Packet
= Duplicate
;
343 // Adjust the unfragmentable part in first fragment
345 UnFragmentLen
= (UINT16
) (This
->HeadLen
- sizeof (EFI_IP6_HEADER
));
346 if (UnFragmentLen
== 0) {
348 // There is not any unfragmentable extension header.
350 ASSERT (Head
->NextHeader
== IP6_FRAGMENT
);
351 Head
->NextHeader
= This
->NextHeader
;
353 NextHeader
= NetbufGetByte (
355 This
->FormerNextHeader
+ sizeof (EFI_IP6_HEADER
),
358 if (NextHeader
== NULL
) {
362 *NextHeader
= This
->NextHeader
;
365 Assemble
->Head
= Head
;
366 Assemble
->Info
= IP6_GET_CLIP_INFO (Packet
);
370 // Don't update the length more than once.
372 if ((This
->LastFrag
!= 0) && (Assemble
->TotalLen
== 0)) {
373 Assemble
->TotalLen
= This
->End
;
377 // Deliver the whole packet if all the fragments received.
378 // All fragments received if:
379 // 1. received the last one, so, the totoal length is know
380 // 2. received all the data. If the last fragment on the
381 // queue ends at the total length, all data is received.
383 if ((Assemble
->TotalLen
!= 0) && (Assemble
->CurLen
>= Assemble
->TotalLen
)) {
385 RemoveEntryList (&Assemble
->Link
);
388 // If the packet is properly formated, the last fragment's End
389 // equals to the packet's total length. Otherwise, the packet
390 // is a fake, drop it now.
392 Fragment
= NET_LIST_USER_STRUCT (ListHead
->BackLink
, NET_BUF
, List
);
393 if (IP6_GET_CLIP_INFO (Fragment
)->End
!= (INTN
) Assemble
->TotalLen
) {
394 Ip6FreeAssembleEntry (Assemble
);
398 Fragment
= NET_LIST_HEAD (ListHead
, NET_BUF
, List
);
399 This
= Assemble
->Info
;
402 // This TmpPacket is used to hold the unfragmentable part, i.e.,
403 // the IPv6 header and the unfragmentable extension headers. Be noted that
404 // the Fragment Header is exluded.
406 TmpPacket
= NetbufGetFragment (Fragment
, 0, This
->HeadLen
, 0);
407 ASSERT (TmpPacket
!= NULL
);
409 NET_LIST_FOR_EACH (Cur
, ListHead
) {
411 // Trim off the unfragment part plus the fragment header from all fragments.
413 Fragment
= NET_LIST_USER_STRUCT (Cur
, NET_BUF
, List
);
414 NetbufTrim (Fragment
, This
->HeadLen
+ sizeof (IP6_FRAGMENT_HEADER
), TRUE
);
417 InsertHeadList (ListHead
, &TmpPacket
->List
);
420 // Wrap the packet in a net buffer then deliver it up
422 NewPacket
= NetbufFromBufList (
423 &Assemble
->Fragments
,
430 if (NewPacket
== NULL
) {
431 Ip6FreeAssembleEntry (Assemble
);
435 NewPacket
->Ip
.Ip6
= Assemble
->Head
;
437 CopyMem (IP6_GET_CLIP_INFO (NewPacket
), Assemble
->Info
, sizeof (IP6_CLIP_INFO
));
451 The callback function for the net buffer that wraps the packet processed by
452 IPsec. It releases the wrap packet and also signals IPsec to free the resources.
454 @param[in] Arg The wrap context.
463 IP6_IPSEC_WRAP
*Wrap
;
465 Wrap
= (IP6_IPSEC_WRAP
*) Arg
;
467 if (Wrap
->IpSecRecycleSignal
!= NULL
) {
468 gBS
->SignalEvent (Wrap
->IpSecRecycleSignal
);
471 NetbufFree (Wrap
->Packet
);
479 The work function to locate the IPsec protocol to process the inbound or
480 outbound IP packets. The process routine handles the packet with the following
481 actions: bypass the packet, discard the packet, or protect the packet.
483 @param[in] IpSb The IP6 service instance.
484 @param[in, out] Head The caller-supplied IP6 header.
485 @param[in, out] LastHead The next header field of last IP header.
486 @param[in, out] Netbuf The IP6 packet to be processed by IPsec.
487 @param[in, out] ExtHdrs The caller-supplied options.
488 @param[in, out] ExtHdrsLen The length of the option.
489 @param[in] Direction The directionality in an SPD entry,
490 EfiIPsecInBound, or EfiIPsecOutBound.
491 @param[in] Context The token's wrap.
493 @retval EFI_SUCCESS The IPsec protocol is not available or disabled.
494 @retval EFI_SUCCESS The packet was bypassed, and all buffers remain the same.
495 @retval EFI_SUCCESS The packet was protected.
496 @retval EFI_ACCESS_DENIED The packet was discarded.
497 @retval EFI_OUT_OF_RESOURCES There are not suffcient resources to complete the operation.
498 @retval EFI_BUFFER_TOO_SMALL The number of non-empty blocks is bigger than the
499 number of input data blocks when building a fragment table.
503 Ip6IpSecProcessPacket (
504 IN IP6_SERVICE
*IpSb
,
505 IN OUT EFI_IP6_HEADER
**Head
,
506 IN OUT UINT8
*LastHead
,
507 IN OUT NET_BUF
**Netbuf
,
508 IN OUT UINT8
**ExtHdrs
,
509 IN OUT UINT32
*ExtHdrsLen
,
510 IN EFI_IPSEC_TRAFFIC_DIR Direction
,
514 NET_FRAGMENT
*FragmentTable
;
515 NET_FRAGMENT
*OriginalFragmentTable
;
516 UINT32 FragmentCount
;
517 UINT32 OriginalFragmentCount
;
518 EFI_EVENT RecycleEvent
;
520 IP6_TXTOKEN_WRAP
*TxWrap
;
521 IP6_IPSEC_WRAP
*IpSecWrap
;
523 EFI_IP6_HEADER
*PacketHead
;
525 EFI_IP6_HEADER ZeroHead
;
527 Status
= EFI_SUCCESS
;
531 FragmentTable
= NULL
;
534 TxWrap
= (IP6_TXTOKEN_WRAP
*) Context
;
535 FragmentCount
= Packet
->BlockOpNum
;
536 ZeroMem (&ZeroHead
, sizeof (EFI_IP6_HEADER
));
538 if (mIpSec
== NULL
) {
539 gBS
->LocateProtocol (&gEfiIpSec2ProtocolGuid
, NULL
, (VOID
**) &mIpSec
);
542 // Check whether the ipsec protocol is available.
544 if (mIpSec
== NULL
) {
550 // Check whether the ipsec enable variable is set.
552 if (mIpSec
->DisabledFlag
) {
554 // If IPsec is disabled, restore the original MTU
556 IpSb
->MaxPacketSize
= IpSb
->OldMaxPacketSize
;
560 // If IPsec is enabled, use the MTU which reduce the IPsec header length.
562 IpSb
->MaxPacketSize
= IpSb
->OldMaxPacketSize
- IP6_MAX_IPSEC_HEADLEN
;
567 // Bypass all multicast inbound or outbound traffic.
569 if (IP6_IS_MULTICAST (&(*Head
)->DestinationAddress
) || IP6_IS_MULTICAST (&(*Head
)->SourceAddress
)) {
574 // Rebuild fragment table from netbuf to ease ipsec process.
576 FragmentTable
= AllocateZeroPool (FragmentCount
* sizeof (NET_FRAGMENT
));
578 if (FragmentTable
== NULL
) {
579 Status
= EFI_OUT_OF_RESOURCES
;
583 Status
= NetbufBuildExt (Packet
, FragmentTable
, &FragmentCount
);
584 OriginalFragmentTable
= FragmentTable
;
585 OriginalFragmentCount
= FragmentCount
;
587 if (EFI_ERROR(Status
)) {
588 FreePool (FragmentTable
);
593 // Convert host byte order to network byte order
597 Status
= mIpSec
->ProcessExt (
605 (EFI_IPSEC_FRAGMENT_DATA
**) (&FragmentTable
),
611 // Convert back to host byte order
615 if (EFI_ERROR (Status
)) {
616 FreePool (OriginalFragmentTable
);
620 if (OriginalFragmentCount
== FragmentCount
&& OriginalFragmentTable
== FragmentTable
) {
624 FreePool (FragmentTable
);
628 // Free the FragmentTable which allocated before calling the IPsec.
630 FreePool (OriginalFragmentTable
);
633 if (Direction
== EfiIPsecOutBound
&& TxWrap
!= NULL
) {
634 TxWrap
->IpSecRecycleSignal
= RecycleEvent
;
635 TxWrap
->Packet
= NetbufFromExt (
643 if (TxWrap
->Packet
== NULL
) {
644 TxWrap
->Packet
= *Netbuf
;
645 Status
= EFI_OUT_OF_RESOURCES
;
650 IP6_GET_CLIP_INFO (TxWrap
->Packet
),
651 IP6_GET_CLIP_INFO (Packet
),
652 sizeof (IP6_CLIP_INFO
)
655 NetIpSecNetbufFree(Packet
);
656 *Netbuf
= TxWrap
->Packet
;
660 IpSecWrap
= AllocateZeroPool (sizeof (IP6_IPSEC_WRAP
));
662 if (IpSecWrap
== NULL
) {
663 Status
= EFI_OUT_OF_RESOURCES
;
664 gBS
->SignalEvent (RecycleEvent
);
668 IpSecWrap
->IpSecRecycleSignal
= RecycleEvent
;
669 IpSecWrap
->Packet
= Packet
;
670 Packet
= NetbufFromExt (
679 if (Packet
== NULL
) {
680 Packet
= IpSecWrap
->Packet
;
681 gBS
->SignalEvent (RecycleEvent
);
682 FreePool (IpSecWrap
);
683 Status
= EFI_OUT_OF_RESOURCES
;
687 if (Direction
== EfiIPsecInBound
&& 0 != CompareMem (&ZeroHead
, *Head
, sizeof (EFI_IP6_HEADER
))) {
689 PacketHead
= (EFI_IP6_HEADER
*) NetbufAllocSpace (
691 sizeof (EFI_IP6_HEADER
) + *ExtHdrsLen
,
694 if (PacketHead
== NULL
) {
696 Status
= EFI_OUT_OF_RESOURCES
;
700 CopyMem (PacketHead
, *Head
, sizeof (EFI_IP6_HEADER
));
702 Packet
->Ip
.Ip6
= PacketHead
;
704 if (*ExtHdrs
!= NULL
) {
705 Buf
= (UINT8
*) (PacketHead
+ 1);
706 CopyMem (Buf
, *ExtHdrs
, *ExtHdrsLen
);
709 NetbufTrim (Packet
, sizeof (EFI_IP6_HEADER
) + *ExtHdrsLen
, TRUE
);
711 IP6_GET_CLIP_INFO (Packet
),
712 IP6_GET_CLIP_INFO (IpSecWrap
->Packet
),
713 sizeof (IP6_CLIP_INFO
)
724 Pre-process the IPv6 packet. First validates the IPv6 packet, and
725 then reassembles packet if it is necessary.
727 @param[in] IpSb The IP6 service instance.
728 @param[in, out] Packet The received IP6 packet to be processed.
729 @param[in] Flag The link layer flag for the packet received, such
731 @param[out] Payload The pointer to the payload of the recieved packet.
732 it starts from the first byte of the extension header.
733 @param[out] LastHead The pointer of NextHeader of the last extension
734 header processed by IP6.
735 @param[out] ExtHdrsLen The length of the whole option.
736 @param[out] UnFragmentLen The length of unfragmented length of extension headers.
737 @param[out] Fragmented Indicate whether the packet is fragmented.
738 @param[out] Head The pointer to the EFI_IP6_Header.
740 @retval EFI_SUCCESS The received packet is well format.
741 @retval EFI_INVALID_PARAMETER The received packet is malformed.
745 Ip6PreProcessPacket (
746 IN IP6_SERVICE
*IpSb
,
747 IN OUT NET_BUF
**Packet
,
750 OUT UINT8
**LastHead
,
751 OUT UINT32
*ExtHdrsLen
,
752 OUT UINT32
*UnFragmentLen
,
753 OUT BOOLEAN
*Fragmented
,
754 OUT EFI_IP6_HEADER
**Head
759 UINT32 FormerHeadOffset
;
761 IP6_FRAGMENT_HEADER
*FragmentHead
;
762 UINT16 FragmentOffset
;
764 EFI_IPv6_ADDRESS Loopback
;
769 // Check whether the input packet is a valid packet
771 if ((*Packet
)->TotalSize
< IP6_MIN_HEADLEN
) {
772 return EFI_INVALID_PARAMETER
;
776 // Get header information of the packet.
778 *Head
= (EFI_IP6_HEADER
*) NetbufGetByte (*Packet
, 0, NULL
);
780 return EFI_INVALID_PARAMETER
;
784 // Multicast addresses must not be used as source addresses in IPv6 packets.
786 if (((*Head
)->Version
!= 6) || (IP6_IS_MULTICAST (&(*Head
)->SourceAddress
))) {
787 return EFI_INVALID_PARAMETER
;
791 // A packet with a destination address of loopback ::1/128 or unspecified must be dropped.
793 ZeroMem (&Loopback
, sizeof (EFI_IPv6_ADDRESS
));
794 Loopback
.Addr
[15] = 0x1;
795 if ((CompareMem (&Loopback
, &(*Head
)->DestinationAddress
, sizeof (EFI_IPv6_ADDRESS
)) == 0) ||
796 (NetIp6IsUnspecifiedAddr (&(*Head
)->DestinationAddress
))) {
797 return EFI_INVALID_PARAMETER
;
801 // Convert the IP header to host byte order.
803 (*Packet
)->Ip
.Ip6
= Ip6NtohHead (*Head
);
806 // Get the per packet info.
808 Info
= IP6_GET_CLIP_INFO (*Packet
);
809 Info
->LinkFlag
= Flag
;
812 if (IpSb
->MnpConfigData
.EnablePromiscuousReceive
) {
813 Info
->CastType
= Ip6Promiscuous
;
816 if (Ip6IsOneOfSetAddress (IpSb
, &(*Head
)->DestinationAddress
, NULL
, NULL
)) {
817 Info
->CastType
= Ip6Unicast
;
818 } else if (IP6_IS_MULTICAST (&(*Head
)->DestinationAddress
)) {
819 if (Ip6FindMldEntry (IpSb
, &(*Head
)->DestinationAddress
) != NULL
) {
820 Info
->CastType
= Ip6Multicast
;
825 // Drop the packet that is not delivered to us.
827 if (Info
->CastType
== 0) {
828 return EFI_INVALID_PARAMETER
;
832 PayloadLen
= (*Head
)->PayloadLength
;
835 Info
->Length
= PayloadLen
;
836 Info
->End
= Info
->Start
+ Info
->Length
;
837 Info
->HeadLen
= (UINT16
) sizeof (EFI_IP6_HEADER
);
838 Info
->Status
= EFI_SUCCESS
;
839 Info
->LastFrag
= FALSE
;
841 TotalLen
= (UINT16
) (PayloadLen
+ sizeof (EFI_IP6_HEADER
));
844 // Mnp may deliver frame trailer sequence up, trim it off.
846 if (TotalLen
< (*Packet
)->TotalSize
) {
847 NetbufTrim (*Packet
, (*Packet
)->TotalSize
- TotalLen
, FALSE
);
850 if (TotalLen
!= (*Packet
)->TotalSize
) {
851 return EFI_INVALID_PARAMETER
;
855 // Check the extension headers, if exist validate them
857 if (PayloadLen
!= 0) {
858 *Payload
= AllocatePool ((UINTN
) PayloadLen
);
859 if (*Payload
== NULL
) {
860 return EFI_INVALID_PARAMETER
;
863 NetbufCopy (*Packet
, sizeof (EFI_IP6_HEADER
), PayloadLen
, *Payload
);
866 if (!Ip6IsExtsValid (
869 &(*Head
)->NextHeader
,
879 return EFI_INVALID_PARAMETER
;
882 HeadLen
= sizeof (EFI_IP6_HEADER
) + *UnFragmentLen
;
886 // Get the fragment offset from the Fragment header
888 FragmentHead
= (IP6_FRAGMENT_HEADER
*) NetbufGetByte (*Packet
, HeadLen
, NULL
);
889 if (FragmentHead
== NULL
) {
890 return EFI_INVALID_PARAMETER
;
893 FragmentOffset
= NTOHS (FragmentHead
->FragmentOffset
);
895 if ((FragmentOffset
& 0x1) == 0) {
896 Info
->LastFrag
= TRUE
;
899 FragmentOffset
&= (~0x1);
902 // This is the first fragment of the packet
904 if (FragmentOffset
== 0) {
905 Info
->NextHeader
= FragmentHead
->NextHeader
;
908 Info
->HeadLen
= (UINT16
) HeadLen
;
909 HeadLen
+= sizeof (IP6_FRAGMENT_HEADER
);
910 Info
->Start
= FragmentOffset
;
911 Info
->Length
= TotalLen
- (UINT16
) HeadLen
;
912 Info
->End
= Info
->Start
+ Info
->Length
;
913 Info
->Id
= FragmentHead
->Identification
;
914 Info
->FormerNextHeader
= FormerHeadOffset
;
917 // Fragments should in the unit of 8 octets long except the last one.
919 if ((Info
->LastFrag
== 0) && (Info
->Length
% 8 != 0)) {
920 return EFI_INVALID_PARAMETER
;
924 // Reassemble the packet.
926 *Packet
= Ip6Reassemble (&IpSb
->Assemble
, *Packet
);
927 if (*Packet
== NULL
) {
928 return EFI_INVALID_PARAMETER
;
932 // Re-check the assembled packet to get the right values.
934 *Head
= (*Packet
)->Ip
.Ip6
;
935 PayloadLen
= (*Head
)->PayloadLength
;
936 if (PayloadLen
!= 0) {
937 if (*Payload
!= NULL
) {
941 *Payload
= AllocatePool ((UINTN
) PayloadLen
);
942 if (*Payload
== NULL
) {
943 return EFI_INVALID_PARAMETER
;
946 NetbufCopy (*Packet
, sizeof (EFI_IP6_HEADER
), PayloadLen
, *Payload
);
949 if (!Ip6IsExtsValid (
952 &(*Head
)->NextHeader
,
962 return EFI_INVALID_PARAMETER
;
967 // Trim the head off, after this point, the packet is headless.
968 // and Packet->TotalLen == Info->Length.
970 NetbufTrim (*Packet
, sizeof (EFI_IP6_HEADER
) + *ExtHdrsLen
, TRUE
);
976 The IP6 input routine. It is called by the IP6_INTERFACE when an
977 IP6 fragment is received from MNP.
979 @param[in] Packet The IP6 packet received.
980 @param[in] IoStatus The return status of receive request.
981 @param[in] Flag The link layer flag for the packet received, such
983 @param[in] Context The IP6 service instance that owns the MNP.
989 IN EFI_STATUS IoStatus
,
995 EFI_IP6_HEADER
*Head
;
998 UINT32 UnFragmentLen
;
1002 EFI_IP6_HEADER ZeroHead
;
1004 IpSb
= (IP6_SERVICE
*) Context
;
1005 NET_CHECK_SIGNATURE (IpSb
, IP6_SERVICE_SIGNATURE
);
1011 // Check input parameters
1013 if (EFI_ERROR (IoStatus
) || (IpSb
->State
== IP6_SERVICE_DESTROY
)) {
1018 // Pre-Process the Ipv6 Packet and then reassemble if it is necessary.
1020 Status
= Ip6PreProcessPacket (
1031 if (EFI_ERROR (Status
)) {
1035 // After trim off, the packet is a esp/ah/udp/tcp/icmp6 net buffer,
1036 // and no need consider any other ahead ext headers.
1038 Status
= Ip6IpSecProcessPacket (
1041 LastHead
, // need get the lasthead value for input
1049 if (EFI_ERROR (Status
)) {
1054 // If the packet is protected by IPsec Tunnel Mode, Check the Inner Ip Packet.
1056 ZeroMem (&ZeroHead
, sizeof (EFI_IP6_HEADER
));
1057 if (0 == CompareMem (Head
, &ZeroHead
, sizeof (EFI_IP6_HEADER
))) {
1058 Status
= Ip6PreProcessPacket (
1069 if (EFI_ERROR (Status
)) {
1075 // Check the Packet again.
1077 if (Packet
== NULL
) {
1082 // Packet may have been changed. The ownership of the packet
1083 // is transfered to the packet process logic.
1085 Head
= Packet
->Ip
.Ip6
;
1086 IP6_GET_CLIP_INFO (Packet
)->Status
= EFI_SUCCESS
;
1088 switch (*LastHead
) {
1090 Ip6IcmpHandle (IpSb
, Head
, Packet
);
1093 Ip6Demultiplex (IpSb
, Head
, Packet
);
1099 // Dispatch the DPCs queued by the NotifyFunction of the rx token's events
1100 // which are signaled with received data.
1105 if (Payload
!= NULL
) {
1109 Ip6ReceiveFrame (Ip6AcceptFrame
, IpSb
);
1112 if (Packet
!= NULL
) {
1113 NetbufFree (Packet
);
1120 Initialize an already allocated assemble table. This is generally
1121 the assemble table embedded in the IP6 service instance.
1123 @param[in, out] Table The assemble table to initialize.
1127 Ip6CreateAssembleTable (
1128 IN OUT IP6_ASSEMBLE_TABLE
*Table
1133 for (Index
= 0; Index
< IP6_ASSEMLE_HASH_SIZE
; Index
++) {
1134 InitializeListHead (&Table
->Bucket
[Index
]);
1139 Clean up the assemble table by removing all of the fragments
1140 and assemble entries.
1142 @param[in, out] Table The assemble table to clean up.
1146 Ip6CleanAssembleTable (
1147 IN OUT IP6_ASSEMBLE_TABLE
*Table
1152 IP6_ASSEMBLE_ENTRY
*Assemble
;
1155 for (Index
= 0; Index
< IP6_ASSEMLE_HASH_SIZE
; Index
++) {
1156 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &Table
->Bucket
[Index
]) {
1157 Assemble
= NET_LIST_USER_STRUCT (Entry
, IP6_ASSEMBLE_ENTRY
, Link
);
1159 RemoveEntryList (Entry
);
1160 Ip6FreeAssembleEntry (Assemble
);
1167 The signal handle of IP6's recycle event. It is called back
1168 when the upper layer releases the packet.
1170 @param[in] Event The IP6's recycle event.
1171 @param[in] Context The context of the handle, which is a IP6_RXDATA_WRAP.
1176 Ip6OnRecyclePacket (
1181 IP6_RXDATA_WRAP
*Wrap
;
1183 Wrap
= (IP6_RXDATA_WRAP
*) Context
;
1185 EfiAcquireLockOrFail (&Wrap
->IpInstance
->RecycleLock
);
1186 RemoveEntryList (&Wrap
->Link
);
1187 EfiReleaseLock (&Wrap
->IpInstance
->RecycleLock
);
1189 ASSERT (!NET_BUF_SHARED (Wrap
->Packet
));
1190 NetbufFree (Wrap
->Packet
);
1192 gBS
->CloseEvent (Wrap
->RxData
.RecycleSignal
);
1197 Wrap the received packet to a IP6_RXDATA_WRAP, which will be
1198 delivered to the upper layer. Each IP6 child that accepts the
1199 packet will get a not-shared copy of the packet which is wrapped
1200 in the IP6_RXDATA_WRAP. The IP6_RXDATA_WRAP->RxData is passed
1201 to the upper layer. The upper layer will signal the recycle event in
1202 it when it is done with the packet.
1204 @param[in] IpInstance The IP6 child to receive the packet.
1205 @param[in] Packet The packet to deliver up.
1207 @return NULL if it failed to wrap the packet; otherwise, the wrapper.
1212 IN IP6_PROTOCOL
*IpInstance
,
1216 IP6_RXDATA_WRAP
*Wrap
;
1217 EFI_IP6_RECEIVE_DATA
*RxData
;
1220 Wrap
= AllocatePool (IP6_RXDATA_WRAP_SIZE (Packet
->BlockOpNum
));
1226 InitializeListHead (&Wrap
->Link
);
1228 Wrap
->IpInstance
= IpInstance
;
1229 Wrap
->Packet
= Packet
;
1230 RxData
= &Wrap
->RxData
;
1232 ZeroMem (&RxData
->TimeStamp
, sizeof (EFI_TIME
));
1234 Status
= gBS
->CreateEvent (
1239 &RxData
->RecycleSignal
1242 if (EFI_ERROR (Status
)) {
1247 ASSERT (Packet
->Ip
.Ip6
!= NULL
);
1250 // The application expects a network byte order header.
1252 RxData
->HeaderLength
= sizeof (EFI_IP6_HEADER
);
1253 RxData
->Header
= (EFI_IP6_HEADER
*) Ip6NtohHead (Packet
->Ip
.Ip6
);
1254 RxData
->DataLength
= Packet
->TotalSize
;
1257 // Build the fragment table to be delivered up.
1259 RxData
->FragmentCount
= Packet
->BlockOpNum
;
1260 NetbufBuildExt (Packet
, (NET_FRAGMENT
*) RxData
->FragmentTable
, &RxData
->FragmentCount
);
1266 Check whether this IP child accepts the packet.
1268 @param[in] IpInstance The IP child to check.
1269 @param[in] Head The IP header of the packet.
1270 @param[in] Packet The data of the packet.
1272 @retval TRUE The child wants to receive the packet.
1273 @retval FALSE The child does not want to receive the packet.
1277 Ip6InstanceFrameAcceptable (
1278 IN IP6_PROTOCOL
*IpInstance
,
1279 IN EFI_IP6_HEADER
*Head
,
1283 IP6_ICMP_ERROR_HEAD Icmp
;
1284 EFI_IP6_CONFIG_DATA
*Config
;
1285 IP6_CLIP_INFO
*Info
;
1289 UINT16 ErrMsgPayloadLen
;
1290 UINT8
*ErrMsgPayload
;
1292 Config
= &IpInstance
->ConfigData
;
1296 // Dirty trick for the Tiano UEFI network stack implmentation. If
1297 // ReceiveTimeout == -1, the receive of the packet for this instance
1298 // is disabled. The UEFI spec don't have such captibility. We add
1299 // this to improve the performance because IP will make a copy of
1300 // the received packet for each accepting instance. Some IP instances
1301 // used by UDP/TCP only send packets, they don't wants to receive.
1303 if (Config
->ReceiveTimeout
== (UINT32
)(-1)) {
1307 if (Config
->AcceptPromiscuous
) {
1312 // Check whether the protocol is acceptable.
1314 ExtHdrs
= NetbufGetByte (Packet
, 0, NULL
);
1316 if (!Ip6IsExtsValid (
1317 IpInstance
->Service
,
1321 (UINT32
) Head
->PayloadLength
,
1333 // The upper layer driver may want to receive the ICMPv6 error packet
1334 // invoked by its packet, like UDP.
1336 if ((*Proto
== IP6_ICMP
) && (!Config
->AcceptAnyProtocol
) && (*Proto
!= Config
->DefaultProtocol
)) {
1337 NetbufCopy (Packet
, 0, sizeof (Icmp
), (UINT8
*) &Icmp
);
1339 if (Icmp
.Head
.Type
<= ICMP_V6_ERROR_MAX
) {
1340 if (!Config
->AcceptIcmpErrors
) {
1345 // Get the protocol of the invoking packet of ICMPv6 error packet.
1347 ErrMsgPayloadLen
= NTOHS (Icmp
.IpHead
.PayloadLength
);
1348 ErrMsgPayload
= NetbufGetByte (Packet
, sizeof (Icmp
), NULL
);
1350 if (!Ip6IsExtsValid (
1353 &Icmp
.IpHead
.NextHeader
,
1369 // Match the protocol
1371 if (!Config
->AcceptAnyProtocol
&& (*Proto
!= Config
->DefaultProtocol
)) {
1376 // Check for broadcast, the caller has computed the packet's
1377 // cast type for this child's interface.
1379 Info
= IP6_GET_CLIP_INFO (Packet
);
1382 // If it is a multicast packet, check whether we are in the group.
1384 if (Info
->CastType
== Ip6Multicast
) {
1386 // Receive the multicast if the instance wants to receive all packets.
1388 if (NetIp6IsUnspecifiedAddr (&IpInstance
->ConfigData
.StationAddress
)) {
1392 for (Index
= 0; Index
< IpInstance
->GroupCount
; Index
++) {
1393 if (EFI_IP6_EQUAL (IpInstance
->GroupList
+ Index
, &Head
->DestinationAddress
)) {
1398 return (BOOLEAN
)(Index
< IpInstance
->GroupCount
);
1405 Enqueue a shared copy of the packet to the IP6 child if the
1406 packet is acceptable to it. Here the data of the packet is
1407 shared, but the net buffer isn't.
1409 @param IpInstance The IP6 child to enqueue the packet to.
1410 @param Head The IP header of the received packet.
1411 @param Packet The data of the received packet.
1413 @retval EFI_NOT_STARTED The IP child hasn't been configured.
1414 @retval EFI_INVALID_PARAMETER The child doesn't want to receive the packet.
1415 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources
1416 @retval EFI_SUCCESS A shared copy the packet is enqueued to the child.
1420 Ip6InstanceEnquePacket (
1421 IN IP6_PROTOCOL
*IpInstance
,
1422 IN EFI_IP6_HEADER
*Head
,
1426 IP6_CLIP_INFO
*Info
;
1430 // Check whether the packet is acceptable to this instance.
1432 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
1433 return EFI_NOT_STARTED
;
1436 if (!Ip6InstanceFrameAcceptable (IpInstance
, Head
, Packet
)) {
1437 return EFI_INVALID_PARAMETER
;
1441 // Enque a shared copy of the packet.
1443 Clone
= NetbufClone (Packet
);
1445 if (Clone
== NULL
) {
1446 return EFI_OUT_OF_RESOURCES
;
1450 // Set the receive time out for the assembled packet. If it expires,
1451 // packet will be removed from the queue.
1453 Info
= IP6_GET_CLIP_INFO (Clone
);
1454 Info
->Life
= IP6_US_TO_SEC (IpInstance
->ConfigData
.ReceiveTimeout
);
1456 InsertTailList (&IpInstance
->Received
, &Clone
->List
);
1461 Deliver the received packets to the upper layer if there are both received
1462 requests and enqueued packets. If the enqueued packet is shared, it will
1463 duplicate it to a non-shared packet, release the shared packet, then
1464 deliver the non-shared packet up.
1466 @param[in] IpInstance The IP child to deliver the packet up.
1468 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to deliver the
1470 @retval EFI_SUCCESS All the enqueued packets that can be delivered
1475 Ip6InstanceDeliverPacket (
1476 IN IP6_PROTOCOL
*IpInstance
1479 EFI_IP6_COMPLETION_TOKEN
*Token
;
1480 IP6_RXDATA_WRAP
*Wrap
;
1486 // Deliver a packet if there are both a packet and a receive token.
1488 while (!IsListEmpty (&IpInstance
->Received
) && !NetMapIsEmpty (&IpInstance
->RxTokens
)) {
1490 Packet
= NET_LIST_HEAD (&IpInstance
->Received
, NET_BUF
, List
);
1492 if (!NET_BUF_SHARED (Packet
)) {
1494 // If this is the only instance that wants the packet, wrap it up.
1496 Wrap
= Ip6WrapRxData (IpInstance
, Packet
);
1499 return EFI_OUT_OF_RESOURCES
;
1502 RemoveEntryList (&Packet
->List
);
1506 // Create a duplicated packet if this packet is shared
1508 Dup
= NetbufDuplicate (Packet
, NULL
, sizeof (EFI_IP6_HEADER
));
1511 return EFI_OUT_OF_RESOURCES
;
1515 // Copy the IP head over. The packet to deliver up is
1516 // headless. Trim the head off after copy. The IP head
1517 // may be not continuous before the data.
1519 Head
= NetbufAllocSpace (Dup
, sizeof (EFI_IP6_HEADER
), NET_BUF_HEAD
);
1520 ASSERT (Head
!= NULL
);
1521 Dup
->Ip
.Ip6
= (EFI_IP6_HEADER
*) Head
;
1523 CopyMem (Head
, Packet
->Ip
.Ip6
, sizeof (EFI_IP6_HEADER
));
1524 NetbufTrim (Dup
, sizeof (EFI_IP6_HEADER
), TRUE
);
1526 Wrap
= Ip6WrapRxData (IpInstance
, Dup
);
1530 return EFI_OUT_OF_RESOURCES
;
1533 RemoveEntryList (&Packet
->List
);
1534 NetbufFree (Packet
);
1540 // Insert it into the delivered packet, then get a user's
1541 // receive token, pass the wrapped packet up.
1543 EfiAcquireLockOrFail (&IpInstance
->RecycleLock
);
1544 InsertHeadList (&IpInstance
->Delivered
, &Wrap
->Link
);
1545 EfiReleaseLock (&IpInstance
->RecycleLock
);
1547 Token
= NetMapRemoveHead (&IpInstance
->RxTokens
, NULL
);
1548 Token
->Status
= IP6_GET_CLIP_INFO (Packet
)->Status
;
1549 Token
->Packet
.RxData
= &Wrap
->RxData
;
1551 gBS
->SignalEvent (Token
->Event
);
1558 Enqueue a received packet to all the IP children that share
1561 @param[in] IpSb The IP6 service instance that receive the packet.
1562 @param[in] Head The header of the received packet.
1563 @param[in] Packet The data of the received packet.
1564 @param[in] IpIf The interface to enqueue the packet to.
1566 @return The number of the IP6 children that accepts the packet.
1570 Ip6InterfaceEnquePacket (
1571 IN IP6_SERVICE
*IpSb
,
1572 IN EFI_IP6_HEADER
*Head
,
1574 IN IP6_INTERFACE
*IpIf
1577 IP6_PROTOCOL
*IpInstance
;
1578 IP6_CLIP_INFO
*Info
;
1585 // First, check that the packet is acceptable to this interface
1586 // and find the local cast type for the interface.
1589 Info
= IP6_GET_CLIP_INFO (Packet
);
1591 if (IpIf
->PromiscRecv
) {
1592 LocalType
= Ip6Promiscuous
;
1594 LocalType
= Info
->CastType
;
1598 // Iterate through the ip instances on the interface, enqueue
1599 // the packet if filter passed. Save the original cast type,
1600 // and pass the local cast type to the IP children on the
1601 // interface. The global cast type will be restored later.
1603 SavedType
= Info
->CastType
;
1604 Info
->CastType
= (UINT32
) LocalType
;
1608 NET_LIST_FOR_EACH (Entry
, &IpIf
->IpInstances
) {
1609 IpInstance
= NET_LIST_USER_STRUCT (Entry
, IP6_PROTOCOL
, AddrLink
);
1610 NET_CHECK_SIGNATURE (IpInstance
, IP6_PROTOCOL_SIGNATURE
);
1612 if (Ip6InstanceEnquePacket (IpInstance
, Head
, Packet
) == EFI_SUCCESS
) {
1617 Info
->CastType
= (UINT32
) SavedType
;
1622 Deliver the packet for each IP6 child on the interface.
1624 @param[in] IpSb The IP6 service instance that received the packet.
1625 @param[in] IpIf The IP6 interface to deliver the packet.
1629 Ip6InterfaceDeliverPacket (
1630 IN IP6_SERVICE
*IpSb
,
1631 IN IP6_INTERFACE
*IpIf
1634 IP6_PROTOCOL
*IpInstance
;
1637 NET_LIST_FOR_EACH (Entry
, &IpIf
->IpInstances
) {
1638 IpInstance
= NET_LIST_USER_STRUCT (Entry
, IP6_PROTOCOL
, AddrLink
);
1639 Ip6InstanceDeliverPacket (IpInstance
);
1644 De-multiplex the packet. the packet delivery is processed in two
1645 passes. The first pass will enqueue a shared copy of the packet
1646 to each IP6 child that accepts the packet. The second pass will
1647 deliver a non-shared copy of the packet to each IP6 child that
1648 has pending receive requests. Data is copied if more than one
1649 child wants to consume the packet, because each IP child needs
1650 its own copy of the packet to make changes.
1652 @param[in] IpSb The IP6 service instance that received the packet.
1653 @param[in] Head The header of the received packet.
1654 @param[in] Packet The data of the received packet.
1656 @retval EFI_NOT_FOUND No IP child accepts the packet.
1657 @retval EFI_SUCCESS The packet is enqueued or delivered to some IP
1663 IN IP6_SERVICE
*IpSb
,
1664 IN EFI_IP6_HEADER
*Head
,
1670 IP6_INTERFACE
*IpIf
;
1674 // Two pass delivery: first, enque a shared copy of the packet
1675 // to each instance that accept the packet.
1679 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
1680 IpIf
= NET_LIST_USER_STRUCT (Entry
, IP6_INTERFACE
, Link
);
1682 if (IpIf
->Configured
) {
1683 Enqueued
+= Ip6InterfaceEnquePacket (IpSb
, Head
, Packet
, IpIf
);
1688 // Second: deliver a duplicate of the packet to each instance.
1689 // Release the local reference first, so that the last instance
1690 // getting the packet will not copy the data.
1692 NetbufFree (Packet
);
1695 if (Enqueued
== 0) {
1696 return EFI_NOT_FOUND
;
1699 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
1700 IpIf
= NET_LIST_USER_STRUCT (Entry
, IP6_INTERFACE
, Link
);
1702 if (IpIf
->Configured
) {
1703 Ip6InterfaceDeliverPacket (IpSb
, IpIf
);
1711 Decrease the life of the transmitted packets. If it is
1712 decreased to zero, cancel the packet. This function is
1713 called by Ip6packetTimerTicking that provides timeout for both the
1714 received-but-not-delivered and transmitted-but-not-recycle
1717 @param[in] Map The IP6 child's transmit map.
1718 @param[in] Item Current transmitted packet.
1719 @param[in] Context Not used.
1721 @retval EFI_SUCCESS Always returns EFI_SUCCESS.
1726 Ip6SentPacketTicking (
1728 IN NET_MAP_ITEM
*Item
,
1732 IP6_TXTOKEN_WRAP
*Wrap
;
1734 Wrap
= (IP6_TXTOKEN_WRAP
*) Item
->Value
;
1735 ASSERT (Wrap
!= NULL
);
1737 if ((Wrap
->Life
> 0) && (--Wrap
->Life
== 0)) {
1738 Ip6CancelPacket (Wrap
->IpInstance
->Interface
, Wrap
->Packet
, EFI_ABORTED
);
1745 Timeout the fragments, and the enqueued, and transmitted packets.
1747 @param[in] IpSb The IP6 service instance to timeout.
1751 Ip6PacketTimerTicking (
1752 IN IP6_SERVICE
*IpSb
1755 LIST_ENTRY
*InstanceEntry
;
1758 IP6_PROTOCOL
*IpInstance
;
1759 IP6_ASSEMBLE_ENTRY
*Assemble
;
1761 IP6_CLIP_INFO
*Info
;
1765 // First, time out the fragments. The packet's life is counting down
1766 // once the first-arriving fragment of that packet was received.
1768 for (Index
= 0; Index
< IP6_ASSEMLE_HASH_SIZE
; Index
++) {
1769 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &(IpSb
->Assemble
.Bucket
[Index
])) {
1770 Assemble
= NET_LIST_USER_STRUCT (Entry
, IP6_ASSEMBLE_ENTRY
, Link
);
1772 if ((Assemble
->Life
> 0) && (--Assemble
->Life
== 0)) {
1774 // If the first fragment (the one with a Fragment Offset of zero)
1775 // has been received, an ICMP Time Exceeded - Fragment Reassembly
1776 // Time Exceeded message should be sent to the source of that fragment.
1778 if ((Assemble
->Packet
!= NULL
) &&
1779 !IP6_IS_MULTICAST (&Assemble
->Head
->DestinationAddress
)) {
1784 &Assemble
->Head
->SourceAddress
,
1785 ICMP_V6_TIME_EXCEEDED
,
1786 ICMP_V6_TIMEOUT_REASSEMBLE
,
1792 // If reassembly of a packet is not completed within 60 seconds of
1793 // the reception of the first-arriving fragment of that packet, the
1794 // reassembly must be abandoned and all the fragments that have been
1795 // received for that packet must be discarded.
1797 RemoveEntryList (Entry
);
1798 Ip6FreeAssembleEntry (Assemble
);
1803 NET_LIST_FOR_EACH (InstanceEntry
, &IpSb
->Children
) {
1804 IpInstance
= NET_LIST_USER_STRUCT (InstanceEntry
, IP6_PROTOCOL
, Link
);
1807 // Second, time out the assembled packets enqueued on each IP child.
1809 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &IpInstance
->Received
) {
1810 Packet
= NET_LIST_USER_STRUCT (Entry
, NET_BUF
, List
);
1811 Info
= IP6_GET_CLIP_INFO (Packet
);
1813 if ((Info
->Life
> 0) && (--Info
->Life
== 0)) {
1814 RemoveEntryList (Entry
);
1815 NetbufFree (Packet
);
1820 // Third: time out the transmitted packets.
1822 NetMapIterate (&IpInstance
->TxTokens
, Ip6SentPacketTicking
, NULL
);