mirror of https://github.com/acidanthera/audk.git
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>
This commit is contained in:
parent
d948cf838e
commit
f1222593f2
|
@ -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_MAX + 1)) {
|
||||
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;
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -609,6 +609,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;
|
||||
|
@ -1252,7 +1259,10 @@ Ip4Config2SetMaunualAddress (
|
|||
StationAddress = EFI_NTOHL (NewAddress.Address);
|
||||
SubnetMask = EFI_NTOHL (NewAddress.SubnetMask);
|
||||
|
||||
if (NetGetMaskLength (SubnetMask) == IP4_MASK_NUM) {
|
||||
//
|
||||
// Check whether the StationAddress/SubnetMask pair is valid.
|
||||
//
|
||||
if (!Ip4StationAddressValid (StationAddress, SubnetMask)) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,15 +560,9 @@ Ip4SetAddress (
|
|||
{
|
||||
EFI_ARP_CONFIG_DATA ArpConfig;
|
||||
EFI_STATUS Status;
|
||||
INTN Len;
|
||||
|
||||
NET_CHECK_SIGNATURE (Interface, IP4_INTERFACE_SIGNATURE);
|
||||
|
||||
Len = NetGetMaskLength (SubnetMask);
|
||||
if (Len == IP4_MASK_NUM) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
//
|
||||
// Set the ip/netmask, then compute the subnet broadcast
|
||||
// and network broadcast for easy access. When computing
|
||||
|
|
|
@ -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
|
||||
|
@ -809,66 +809,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_MAX + 1)) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance.
|
||||
|
||||
|
|
Loading…
Reference in New Issue