X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FDhcp4Dxe%2FDhcp4Impl.c;h=821dfbb450a7b592b7d42ac8b828a68d2f8b36c4;hp=b9a85f2333e3c525004b646b8350d3c75c6f9df4;hb=27f19717275af51d13df543c6627e1d743eb11cf;hpb=842d83d65ecb05ef35578ea947f0e3da98b10d1f diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c index b9a85f2333..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 - 2011, 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 @@ -1188,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)); @@ -1204,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)) { @@ -1234,6 +1239,8 @@ Dhcp4InstanceCreateUdpIo ( ) { DHCP_SERVICE *DhcpSb; + EFI_STATUS Status; + VOID *Udp4; ASSERT (Instance->Token != NULL); @@ -1248,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; } } @@ -1288,7 +1307,6 @@ PxeDhcpInput ( ) { DHCP_PROTOCOL *Instance; - DHCP_SERVICE *DhcpSb; EFI_DHCP4_HEADER *Head; NET_BUF *Wrap; EFI_DHCP4_PACKET *Packet; @@ -1299,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. @@ -1343,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; } @@ -1416,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; @@ -1461,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)) { @@ -1469,6 +1494,7 @@ EfiDhcp4TransmitReceive ( Instance = DHCP_INSTANCE_FROM_THIS (This); DhcpSb = Instance->Service; + DhcpSb->ActiveChild = Instance; if (Instance->Token != NULL) { // @@ -1492,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; } @@ -1553,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]); } @@ -1581,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;