2 IP6 internal functions to process the incoming packets.
4 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
14 Create an empty assemble entry for the packet identified by
15 (Dst, Src, Id). The default life for the packet is 60 seconds.
17 @param[in] Dst The destination address.
18 @param[in] Src The source address.
19 @param[in] Id The ID field in the IP header.
21 @return NULL if failed to allocate memory for the entry. Otherwise,
22 the pointer to the just created reassemble entry.
26 Ip6CreateAssembleEntry (
27 IN EFI_IPv6_ADDRESS
*Dst
,
28 IN EFI_IPv6_ADDRESS
*Src
,
32 IP6_ASSEMBLE_ENTRY
*Assemble
;
34 Assemble
= AllocatePool (sizeof (IP6_ASSEMBLE_ENTRY
));
35 if (Assemble
== NULL
) {
39 IP6_COPY_ADDRESS (&Assemble
->Dst
, Dst
);
40 IP6_COPY_ADDRESS (&Assemble
->Src
, Src
);
41 InitializeListHead (&Assemble
->Fragments
);
44 Assemble
->Life
= IP6_FRAGMENT_LIFE
+ 1;
46 Assemble
->TotalLen
= 0;
48 Assemble
->Head
= NULL
;
49 Assemble
->Info
= NULL
;
50 Assemble
->Packet
= NULL
;
56 Release all the fragments of a packet, then free the assemble entry.
58 @param[in] Assemble The assemble entry to free.
62 Ip6FreeAssembleEntry (
63 IN IP6_ASSEMBLE_ENTRY
*Assemble
70 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &Assemble
->Fragments
) {
71 Fragment
= NET_LIST_USER_STRUCT (Entry
, NET_BUF
, List
);
73 RemoveEntryList (Entry
);
74 NetbufFree (Fragment
);
77 if (Assemble
->Packet
!= NULL
) {
78 NetbufFree (Assemble
->Packet
);
85 Release all the fragments of the packet. This is the callback for
86 the assembled packet's OnFree. It will free the assemble entry,
87 which in turn frees all the fragments of the packet.
89 @param[in] Arg The assemble entry to free.
98 Ip6FreeAssembleEntry ((IP6_ASSEMBLE_ENTRY
*) Arg
);
102 Trim the packet to fit in [Start, End), and update per the
105 @param[in, out] Packet Packet to trim.
106 @param[in] Start The sequence of the first byte to fit in.
107 @param[in] End One beyond the sequence of last byte to fit in.
112 IN OUT NET_BUF
*Packet
,
120 Info
= IP6_GET_CLIP_INFO (Packet
);
122 ASSERT (Info
->Start
+ Info
->Length
== Info
->End
);
123 ASSERT ((Info
->Start
< End
) && (Start
< Info
->End
));
125 if (Info
->Start
< Start
) {
126 Len
= Start
- Info
->Start
;
128 NetbufTrim (Packet
, (UINT32
) Len
, NET_BUF_HEAD
);
129 Info
->Start
= (UINT32
) Start
;
130 Info
->Length
-= (UINT32
) Len
;
133 if (End
< Info
->End
) {
134 Len
= End
- Info
->End
;
136 NetbufTrim (Packet
, (UINT32
) Len
, NET_BUF_TAIL
);
137 Info
->End
= (UINT32
) End
;
138 Info
->Length
-= (UINT32
) Len
;
143 Reassemble the IP fragments. If all the fragments of the packet
144 have been received, it will wrap the packet in a net buffer then
145 return it to caller. If the packet can't be assembled, NULL is
148 @param[in, out] Table The assemble table used. A new assemble entry will be created
149 if the Packet is from a new chain of fragments.
150 @param[in] Packet The fragment to assemble. It might be freed if the fragment
151 can't be re-assembled.
153 @return NULL if the packet can't be reassembled. The pointer to the just assembled
154 packet if all the fragments of the packet have arrived.
159 IN OUT IP6_ASSEMBLE_TABLE
*Table
,
163 EFI_IP6_HEADER
*Head
;
166 IP6_ASSEMBLE_ENTRY
*Assemble
;
167 IP6_ASSEMBLE_ENTRY
*Entry
;
168 LIST_ENTRY
*ListHead
;
177 UINT16 UnFragmentLen
;
180 Head
= Packet
->Ip
.Ip6
;
181 This
= IP6_GET_CLIP_INFO (Packet
);
183 ASSERT (Head
!= NULL
);
186 // Find the corresponding assemble entry by (Dst, Src, Id)
189 Index
= IP6_ASSEMBLE_HASH (&Head
->DestinationAddress
, &Head
->SourceAddress
, This
->Id
);
191 NET_LIST_FOR_EACH (Cur
, &Table
->Bucket
[Index
]) {
192 Entry
= NET_LIST_USER_STRUCT (Cur
, IP6_ASSEMBLE_ENTRY
, Link
);
194 if (Entry
->Id
== This
->Id
&&
195 EFI_IP6_EQUAL (&Entry
->Src
, &Head
->SourceAddress
) &&
196 EFI_IP6_EQUAL (&Entry
->Dst
, &Head
->DestinationAddress
)
204 // Create a new entry if can not find an existing one, insert it to assemble table
206 if (Assemble
== NULL
) {
207 Assemble
= Ip6CreateAssembleEntry (
208 &Head
->DestinationAddress
,
209 &Head
->SourceAddress
,
213 if (Assemble
== NULL
) {
217 InsertHeadList (&Table
->Bucket
[Index
], &Assemble
->Link
);
221 // Find the point to insert the packet: before the first
222 // fragment with THIS.Start < CUR.Start. the previous one
223 // has PREV.Start <= THIS.Start < CUR.Start.
225 ListHead
= &Assemble
->Fragments
;
227 NET_LIST_FOR_EACH (Cur
, ListHead
) {
228 Fragment
= NET_LIST_USER_STRUCT (Cur
, NET_BUF
, List
);
230 if (This
->Start
< IP6_GET_CLIP_INFO (Fragment
)->Start
) {
236 // Check whether the current fragment overlaps with the previous one.
237 // It holds that: PREV.Start <= THIS.Start < THIS.End. Only need to
238 // check whether THIS.Start < PREV.End for overlap. If two fragments
239 // overlaps, trim the overlapped part off THIS fragment.
241 if ((Prev
= Cur
->BackLink
) != ListHead
) {
242 Fragment
= NET_LIST_USER_STRUCT (Prev
, NET_BUF
, List
);
243 Node
= IP6_GET_CLIP_INFO (Fragment
);
245 if (This
->Start
< Node
->End
) {
246 if (This
->End
<= Node
->End
) {
251 // Trim the previous fragment from tail.
253 Ip6TrimPacket (Fragment
, Node
->Start
, This
->Start
);
258 // Insert the fragment into the packet. The fragment may be removed
259 // from the list by the following checks.
261 NetListInsertBefore (Cur
, &Packet
->List
);
264 // Check the packets after the insert point. It holds that:
265 // THIS.Start <= NODE.Start < NODE.End. The equality holds
266 // if PREV and NEXT are continuous. THIS fragment may fill
267 // several holes. Remove the completely overlapped fragments
269 while (Cur
!= ListHead
) {
270 Fragment
= NET_LIST_USER_STRUCT (Cur
, NET_BUF
, List
);
271 Node
= IP6_GET_CLIP_INFO (Fragment
);
274 // Remove fragments completely overlapped by this fragment
276 if (Node
->End
<= This
->End
) {
277 Cur
= Cur
->ForwardLink
;
279 RemoveEntryList (&Fragment
->List
);
280 Assemble
->CurLen
-= Node
->Length
;
282 NetbufFree (Fragment
);
287 // The conditions are: THIS.Start <= NODE.Start, and THIS.End <
288 // NODE.End. Two fragments overlaps if NODE.Start < THIS.End.
289 // If two fragments start at the same offset, remove THIS fragment
290 // because ((THIS.Start == NODE.Start) && (THIS.End < NODE.End)).
292 if (Node
->Start
< This
->End
) {
293 if (This
->Start
== Node
->Start
) {
294 RemoveEntryList (&Packet
->List
);
298 Ip6TrimPacket (Packet
, This
->Start
, Node
->Start
);
305 // Update the assemble info: increase the current length. If it is
306 // the frist fragment, update the packet's IP head and per packet
307 // info. If it is the last fragment, update the total length.
309 Assemble
->CurLen
+= This
->Length
;
311 if (This
->Start
== 0) {
313 // Once the first fragment is enqueued, it can't be removed
314 // from the fragment list. So, Assemble->Head always point
315 // to valid memory area.
317 if ((Assemble
->Head
!= NULL
) || (Assemble
->Packet
!= NULL
)) {
322 // Backup the first fragment in case the reassembly of that packet fail.
324 Duplicate
= NetbufDuplicate (Packet
, NULL
, sizeof (EFI_IP6_HEADER
));
325 if (Duplicate
== NULL
) {
330 // Revert IP head to network order.
332 DupHead
= NetbufGetByte (Duplicate
, 0, NULL
);
333 ASSERT (DupHead
!= NULL
);
334 Duplicate
->Ip
.Ip6
= Ip6NtohHead ((EFI_IP6_HEADER
*) DupHead
);
335 Assemble
->Packet
= Duplicate
;
338 // Adjust the unfragmentable part in first fragment
340 UnFragmentLen
= (UINT16
) (This
->HeadLen
- sizeof (EFI_IP6_HEADER
));
341 if (UnFragmentLen
== 0) {
343 // There is not any unfragmentable extension header.
345 ASSERT (Head
->NextHeader
== IP6_FRAGMENT
);
346 Head
->NextHeader
= This
->NextHeader
;
348 NextHeader
= NetbufGetByte (
350 This
->FormerNextHeader
+ sizeof (EFI_IP6_HEADER
),
353 if (NextHeader
== NULL
) {
357 *NextHeader
= This
->NextHeader
;
360 Assemble
->Head
= Head
;
361 Assemble
->Info
= IP6_GET_CLIP_INFO (Packet
);
365 // Don't update the length more than once.
367 if ((This
->LastFrag
!= 0) && (Assemble
->TotalLen
== 0)) {
368 Assemble
->TotalLen
= This
->End
;
372 // Deliver the whole packet if all the fragments received.
373 // All fragments received if:
374 // 1. received the last one, so, the total length is known
375 // 2. received all the data. If the last fragment on the
376 // queue ends at the total length, all data is received.
378 if ((Assemble
->TotalLen
!= 0) && (Assemble
->CurLen
>= Assemble
->TotalLen
)) {
380 RemoveEntryList (&Assemble
->Link
);
383 // If the packet is properly formatted, the last fragment's End
384 // equals to the packet's total length. Otherwise, the packet
385 // is a fake, drop it now.
387 Fragment
= NET_LIST_USER_STRUCT (ListHead
->BackLink
, NET_BUF
, List
);
388 if (IP6_GET_CLIP_INFO (Fragment
)->End
!= (INTN
) Assemble
->TotalLen
) {
389 Ip6FreeAssembleEntry (Assemble
);
393 Fragment
= NET_LIST_HEAD (ListHead
, NET_BUF
, List
);
394 This
= Assemble
->Info
;
397 // This TmpPacket is used to hold the unfragmentable part, i.e.,
398 // the IPv6 header and the unfragmentable extension headers. Be noted that
399 // the Fragment Header is excluded.
401 TmpPacket
= NetbufGetFragment (Fragment
, 0, This
->HeadLen
, 0);
402 ASSERT (TmpPacket
!= NULL
);
404 NET_LIST_FOR_EACH (Cur
, ListHead
) {
406 // Trim off the unfragment part plus the fragment header from all fragments.
408 Fragment
= NET_LIST_USER_STRUCT (Cur
, NET_BUF
, List
);
409 NetbufTrim (Fragment
, This
->HeadLen
+ sizeof (IP6_FRAGMENT_HEADER
), TRUE
);
412 InsertHeadList (ListHead
, &TmpPacket
->List
);
415 // Wrap the packet in a net buffer then deliver it up
417 NewPacket
= NetbufFromBufList (
418 &Assemble
->Fragments
,
425 if (NewPacket
== NULL
) {
426 Ip6FreeAssembleEntry (Assemble
);
430 NewPacket
->Ip
.Ip6
= Assemble
->Head
;
432 CopyMem (IP6_GET_CLIP_INFO (NewPacket
), Assemble
->Info
, sizeof (IP6_CLIP_INFO
));
446 The callback function for the net buffer that wraps the packet processed by
447 IPsec. It releases the wrap packet and also signals IPsec to free the resources.
449 @param[in] Arg The wrap context.
458 IP6_IPSEC_WRAP
*Wrap
;
460 Wrap
= (IP6_IPSEC_WRAP
*) Arg
;
462 if (Wrap
->IpSecRecycleSignal
!= NULL
) {
463 gBS
->SignalEvent (Wrap
->IpSecRecycleSignal
);
466 NetbufFree (Wrap
->Packet
);
474 The work function to locate the IPsec protocol to process the inbound or
475 outbound IP packets. The process routine handles the packet with the following
476 actions: bypass the packet, discard the packet, or protect the packet.
478 @param[in] IpSb The IP6 service instance.
479 @param[in, out] Head The caller-supplied IP6 header.
480 @param[in, out] LastHead The next header field of last IP header.
481 @param[in, out] Netbuf The IP6 packet to be processed by IPsec.
482 @param[in, out] ExtHdrs The caller-supplied options.
483 @param[in, out] ExtHdrsLen The length of the option.
484 @param[in] Direction The directionality in an SPD entry,
485 EfiIPsecInBound, or EfiIPsecOutBound.
486 @param[in] Context The token's wrap.
488 @retval EFI_SUCCESS The IPsec protocol is not available or disabled.
489 @retval EFI_SUCCESS The packet was bypassed, and all buffers remain the same.
490 @retval EFI_SUCCESS The packet was protected.
491 @retval EFI_ACCESS_DENIED The packet was discarded.
492 @retval EFI_OUT_OF_RESOURCES There are not sufficient resources to complete the operation.
493 @retval EFI_BUFFER_TOO_SMALL The number of non-empty blocks is bigger than the
494 number of input data blocks when building a fragment table.
498 Ip6IpSecProcessPacket (
499 IN IP6_SERVICE
*IpSb
,
500 IN OUT EFI_IP6_HEADER
**Head
,
501 IN OUT UINT8
*LastHead
,
502 IN OUT NET_BUF
**Netbuf
,
503 IN OUT UINT8
**ExtHdrs
,
504 IN OUT UINT32
*ExtHdrsLen
,
505 IN EFI_IPSEC_TRAFFIC_DIR Direction
,
509 NET_FRAGMENT
*FragmentTable
;
510 NET_FRAGMENT
*OriginalFragmentTable
;
511 UINT32 FragmentCount
;
512 UINT32 OriginalFragmentCount
;
513 EFI_EVENT RecycleEvent
;
515 IP6_TXTOKEN_WRAP
*TxWrap
;
516 IP6_IPSEC_WRAP
*IpSecWrap
;
518 EFI_IP6_HEADER
*PacketHead
;
520 EFI_IP6_HEADER ZeroHead
;
522 Status
= EFI_SUCCESS
;
524 if (!mIpSec2Installed
) {
527 ASSERT (mIpSec
!= NULL
);
532 FragmentTable
= NULL
;
535 TxWrap
= (IP6_TXTOKEN_WRAP
*) Context
;
536 FragmentCount
= Packet
->BlockOpNum
;
537 ZeroMem (&ZeroHead
, sizeof (EFI_IP6_HEADER
));
540 // Check whether the ipsec enable variable is set.
542 if (mIpSec
->DisabledFlag
) {
544 // If IPsec is disabled, restore the original MTU
546 IpSb
->MaxPacketSize
= IpSb
->OldMaxPacketSize
;
550 // If IPsec is enabled, use the MTU which reduce the IPsec header length.
552 IpSb
->MaxPacketSize
= IpSb
->OldMaxPacketSize
- IP6_MAX_IPSEC_HEADLEN
;
557 // Bypass all multicast inbound or outbound traffic.
559 if (IP6_IS_MULTICAST (&(*Head
)->DestinationAddress
) || IP6_IS_MULTICAST (&(*Head
)->SourceAddress
)) {
564 // Rebuild fragment table from netbuf to ease ipsec process.
566 FragmentTable
= AllocateZeroPool (FragmentCount
* sizeof (NET_FRAGMENT
));
568 if (FragmentTable
== NULL
) {
569 Status
= EFI_OUT_OF_RESOURCES
;
573 Status
= NetbufBuildExt (Packet
, FragmentTable
, &FragmentCount
);
574 OriginalFragmentTable
= FragmentTable
;
575 OriginalFragmentCount
= FragmentCount
;
577 if (EFI_ERROR(Status
)) {
578 FreePool (FragmentTable
);
583 // Convert host byte order to network byte order
587 Status
= mIpSec
->ProcessExt (
595 (EFI_IPSEC_FRAGMENT_DATA
**) (&FragmentTable
),
601 // Convert back to host byte order
605 if (EFI_ERROR (Status
)) {
606 FreePool (OriginalFragmentTable
);
610 if (OriginalFragmentCount
== FragmentCount
&& OriginalFragmentTable
== FragmentTable
) {
614 FreePool (FragmentTable
);
618 // Free the FragmentTable which allocated before calling the IPsec.
620 FreePool (OriginalFragmentTable
);
623 if (Direction
== EfiIPsecOutBound
&& TxWrap
!= NULL
) {
624 TxWrap
->IpSecRecycleSignal
= RecycleEvent
;
625 TxWrap
->Packet
= NetbufFromExt (
633 if (TxWrap
->Packet
== NULL
) {
634 TxWrap
->Packet
= *Netbuf
;
635 Status
= EFI_OUT_OF_RESOURCES
;
640 IP6_GET_CLIP_INFO (TxWrap
->Packet
),
641 IP6_GET_CLIP_INFO (Packet
),
642 sizeof (IP6_CLIP_INFO
)
645 NetIpSecNetbufFree(Packet
);
646 *Netbuf
= TxWrap
->Packet
;
650 IpSecWrap
= AllocateZeroPool (sizeof (IP6_IPSEC_WRAP
));
652 if (IpSecWrap
== NULL
) {
653 Status
= EFI_OUT_OF_RESOURCES
;
654 gBS
->SignalEvent (RecycleEvent
);
658 IpSecWrap
->IpSecRecycleSignal
= RecycleEvent
;
659 IpSecWrap
->Packet
= Packet
;
660 Packet
= NetbufFromExt (
669 if (Packet
== NULL
) {
670 Packet
= IpSecWrap
->Packet
;
671 gBS
->SignalEvent (RecycleEvent
);
672 FreePool (IpSecWrap
);
673 Status
= EFI_OUT_OF_RESOURCES
;
677 if (Direction
== EfiIPsecInBound
&& 0 != CompareMem (&ZeroHead
, *Head
, sizeof (EFI_IP6_HEADER
))) {
679 PacketHead
= (EFI_IP6_HEADER
*) NetbufAllocSpace (
681 sizeof (EFI_IP6_HEADER
) + *ExtHdrsLen
,
684 if (PacketHead
== NULL
) {
686 Status
= EFI_OUT_OF_RESOURCES
;
690 CopyMem (PacketHead
, *Head
, sizeof (EFI_IP6_HEADER
));
692 Packet
->Ip
.Ip6
= PacketHead
;
694 if (*ExtHdrs
!= NULL
) {
695 Buf
= (UINT8
*) (PacketHead
+ 1);
696 CopyMem (Buf
, *ExtHdrs
, *ExtHdrsLen
);
699 NetbufTrim (Packet
, sizeof (EFI_IP6_HEADER
) + *ExtHdrsLen
, TRUE
);
701 IP6_GET_CLIP_INFO (Packet
),
702 IP6_GET_CLIP_INFO (IpSecWrap
->Packet
),
703 sizeof (IP6_CLIP_INFO
)
714 Pre-process the IPv6 packet. First validates the IPv6 packet, and
715 then reassembles packet if it is necessary.
717 @param[in] IpSb The IP6 service instance.
718 @param[in, out] Packet The received IP6 packet to be processed.
719 @param[in] Flag The link layer flag for the packet received, such
721 @param[out] Payload The pointer to the payload of the received packet.
722 it starts from the first byte of the extension header.
723 @param[out] LastHead The pointer of NextHeader of the last extension
724 header processed by IP6.
725 @param[out] ExtHdrsLen The length of the whole option.
726 @param[out] UnFragmentLen The length of unfragmented length of extension headers.
727 @param[out] Fragmented Indicate whether the packet is fragmented.
728 @param[out] Head The pointer to the EFI_IP6_Header.
730 @retval EFI_SUCCESS The received packet is well format.
731 @retval EFI_INVALID_PARAMETER The received packet is malformed.
735 Ip6PreProcessPacket (
736 IN IP6_SERVICE
*IpSb
,
737 IN OUT NET_BUF
**Packet
,
740 OUT UINT8
**LastHead
,
741 OUT UINT32
*ExtHdrsLen
,
742 OUT UINT32
*UnFragmentLen
,
743 OUT BOOLEAN
*Fragmented
,
744 OUT EFI_IP6_HEADER
**Head
749 UINT32 FormerHeadOffset
;
751 IP6_FRAGMENT_HEADER
*FragmentHead
;
752 UINT16 FragmentOffset
;
754 EFI_IPv6_ADDRESS Loopback
;
759 // Check whether the input packet is a valid packet
761 if ((*Packet
)->TotalSize
< IP6_MIN_HEADLEN
) {
762 return EFI_INVALID_PARAMETER
;
766 // Get header information of the packet.
768 *Head
= (EFI_IP6_HEADER
*) NetbufGetByte (*Packet
, 0, NULL
);
770 return EFI_INVALID_PARAMETER
;
774 // Multicast addresses must not be used as source addresses in IPv6 packets.
776 if (((*Head
)->Version
!= 6) || (IP6_IS_MULTICAST (&(*Head
)->SourceAddress
))) {
777 return EFI_INVALID_PARAMETER
;
781 // A packet with a destination address of loopback ::1/128 or unspecified must be dropped.
783 ZeroMem (&Loopback
, sizeof (EFI_IPv6_ADDRESS
));
784 Loopback
.Addr
[15] = 0x1;
785 if ((CompareMem (&Loopback
, &(*Head
)->DestinationAddress
, sizeof (EFI_IPv6_ADDRESS
)) == 0) ||
786 (NetIp6IsUnspecifiedAddr (&(*Head
)->DestinationAddress
))) {
787 return EFI_INVALID_PARAMETER
;
791 // Convert the IP header to host byte order.
793 (*Packet
)->Ip
.Ip6
= Ip6NtohHead (*Head
);
796 // Get the per packet info.
798 Info
= IP6_GET_CLIP_INFO (*Packet
);
799 Info
->LinkFlag
= Flag
;
802 if (IpSb
->MnpConfigData
.EnablePromiscuousReceive
) {
803 Info
->CastType
= Ip6Promiscuous
;
806 if (Ip6IsOneOfSetAddress (IpSb
, &(*Head
)->DestinationAddress
, NULL
, NULL
)) {
807 Info
->CastType
= Ip6Unicast
;
808 } else if (IP6_IS_MULTICAST (&(*Head
)->DestinationAddress
)) {
809 if (Ip6FindMldEntry (IpSb
, &(*Head
)->DestinationAddress
) != NULL
) {
810 Info
->CastType
= Ip6Multicast
;
815 // Drop the packet that is not delivered to us.
817 if (Info
->CastType
== 0) {
818 return EFI_INVALID_PARAMETER
;
822 PayloadLen
= (*Head
)->PayloadLength
;
825 Info
->Length
= PayloadLen
;
826 Info
->End
= Info
->Start
+ Info
->Length
;
827 Info
->HeadLen
= (UINT16
) sizeof (EFI_IP6_HEADER
);
828 Info
->Status
= EFI_SUCCESS
;
829 Info
->LastFrag
= FALSE
;
831 TotalLen
= (UINT16
) (PayloadLen
+ sizeof (EFI_IP6_HEADER
));
834 // Mnp may deliver frame trailer sequence up, trim it off.
836 if (TotalLen
< (*Packet
)->TotalSize
) {
837 NetbufTrim (*Packet
, (*Packet
)->TotalSize
- TotalLen
, FALSE
);
840 if (TotalLen
!= (*Packet
)->TotalSize
) {
841 return EFI_INVALID_PARAMETER
;
845 // Check the extension headers, if exist validate them
847 if (PayloadLen
!= 0) {
848 *Payload
= AllocatePool ((UINTN
) PayloadLen
);
849 if (*Payload
== NULL
) {
850 return EFI_INVALID_PARAMETER
;
853 NetbufCopy (*Packet
, sizeof (EFI_IP6_HEADER
), PayloadLen
, *Payload
);
856 if (!Ip6IsExtsValid (
859 &(*Head
)->NextHeader
,
869 return EFI_INVALID_PARAMETER
;
872 HeadLen
= sizeof (EFI_IP6_HEADER
) + *UnFragmentLen
;
876 // Get the fragment offset from the Fragment header
878 FragmentHead
= (IP6_FRAGMENT_HEADER
*) NetbufGetByte (*Packet
, HeadLen
, NULL
);
879 if (FragmentHead
== NULL
) {
880 return EFI_INVALID_PARAMETER
;
883 FragmentOffset
= NTOHS (FragmentHead
->FragmentOffset
);
885 if ((FragmentOffset
& 0x1) == 0) {
886 Info
->LastFrag
= TRUE
;
889 FragmentOffset
&= (~0x1);
892 // This is the first fragment of the packet
894 if (FragmentOffset
== 0) {
895 Info
->NextHeader
= FragmentHead
->NextHeader
;
898 Info
->HeadLen
= (UINT16
) HeadLen
;
899 HeadLen
+= sizeof (IP6_FRAGMENT_HEADER
);
900 Info
->Start
= FragmentOffset
;
901 Info
->Length
= TotalLen
- (UINT16
) HeadLen
;
902 Info
->End
= Info
->Start
+ Info
->Length
;
903 Info
->Id
= FragmentHead
->Identification
;
904 Info
->FormerNextHeader
= FormerHeadOffset
;
907 // Fragments should in the unit of 8 octets long except the last one.
909 if ((Info
->LastFrag
== 0) && (Info
->Length
% 8 != 0)) {
910 return EFI_INVALID_PARAMETER
;
914 // Reassemble the packet.
916 *Packet
= Ip6Reassemble (&IpSb
->Assemble
, *Packet
);
917 if (*Packet
== NULL
) {
918 return EFI_INVALID_PARAMETER
;
922 // Re-check the assembled packet to get the right values.
924 *Head
= (*Packet
)->Ip
.Ip6
;
925 PayloadLen
= (*Head
)->PayloadLength
;
926 if (PayloadLen
!= 0) {
927 if (*Payload
!= NULL
) {
931 *Payload
= AllocatePool ((UINTN
) PayloadLen
);
932 if (*Payload
== NULL
) {
933 return EFI_INVALID_PARAMETER
;
936 NetbufCopy (*Packet
, sizeof (EFI_IP6_HEADER
), PayloadLen
, *Payload
);
939 if (!Ip6IsExtsValid (
942 &(*Head
)->NextHeader
,
952 return EFI_INVALID_PARAMETER
;
957 // Trim the head off, after this point, the packet is headless.
958 // and Packet->TotalLen == Info->Length.
960 NetbufTrim (*Packet
, sizeof (EFI_IP6_HEADER
) + *ExtHdrsLen
, TRUE
);
966 The IP6 input routine. It is called by the IP6_INTERFACE when an
967 IP6 fragment is received from MNP.
969 @param[in] Packet The IP6 packet received.
970 @param[in] IoStatus The return status of receive request.
971 @param[in] Flag The link layer flag for the packet received, such
973 @param[in] Context The IP6 service instance that owns the MNP.
979 IN EFI_STATUS IoStatus
,
985 EFI_IP6_HEADER
*Head
;
988 UINT32 UnFragmentLen
;
992 EFI_IP6_HEADER ZeroHead
;
994 IpSb
= (IP6_SERVICE
*) Context
;
995 NET_CHECK_SIGNATURE (IpSb
, IP6_SERVICE_SIGNATURE
);
1001 // Check input parameters
1003 if (EFI_ERROR (IoStatus
) || (IpSb
->State
== IP6_SERVICE_DESTROY
)) {
1008 // Pre-Process the Ipv6 Packet and then reassemble if it is necessary.
1010 Status
= Ip6PreProcessPacket (
1021 if (EFI_ERROR (Status
)) {
1025 // After trim off, the packet is a esp/ah/udp/tcp/icmp6 net buffer,
1026 // and no need consider any other ahead ext headers.
1028 Status
= Ip6IpSecProcessPacket (
1031 LastHead
, // need get the lasthead value for input
1039 if (EFI_ERROR (Status
)) {
1044 // If the packet is protected by IPsec Tunnel Mode, Check the Inner Ip Packet.
1046 ZeroMem (&ZeroHead
, sizeof (EFI_IP6_HEADER
));
1047 if (0 == CompareMem (Head
, &ZeroHead
, sizeof (EFI_IP6_HEADER
))) {
1048 Status
= Ip6PreProcessPacket (
1059 if (EFI_ERROR (Status
)) {
1065 // Check the Packet again.
1067 if (Packet
== NULL
) {
1072 // Packet may have been changed. The ownership of the packet
1073 // is transferred to the packet process logic.
1075 Head
= Packet
->Ip
.Ip6
;
1076 IP6_GET_CLIP_INFO (Packet
)->Status
= EFI_SUCCESS
;
1078 switch (*LastHead
) {
1080 Ip6IcmpHandle (IpSb
, Head
, Packet
);
1083 Ip6Demultiplex (IpSb
, Head
, Packet
);
1089 // Dispatch the DPCs queued by the NotifyFunction of the rx token's events
1090 // which are signaled with received data.
1095 if (Payload
!= NULL
) {
1099 Ip6ReceiveFrame (Ip6AcceptFrame
, IpSb
);
1102 if (Packet
!= NULL
) {
1103 NetbufFree (Packet
);
1110 Initialize an already allocated assemble table. This is generally
1111 the assemble table embedded in the IP6 service instance.
1113 @param[in, out] Table The assemble table to initialize.
1117 Ip6CreateAssembleTable (
1118 IN OUT IP6_ASSEMBLE_TABLE
*Table
1123 for (Index
= 0; Index
< IP6_ASSEMLE_HASH_SIZE
; Index
++) {
1124 InitializeListHead (&Table
->Bucket
[Index
]);
1129 Clean up the assemble table by removing all of the fragments
1130 and assemble entries.
1132 @param[in, out] Table The assemble table to clean up.
1136 Ip6CleanAssembleTable (
1137 IN OUT IP6_ASSEMBLE_TABLE
*Table
1142 IP6_ASSEMBLE_ENTRY
*Assemble
;
1145 for (Index
= 0; Index
< IP6_ASSEMLE_HASH_SIZE
; Index
++) {
1146 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &Table
->Bucket
[Index
]) {
1147 Assemble
= NET_LIST_USER_STRUCT (Entry
, IP6_ASSEMBLE_ENTRY
, Link
);
1149 RemoveEntryList (Entry
);
1150 Ip6FreeAssembleEntry (Assemble
);
1157 The signal handle of IP6's recycle event. It is called back
1158 when the upper layer releases the packet.
1160 @param[in] Event The IP6's recycle event.
1161 @param[in] Context The context of the handle, which is a IP6_RXDATA_WRAP.
1166 Ip6OnRecyclePacket (
1171 IP6_RXDATA_WRAP
*Wrap
;
1173 Wrap
= (IP6_RXDATA_WRAP
*) Context
;
1175 EfiAcquireLockOrFail (&Wrap
->IpInstance
->RecycleLock
);
1176 RemoveEntryList (&Wrap
->Link
);
1177 EfiReleaseLock (&Wrap
->IpInstance
->RecycleLock
);
1179 ASSERT (!NET_BUF_SHARED (Wrap
->Packet
));
1180 NetbufFree (Wrap
->Packet
);
1182 gBS
->CloseEvent (Wrap
->RxData
.RecycleSignal
);
1187 Wrap the received packet to a IP6_RXDATA_WRAP, which will be
1188 delivered to the upper layer. Each IP6 child that accepts the
1189 packet will get a not-shared copy of the packet which is wrapped
1190 in the IP6_RXDATA_WRAP. The IP6_RXDATA_WRAP->RxData is passed
1191 to the upper layer. The upper layer will signal the recycle event in
1192 it when it is done with the packet.
1194 @param[in] IpInstance The IP6 child to receive the packet.
1195 @param[in] Packet The packet to deliver up.
1197 @return NULL if it failed to wrap the packet; otherwise, the wrapper.
1202 IN IP6_PROTOCOL
*IpInstance
,
1206 IP6_RXDATA_WRAP
*Wrap
;
1207 EFI_IP6_RECEIVE_DATA
*RxData
;
1210 Wrap
= AllocatePool (IP6_RXDATA_WRAP_SIZE (Packet
->BlockOpNum
));
1216 InitializeListHead (&Wrap
->Link
);
1218 Wrap
->IpInstance
= IpInstance
;
1219 Wrap
->Packet
= Packet
;
1220 RxData
= &Wrap
->RxData
;
1222 ZeroMem (&RxData
->TimeStamp
, sizeof (EFI_TIME
));
1224 Status
= gBS
->CreateEvent (
1229 &RxData
->RecycleSignal
1232 if (EFI_ERROR (Status
)) {
1237 ASSERT (Packet
->Ip
.Ip6
!= NULL
);
1240 // The application expects a network byte order header.
1242 RxData
->HeaderLength
= sizeof (EFI_IP6_HEADER
);
1243 RxData
->Header
= (EFI_IP6_HEADER
*) Ip6NtohHead (Packet
->Ip
.Ip6
);
1244 RxData
->DataLength
= Packet
->TotalSize
;
1247 // Build the fragment table to be delivered up.
1249 RxData
->FragmentCount
= Packet
->BlockOpNum
;
1250 NetbufBuildExt (Packet
, (NET_FRAGMENT
*) RxData
->FragmentTable
, &RxData
->FragmentCount
);
1256 Check whether this IP child accepts the packet.
1258 @param[in] IpInstance The IP child to check.
1259 @param[in] Head The IP header of the packet.
1260 @param[in] Packet The data of the packet.
1262 @retval TRUE The child wants to receive the packet.
1263 @retval FALSE The child does not want to receive the packet.
1267 Ip6InstanceFrameAcceptable (
1268 IN IP6_PROTOCOL
*IpInstance
,
1269 IN EFI_IP6_HEADER
*Head
,
1273 IP6_ICMP_ERROR_HEAD Icmp
;
1274 EFI_IP6_CONFIG_DATA
*Config
;
1275 IP6_CLIP_INFO
*Info
;
1279 UINT16 ErrMsgPayloadLen
;
1280 UINT8
*ErrMsgPayload
;
1282 Config
= &IpInstance
->ConfigData
;
1286 // Dirty trick for the Tiano UEFI network stack implementation. If
1287 // ReceiveTimeout == -1, the receive of the packet for this instance
1288 // is disabled. The UEFI spec don't have such captibility. We add
1289 // this to improve the performance because IP will make a copy of
1290 // the received packet for each accepting instance. Some IP instances
1291 // used by UDP/TCP only send packets, they don't wants to receive.
1293 if (Config
->ReceiveTimeout
== (UINT32
)(-1)) {
1297 if (Config
->AcceptPromiscuous
) {
1302 // Check whether the protocol is acceptable.
1304 ExtHdrs
= NetbufGetByte (Packet
, 0, NULL
);
1306 if (!Ip6IsExtsValid (
1307 IpInstance
->Service
,
1311 (UINT32
) Head
->PayloadLength
,
1323 // The upper layer driver may want to receive the ICMPv6 error packet
1324 // invoked by its packet, like UDP.
1326 if ((*Proto
== IP6_ICMP
) && (!Config
->AcceptAnyProtocol
) && (*Proto
!= Config
->DefaultProtocol
)) {
1327 NetbufCopy (Packet
, 0, sizeof (Icmp
), (UINT8
*) &Icmp
);
1329 if (Icmp
.Head
.Type
<= ICMP_V6_ERROR_MAX
) {
1330 if (!Config
->AcceptIcmpErrors
) {
1335 // Get the protocol of the invoking packet of ICMPv6 error packet.
1337 ErrMsgPayloadLen
= NTOHS (Icmp
.IpHead
.PayloadLength
);
1338 ErrMsgPayload
= NetbufGetByte (Packet
, sizeof (Icmp
), NULL
);
1340 if (!Ip6IsExtsValid (
1343 &Icmp
.IpHead
.NextHeader
,
1359 // Match the protocol
1361 if (!Config
->AcceptAnyProtocol
&& (*Proto
!= Config
->DefaultProtocol
)) {
1366 // Check for broadcast, the caller has computed the packet's
1367 // cast type for this child's interface.
1369 Info
= IP6_GET_CLIP_INFO (Packet
);
1372 // If it is a multicast packet, check whether we are in the group.
1374 if (Info
->CastType
== Ip6Multicast
) {
1376 // Receive the multicast if the instance wants to receive all packets.
1378 if (NetIp6IsUnspecifiedAddr (&IpInstance
->ConfigData
.StationAddress
)) {
1382 for (Index
= 0; Index
< IpInstance
->GroupCount
; Index
++) {
1383 if (EFI_IP6_EQUAL (IpInstance
->GroupList
+ Index
, &Head
->DestinationAddress
)) {
1388 return (BOOLEAN
)(Index
< IpInstance
->GroupCount
);
1395 Enqueue a shared copy of the packet to the IP6 child if the
1396 packet is acceptable to it. Here the data of the packet is
1397 shared, but the net buffer isn't.
1399 @param IpInstance The IP6 child to enqueue the packet to.
1400 @param Head The IP header of the received packet.
1401 @param Packet The data of the received packet.
1403 @retval EFI_NOT_STARTED The IP child hasn't been configured.
1404 @retval EFI_INVALID_PARAMETER The child doesn't want to receive the packet.
1405 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources
1406 @retval EFI_SUCCESS A shared copy the packet is enqueued to the child.
1410 Ip6InstanceEnquePacket (
1411 IN IP6_PROTOCOL
*IpInstance
,
1412 IN EFI_IP6_HEADER
*Head
,
1416 IP6_CLIP_INFO
*Info
;
1420 // Check whether the packet is acceptable to this instance.
1422 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
1423 return EFI_NOT_STARTED
;
1426 if (!Ip6InstanceFrameAcceptable (IpInstance
, Head
, Packet
)) {
1427 return EFI_INVALID_PARAMETER
;
1431 // Enqueue a shared copy of the packet.
1433 Clone
= NetbufClone (Packet
);
1435 if (Clone
== NULL
) {
1436 return EFI_OUT_OF_RESOURCES
;
1440 // Set the receive time out for the assembled packet. If it expires,
1441 // packet will be removed from the queue.
1443 Info
= IP6_GET_CLIP_INFO (Clone
);
1444 Info
->Life
= IP6_US_TO_SEC (IpInstance
->ConfigData
.ReceiveTimeout
);
1446 InsertTailList (&IpInstance
->Received
, &Clone
->List
);
1451 Deliver the received packets to the upper layer if there are both received
1452 requests and enqueued packets. If the enqueued packet is shared, it will
1453 duplicate it to a non-shared packet, release the shared packet, then
1454 deliver the non-shared packet up.
1456 @param[in] IpInstance The IP child to deliver the packet up.
1458 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to deliver the
1460 @retval EFI_SUCCESS All the enqueued packets that can be delivered
1465 Ip6InstanceDeliverPacket (
1466 IN IP6_PROTOCOL
*IpInstance
1469 EFI_IP6_COMPLETION_TOKEN
*Token
;
1470 IP6_RXDATA_WRAP
*Wrap
;
1476 // Deliver a packet if there are both a packet and a receive token.
1478 while (!IsListEmpty (&IpInstance
->Received
) && !NetMapIsEmpty (&IpInstance
->RxTokens
)) {
1480 Packet
= NET_LIST_HEAD (&IpInstance
->Received
, NET_BUF
, List
);
1482 if (!NET_BUF_SHARED (Packet
)) {
1484 // If this is the only instance that wants the packet, wrap it up.
1486 Wrap
= Ip6WrapRxData (IpInstance
, Packet
);
1489 return EFI_OUT_OF_RESOURCES
;
1492 RemoveEntryList (&Packet
->List
);
1496 // Create a duplicated packet if this packet is shared
1498 Dup
= NetbufDuplicate (Packet
, NULL
, sizeof (EFI_IP6_HEADER
));
1501 return EFI_OUT_OF_RESOURCES
;
1505 // Copy the IP head over. The packet to deliver up is
1506 // headless. Trim the head off after copy. The IP head
1507 // may be not continuous before the data.
1509 Head
= NetbufAllocSpace (Dup
, sizeof (EFI_IP6_HEADER
), NET_BUF_HEAD
);
1510 ASSERT (Head
!= NULL
);
1511 Dup
->Ip
.Ip6
= (EFI_IP6_HEADER
*) Head
;
1513 CopyMem (Head
, Packet
->Ip
.Ip6
, sizeof (EFI_IP6_HEADER
));
1514 NetbufTrim (Dup
, sizeof (EFI_IP6_HEADER
), TRUE
);
1516 Wrap
= Ip6WrapRxData (IpInstance
, Dup
);
1520 return EFI_OUT_OF_RESOURCES
;
1523 RemoveEntryList (&Packet
->List
);
1524 NetbufFree (Packet
);
1530 // Insert it into the delivered packet, then get a user's
1531 // receive token, pass the wrapped packet up.
1533 EfiAcquireLockOrFail (&IpInstance
->RecycleLock
);
1534 InsertHeadList (&IpInstance
->Delivered
, &Wrap
->Link
);
1535 EfiReleaseLock (&IpInstance
->RecycleLock
);
1537 Token
= NetMapRemoveHead (&IpInstance
->RxTokens
, NULL
);
1538 Token
->Status
= IP6_GET_CLIP_INFO (Packet
)->Status
;
1539 Token
->Packet
.RxData
= &Wrap
->RxData
;
1541 gBS
->SignalEvent (Token
->Event
);
1548 Enqueue a received packet to all the IP children that share
1551 @param[in] IpSb The IP6 service instance that receive the packet.
1552 @param[in] Head The header of the received packet.
1553 @param[in] Packet The data of the received packet.
1554 @param[in] IpIf The interface to enqueue the packet to.
1556 @return The number of the IP6 children that accepts the packet.
1560 Ip6InterfaceEnquePacket (
1561 IN IP6_SERVICE
*IpSb
,
1562 IN EFI_IP6_HEADER
*Head
,
1564 IN IP6_INTERFACE
*IpIf
1567 IP6_PROTOCOL
*IpInstance
;
1568 IP6_CLIP_INFO
*Info
;
1575 // First, check that the packet is acceptable to this interface
1576 // and find the local cast type for the interface.
1579 Info
= IP6_GET_CLIP_INFO (Packet
);
1581 if (IpIf
->PromiscRecv
) {
1582 LocalType
= Ip6Promiscuous
;
1584 LocalType
= Info
->CastType
;
1588 // Iterate through the ip instances on the interface, enqueue
1589 // the packet if filter passed. Save the original cast type,
1590 // and pass the local cast type to the IP children on the
1591 // interface. The global cast type will be restored later.
1593 SavedType
= Info
->CastType
;
1594 Info
->CastType
= (UINT32
) LocalType
;
1598 NET_LIST_FOR_EACH (Entry
, &IpIf
->IpInstances
) {
1599 IpInstance
= NET_LIST_USER_STRUCT (Entry
, IP6_PROTOCOL
, AddrLink
);
1600 NET_CHECK_SIGNATURE (IpInstance
, IP6_PROTOCOL_SIGNATURE
);
1602 if (Ip6InstanceEnquePacket (IpInstance
, Head
, Packet
) == EFI_SUCCESS
) {
1607 Info
->CastType
= (UINT32
) SavedType
;
1612 Deliver the packet for each IP6 child on the interface.
1614 @param[in] IpSb The IP6 service instance that received the packet.
1615 @param[in] IpIf The IP6 interface to deliver the packet.
1619 Ip6InterfaceDeliverPacket (
1620 IN IP6_SERVICE
*IpSb
,
1621 IN IP6_INTERFACE
*IpIf
1624 IP6_PROTOCOL
*IpInstance
;
1627 NET_LIST_FOR_EACH (Entry
, &IpIf
->IpInstances
) {
1628 IpInstance
= NET_LIST_USER_STRUCT (Entry
, IP6_PROTOCOL
, AddrLink
);
1629 Ip6InstanceDeliverPacket (IpInstance
);
1634 De-multiplex the packet. the packet delivery is processed in two
1635 passes. The first pass will enqueue a shared copy of the packet
1636 to each IP6 child that accepts the packet. The second pass will
1637 deliver a non-shared copy of the packet to each IP6 child that
1638 has pending receive requests. Data is copied if more than one
1639 child wants to consume the packet, because each IP child needs
1640 its own copy of the packet to make changes.
1642 @param[in] IpSb The IP6 service instance that received the packet.
1643 @param[in] Head The header of the received packet.
1644 @param[in] Packet The data of the received packet.
1646 @retval EFI_NOT_FOUND No IP child accepts the packet.
1647 @retval EFI_SUCCESS The packet is enqueued or delivered to some IP
1653 IN IP6_SERVICE
*IpSb
,
1654 IN EFI_IP6_HEADER
*Head
,
1660 IP6_INTERFACE
*IpIf
;
1664 // Two pass delivery: first, enqueue a shared copy of the packet
1665 // to each instance that accept the packet.
1669 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
1670 IpIf
= NET_LIST_USER_STRUCT (Entry
, IP6_INTERFACE
, Link
);
1672 if (IpIf
->Configured
) {
1673 Enqueued
+= Ip6InterfaceEnquePacket (IpSb
, Head
, Packet
, IpIf
);
1678 // Second: deliver a duplicate of the packet to each instance.
1679 // Release the local reference first, so that the last instance
1680 // getting the packet will not copy the data.
1682 NetbufFree (Packet
);
1685 if (Enqueued
== 0) {
1686 return EFI_NOT_FOUND
;
1689 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
1690 IpIf
= NET_LIST_USER_STRUCT (Entry
, IP6_INTERFACE
, Link
);
1692 if (IpIf
->Configured
) {
1693 Ip6InterfaceDeliverPacket (IpSb
, IpIf
);
1701 Decrease the life of the transmitted packets. If it is
1702 decreased to zero, cancel the packet. This function is
1703 called by Ip6packetTimerTicking that provides timeout for both the
1704 received-but-not-delivered and transmitted-but-not-recycle
1707 @param[in] Map The IP6 child's transmit map.
1708 @param[in] Item Current transmitted packet.
1709 @param[in] Context Not used.
1711 @retval EFI_SUCCESS Always returns EFI_SUCCESS.
1716 Ip6SentPacketTicking (
1718 IN NET_MAP_ITEM
*Item
,
1722 IP6_TXTOKEN_WRAP
*Wrap
;
1724 Wrap
= (IP6_TXTOKEN_WRAP
*) Item
->Value
;
1725 ASSERT (Wrap
!= NULL
);
1727 if ((Wrap
->Life
> 0) && (--Wrap
->Life
== 0)) {
1728 Ip6CancelPacket (Wrap
->IpInstance
->Interface
, Wrap
->Packet
, EFI_ABORTED
);
1735 Timeout the fragments, and the enqueued, and transmitted packets.
1737 @param[in] IpSb The IP6 service instance to timeout.
1741 Ip6PacketTimerTicking (
1742 IN IP6_SERVICE
*IpSb
1745 LIST_ENTRY
*InstanceEntry
;
1748 IP6_PROTOCOL
*IpInstance
;
1749 IP6_ASSEMBLE_ENTRY
*Assemble
;
1751 IP6_CLIP_INFO
*Info
;
1755 // First, time out the fragments. The packet's life is counting down
1756 // once the first-arriving fragment of that packet was received.
1758 for (Index
= 0; Index
< IP6_ASSEMLE_HASH_SIZE
; Index
++) {
1759 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &(IpSb
->Assemble
.Bucket
[Index
])) {
1760 Assemble
= NET_LIST_USER_STRUCT (Entry
, IP6_ASSEMBLE_ENTRY
, Link
);
1762 if ((Assemble
->Life
> 0) && (--Assemble
->Life
== 0)) {
1764 // If the first fragment (the one with a Fragment Offset of zero)
1765 // has been received, an ICMP Time Exceeded - Fragment Reassembly
1766 // Time Exceeded message should be sent to the source of that fragment.
1768 if ((Assemble
->Packet
!= NULL
) &&
1769 !IP6_IS_MULTICAST (&Assemble
->Head
->DestinationAddress
)) {
1774 &Assemble
->Head
->SourceAddress
,
1775 ICMP_V6_TIME_EXCEEDED
,
1776 ICMP_V6_TIMEOUT_REASSEMBLE
,
1782 // If reassembly of a packet is not completed within 60 seconds of
1783 // the reception of the first-arriving fragment of that packet, the
1784 // reassembly must be abandoned and all the fragments that have been
1785 // received for that packet must be discarded.
1787 RemoveEntryList (Entry
);
1788 Ip6FreeAssembleEntry (Assemble
);
1793 NET_LIST_FOR_EACH (InstanceEntry
, &IpSb
->Children
) {
1794 IpInstance
= NET_LIST_USER_STRUCT (InstanceEntry
, IP6_PROTOCOL
, Link
);
1797 // Second, time out the assembled packets enqueued on each IP child.
1799 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &IpInstance
->Received
) {
1800 Packet
= NET_LIST_USER_STRUCT (Entry
, NET_BUF
, List
);
1801 Info
= IP6_GET_CLIP_INFO (Packet
);
1803 if ((Info
->Life
> 0) && (--Info
->Life
== 0)) {
1804 RemoveEntryList (Entry
);
1805 NetbufFree (Packet
);
1810 // Third: time out the transmitted packets.
1812 NetMapIterate (&IpInstance
->TxTokens
, Ip6SentPacketTicking
, NULL
);