X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FDhcp4Dxe%2FDhcp4Impl.c;h=ac4b11f09402a1cadc793db6038c5fb1c01c8574;hp=8beab59f2b407f938498946873d7841479f3c9c7;hb=ce964733292e31dce34e0be651f20a9d79884132;hpb=e798cd87ca9a3a30c4cea50c5f5de84e10a8bc5a diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c index 8beab59f2b..ac4b11f094 100644 --- a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c +++ b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c @@ -1,8 +1,8 @@ /** @file This file implement the EFI_DHCP4_PROTOCOL interface. -Copyright (c) 2006 - 2010, Intel Corporation.
-All rights reserved. This program and the accompanying materials +Copyright (c) 2006 - 2015, 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 @@ -467,7 +467,7 @@ DhcpCopyConfigure ( { EFI_DHCP4_PACKET_OPTION **DstOptions; EFI_DHCP4_PACKET_OPTION **SrcOptions; - INTN Len; + UINTN Len; UINT32 Index; CopyMem (Dst, Src, sizeof (*Dst)); @@ -910,16 +910,17 @@ EfiDhcp4RenewRebind ( if (DhcpSb->DhcpState == Dhcp4Stopped) { Status = EFI_NOT_STARTED; - goto ON_ERROR; + goto ON_EXIT; } if (DhcpSb->DhcpState != Dhcp4Bound) { Status = EFI_ACCESS_DENIED; - goto ON_ERROR; + goto ON_EXIT; } if (DHCP_IS_BOOTP (DhcpSb->Para)) { - return EFI_SUCCESS; + Status = EFI_SUCCESS; + goto ON_EXIT; } // @@ -931,6 +932,12 @@ EfiDhcp4RenewRebind ( DhcpSetState (DhcpSb, Dhcp4Rebinding, FALSE); } + // + // Clear initial time to make sure that elapsed-time + // is set to 0 for first REQUEST in renewal process. + // + Instance->ElaspedTime = 0; + Status = DhcpSendMessage ( DhcpSb, DhcpSb->Selected, @@ -941,7 +948,7 @@ EfiDhcp4RenewRebind ( if (EFI_ERROR (Status)) { DhcpSetState (DhcpSb, Dhcp4Bound, FALSE); - goto ON_ERROR; + goto ON_EXIT; } DhcpSb->ExtraRefresh = TRUE; @@ -961,7 +968,7 @@ EfiDhcp4RenewRebind ( return EFI_SUCCESS; -ON_ERROR: +ON_EXIT: gBS->RestoreTPL (OldTpl); return Status; } @@ -1184,7 +1191,10 @@ Dhcp4InstanceConfigUdpIo ( DHCP_SERVICE *DhcpSb; EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN *Token; EFI_UDP4_CONFIG_DATA UdpConfigData; - IP4_ADDR Ip; + IP4_ADDR ClientAddr; + IP4_ADDR Ip; + INTN Class; + IP4_ADDR SubnetMask; Instance = (DHCP_PROTOCOL *) Context; DhcpSb = Instance->Service; @@ -1197,10 +1207,14 @@ Dhcp4InstanceConfigUdpIo ( UdpConfigData.TimeToLive = 64; UdpConfigData.DoNotFragment = TRUE; - Ip = HTONL (DhcpSb->ClientAddr); + ClientAddr = EFI_NTOHL (Token->Packet->Dhcp4.Header.ClientAddr); + Ip = HTONL (ClientAddr); CopyMem (&UdpConfigData.StationAddress, &Ip, sizeof (EFI_IPv4_ADDRESS)); - - Ip = HTONL (DhcpSb->Netmask); + + Class = NetGetIpClass (ClientAddr); + ASSERT (Class < IP4_ADDR_CLASSE); + SubnetMask = gIp4AllMasks[Class << 3]; + Ip = HTONL (SubnetMask); CopyMem (&UdpConfigData.SubnetMask, &Ip, sizeof (EFI_IPv4_ADDRESS)); if ((Token->ListenPointCount == 0) || (Token->ListenPoints[0].ListenPort == 0)) { @@ -1227,6 +1241,8 @@ Dhcp4InstanceCreateUdpIo ( ) { DHCP_SERVICE *DhcpSb; + EFI_STATUS Status; + VOID *Udp4; ASSERT (Instance->Token != NULL); @@ -1241,7 +1257,19 @@ Dhcp4InstanceCreateUdpIo ( if (Instance->UdpIo == NULL) { return EFI_OUT_OF_RESOURCES; } else { - return EFI_SUCCESS; + Status = gBS->OpenProtocol ( + Instance->UdpIo->UdpHandle, + &gEfiUdp4ProtocolGuid, + (VOID **) &Udp4, + Instance->Service->Image, + Instance->Handle, + EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER + ); + if (EFI_ERROR (Status)) { + UdpIoFreeIo (Instance->UdpIo); + Instance->UdpIo = NULL; + } + return Status; } } @@ -1336,7 +1364,7 @@ PxeDhcpInput ( // if ((Head->OpCode != BOOTP_REPLY) || (Head->Xid != Token->Packet->Dhcp4.Header.Xid) || - (CompareMem (DhcpSb->ClientAddressSendOut, Head->ClientHwAddr, Head->HwAddrLen) != 0)) { + (CompareMem (&Token->Packet->Dhcp4.Header.ClientHwAddr[0], Head->ClientHwAddr, Head->HwAddrLen) != 0)) { goto RESTART; } @@ -1409,6 +1437,12 @@ SIGNAL_USER: // NetbufQueFlush (&Instance->ResponseQueue); UdpIoCleanIo (Instance->UdpIo); + gBS->CloseProtocol ( + Instance->UdpIo->UdpHandle, + &gEfiUdp4ProtocolGuid, + Instance->Service->Image, + Instance->Handle + ); UdpIoFreeIo (Instance->UdpIo); Instance->UdpIo = NULL; Instance->Token = NULL; @@ -1454,6 +1488,8 @@ EfiDhcp4TransmitReceive ( IP4_ADDR Ip; DHCP_SERVICE *DhcpSb; EFI_IP_ADDRESS Gateway; + IP4_ADDR ClientAddr; + INTN Class; IP4_ADDR SubnetMask; if ((This == NULL) || (Token == NULL) || (Token->Packet == NULL)) { @@ -1462,6 +1498,7 @@ EfiDhcp4TransmitReceive ( Instance = DHCP_INSTANCE_FROM_THIS (This); DhcpSb = Instance->Service; + DhcpSb->ActiveChild = Instance; if (Instance->Token != NULL) { // @@ -1485,8 +1522,9 @@ EfiDhcp4TransmitReceive ( return EFI_INVALID_PARAMETER; } - if (DhcpSb->ClientAddr == 0) { - + ClientAddr = EFI_NTOHL (Token->Packet->Dhcp4.Header.ClientAddr); + + if (ClientAddr == 0) { return EFI_NO_MAPPING; } @@ -1546,9 +1584,11 @@ EfiDhcp4TransmitReceive ( // // Get the gateway. // - SubnetMask = DhcpSb->Netmask; + Class = NetGetIpClass (ClientAddr); + ASSERT (Class < IP4_ADDR_CLASSE); + SubnetMask = gIp4AllMasks[Class << 3]; ZeroMem (&Gateway, sizeof (Gateway)); - if (!IP4_NET_EQUAL (DhcpSb->ClientAddr, EndPoint.RemoteAddr.Addr[0], SubnetMask)) { + if (!IP4_NET_EQUAL (ClientAddr, EndPoint.RemoteAddr.Addr[0], SubnetMask)) { CopyMem (&Gateway.v4, &Token->GatewayAddress, sizeof (EFI_IPv4_ADDRESS)); Gateway.Addr[0] = NTOHL (Gateway.Addr[0]); } @@ -1574,6 +1614,12 @@ ON_ERROR: if (EFI_ERROR (Status) && (Instance->UdpIo != NULL)) { UdpIoCleanIo (Instance->UdpIo); + gBS->CloseProtocol ( + Instance->UdpIo->UdpHandle, + &gEfiUdp4ProtocolGuid, + Instance->Service->Image, + Instance->Handle + ); UdpIoFreeIo (Instance->UdpIo); Instance->UdpIo = NULL; Instance->Token = NULL; @@ -1722,3 +1768,19 @@ EfiDhcp4Parse ( return EFI_SUCCESS; } + +/** + Set the elapsed time based on the given instance and the pointer to the + elapsed time option. + + @param[in] Elapsed The pointer to the position to append. + @param[in] Instance The pointer to the Dhcp4 instance. +**/ +VOID +SetElapsedTime ( + IN UINT16 *Elapsed, + IN DHCP_PROTOCOL *Instance + ) +{ + WriteUnaligned16 (Elapsed, HTONS(Instance->ElaspedTime)); +}