]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Support classless IP for DHCPv4 TransmitReceive()
authorJiaxin Wu <jiaxin.wu@intel.com>
Thu, 18 Aug 2016 05:31:07 +0000 (13:31 +0800)
committerJiaxin Wu <jiaxin.wu@intel.com>
Tue, 6 Sep 2016 11:00:00 +0000 (19:00 +0800)
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>
MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c

index 4f491b4bba3b3bed6fc4a124080d7bc6724e7fb5..79f7cded8ddd9f965250da6ee683448f402b3bfa 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   This file implement the EFI_DHCP4_PROTOCOL interface.\r
 \r
-Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -1188,6 +1188,7 @@ Dhcp4InstanceConfigUdpIo (
   )\r
 {\r
   DHCP_PROTOCOL                     *Instance;\r
+  DHCP_SERVICE                      *DhcpSb;\r
   EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN  *Token;\r
   EFI_UDP4_CONFIG_DATA              UdpConfigData;\r
   IP4_ADDR                          ClientAddr;\r
@@ -1196,6 +1197,7 @@ Dhcp4InstanceConfigUdpIo (
   IP4_ADDR                          SubnetMask;\r
 \r
   Instance = (DHCP_PROTOCOL *) Context;\r
+  DhcpSb   = Instance->Service;\r
   Token    = Instance->Token;\r
 \r
   ZeroMem (&UdpConfigData, sizeof (EFI_UDP4_CONFIG_DATA));\r
@@ -1208,10 +1210,15 @@ Dhcp4InstanceConfigUdpIo (
   ClientAddr = EFI_NTOHL (Token->Packet->Dhcp4.Header.ClientAddr);\r
   Ip = HTONL (ClientAddr);\r
   CopyMem (&UdpConfigData.StationAddress, &Ip, sizeof (EFI_IPv4_ADDRESS));\r
-  \r
-  Class = NetGetIpClass (ClientAddr);\r
-  ASSERT (Class < IP4_ADDR_CLASSE);\r
-  SubnetMask = gIp4AllMasks[Class << 3];\r
+\r
+  if (DhcpSb->Netmask == 0) {\r
+    Class = NetGetIpClass (ClientAddr);\r
+    ASSERT (Class < IP4_ADDR_CLASSE);\r
+    SubnetMask = gIp4AllMasks[Class << 3];\r
+  } else {\r
+    SubnetMask = DhcpSb->Netmask;\r
+  }\r
+\r
   Ip = HTONL (SubnetMask);\r
   CopyMem (&UdpConfigData.SubnetMask, &Ip, sizeof (EFI_IPv4_ADDRESS));\r
 \r
@@ -1576,12 +1583,17 @@ EfiDhcp4TransmitReceive (
     EndPoint.RemotePort = Token->RemotePort;\r
   }\r
 \r
+  if (DhcpSb->Netmask == 0) {\r
+    Class = NetGetIpClass (ClientAddr);\r
+    ASSERT (Class < IP4_ADDR_CLASSE);\r
+    SubnetMask = gIp4AllMasks[Class << 3];\r
+  } else {\r
+    SubnetMask = DhcpSb->Netmask;\r
+  }\r
+  \r
   //\r
   // Get the gateway.\r
   //\r
-  Class = NetGetIpClass (ClientAddr);\r
-  ASSERT (Class < IP4_ADDR_CLASSE);\r
-  SubnetMask = gIp4AllMasks[Class << 3];\r
   ZeroMem (&Gateway, sizeof (Gateway));\r
   if (!IP4_NET_EQUAL (ClientAddr, EndPoint.RemoteAddr.Addr[0], SubnetMask)) {\r
     CopyMem (&Gateway.v4, &Token->GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r