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:
Fu Siyuan
2016-10-27 09:23:08 +08:00
parent 3289dcba45
commit 01b5ac880f
14 changed files with 83 additions and 77 deletions

View File

@ -2,7 +2,7 @@
This library is only intended to be used by UEFI network stack modules. This library is only intended to be used by UEFI network stack modules.
It provides the combined IpIo layer on the EFI IP4 Protocol and EFI IP6 protocol. It provides the combined IpIo layer on the EFI IP4 Protocol and EFI IP6 protocol.
Copyright (c) 2005 - 2010, 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 This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution. the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at The full text of the license may be found at
@ -261,6 +261,8 @@ typedef struct _IP_IO {
PKT_RCVD_NOTIFY PktRcvdNotify; ///< See IP_IO_OPEN_DATA::PktRcvdNotify. PKT_RCVD_NOTIFY PktRcvdNotify; ///< See IP_IO_OPEN_DATA::PktRcvdNotify.
PKT_SENT_NOTIFY PktSentNotify; ///< See IP_IO_OPEN_DATA::PktSentNotify. PKT_SENT_NOTIFY PktSentNotify; ///< See IP_IO_OPEN_DATA::PktSentNotify.
UINT8 IpVersion; UINT8 IpVersion;
IP4_ADDR StationIp;
IP4_ADDR SubnetMask;
} IP_IO; } IP_IO;
/// ///

View File

