X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FUdp4Dxe%2FUdp4Impl.c;h=ce952b1e2d19b148d41b88a607e682d79768b07e;hp=0f14021e2397407b9ae63f4103f1dd5ac6311f69;hb=d551cc64cdf1f943744294819220b78a60b10822;hpb=894d038a8d0e99d456042e2b6d1554c4a406ea70 diff --git a/MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c b/MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c index 0f14021e23..ce952b1e2d 100644 --- a/MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c +++ b/MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c @@ -1,8 +1,8 @@ /** @file The implementation of the Udp4 protocol. -Copyright (c) 2006 - 2009, Intel Corporation.
-All rights reserved. This program and the accompanying materials +Copyright (c) 2006 - 2014, 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 which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php @@ -59,16 +59,17 @@ Udp4FindInstanceByPort ( @param[in] Status The completion status of the output udp datagram. @param[in] Context Pointer to the context data. - @param[in] Sender Pointer to the Ip sender of the udp datagram. + @param[in] Sender Specify a pointer of EFI_IP4_PROTOCOL for sending. @param[in] NotifyData Pointer to the notify data. **/ VOID +EFIAPI Udp4DgramSent ( - IN EFI_STATUS Status, - IN VOID *Context, - IN VOID *Sender, - IN VOID *NotifyData + IN EFI_STATUS Status, + IN VOID *Context, + IN IP_IO_IP_PROTOCOL Sender, + IN VOID *NotifyData ); /** @@ -84,9 +85,10 @@ Udp4DgramSent ( **/ VOID +EFIAPI Udp4DgramRcvd ( IN EFI_STATUS Status, - IN ICMP_ERROR IcmpError, + IN UINT8 IcmpError, IN EFI_NET_SESSION_DATA *NetSession, IN NET_BUF *Packet, IN VOID *Context @@ -109,6 +111,7 @@ Udp4DgramRcvd ( **/ EFI_STATUS +EFIAPI Udp4CancelTokens ( IN NET_MAP *Map, IN NET_MAP_ITEM *Item, @@ -227,7 +230,7 @@ Udp4Demultiplex ( VOID Udp4IcmpHandler ( IN UDP4_SERVICE_DATA *Udp4Service, - IN ICMP_ERROR IcmpError, + IN UINT8 IcmpError, IN EFI_NET_SESSION_DATA *NetSession, IN NET_BUF *Packet ); @@ -253,14 +256,14 @@ Udp4SendPortUnreach ( /** Create the Udp service context data. - @param Udp4Service Pointer to the UDP4_SERVICE_DATA. - @param ImageHandle The image handle of this udp4 driver. - @param ControllerHandle The controller handle this udp4 driver binds on. + @param[in, out] Udp4Service Pointer to the UDP4_SERVICE_DATA. + @param[in] ImageHandle The image handle of this udp4 driver. + @param[in] ControllerHandle The controller handle this udp4 driver binds on. - @retval EFI_SUCCESS The udp4 service context data is created and - initialized. - @retval EFI_OUT_OF_RESOURCES Cannot allocate memory. - @retval other Other error occurs. + @retval EFI_SUCCESS The udp4 service context data is created and + initialized. + @retval EFI_OUT_OF_RESOURCES Cannot allocate memory. + @retval other Other error occurs. **/ EFI_STATUS @@ -270,8 +273,9 @@ Udp4CreateService ( IN EFI_HANDLE ControllerHandle ) { - EFI_STATUS Status; - IP_IO_OPEN_DATA OpenData; + EFI_STATUS Status; + IP_IO_OPEN_DATA OpenData; + EFI_IP4_CONFIG_DATA *Ip4ConfigData; ZeroMem (Udp4Service, sizeof (UDP4_SERVICE_DATA)); @@ -286,7 +290,7 @@ Udp4CreateService ( // // Create the IpIo for this service context. // - Udp4Service->IpIo = IpIoCreate (ImageHandle, ControllerHandle); + Udp4Service->IpIo = IpIoCreate (ImageHandle, ControllerHandle, IP_VERSION_4); if (Udp4Service->IpIo == NULL) { return EFI_OUT_OF_RESOURCES; } @@ -294,12 +298,13 @@ Udp4CreateService ( // // Set the OpenData used to open the IpIo. // - CopyMem (&OpenData.IpConfigData, &mIpIoDefaultIpConfigData, sizeof (OpenData.IpConfigData)); - OpenData.IpConfigData.AcceptBroadcast = TRUE; - OpenData.RcvdContext = (VOID *) Udp4Service; - OpenData.SndContext = NULL; - OpenData.PktRcvdNotify = Udp4DgramRcvd; - OpenData.PktSentNotify = Udp4DgramSent; + Ip4ConfigData = &OpenData.IpConfigData.Ip4CfgData; + CopyMem (Ip4ConfigData, &mIp4IoDefaultIpConfigData, sizeof (EFI_IP4_CONFIG_DATA)); + Ip4ConfigData->AcceptBroadcast = TRUE; + OpenData.RcvdContext = (VOID *) Udp4Service; + OpenData.SndContext = NULL; + OpenData.PktRcvdNotify = Udp4DgramRcvd; + OpenData.PktSentNotify = Udp4DgramSent; // // Configure and start the IpIo. @@ -424,9 +429,9 @@ Udp4CheckTimeout ( Wrap = NET_LIST_USER_STRUCT (WrapEntry, UDP4_RXDATA_WRAP, Link); // - // TimeoutTick unit is ms, MNP_TIMEOUT_CHECK_INTERVAL unit is 100ns. + // TimeoutTick unit is microsecond, MNP_TIMEOUT_CHECK_INTERVAL unit is 100ns. // - if (Wrap->TimeoutTick <= (UDP4_TIMEOUT_INTERVAL / 10)) { + if (Wrap->TimeoutTick < (UDP4_TIMEOUT_INTERVAL / 10)) { // // Remove this RxData if it timeouts. // @@ -442,8 +447,8 @@ Udp4CheckTimeout ( /** This function intializes the new created udp instance. - @param Udp4Service Pointer to the UDP4_SERVICE_DATA. - @param Instance Pointer to the un-initialized UDP4_INSTANCE_DATA. + @param[in] Udp4Service Pointer to the UDP4_SERVICE_DATA. + @param[in, out] Instance Pointer to the un-initialized UDP4_INSTANCE_DATA. **/ VOID @@ -479,7 +484,7 @@ Udp4InitInstance ( Instance->IcmpError = EFI_SUCCESS; Instance->Configured = FALSE; Instance->IsNoMapping = FALSE; - Instance->Destroyed = FALSE; + Instance->InDestroy = FALSE; } @@ -558,9 +563,9 @@ Udp4FindInstanceByPort ( This function tries to bind the udp instance according to the configured port allocation strategy. - @param InstanceList Pointer to the head of the list linking the udp + @param[in] InstanceList Pointer to the head of the list linking the udp instances. - @param ConfigData Pointer to the ConfigData of the instance to be + @param[in, out] ConfigData Pointer to the ConfigData of the instance to be bound. ConfigData->StationPort will be assigned with an available port value on success. @@ -731,7 +736,7 @@ Udp4BuildIp4ConfigData ( IN OUT EFI_IP4_CONFIG_DATA *Ip4ConfigData ) { - CopyMem (Ip4ConfigData, &mIpIoDefaultIpConfigData, sizeof (*Ip4ConfigData)); + CopyMem (Ip4ConfigData, &mIp4IoDefaultIpConfigData, sizeof (*Ip4ConfigData)); Ip4ConfigData->DefaultProtocol = EFI_IP_PROTO_UDP; Ip4ConfigData->AcceptBroadcast = Udp4ConfigData->AcceptBroadcast; @@ -822,7 +827,7 @@ Udp4ValidateTxToken ( if (TxData->GatewayAddress != NULL) { CopyMem (&GatewayAddress, TxData->GatewayAddress, sizeof (IP4_ADDR)); - if (!Ip4IsUnicast (NTOHL (GatewayAddress), 0)) { + if (!NetIp4IsUnicast (NTOHL (GatewayAddress), 0)) { // // The specified GatewayAddress is not a unicast IPv4 address while it's not 0. // @@ -837,7 +842,7 @@ Udp4ValidateTxToken ( CopyMem (&SourceAddress, &UdpSessionData->SourceAddress, sizeof (IP4_ADDR)); - if ((SourceAddress != 0) && !Ip4IsUnicast (HTONL (SourceAddress), 0)) { + if ((SourceAddress != 0) && !NetIp4IsUnicast (HTONL (SourceAddress), 0)) { // // Check whether SourceAddress is a valid IPv4 address in case it's not zero. // The configured station address is used if SourceAddress is zero. @@ -888,6 +893,7 @@ Udp4ValidateTxToken ( **/ EFI_STATUS +EFIAPI Udp4TokenExist ( IN NET_MAP *Map, IN NET_MAP_ITEM *Item, @@ -943,8 +949,8 @@ Udp4Checksum ( /** This function removes the specified Token from the TokenMap. - @param TokenMap Pointer to the NET_MAP containing the tokens. - @param Token Pointer to the Token to be removed. + @param[in, out] TokenMap Pointer to the NET_MAP containing the tokens. + @param[in] Token Pointer to the Token to be removed. @retval EFI_SUCCESS The specified Token is removed from the TokenMap. @retval EFI_NOT_FOUND The specified Token is not found in the TokenMap. @@ -983,16 +989,17 @@ Udp4RemoveToken ( @param[in] Status The completion status of the output udp datagram. @param[in] Context Pointer to the context data. - @param[in] Sender Pointer to the Ip sender of the udp datagram. + @param[in] Sender Specify a pointer of EFI_IP4_PROTOCOL for sending. @param[in] NotifyData Pointer to the notify data. **/ VOID +EFIAPI Udp4DgramSent ( - IN EFI_STATUS Status, - IN VOID *Context, - IN VOID *Sender, - IN VOID *NotifyData + IN EFI_STATUS Status, + IN VOID *Context, + IN IP_IO_IP_PROTOCOL Sender, + IN VOID *NotifyData ) { UDP4_INSTANCE_DATA *Instance; @@ -1007,7 +1014,7 @@ Udp4DgramSent ( // Token->Status = Status; gBS->SignalEvent (Token->Event); - NetLibDispatchDpc (); + DispatchDpc (); } } @@ -1025,9 +1032,10 @@ Udp4DgramSent ( **/ VOID +EFIAPI Udp4DgramRcvd ( IN EFI_STATUS Status, - IN ICMP_ERROR IcmpError, + IN UINT8 IcmpError, IN EFI_NET_SESSION_DATA *NetSession, IN NET_BUF *Packet, IN VOID *Context @@ -1054,16 +1062,16 @@ Udp4DgramRcvd ( // Dispatch the DPC queued by the NotifyFunction of the rx token's events // which are signaled with received data. // - NetLibDispatchDpc (); + DispatchDpc (); } /** This function removes the multicast group specified by Arg from the Map. - @param Map Pointer to the NET_MAP. - @param Item Pointer to the NET_MAP_ITEM. - @param Arg Pointer to the Arg, it's the pointer to a + @param[in, out] Map Pointer to the NET_MAP. + @param[in] Item Pointer to the NET_MAP_ITEM. + @param[in] Arg Pointer to the Arg, it's the pointer to a multicast IPv4 Address. @retval EFI_SUCCESS The multicast address is removed. @@ -1072,6 +1080,7 @@ Udp4DgramRcvd ( **/ EFI_STATUS +EFIAPI Udp4LeaveGroup ( IN OUT NET_MAP *Map, IN NET_MAP_ITEM *Item, @@ -1123,6 +1132,7 @@ Udp4LeaveGroup ( **/ EFI_STATUS +EFIAPI Udp4CancelTokens ( IN NET_MAP *Map, IN NET_MAP_ITEM *Item, @@ -1361,7 +1371,7 @@ Udp4RecycleRxDataWrap ( // gBS->CloseEvent (Wrap->RxData.RecycleSignal); - gBS->FreePool (Wrap); + FreePool (Wrap); } @@ -1411,7 +1421,7 @@ Udp4WrapRxData ( &Wrap->RxData.RecycleSignal ); if (EFI_ERROR (Status)) { - gBS->FreePool (Wrap); + FreePool (Wrap); return NULL; } @@ -1592,7 +1602,7 @@ Udp4Demultiplex ( IN NET_BUF *Packet ) { - EFI_UDP4_HEADER *Udp4Header; + EFI_UDP_HEADER *Udp4Header; UINT16 HeadSum; EFI_UDP4_RECEIVE_DATA RxData; EFI_UDP4_SESSION_DATA *Udp4Session; @@ -1601,15 +1611,16 @@ Udp4Demultiplex ( // // Get the datagram header from the packet buffer. // - Udp4Header = (EFI_UDP4_HEADER *) NetbufGetByte (Packet, 0, NULL); + Udp4Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL); + ASSERT (Udp4Header != NULL); if (Udp4Header->Checksum != 0) { // // check the checksum. // HeadSum = NetPseudoHeadChecksum ( - NetSession->Source, - NetSession->Dest, + NetSession->Source.Addr[0], + NetSession->Dest.Addr[0], EFI_IP_PROTO_UDP, 0 ); @@ -1622,8 +1633,6 @@ Udp4Demultiplex ( } } - gRT->GetTime (&RxData.TimeStamp, NULL); - Udp4Session = &RxData.UdpSession; Udp4Session->SourcePort = NTOHS (Udp4Header->SrcPort); Udp4Session->DestinationPort = NTOHS (Udp4Header->DstPort); @@ -1689,7 +1698,7 @@ Udp4SendPortUnreach ( IP_IO_OVERRIDE Override; IP_IO_IP_INFO *IpSender; - IpSender = IpIoFindSender (&IpIo, NetSession->Dest); + IpSender = IpIoFindSender (&IpIo, NetSession->IpVersion, &NetSession->Dest); if (IpSender == NULL) { // // No apropriate sender, since we cannot send out the ICMP message through @@ -1698,7 +1707,7 @@ Udp4SendPortUnreach ( return; } - IpHdr = NetSession->IpHdr; + IpHdr = NetSession->IpHdr.Ip4Hdr; // // Calculate the requried length of the icmp error message. @@ -1747,18 +1756,18 @@ Udp4SendPortUnreach ( // // Fill the override data. // - Override.DoNotFragment = FALSE; - Override.TypeOfService = 0; - Override.TimeToLive = 255; - Override.Protocol = EFI_IP_PROTO_ICMP; + Override.Ip4OverrideData.DoNotFragment = FALSE; + Override.Ip4OverrideData.TypeOfService = 0; + Override.Ip4OverrideData.TimeToLive = 255; + Override.Ip4OverrideData.Protocol = EFI_IP_PROTO_ICMP; - CopyMem (&Override.SourceAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS)); - ZeroMem (&Override.GatewayAddress, sizeof (EFI_IPv4_ADDRESS)); + CopyMem (&Override.Ip4OverrideData.SourceAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS)); + ZeroMem (&Override.Ip4OverrideData.GatewayAddress, sizeof (EFI_IPv4_ADDRESS)); // // Send out this icmp packet. // - IpIoSend (IpIo, Packet, IpSender, NULL, NULL, NetSession->Source, &Override); + IpIoSend (IpIo, Packet, IpSender, NULL, NULL, &NetSession->Source, &Override); NetbufFree (Packet); } @@ -1778,17 +1787,18 @@ Udp4SendPortUnreach ( VOID Udp4IcmpHandler ( IN UDP4_SERVICE_DATA *Udp4Service, - IN ICMP_ERROR IcmpError, + IN UINT8 IcmpError, IN EFI_NET_SESSION_DATA *NetSession, IN NET_BUF *Packet ) { - EFI_UDP4_HEADER *Udp4Header; + EFI_UDP_HEADER *Udp4Header; EFI_UDP4_SESSION_DATA Udp4Session; LIST_ENTRY *Entry; UDP4_INSTANCE_DATA *Instance; - Udp4Header = (EFI_UDP4_HEADER *) NetbufGetByte (Packet, 0, NULL); + Udp4Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL); + ASSERT (Udp4Header != NULL); CopyMem (&Udp4Session.SourceAddress, &NetSession->Source, sizeof (EFI_IPv4_ADDRESS)); CopyMem (&Udp4Session.DestinationAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS)); @@ -1802,16 +1812,7 @@ Udp4IcmpHandler ( // Instance = NET_LIST_USER_STRUCT (Entry, UDP4_INSTANCE_DATA, Link); - if (!Instance->Configured || - Instance->ConfigData.AcceptPromiscuous || - Instance->ConfigData.AcceptAnyPort || - EFI_IP4_EQUAL (&Instance->ConfigData.StationAddress, &mZeroIp4Addr) - ) { - // - // Don't try to deliver the ICMP error to this instance if it is not configured, - // or it's configured to be promiscuous or accept any port or accept all the - // datagrams. - // + if (!Instance->Configured) { continue; } @@ -1819,7 +1820,7 @@ Udp4IcmpHandler ( // // Translate the Icmp Error code according to the udp spec. // - Instance->IcmpError = IpIoGetIcmpErrStatus (IcmpError, NULL, NULL); + Instance->IcmpError = IpIoGetIcmpErrStatus (IcmpError, IP_VERSION_4, NULL, NULL); if (IcmpError > ICMP_ERR_UNREACH_PORT) { Instance->IcmpError = EFI_ICMP_ERROR; @@ -1888,170 +1889,9 @@ Udp4ReportIcmpError ( **/ VOID +EFIAPI Udp4NetVectorExtFree ( VOID *Context ) { -} - - -/** - Set the Udp4 variable data. - - @param Udp4Service Udp4 service data. - - @retval EFI_OUT_OF_RESOURCES There are not enough resources to set the - variable. - @retval EFI_SUCCESS Set variable successfully. - @retval other Set variable failed. - -**/ -EFI_STATUS -Udp4SetVariableData ( - IN UDP4_SERVICE_DATA *Udp4Service - ) -{ - UINT32 NumConfiguredInstance; - LIST_ENTRY *Entry; - UINTN VariableDataSize; - EFI_UDP4_VARIABLE_DATA *Udp4VariableData; - EFI_UDP4_SERVICE_POINT *Udp4ServicePoint; - UDP4_INSTANCE_DATA *Udp4Instance; - CHAR16 *NewMacString; - EFI_STATUS Status; - - NumConfiguredInstance = 0; - - // - // Go through the children list to count the configured children. - // - NET_LIST_FOR_EACH (Entry, &Udp4Service->ChildrenList) { - Udp4Instance = NET_LIST_USER_STRUCT_S ( - Entry, - UDP4_INSTANCE_DATA, - Link, - UDP4_INSTANCE_DATA_SIGNATURE - ); - - if (Udp4Instance->Configured) { - NumConfiguredInstance++; - } - } - - // - // Calculate the size of the Udp4VariableData. As there may be no Udp4 child, - // we should add extra buffer for the service points only if the number of configured - // children is more than 1. - // - VariableDataSize = sizeof (EFI_UDP4_VARIABLE_DATA); - - if (NumConfiguredInstance > 1) { - VariableDataSize += sizeof (EFI_UDP4_SERVICE_POINT) * (NumConfiguredInstance - 1); - } - - Udp4VariableData = AllocatePool (VariableDataSize); - if (Udp4VariableData == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - Udp4VariableData->DriverHandle = Udp4Service->ImageHandle; - Udp4VariableData->ServiceCount = NumConfiguredInstance; - - Udp4ServicePoint = &Udp4VariableData->Services[0]; - - // - // Go through the children list to fill the configured children's address pairs. - // - NET_LIST_FOR_EACH (Entry, &Udp4Service->ChildrenList) { - Udp4Instance = NET_LIST_USER_STRUCT_S ( - Entry, - UDP4_INSTANCE_DATA, - Link, - UDP4_INSTANCE_DATA_SIGNATURE - ); - - if (Udp4Instance->Configured) { - Udp4ServicePoint->InstanceHandle = Udp4Instance->ChildHandle; - Udp4ServicePoint->LocalAddress = Udp4Instance->ConfigData.StationAddress; - Udp4ServicePoint->LocalPort = Udp4Instance->ConfigData.StationPort; - Udp4ServicePoint->RemoteAddress = Udp4Instance->ConfigData.RemoteAddress; - Udp4ServicePoint->RemotePort = Udp4Instance->ConfigData.RemotePort; - - Udp4ServicePoint++; - } - } - - // - // Get the mac string. - // - Status = NetLibGetMacString ( - Udp4Service->ControllerHandle, - Udp4Service->ImageHandle, - &NewMacString - ); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - if (Udp4Service->MacString != NULL) { - // - // The variable is set already, we're going to update it. - // - if (StrCmp (Udp4Service->MacString, NewMacString) != 0) { - // - // The mac address is changed, delete the previous variable first. - // - gRT->SetVariable ( - Udp4Service->MacString, - &gEfiUdp4ServiceBindingProtocolGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS, - 0, - NULL - ); - } - - gBS->FreePool (Udp4Service->MacString); - } - - Udp4Service->MacString = NewMacString; - - Status = gRT->SetVariable ( - Udp4Service->MacString, - &gEfiUdp4ServiceBindingProtocolGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS, - VariableDataSize, - (VOID *) Udp4VariableData - ); - -ON_ERROR: - - gBS->FreePool (Udp4VariableData); - - return Status; -} - - -/** - Clear the variable and free the resource. - - @param[[in] Udp4Service Udp4 service data. - -**/ -VOID -Udp4ClearVariableData ( - IN UDP4_SERVICE_DATA *Udp4Service - ) -{ - ASSERT (Udp4Service->MacString != NULL); - - gRT->SetVariable ( - Udp4Service->MacString, - &gEfiUdp4ServiceBindingProtocolGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS, - 0, - NULL - ); - - gBS->FreePool (Udp4Service->MacString); - Udp4Service->MacString = NULL; -} +} \ No newline at end of file