]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Update IP4 stack to support point-to-point link with 31-bit mask.
authorFu Siyuan <siyuan.fu@intel.com>
Wed, 18 Oct 2017 02:13:39 +0000 (10:13 +0800)
committerFu Siyuan <siyuan.fu@intel.com>
Mon, 13 Nov 2017 05:52:17 +0000 (13:52 +0800)
V2 update: Directly use NetIp4IsUnicast() to check station address in IP driver.

This patch is to follow RFC3021 which allows to use 31-bit mask
in point-to-point link.
If a 31-bit subnet mask is assigned to a point-to-point link, it
leaves the <Host-number> with only 1 bit.  Consequently, only two
possible addresses may result:
  {<Network-number>, 0} and {<Network-number>, -1}
These addresses have historically been associated with network and
broadcast addresses (see Section 2.2).  In a point-to-point link with
a 31-bit subnet mask, the two addresses above MUST be interpreted as
host addresses.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>
MdeModulePkg/Include/Library/NetLib.h
MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c

index 4cd42270f6c03d386497890e18afed71fd6f4ef5..b9df46c50f63f73671654e246bdb37d8caf8d603 100644 (file)
@@ -414,8 +414,10 @@ NetGetIpClass (
 \r
   ASSERT if NetMask is zero.\r
   \r
 \r
   ASSERT if NetMask is zero.\r
   \r
-  If all bits of the host address of IP are 0 or 1, IP is also not a valid unicast address.\r
-\r
+  If all bits of the host address of IP are 0 or 1, IP is also not a valid unicast address,\r
+  except when the originator is one of the endpoints of a point-to-point link with a 31-bit\r
+  mask (RFC3021).\r
+  \r
   @param[in]  Ip                    The IP to check against.\r
   @param[in]  NetMask               The mask of the IP.\r
 \r
   @param[in]  Ip                    The IP to check against.\r
   @param[in]  NetMask               The mask of the IP.\r
 \r
index 1ee77fe03694475a81b07b8d627d6c3c72ec1ea2..b8544b89ab8d3f5bee7b5e94c1eb12f615b170c2 100644 (file)
@@ -637,7 +637,9 @@ NetGetIpClass (
 \r
   ASSERT if NetMask is zero.\r
   \r
 \r
   ASSERT if NetMask is zero.\r
   \r
-  If all bits of the host address of IP are 0 or 1, IP is also not a valid unicast address.\r
+  If all bits of the host address of IP are 0 or 1, IP is also not a valid unicast address,\r
+  except when the originator is one of the endpoints of a point-to-point link with a 31-bit\r
+  mask (RFC3021).\r
 \r
   @param[in]  Ip                    The IP to check against.\r
   @param[in]  NetMask               The mask of the IP.\r
 \r
   @param[in]  Ip                    The IP to check against.\r
   @param[in]  NetMask               The mask of the IP.\r
@@ -657,9 +659,13 @@ NetIp4IsUnicast (
   if (Ip == 0 || IP4_IS_LOCAL_BROADCAST (Ip)) {\r
     return FALSE;\r
   }\r
   if (Ip == 0 || IP4_IS_LOCAL_BROADCAST (Ip)) {\r
     return FALSE;\r
   }\r
-  \r
-  if (((Ip &~NetMask) == ~NetMask) || ((Ip &~NetMask) == 0)) {\r
-    return FALSE;\r
+\r
+  if (NetGetMaskLength (NetMask) != 31) {\r
+    if (((Ip &~NetMask) == ~NetMask) || ((Ip &~NetMask) == 0)) {\r
+      return FALSE;\r
+    }\r
+  } else {\r
+    return TRUE;\r
   }\r
 \r
   return TRUE;\r
   }\r
 \r
   return TRUE;\r
index 7c7d1820736a8abc687f6054f78887ad87ebf00c..b582ccf13f66836768ed6e7e57865ef6af269e3e 100644 (file)
@@ -287,10 +287,6 @@ Ip4StationAddressValid (
   IN IP4_ADDR               Netmask\r
   )\r
 {\r
   IN IP4_ADDR               Netmask\r
   )\r
 {\r
-  IP4_ADDR                  NetBrdcastMask;\r
-  INTN                      Len;\r
-  INTN                      Type;\r
-\r
   //\r
   // Only support the station address with 0.0.0.0/0 to enable DHCP client.\r
   //\r
   //\r
   // Only support the station address with 0.0.0.0/0 to enable DHCP client.\r
   //\r
@@ -301,29 +297,16 @@ Ip4StationAddressValid (
   //\r
   // Only support the continuous net masks\r
   //\r
   //\r
   // Only support the continuous net masks\r
   //\r
-  if ((Len = NetGetMaskLength (Netmask)) == (IP4_MASK_MAX + 1)) {\r
+  if (NetGetMaskLength (Netmask) == (IP4_MASK_MAX + 1)) {\r
     return FALSE;\r
   }\r
 \r
   //\r
   // Station address can't be class D or class E address\r
   //\r
     return FALSE;\r
   }\r
 \r
   //\r
   // Station address can't be class D or class E address\r
   //\r
-  if ((Type = NetGetIpClass (Ip)) > IP4_ADDR_CLASSC) {\r
-    return FALSE;\r
-  }\r
-\r
-  //\r
-  // Station address can't be subnet broadcast/net broadcast address\r
-  //\r
-  if ((Ip == (Ip & Netmask)) || (Ip == (Ip | ~Netmask))) {\r
+  if (NetGetIpClass (Ip) > IP4_ADDR_CLASSC) {\r
     return FALSE;\r
   }\r
 \r
     return FALSE;\r
   }\r
 \r
-  NetBrdcastMask = gIp4AllMasks[MIN (Len, Type << 3)];\r
-\r
-  if (Ip == (Ip | ~NetBrdcastMask)) {\r
-    return FALSE;\r
-  }\r
-\r
-  return TRUE;\r
-}
\ No newline at end of file
+  return NetIp4IsUnicast (Ip, Netmask);\r
+}\r