X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=NetworkPkg%2FUdp6Dxe%2FUdp6Impl.c;h=25336362b0c19515cd95ade036dd4e561bee8307;hb=728f8950d6aa5c050ee028eccaab47f0b3a06872;hp=3830b14415e6bdb2a8fcccd6b177c32a9ccd4b53;hpb=216f79703b8cb8dc65abdd768bedb2bcdbc1a1f8;p=mirror_edk2.git diff --git a/NetworkPkg/Udp6Dxe/Udp6Impl.c b/NetworkPkg/Udp6Dxe/Udp6Impl.c index 3830b14415..25336362b0 100644 --- a/NetworkPkg/Udp6Dxe/Udp6Impl.c +++ b/NetworkPkg/Udp6Dxe/Udp6Impl.c @@ -1,7 +1,7 @@ /** @file Udp6 driver's whole implementation. - Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -57,6 +57,9 @@ Udp6FindInstanceByPort ( interface. It's called to signal the udp TxToken when the IpIo layer completes transmitting of the udp datagram. + If Context is NULL, then ASSERT(). + If NotifyData is NULL, then ASSERT(). + @param[in] Status The completion status of the output udp datagram. @param[in] Context Pointer to the context data. @param[in] Sender Specify a EFI_IP6_PROTOCOL for sending. @@ -75,6 +78,10 @@ Udp6DgramSent ( /** This function processes the received datagram passed up by the IpIo layer. + If NetSession is NULL, then ASSERT(). + If Packet is NULL, then ASSERT(). + If Context is NULL, then ASSERT(). + @param[in] Status The status of this udp datagram. @param[in] IcmpError The IcmpError code, only available when Status is EFI_ICMP_ERROR. @@ -158,7 +165,8 @@ Udp6RecycleRxDataWrap ( @param[in] RxData Pointer to the EFI_UDP6_RECEIVE_DATA of this datagram. - @return Pointer to the structure wrapping the RxData and the Packet. + @return Pointer to the structure wrapping the RxData and the Packet. NULL will + be returned if any error occurs. **/ UDP6_RXDATA_WRAP * @@ -199,10 +207,10 @@ Udp6DeliverDgram ( ); /** - This function demultiplexes the received udp datagram to the apropriate instances. + This function demultiplexes the received udp datagram to the appropriate instances. @param[in] Udp6Service Pointer to the udp service context data. - @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstrated from + @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted from the received datagram. @param[in] Packet Pointer to the buffer containing the received udp datagram. @@ -364,7 +372,7 @@ ON_ERROR: IpIoDestroy (Udp6Service->IpIo); Udp6Service->IpIo = NULL; - + return Status; } @@ -390,7 +398,7 @@ Udp6CleanService ( // IpIoDestroy (Udp6Service->IpIo); Udp6Service->IpIo = NULL; - + ZeroMem (Udp6Service, sizeof (UDP6_SERVICE_DATA)); } @@ -976,6 +984,9 @@ Udp6RemoveToken ( interface. It's called to signal the udp TxToken when IpIo layer completes the transmitting of the udp datagram. + If Context is NULL, then ASSERT(). + If NotifyData is NULL, then ASSERT(). + @param[in] Status The completion status of the output udp datagram. @param[in] Context Pointer to the context data. @param[in] Sender Specify a EFI_IP6_PROTOCOL for sending. @@ -994,6 +1005,8 @@ Udp6DgramSent ( UDP6_INSTANCE_DATA *Instance; EFI_UDP6_COMPLETION_TOKEN *Token; + ASSERT (Context != NULL && NotifyData != NULL); + Instance = (UDP6_INSTANCE_DATA *) Context; Token = (EFI_UDP6_COMPLETION_TOKEN *) NotifyData; @@ -1011,6 +1024,10 @@ Udp6DgramSent ( /** This function processes the received datagram passed up by the IpIo layer. + If NetSession is NULL, then ASSERT(). + If Packet is NULL, then ASSERT(). + If Context is NULL, then ASSERT(). + @param[in] Status The status of this udp datagram. @param[in] IcmpError The IcmpError code, only available when Status is EFI_ICMP_ERROR. @@ -1030,6 +1047,7 @@ Udp6DgramRcvd ( IN VOID *Context ) { + ASSERT (NetSession != NULL && Packet != NULL && Context != NULL); NET_CHECK_SIGNATURE (Packet, NET_BUF_SIGNATURE); // @@ -1374,7 +1392,8 @@ Udp6RecycleRxDataWrap ( @param[in] RxData Pointer to the EFI_UDP6_RECEIVE_DATA of this datagram. - @return Pointer to the structure wrapping the RxData and the Packet. + @return Pointer to the structure wrapping the RxData and the Packet. NULL will + be returned if any error occurs. **/ UDP6_RXDATA_WRAP * @@ -1579,7 +1598,7 @@ Udp6DeliverDgram ( This function demultiplexes the received udp datagram to the appropriate instances. @param[in] Udp6Service Pointer to the udp service context data. - @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstrated from + @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted from the received datagram. @param[in] Packet Pointer to the buffer containing the received udp datagram. @@ -1598,11 +1617,20 @@ Udp6Demultiplex ( EFI_UDP6_SESSION_DATA *Udp6Session; UINTN Enqueued; + if (Packet->TotalSize < UDP6_HEADER_SIZE) { + NetbufFree (Packet); + return; + } + // // Get the datagram header from the packet buffer. // Udp6Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL); ASSERT (Udp6Header != NULL); + if (Udp6Header == NULL) { + NetbufFree (Packet); + return; + } if (Udp6Header->Checksum != 0) { // @@ -1619,12 +1647,11 @@ Udp6Demultiplex ( // // Wrong checksum. // + NetbufFree (Packet); return; } } - gRT->GetTime (&RxData.TimeStamp, NULL); - Udp6Session = &RxData.UdpSession; Udp6Session->SourcePort = NTOHS (Udp6Header->SrcPort); Udp6Session->DestinationPort = NTOHS (Udp6Header->DstPort); @@ -1714,6 +1741,9 @@ Udp6SendPortUnreach ( // Ip6ModeData = AllocateZeroPool (sizeof (EFI_IP6_MODE_DATA)); ASSERT (Ip6ModeData != NULL); + if (Ip6ModeData == NULL) { + goto EXIT; + } // // If not finding the related IpSender use the default IpIo to send out @@ -1762,6 +1792,9 @@ Udp6SendPortUnreach ( // IcmpErrHdr = (IP6_ICMP_ERROR_HEAD *) NetbufAllocSpace (Packet, Len, FALSE); ASSERT (IcmpErrHdr != NULL); + if (IcmpErrHdr == NULL) { + goto EXIT; + } // // Set the required fields for the icmp port unreachable message. @@ -1836,8 +1869,17 @@ Udp6IcmpHandler ( LIST_ENTRY *Entry; UDP6_INSTANCE_DATA *Instance; + if (Packet->TotalSize < UDP6_HEADER_SIZE) { + NetbufFree (Packet); + return; + } + Udp6Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL); ASSERT (Udp6Header != NULL); + if (Udp6Header == NULL) { + NetbufFree (Packet); + return; + } IP6_COPY_ADDRESS (&Udp6Session.SourceAddress, &NetSession->Source); IP6_COPY_ADDRESS (&Udp6Session.DestinationAddress, &NetSession->Dest); @@ -1935,174 +1977,6 @@ Udp6NetVectorExtFree ( { } - -/** - Set the Udp6 variable data. - - @param[in] Udp6Service Udp6 service data. - - @retval EFI_OUT_OF_RESOURCES There are not enough resources to set the - variable. - @retval other Set variable failed. - -**/ -EFI_STATUS -Udp6SetVariableData ( - IN UDP6_SERVICE_DATA *Udp6Service - ) -{ - UINT32 NumConfiguredInstance; - LIST_ENTRY *Entry; - UINTN VariableDataSize; - EFI_UDP6_VARIABLE_DATA *Udp6VariableData; - EFI_UDP6_SERVICE_POINT *Udp6ServicePoint; - UDP6_INSTANCE_DATA *Udp6Instance; - CHAR16 *NewMacString; - EFI_STATUS Status; - - NumConfiguredInstance = 0; - - // - // Go through the children list to count the configured children. - // - NET_LIST_FOR_EACH (Entry, &Udp6Service->ChildrenList) { - Udp6Instance = NET_LIST_USER_STRUCT_S ( - Entry, - UDP6_INSTANCE_DATA, - Link, - UDP6_INSTANCE_DATA_SIGNATURE - ); - - if (Udp6Instance->Configured) { - NumConfiguredInstance++; - } - } - - // - // Calculate the size of the Udp6VariableData. As there may be no Udp6 child, - // we should add extra buffer for the service points only if the number of configured - // children is more than 1. - // - VariableDataSize = sizeof (EFI_UDP6_VARIABLE_DATA); - - if (NumConfiguredInstance > 1) { - VariableDataSize += sizeof (EFI_UDP6_SERVICE_POINT) * (NumConfiguredInstance - 1); - } - - Udp6VariableData = AllocateZeroPool (VariableDataSize); - if (Udp6VariableData == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - Udp6VariableData->DriverHandle = Udp6Service->ImageHandle; - Udp6VariableData->ServiceCount = NumConfiguredInstance; - - Udp6ServicePoint = &Udp6VariableData->Services[0]; - - // - // Go through the children list to fill the configured children's address pairs. - // - NET_LIST_FOR_EACH (Entry, &Udp6Service->ChildrenList) { - Udp6Instance = NET_LIST_USER_STRUCT_S ( - Entry, - UDP6_INSTANCE_DATA, - Link, - UDP6_INSTANCE_DATA_SIGNATURE - ); - - if (Udp6Instance->Configured) { - Udp6ServicePoint->InstanceHandle = Udp6Instance->ChildHandle; - Udp6ServicePoint->LocalPort = Udp6Instance->ConfigData.StationPort; - Udp6ServicePoint->RemotePort = Udp6Instance->ConfigData.RemotePort; - - IP6_COPY_ADDRESS ( - &Udp6ServicePoint->LocalAddress, - &Udp6Instance->ConfigData.StationAddress - ); - IP6_COPY_ADDRESS ( - &Udp6ServicePoint->RemoteAddress, - &Udp6Instance->ConfigData.RemoteAddress - ); - Udp6ServicePoint++; - } - } - - // - // Get the MAC string. - // - Status = NetLibGetMacString ( - Udp6Service->ControllerHandle, - Udp6Service->ImageHandle, - &NewMacString - ); - if (EFI_ERROR (Status)) { - goto EXIT; - } - - if (Udp6Service->MacString != NULL) { - // - // The variable is set already, we're going to update it. - // - if (StrCmp (Udp6Service->MacString, NewMacString) != 0) { - // - // The MAC address is changed, delete the previous variable first. - // - gRT->SetVariable ( - Udp6Service->MacString, - &gEfiUdp6ServiceBindingProtocolGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS, - 0, - NULL - ); - } - - FreePool (Udp6Service->MacString); - } - - Udp6Service->MacString = NewMacString; - - Status = gRT->SetVariable ( - Udp6Service->MacString, - &gEfiUdp6ServiceBindingProtocolGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS, - VariableDataSize, - (VOID *) Udp6VariableData - ); - -EXIT: - - FreePool (Udp6VariableData); - - return Status; -} - - -/** - Clear the variable and free the resource. - - @param[in, out] Udp6Service Udp6 service data. - -**/ -VOID -Udp6ClearVariableData ( - IN OUT UDP6_SERVICE_DATA *Udp6Service - ) -{ - ASSERT (Udp6Service->MacString != NULL); - - gRT->SetVariable ( - Udp6Service->MacString, - &gEfiUdp6ServiceBindingProtocolGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS, - 0, - NULL - ); - - FreePool (Udp6Service->MacString); - Udp6Service->MacString = NULL; -} - - /** Find the key in the netmap.