mirror of https://github.com/acidanthera/audk.git
MdeModulePkg: Add new macros and refine codes
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>
This commit is contained in:
parent
c720da2866
commit
364f4efa44
|
@ -52,6 +52,9 @@ typedef UINT16 TCP_PORTNO;
|
|||
#define IP4_MASK_NUM 33
|
||||
#define IP6_PREFIX_NUM 129
|
||||
|
||||
#define IP4_MASK_MAX 32
|
||||
#define IP6_PREFIX_MAX 128
|
||||
|
||||
#define IP6_HOP_BY_HOP 0
|
||||
#define IP6_DESTINATION 60
|
||||
#define IP6_ROUTING 43
|
||||
|
@ -230,7 +233,7 @@ typedef struct {
|
|||
#define IP4_IS_MULTICAST(Ip) (((Ip) & 0xF0000000) == 0xE0000000)
|
||||
#define IP4_IS_LOCAL_BROADCAST(Ip) ((Ip) == 0xFFFFFFFF)
|
||||
#define IP4_NET_EQUAL(Ip1, Ip2, NetMask) (((Ip1) & (NetMask)) == ((Ip2) & (NetMask)))
|
||||
#define IP4_IS_VALID_NETMASK(Ip) (NetGetMaskLength (Ip) != IP4_MASK_NUM)
|
||||
#define IP4_IS_VALID_NETMASK(Ip) (NetGetMaskLength (Ip) != (IP4_MASK_MAX + 1))
|
||||
|
||||
#define IP6_IS_MULTICAST(Ip6) (((Ip6)->Addr[0]) == 0xFF)
|
||||
|
||||
|
|
|
@ -565,7 +565,7 @@ NetGetMaskLength (
|
|||
{
|
||||
INTN Index;
|
||||
|
||||
for (Index = 0; Index < IP4_MASK_NUM; Index++) {
|
||||
for (Index = 0; Index <= IP4_MASK_MAX; Index++) {
|
||||
if (NetMask == gIp4AllMasks[Index]) {
|
||||
break;
|
||||
}
|
||||
|
@ -794,7 +794,7 @@ NetIp6IsNetEqual (
|
|||
UINT8 Bit;
|
||||
UINT8 Mask;
|
||||
|
||||
ASSERT ((Ip1 != NULL) && (Ip2 != NULL) && (PrefixLength < IP6_PREFIX_NUM));
|
||||
ASSERT ((Ip1 != NULL) && (Ip2 != NULL) && (PrefixLength <= IP6_PREFIX_MAX));
|
||||
|
||||
if (PrefixLength == 0) {
|
||||
return TRUE;
|
||||
|
@ -3115,7 +3115,7 @@ NetLibStrToIp6andPrefix (
|
|||
while (*PrefixStr != '\0') {
|
||||
if (NET_IS_DIGIT (*PrefixStr)) {
|
||||
Length = (UINT8) (Length * 10 + (*PrefixStr - '0'));
|
||||
if (Length >= IP6_PREFIX_NUM) {
|
||||
if (Length > IP6_PREFIX_MAX) {
|
||||
goto Exit;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -416,7 +416,7 @@ Ip4Config2BuildDefaultRouteTable (
|
|||
//
|
||||
Count = 0;
|
||||
|
||||
for (Index = IP4_MASK_NUM - 1; Index >= 0; Index--) {
|
||||
for (Index = IP4_MASK_MAX; Index >= 0; Index--) {
|
||||
|
||||
NET_LIST_FOR_EACH (Entry, &(IpSb->DefaultRouteTable->RouteArea[Index])) {
|
||||
RtEntry = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_ENTRY, Link);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/** @file
|
||||
Implement IP4 pesudo interface.
|
||||
|
||||
Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
|
@ -581,7 +581,7 @@ Ip4SetAddress (
|
|||
Type = NetGetIpClass (IpAddr);
|
||||
ASSERT (Type <= IP4_ADDR_CLASSC);
|
||||
Len = NetGetMaskLength (SubnetMask);
|
||||
ASSERT (Len < IP4_MASK_NUM);
|
||||
ASSERT (Len <= IP4_MASK_MAX);
|
||||
Netmask = gIp4AllMasks[MIN (Len, Type << 3)];
|
||||
Interface->NetBrdcast = (IpAddr | ~Netmask);
|
||||
|
||||
|
|
|
@ -838,7 +838,7 @@ Ip4StationAddressValid (
|
|||
//
|
||||
// Only support the continuous net masks
|
||||
//
|
||||
if ((Len = NetGetMaskLength (Netmask)) == IP4_MASK_NUM) {
|
||||
if ((Len = NetGetMaskLength (Netmask)) == (IP4_MASK_MAX + 1)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/** @file
|
||||
|
||||
Copyright (c) 2005 - 2009, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
|
@ -204,7 +204,7 @@ Ip4CreateRouteTable (
|
|||
RtTable->RefCnt = 1;
|
||||
RtTable->TotalNum = 0;
|
||||
|
||||
for (Index = 0; Index < IP4_MASK_NUM; Index++) {
|
||||
for (Index = 0; Index <= IP4_MASK_MAX; Index++) {
|
||||
InitializeListHead (&(RtTable->RouteArea[Index]));
|
||||
}
|
||||
|
||||
|
@ -241,7 +241,7 @@ Ip4FreeRouteTable (
|
|||
//
|
||||
// Free all the route table entry and its route cache.
|
||||
//
|
||||
for (Index = 0; Index < IP4_MASK_NUM; Index++) {
|
||||
for (Index = 0; Index <= IP4_MASK_MAX; Index++) {
|
||||
NET_LIST_FOR_EACH_SAFE (Entry, Next, &(RtTable->RouteArea[Index])) {
|
||||
RtEntry = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_ENTRY, Link);
|
||||
|
||||
|
@ -469,7 +469,7 @@ Ip4FindRouteEntry (
|
|||
|
||||
RtEntry = NULL;
|
||||
|
||||
for (Index = IP4_MASK_NUM - 1; Index >= 0; Index--) {
|
||||
for (Index = IP4_MASK_MAX; Index >= 0; Index--) {
|
||||
for (Table = RtTable; Table != NULL; Table = Table->Next) {
|
||||
NET_LIST_FOR_EACH (Entry, &Table->RouteArea[Index]) {
|
||||
RtEntry = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_ENTRY, Link);
|
||||
|
@ -641,7 +641,7 @@ Ip4BuildEfiRouteTable (
|
|||
//
|
||||
Count = 0;
|
||||
|
||||
for (Index = IP4_MASK_NUM - 1; Index >= 0; Index--) {
|
||||
for (Index = IP4_MASK_MAX; Index >= 0; Index--) {
|
||||
for (RtTable = IpInstance->RouteTable; RtTable != NULL; RtTable = RtTable->Next) {
|
||||
NET_LIST_FOR_EACH (Entry, &(RtTable->RouteArea[Index])) {
|
||||
RtEntry = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_ENTRY, Link);
|
||||
|
|
Loading…
Reference in New Issue