MdeModulePkg: Update IP4 stack drivers for classless address unicast check.
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Fu Siyuan <siyuan.fu@intel.com> Reviewed-by: Ye Ting <ting.ye@intel.com> Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>
This commit is contained in:
@@ -737,8 +737,7 @@ Ip4Config2SetDnsServerWorker (
|
||||
|
||||
for (NewIndex = 0; NewIndex < NewDnsCount; NewIndex++) {
|
||||
CopyMem (&DnsAddress, NewDns + NewIndex, sizeof (IP4_ADDR));
|
||||
|
||||
if (!NetIp4IsUnicast (NTOHL (DnsAddress), 0)) {
|
||||
if (IP4_IS_UNSPECIFIED (NTOHL (DnsAddress)) || IP4_IS_LOCAL_BROADCAST (NTOHL (DnsAddress))) {
|
||||
//
|
||||
// The dns server address must be unicast.
|
||||
//
|
||||
@@ -1347,14 +1346,15 @@ Ip4Config2SetGateway (
|
||||
return EFI_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);
|
||||
|
||||
NewGateway = (EFI_IPv4_ADDRESS *) Data;
|
||||
NewGatewayCount = DataSize / sizeof (EFI_IPv4_ADDRESS);
|
||||
for (Index1 = 0; Index1 < NewGatewayCount; Index1++) {
|
||||
CopyMem (&Gateway, NewGateway + Index1, sizeof (IP4_ADDR));
|
||||
|
||||
if (!NetIp4IsUnicast (NTOHL (Gateway), 0)) {
|
||||
|
||||
if ((IpSb->DefaultInterface->SubnetMask != 0) &&
|
||||
!NetIp4IsUnicast (NTOHL (Gateway), IpSb->DefaultInterface->SubnetMask)) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
@@ -1365,7 +1365,6 @@ Ip4Config2SetGateway (
|
||||
}
|
||||
}
|
||||
|
||||
IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);
|
||||
DataItem = &Instance->DataItem[Ip4Config2DataTypeGateway];
|
||||
OldGateway = DataItem->Data.Gateway;
|
||||
OldGatewayCount = DataItem->DataSize / sizeof (EFI_IPv4_ADDRESS);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
Helper functions for configuring or getting the parameters relating to Ip4.
|
||||
|
||||
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2015 - 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
|
||||
@@ -608,20 +608,20 @@ Ip4Config2ConvertIfrNvDataToConfigNvData (
|
||||
//
|
||||
Ip4NvData->Policy = Ip4Config2PolicyStatic;
|
||||
|
||||
Status = Ip4Config2StrToIp (IfrFormNvData->StationAddress, &StationAddress.v4);
|
||||
if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (StationAddress.Addr[0]), 0)) {
|
||||
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
Status = Ip4Config2StrToIp (IfrFormNvData->SubnetMask, &SubnetMask.v4);
|
||||
if (EFI_ERROR (Status) || ((SubnetMask.Addr[0] != 0) && (GetSubnetMaskPrefixLength (&SubnetMask.v4) == 0))) {
|
||||
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Subnet Mask!", NULL);
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
Status = Ip4Config2StrToIp (IfrFormNvData->StationAddress, &StationAddress.v4);
|
||||
if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (StationAddress.Addr[0]), NTOHL (SubnetMask.Addr[0]))) {
|
||||
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
Status = Ip4Config2StrToIp (IfrFormNvData->GatewayAddress, &Gateway.v4);
|
||||
if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), 0))) {
|
||||
if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), NTOHL (SubnetMask.Addr[0])))) {
|
||||
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL);
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
@@ -630,7 +630,7 @@ Ip4Config2ConvertIfrNvDataToConfigNvData (
|
||||
if (!EFI_ERROR (Status) && DnsCount > 0) {
|
||||
for (Index = 0; Index < DnsCount; Index ++) {
|
||||
CopyMem (&Ip, &DnsAddress[Index], sizeof (IP4_ADDR));
|
||||
if (!NetIp4IsUnicast (NTOHL (Ip), 0)) {
|
||||
if (IP4_IS_UNSPECIFIED (NTOHL (Ip)) || IP4_IS_LOCAL_BROADCAST (NTOHL (Ip))) {
|
||||
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Dns Server!", NULL);
|
||||
FreePool(DnsAddress);
|
||||
return EFI_INVALID_PARAMETER;
|
||||
@@ -1146,7 +1146,7 @@ Ip4FormCallback (
|
||||
switch (QuestionId) {
|
||||
case KEY_LOCAL_IP:
|
||||
Status = Ip4Config2StrToIp (IfrFormNvData->StationAddress, &StationAddress.v4);
|
||||
if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (StationAddress.Addr[0]), 0)) {
|
||||
if (EFI_ERROR (Status) || IP4_IS_UNSPECIFIED (NTOHL (StationAddress.Addr[0])) || IP4_IS_LOCAL_BROADCAST (NTOHL (StationAddress.Addr[0]))) {
|
||||
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
}
|
||||
@@ -1162,7 +1162,7 @@ Ip4FormCallback (
|
||||
|
||||
case KEY_GATE_WAY:
|
||||
Status = Ip4Config2StrToIp (IfrFormNvData->GatewayAddress, &Gateway.v4);
|
||||
if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), 0))) {
|
||||
if (EFI_ERROR (Status) || IP4_IS_LOCAL_BROADCAST(NTOHL(Gateway.Addr[0]))) {
|
||||
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL);
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
}
|
||||
@@ -1173,7 +1173,7 @@ Ip4FormCallback (
|
||||
if (!EFI_ERROR (Status) && DnsCount > 0) {
|
||||
for (Index = 0; Index < DnsCount; Index ++) {
|
||||
CopyMem (&Ip, &DnsAddress[Index], sizeof (IP4_ADDR));
|
||||
if (!NetIp4IsUnicast (NTOHL (Ip), 0)) {
|
||||
if (IP4_IS_UNSPECIFIED (NTOHL (Ip)) || IP4_IS_LOCAL_BROADCAST (NTOHL (Ip))) {
|
||||
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Dns Server!", NULL);
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
break;
|
||||
|
@@ -560,9 +560,7 @@ Ip4SetAddress (
|
||||
{
|
||||
EFI_ARP_CONFIG_DATA ArpConfig;
|
||||
EFI_STATUS Status;
|
||||
INTN Type;
|
||||
INTN Len;
|
||||
IP4_ADDR Netmask;
|
||||
|
||||
NET_CHECK_SIGNATURE (Interface, IP4_INTERFACE_SIGNATURE);
|
||||
|
||||
@@ -578,12 +576,9 @@ Ip4SetAddress (
|
||||
Interface->SubnetMask = SubnetMask;
|
||||
Interface->SubnetBrdcast = (IpAddr | ~SubnetMask);
|
||||
|
||||
Type = NetGetIpClass (IpAddr);
|
||||
ASSERT (Type <= IP4_ADDR_CLASSC);
|
||||
Len = NetGetMaskLength (SubnetMask);
|
||||
ASSERT (Len <= IP4_MASK_MAX);
|
||||
Netmask = gIp4AllMasks[MIN (Len, Type << 3)];
|
||||
Interface->NetBrdcast = (IpAddr | ~Netmask);
|
||||
Interface->NetBrdcast = (IpAddr | ~SubnetMask);
|
||||
|
||||
//
|
||||
// Do clean up for Arp child
|
||||
|
Reference in New Issue
Block a user