]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Add new macros and refine codes
authorZhang Lubo <lubo.zhang@intel.com>
Fri, 8 Apr 2016 01:48:14 +0000 (09:48 +0800)
committerJiaxin Wu <jiaxin.wu@intel.com>
Mon, 11 Apr 2016 00:25:33 +0000 (08:25 +0800)
Add 2 macros inNetLib.h
#define  IP4_MASK_MAX          32
#define  IP6_PREFIX_MAX        128
we will use these two macros to check the max mask/prefix length,
instead of
#define  IP4_MASK_NUM          33
#define  IP6_PREFIX_NUM        129
which means a valid number.
This will make the code readability and maintainability.

Cc: Subramanian Sriram <sriram-s@hpe.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Zhang Lubo <lubo.zhang@intel.com>
Reviewed-by: Sriram Subramanian <sriram-s@hpe.com>
MdeModulePkg/Include/Library/NetLib.h
MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Route.c

index b871a857f950a337fadd6efea267cf80e917292c..87f393e2de045ff3020b80305294bded71f23e6a 100644 (file)
@@ -52,6 +52,9 @@ typedef UINT16          TCP_PORTNO;
 #define  IP4_MASK_NUM          33\r
 #define  IP6_PREFIX_NUM        129\r
 \r
+#define  IP4_MASK_MAX          32 \r
+#define  IP6_PREFIX_MAX        128\r
+\r
 #define  IP6_HOP_BY_HOP        0\r
 #define  IP6_DESTINATION       60\r
 #define  IP6_ROUTING           43\r
