X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FDhcp4Dxe%2FDhcp4Io.c;h=3898223af5db37d910862e360bcdff9fbd245a14;hb=8ce6b650b0df28a0b8aa5784ccbbe4f8259b5626;hp=ba7082e9851c2151e9c3694954312b6f959aa954;hpb=39669f1281f56c399a48af1b976696f9d86e1089;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c index ba7082e985..3898223af5 100644 --- a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c +++ b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c @@ -1,7 +1,7 @@ /** @file EFI DHCP protocol implementation. -Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2016, 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 @@ -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); @@ -388,8 +393,6 @@ DhcpLeaseAcquired ( IN OUT DHCP_SERVICE *DhcpSb ) { - INTN Class; - DhcpSb->ClientAddr = EFI_NTOHL (DhcpSb->Selected->Dhcp4.Header.YourAddr); if (DhcpSb->Para != NULL) { @@ -398,8 +401,7 @@ DhcpLeaseAcquired ( } if (DhcpSb->Netmask == 0) { - Class = NetGetIpClass (DhcpSb->ClientAddr); - DhcpSb->Netmask = gIp4AllMasks[Class << 3]; + return EFI_ABORTED; } if (DhcpSb->LeaseIoPort != NULL) { @@ -967,11 +969,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,12 +1220,23 @@ 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 // Packet->Dhcp4.Magik = DHCP_OPTION_MAGIC; Buf = Packet->Dhcp4.Option; - Buf = DhcpAppendOption (Buf, DHCP_TAG_TYPE, 1, &Type); + Buf = DhcpAppendOption (Buf, DHCP4_TAG_MSG_TYPE, 1, &Type); // // Append the serverid option if necessary: @@ -1238,7 +1251,7 @@ DhcpSendMessage ( ASSERT ((Para != NULL) && (Para->ServerId != 0)); IpAddr = HTONL (Para->ServerId); - Buf = DhcpAppendOption (Buf, DHCP_TAG_SERVER_ID, 4, (UINT8 *) &IpAddr); + Buf = DhcpAppendOption (Buf, DHCP4_TAG_SERVER_ID, 4, (UINT8 *) &IpAddr); } // @@ -1264,7 +1277,7 @@ DhcpSendMessage ( } if (IpAddr != 0) { - Buf = DhcpAppendOption (Buf, DHCP_TAG_REQUEST_IP, 4, (UINT8 *) &IpAddr); + Buf = DhcpAppendOption (Buf, DHCP4_TAG_REQUEST_IP, 4, (UINT8 *) &IpAddr); } // @@ -1274,7 +1287,7 @@ DhcpSendMessage ( // if ((Type != DHCP_MSG_DECLINE) && (Type != DHCP_MSG_RELEASE)) { MaxMsg = HTONS (0xFF00); - Buf = DhcpAppendOption (Buf, DHCP_TAG_MAXMSG, 2, (UINT8 *) &MaxMsg); + Buf = DhcpAppendOption (Buf, DHCP4_TAG_MAXMSG, 2, (UINT8 *) &MaxMsg); } // @@ -1282,7 +1295,7 @@ DhcpSendMessage ( // if (Msg != NULL) { Len = MIN ((UINT32) AsciiStrLen ((CHAR8 *) Msg), 255); - Buf = DhcpAppendOption (Buf, DHCP_TAG_MESSAGE, (UINT16) Len, Msg); + Buf = DhcpAppendOption (Buf, DHCP4_TAG_MESSAGE, (UINT16) Len, Msg); } // @@ -1295,7 +1308,7 @@ DhcpSendMessage ( // if it is a DHCP decline or DHCP release . // if (((Type == DHCP_MSG_DECLINE) || (Type == DHCP_MSG_RELEASE)) && - (Config->OptionList[Index]->OpCode != DHCP_TAG_CLIENT_ID)) { + (Config->OptionList[Index]->OpCode != DHCP4_TAG_CLIENT_ID)) { continue; } @@ -1308,7 +1321,7 @@ DhcpSendMessage ( } } - *(Buf++) = DHCP_TAG_EOP; + *(Buf++) = DHCP4_TAG_EOP; Packet->Length += (UINT32) (Buf - Packet->Dhcp4.Option); // @@ -1429,7 +1442,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. @@ -1496,12 +1514,21 @@ DhcpOnTimerTick ( IN VOID *Context ) { + LIST_ENTRY *Entry; + LIST_ENTRY *Next; DHCP_SERVICE *DhcpSb; DHCP_PROTOCOL *Instance; EFI_STATUS Status; 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 @@ -1593,6 +1620,10 @@ DhcpOnTimerTick ( goto END_SESSION; } + if (Instance != NULL) { + Instance->ElaspedTime= 0; + } + Status = DhcpSendMessage ( DhcpSb, DhcpSb->Selected, @@ -1613,6 +1644,10 @@ DhcpOnTimerTick ( goto END_SESSION; } + if (Instance != NULL) { + Instance->ElaspedTime= 0; + } + Status = DhcpSendMessage ( DhcpSb, DhcpSb->Selected, @@ -1628,10 +1663,17 @@ DhcpOnTimerTick ( } ON_EXIT: - if ((Instance != NULL) && (Instance->Token != NULL)) { - Instance->Timeout--; - if (Instance->Timeout == 0) { - PxeDhcpDone (Instance); + // + // Iterate through all the DhcpSb Children. + // + NET_LIST_FOR_EACH_SAFE (Entry, Next, &DhcpSb->Children) { + Instance = NET_LIST_USER_STRUCT (Entry, DHCP_PROTOCOL, Link); + + if ((Instance != NULL) && (Instance->Token != NULL)) { + Instance->Timeout--; + if (Instance->Timeout == 0) { + PxeDhcpDone (Instance); + } } }