summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiaxin Wu <jiaxin.wu@intel.com>2017-03-16 09:39:34 +0800
committerFu Siyuan <siyuan.fu@intel.com>2017-05-18 15:53:22 +0800
commit95d0b0a38820fc13d85be4cea2a3588f4f44c3a1 (patch)
tree7dece9dcbe95396070cc99318b89f652b5c05486
parentfed522a15a41abc630aab8cb04a9965dc3a983ce (diff)
downloadedk2-95d0b0a38820fc13d85be4cea2a3588f4f44c3a1.zip
edk2-95d0b0a38820fc13d85be4cea2a3588f4f44c3a1.tar.gz
edk2-95d0b0a38820fc13d85be4cea2a3588f4f44c3a1.tar.bz2
MdeModulePkg/Ip4Dxe: Add Ip/Netmask pair check for Ip4Config2
v2: * Add the check in Ip4Config2SetDefaultIf to avoid the DHCP configuration case. Ip4config2 doesn't check the validity of Ip/Netmask pair, which leads to the invalid combination of Ip and Netmask setting. This patch is to resolve the issue. Cc: Hegde Nagaraj P <nagaraj-p.hegde@hpe.com> Cc: Subramanian Sriram <sriram-s@hpe.com> Cc: Ye Ting <ting.ye@intel.com> Cc: Fu Siyuan <siyuan.fu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com> Reviewed-by: Sriram Subramanian <sriram-s@hpe.com> Reviewed-by: Hegde Nagaraj P <nagaraj-p.hegde@hpe.com> (cherry picked from commit f1222593f2a8944ab8f61f3864b6ae80633faecf) Conflicts: MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
-rw-r--r--MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c62
-rw-r--r--MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h21
-rw-r--r--MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c16
-rw-r--r--MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c6
-rw-r--r--MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c60
5 files changed, 99 insertions, 66 deletions
diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
index 004a8bc..47063b4 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
@@ -1,6 +1,6 @@
/** @file
-Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2005 - 2017, 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
@@ -267,3 +267,63 @@ Ip4NtohHead (
return Head;
}
+
+
+/**
+ Validate that Ip/Netmask pair is OK to be used as station
+ address. Only continuous netmasks are supported. and check
+ that StationAddress is a unicast address on the newtwork.
+
+ @param[in] Ip The IP address to validate.
+ @param[in] Netmask The netmaks of the IP.
+
+ @retval TRUE The Ip/Netmask pair is valid.
+ @retval FALSE The Ip/Netmask pair is invalid.
+
+**/
+BOOLEAN
+Ip4StationAddressValid (
+ IN IP4_ADDR Ip,
+ IN IP4_ADDR Netmask
+ )
+{
+ IP4_ADDR NetBrdcastMask;
+ INTN Len;
+ INTN Type;
+
+ //
+ // Only support the station address with 0.0.0.0/0 to enable DHCP client.
+ //
+ if (Netmask == IP4_ALLZERO_ADDRESS) {
+ return (BOOLEAN) (Ip == IP4_ALLZERO_ADDRESS);
+ }
+
+ //
+ // Only support the continuous net masks
+ //
+ if ((Len = NetGetMaskLength (Netmask)) == (IP4_MASK_NUM)) {
+ return FALSE;
+ }
+
+ //
+ // Station address can't be class D or class E address
+ //
+ if ((Type = NetGetIpClass (Ip)) > IP4_ADDR_CLASSC) {
+ return FALSE;
+ }
+
+ //
+ // Station address can't be subnet broadcast/net broadcast address
+ //
+ if ((Ip == (Ip & Netmask)) || (Ip == (Ip | ~Netmask))) {
+ return FALSE;
+ }
+
+ NetBrdcastMask = gIp4AllMasks[MIN (Len, Type << 3)];
+
+ if (Ip == (Ip | ~NetBrdcastMask)) {
+ return FALSE;
+ }
+
+ return TRUE;
+} \ No newline at end of file
diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h
index d38857c..9689f37 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h
@@ -1,7 +1,7 @@
/** @file
Common definition for IP4.
-Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2005 - 2017, 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
@@ -201,4 +201,23 @@ Ip4NtohHead (
IN IP4_HEAD *Head
);
+
+/**
+ Validate that Ip/Netmask pair is OK to be used as station
+ address. Only continuous netmasks are supported. and check
+ that StationAddress is a unicast address on the newtwork.
+
+ @param[in] Ip The IP address to validate.
+ @param[in] Netmask The netmaks of the IP.
+
+ @retval TRUE The Ip/Netmask pair is valid.
+ @retval FALSE The Ip/Netmask pair is invalid.
+
+**/
+BOOLEAN
+Ip4StationAddressValid (
+ IN IP4_ADDR Ip,
+ IN IP4_ADDR Netmask
+ );
+
#endif
diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c
index 49a98b3..65997aa 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c
@@ -610,6 +610,13 @@ Ip4Config2SetDefaultIf (
IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);
+ //
+ // Check whether the StationAddress/SubnetMask pair is valid.
+ //
+ if (!Ip4StationAddressValid (StationAddress, SubnetMask)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
Status = Ip4Config2SetDefaultAddr (IpSb, StationAddress, SubnetMask);
if (EFI_ERROR (Status)) {
return Status;
@@ -1255,6 +1262,15 @@ Ip4Config2SetMaunualAddress (
NewAddress = *((EFI_IP4_CONFIG2_MANUAL_ADDRESS *) Data);
+ StationAddress = EFI_NTOHL (NewAddress.Address);
+ SubnetMask = EFI_NTOHL (NewAddress.SubnetMask);
+
+ //
+ // Check whether the StationAddress/SubnetMask pair is valid.
+ //
+ if (!Ip4StationAddressValid (StationAddress, SubnetMask)) {
+ return EFI_INVALID_PARAMETER;
+ }
//
// Store the new data, and init the DataItem status to EFI_NOT_READY because
// we may have an asynchronous configuration process.
diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c
index 6c3023d..7512a00 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c
@@ -1,7 +1,7 @@
/** @file
Implement IP4 pesudo interface.
-Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2005 - 2017, 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
@@ -560,7 +560,6 @@ Ip4SetAddress (
{
EFI_ARP_CONFIG_DATA ArpConfig;
EFI_STATUS Status;
- INTN Len;
NET_CHECK_SIGNATURE (Interface, IP4_INTERFACE_SIGNATURE);
@@ -575,9 +574,6 @@ Ip4SetAddress (
Interface->Ip = IpAddr;
Interface->SubnetMask = SubnetMask;
Interface->SubnetBrdcast = (IpAddr | ~SubnetMask);
-
- Len = NetGetMaskLength (SubnetMask);
- ASSERT (Len < IP4_MASK_NUM);
Interface->NetBrdcast = (IpAddr | ~SubnetMask);
//
diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
index 58adba7..b8c185f 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
@@ -1,6 +1,6 @@
/** @file
-Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2005 - 2017, 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
@@ -806,64 +806,6 @@ Ip4CleanProtocol (
}
-/**
- Validate that Ip/Netmask pair is OK to be used as station
- address. Only continuous netmasks are supported. and check
- that StationAddress is a unicast address on the newtwork.
-
- @param[in] Ip The IP address to validate.
- @param[in] Netmask The netmaks of the IP.
-
- @retval TRUE The Ip/Netmask pair is valid.
- @retval FALSE The Ip/Netmask pair is invalid.
-
-**/
-BOOLEAN
-Ip4StationAddressValid (
- IN IP4_ADDR Ip,
- IN IP4_ADDR Netmask
- )
-{
- IP4_ADDR NetBrdcastMask;
- INTN Len;
- INTN Type;
-
- //
- // Only support the station address with 0.0.0.0/0 to enable DHCP client.
- //
- if (Netmask == IP4_ALLZERO_ADDRESS) {
- return (BOOLEAN) (Ip == IP4_ALLZERO_ADDRESS);
- }
-
- //
- // Only support the continuous net masks
- //
- if ((Len = NetGetMaskLength (Netmask)) == IP4_MASK_NUM) {
- return FALSE;
- }
-
- //
- // Station address can't be class D or class E address
- //
- if ((Type = NetGetIpClass (Ip)) > IP4_ADDR_CLASSC) {
- return FALSE;
- }
-
- //
- // Station address can't be subnet broadcast/net broadcast address
- //
- if ((Ip == (Ip & Netmask)) || (Ip == (Ip | ~Netmask))) {
- return FALSE;
- }
-
- NetBrdcastMask = gIp4AllMasks[MIN (Len, Type << 3)];
-
- if (Ip == (Ip | ~NetBrdcastMask)) {
- return FALSE;
- }
-
- return TRUE;
-}
/**