@@ -230,7 +233,7 @@ typedef struct {
 #define IP4_IS_MULTICAST(Ip)              (((Ip) & 0xF0000000) == 0xE0000000)\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_NUM)\r
+#define IP4_IS_VALID_NETMASK(Ip)          (NetGetMaskLength (Ip) != (IP4_MASK_MAX + 1))\r
 \r
 #define IP6_IS_MULTICAST(Ip6)             (((Ip6)->Addr[0]) == 0xFF)\r
 \r
index ebc3e125a21736148ba9fb609bc19b6d25a11e67..4acd0fad2c4dd2f884284a6cf50d81ec5c1be4f9 100644 (file)
@@ -565,7 +565,7 @@ NetGetMaskLength (
 {\r
   INTN                      Index;\r
 \r
-  for (Index = 0; Index < IP4_MASK_NUM; Index++) {\r
+  for (Index = 0; Index <= IP4_MASK_MAX; Index++) {\r
     if (NetMask == gIp4AllMasks[Index]) {\r
       break;\r
     }\r
@@ -794,7 +794,7 @@ NetIp6IsNetEqual (
   UINT8 Bit;\r
   UINT8 Mask;\r
 \r
-  ASSERT ((Ip1 != NULL) && (Ip2 != NULL) && (PrefixLength < IP6_PREFIX_NUM));\r
+  ASSERT ((Ip1 != NULL) && (Ip2 != NULL) && (PrefixLength <= IP6_PREFIX_MAX));\r
 \r
   if (PrefixLength == 0) {\r
     return TRUE;\r
@@ -3115,7 +3115,7 @@ NetLibStrToIp6andPrefix (
     while (*PrefixStr != '\0') {\r
       if (NET_IS_DIGIT (*PrefixStr)) {\r
         Length = (UINT8) (Length * 10 + (*PrefixStr - '0'));\r
-        if (Length >= IP6_PREFIX_NUM) {\r
+        if (Length > IP6_PREFIX_MAX) {\r
           goto Exit;\r
         }\r
       } else {\r
index 17e0247832200cbf3fe7504ab762544cff18b5d4..d0fa1326215e7c469734c31a15949748acd25fc5 100644 (file)
@@ -416,7 +416,7 @@ Ip4Config2BuildDefaultRouteTable (
   //\r
   Count = 0;\r
 \r
-  for (Index = IP4_MASK_NUM - 1; Index >= 0; Index--) {\r
+  for (Index = IP4_MASK_MAX; Index >= 0; Index--) {\r
 \r
     NET_LIST_FOR_EACH (Entry, &(IpSb->DefaultRouteTable->RouteArea[Index])) {\r
       RtEntry = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_ENTRY, Link);\r
index 669e041c102929adaa9a8dea3417121462756b14..e45727679638106bf2a021d833fa822fbb43aa8e 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implement IP4 pesudo interface.\r
   \r
-Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 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
@@ -581,7 +581,7 @@ Ip4SetAddress (
   Type                      = NetGetIpClass (IpAddr);\r
   ASSERT (Type <= IP4_ADDR_CLASSC);\r
   Len                       = NetGetMaskLength (SubnetMask);\r
-  ASSERT (Len < IP4_MASK_NUM);\r
+  ASSERT (Len <= IP4_MASK_MAX);\r
   Netmask                   = gIp4AllMasks[MIN (Len, Type << 3)];\r
   Interface->NetBrdcast     = (IpAddr | ~Netmask);\r
 \r
index 58adba7c8c158518dcaa5ff55d8378a46fc4dc28..e733816556bf888dacb71af921da42a554860a41 100644 (file)
@@ -838,7 +838,7 @@ Ip4StationAddressValid (
   //\r
   // Only support the continuous net masks\r
   //\r
-  if ((Len = NetGetMaskLength (Netmask)) == IP4_MASK_NUM) {\r
+  if ((Len = NetGetMaskLength (Netmask)) == (IP4_MASK_MAX + 1)) {\r
     return FALSE;\r
   }\r
 \r
index ea0023ddcb2d823d3f8cf50a5ef2720955c1dccd..d240d5343aea366a3f0acab82ef73f09724114e6 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2005 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 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
@@ -204,7 +204,7 @@ Ip4CreateRouteTable (
   RtTable->RefCnt   = 1;\r
   RtTable->TotalNum = 0;\r
 \r
-  for (Index = 0; Index < IP4_MASK_NUM; Index++) {\r
+  for (Index = 0; Index <= IP4_MASK_MAX; Index++) {\r
     InitializeListHead (&(RtTable->RouteArea[Index]));\r
   }\r
 \r
@@ -241,7 +241,7 @@ Ip4FreeRouteTable (
   //\r
   // Free all the route table entry and its route cache.\r
   //\r
-  for (Index = 0; Index < IP4_MASK_NUM; Index++) {\r
+  for (Index = 0; Index <= IP4_MASK_MAX; Index++) {\r
     NET_LIST_FOR_EACH_SAFE (Entry, Next, &(RtTable->RouteArea[Index])) {\r
       RtEntry = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_ENTRY, Link);\r
 \r
@@ -469,7 +469,7 @@ Ip4FindRouteEntry (
 \r
   RtEntry = NULL;\r
 \r
-  for (Index = IP4_MASK_NUM - 1; Index >= 0; Index--) {\r
+  for (Index = IP4_MASK_MAX; Index >= 0; Index--) {\r
     for (Table = RtTable; Table != NULL; Table = Table->Next) {\r
       NET_LIST_FOR_EACH (Entry, &Table->RouteArea[Index]) {\r
         RtEntry = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_ENTRY, Link);\r
@@ -641,7 +641,7 @@ Ip4BuildEfiRouteTable (
   //\r
   Count = 0;\r
 \r
-  for (Index = IP4_MASK_NUM - 1; Index >= 0; Index--) {\r
+  for (Index = IP4_MASK_MAX; Index >= 0; Index--) {\r
     for (RtTable = IpInstance->RouteTable; RtTable != NULL; RtTable = RtTable->Next) {\r
       NET_LIST_FOR_EACH (Entry, &(RtTable->RouteArea[Index])) {\r
         RtEntry = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_ENTRY, Link);\r