X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FDhcp4Dxe%2FDhcp4Io.c;h=d021d1c02e1d0d06d37209c08ea37eb27dcbab01;hb=893ce03b01de6dcd7ffd4b05a58e627d1f6c50ae;hp=41554393a5e51d7b59e06172c49d248bb5f5d8d4;hpb=687a2e5f6902fa26c7a1d7a7705e0747c4095125;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c index 41554393a5..d021d1c02e 100644 --- a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c +++ b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c @@ -52,8 +52,6 @@ DhcpInitRequest ( DhcpSb->DhcpState = Dhcp4Init; return Status; } - - DhcpSb->WaitOffer = DHCP_WAIT_OFFER; } else { DhcpSetState (DhcpSb, Dhcp4Rebooting, FALSE); Status = DhcpSendMessage (DhcpSb, NULL, NULL, DHCP_MSG_REQUEST, NULL); @@ -225,7 +223,7 @@ DhcpSetState ( // This will clear the retry count. This is also why the rule // first transit the state, then send packets. // - if (State == Dhcp4Init) { + if (State == Dhcp4Selecting) { DhcpSb->MaxRetries = DhcpSb->ActiveConfig.DiscoverTryCount; } else { DhcpSb->MaxRetries = DhcpSb->ActiveConfig.RequestTryCount; @@ -262,7 +260,7 @@ DhcpSetTransmitTimer ( ASSERT (DhcpSb->MaxRetries > DhcpSb->CurRetry); - if (DhcpSb->DhcpState == Dhcp4Init) { + if (DhcpSb->DhcpState == Dhcp4Selecting) { Times = DhcpSb->ActiveConfig.DiscoverTimeout; } else { Times = DhcpSb->ActiveConfig.RequestTimeout; @@ -273,8 +271,11 @@ DhcpSetTransmitTimer ( } DhcpSb->PacketToLive = Times[DhcpSb->CurRetry]; -} + if (DhcpSb->DhcpState == Dhcp4Selecting) { + DhcpSb->WaitOffer = DhcpSb->PacketToLive; + } +} /** Compute the lease. If the server grants a permanent lease, just @@ -519,6 +520,7 @@ DhcpChooseOffer ( { EFI_DHCP4_PACKET *Selected; EFI_DHCP4_PACKET *NewPacket; + EFI_DHCP4_PACKET *TempPacket; EFI_STATUS Status; ASSERT (DhcpSb->LastOffer != NULL); @@ -542,12 +544,12 @@ DhcpChooseOffer ( Selected = DhcpSb->LastOffer; - if (NewPacket != NULL) { - if (EFI_ERROR (DhcpValidateOptions (NewPacket, NULL))) { - NetFreePool (NewPacket); - } else { + if ((NewPacket != NULL) && !EFI_ERROR (DhcpValidateOptions (NewPacket, NULL))) { + TempPacket = (EFI_DHCP4_PACKET *) NetAllocatePool (NewPacket->Size); + if (TempPacket != NULL) { + NetCopyMem (TempPacket, NewPacket, NewPacket->Size); NetFreePool (Selected); - Selected = NewPacket; + Selected = TempPacket; } } @@ -637,7 +639,6 @@ DhcpHandleSelect ( IN DHCP_PARAMETER *Para ) { - EFI_DHCP4_HEADER *Head; EFI_STATUS Status; Status = EFI_SUCCESS; @@ -648,12 +649,6 @@ DhcpHandleSelect ( // 2. if it is a DHCP message, it must contains a server ID. // Don't return a error for these two case otherwise the session is ended. // - Head = &Packet->Dhcp4.Header; - - if (!Ip4IsUnicast (EFI_NTOHL (Head->YourAddr), (Para == NULL ? 0 : Para->NetMask))) { - goto ON_EXIT; - } - if (!DHCP_IS_BOOTP (Para) && ((Para->DhcpType != DHCP_MSG_OFFER) || (Para->ServerId == 0))) { goto ON_EXIT; @@ -755,15 +750,15 @@ DhcpHandleRequest ( // Message = NULL; - if (!EFI_IP4_EQUAL (Head->YourAddr, Selected->YourAddr)) { - Message = "Lease confirmed isn't the same as that in the offer"; + if (!EFI_IP4_EQUAL (&Head->YourAddr, &Selected->YourAddr)) { + Message = (UINT8 *) "Lease confirmed isn't the same as that in the offer"; goto REJECT; } Status = DhcpCallUser (DhcpSb, Dhcp4RcvdAck, Packet, NULL); if (EFI_ERROR (Status)) { - Message = "Lease is denied upon received ACK"; + Message = (UINT8 *) "Lease is denied upon received ACK"; goto REJECT; } @@ -773,7 +768,7 @@ DhcpHandleRequest ( Status = DhcpLeaseAcquired (DhcpSb); if (EFI_ERROR (Status)) { - Message = "Lease is denied upon entering bound"; + Message = (UINT8 *) "Lease is denied upon entering bound"; goto REJECT; } @@ -846,7 +841,7 @@ DhcpHandleRenewRebind ( // The lease is different from the selected. Don't send a DECLINE // since it isn't existed in the client's FSM. // - if (!EFI_IP4_EQUAL (Head->YourAddr, Selected->YourAddr)) { + if (!EFI_IP4_EQUAL (&Head->YourAddr, &Selected->YourAddr)) { goto ON_EXIT; } @@ -1310,7 +1305,7 @@ DhcpSendMessage ( // Append the user's message if it isn't NULL // if (Msg != NULL) { - Len = NET_MIN ((UINT32) AsciiStrLen ((CHAR8 *) Msg), 255); + Len = MIN ((UINT32) AsciiStrLen ((CHAR8 *) Msg), 255); Buf = DhcpAppendOption (Buf, DHCP_TAG_MESSAGE, (UINT16) Len, Msg); } @@ -1495,12 +1490,32 @@ DhcpOnTimerTick ( ) { DHCP_SERVICE *DhcpSb; + DHCP_PROTOCOL *Instance; EFI_STATUS Status; + + DhcpSb = (DHCP_SERVICE *) Context; + Instance = DhcpSb->ActiveChild; - DhcpSb = (DHCP_SERVICE *) Context; + // + // Check the time to wait offer + // + if ((DhcpSb->WaitOffer > 0) && (--DhcpSb->WaitOffer == 0)) { + // + // OK, offer collection finished, select a offer + // + ASSERT (DhcpSb->DhcpState == Dhcp4Selecting); + + if (DhcpSb->LastOffer == NULL) { + goto END_SESSION; + } + if (EFI_ERROR (DhcpChooseOffer (DhcpSb))) { + goto END_SESSION; + } + } + // - // Check the retransmit timer first + // Check the retransmit timer // if ((DhcpSb->PacketToLive > 0) && (--DhcpSb->PacketToLive == 0)) { @@ -1543,22 +1558,7 @@ DhcpOnTimerTick ( } } } - - if ((DhcpSb->WaitOffer > 0) && (--DhcpSb->WaitOffer == 0)) { - // - // OK, offer collection finished, select a offer - // - ASSERT (DhcpSb->DhcpState == Dhcp4Selecting); - - if (DhcpSb->LastOffer == NULL) { - goto END_SESSION; - } - - if (EFI_ERROR (DhcpChooseOffer (DhcpSb))) { - goto END_SESSION; - } - } - + // // If an address has been acquired, check whether need to // refresh or whether it has expired. @@ -1622,6 +1622,16 @@ DhcpOnTimerTick ( } } + // + // + // + if ((Instance != NULL) && (Instance->Token != NULL)) { + Instance->Timeout--; + if (Instance->Timeout == 0) { + PxeDhcpDone (Instance); + } + } + return ; END_SESSION: