X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FDhcp4Dxe%2FDhcp4Impl.c;h=821dfbb450a7b592b7d42ac8b828a68d2f8b36c4;hp=0884026db436e6d6bc44694ad29c9d9154f022a4;hb=27f19717275af51d13df543c6627e1d743eb11cf;hpb=cd7bfc2c632841fab110f601a32850eeddc16af1 diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c index 0884026db4..821dfbb450 100644 --- a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c +++ b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c @@ -1,7 +1,7 @@ /** @file This file implement the EFI_DHCP4_PROTOCOL interface. -Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
+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 @@ -932,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, @@ -1182,13 +1188,14 @@ Dhcp4InstanceConfigUdpIo ( ) { DHCP_PROTOCOL *Instance; - 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; Token = Instance->Token; ZeroMem (&UdpConfigData, sizeof (EFI_UDP4_CONFIG_DATA)); @@ -1198,10 +1205,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)) { @@ -1228,6 +1239,8 @@ Dhcp4InstanceCreateUdpIo ( ) { DHCP_SERVICE *DhcpSb; + EFI_STATUS Status; + VOID *Udp4; ASSERT (Instance->Token != NULL); @@ -1242,7 +1255,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; } } @@ -1282,7 +1307,6 @@ PxeDhcpInput ( ) { DHCP_PROTOCOL *Instance; - DHCP_SERVICE *DhcpSb; EFI_DHCP4_HEADER *Head; NET_BUF *Wrap; EFI_DHCP4_PACKET *Packet; @@ -1293,7 +1317,6 @@ PxeDhcpInput ( Wrap = NULL; Instance = (DHCP_PROTOCOL *) Context; Token = Instance->Token; - DhcpSb = Instance->Service; // // Don't restart receive if error occurs or DHCP is destroyed. @@ -1337,7 +1360,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; } @@ -1410,6 +1433,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; @@ -1455,6 +1484,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)) { @@ -1463,6 +1494,7 @@ EfiDhcp4TransmitReceive ( Instance = DHCP_INSTANCE_FROM_THIS (This); DhcpSb = Instance->Service; + DhcpSb->ActiveChild = Instance; if (Instance->Token != NULL) { // @@ -1486,8 +1518,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; } @@ -1547,9 +1580,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]); } @@ -1575,6 +1610,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; @@ -1723,3 +1764,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)); +}