X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FDhcp4Dxe%2FDhcp4Io.c;h=da42e670b5ce381f4770df7febe2c722a2a064e6;hp=d021d1c02e1d0d06d37209c08ea37eb27dcbab01;hb=f92046412a466c208adbeb5e09e511a3a5e2ae31;hpb=893ce03b01de6dcd7ffd4b05a58e627d1f6c50ae diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c index d021d1c02e..da42e670b5 100644 --- a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c +++ b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c @@ -1,6 +1,6 @@ /** @file -Copyright (c) 2006 - 2007, Intel Corporation +Copyright (c) 2006 - 2008, 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 @@ -33,6 +33,7 @@ UINT32 mDhcp4DefaultTimeout[4] = { 4, 8, 16, 32 }; @param DhcpSb The DHCP service instance @retval EFI_SUCCESS The request has been sent + @retval other Some error occurs when sending the request. **/ EFI_STATUS @@ -82,7 +83,6 @@ DhcpInitRequest ( @retval EFI_ABORTED The user function ask it to abort. **/ -STATIC EFI_STATUS DhcpCallUser ( IN DHCP_SERVICE *DhcpSb, @@ -141,7 +141,7 @@ DhcpCallUser ( Notify the user about the operation result. @param DhcpSb DHCP service instance - @param Which which notify function to signal + @param Which Which notify function to signal @return None @@ -159,14 +159,16 @@ DhcpNotifyUser ( } if ((Child->CompletionEvent != NULL) && - ((Which == DHCP_NOTIFY_COMPLETION) || (Which == DHCP_NOTIFY_ALL))) { + ((Which == DHCP_NOTIFY_COMPLETION) || (Which == DHCP_NOTIFY_ALL)) + ) { gBS->SignalEvent (Child->CompletionEvent); Child->CompletionEvent = NULL; } if ((Child->RenewRebindEvent != NULL) && - ((Which == DHCP_NOTIFY_RENEWREBIND) || (Which == DHCP_NOTIFY_ALL))) { + ((Which == DHCP_NOTIFY_RENEWREBIND) || (Which == DHCP_NOTIFY_ALL)) + ) { gBS->SignalEvent (Child->RenewRebindEvent); Child->RenewRebindEvent = NULL; @@ -192,9 +194,9 @@ DhcpNotifyUser ( **/ EFI_STATUS DhcpSetState ( - IN DHCP_SERVICE *DhcpSb, - IN INTN State, - IN BOOLEAN CallUser + IN OUT DHCP_SERVICE *DhcpSb, + IN INTN State, + IN BOOLEAN CallUser ) { EFI_STATUS Status; @@ -250,10 +252,9 @@ DhcpSetState ( @return None **/ -STATIC VOID DhcpSetTransmitTimer ( - IN DHCP_SERVICE *DhcpSb + IN OUT DHCP_SERVICE *DhcpSb ) { UINT32 *Times; @@ -272,9 +273,7 @@ DhcpSetTransmitTimer ( DhcpSb->PacketToLive = Times[DhcpSb->CurRetry]; - if (DhcpSb->DhcpState == Dhcp4Selecting) { - DhcpSb->WaitOffer = DhcpSb->PacketToLive; - } + return; } /** @@ -289,11 +288,10 @@ DhcpSetTransmitTimer ( @return None **/ -STATIC VOID DhcpComputeLease ( - IN DHCP_SERVICE *DhcpSb, - IN DHCP_PARAMETER *Para + IN OUT DHCP_SERVICE *DhcpSb, + IN DHCP_PARAMETER *Para ) { ASSERT (Para != NULL); @@ -322,7 +320,7 @@ DhcpComputeLease ( such as DHCP release. @param UdpIo The UDP IO port to configure - @param Context The opaque parameter to the function. + @param Context Dhcp service instance. @retval EFI_SUCCESS The UDP IO port is successfully configured. @retval Others It failed to configure the port. @@ -358,12 +356,12 @@ DhcpConfigLeaseIoPort ( UdpConfigData.RemotePort = DHCP_SERVER_PORT; Ip = HTONL (DhcpSb->ClientAddr); - NetCopyMem (&UdpConfigData.StationAddress, &Ip, sizeof (EFI_IPv4_ADDRESS)); + CopyMem (&UdpConfigData.StationAddress, &Ip, sizeof (EFI_IPv4_ADDRESS)); Ip = HTONL (DhcpSb->Netmask); - NetCopyMem (&UdpConfigData.SubnetMask, &Ip, sizeof (EFI_IPv4_ADDRESS)); + CopyMem (&UdpConfigData.SubnetMask, &Ip, sizeof (EFI_IPv4_ADDRESS)); - NetZeroMem (&UdpConfigData.RemoteAddress, sizeof (EFI_IPv4_ADDRESS)); + ZeroMem (&UdpConfigData.RemoteAddress, sizeof (EFI_IPv4_ADDRESS)); Status = UdpIo->Udp->Configure (UdpIo->Udp, &UdpConfigData); @@ -375,10 +373,10 @@ DhcpConfigLeaseIoPort ( // Add a default route if received from the server. // if ((DhcpSb->Para != NULL) && (DhcpSb->Para->Router != 0)) { - NetZeroMem (&Subnet, sizeof (EFI_IPv4_ADDRESS)); + ZeroMem (&Subnet, sizeof (EFI_IPv4_ADDRESS)); Ip = HTONL (DhcpSb->Para->Router); - NetCopyMem (&Gateway, &Ip, sizeof (EFI_IPv4_ADDRESS)); + CopyMem (&Gateway, &Ip, sizeof (EFI_IPv4_ADDRESS)); UdpIo->Udp->Routes (UdpIo->Udp, FALSE, &Subnet, &Subnet, &Gateway); } @@ -398,10 +396,9 @@ DhcpConfigLeaseIoPort ( @retval EFI_SUCCESS The lease is recorded. **/ -STATIC EFI_STATUS DhcpLeaseAcquired ( - IN DHCP_SERVICE *DhcpSb + IN OUT DHCP_SERVICE *DhcpSb ) { INTN Class; @@ -415,7 +412,7 @@ DhcpLeaseAcquired ( if (DhcpSb->Netmask == 0) { Class = NetGetIpClass (DhcpSb->ClientAddr); - DhcpSb->Netmask = mIp4AllMasks[Class << 3]; + DhcpSb->Netmask = gIp4AllMasks[Class << 3]; } if (DhcpSb->LeaseIoPort != NULL) { @@ -465,17 +462,17 @@ DhcpCleanLease ( DhcpSb->ServerAddr = 0; if (DhcpSb->LastOffer != NULL) { - NetFreePool (DhcpSb->LastOffer); + gBS->FreePool (DhcpSb->LastOffer); DhcpSb->LastOffer = NULL; } if (DhcpSb->Selected != NULL) { - NetFreePool (DhcpSb->Selected); + gBS->FreePool (DhcpSb->Selected); DhcpSb->Selected = NULL; } if (DhcpSb->Para != NULL) { - NetFreePool (DhcpSb->Para); + gBS->FreePool (DhcpSb->Para); DhcpSb->Para = NULL; } @@ -497,7 +494,6 @@ DhcpCleanLease ( DhcpSb->PacketToLive = 0; DhcpSb->CurRetry = 0; DhcpSb->MaxRetries = 0; - DhcpSb->WaitOffer = 0; DhcpSb->LeaseLife = 0; } @@ -512,7 +508,6 @@ DhcpCleanLease ( @retval EFI_SUCCESS One of the offer is selected. **/ -STATIC EFI_STATUS DhcpChooseOffer ( IN DHCP_SERVICE *DhcpSb @@ -525,11 +520,6 @@ DhcpChooseOffer ( ASSERT (DhcpSb->LastOffer != NULL); - // - // Stop waiting more offers - // - DhcpSb->WaitOffer = 0; - // // User will cache previous offers if he wants to select // from multiple offers. If user provides an invalid packet, @@ -545,10 +535,10 @@ DhcpChooseOffer ( Selected = DhcpSb->LastOffer; if ((NewPacket != NULL) && !EFI_ERROR (DhcpValidateOptions (NewPacket, NULL))) { - TempPacket = (EFI_DHCP4_PACKET *) NetAllocatePool (NewPacket->Size); + TempPacket = (EFI_DHCP4_PACKET *) AllocatePool (NewPacket->Size); if (TempPacket != NULL) { - NetCopyMem (TempPacket, NewPacket, NewPacket->Size); - NetFreePool (Selected); + CopyMem (TempPacket, NewPacket, NewPacket->Size); + gBS->FreePool (Selected); Selected = TempPacket; } } @@ -599,7 +589,6 @@ DhcpChooseOffer ( @return None **/ -STATIC VOID DhcpEndSession ( IN DHCP_SERVICE *DhcpSb, @@ -631,7 +620,6 @@ DhcpEndSession ( @retval Others Some error occured. **/ -STATIC EFI_STATUS DhcpHandleSelect ( IN DHCP_SERVICE *DhcpSb, @@ -650,7 +638,8 @@ DhcpHandleSelect ( // Don't return a error for these two case otherwise the session is ended. // if (!DHCP_IS_BOOTP (Para) && - ((Para->DhcpType != DHCP_MSG_OFFER) || (Para->ServerId == 0))) { + ((Para->DhcpType != DHCP_MSG_OFFER) || (Para->ServerId == 0)) + ) { goto ON_EXIT; } @@ -664,7 +653,7 @@ DhcpHandleSelect ( if (Status == EFI_SUCCESS) { if (DhcpSb->LastOffer != NULL) { - NetFreePool (DhcpSb->LastOffer); + gBS->FreePool (DhcpSb->LastOffer); } DhcpSb->LastOffer = Packet; @@ -673,7 +662,7 @@ DhcpHandleSelect ( } else if (Status == EFI_NOT_READY) { if (DhcpSb->LastOffer != NULL) { - NetFreePool (DhcpSb->LastOffer); + gBS->FreePool (DhcpSb->LastOffer); } DhcpSb->LastOffer = Packet; @@ -689,7 +678,7 @@ DhcpHandleSelect ( return EFI_SUCCESS; ON_EXIT: - NetFreePool (Packet); + gBS->FreePool (Packet); return Status; } @@ -706,7 +695,6 @@ ON_EXIT: @retval Others Some error occured. **/ -STATIC EFI_STATUS DhcpHandleRequest ( IN DHCP_SERVICE *DhcpSb, @@ -728,8 +716,9 @@ DhcpHandleRequest ( // Ignore the BOOTP message and DHCP messages other than DHCP ACK/NACK. // if (DHCP_IS_BOOTP (Para) || - (Para->ServerId != DhcpSb->Para->ServerId) || - ((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK))) { + (Para->ServerId != DhcpSb->Para->ServerId) || + ((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK)) + ) { Status = EFI_SUCCESS; goto ON_EXIT; @@ -775,14 +764,14 @@ DhcpHandleRequest ( DhcpSb->IoStatus = EFI_SUCCESS; DhcpNotifyUser (DhcpSb, DHCP_NOTIFY_COMPLETION); - NetFreePool (Packet); + gBS->FreePool (Packet); return EFI_SUCCESS; REJECT: DhcpSendMessage (DhcpSb, DhcpSb->Selected, DhcpSb->Para, DHCP_MSG_DECLINE, Message); ON_EXIT: - NetFreePool (Packet); + gBS->FreePool (Packet); return Status; } @@ -799,7 +788,6 @@ ON_EXIT: @retval Others Some error occured. **/ -STATIC EFI_STATUS DhcpHandleRenewRebind ( IN DHCP_SERVICE *DhcpSb, @@ -820,8 +808,9 @@ DhcpHandleRenewRebind ( // Ignore the BOOTP message and DHCP messages other than DHCP ACK/NACK // if (DHCP_IS_BOOTP (Para) || - (Para->ServerId != DhcpSb->Para->ServerId) || - ((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK))) { + (Para->ServerId != DhcpSb->Para->ServerId) || + ((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK)) + ) { Status = EFI_SUCCESS; goto ON_EXIT; @@ -858,7 +847,7 @@ DhcpHandleRenewRebind ( DhcpSb->LeaseLife = 0; DhcpSetState (DhcpSb, Dhcp4Bound, TRUE); - if (DhcpSb->ExtraRefresh) { + if (DhcpSb->ExtraRefresh != 0) { DhcpSb->ExtraRefresh = FALSE; DhcpSb->IoStatus = EFI_SUCCESS; @@ -866,7 +855,7 @@ DhcpHandleRenewRebind ( } ON_EXIT: - NetFreePool (Packet); + gBS->FreePool (Packet); return Status; } @@ -883,7 +872,6 @@ ON_EXIT: @retval Others Some error occured. **/ -STATIC EFI_STATUS DhcpHandleReboot ( IN DHCP_SERVICE *DhcpSb, @@ -900,7 +888,8 @@ DhcpHandleReboot ( // Ignore the BOOTP message and DHCP messages other than DHCP ACK/NACK // if (DHCP_IS_BOOTP (Para) || - ((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK))) { + ((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK)) + ) { Status = EFI_SUCCESS; goto ON_EXIT; @@ -935,7 +924,7 @@ DhcpHandleReboot ( // // OK, get the parameter from server, record the lease // - DhcpSb->Para = NetAllocatePool (sizeof (DHCP_PARAMETER)); + DhcpSb->Para = AllocatePool (sizeof (DHCP_PARAMETER)); if (DhcpSb->Para == NULL) { Status = EFI_OUT_OF_RESOURCES; @@ -956,13 +945,13 @@ DhcpHandleReboot ( return EFI_SUCCESS; ON_EXIT: - NetFreePool (Packet); + gBS->FreePool (Packet); return Status; } /** - Handle the received DHCP packets. This function drivers the DHCP + Handle the received DHCP packets. This function drives the DHCP state machine. @param UdpPacket The UDP packets received. @@ -1018,7 +1007,7 @@ DhcpInput ( // Copy the DHCP message to a continuous memory block // Len = sizeof (EFI_DHCP4_PACKET) + UdpPacket->TotalSize - sizeof (EFI_DHCP4_HEADER); - Packet = (EFI_DHCP4_PACKET *) NetAllocatePool (Len); + Packet = (EFI_DHCP4_PACKET *) AllocatePool (Len); if (Packet == NULL) { goto RESTART; @@ -1037,7 +1026,7 @@ DhcpInput ( // if ((Head->OpCode != BOOTP_REPLY) || (NTOHL (Head->Xid) != DhcpSb->Xid) || - !NET_MAC_EQUAL (&DhcpSb->Mac, Head->ClientHwAddr, DhcpSb->HwLen)) { + (CompareMem (DhcpSb->ClientAddressSendOut, Head->ClientHwAddr, Head->HwAddrLen) != 0)) { goto RESTART; } @@ -1078,7 +1067,7 @@ DhcpInput ( // // Ignore the packet in INITREBOOT, INIT and BOUND states // - NetFreePool (Packet); + gBS->FreePool (Packet); Status = EFI_SUCCESS; break; @@ -1093,7 +1082,7 @@ DhcpInput ( } if (Para != NULL) { - NetFreePool (Para); + gBS->FreePool (Para); } Packet = NULL; @@ -1108,7 +1097,7 @@ RESTART: NetbufFree (UdpPacket); if (Packet != NULL) { - NetFreePool (Packet); + gBS->FreePool (Packet); } Status = UdpIoRecvDatagram (DhcpSb->UdpIo, DhcpInput, DhcpSb, 0); @@ -1132,7 +1121,7 @@ DhcpReleasePacket ( IN VOID *Arg ) { - NetFreePool (Arg); + gBS->FreePool (Arg); } @@ -1176,6 +1165,7 @@ DhcpOnPacketSent ( @retval EFI_OUT_OF_RESOURCES Failed to allocate resources for the packet @retval EFI_ACCESS_DENIED Failed to transmit the packet through UDP @retval EFI_SUCCESS The message is sent + @retval other Other error occurs **/ EFI_STATUS @@ -1212,7 +1202,7 @@ DhcpSendMessage ( Len += (UINT32)AsciiStrLen ((CHAR8 *) Msg); } - Packet = NetAllocatePool (Len); + Packet = AllocatePool (Len); if (Packet == NULL) { return EFI_OUT_OF_RESOURCES; @@ -1232,7 +1222,7 @@ DhcpSendMessage ( } Head = &Packet->Dhcp4.Header; - NetZeroMem (Head, sizeof (EFI_DHCP4_HEADER)); + ZeroMem (Head, sizeof (EFI_DHCP4_HEADER)); Head->OpCode = BOOTP_REQUEST; Head->HwType = DhcpSb->HwType; @@ -1241,7 +1231,7 @@ DhcpSendMessage ( Head->Reserved = HTONS (0x8000); //Server, broadcast the message please. EFI_IP4 (Head->ClientAddr) = HTONL (DhcpSb->ClientAddr); - NetCopyMem (Head->ClientHwAddr, DhcpSb->Mac.Addr, DhcpSb->HwLen); + CopyMem (Head->ClientHwAddr, DhcpSb->Mac.Addr, DhcpSb->HwLen); // // Append the DHCP message type @@ -1257,7 +1247,8 @@ DhcpSendMessage ( // 3. DHCP request to confirm one lease. // if ((Type == DHCP_MSG_DECLINE) || (Type == DHCP_MSG_RELEASE) || - ((Type == DHCP_MSG_REQUEST) && (DhcpSb->DhcpState == Dhcp4Requesting))) { + ((Type == DHCP_MSG_REQUEST) && (DhcpSb->DhcpState == Dhcp4Requesting)) + ) { ASSERT ((Para != NULL) && (Para->ServerId != 0)); @@ -1352,15 +1343,25 @@ DhcpSendMessage ( } if (EFI_ERROR (Status)) { - NetFreePool (Packet); + gBS->FreePool (Packet); return Status; } if (NewPacket != NULL) { - NetFreePool (Packet); + gBS->FreePool (Packet); Packet = NewPacket; } + // + // Save the Client Address will be sent out + // + CopyMem ( + &DhcpSb->ClientAddressSendOut[0], + &Packet->Dhcp4.Header.ClientHwAddr[0], + Packet->Dhcp4.Header.HwAddrLen + ); + + // // Wrap it into a netbuf then send it. // @@ -1369,7 +1370,7 @@ DhcpSendMessage ( Wrap = NetbufFromExt (&Frag, 1, 0, 0, DhcpReleasePacket, Packet); if (Wrap == NULL) { - NetFreePool (Packet); + gBS->FreePool (Packet); return EFI_OUT_OF_RESOURCES; } @@ -1492,33 +1493,30 @@ DhcpOnTimerTick ( DHCP_SERVICE *DhcpSb; DHCP_PROTOCOL *Instance; EFI_STATUS Status; - + DhcpSb = (DHCP_SERVICE *) Context; Instance = DhcpSb->ActiveChild; - + // - // Check the time to wait offer + // Check the retransmit timer // - if ((DhcpSb->WaitOffer > 0) && (--DhcpSb->WaitOffer == 0)) { + if ((DhcpSb->PacketToLive > 0) && (--DhcpSb->PacketToLive == 0)) { + // - // OK, offer collection finished, select a offer + // Select offer at each timeout if any offer received. // - ASSERT (DhcpSb->DhcpState == Dhcp4Selecting); + if (DhcpSb->DhcpState == Dhcp4Selecting && DhcpSb->LastOffer != NULL) { - if (DhcpSb->LastOffer == NULL) { - goto END_SESSION; - } + Status = DhcpChooseOffer (DhcpSb); - if (EFI_ERROR (DhcpChooseOffer (DhcpSb))) { - goto END_SESSION; + if (EFI_ERROR(Status)) { + FreePool (DhcpSb->LastOffer); + DhcpSb->LastOffer = NULL; + } else { + goto ON_EXIT; + } } - } - - // - // Check the retransmit timer - // - if ((DhcpSb->PacketToLive > 0) && (--DhcpSb->PacketToLive == 0)) { - + if (++DhcpSb->CurRetry < DhcpSb->MaxRetries) { // // Still has another try @@ -1526,17 +1524,14 @@ DhcpOnTimerTick ( DhcpRetransmit (DhcpSb); DhcpSetTransmitTimer (DhcpSb); - } else { - if (!DHCP_CONNECTED (DhcpSb->DhcpState)) { - goto END_SESSION; - } + } else if (DHCP_CONNECTED (DhcpSb->DhcpState)) { // // Retransmission failed, if the DHCP request is initiated by // user, adjust the current state according to the lease life. // Otherwise do nothing to wait the lease to timeout // - if (DhcpSb->ExtraRefresh) { + if (DhcpSb->ExtraRefresh != 0) { Status = EFI_SUCCESS; if (DhcpSb->LeaseLife < DhcpSb->T1) { @@ -1556,6 +1551,8 @@ DhcpOnTimerTick ( DhcpSb->IoStatus = EFI_TIMEOUT; DhcpNotifyUser (DhcpSb, DHCP_NOTIFY_RENEWREBIND); } + } else { + goto END_SESSION; } } @@ -1570,7 +1567,7 @@ DhcpOnTimerTick ( // Don't timeout the lease, only count the life if user is // requesting extra renew/rebind. Adjust the state after that. // - if (DhcpSb->ExtraRefresh) { + if (DhcpSb->ExtraRefresh != 0) { return ; } @@ -1622,9 +1619,7 @@ DhcpOnTimerTick ( } } - // - // - // +ON_EXIT: if ((Instance != NULL) && (Instance->Token != NULL)) { Instance->Timeout--; if (Instance->Timeout == 0) {