public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch] MdeModulePkg: Update IP4 stack to support point-to-point link with 31-bit mask.
@ 2017-10-18  5:17 Fu Siyuan
  2017-11-10  6:56 ` Wu, Jiaxin
  0 siblings, 1 reply; 2+ messages in thread
From: Fu Siyuan @ 2017-10-18  5:17 UTC (permalink / raw)
  To: edk2-devel; +Cc: Wu Jiaxin, Ye Ting

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>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
---
 MdeModulePkg/Include/Library/NetLib.h             |  6 ++++--
 MdeModulePkg/Library/DxeNetLib/DxeNetLib.c        | 14 ++++++++++----
 MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c | 20 +++++++++++++-------
 3 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/MdeModulePkg/Include/Library/NetLib.h b/MdeModulePkg/Include/Library/NetLib.h
index 4cd4227..b9df46c 100644
--- a/MdeModulePkg/Include/Library/NetLib.h
+++ b/MdeModulePkg/Include/Library/NetLib.h
@@ -414,8 +414,10 @@ NetGetIpClass (
 
   ASSERT if NetMask is zero.
   
-  If all bits of the host address of IP are 0 or 1, IP is also not a valid unicast address.
-
+  If all bits of the host address of IP are 0 or 1, IP is also not a valid unicast address,
+  except when the originator is one of the endpoints of a point-to-point link with a 31-bit
+  mask (RFC3021).
+  
   @param[in]  Ip                    The IP to check against.
   @param[in]  NetMask               The mask of the IP.
 
diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
index 1ee77fe..b8544b8 100644
--- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
+++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
@@ -637,7 +637,9 @@ NetGetIpClass (
 
   ASSERT if NetMask is zero.
   
-  If all bits of the host address of IP are 0 or 1, IP is also not a valid unicast address.
+  If all bits of the host address of IP are 0 or 1, IP is also not a valid unicast address,
+  except when the originator is one of the endpoints of a point-to-point link with a 31-bit
+  mask (RFC3021).
 
   @param[in]  Ip                    The IP to check against.
   @param[in]  NetMask               The mask of the IP.
@@ -657,9 +659,13 @@ NetIp4IsUnicast (
   if (Ip == 0 || IP4_IS_LOCAL_BROADCAST (Ip)) {
     return FALSE;
   }
-  
-  if (((Ip &~NetMask) == ~NetMask) || ((Ip &~NetMask) == 0)) {
-    return FALSE;
+
+  if (NetGetMaskLength (NetMask) != 31) {
+    if (((Ip &~NetMask) == ~NetMask) || ((Ip &~NetMask) == 0)) {
+      return FALSE;
+    }
+  } else {
+    return TRUE;
   }
 
   return TRUE;
diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
index 7c7d182..b8160c1 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
@@ -314,16 +314,22 @@ Ip4StationAddressValid (
 
   //
   // Station address can't be subnet broadcast/net broadcast address
+  // RFC3021: In a point-to-point network with 31-bit mask, the <Host-number> only has
+  // 1 bit, only two possible addresses may result:
+  //   {<Network-number>, 0} and {<Network-number>, -1}
+  // The two address above must be interpreted as host addresses.
   //
-  if ((Ip == (Ip & Netmask)) || (Ip == (Ip | ~Netmask))) {
-    return FALSE;
-  }
+  if (Len != 31) {
+    if ((Ip == (Ip & Netmask)) || (Ip == (Ip | ~Netmask))) {
+      return FALSE;
+    }
 
-  NetBrdcastMask = gIp4AllMasks[MIN (Len, Type << 3)];
+    NetBrdcastMask = gIp4AllMasks[MIN (Len, Type << 3)];
 
-  if (Ip == (Ip | ~NetBrdcastMask)) {
-    return FALSE;
+    if (Ip == (Ip | ~NetBrdcastMask)) {
+      return FALSE;
+    }
   }
 
   return TRUE;
-}
\ No newline at end of file
+}
-- 
1.9.5.msysgit.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Patch] MdeModulePkg: Update IP4 stack to support point-to-point link with 31-bit mask.
  2017-10-18  5:17 [Patch] MdeModulePkg: Update IP4 stack to support point-to-point link with 31-bit mask Fu Siyuan
@ 2017-11-10  6:56 ` Wu, Jiaxin
  0 siblings, 0 replies; 2+ messages in thread
From: Wu, Jiaxin @ 2017-11-10  6:56 UTC (permalink / raw)
  To: Fu, Siyuan, edk2-devel@lists.01.org; +Cc: Ye, Ting

Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>



