NetworkPkg: Add new macros and refine codes

v2:
*refine some codes

Add 2 macros in NetLib.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:
Zhang Lubo 2016-04-08 09:44:09 +08:00 committed by Jiaxin Wu
parent 70dc0b809c
commit c720da2866
5 changed files with 15 additions and 15 deletions

View File

@ -1,7 +1,7 @@
/** @file /** @file
The implementation of common functions shared by IP6 driver. The implementation of common functions shared by IP6 driver.
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR> Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
@ -428,7 +428,7 @@ Ip6RemoveAddr (
IP6_ADDRESS_INFO *AddrInfo; IP6_ADDRESS_INFO *AddrInfo;
EFI_IPv6_ADDRESS SnMCastAddr; EFI_IPv6_ADDRESS SnMCastAddr;
if (IsListEmpty (AddressList) || *AddressCount < 1 || PrefixLength > IP6_PREFIX_NUM) { if (IsListEmpty (AddressList) || *AddressCount < 1 || PrefixLength > IP6_PREFIX_MAX) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -606,7 +606,7 @@ Ip6CopyAddressByPrefix (
UINT8 Mask; UINT8 Mask;
ASSERT (Dest != NULL && Src != NULL); ASSERT (Dest != NULL && Src != NULL);
ASSERT (PrefixLength < IP6_PREFIX_NUM); ASSERT (PrefixLength <= IP6_PREFIX_MAX);
Byte = (UINT8) (PrefixLength / 8); Byte = (UINT8) (PrefixLength / 8);
Bit = (UINT8) (PrefixLength % 8); Bit = (UINT8) (PrefixLength % 8);

View File

@ -1,7 +1,7 @@
/** @file /** @file
The ICMPv6 handle routines to process the ICMPv6 control messages. The ICMPv6 handle routines to process the ICMPv6 control messages.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR> Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR> (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
This program and the accompanying materials This program and the accompanying materials
@ -473,14 +473,14 @@ Ip6GetPrefix (
UINT8 Mask; UINT8 Mask;
UINT8 Value; UINT8 Value;
ASSERT ((Prefix != NULL) && (PrefixLength < IP6_PREFIX_NUM)); ASSERT ((Prefix != NULL) && (PrefixLength < IP6_PREFIX_MAX));
if (PrefixLength == 0) { if (PrefixLength == 0) {
ZeroMem (Prefix, sizeof (EFI_IPv6_ADDRESS)); ZeroMem (Prefix, sizeof (EFI_IPv6_ADDRESS));
return ; return ;
} }
if (PrefixLength >= IP6_PREFIX_NUM - 1) { if (PrefixLength >= IP6_PREFIX_MAX) {
return ; return ;
} }

View File

@ -2,7 +2,7 @@
Implementation of EFI_IP6_PROTOCOL protocol interfaces. Implementation of EFI_IP6_PROTOCOL protocol interfaces.
(C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR> (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR> Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
@ -842,7 +842,7 @@ EfiIp6Routes (
EFI_TPL OldTpl; EFI_TPL OldTpl;
IP6_SERVICE *IpSb; IP6_SERVICE *IpSb;
if ((This == NULL) || (PrefixLength >= IP6_PREFIX_NUM)) { if ((This == NULL) || (PrefixLength > IP6_PREFIX_MAX)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }

View File

@ -1,7 +1,7 @@
/** @file /** @file
Implementation of Neighbor Discovery support routines. Implementation of Neighbor Discovery support routines.
Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR> Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
@ -198,7 +198,7 @@ Ip6CreatePrefixListEntry (
LIST_ENTRY *Entry; LIST_ENTRY *Entry;
IP6_PREFIX_LIST_ENTRY *TmpPrefixEntry; IP6_PREFIX_LIST_ENTRY *TmpPrefixEntry;
if (Prefix == NULL || PreferredLifetime > ValidLifetime || PrefixLength >= IP6_PREFIX_NUM) { if (Prefix == NULL || PreferredLifetime > ValidLifetime || PrefixLength > IP6_PREFIX_MAX) {
return NULL; return NULL;
} }

View File

@ -1,7 +1,7 @@
/** @file /** @file
The functions and routines to handle the route caches and route table. The functions and routines to handle the route caches and route table.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR> Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
@ -135,7 +135,7 @@ Ip6FindRouteEntry (
RtEntry = NULL; RtEntry = NULL;
for (Index = IP6_PREFIX_NUM - 1; Index >= 0; Index--) { for (Index = IP6_PREFIX_MAX; Index >= 0; Index--) {
NET_LIST_FOR_EACH (Entry, &RtTable->RouteArea[Index]) { NET_LIST_FOR_EACH (Entry, &RtTable->RouteArea[Index]) {
RtEntry = NET_LIST_USER_STRUCT (Entry, IP6_ROUTE_ENTRY, Link); RtEntry = NET_LIST_USER_STRUCT (Entry, IP6_ROUTE_ENTRY, Link);
@ -300,7 +300,7 @@ Ip6BuildEfiRouteTable (
// //
Count = 0; Count = 0;
for (Index = IP6_PREFIX_NUM - 1; Index >= 0; Index--) { for (Index = IP6_PREFIX_MAX; Index >= 0; Index--) {
NET_LIST_FOR_EACH (Entry, &(RouteTable->RouteArea[Index])) { NET_LIST_FOR_EACH (Entry, &(RouteTable->RouteArea[Index])) {
RtEntry = NET_LIST_USER_STRUCT (Entry, IP6_ROUTE_ENTRY, Link); RtEntry = NET_LIST_USER_STRUCT (Entry, IP6_ROUTE_ENTRY, Link);
@ -346,7 +346,7 @@ Ip6CreateRouteTable (
RtTable->RefCnt = 1; RtTable->RefCnt = 1;
RtTable->TotalNum = 0; RtTable->TotalNum = 0;
for (Index = 0; Index < IP6_PREFIX_NUM; Index++) { for (Index = 0; Index <= IP6_PREFIX_MAX; Index++) {
InitializeListHead (&RtTable->RouteArea[Index]); InitializeListHead (&RtTable->RouteArea[Index]);
} }
@ -385,7 +385,7 @@ Ip6CleanRouteTable (
// //
// Free all the route table entry and its route cache. // Free all the route table entry and its route cache.
// //
for (Index = 0; Index < IP6_PREFIX_NUM; Index++) { for (Index = 0; Index <= IP6_PREFIX_MAX; Index++) {
NET_LIST_FOR_EACH_SAFE (Entry, Next, &RtTable->RouteArea[Index]) { NET_LIST_FOR_EACH_SAFE (Entry, Next, &RtTable->RouteArea[Index]) {
RtEntry = NET_LIST_USER_STRUCT (Entry, IP6_ROUTE_ENTRY, Link); RtEntry = NET_LIST_USER_STRUCT (Entry, IP6_ROUTE_ENTRY, Link);
RemoveEntryList (Entry); RemoveEntryList (Entry);