]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Include/Library/NetLib.h
MdeModulePkg: Update IP4 stack to support point-to-point link with 31-bit mask.
[mirror_edk2.git] / MdeModulePkg / Include / Library / NetLib.h
index c5c0fc212bd8191077c003a23e1d8df9505de2ac..b9df46c50f63f73671654e246bdb37d8caf8d603 100644 (file)
@@ -2,7 +2,7 @@
   This library is only intended to be used by UEFI network stack modules.\r
   It provides basic functions for the UEFI network stack.\r
 \r
-Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2017, 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<BR>\r
@@ -43,9 +43,9 @@ typedef UINT16          TCP_PORTNO;
 //\r
 // The address classification\r
 //\r
-#define  IP4_ADDR_CLASSA       1\r
-#define  IP4_ADDR_CLASSB       2\r
-#define  IP4_ADDR_CLASSC       3\r
+#define  IP4_ADDR_CLASSA       1     // Deprecated\r
+#define  IP4_ADDR_CLASSB       2     // Deprecated\r
+#define  IP4_ADDR_CLASSC       3     // Deprecated\r
 #define  IP4_ADDR_CLASSD       4\r
 #define  IP4_ADDR_CLASSE       5\r
 \r
@@ -231,6 +231,7 @@ typedef struct {
 // Test the IP's attribute, All the IPs are in host byte order.\r
 //\r
 #define IP4_IS_MULTICAST(Ip)              (((Ip) & 0xF0000000) == 0xE0000000)\r
+#define IP4_IS_UNSPECIFIED(Ip)            ((Ip) == 0)\r
 #define IP4_IS_LOCAL_BROADCAST(Ip)        ((Ip) == 0xFFFFFFFF)\r
 #define IP4_NET_EQUAL(Ip1, Ip2, NetMask)  (((Ip1) & (NetMask)) == ((Ip2) & (NetMask)))\r
 #define IP4_IS_VALID_NETMASK(Ip)          (NetGetMaskLength (Ip) != (IP4_MASK_MAX + 1))\r
@@ -379,6 +380,11 @@ NetGetMaskLength (
   Return the class of the IP address, such as class A, B, C.\r
   Addr is in host byte order.\r
 \r
+  [ATTENTION]\r
+  Classful addressing (IP class A/B/C) has been deprecated according to RFC4632.\r
+  Caller of this function could only check the returned value against\r
+  IP4_ADDR_CLASSD (multicast) or IP4_ADDR_CLASSE (reserved) now.\r
+\r
   The address of class A  starts with 0.\r
   If the address belong to class A, return IP4_ADDR_CLASSA.\r
   The address of class B  starts with 10.\r
@@ -404,17 +410,18 @@ NetGetIpClass (
 \r
 /**\r
   Check whether the IP is a valid unicast address according to\r
-  the netmask. If NetMask is zero, use the IP address's class to get the default mask.\r
-\r
-  If Ip is 0, IP is not a valid unicast address.\r
-  Class D address is used for multicasting and class E address is reserved for future. If Ip\r
-  belongs to class D or class E, Ip is not a valid unicast address.\r
-  If all bits of the host address of Ip are 0 or 1, Ip is not a valid unicast address.\r
+  the netmask. \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
+  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
-  @return TRUE if Ip is a valid unicast address on the network, otherwise FALSE.\r
+  @return TRUE if IP is a valid unicast address on the network, otherwise FALSE.\r
 \r
 **/\r
 BOOLEAN\r
@@ -518,6 +525,7 @@ extern IP4_ADDR gIp4AllMasks[IP4_MASK_NUM];
 extern EFI_IPv4_ADDRESS  mZeroIp4Addr;\r
 \r
 #define NET_IS_DIGIT(Ch)            (('0' <= (Ch)) && ((Ch) <= '9'))\r
+#define NET_IS_HEX(Ch)              ((('0' <= (Ch)) && ((Ch) <= '9')) || (('A' <= (Ch)) && ((Ch) <= 'F')) || (('a' <= (Ch)) && ((Ch) <= 'f')))\r
 #define NET_ROUNDUP(size, unit)     (((size) + (unit) - 1) & (~((unit) - 1)))\r
 #define NET_IS_LOWER_CASE_CHAR(Ch)  (('a' <= (Ch)) && ((Ch) <= 'z'))\r
 #define NET_IS_UPPER_CASE_CHAR(Ch)  (('A' <= (Ch)) && ((Ch) <= 'Z'))\r
@@ -1385,7 +1393,6 @@ NetLibAsciiStrToIp6 (
 \r
   @retval EFI_SUCCESS            Converted to an IPv4 address successfully.\r
   @retval EFI_INVALID_PARAMETER  The string is mal-formatted or Ip4Address is NULL.\r
-  @retval EFI_OUT_OF_RESOURCES   Failed to perform the operation due to lack of resources.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1404,7 +1411,6 @@ NetLibStrToIp4 (
 \r
   @retval EFI_SUCCESS            Converted to an IPv6 address successfully.\r
   @retval EFI_INVALID_PARAMETER  The string is malformatted or Ip6Address is NULL.\r
-  @retval EFI_OUT_OF_RESOURCES   Failed to perform the operation due to a lack of resources.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1425,7 +1431,6 @@ NetLibStrToIp6 (
 \r
   @retval EFI_SUCCESS            Converted to an  IPv6 address successfully.\r
   @retval EFI_INVALID_PARAMETER  The string is malformatted, or Ip6Address is NULL.\r
-  @retval EFI_OUT_OF_RESOURCES   Failed to perform the operation due to a lack of resources.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1604,10 +1609,10 @@ typedef struct {
   (sizeof (NET_BUF) + ((BlockOpNum) - 1) * sizeof (NET_BLOCK_OP))\r
 \r
 #define NET_HEADSPACE(BlockOp)  \\r
-  (UINTN)((BlockOp)->Head - (BlockOp)->BlockHead)\r
+  ((UINTN)((BlockOp)->Head) - (UINTN)((BlockOp)->BlockHead))\r
 \r
 #define NET_TAILSPACE(BlockOp)  \\r
-  (UINTN)((BlockOp)->BlockTail - (BlockOp)->Tail)\r
+  ((UINTN)((BlockOp)->BlockTail) - (UINTN)((BlockOp)->Tail))\r
 \r
 /**\r
   Allocate a single block NET_BUF. Upon allocation, all the\r