X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FDhcp4Dxe%2FDhcp4Impl.c;h=f470844ee4d9930b975900cd3867290b1a41bc51;hp=e964f6b292615023ea066344b53758e7bf6acb30;hb=dd29f3edb9849b7bb51f0ae4be8941a760846ef3;hpb=3e8c18da0441069591e5aa218f378001b29512dd diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c index e964f6b292..f470844ee4 100644 --- a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c +++ b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c @@ -1,7 +1,7 @@ /** @file This file implement the EFI_DHCP4_PROTOCOL interface. - -Copyright (c) 2006 - 2008, Intel Corporation.
+ +Copyright (c) 2006 - 2010, 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 @@ -17,7 +17,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. /** Returns the current operating mode and cached data packet for the EFI DHCPv4 Protocol driver. - + The GetModeData() function returns the current operating mode and cached data packet for the EFI DHCPv4 Protocol driver. @@ -82,7 +82,7 @@ EFIAPI EfiDhcp4Configure ( IN EFI_DHCP4_PROTOCOL *This, IN EFI_DHCP4_CONFIG_DATA *Dhcp4CfgData OPTIONAL - ); + ); /** Starts the DHCP configuration process. @@ -100,7 +100,7 @@ EfiDhcp4Configure ( time when each event occurs in this process, the callback function that was set by EFI_DHCP4_PROTOCOL.Configure() will be called and the user can take this opportunity to control the process. - + @param[in] This Pointer to the EFI_DHCP4_PROTOCOL instance. @param[in] CompletionEvent If not NULL, indicates the event that will be signaled when the EFI DHCPv4 Protocol driver is transferred into the @@ -133,7 +133,7 @@ EfiDhcp4Start ( /** Extends the lease time by sending a request packet. - + The RenewRebind() function is used to manually extend the lease time when the EFI DHCPv4 Protocol driver is in the Dhcp4Bound state and the lease time has not expired yet. This function will send a request packet to the previously @@ -206,7 +206,7 @@ EfiDhcp4Release ( /** Stops the current address configuration. - + The Stop() function is used to stop the DHCP configuration process. After this function is called successfully, the EFI DHCPv4 Protocol driver is transferred into the Dhcp4Stopped state. EFI_DHCP4_PROTOCOL.Configure() needs to be called @@ -263,10 +263,10 @@ EfiDhcp4Build ( IN EFI_DHCP4_PACKET_OPTION *AppendList[] OPTIONAL, OUT EFI_DHCP4_PACKET **NewPacket ); - + /** Transmits a DHCP formatted packet and optionally waits for responses. - + The TransmitReceive() function is used to transmit a DHCP packet and optionally wait for the response from servers. This function does not change the state of the EFI DHCPv4 Protocol driver and thus can be used at any time. @@ -292,13 +292,13 @@ EfiDhcp4TransmitReceive ( /** Parses the packed DHCP option data. - + The Parse() function is used to retrieve the option list from a DHCP packet. - If *OptionCount isn’t zero, and there is enough space for all the DHCP options + If *OptionCount isn't zero, and there is enough space for all the DHCP options in the Packet, each element of PacketOptionList is set to point to somewhere in the Packet->Dhcp4.Option where a new DHCP option begins. If RFC3396 is supported, the caller should reassemble the parsed DHCP options to get the finial result. - If *OptionCount is zero or there isn’t enough space for all of them, the number + If *OptionCount is zero or there isn't enough space for all of them, the number of DHCP options in the Packet is returned in OptionCount. @param This Pointer to the EFI_DHCP4_PROTOCOL instance. @@ -340,7 +340,7 @@ EFI_DHCP4_PROTOCOL mDhcp4ProtocolTemplate = { /** Returns the current operating mode and cached data packet for the EFI DHCPv4 Protocol driver. - + The GetModeData() function returns the current operating mode and cached data packet for the EFI DHCPv4 Protocol driver. @@ -427,21 +427,21 @@ DhcpCleanConfigure ( UINT32 Index; if (Config->DiscoverTimeout != NULL) { - gBS->FreePool (Config->DiscoverTimeout); + FreePool (Config->DiscoverTimeout); } if (Config->RequestTimeout != NULL) { - gBS->FreePool (Config->RequestTimeout); + FreePool (Config->RequestTimeout); } if (Config->OptionList != NULL) { for (Index = 0; Index < Config->OptionCount; Index++) { if (Config->OptionList[Index] != NULL) { - gBS->FreePool (Config->OptionList[Index]); + FreePool (Config->OptionList[Index]); } } - gBS->FreePool (Config->OptionList); + FreePool (Config->OptionList); } ZeroMem (Config, sizeof (EFI_DHCP4_CONFIG_DATA)); @@ -564,14 +564,14 @@ DhcpYieldControl ( DhcpSb->ActiveChild = NULL; if (Config->DiscoverTimeout != NULL) { - gBS->FreePool (Config->DiscoverTimeout); + FreePool (Config->DiscoverTimeout); Config->DiscoverTryCount = 0; Config->DiscoverTimeout = NULL; } if (Config->RequestTimeout != NULL) { - gBS->FreePool (Config->RequestTimeout); + FreePool (Config->RequestTimeout); Config->RequestTryCount = 0; Config->RequestTimeout = NULL; @@ -647,21 +647,21 @@ EfiDhcp4Configure ( } if (Dhcp4CfgData != NULL) { - if (Dhcp4CfgData->DiscoverTryCount && (Dhcp4CfgData->DiscoverTimeout == NULL)) { + if ((Dhcp4CfgData->DiscoverTryCount != 0) && (Dhcp4CfgData->DiscoverTimeout == NULL)) { return EFI_INVALID_PARAMETER; } - if (Dhcp4CfgData->RequestTryCount && (Dhcp4CfgData->RequestTimeout == NULL)) { + if ((Dhcp4CfgData->RequestTryCount != 0) && (Dhcp4CfgData->RequestTimeout == NULL)) { return EFI_INVALID_PARAMETER; } - if (Dhcp4CfgData->OptionCount && (Dhcp4CfgData->OptionList == NULL)) { + if ((Dhcp4CfgData->OptionCount != 0) && (Dhcp4CfgData->OptionList == NULL)) { return EFI_INVALID_PARAMETER; } CopyMem (&Ip, &Dhcp4CfgData->ClientAddress, sizeof (IP4_ADDR)); - if ((Ip != 0) && !Ip4IsUnicast (NTOHL (Ip), 0)) { + if ((Ip != 0) && !NetIp4IsUnicast (NTOHL (Ip), 0)) { return EFI_INVALID_PARAMETER; } @@ -748,7 +748,7 @@ ON_EXIT: time when each event occurs in this process, the callback function that was set by EFI_DHCP4_PROTOCOL.Configure() will be called and the user can take this opportunity to control the process. - + @param[in] This Pointer to the EFI_DHCP4_PROTOCOL instance. @param[in] CompletionEvent If not NULL, indicates the event that will be signaled when the EFI DHCPv4 Protocol driver is transferred into the @@ -770,6 +770,7 @@ ON_EXIT: @retval EFI_ALREADY_STARTED Some other EFI DHCPv4 Protocol instance already started the DHCP process. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. + @retval EFI_NO_MEDIA There was a media error. **/ EFI_STATUS @@ -816,14 +817,6 @@ EfiDhcp4Start ( goto ON_ERROR; } - // - // Start/Restart the receiving. - // - Status = UdpIoRecvDatagram (DhcpSb->UdpIo, DhcpInput, DhcpSb, 0); - - if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) { - goto ON_ERROR; - } Instance->CompletionEvent = CompletionEvent; @@ -834,7 +827,7 @@ EfiDhcp4Start ( if (CompletionEvent == NULL) { while (DhcpSb->IoStatus == EFI_ALREADY_STARTED) { - DhcpSb->UdpIo->Udp->Poll (DhcpSb->UdpIo->Udp); + DhcpSb->UdpIo->Protocol.Udp4->Poll (DhcpSb->UdpIo->Protocol.Udp4); } return DhcpSb->IoStatus; @@ -850,7 +843,7 @@ ON_ERROR: /** Extends the lease time by sending a request packet. - + The RenewRebind() function is used to manually extend the lease time when the EFI DHCPv4 Protocol driver is in the Dhcp4Bound state and the lease time has not expired yet. This function will send a request packet to the previously @@ -959,7 +952,8 @@ EfiDhcp4RenewRebind ( if (CompletionEvent == NULL) { while (DhcpSb->IoStatus == EFI_ALREADY_STARTED) { - DhcpSb->UdpIo->Udp->Poll (DhcpSb->UdpIo->Udp); + DhcpSb->UdpIo->Protocol.Udp4->Poll (DhcpSb->UdpIo->Protocol.Udp4); + } return DhcpSb->IoStatus; @@ -1052,7 +1046,7 @@ ON_EXIT: /** Stops the current address configuration. - + The Stop() function is used to stop the DHCP configuration process. After this function is called successfully, the EFI DHCPv4 Protocol driver is transferred into the Dhcp4Stopped state. EFI_DHCP4_PROTOCOL.Configure() needs to be called @@ -1172,16 +1166,16 @@ EfiDhcp4Build ( /** Callback by UdpIoCreatePort() when creating UdpIo for this Dhcp4 instance. - + @param[in] UdpIo The UdpIo being created. @param[in] Context Dhcp4 instance. - + @retval EFI_SUCCESS UdpIo is configured successfully. @retval other Other error occurs. **/ EFI_STATUS Dhcp4InstanceConfigUdpIo ( - IN UDP_IO_PORT *UdpIo, + IN UDP_IO *UdpIo, IN VOID *Context ) { @@ -1214,14 +1208,14 @@ Dhcp4InstanceConfigUdpIo ( UdpConfigData.StationPort = Token->ListenPoints[0].ListenPort; } - return UdpIo->Udp->Configure (UdpIo->Udp, &UdpConfigData); + return UdpIo->Protocol.Udp4->Configure (UdpIo->Protocol.Udp4, &UdpConfigData); } /** Create UdpIo for this Dhcp4 instance. - + @param Instance The Dhcp4 instance. - + @retval EFI_SUCCESS UdpIo is created successfully. @retval EFI_OUT_OF_RESOURCES Fails to create UdpIo because of limited resources or configuration failure. @@ -1236,7 +1230,13 @@ Dhcp4InstanceCreateUdpIo ( ASSERT (Instance->Token != NULL); DhcpSb = Instance->Service; - Instance->UdpIo = UdpIoCreatePort (DhcpSb->Controller, DhcpSb->Image, Dhcp4InstanceConfigUdpIo, Instance); + Instance->UdpIo = UdpIoCreateIo ( + DhcpSb->Controller, + DhcpSb->Image, + Dhcp4InstanceConfigUdpIo, + UDP_IO_UDP4_VERSION, + Instance + ); if (Instance->UdpIo == NULL) { return EFI_OUT_OF_RESOURCES; } else { @@ -1246,7 +1246,7 @@ Dhcp4InstanceCreateUdpIo ( /** Callback of Dhcp packet. Does nothing. - + @param Arg The context. **/ @@ -1259,20 +1259,20 @@ DhcpDummyExtFree ( /** Callback of UdpIoRecvDatagram() that handles a Dhcp4 packet. - + Only BOOTP responses will be handled that correspond to the Xid of the request sent out. The packet will be queued to the response queue. - + @param UdpPacket The Dhcp4 packet. - @param Points Udp4 address pair. + @param EndPoint Udp4 address pair. @param IoStatus Status of the input. @param Context Extra info for the input. - + **/ VOID PxeDhcpInput ( NET_BUF *UdpPacket, - UDP_POINTS *Points, + UDP_END_POINT *EndPoint, EFI_STATUS IoStatus, VOID *Context ) @@ -1313,12 +1313,13 @@ PxeDhcpInput ( // Len = NET_ROUNDUP (sizeof (EFI_DHCP4_PACKET) + UdpPacket->TotalSize - sizeof (EFI_DHCP4_HEADER), 4); Wrap = NetbufAlloc (Len); - if (Wrap == NULL) { goto RESTART; } Packet = (EFI_DHCP4_PACKET *) NetbufAllocSpace (Wrap, Len, NET_BUF_TAIL); + ASSERT (Packet != NULL); + Packet->Size = Len; Head = &Packet->Dhcp4.Header; Packet->Length = NetbufCopy (UdpPacket, 0, UdpPacket->TotalSize, (UINT8 *) Head); @@ -1368,7 +1369,7 @@ RESTART: /** Complete a Dhcp4 transaction and signal the upper layer. - + @param Instance Dhcp4 instance. **/ @@ -1404,8 +1405,8 @@ SIGNAL_USER: // Clean up the resources dedicated for this transmit receive transaction. // NetbufQueFlush (&Instance->ResponseQueue); - UdpIoCleanPort (Instance->UdpIo); - UdpIoFreePort (Instance->UdpIo); + UdpIoCleanIo (Instance->UdpIo); + UdpIoFreeIo (Instance->UdpIo); Instance->UdpIo = NULL; Instance->Token = NULL; @@ -1417,7 +1418,7 @@ SIGNAL_USER: /** Transmits a DHCP formatted packet and optionally waits for responses. - + The TransmitReceive() function is used to transmit a DHCP packet and optionally wait for the response from servers. This function does not change the state of the EFI DHCPv4 Protocol driver and thus can be used at any time. @@ -1446,10 +1447,10 @@ EfiDhcp4TransmitReceive ( EFI_STATUS Status; NET_FRAGMENT Frag; NET_BUF *Wrap; - UDP_POINTS EndPoint; + UDP_END_POINT EndPoint; IP4_ADDR Ip; DHCP_SERVICE *DhcpSb; - IP4_ADDR Gateway; + EFI_IP_ADDRESS Gateway; IP4_ADDR SubnetMask; if ((This == NULL) || (Token == NULL) || (Token->Packet == NULL)) { @@ -1523,16 +1524,15 @@ EfiDhcp4TransmitReceive ( } // - // Set the local address and local port. + // Set the local address and local port to ZERO. // - EndPoint.LocalAddr = 0; - EndPoint.LocalPort = 0; + ZeroMem (&EndPoint, sizeof (UDP_END_POINT)); // // Set the destination address and destination port. // CopyMem (&Ip, &Token->RemoteAddress, sizeof (EFI_IPv4_ADDRESS)); - EndPoint.RemoteAddr = NTOHL (Ip); + EndPoint.RemoteAddr.Addr[0] = NTOHL (Ip); if (Token->RemotePort == 0) { EndPoint.RemotePort = DHCP_SERVER_PORT; @@ -1544,16 +1544,16 @@ EfiDhcp4TransmitReceive ( // Get the gateway. // SubnetMask = DhcpSb->Netmask; - Gateway = 0; - if (!IP4_NET_EQUAL (DhcpSb->ClientAddr, EndPoint.RemoteAddr, SubnetMask)) { - CopyMem (&Gateway, &Token->GatewayAddress, sizeof (EFI_IPv4_ADDRESS)); - Gateway = NTOHL (Gateway); + ZeroMem (&Gateway, sizeof (Gateway)); + if (!IP4_NET_EQUAL (DhcpSb->ClientAddr, EndPoint.RemoteAddr.Addr[0], SubnetMask)) { + CopyMem (&Gateway.v4, &Token->GatewayAddress, sizeof (EFI_IPv4_ADDRESS)); + Gateway.Addr[0] = NTOHL (Gateway.Addr[0]); } // // Transmit the DHCP packet. // - Status = UdpIoSendDatagram (Instance->UdpIo, Wrap, &EndPoint, Gateway, DhcpOnPacketSent, NULL); + Status = UdpIoSendDatagram (Instance->UdpIo, Wrap, &EndPoint, &Gateway, DhcpOnPacketSent, NULL); if (EFI_ERROR (Status)) { NetbufFree (Wrap); goto ON_ERROR; @@ -1570,8 +1570,8 @@ EfiDhcp4TransmitReceive ( ON_ERROR: if (EFI_ERROR (Status) && (Instance->UdpIo != NULL)) { - UdpIoCleanPort (Instance->UdpIo); - UdpIoFreePort (Instance->UdpIo); + UdpIoCleanIo (Instance->UdpIo); + UdpIoFreeIo (Instance->UdpIo); Instance->UdpIo = NULL; Instance->Token = NULL; } @@ -1583,8 +1583,19 @@ ON_ERROR: // Keep polling until timeout if no error happens and the CompletionEvent // is NULL. // - while (Instance->Timeout != 0) { - Instance->UdpIo->Udp->Poll (Instance->UdpIo->Udp); + while (TRUE) { + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); + // + // Raise TPL to protect the UDPIO in instance, in case that DhcpOnTimerTick + // free it when timeout. + // + if (Instance->Timeout > 0) { + Instance->UdpIo->Protocol.Udp4->Poll (Instance->UdpIo->Protocol.Udp4); + gBS->RestoreTPL (OldTpl); + } else { + gBS->RestoreTPL (OldTpl); + break; + } } } @@ -1633,13 +1644,13 @@ Dhcp4ParseCheckOption ( /** Parses the packed DHCP option data. - + The Parse() function is used to retrieve the option list from a DHCP packet. - If *OptionCount isn’t zero, and there is enough space for all the DHCP options + If *OptionCount isn't zero, and there is enough space for all the DHCP options in the Packet, each element of PacketOptionList is set to point to somewhere in the Packet->Dhcp4.Option where a new DHCP option begins. If RFC3396 is supported, the caller should reassemble the parsed DHCP options to get the finial result. - If *OptionCount is zero or there isn’t enough space for all of them, the number + If *OptionCount is zero or there isn't enough space for all of them, the number of DHCP options in the Packet is returned in OptionCount. @param This Pointer to the EFI_DHCP4_PROTOCOL instance.