@ -1029,7 +1029,9 @@ IpIoListenHandlerDpc (
if (IpIo->IpVersion == IP_VERSION_4) { if (IpIo->IpVersion == IP_VERSION_4) {
if ((EFI_IP4 (RxData->Ip4RxData.Header->SourceAddress) != 0) && if ((EFI_IP4 (RxData->Ip4RxData.Header->SourceAddress) != 0) &&
!NetIp4IsUnicast (EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *) RxData)->Header->SourceAddress), 0)) { (IpIo->SubnetMask != 0) &&
IP4_NET_EQUAL (IpIo->StationIp, EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *) RxData)->Header->SourceAddress), IpIo->SubnetMask) &&
!NetIp4IsUnicast (EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *) RxData)->Header->SourceAddress), IpIo->SubnetMask)) {
// //
// The source address is not zero and it's not a unicast IP address, discard it. // The source address is not zero and it's not a unicast IP address, discard it.
// //
@ -1301,6 +1303,11 @@ IpIoOpen (
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
if (!OpenData->IpConfigData.Ip4CfgData.UseDefaultAddress) {
IpIo->StationIp = EFI_NTOHL (OpenData->IpConfigData.Ip4CfgData.StationAddress);
IpIo->SubnetMask = EFI_NTOHL (OpenData->IpConfigData.Ip4CfgData.SubnetMask);
}
Status = IpIo->Ip.Ip4->Configure ( Status = IpIo->Ip.Ip4->Configure (
IpIo->Ip.Ip4, IpIo->Ip.Ip4,
&OpenData->IpConfigData.Ip4CfgData &OpenData->IpConfigData.Ip4CfgData

View File

@ -943,9 +943,9 @@ ArpConfigureInstance (
if (ConfigData->SwAddressType == IPV4_ETHER_PROTO_TYPE) { if (ConfigData->SwAddressType == IPV4_ETHER_PROTO_TYPE) {
CopyMem (&Ip, ConfigData->StationAddress, sizeof (IP4_ADDR)); CopyMem (&Ip, ConfigData->StationAddress, sizeof (IP4_ADDR));
if (!NetIp4IsUnicast (NTOHL (Ip), 0)) { if (IP4_IS_UNSPECIFIED (Ip) || IP4_IS_LOCAL_BROADCAST (Ip)) {
// //
// The station address is not a valid IPv4 unicast address. // The station address should not be zero or broadcast address.
// //
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }

View File

@ -660,9 +660,7 @@ EfiDhcp4Configure (
} }
CopyMem (&Ip, &Dhcp4CfgData->ClientAddress, sizeof (IP4_ADDR)); CopyMem (&Ip, &Dhcp4CfgData->ClientAddress, sizeof (IP4_ADDR));
if (IP4_IS_LOCAL_BROADCAST(NTOHL (Ip))) {
if ((Ip != 0) && !NetIp4IsUnicast (NTOHL (Ip), 0)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
} }
@ -1212,6 +1210,13 @@ Dhcp4InstanceConfigUdpIo (
CopyMem (&UdpConfigData.StationAddress, &Ip, sizeof (EFI_IPv4_ADDRESS)); CopyMem (&UdpConfigData.StationAddress, &Ip, sizeof (EFI_IPv4_ADDRESS));
if (DhcpSb->Netmask == 0) { if (DhcpSb->Netmask == 0) {
//
// The Dhcp4.TransmitReceive() API should be able to used at any time according to
// UEFI spec, while in classless addressing network, the netmask must be explicitly
// provided together with the station address.
// If the DHCP instance haven't be configured with a valid netmask, we could only
// compute it accroding to the classful addressing rule.
//
Class = NetGetIpClass (ClientAddr); Class = NetGetIpClass (ClientAddr);
ASSERT (Class < IP4_ADDR_CLASSE); ASSERT (Class < IP4_ADDR_CLASSE);
SubnetMask = gIp4AllMasks[Class << 3]; SubnetMask = gIp4AllMasks[Class << 3];
@ -1492,8 +1497,6 @@ EfiDhcp4TransmitReceive (
DHCP_SERVICE *DhcpSb; DHCP_SERVICE *DhcpSb;
EFI_IP_ADDRESS Gateway; EFI_IP_ADDRESS Gateway;
IP4_ADDR ClientAddr; IP4_ADDR ClientAddr;
INTN Class;
IP4_ADDR SubnetMask;
if ((This == NULL) || (Token == NULL) || (Token->Packet == NULL)) { if ((This == NULL) || (Token == NULL) || (Token->Packet == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
@ -1583,19 +1586,11 @@ EfiDhcp4TransmitReceive (
EndPoint.RemotePort = Token->RemotePort; EndPoint.RemotePort = Token->RemotePort;
} }
if (DhcpSb->Netmask == 0) {
Class = NetGetIpClass (ClientAddr);
ASSERT (Class < IP4_ADDR_CLASSE);
SubnetMask = gIp4AllMasks[Class << 3];
} else {
SubnetMask = DhcpSb->Netmask;
}
// //
// Get the gateway. // Get the gateway.
// //
ZeroMem (&Gateway, sizeof (Gateway)); ZeroMem (&Gateway, sizeof (Gateway));
if (!IP4_NET_EQUAL (ClientAddr, EndPoint.RemoteAddr.Addr[0], SubnetMask)) { if (!IP4_NET_EQUAL (ClientAddr, EndPoint.RemoteAddr.Addr[0], DhcpSb->Netmask)) {
CopyMem (&Gateway.v4, &Token->GatewayAddress, sizeof (EFI_IPv4_ADDRESS)); CopyMem (&Gateway.v4, &Token->GatewayAddress, sizeof (EFI_IPv4_ADDRESS));
Gateway.Addr[0] = NTOHL (Gateway.Addr[0]); Gateway.Addr[0] = NTOHL (Gateway.Addr[0]);
} }

View File

@ -393,8 +393,6 @@ DhcpLeaseAcquired (
IN OUT DHCP_SERVICE *DhcpSb IN OUT DHCP_SERVICE *DhcpSb
) )
{ {
INTN Class;
DhcpSb->ClientAddr = EFI_NTOHL (DhcpSb->Selected->Dhcp4.Header.YourAddr); DhcpSb->ClientAddr = EFI_NTOHL (DhcpSb->Selected->Dhcp4.Header.YourAddr);
if (DhcpSb->Para != NULL) { if (DhcpSb->Para != NULL) {
@ -403,9 +401,7 @@ DhcpLeaseAcquired (
} }
if (DhcpSb->Netmask == 0) { if (DhcpSb->Netmask == 0) {
Class = NetGetIpClass (DhcpSb->ClientAddr); return EFI_ABORTED;
ASSERT (Class < IP4_ADDR_CLASSE);
DhcpSb->Netmask = gIp4AllMasks[Class << 3];
} }
if (DhcpSb->LeaseIoPort != NULL) { if (DhcpSb->LeaseIoPort != NULL) {

View File

@ -1,7 +1,7 @@
/** @file /** @file
Helper functions for configuring or getting the parameters relating to iSCSI. Helper functions for configuring or getting the parameters relating to iSCSI.
Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2004 - 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
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
@ -727,7 +727,9 @@ IScsiFormCallback (
case KEY_LOCAL_IP: case KEY_LOCAL_IP:
IScsiUnicodeStrToAsciiStr (IfrNvData->LocalIp, Ip4String); IScsiUnicodeStrToAsciiStr (IfrNvData->LocalIp, Ip4String);
Status = IScsiAsciiStrToIp (Ip4String, &HostIp.v4); Status = IScsiAsciiStrToIp (Ip4String, &HostIp.v4);
if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) { if (EFI_ERROR (Status) ||
((Private->Current->SessionConfigData.SubnetMask.Addr[0] != 0) &&
!NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), NTOHL(*(UINT32*)Private->Current->SessionConfigData.SubnetMask.Addr)))) {
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL); CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
} else { } else {
@ -751,7 +753,10 @@ IScsiFormCallback (
case KEY_GATE_WAY: case KEY_GATE_WAY:
IScsiUnicodeStrToAsciiStr (IfrNvData->Gateway, Ip4String); IScsiUnicodeStrToAsciiStr (IfrNvData->Gateway, Ip4String);
Status = IScsiAsciiStrToIp (Ip4String, &Gateway.v4); Status = IScsiAsciiStrToIp (Ip4String, &Gateway.v4);
if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), 0))) { if (EFI_ERROR (Status) ||
((Gateway.Addr[0] != 0) &&
(Private->Current->SessionConfigData.SubnetMask.Addr[0] != 0) &&
!NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), NTOHL(*(UINT32*)Private->Current->SessionConfigData.SubnetMask.Addr)))) {
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL); CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL);
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
} else { } else {
@ -763,7 +768,7 @@ IScsiFormCallback (
case KEY_TARGET_IP: case KEY_TARGET_IP:
IScsiUnicodeStrToAsciiStr (IfrNvData->TargetIp, Ip4String); IScsiUnicodeStrToAsciiStr (IfrNvData->TargetIp, Ip4String);
Status = IScsiAsciiStrToIp (Ip4String, &HostIp.v4); Status = IScsiAsciiStrToIp (Ip4String, &HostIp.v4);
if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) { if (EFI_ERROR (Status) || IP4_IS_LOCAL_BROADCAST (EFI_NTOHL(HostIp.v4)) || IP4_IS_UNSPECIFIED (EFI_NTOHL(HostIp.v4))) {
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL); CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
} else { } else {
@ -867,7 +872,7 @@ IScsiFormCallback (
// //
if (!Private->Current->SessionConfigData.TargetInfoFromDhcp) { if (!Private->Current->SessionConfigData.TargetInfoFromDhcp) {
CopyMem (&HostIp.v4, &Private->Current->SessionConfigData.TargetIp, sizeof (HostIp.v4)); CopyMem (&HostIp.v4, &Private->Current->SessionConfigData.TargetIp, sizeof (HostIp.v4));
if (!NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) { if (IP4_IS_UNSPECIFIED (NTOHL (HostIp.Addr[0])) || IP4_IS_LOCAL_BROADCAST (NTOHL (HostIp.Addr[0]))) {
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Target IP is invalid!", NULL); CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Target IP is invalid!", NULL);
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
break; break;

View File

@ -737,8 +737,7 @@ Ip4Config2SetDnsServerWorker (
for (NewIndex = 0; NewIndex < NewDnsCount; NewIndex++) { for (NewIndex = 0; NewIndex < NewDnsCount; NewIndex++) {
CopyMem (&DnsAddress, NewDns + NewIndex, sizeof (IP4_ADDR)); CopyMem (&DnsAddress, NewDns + NewIndex, sizeof (IP4_ADDR));
if (IP4_IS_UNSPECIFIED (NTOHL (DnsAddress)) || IP4_IS_LOCAL_BROADCAST (NTOHL (DnsAddress))) {
if (!NetIp4IsUnicast (NTOHL (DnsAddress), 0)) {
// //
// The dns server address must be unicast. // The dns server address must be unicast.
// //
@ -1347,14 +1346,15 @@ Ip4Config2SetGateway (
return EFI_WRITE_PROTECTED; return EFI_WRITE_PROTECTED;
} }
IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);
NewGateway = (EFI_IPv4_ADDRESS *) Data; NewGateway = (EFI_IPv4_ADDRESS *) Data;
NewGatewayCount = DataSize / sizeof (EFI_IPv4_ADDRESS); NewGatewayCount = DataSize / sizeof (EFI_IPv4_ADDRESS);
for (Index1 = 0; Index1 < NewGatewayCount; Index1++) { for (Index1 = 0; Index1 < NewGatewayCount; Index1++) {
CopyMem (&Gateway, NewGateway + Index1, sizeof (IP4_ADDR)); 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; return EFI_INVALID_PARAMETER;
} }
@ -1365,7 +1365,6 @@ Ip4Config2SetGateway (
} }
} }
IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);
DataItem = &Instance->DataItem[Ip4Config2DataTypeGateway]; DataItem = &Instance->DataItem[Ip4Config2DataTypeGateway];
OldGateway = DataItem->Data.Gateway; OldGateway = DataItem->Data.Gateway;
OldGatewayCount = DataItem->DataSize / sizeof (EFI_IPv4_ADDRESS); OldGatewayCount = DataItem->DataSize / sizeof (EFI_IPv4_ADDRESS);

View File

@ -1,7 +1,7 @@
/** @file /** @file
Helper functions for configuring or getting the parameters relating to Ip4. 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 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
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
@ -608,20 +608,20 @@ Ip4Config2ConvertIfrNvDataToConfigNvData (
// //
Ip4NvData->Policy = Ip4Config2PolicyStatic; 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); Status = Ip4Config2StrToIp (IfrFormNvData->SubnetMask, &SubnetMask.v4);
if (EFI_ERROR (Status) || ((SubnetMask.Addr[0] != 0) && (GetSubnetMaskPrefixLength (&SubnetMask.v4) == 0))) { if (EFI_ERROR (Status) || ((SubnetMask.Addr[0] != 0) && (GetSubnetMaskPrefixLength (&SubnetMask.v4) == 0))) {
CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Subnet Mask!", NULL); CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Subnet Mask!", NULL);
return EFI_INVALID_PARAMETER; 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); 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); CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL);
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -630,7 +630,7 @@ Ip4Config2ConvertIfrNvDataToConfigNvData (
if (!EFI_ERROR (Status) && DnsCount > 0) { if (!EFI_ERROR (Status) && DnsCount > 0) {
for (Index = 0; Index < DnsCount; Index ++) { for (Index = 0; Index < DnsCount; Index ++) {
CopyMem (&Ip, &DnsAddress[Index], sizeof (IP4_ADDR)); 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); CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Dns Server!", NULL);
FreePool(DnsAddress); FreePool(DnsAddress);
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
@ -1146,7 +1146,7 @@ Ip4FormCallback (
switch (QuestionId) { switch (QuestionId) {
case KEY_LOCAL_IP: case KEY_LOCAL_IP:
Status = Ip4Config2StrToIp (IfrFormNvData->StationAddress, &StationAddress.v4); 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); CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
} }
@ -1162,7 +1162,7 @@ Ip4FormCallback (
case KEY_GATE_WAY: case KEY_GATE_WAY:
Status = Ip4Config2StrToIp (IfrFormNvData->GatewayAddress, &Gateway.v4); 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); CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL);
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
} }
@ -1173,7 +1173,7 @@ Ip4FormCallback (
if (!EFI_ERROR (Status) && DnsCount > 0) { if (!EFI_ERROR (Status) && DnsCount > 0) {
for (Index = 0; Index < DnsCount; Index ++) { for (Index = 0; Index < DnsCount; Index ++) {
CopyMem (&Ip, &DnsAddress[Index], sizeof (IP4_ADDR)); 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); CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Dns Server!", NULL);
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
break; break;

View File

@ -560,9 +560,7 @@ Ip4SetAddress (
{ {
EFI_ARP_CONFIG_DATA ArpConfig; EFI_ARP_CONFIG_DATA ArpConfig;
EFI_STATUS Status; EFI_STATUS Status;
INTN Type;
INTN Len; INTN Len;
IP4_ADDR Netmask;
NET_CHECK_SIGNATURE (Interface, IP4_INTERFACE_SIGNATURE); NET_CHECK_SIGNATURE (Interface, IP4_INTERFACE_SIGNATURE);
@ -578,12 +576,9 @@ Ip4SetAddress (
Interface->SubnetMask = SubnetMask; Interface->SubnetMask = SubnetMask;
Interface->SubnetBrdcast = (IpAddr | ~SubnetMask); Interface->SubnetBrdcast = (IpAddr | ~SubnetMask);
Type = NetGetIpClass (IpAddr);
ASSERT (Type <= IP4_ADDR_CLASSC);
Len = NetGetMaskLength (SubnetMask); Len = NetGetMaskLength (SubnetMask);
ASSERT (Len <= IP4_MASK_MAX); ASSERT (Len <= IP4_MASK_MAX);
Netmask = gIp4AllMasks[MIN (Len, Type << 3)]; Interface->NetBrdcast = (IpAddr | ~SubnetMask);
Interface->NetBrdcast = (IpAddr | ~Netmask);
// //
// Do clean up for Arp child // Do clean up for Arp child

View File

@ -2,7 +2,7 @@
Interface routine for Mtftp4. Interface routine for Mtftp4.
(C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR> (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR> Copyright (c) 2006 - 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
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
@ -192,7 +192,7 @@ Mtftp4OverrideValid (
IP4_ADDR Gateway; IP4_ADDR Gateway;
CopyMem (&Ip, &Override->ServerIp, sizeof (IP4_ADDR)); CopyMem (&Ip, &Override->ServerIp, sizeof (IP4_ADDR));
if (!NetIp4IsUnicast (NTOHL (Ip), 0)) { if (IP4_IS_UNSPECIFIED (NTOHL (Ip)) || IP4_IS_LOCAL_BROADCAST (NTOHL (Ip))) {
return FALSE; return FALSE;
} }
@ -667,10 +667,6 @@ EfiMtftp4Configure (
Gateway = NTOHL (Gateway); Gateway = NTOHL (Gateway);
ServerIp = NTOHL (ServerIp); ServerIp = NTOHL (ServerIp);
if (!NetIp4IsUnicast (ServerIp, 0)) {
return EFI_INVALID_PARAMETER;
}
if (!ConfigData->UseDefaultSetting && if (!ConfigData->UseDefaultSetting &&
((!IP4_IS_VALID_NETMASK (Netmask) || !NetIp4IsUnicast (Ip, Netmask)))) { ((!IP4_IS_VALID_NETMASK (Netmask) || !NetIp4IsUnicast (Ip, Netmask)))) {

View File

@ -1,7 +1,7 @@
/** @file /** @file
Implementation of TCP4 protocol services. Implementation of TCP4 protocol services.
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.<BR> Copyright (c) 2005 - 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
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
@ -170,7 +170,7 @@ Tcp4Configure (
if (NULL != TcpConfigData) { if (NULL != TcpConfigData) {
CopyMem (&Ip, &TcpConfigData->AccessPoint.RemoteAddress, sizeof (IP4_ADDR)); CopyMem (&Ip, &TcpConfigData->AccessPoint.RemoteAddress, sizeof (IP4_ADDR));
if ((Ip != 0) && !NetIp4IsUnicast (NTOHL (Ip), 0)) { if (IP4_IS_LOCAL_BROADCAST (NTOHL (Ip))) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -183,7 +183,7 @@ Tcp4Configure (
CopyMem (&Ip, &TcpConfigData->AccessPoint.StationAddress, sizeof (IP4_ADDR)); CopyMem (&Ip, &TcpConfigData->AccessPoint.StationAddress, sizeof (IP4_ADDR));
CopyMem (&SubnetMask, &TcpConfigData->AccessPoint.SubnetMask, sizeof (IP4_ADDR)); CopyMem (&SubnetMask, &TcpConfigData->AccessPoint.SubnetMask, sizeof (IP4_ADDR));
if (!NetIp4IsUnicast (NTOHL (Ip), 0) || !IP4_IS_VALID_NETMASK (NTOHL (SubnetMask))) { if (!IP4_IS_VALID_NETMASK (NTOHL (SubnetMask)) || !NetIp4IsUnicast (NTOHL (Ip), NTOHL (SubnetMask))) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
} }

View File

@ -827,7 +827,9 @@ Udp4ValidateTxToken (
if (TxData->GatewayAddress != NULL) { if (TxData->GatewayAddress != NULL) {
CopyMem (&GatewayAddress, TxData->GatewayAddress, sizeof (IP4_ADDR)); CopyMem (&GatewayAddress, TxData->GatewayAddress, sizeof (IP4_ADDR));
if (!NetIp4IsUnicast (NTOHL (GatewayAddress), 0)) { if (!Instance->ConfigData.UseDefaultAddress &&
(EFI_NTOHL(Instance->ConfigData.SubnetMask) != 0) &&
!NetIp4IsUnicast (NTOHL (GatewayAddress), EFI_NTOHL(Instance->ConfigData.SubnetMask))) {
// //
// The specified GatewayAddress is not a unicast IPv4 address while it's not 0. // The specified GatewayAddress is not a unicast IPv4 address while it's not 0.
// //
@ -842,7 +844,10 @@ Udp4ValidateTxToken (
CopyMem (&SourceAddress, &UdpSessionData->SourceAddress, sizeof (IP4_ADDR)); CopyMem (&SourceAddress, &UdpSessionData->SourceAddress, sizeof (IP4_ADDR));
if ((SourceAddress != 0) && !NetIp4IsUnicast (HTONL (SourceAddress), 0)) { if ((SourceAddress != 0) &&
!Instance->ConfigData.UseDefaultAddress &&
(EFI_NTOHL(Instance->ConfigData.SubnetMask) != 0) &&
!NetIp4IsUnicast (HTONL (SourceAddress), EFI_NTOHL(Instance->ConfigData.SubnetMask))) {
// //
// Check whether SourceAddress is a valid IPv4 address in case it's not zero. // Check whether SourceAddress is a valid IPv4 address in case it's not zero.
// The configured station address is used if SourceAddress is zero. // The configured station address is used if SourceAddress is zero.

View File

@ -1,7 +1,7 @@
/** @file /** @file
(C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR> (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR> Copyright (c) 2006 - 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
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
@ -173,7 +173,7 @@ Udp4Configure (
if (!UdpConfigData->UseDefaultAddress && if (!UdpConfigData->UseDefaultAddress &&
(!IP4_IS_VALID_NETMASK (SubnetMask) || (!IP4_IS_VALID_NETMASK (SubnetMask) ||
!((StationAddress == 0) || NetIp4IsUnicast (StationAddress, SubnetMask)) || !((StationAddress == 0) || NetIp4IsUnicast (StationAddress, SubnetMask)) ||
!((RemoteAddress == 0) || NetIp4IsUnicast (RemoteAddress, 0)))) { IP4_IS_LOCAL_BROADCAST (RemoteAddress))) {
// //
// Don't use default address, and subnet mask is invalid or StationAddress is not // Don't use default address, and subnet mask is invalid or StationAddress is not
// a valid unicast IPv4 address or RemoteAddress is not a valid unicast IPv4 address // a valid unicast IPv4 address or RemoteAddress is not a valid unicast IPv4 address

View File

@ -176,7 +176,9 @@ IcmpErrorListenHandlerDpc (
} }
if (EFI_IP4 (RxData->Header->SourceAddress) != 0 && if (EFI_IP4 (RxData->Header->SourceAddress) != 0 &&
!NetIp4IsUnicast (EFI_NTOHL (RxData->Header->SourceAddress), 0)) { (NTOHL (Mode->SubnetMask.Addr[0]) != 0) &&
IP4_NET_EQUAL (NTOHL(Mode->StationIp.Addr[0]), EFI_NTOHL (RxData->Header->SourceAddress), NTOHL (Mode->SubnetMask.Addr[0])) &&
!NetIp4IsUnicast (EFI_NTOHL (RxData->Header->SourceAddress), NTOHL (Mode->SubnetMask.Addr[0]))) {
// //
// The source address is not zero and it's not a unicast IP address, discard it. // The source address is not zero and it's not a unicast IP address, discard it.
// //
@ -1163,7 +1165,9 @@ EfiPxeBcMtftp (
if ((This == NULL) || if ((This == NULL) ||
(Filename == NULL) || (Filename == NULL) ||
(BufferSize == NULL) || (BufferSize == NULL) ||
((ServerIp == NULL) || !NetIp4IsUnicast (NTOHL (ServerIp->Addr[0]), 0)) || ((ServerIp == NULL) ||
(IP4_IS_UNSPECIFIED (NTOHL (ServerIp->Addr[0])) ||
IP4_IS_LOCAL_BROADCAST (NTOHL (ServerIp->Addr[0])))) ||
((BufferPtr == NULL) && DontUseBuffer) || ((BufferPtr == NULL) && DontUseBuffer) ||
((BlockSize != NULL) && (*BlockSize < 512))) { ((BlockSize != NULL) && (*BlockSize < 512))) {
@ -1378,7 +1382,7 @@ EfiPxeBcUdpWrite (
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if ((GatewayIp != NULL) && !NetIp4IsUnicast (NTOHL (GatewayIp->Addr[0]), 0)) { if ((GatewayIp != NULL) && (IP4_IS_UNSPECIFIED (NTOHL (GatewayIp->Addr[0])) || IP4_IS_LOCAL_BROADCAST (NTOHL (GatewayIp->Addr[0])))) {
// //
// Gateway is provided but it's not a unicast IP address. // Gateway is provided but it's not a unicast IP address.
// //
@ -1964,9 +1968,11 @@ EfiPxeBcSetIpFilter (
DEBUG ((EFI_D_ERROR, "There is broadcast address in NewFilter.\n")); DEBUG ((EFI_D_ERROR, "There is broadcast address in NewFilter.\n"));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (NetIp4IsUnicast (EFI_IP4 (NewFilter->IpList[Index].v4), 0) && if ((EFI_NTOHL(Mode->StationIp) != 0) &&
((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != 0) (EFI_NTOHL(Mode->SubnetMask) != 0) &&
) { IP4_NET_EQUAL(EFI_NTOHL(Mode->StationIp), EFI_NTOHL(NewFilter->IpList[Index].v4), EFI_NTOHL(Mode->SubnetMask)) &&
NetIp4IsUnicast (EFI_IP4 (NewFilter->IpList[Index].v4), EFI_NTOHL(Mode->SubnetMask)) &&
((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != 0)) {
// //
// If EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP is set and IP4 address is in IpList, // If EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP is set and IP4 address is in IpList,
// promiscuous mode is needed. // promiscuous mode is needed.
@ -2308,11 +2314,11 @@ EfiPxeBcSetStationIP (
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (NewStationIp != NULL && !NetIp4IsUnicast (NTOHL (NewStationIp->Addr[0]), 0)) { if (NewSubnetMask != NULL && !IP4_IS_VALID_NETMASK (NTOHL (NewSubnetMask->Addr[0]))) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (NewSubnetMask != NULL && !IP4_IS_VALID_NETMASK (NTOHL (NewSubnetMask->Addr[0]))) { if (NewStationIp != NULL && !NetIp4IsUnicast (NTOHL (NewStationIp->Addr[0]), NTOHL (NewSubnetMask->Addr[0]))) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }