X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FDhcp4Dxe%2FDhcp4Impl.c;h=1db4c667d7cce721048ba2f02fb1a395e2e43f98;hp=821dfbb450a7b592b7d42ac8b828a68d2f8b36c4;hb=24648548886af2563f7a0c2f42da18bb89e40b2d;hpb=27f19717275af51d13df543c6627e1d743eb11cf diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c index 821dfbb450..1db4c667d7 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 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2016, 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 @@ -660,9 +660,7 @@ EfiDhcp4Configure ( } CopyMem (&Ip, &Dhcp4CfgData->ClientAddress, sizeof (IP4_ADDR)); - - if ((Ip != 0) && !NetIp4IsUnicast (NTOHL (Ip), 0)) { - + if (IP4_IS_LOCAL_BROADCAST(NTOHL (Ip))) { return EFI_INVALID_PARAMETER; } } @@ -1188,14 +1186,16 @@ Dhcp4InstanceConfigUdpIo ( ) { DHCP_PROTOCOL *Instance; + DHCP_SERVICE *DhcpSb; EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN *Token; EFI_UDP4_CONFIG_DATA UdpConfigData; IP4_ADDR ClientAddr; - IP4_ADDR Ip; + IP4_ADDR Ip; INTN Class; - IP4_ADDR SubnetMask; + IP4_ADDR SubnetMask; Instance = (DHCP_PROTOCOL *) Context; + DhcpSb = Instance->Service; Token = Instance->Token; ZeroMem (&UdpConfigData, sizeof (EFI_UDP4_CONFIG_DATA)); @@ -1208,10 +1208,22 @@ Dhcp4InstanceConfigUdpIo ( ClientAddr = EFI_NTOHL (Token->Packet->Dhcp4.Header.ClientAddr); Ip = HTONL (ClientAddr); CopyMem (&UdpConfigData.StationAddress, &Ip, sizeof (EFI_IPv4_ADDRESS)); - - Class = NetGetIpClass (ClientAddr); - ASSERT (Class < IP4_ADDR_CLASSE); - SubnetMask = gIp4AllMasks[Class << 3]; + + if (DhcpSb->Netmask == 0) { + // + // The Dhcp4.TransmitReceive() API should be able to used at any time according to + // UEFI spec, while in classless addressing network, the netmask must be explicitly + // provided together with the station address. + // If the DHCP instance haven't be configured with a valid netmask, we could only + // compute it according to the classful addressing rule. + // + Class = NetGetIpClass (ClientAddr); + ASSERT (Class < IP4_ADDR_CLASSE); + SubnetMask = gIp4AllMasks[Class << 3]; + } else { + SubnetMask = DhcpSb->Netmask; + } + Ip = HTONL (SubnetMask); CopyMem (&UdpConfigData.SubnetMask, &Ip, sizeof (EFI_IPv4_ADDRESS)); @@ -1485,8 +1497,6 @@ EfiDhcp4TransmitReceive ( DHCP_SERVICE *DhcpSb; EFI_IP_ADDRESS Gateway; IP4_ADDR ClientAddr; - INTN Class; - IP4_ADDR SubnetMask; if ((This == NULL) || (Token == NULL) || (Token->Packet == NULL)) { return EFI_INVALID_PARAMETER; @@ -1494,7 +1504,6 @@ EfiDhcp4TransmitReceive ( Instance = DHCP_INSTANCE_FROM_THIS (This); DhcpSb = Instance->Service; - DhcpSb->ActiveChild = Instance; if (Instance->Token != NULL) { // @@ -1580,11 +1589,8 @@ EfiDhcp4TransmitReceive ( // // Get the gateway. // - Class = NetGetIpClass (ClientAddr); - ASSERT (Class < IP4_ADDR_CLASSE); - SubnetMask = gIp4AllMasks[Class << 3]; ZeroMem (&Gateway, sizeof (Gateway)); - if (!IP4_NET_EQUAL (ClientAddr, EndPoint.RemoteAddr.Addr[0], SubnetMask)) { + if (!IP4_NET_EQUAL (ClientAddr, EndPoint.RemoteAddr.Addr[0], DhcpSb->Netmask)) { CopyMem (&Gateway.v4, &Token->GatewayAddress, sizeof (EFI_IPv4_ADDRESS)); Gateway.Addr[0] = NTOHL (Gateway.Addr[0]); }