> -----Original Message-----
> From: Fu, Siyuan
> Sent: Wednesday, October 18, 2017 1:17 PM
> To: edk2-devel@lists.01.org
> Cc: Wu, Jiaxin <jiaxin.wu@intel.com>; Ye, Ting <ting.ye@intel.com>
> Subject: [Patch] MdeModulePkg: Update IP4 stack to support point-to-point
> link with 31-bit mask.
> 
> 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>
> Cc: Wu Jiaxin <jiaxin.wu@intel.com>
> Cc: Ye Ting <ting.ye@intel.com>
> ---
>  MdeModulePkg/Include/Library/NetLib.h             |  6 ++++--
>  MdeModulePkg/Library/DxeNetLib/DxeNetLib.c        | 14 ++++++++++----
>  MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c | 20
> +++++++++++++-------
>  3 files changed, 27 insertions(+), 13 deletions(-)
> 
> diff --git a/MdeModulePkg/Include/Library/NetLib.h
> b/MdeModulePkg/Include/Library/NetLib.h
> index 4cd4227..b9df46c 100644
> --- a/MdeModulePkg/Include/Library/NetLib.h
> +++ b/MdeModulePkg/Include/Library/NetLib.h
> @@ -414,8 +414,10 @@ NetGetIpClass (
> 
>    ASSERT if NetMask is zero.
> 
> -  If all bits of the host address of IP are 0 or 1, IP is also not a valid unicast
> address.
> -
> +  If all bits of the host address of IP are 0 or 1, IP is also not a valid unicast
> address,
> +  except when the originator is one of the endpoints of a point-to-point link
> with a 31-bit
> +  mask (RFC3021).
> +
>    @param[in]  Ip                    The IP to check against.
>    @param[in]  NetMask               The mask of the IP.
> 
> diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
> b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
> index 1ee77fe..b8544b8 100644
> --- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
> +++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
> @@ -637,7 +637,9 @@ NetGetIpClass (
> 
>    ASSERT if NetMask is zero.
> 
> -  If all bits of the host address of IP are 0 or 1, IP is also not a valid unicast
> address.
> +  If all bits of the host address of IP are 0 or 1, IP is also not a valid unicast
> address,
> +  except when the originator is one of the endpoints of a point-to-point link
> with a 31-bit
> +  mask (RFC3021).
> 
>    @param[in]  Ip                    The IP to check against.
>    @param[in]  NetMask               The mask of the IP.
> @@ -657,9 +659,13 @@ NetIp4IsUnicast (
>    if (Ip == 0 || IP4_IS_LOCAL_BROADCAST (Ip)) {
>      return FALSE;
>    }
> -
> -  if (((Ip &~NetMask) == ~NetMask) || ((Ip &~NetMask) == 0)) {
> -    return FALSE;
> +
> +  if (NetGetMaskLength (NetMask) != 31) {
> +    if (((Ip &~NetMask) == ~NetMask) || ((Ip &~NetMask) == 0)) {
> +      return FALSE;
> +    }
> +  } else {
> +    return TRUE;
>    }
> 
>    return TRUE;
> diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
> b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
> index 7c7d182..b8160c1 100644
> --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
> +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
> @@ -314,16 +314,22 @@ Ip4StationAddressValid (
> 
>    //
>    // Station address can't be subnet broadcast/net broadcast address
> +  // RFC3021: In a point-to-point network with 31-bit mask, the <Host-
> number> only has
> +  // 1 bit, only two possible addresses may result:
> +  //   {<Network-number>, 0} and {<Network-number>, -1}
> +  // The two address above must be interpreted as host addresses.
>    //
> -  if ((Ip == (Ip & Netmask)) || (Ip == (Ip | ~Netmask))) {
> -    return FALSE;
> -  }
> +  if (Len != 31) {
> +    if ((Ip == (Ip & Netmask)) || (Ip == (Ip | ~Netmask))) {
> +      return FALSE;
> +    }
> 
> -  NetBrdcastMask = gIp4AllMasks[MIN (Len, Type << 3)];
> +    NetBrdcastMask = gIp4AllMasks[MIN (Len, Type << 3)];
> 
> -  if (Ip == (Ip | ~NetBrdcastMask)) {
> -    return FALSE;
> +    if (Ip == (Ip | ~NetBrdcastMask)) {
> +      return FALSE;
> +    }
>    }
> 
>    return TRUE;
> -}
> \ No newline at end of file
> +}
> --
> 1.9.5.msysgit.1



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-11-10  6:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-18  5:17 [Patch] MdeModulePkg: Update IP4 stack to support point-to-point link with 31-bit mask Fu Siyuan
2017-11-10  6:56 ` Wu, Jiaxin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox