X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FDhcp4Dxe%2FDhcp4Impl.c;h=ac4b11f09402a1cadc793db6038c5fb1c01c8574;hp=a0a53a4e33665cc160ad1a00d94f4eb9253e0cdb;hb=ce964733292e31dce34e0be651f20a9d79884132;hpb=e285199897e538523f762cb5b3900e81f872035a diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c index a0a53a4e33..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)); @@ -770,6 +770,7 @@ ON_EXIT: @retval EFI_ALREADY_STARTED Some other EFI DHCPv4 Protocol instance already started the DHCP process. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. + @retval EFI_NO_MEDIA There was a media error. **/ EFI_STATUS @@ -909,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; } // @@ -930,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, @@ -940,7 +948,7 @@ EfiDhcp4RenewRebind ( if (EFI_ERROR (Status)) { DhcpSetState (DhcpSb, Dhcp4Bound, FALSE); - goto ON_ERROR; + goto ON_EXIT; } DhcpSb->ExtraRefresh = TRUE; @@ -960,7 +968,7 @@ EfiDhcp4RenewRebind ( return EFI_SUCCESS; -ON_ERROR: +ON_EXIT: gBS->RestoreTPL (OldTpl); return Status; } @@ -1173,6 +1181,7 @@ EfiDhcp4Build ( @retval other Other error occurs. **/ EFI_STATUS +EFIAPI Dhcp4InstanceConfigUdpIo ( IN UDP_IO *UdpIo, IN VOID *Context @@ -1182,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; @@ -1195,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)) { @@ -1225,6 +1241,8 @@ Dhcp4InstanceCreateUdpIo ( ) { DHCP_SERVICE *DhcpSb; + EFI_STATUS Status; + VOID *Udp4; ASSERT (Instance->Token != NULL); @@ -1239,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; } } @@ -1250,6 +1280,7 @@ Dhcp4InstanceCreateUdpIo ( **/ VOID +EFIAPI DhcpDummyExtFree ( IN VOID *Arg ) @@ -1269,6 +1300,7 @@ DhcpDummyExtFree ( **/ VOID +EFIAPI PxeDhcpInput ( NET_BUF *UdpPacket, UDP_END_POINT *EndPoint, @@ -1332,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; } @@ -1405,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; @@ -1450,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)) { @@ -1458,6 +1498,7 @@ EfiDhcp4TransmitReceive ( Instance = DHCP_INSTANCE_FROM_THIS (This); DhcpSb = Instance->Service; + DhcpSb->ActiveChild = Instance; if (Instance->Token != NULL) { // @@ -1481,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; } @@ -1542,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]); } @@ -1570,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; @@ -1718,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)); +}