X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FDhcp4Dxe%2FDhcp4Io.c;h=19ad101d5404d812998568727fdbb7175f43e72c;hp=56b03a8a596cebd96ad16be354e78ba6fa3f3243;hb=75dce340624dba5e4a79b2e5b2dbe943bae0d0e9;hpb=e798cd87ca9a3a30c4cea50c5f5de84e10a8bc5a diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c index 56b03a8a59..19ad101d54 100644 --- a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c +++ b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c @@ -1,8 +1,8 @@ /** @file EFI DHCP protocol implementation. -Copyright (c) 2006 - 2010, Intel Corporation.
-All rights reserved. This program and the accompanying materials +Copyright (c) 2006 - 2012, 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 @@ -37,6 +37,11 @@ DhcpInitRequest ( ASSERT ((DhcpSb->DhcpState == Dhcp4Init) || (DhcpSb->DhcpState == Dhcp4InitReboot)); + // + // Clear initial time to make sure that elapsed-time is set to 0 for first Discover or REQUEST message. + // + DhcpSb->ActiveChild->ElaspedTime= 0; + if (DhcpSb->DhcpState == Dhcp4Init) { DhcpSetState (DhcpSb, Dhcp4Selecting, FALSE); Status = DhcpSendMessage (DhcpSb, NULL, NULL, DHCP_MSG_DISCOVER, NULL); @@ -967,11 +972,11 @@ DhcpInput ( DhcpSb = (DHCP_SERVICE *) Context; // - // Don't restart receive if error occurs or DHCP is destoried. + // Don't restart receive if error occurs or DHCP is destroyed. // if (EFI_ERROR (IoStatus)) { return ; - } else if (DhcpSb->ServiceState == DHCP_DESTORY) { + } else if (DhcpSb->ServiceState == DHCP_DESTROY) { NetbufFree (UdpPacket); return ; } @@ -1218,6 +1223,17 @@ DhcpSendMessage ( EFI_IP4 (Head->ClientAddr) = HTONL (DhcpSb->ClientAddr); CopyMem (Head->ClientHwAddr, DhcpSb->Mac.Addr, DhcpSb->HwLen); + if ((Type == DHCP_MSG_DECLINE) || (Type == DHCP_MSG_RELEASE)) { + Head->Seconds = 0; + } else if ((Type == DHCP_MSG_REQUEST) && (DhcpSb->DhcpState == Dhcp4Requesting)) { + // + // Use the same value as the original DHCPDISCOVER message. + // + Head->Seconds = DhcpSb->LastPacket->Dhcp4.Header.Seconds; + } else { + SetElapsedTime(&Head->Seconds, DhcpSb->ActiveChild); + } + // // Append the DHCP message type // @@ -1429,7 +1445,12 @@ DhcpRetransmit ( ASSERT (DhcpSb->LastPacket != NULL); - DhcpSb->LastPacket->Dhcp4.Header.Seconds = HTONS (*(UINT16 *)(&DhcpSb->LastTimeout)); + // + // For REQUEST message in Dhcp4Requesting state, do not change the secs fields. + // + if (DhcpSb->DhcpState != Dhcp4Requesting) { + SetElapsedTime(&DhcpSb->LastPacket->Dhcp4.Header.Seconds, DhcpSb->ActiveChild); + } // // Wrap it into a netbuf then send it. @@ -1502,6 +1523,13 @@ DhcpOnTimerTick ( DhcpSb = (DHCP_SERVICE *) Context; Instance = DhcpSb->ActiveChild; + + // + // 0xffff is the maximum supported value for elapsed time according to RFC. + // + if (Instance != NULL && Instance->ElaspedTime < 0xffff) { + Instance->ElaspedTime++; + } // // Check the retransmit timer @@ -1516,8 +1544,10 @@ DhcpOnTimerTick ( Status = DhcpChooseOffer (DhcpSb); if (EFI_ERROR(Status)) { - FreePool (DhcpSb->LastOffer); - DhcpSb->LastOffer = NULL; + if (DhcpSb->LastOffer != NULL) { + FreePool (DhcpSb->LastOffer); + DhcpSb->LastOffer = NULL; + } } else { goto ON_EXIT; } @@ -1591,6 +1621,10 @@ DhcpOnTimerTick ( goto END_SESSION; } + if (Instance != NULL) { + Instance->ElaspedTime= 0; + } + Status = DhcpSendMessage ( DhcpSb, DhcpSb->Selected, @@ -1611,6 +1645,10 @@ DhcpOnTimerTick ( goto END_SESSION; } + if (Instance != NULL) { + Instance->ElaspedTime= 0; + } + Status = DhcpSendMessage ( DhcpSb, DhcpSb->Selected,