summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiaxin Wu <jiaxin.wu@intel.com>2016-08-18 13:31:07 +0800
committerFu Siyuan <siyuan.fu@intel.com>2017-05-17 10:17:59 +0800
commit7cc582ee7915cb933990ecf4e4b5fe7ca4916a20 (patch)
treeec09b534b2245ddb3bbe54f7f47aeff3431d7ba7
parent6404e16dbbf89fffc246bdc627de8be8e3a3003e (diff)
downloadedk2-7cc582ee7915cb933990ecf4e4b5fe7ca4916a20.tar.gz
MdeModulePkg: Support classless IP for DHCPv4 TransmitReceive()
The IP address should not be treated as classful one if DHCP options contain a classless IP with its true subnet mask. Otherwise, DHCPv4 TransmitReceive() will failed. This real subnet mask will be parsed and recorded in DhcpSb->Netmask. So, we need check it before get the IP's corresponding subnet mask. Cc: Santhapur Naveen <naveens@amiindia.co.in> Cc: Ye Ting <ting.ye@intel.com> Cc: Fu Siyuan <siyuan.fu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com> Reviewed-by: Fu Siyuan <siyuan.fu@intel.com> (cherry picked from commit 8c5f78a2cc15199e3f77ae4b156023af366fd6c7)
-rw-r--r--MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c
index 4f491b4bba..79f7cded8d 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.<BR>
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
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,6 +1188,7 @@ Dhcp4InstanceConfigUdpIo (
)
{
DHCP_PROTOCOL *Instance;
+ DHCP_SERVICE *DhcpSb;
EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN *Token;
EFI_UDP4_CONFIG_DATA UdpConfigData;
IP4_ADDR ClientAddr;
@@ -1196,6 +1197,7 @@ Dhcp4InstanceConfigUdpIo (
IP4_ADDR SubnetMask;
Instance = (DHCP_PROTOCOL *) Context;
+ DhcpSb = Instance->Service;
Token = Instance->Token;
ZeroMem (&UdpConfigData, sizeof (EFI_UDP4_CONFIG_DATA));
@@ -1208,10 +1210,15 @@ 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) {
+ 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));
@@ -1576,12 +1583,17 @@ EfiDhcp4TransmitReceive (
EndPoint.RemotePort = Token->RemotePort;
}
+ if (DhcpSb->Netmask == 0) {
+ Class = NetGetIpClass (ClientAddr);
+ ASSERT (Class < IP4_ADDR_CLASSE);
+ SubnetMask = gIp4AllMasks[Class << 3];
+ } else {
+ SubnetMask = DhcpSb->Netmask;
+ }
+
//
// 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)) {
CopyMem (&Gateway.v4, &Token->GatewayAddress, sizeof (EFI_IPv4_ADDRESS));