2 The internal functions and routines to transmit the IP6 packet.
4 Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
15 Output all the available source addresses to a list entry head SourceList. The
16 number of source addresses are also returned.
18 @param[in] IpSb Points to an IP6 service binding instance.
19 @param[out] SourceList The list entry head of all source addresses.
20 It is the caller's responsibility to free the
22 @param[out] SourceCount The number of source addresses.
24 @retval EFI_SUCCESS The source addresses were copied to a list entry head
26 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to complete the operation.
32 OUT LIST_ENTRY
*SourceList
,
33 OUT UINT32
*SourceCount
39 IP6_ADDRESS_INFO
*AddrInfo
;
40 IP6_ADDRESS_INFO
*Copy
;
44 if (IpSb
->LinkLocalOk
) {
45 Copy
= AllocatePool (sizeof (IP6_ADDRESS_INFO
));
47 return EFI_OUT_OF_RESOURCES
;
50 Copy
->Signature
= IP6_ADDR_INFO_SIGNATURE
;
51 IP6_COPY_ADDRESS (&Copy
->Address
, &IpSb
->LinkLocalAddr
);
52 Copy
->IsAnycast
= FALSE
;
53 Copy
->PrefixLength
= IP6_LINK_LOCAL_PREFIX_LENGTH
;
54 Copy
->ValidLifetime
= (UINT32
) IP6_INFINIT_LIFETIME
;
55 Copy
->PreferredLifetime
= (UINT32
) IP6_INFINIT_LIFETIME
;
57 InsertTailList (SourceList
, &Copy
->Link
);
61 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
62 IpIf
= NET_LIST_USER_STRUCT (Entry
, IP6_INTERFACE
, Link
);
64 NET_LIST_FOR_EACH (Entry2
, &IpIf
->AddressList
) {
65 AddrInfo
= NET_LIST_USER_STRUCT_S (Entry2
, IP6_ADDRESS_INFO
, Link
, IP6_ADDR_INFO_SIGNATURE
);
67 if (AddrInfo
->IsAnycast
) {
69 // Never use an anycast address.
74 Copy
= AllocateCopyPool (sizeof (IP6_ADDRESS_INFO
), AddrInfo
);
76 return EFI_OUT_OF_RESOURCES
;
79 InsertTailList (SourceList
, &Copy
->Link
);
88 Calculate how many bits are the same between two IPv6 addresses.
90 @param[in] AddressA Points to an IPv6 address.
91 @param[in] AddressB Points to another IPv6 address.
93 @return The common bits of the AddressA and AddressB.
98 IN EFI_IPv6_ADDRESS
*AddressA
,
99 IN EFI_IPv6_ADDRESS
*AddressB
112 ByteA
= AddressA
->Addr
[Index
];
113 ByteB
= AddressB
->Addr
[Index
];
115 if (ByteA
== ByteB
) {
122 // Check how many bits are common between the two bytes.
125 ByteA
= (UINT8
) (ByteA
^ ByteB
);
129 ByteA
= (UINT8
) (ByteA
>> 1);
132 return (UINT8
) (Count
+ NumBits
);
139 Output all the available source addresses to a list entry head SourceList. The
140 number of source addresses are also returned.
142 @param[in] IpSb Points to a IP6 service binding instance.
143 @param[in] Destination The IPv6 destination address.
144 @param[out] Source The selected IPv6 source address according to
147 @retval EFI_SUCCESS The source addresses were copied to a list entry
149 @retval EFI_NO_MAPPING The IPv6 stack is not auto configured.
153 Ip6SelectSourceAddress (
154 IN IP6_SERVICE
*IpSb
,
155 IN EFI_IPv6_ADDRESS
*Destination
,
156 OUT EFI_IPv6_ADDRESS
*Source
160 LIST_ENTRY SourceList
;
164 IP6_ADDRESS_INFO
*AddrInfo
;
165 IP6_PREFIX_LIST_ENTRY
*Prefix
;
166 UINT8 LastCommonLength
;
167 UINT8 CurrentCommonLength
;
168 EFI_IPv6_ADDRESS
*TmpAddress
;
170 NET_CHECK_SIGNATURE (IpSb
, IP6_SERVICE_SIGNATURE
);
172 Status
= EFI_SUCCESS
;
173 InitializeListHead (&SourceList
);
175 if (!IpSb
->LinkLocalOk
) {
176 return EFI_NO_MAPPING
;
180 // Rule 1: Prefer same address.
182 if (Ip6IsOneOfSetAddress (IpSb
, Destination
, NULL
, NULL
)) {
183 IP6_COPY_ADDRESS (Source
, Destination
);
188 // Rule 2: Prefer appropriate scope.
190 if (IP6_IS_MULTICAST (Destination
)) {
191 ScopeD
= (UINT8
) (Destination
->Addr
[1] >> 4);
192 } else if (NetIp6IsLinkLocalAddr (Destination
)) {
200 // Return the link-local address if it exists
201 // One IP6_SERVICE only has one link-local address.
203 IP6_COPY_ADDRESS (Source
, &IpSb
->LinkLocalAddr
);
208 // All candidate source addresses are global unicast address.
210 Ip6CandidateSource (IpSb
, &SourceList
, &SourceCount
);
212 if (SourceCount
== 0) {
213 Status
= EFI_NO_MAPPING
;
217 IP6_COPY_ADDRESS (Source
, &IpSb
->LinkLocalAddr
);
219 if (SourceCount
== 1) {
224 // Rule 3: Avoid deprecated addresses.
225 // TODO: check the "deprecated" state of the stateful configured address
227 NET_LIST_FOR_EACH (Entry
, &IpSb
->AutonomousPrefix
) {
228 Prefix
= NET_LIST_USER_STRUCT (Entry
, IP6_PREFIX_LIST_ENTRY
, Link
);
229 if (Prefix
->PreferredLifetime
== 0) {
230 Ip6RemoveAddr (NULL
, &SourceList
, &SourceCount
, &Prefix
->Prefix
, Prefix
->PrefixLength
);
232 if (SourceCount
== 1) {
239 // TODO: Rule 4: Prefer home addresses.
240 // TODO: Rule 5: Prefer outgoing interface.
241 // TODO: Rule 6: Prefer matching label.
242 // TODO: Rule 7: Prefer public addresses.
246 // Rule 8: Use longest matching prefix.
248 LastCommonLength
= Ip6CommonPrefixLen (Source
, Destination
);
251 for (Entry
= SourceList
.ForwardLink
; Entry
!= &SourceList
; Entry
= Entry
->ForwardLink
) {
252 AddrInfo
= NET_LIST_USER_STRUCT_S (Entry
, IP6_ADDRESS_INFO
, Link
, IP6_ADDR_INFO_SIGNATURE
);
254 CurrentCommonLength
= Ip6CommonPrefixLen (&AddrInfo
->Address
, Destination
);
255 if (CurrentCommonLength
> LastCommonLength
) {
256 LastCommonLength
= CurrentCommonLength
;
257 TmpAddress
= &AddrInfo
->Address
;
261 if (TmpAddress
!= NULL
) {
262 IP6_COPY_ADDRESS (Source
, TmpAddress
);
267 Ip6RemoveAddr (NULL
, &SourceList
, &SourceCount
, NULL
, 0);
273 Select an interface to send the packet generated in the IP6 driver
274 itself: that is, not by the requests of the IP6 child's consumer. Such
275 packets include the ICMPv6 echo replies and other ICMPv6 error packets.
277 @param[in] IpSb The IP4 service that wants to send the packets.
278 @param[in] Destination The destination of the packet.
279 @param[in, out] Source The source of the packet.
281 @return NULL if no proper interface is found, otherwise, the interface that
282 can be used to send the system packet from.
287 IN IP6_SERVICE
*IpSb
,
288 IN EFI_IPv6_ADDRESS
*Destination
,
289 IN OUT EFI_IPv6_ADDRESS
*Source
293 EFI_IPv6_ADDRESS SelectedSource
;
297 NET_CHECK_SIGNATURE (IpSb
, IP6_SERVICE_SIGNATURE
);
298 ASSERT (Destination
!= NULL
&& Source
!= NULL
);
300 if (NetIp6IsUnspecifiedAddr (Destination
)) {
304 if (!NetIp6IsUnspecifiedAddr (Source
)) {
305 Exist
= Ip6IsOneOfSetAddress (IpSb
, Source
, &IpIf
, NULL
);
312 // If source is unspecified, select a source according to the destination.
314 Status
= Ip6SelectSourceAddress (IpSb
, Destination
, &SelectedSource
);
315 if (EFI_ERROR (Status
)) {
316 return IpSb
->DefaultInterface
;
319 Ip6IsOneOfSetAddress (IpSb
, &SelectedSource
, &IpIf
, NULL
);
320 IP6_COPY_ADDRESS (Source
, &SelectedSource
);
326 The default callback function for the system generated packet.
327 It will free the packet.
329 @param[in] Packet The packet that transmitted.
330 @param[in] IoStatus The result of the transmission, succeeded or failed.
331 @param[in] LinkFlag Not used when transmitted. Check IP6_FRAME_CALLBACK
333 @param[in] Context The context provided by us.
349 Prefix an IP6 basic head and unfragmentable extension headers and a fragment header
350 to the Packet. Used for IP6 fragmentation.
352 @param[in] IpSb The IP6 service instance to transmit the packet.
353 @param[in] Packet The packet to prefix the IP6 header to.
354 @param[in] Head The caller supplied header.
355 @param[in] FragmentOffset The fragment offset of the data following the header.
356 @param[in] ExtHdrs The length of the original extension header.
357 @param[in] ExtHdrsLen The length of the extension headers.
358 @param[in] LastHeader The pointer of next header of last extension header.
359 @param[in] HeadLen The length of the unfragmented part of the IP6 header.
361 @retval EFI_BAD_BUFFER_SIZE There is no enough room in the head space of
363 @retval EFI_SUCCESS The operation performed successfully.
368 IN IP6_SERVICE
*IpSb
,
370 IN EFI_IP6_HEADER
*Head
,
371 IN UINT16 FragmentOffset
,
373 IN UINT32 ExtHdrsLen
,
379 UINT32 UnFragExtHdrsLen
;
380 EFI_IP6_HEADER
*PacketHead
;
381 UINT8
*UpdatedExtHdrs
;
385 UpdatedExtHdrs
= NULL
;
388 // HeadLen is the length of the fixed part of the sequences of fragments, i.e.
389 // the unfragment part.
391 PacketHead
= (EFI_IP6_HEADER
*) NetbufAllocSpace (Packet
, HeadLen
, NET_BUF_HEAD
);
392 if (PacketHead
== NULL
) {
393 return EFI_BAD_BUFFER_SIZE
;
397 // Set the head up, convert the host byte order to network byte order
399 CopyMem (PacketHead
, Head
, sizeof (EFI_IP6_HEADER
));
400 PacketHead
->PayloadLength
= HTONS ((UINT16
) (Packet
->TotalSize
- sizeof (EFI_IP6_HEADER
)));
401 Packet
->Ip
.Ip6
= PacketHead
;
403 Len
= HeadLen
- sizeof (EFI_IP6_HEADER
);
404 UnFragExtHdrsLen
= Len
- sizeof (IP6_FRAGMENT_HEADER
);
406 if (UnFragExtHdrsLen
== 0) {
407 PacketHead
->NextHeader
= IP6_FRAGMENT
;
411 // Append the extension headers: firstly copy the unfragmentable headers, then append
412 // fragmentation header.
414 if ((FragmentOffset
& IP6_FRAGMENT_OFFSET_MASK
) == 0) {
415 NextHeader
= Head
->NextHeader
;
417 NextHeader
= PacketHead
->NextHeader
;
420 Status
= Ip6FillFragmentHeader (
429 if (EFI_ERROR (Status
)) {
434 (UINT8
*) (PacketHead
+ 1),
436 UnFragExtHdrsLen
+ sizeof (IP6_FRAGMENT_HEADER
)
439 FreePool (UpdatedExtHdrs
);
444 Transmit an IP6 packet. The packet comes either from the IP6
445 child's consumer (IpInstance != NULL) or the IP6 driver itself
446 (IpInstance == NULL). It will route the packet, fragment it,
447 then transmit all the fragments through an interface.
449 @param[in] IpSb The IP6 service instance to transmit the packet.
450 @param[in] Interface The IP6 interface to transmit the packet. Ignored
452 @param[in] IpInstance The IP6 child that issues the transmission. It is
453 NULL if the packet is from the system.
454 @param[in] Packet The user data to send, excluding the IP header.
455 @param[in] Head The caller supplied header. The caller should set
456 the following header fields: NextHeader, HopLimit,
457 Src, Dest, FlowLabel, PayloadLength. This function
458 will fill in the Ver, TrafficClass.
459 @param[in] ExtHdrs The extension headers to append to the IPv6 basic
461 @param[in] ExtHdrsLen The length of the extension headers.
462 @param[in] Callback The callback function to issue when transmission
464 @param[in] Context The opaque context for the callback.
466 @retval EFI_INVALID_PARAMETER Any input parameter or the packet is invalid.
467 @retval EFI_NO_MAPPING There is no interface to the destination.
468 @retval EFI_NOT_FOUND There is no route to the destination.
469 @retval EFI_SUCCESS The packet successfully transmitted.
470 @retval EFI_OUT_OF_RESOURCES Failed to finish the operation due to lack of
472 @retval Others Failed to transmit the packet.
477 IN IP6_SERVICE
*IpSb
,
478 IN IP6_INTERFACE
*Interface OPTIONAL
,
479 IN IP6_PROTOCOL
*IpInstance OPTIONAL
,
481 IN EFI_IP6_HEADER
*Head
,
483 IN UINT32 ExtHdrsLen
,
484 IN IP6_FRAME_CALLBACK Callback
,
489 EFI_IPv6_ADDRESS NextHop
;
490 IP6_NEIGHBOR_ENTRY
*NeighborCache
;
491 IP6_ROUTE_CACHE_ENTRY
*RouteCache
;
495 UINT16 FragmentOffset
;
497 UINT32 UnFragmentLen
;
498 UINT32 UnFragmentHdrsLen
;
499 UINT32 FragmentHdrsLen
;
501 UINT16 PacketChecksum
;
502 UINT16 PseudoChecksum
;
511 EFI_IP6_HEADER
*PacketHead
;
512 IP6_ICMP_HEAD
*IcmpHead
;
513 IP6_TXTOKEN_WRAP
*Wrap
;
514 IP6_ROUTE_ENTRY
*RouteEntry
;
515 UINT8
*UpdatedExtHdrs
;
517 UINT8 LastHeaderBackup
;
518 BOOLEAN FragmentHeadInserted
;
519 UINT8
*ExtHdrsBackup
;
520 UINT8 NextHeaderBackup
;
521 EFI_IPv6_ADDRESS Source
;
522 EFI_IPv6_ADDRESS Destination
;
524 NET_CHECK_SIGNATURE (IpSb
, IP6_SERVICE_SIGNATURE
);
527 // RFC2460: Each extension header is an integer multiple of 8 octets long,
528 // in order to retain 8-octet alignment for subsequent headers.
530 if ((ExtHdrsLen
& 0x7) != 0) {
531 return EFI_INVALID_PARAMETER
;
551 // Select an interface/source for system packet, application
552 // should select them itself.
557 // IpInstance->Interface is NULL when IpInstance is configured with both stationaddress
558 // and destinationaddress is unspecified.
560 if (IpInstance
== NULL
|| IpInstance
->Interface
== NULL
) {
561 IpIf
= Ip6SelectInterface (IpSb
, &Head
->DestinationAddress
, &Head
->SourceAddress
);
562 if (IpInstance
!= NULL
) {
563 IpInstance
->Interface
= IpIf
;
566 IpIf
= IpInstance
->Interface
;
571 return EFI_NO_MAPPING
;
575 // Update the common field in Head here.
578 Head
->TrafficClassL
= 0;
579 Head
->TrafficClassH
= 0;
582 NextHeader
= *LastHeader
;
584 switch (NextHeader
) {
585 case EFI_IP_PROTO_UDP
:
586 Packet
->Udp
= (EFI_UDP_HEADER
*) NetbufGetByte (Packet
, 0, NULL
);
587 ASSERT (Packet
->Udp
!= NULL
);
588 if (Packet
->Udp
->Checksum
== 0) {
589 Checksum
= &Packet
->Udp
->Checksum
;
593 case EFI_IP_PROTO_TCP
:
594 Packet
->Tcp
= (TCP_HEAD
*) NetbufGetByte (Packet
, 0, NULL
);
595 ASSERT (Packet
->Tcp
!= NULL
);
596 if (Packet
->Tcp
->Checksum
== 0) {
597 Checksum
= &Packet
->Tcp
->Checksum
;
603 // Don't send ICMP packet to an IPv6 anycast address.
605 if (Ip6IsAnycast (IpSb
, &Head
->DestinationAddress
)) {
606 return EFI_INVALID_PARAMETER
;
609 IcmpHead
= (IP6_ICMP_HEAD
*) NetbufGetByte (Packet
, 0, NULL
);
610 ASSERT (IcmpHead
!= NULL
);
611 if (IcmpHead
->Checksum
== 0) {
612 Checksum
= &IcmpHead
->Checksum
;
620 if (Checksum
!= NULL
) {
622 // Calculate the checksum for upper layer protocol if it is not calculated due to lack of
623 // IPv6 source address.
625 PacketChecksum
= NetbufChecksum (Packet
);
626 PseudoChecksum
= NetIp6PseudoHeadChecksum (
627 &Head
->SourceAddress
,
628 &Head
->DestinationAddress
,
632 *Checksum
= (UINT16
) ~NetAddChecksum (PacketChecksum
, PseudoChecksum
);
635 Status
= Ip6IpSecProcessPacket (
638 LastHeader
, // no need get the lasthead value for output
646 if (EFI_ERROR(Status
)) {
652 // Check incoming parameters.
654 if (!Ip6IsExtsValid (
667 return EFI_INVALID_PARAMETER
;
670 if ((RealExtLen
& 0x7) != 0) {
671 return EFI_INVALID_PARAMETER
;
674 LastHeaderBackup
= *LastHeader
;
677 // Perform next hop determination:
678 // For multicast packets, the next-hop is always the destination address and
679 // is considered to be on-link.
681 if (IP6_IS_MULTICAST (&Head
->DestinationAddress
)) {
682 IP6_COPY_ADDRESS (&NextHop
, &Head
->DestinationAddress
);
685 // For unicast packets, use a combination of the Destination Cache, the Prefix List
686 // and the Default Router List to determine the IP address of the appropriate next hop.
689 NeighborCache
= Ip6FindNeighborEntry (IpSb
, &Head
->DestinationAddress
);
690 if (NeighborCache
!= NULL
) {
692 // Hit Neighbor Cache.
694 IP6_COPY_ADDRESS (&NextHop
, &Head
->DestinationAddress
);
697 // Not in Neighbor Cache, check Router cache
699 RouteCache
= Ip6Route (IpSb
, &Head
->DestinationAddress
, &Head
->SourceAddress
);
700 if (RouteCache
== NULL
) {
701 return EFI_NOT_FOUND
;
704 IP6_COPY_ADDRESS (&NextHop
, &RouteCache
->NextHop
);
705 Ip6FreeRouteCacheEntry (RouteCache
);
710 // Examines the Neighbor Cache for link-layer information about that neighbor.
711 // DO NOT create neighbor cache if neighbor is itself - when reporting ICMP error.
713 if (!IP6_IS_MULTICAST (&NextHop
) && !EFI_IP6_EQUAL (&Head
->DestinationAddress
, &Head
->SourceAddress
)) {
714 NeighborCache
= Ip6FindNeighborEntry (IpSb
, &NextHop
);
715 if (NeighborCache
== NULL
) {
716 NeighborCache
= Ip6CreateNeighborEntry (IpSb
, Ip6OnArpResolved
, &NextHop
, NULL
);
718 if (NeighborCache
== NULL
) {
719 return EFI_OUT_OF_RESOURCES
;
723 // Send out multicast neighbor solicitation for address resolution immediately.
725 Ip6CreateSNMulticastAddr (&NeighborCache
->Neighbor
, &Destination
);
726 Status
= Ip6SelectSourceAddress (IpSb
, &NeighborCache
->Neighbor
, &Source
);
727 if (EFI_ERROR (Status
)) {
731 Status
= Ip6SendNeighborSolicit (
735 &NeighborCache
->Neighbor
,
736 &IpSb
->SnpMode
.CurrentAddress
738 if (EFI_ERROR (Status
)) {
742 --NeighborCache
->Transmit
;
743 NeighborCache
->Ticks
= IP6_GET_TICKS (IpSb
->RetransTimer
) + 1;
746 NeighborCache
->Interface
= IpIf
;
749 UpdatedExtHdrs
= NULL
;
750 ExtHdrsBackup
= NULL
;
751 NextHeaderBackup
= 0;
752 FragmentHeadInserted
= FALSE
;
755 // Check whether we received Packet Too Big message for the packet sent to the
756 // Destination. If yes include a Fragment Header in the subsequent packets.
758 RouteEntry
= Ip6FindRouteEntry (
760 &Head
->DestinationAddress
,
763 if (RouteEntry
!= NULL
) {
764 if ((RouteEntry
->Flag
& IP6_PACKET_TOO_BIG
) == IP6_PACKET_TOO_BIG
) {
767 // FragmentHead is inserted after Hop-by-Hop Options header, Destination
768 // Options header (first occur), Routing header, and before Fragment header,
769 // Authentication header, Encapsulating Security Payload header, and
770 // Destination Options header (last occur), and upper-layer header.
772 Status
= Ip6FillFragmentHeader (
781 if (EFI_ERROR (Status
)) {
785 if ((ExtHdrs
== NULL
) && (ExtHdrsLen
== 0)) {
786 NextHeaderBackup
= Head
->NextHeader
;
787 Head
->NextHeader
= IP6_FRAGMENT
;
790 ExtHdrsBackup
= ExtHdrs
;
791 ExtHdrs
= UpdatedExtHdrs
;
792 ExtHdrsLen
= ExtHdrsLen
+ sizeof (IP6_FRAGMENT_HEADER
);
793 RealExtLen
= RealExtLen
+ sizeof (IP6_FRAGMENT_HEADER
);
797 FragmentHeadInserted
= TRUE
;
800 Ip6FreeRouteEntry (RouteEntry
);
804 // OK, selected the source and route, fragment the packet then send
805 // them. Tag each fragment other than the first one as spawn from it.
806 // Each extension header is an integer multiple of 8 octets long, in
807 // order to retain 8-octet alignment for subsequent headers.
809 Mtu
= IpSb
->MaxPacketSize
+ sizeof (EFI_IP6_HEADER
);
810 HeadLen
= sizeof (EFI_IP6_HEADER
) + RealExtLen
;
812 if (Packet
->TotalSize
+ HeadLen
> Mtu
) {
814 // Remove the inserted Fragment Header since we need fragment the packet.
816 if (FragmentHeadInserted
) {
817 ExtHdrs
= ExtHdrsBackup
;
818 ExtHdrsLen
= ExtHdrsLen
- sizeof (IP6_FRAGMENT_HEADER
);
820 if ((ExtHdrs
== NULL
) && (ExtHdrsLen
== 0)) {
821 Head
->NextHeader
= NextHeaderBackup
;
825 FragmentHdrsLen
= ExtHdrsLen
- UnFragmentHdrsLen
;
828 // The packet is beyond the maximum which can be described through the
829 // fragment offset field in Fragment header.
831 if ((((Packet
->TotalSize
+ FragmentHdrsLen
) >> 3) & (~0x1fff)) != 0) {
832 Status
= EFI_BAD_BUFFER_SIZE
;
836 if (FragmentHdrsLen
!= 0) {
838 // Append the fragmentable extension hdrs before the upper layer payload
839 // to form a new NET_BUF. This NET_BUF contains all the buffer which will
840 // be fragmented below.
842 TmpPacket
= NetbufGetFragment (Packet
, 0, Packet
->TotalSize
, FragmentHdrsLen
);
843 ASSERT (TmpPacket
!= NULL
);
846 // Allocate the space to contain the fragmentable hdrs and copy the data.
848 Buf
= NetbufAllocSpace (TmpPacket
, FragmentHdrsLen
, TRUE
);
849 ASSERT (Buf
!= NULL
);
850 CopyMem (Buf
, ExtHdrs
+ UnFragmentHdrsLen
, FragmentHdrsLen
);
853 // Free the old Packet.
860 // The unfragment part which appears in every fragmented IPv6 packet includes
861 // the IPv6 header, the unfragmentable extension hdrs and the fragment header.
863 UnFragmentLen
= sizeof (EFI_IP6_HEADER
) + UnFragmentHdrsLen
+ sizeof (IP6_FRAGMENT_HEADER
);
866 // Mtu now is the length of the fragment part in a full-length fragment.
868 Mtu
= (Mtu
- UnFragmentLen
) & (~0x07);
869 Num
= (Packet
->TotalSize
+ Mtu
- 1) / Mtu
;
871 for (Index
= 0, Offset
= 0, PacketLen
= Mtu
; Index
< Num
; Index
++) {
873 // Get fragment from the Packet, append UnFragmentLen spare buffer
874 // before the fragmented data, the corresponding data is filled in later.
876 Fragment
= NetbufGetFragment (Packet
, Offset
, PacketLen
, UnFragmentLen
);
877 if (Fragment
== NULL
) {
878 Status
= EFI_OUT_OF_RESOURCES
;
882 FragmentOffset
= (UINT16
) ((UINT16
) Offset
| 0x1);
883 if (Index
== Num
- 1){
885 // The last fragment, clear the M flag.
887 FragmentOffset
&= (~0x1);
890 Status
= Ip6PrependHead (
900 ASSERT (Status
== EFI_SUCCESS
);
902 Status
= Ip6SendFrame (
910 if (EFI_ERROR (Status
)) {
915 // The last fragment of upper layer packet, update the IP6 token status.
917 if ((Index
== Num
-1) && (Context
!= NULL
)) {
918 Wrap
= (IP6_TXTOKEN_WRAP
*) Context
;
919 Wrap
->Token
->Status
= Status
;
923 PacketLen
= Packet
->TotalSize
- Offset
;
924 if (PacketLen
> Mtu
) {
932 if (UpdatedExtHdrs
!= NULL
) {
933 FreePool (UpdatedExtHdrs
);
940 // Need not fragment the packet, send it in one frame.
942 PacketHead
= (EFI_IP6_HEADER
*) NetbufAllocSpace (Packet
, HeadLen
, NET_BUF_HEAD
);
943 if (PacketHead
== NULL
) {
944 Status
= EFI_BAD_BUFFER_SIZE
;
948 CopyMem (PacketHead
, Head
, sizeof (EFI_IP6_HEADER
));
949 Packet
->Ip
.Ip6
= PacketHead
;
951 if (ExtHdrs
!= NULL
) {
952 Buf
= (UINT8
*) (PacketHead
+ 1);
953 CopyMem (Buf
, ExtHdrs
, ExtHdrsLen
);
956 if (UpdatedExtHdrs
!= NULL
) {
958 // A Fragment Header is inserted to the packet, update the payload length.
960 PacketHead
->PayloadLength
= (UINT16
) (NTOHS (PacketHead
->PayloadLength
) +
961 sizeof (IP6_FRAGMENT_HEADER
));
962 PacketHead
->PayloadLength
= HTONS (PacketHead
->PayloadLength
);
963 FreePool (UpdatedExtHdrs
);
966 return Ip6SendFrame (
976 if (UpdatedExtHdrs
!= NULL
) {
977 FreePool (UpdatedExtHdrs
);
979 Ip6CancelPacket (IpIf
, Packet
, Status
);
984 The filter function to find a packet and all its fragments.
985 The packet's fragments have their Context set to the packet.
987 @param[in] Frame The frames hold by the low level interface.
988 @param[in] Context Context to the function, which is the packet.
990 @retval TRUE This is the packet to cancel or its fragments.
991 @retval FALSE This is an unrelated packet.
995 Ip6CancelPacketFragments (
996 IN IP6_LINK_TX_TOKEN
*Frame
,
1000 if ((Frame
->Packet
== (NET_BUF
*) Context
) || (Frame
->Context
== Context
)) {
1008 Remove all the frames on the interface that pass the FrameToCancel,
1009 either queued on ARP queues or that have already been delivered to
1010 MNP and not yet recycled.
1012 @param[in] Interface Interface to remove the frames from.
1013 @param[in] IoStatus The transmit status returned to the frames' callback.
1014 @param[in] FrameToCancel Function to select the frame to cancel; NULL to select all.
1015 @param[in] Context Opaque parameters passed to FrameToCancel. Ignored if
1016 FrameToCancel is NULL.
1021 IN IP6_INTERFACE
*Interface
,
1022 IN EFI_STATUS IoStatus
,
1023 IN IP6_FRAME_TO_CANCEL FrameToCancel OPTIONAL
,
1024 IN VOID
*Context OPTIONAL
1029 IP6_LINK_TX_TOKEN
*Token
;
1031 IP6_NEIGHBOR_ENTRY
*ArpQue
;
1034 IpSb
= Interface
->Service
;
1035 NET_CHECK_SIGNATURE (IpSb
, IP6_SERVICE_SIGNATURE
);
1038 // Cancel all the pending frames on ARP requests
1040 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &Interface
->ArpQues
) {
1041 ArpQue
= NET_LIST_USER_STRUCT (Entry
, IP6_NEIGHBOR_ENTRY
, ArpList
);
1043 Status
= Ip6FreeNeighborEntry (
1052 ASSERT_EFI_ERROR (Status
);
1056 // Cancel all the frames that have been delivered to MNP
1057 // but not yet recycled.
1059 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &Interface
->SentFrames
) {
1060 Token
= NET_LIST_USER_STRUCT (Entry
, IP6_LINK_TX_TOKEN
, Link
);
1062 if ((FrameToCancel
== NULL
) || FrameToCancel (Token
, Context
)) {
1063 IpSb
->Mnp
->Cancel (IpSb
->Mnp
, &Token
->MnpToken
);
1069 Cancel the Packet and all its fragments.
1071 @param[in] IpIf The interface from which the Packet is sent.
1072 @param[in] Packet The Packet to cancel.
1073 @param[in] IoStatus The status returns to the sender.
1078 IN IP6_INTERFACE
*IpIf
,
1080 IN EFI_STATUS IoStatus
1083 Ip6CancelFrames (IpIf
, IoStatus
, Ip6CancelPacketFragments
, Packet
);