From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2CC311A1E57 for ; Thu, 27 Oct 2016 00:17:48 -0700 (PDT) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP; 27 Oct 2016 00:17:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,404,1473145200"; d="scan'208";a="24252831" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga005.fm.intel.com with ESMTP; 27 Oct 2016 00:17:47 -0700 Received: from fmsmsx113.amr.corp.intel.com (10.18.116.7) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.248.2; Thu, 27 Oct 2016 00:17:47 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by FMSMSX113.amr.corp.intel.com (10.18.116.7) with Microsoft SMTP Server (TLS) id 14.3.248.2; Thu, 27 Oct 2016 00:17:46 -0700 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.139]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.2]) with mapi id 14.03.0248.002; Thu, 27 Oct 2016 15:17:44 +0800 From: "Ye, Ting" To: "Fu, Siyuan" , "edk2-devel@lists.01.org" CC: "Zhang, Lubo" , "Wu, Jiaxin" Thread-Topic: [edk2] [Patch 2/3] MdeModulePkg: Update IP4 stack drivers for classless address unicast check. Thread-Index: AQHSL/GFQIylmGi56EesIYRVJOcN16C74zGw Date: Thu, 27 Oct 2016 07:17:44 +0000 Message-ID: References: <1477531734-14944-1-git-send-email-siyuan.fu@intel.com> <1477531734-14944-3-git-send-email-siyuan.fu@intel.com> In-Reply-To: <1477531734-14944-3-git-send-email-siyuan.fu@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [Patch 2/3] MdeModulePkg: Update IP4 stack drivers for classless address unicast check. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Oct 2016 07:17:48 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Siyuan, When checking IPv4 address without subnet mask, do you think we need keep A= LL-ZERO address check? I see the patch removes all checking, for example, w= hen user input local IP/Gateway from UI in Ip4Config2Nv.c. Best Regards, Ye Ting -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Fu S= iyuan Sent: Thursday, October 27, 2016 9:29 AM To: edk2-devel@lists.01.org Cc: Ye, Ting ; Zhang, Lubo ; Wu, J= iaxin Subject: [edk2] [Patch 2/3] MdeModulePkg: Update IP4 stack drivers for clas= sless address unicast check. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Fu Siyuan Cc: Ye Ting Cc: Zhang Lubo Cc: Wu Jiaxin --- MdeModulePkg/Include/Library/IpIoLib.h | 4 ++- MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c | 9 ++++++- MdeModulePkg/Universal/Network/ArpDxe/ArpImpl.c | 7 ----- .../Universal/Network/Dhcp4Dxe/Dhcp4Impl.c | 29 ++----------------= --- MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c | 6 +---- .../Universal/Network/IScsiDxe/IScsiConfig.c | 18 ++++++------- .../Universal/Network/Ip4Dxe/Ip4Config2Impl.c | 15 +++-------- .../Universal/Network/Ip4Dxe/Ip4Config2Nv.c | 30 ++++++++----------= ---- MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c | 7 +---- .../Universal/Network/Mtftp4Dxe/Mtftp4Impl.c | 9 +------ MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Main.c | 7 ++--- MdeModulePk= g/Universal/Network/Udp4Dxe/Udp4Impl.c | 9 +++++-- MdeModulePkg/Universa= l/Network/Udp4Dxe/Udp4Main.c | 5 ++-- .../Universal/Network/UefiPxeBcDxe/PxeBcImpl.c | 27 +++++++++---------= - 14 files changed, 61 insertions(+), 121 deletions(-) diff --git a/MdeModulePkg/Include/Library/IpIoLib.h b/MdeModulePkg/Include/= Library/IpIoLib.h index 37cba07..aab0c68 100644 --- a/MdeModulePkg/Include/Library/IpIoLib.h +++ b/MdeModulePkg/Include/Library/IpIoLib.h @@ -2,7 +2,7 @@ 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. =20 -Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made availabl= e under the terms and conditions of the BSD License that accompanies this = distribution. =20 The full text of the license may be found at @@ -261,6 +261,8 @@ typedef s= truct _IP_IO { PKT_RCVD_NOTIFY PktRcvdNotify; ///< See IP_IO_OPEN_DATA:= :PktRcvdNotify. PKT_SENT_NOTIFY PktSentNotify; ///< See IP_IO_OPEN_DATA:= :PktSentNotify. UINT8 IpVersion; + IP4_ADDR StationIp; + IP4_ADDR SubnetMask; } IP_IO; =20 /// diff --git a/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c b/MdeModulePkg/Li= brary/DxeIpIoLib/DxeIpIoLib.c index ab4df80..d4e9dc1 100644 --- a/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c +++ b/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c @@ -1029,7 +1029,9 @@ IpIoListenHandlerDpc ( =20 if (IpIo->IpVersion =3D=3D IP_VERSION_4) { if ((EFI_IP4 (RxData->Ip4RxData.Header->SourceAddress) !=3D 0) && - !NetIp4IsUnicast (EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *) RxData)->He= ader->SourceAddress), 0)) { + (IpIo->SubnetMask !=3D 0) && + IP4_NET_EQUAL (IpIo->StationIp, EFI_NTOHL (((EFI_IP4_RECEIVE_DATA = *) RxData)->Header->SourceAddress), IpIo->SubnetMask) && + !NetIp4IsUnicast (EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *)=20 + RxData)->Header->SourceAddress), IpIo->SubnetMask)) { // // The source address is not zero and it's not a unicast IP address,= discard it. // @@ -1300,6 +1302,11 @@ IpIoOpen ( if (OpenData->IpConfigData.Ip4CfgData.RawData) { return EFI_UNSUPPORTED; } + + if (!OpenData->IpConfigData.Ip4CfgData.UseDefaultAddress) { + IpIo->StationIp =3D EFI_NTOHL (OpenData->IpConfigData.Ip4CfgData.Sta= tionAddress); + IpIo->SubnetMask =3D EFI_NTOHL (OpenData->IpConfigData.Ip4CfgData.Su= bnetMask); + } =20 Status =3D IpIo->Ip.Ip4->Configure ( IpIo->Ip.Ip4, diff --git a/MdeModulePkg/Unive= rsal/Network/ArpDxe/ArpImpl.c b/MdeModulePkg/Universal/Network/ArpDxe/ArpIm= pl.c index afe4929..d1cebbb 100644 --- a/MdeModulePkg/Universal/Network/ArpDxe/ArpImpl.c +++ b/MdeModulePkg/Universal/Network/ArpDxe/ArpImpl.c @@ -942,13 +942,6 @@ ArpConfigureInstance ( =20 if (ConfigData->SwAddressType =3D=3D IPV4_ETHER_PROTO_TYPE) { CopyMem (&Ip, ConfigData->StationAddress, sizeof (IP4_ADDR)); - - if (!NetIp4IsUnicast (NTOHL (Ip), 0)) { - // - // The station address is not a valid IPv4 unicast address. - // - return EFI_INVALID_PARAMETER; - } } =20 // diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c b/MdeModul= ePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c index 79f7cde..51cb4fd 100644 --- a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c +++ b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c @@ -660,11 +660,6 @@ EfiDhcp4Configure ( } =20 CopyMem (&Ip, &Dhcp4CfgData->ClientAddress, sizeof (IP4_ADDR)); - - if ((Ip !=3D 0) && !NetIp4IsUnicast (NTOHL (Ip), 0)) { - - return EFI_INVALID_PARAMETER; - } } =20 Instance =3D DHCP_INSTANCE_FROM_THIS (This); @@ -1193,8 +1188,6 @@ Dhcp4= InstanceConfigUdpIo ( EFI_UDP4_CONFIG_DATA UdpConfigData; IP4_ADDR ClientAddr; IP4_ADDR Ip; =20 - INTN Class;=20 - IP4_ADDR SubnetMask; =20 Instance =3D (DHCP_PROTOCOL *) Context; DhcpSb =3D Instance->Service; @@ -1211,15 +1204,7 @@ Dhcp4InstanceConfigUdpIo ( Ip =3D HTONL (ClientAddr); CopyMem (&UdpConfigData.StationAddress, &Ip, sizeof (EFI_IPv4_ADDRESS)); =20 - if (DhcpSb->Netmask =3D=3D 0) { - Class =3D NetGetIpClass (ClientAddr); - ASSERT (Class < IP4_ADDR_CLASSE); - SubnetMask =3D gIp4AllMasks[Class << 3]; - } else { - SubnetMask =3D DhcpSb->Netmask; - } - - Ip =3D HTONL (SubnetMask); + Ip =3D HTONL (DhcpSb->Netmask); CopyMem (&UdpConfigData.SubnetMask, &Ip, sizeof (EFI_IPv4_ADDRESS)); =20 if ((Token->ListenPointCount =3D=3D 0) || (Token->ListenPoints[0].Listen= Port =3D=3D 0)) { @@ -1492,8 +1477,6 @@ EfiDhcp4TransmitReceive ( DHCP_SERVICE *DhcpSb; EFI_IP_ADDRESS Gateway; IP4_ADDR ClientAddr; - INTN Class; - IP4_ADDR SubnetMask; =20 if ((This =3D=3D NULL) || (Token =3D=3D NULL) || (Token->Packet =3D=3D N= ULL)) { return EFI_INVALID_PARAMETER; @@ -1583,19 +1566,11 @@ EfiDhcp4TransmitReceive ( EndPoint.RemotePort =3D Token->RemotePort; } =20 - if (DhcpSb->Netmask =3D=3D 0) { - Class =3D NetGetIpClass (ClientAddr); - ASSERT (Class < IP4_ADDR_CLASSE); - SubnetMask =3D gIp4AllMasks[Class << 3]; - } else { - SubnetMask =3D DhcpSb->Netmask; - } - =20 // // Get the gateway. // ZeroMem (&Gateway, sizeof (Gateway)); - if (!IP4_NET_EQUAL (ClientAddr, EndPoint.RemoteAddr.Addr[0], SubnetMask)= ) { + if (!IP4_NET_EQUAL (ClientAddr, EndPoint.RemoteAddr.Addr[0],=20 + DhcpSb->Netmask)) { CopyMem (&Gateway.v4, &Token->GatewayAddress, sizeof (EFI_IPv4_ADDRESS= )); Gateway.Addr[0] =3D NTOHL (Gateway.Addr[0]); } diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c b/MdeModuleP= kg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c index 037d1cc..3898223 100644 --- a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c +++ b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c @@ -393,8 +393,6 @@ DhcpLeaseAcquired ( IN OUT DHCP_SERVICE *DhcpSb ) { - INTN Class; - DhcpSb->ClientAddr =3D EFI_NTOHL (DhcpSb->Selected->Dhcp4.Header.YourAdd= r); =20 if (DhcpSb->Para !=3D NULL) { @@ -403,9 +401,7 @@ DhcpLeaseAcquired ( } =20 if (DhcpSb->Netmask =3D=3D 0) { - Class =3D NetGetIpClass (DhcpSb->ClientAddr); - ASSERT (Class < IP4_ADDR_CLASSE); - DhcpSb->Netmask =3D gIp4AllMasks[Class << 3]; + return EFI_ABORTED; } =20 if (DhcpSb->LeaseIoPort !=3D NULL) { diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c b/MdeMod= ulePkg/Universal/Network/IScsiDxe/IScsiConfig.c index 7b77fd3..be41f25 100644 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c +++ b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c @@ -1,7 +1,7 @@ /** @file Helper functions for configuring or getting the parameters relating to i= SCSI. =20 -Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made availab= le under the terms and conditions of the BSD License which accompanies thi= s distribution. The full text of the license may be found at @@ -727,7 +72= 7,9 @@ IScsiFormCallback ( case KEY_LOCAL_IP: IScsiUnicodeStrToAsciiStr (IfrNvData->LocalIp, Ip4String); Status =3D IScsiAsciiStrToIp (Ip4String, &HostIp.v4); - if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), = 0)) { + if (EFI_ERROR (Status) ||=20 + ((Private->Current->SessionConfigData.SubnetMask.Addr[0] !=3D 0)= &&=20 + !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]),=20 + NTOHL(*(UINT32*)Private->Current->SessionConfigData.SubnetMask.Addr))) + ) { CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid = IP address!", NULL); Status =3D EFI_INVALID_PARAMETER; } else { @@ -751,7 +753,10 @@ IScsiFormCallback ( case KEY_GATE_WAY: IScsiUnicodeStrToAsciiStr (IfrNvData->Gateway, Ip4String); Status =3D IScsiAsciiStrToIp (Ip4String, &Gateway.v4); - if (EFI_ERROR (Status) || ((Gateway.Addr[0] !=3D 0) && !NetIp4IsUnic= ast (NTOHL (Gateway.Addr[0]), 0))) { + if (EFI_ERROR (Status) ||=20 + ((Gateway.Addr[0] !=3D 0) &&=20 + (Private->Current->SessionConfigData.SubnetMask.Addr[0] !=3D 0)= &&=20 + !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]),=20 + NTOHL(*(UINT32*)Private->Current->SessionConfigData.SubnetMask.Addr))) + ) { CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid = Gateway!", NULL); Status =3D EFI_INVALID_PARAMETER; } else { @@ -763,7 +768,7 @@ IScsiFormCallback ( case KEY_TARGET_IP: IScsiUnicodeStrToAsciiStr (IfrNvData->TargetIp, Ip4String); Status =3D IScsiAsciiStrToIp (Ip4String, &HostIp.v4); - if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), = 0)) { + if (EFI_ERROR (Status)) { CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid = IP address!", NULL); Status =3D EFI_INVALID_PARAMETER; } else { @@ -867,11 +872,6 @@ IScsiFormCallback ( // if (!Private->Current->SessionConfigData.TargetInfoFromDhcp) { CopyMem (&HostIp.v4, &Private->Current->SessionConfigData.Target= Ip, sizeof (HostIp.v4)); - if (!NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) { - CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Targ= et IP is invalid!", NULL); - Status =3D EFI_INVALID_PARAMETER; - break; - } =20 // // Validate iSCSI target name configuration again: diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c b/MdeMo= dulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c index 97b555b..51f7a67 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c @@ -737,15 +737,6 @@ Ip4Config2SetDnsServerWorker ( =20 for (NewIndex =3D 0; NewIndex < NewDnsCount; NewIndex++) { CopyMem (&DnsAddress, NewDns + NewIndex, sizeof (IP4_ADDR)); - - if (!NetIp4IsUnicast (NTOHL (DnsAddress), 0)) { - // - // The dns server address must be unicast. - // - FreePool (Tmp); - return EFI_INVALID_PARAMETER; - } - for (Index1 =3D NewIndex + 1; Index1 < NewDnsCount; Index1++) { if (EFI_IP4_EQUAL (NewDns + NewIndex, NewDns + Index1)) { FreePool (Tmp); @@ -1347,14 +1338,15 @@ Ip4Config2SetGateway ( return EFI_WRITE_PROTECTED; } =20 + IpSb =3D IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance); =20 NewGateway =3D (EFI_IPv4_ADDRESS *) Data; NewGatewayCount =3D DataSize / sizeof (EFI_IPv4_ADDRESS); for (Index1 =3D 0; Index1 < NewGatewayCount; Index1++) { CopyMem (&Gateway, NewGateway + Index1, sizeof (IP4_ADDR)); - =20 - if (!NetIp4IsUnicast (NTOHL (Gateway), 0)) { =20 + if ((IpSb->DefaultInterface->SubnetMask !=3D 0) &&=20 + !NetIp4IsUnicast (NTOHL (Gateway),=20 + IpSb->DefaultInterface->SubnetMask)) { return EFI_INVALID_PARAMETER; } =20 @@ -1365,7 +1357,6 @@ Ip4Config2SetGateway ( } } =20 - IpSb =3D IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance); DataItem =3D &Instance->DataItem[Ip4Config2DataTypeGateway]; OldGateway =3D DataItem->Data.Gateway; OldGatewayCount =3D DataItem->DataSize / sizeof (EFI_IPv4_ADDRESS); diff= --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c b/MdeModulePk= g/Universal/Network/Ip4Dxe/Ip4Config2Nv.c index 381dcb1..9a2bbdf 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c @@ -1,7 +1,7 @@ /** @file Helper functions for configuring or getting the parameters relating to I= p4. =20 -Copyright (c) 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made availab= le under the terms and conditions of the BSD License which accompanies thi= s distribution. The full text of the license may be found at @@ -608,20 +6= 08,20 @@ Ip4Config2ConvertIfrNvDataToConfigNvData ( // Ip4NvData->Policy =3D Ip4Config2PolicyStatic; =20 - Status =3D Ip4Config2StrToIp (IfrFormNvData->StationAddress, &StationA= ddress.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; - } - =20 Status =3D Ip4Config2StrToIp (IfrFormNvData->SubnetMask, &SubnetMask.v= 4); if (EFI_ERROR (Status) || ((SubnetMask.Addr[0] !=3D 0) && (GetSubnetMa= skPrefixLength (&SubnetMask.v4) =3D=3D 0))) { CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Su= bnet Mask!", NULL); return EFI_INVALID_PARAMETER; } + + Status =3D Ip4Config2StrToIp (IfrFormNvData->StationAddress, &StationA= ddress.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; + } =20 Status =3D Ip4Config2StrToIp (IfrFormNvData->GatewayAddress, &Gateway.= v4); - if (EFI_ERROR (Status) || ((Gateway.Addr[0] !=3D 0) && !NetIp4IsUnicas= t (NTOHL (Gateway.Addr[0]), 0))) { + if (EFI_ERROR (Status) || ((Gateway.Addr[0] !=3D 0) &&=20 + !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), NTOHL=20 + (SubnetMask.Addr[0])))) { CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Ga= teway!", NULL); return EFI_INVALID_PARAMETER; } @@ -630,11 +630,6 @@ Ip4Config2ConvertIfrNvDataToConfigNvData ( if (!EFI_ERROR (Status) && DnsCount > 0) { for (Index =3D 0; Index < DnsCount; Index ++) { CopyMem (&Ip, &DnsAddress[Index], sizeof (IP4_ADDR)); - if (!NetIp4IsUnicast (NTOHL (Ip), 0)) { - CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invali= d Dns Server!", NULL); - FreePool(DnsAddress); - return EFI_INVALID_PARAMETER; - }=20 }=20 } else { if (EFI_ERROR (Status)) { @@ -1146,7 +1141,7 @@ Ip4FormCallback ( switch (QuestionId) { case KEY_LOCAL_IP: Status =3D Ip4Config2StrToIp (IfrFormNvData->StationAddress, &Statio= nAddress.v4); - if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (StationAddress.Ad= dr[0]), 0)) { + if (EFI_ERROR (Status)) { CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid = IP address!", NULL); Status =3D EFI_INVALID_PARAMETER; } @@ -1162,7 +1157,7 @@ Ip4FormCallback ( =20 case KEY_GATE_WAY: Status =3D Ip4Config2StrToIp (IfrFormNvData->GatewayAddress, &Gatewa= y.v4); - if (EFI_ERROR (Status) || ((Gateway.Addr[0] !=3D 0) && !NetIp4IsUnic= ast (NTOHL (Gateway.Addr[0]), 0))) { + if (EFI_ERROR (Status)) { CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid = Gateway!", NULL); Status =3D EFI_INVALID_PARAMETER; } @@ -1173,11 +1168,6 @@ Ip4FormCallback ( if (!EFI_ERROR (Status) && DnsCount > 0) { for (Index =3D 0; Index < DnsCount; Index ++) { CopyMem (&Ip, &DnsAddress[Index], sizeof (IP4_ADDR)); - if (!NetIp4IsUnicast (NTOHL (Ip), 0)) { - CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Inva= lid Dns Server!", NULL); - Status =3D EFI_INVALID_PARAMETER; - break; - }=20 } } else { if (EFI_ERROR (Status)) { diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c b/MdeModulePkg/U= niversal/Network/Ip4Dxe/Ip4If.c index e457276..9cd5dd5 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c @@ -560,9 +560,7 @@ Ip4SetAddress ( { EFI_ARP_CONFIG_DATA ArpConfig; EFI_STATUS Status; - INTN Type; INTN Len; - IP4_ADDR Netmask; =20 NET_CHECK_SIGNATURE (Interface, IP4_INTERFACE_SIGNATURE); =20 @@ -578,12 +576,9 @@ Ip4SetAddress ( Interface->SubnetMask =3D SubnetMask; Interface->SubnetBrdcast =3D (IpAddr | ~SubnetMask); =20 - Type =3D NetGetIpClass (IpAddr); - ASSERT (Type <=3D IP4_ADDR_CLASSC); Len =3D NetGetMaskLength (SubnetMask); ASSERT (Len <=3D IP4_MASK_MAX); - Netmask =3D gIp4AllMasks[MIN (Len, Type << 3)]; - Interface->NetBrdcast =3D (IpAddr | ~Netmask); + Interface->NetBrdcast =3D (IpAddr | ~SubnetMask); =20 // // Do clean up for Arp child diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c b/MdeMod= ulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c index 7ed2e52..1f8288e 100644 --- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c +++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c @@ -2,7 +2,7 @@ Interface routine for Mtftp4. =20 (C) Copyright 2014 Hewlett-Packard Development Company, L.P.
-Copyrigh= t (c) 2006 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made availab= le under the terms and conditions of the BSD License which accompanies thi= s distribution. The full text of the license may be found at @@ -192,9 +19= 2,6 @@ Mtftp4OverrideValid ( IP4_ADDR Gateway; =20 CopyMem (&Ip, &Override->ServerIp, sizeof (IP4_ADDR)); - if (!NetIp4IsUnicast (NTOHL (Ip), 0)) { - return FALSE; - } =20 Config =3D &Instance->Config; =20 @@ -667,10 +664,6 @@ EfiMtftp4Configure ( Gateway =3D NTOHL (Gateway); ServerIp =3D NTOHL (ServerIp); =20 - if (!NetIp4IsUnicast (ServerIp, 0)) { - return EFI_INVALID_PARAMETER; - } - if (!ConfigData->UseDefaultSetting && ((!IP4_IS_VALID_NETMASK (Netmask) || !NetIp4IsUnicast (Ip, Netmask)= ))) { =20 diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Main.c b/MdeModuleP= kg/Universal/Network/Tcp4Dxe/Tcp4Main.c index c7d3d32..0266ff5 100644 --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Main.c +++ b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Main.c @@ -1,7 +1,7 @@ /** @file Implementation of TCP4 protocol services. =20 -Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made availab= le under the terms and conditions of the BSD License which accompanies thi= s distribution. The full text of the license may be found at @@ -170,9 +17= 0,6 @@ Tcp4Configure ( if (NULL !=3D TcpConfigData) { =20 CopyMem (&Ip, &TcpConfigData->AccessPoint.RemoteAddress, sizeof (IP4_A= DDR)); - if ((Ip !=3D 0) && !NetIp4IsUnicast (NTOHL (Ip), 0)) { - return EFI_INVALID_PARAMETER; - } =20 if (TcpConfigData->AccessPoint.ActiveFlag && (0 =3D=3D TcpConfigData->AccessPoint.RemotePort || (Ip =3D=3D 0))) {= @@ -183,7 +180,7 @@ Tcp4Configure ( =20 CopyMem (&Ip, &TcpConfigData->AccessPoint.StationAddress, sizeof (IP= 4_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)) ||=20 + !NetIp4IsUnicast (NTOHL (Ip), NTOHL (SubnetMask))) { return EFI_INVALID_PARAMETER; } } diff --git a/MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c b/MdeModuleP= kg/Universal/Network/Udp4Dxe/Udp4Impl.c index 20dbeff..df41433 100644 --- a/MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c +++ b/MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c @@ -827,7 +827,9 @@ Udp4ValidateTxToken ( if (TxData->GatewayAddress !=3D NULL) { CopyMem (&GatewayAddress, TxData->GatewayAddress, sizeof (IP4_ADDR)); =20 - if (!NetIp4IsUnicast (NTOHL (GatewayAddress), 0)) { + if (!Instance->ConfigData.UseDefaultAddress && + (EFI_NTOHL(Instance->ConfigData.SubnetMask) !=3D 0) && + !NetIp4IsUnicast (NTOHL (GatewayAddress),=20 + EFI_NTOHL(Instance->ConfigData.SubnetMask))) { // // The specified GatewayAddress is not a unicast IPv4 address while = it's not 0. // @@ -842,7 +844,10 @@ Udp4ValidateTxToken ( =20 CopyMem (&SourceAddress, &UdpSessionData->SourceAddress, sizeof (IP4_A= DDR)); =20 - if ((SourceAddress !=3D 0) && !NetIp4IsUnicast (HTONL (SourceAddress),= 0)) { + if ((SourceAddress !=3D 0) &&=20 + !Instance->ConfigData.UseDefaultAddress && + (EFI_NTOHL(Instance->ConfigData.SubnetMask) !=3D 0) && + !NetIp4IsUnicast (HTONL (SourceAddress),=20 + EFI_NTOHL(Instance->ConfigData.SubnetMask))) { // // Check whether SourceAddress is a valid IPv4 address in case it's = not zero. // The configured station address is used if SourceAddress is zero. diff --git a/MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Main.c b/MdeModuleP= kg/Universal/Network/Udp4Dxe/Udp4Main.c index 5ea22ac..4330c91 100644 --- a/MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Main.c +++ b/MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Main.c @@ -1,7 +1,7 @@ /** @file =20 (C) Copyright 2014 Hewlett-Packard Development Company, L.P.
-Copyrigh= t (c) 2006 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made availab= le under the terms and conditions of the BSD License which accompanies thi= s distribution. The full text of the license may be found at @@ -172,8 +17= 2,7 @@ Udp4Configure ( =20 if (!UdpConfigData->UseDefaultAddress && (!IP4_IS_VALID_NETMASK (SubnetMask) || - !((StationAddress =3D=3D 0) || NetIp4IsUnicast (StationAddress, Subn= etMask)) || - !((RemoteAddress =3D=3D 0) || NetIp4IsUnicast (RemoteAddress, 0))))= { + !((StationAddress =3D=3D 0) || NetIp4IsUnicast (StationAddress,=20 + SubnetMask)))) { // // Don't use default address, and subnet mask is invalid or StationA= ddress is not // a valid unicast IPv4 address or RemoteAddress is not a valid unic= ast IPv4 address diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/P= xeBcImpl.c b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c index cf7b7b5..ac05451 100644 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c +++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c @@ -176,7 +176,9 @@ IcmpErrorListenHandlerDpc ( } =20 if (EFI_IP4 (RxData->Header->SourceAddress) !=3D 0 && - !NetIp4IsUnicast (EFI_NTOHL (RxData->Header->SourceAddress), 0)) { + (NTOHL (Mode->SubnetMask.Addr[0]) !=3D 0) && + IP4_NET_EQUAL (NTOHL(Mode->StationIp.Addr[0]), EFI_NTOHL (RxData->He= ader->SourceAddress), NTOHL (Mode->SubnetMask.Addr[0])) && + !NetIp4IsUnicast (EFI_NTOHL (RxData->Header->SourceAddress),=20 + NTOHL (Mode->SubnetMask.Addr[0]))) { // // The source address is not zero and it's not a unicast IP address, d= iscard it. // @@ -1163,7 +1165,7 @@ EfiPxeBcMtftp ( if ((This =3D=3D NULL) = || (Filename =3D=3D NULL) = || (BufferSize =3D=3D NULL) = || - ((ServerIp =3D=3D NULL) || !NetIp4IsUnicast (NTOHL (ServerIp->Addr[0= ]), 0)) || + (ServerIp =3D=3D NULL) = || ((BufferPtr =3D=3D NULL) && DontUseBuffer) = || ((BlockSize !=3D NULL) && (*BlockSize < 512))) { =20 @@ -1378,13 +1380,6 @@ EfiPxeBcUdpWrite ( return EFI_INVALID_PARAMETER; } =20 - if ((GatewayIp !=3D NULL) && !NetIp4IsUnicast (NTOHL (GatewayIp->Addr[0]= ), 0)) { - // - // Gateway is provided but it's not a unicast IP address. - // - return EFI_INVALID_PARAMETER; - } - if ((HeaderSize !=3D NULL) && ((*HeaderSize =3D=3D 0) || (HeaderPtr =3D= =3D NULL))) { // // The HeaderSize ptr isn't NULL and: 1. the value is zero; or 2. the = HeaderPtr @@ -1964,9 +1959,11 @@ EfiPxeBcSetIpFilter ( DEBUG ((EFI_D_ERROR, "There is broadcast address in NewFilter.\n")); return EFI_INVALID_PARAMETER; } - if (NetIp4IsUnicast (EFI_IP4 (NewFilter->IpList[Index].v4), 0) && - ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != =3D 0) - ) { + if ((EFI_NTOHL(Mode->StationIp) !=3D 0) && + (EFI_NTOHL(Mode->SubnetMask) !=3D 0) && + IP4_NET_EQUAL(EFI_NTOHL(Mode->StationIp), EFI_NTOHL(NewFilter->IpL= ist[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)=20 + !=3D 0)) { // // If EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP is set and IP4 address = is in IpList, // promiscuous mode is needed. @@ -2308,11 +2305,11 @@ EfiPxeBcSetStationIP ( return EFI_INVALID_PARAMETER; } =20 - if (NewStationIp !=3D NULL && !NetIp4IsUnicast (NTOHL (NewStationIp->Add= r[0]), 0)) { + if (NewSubnetMask !=3D NULL && !IP4_IS_VALID_NETMASK (NTOHL=20 + (NewSubnetMask->Addr[0]))) { return EFI_INVALID_PARAMETER; } - - if (NewSubnetMask !=3D NULL && !IP4_IS_VALID_NETMASK (NTOHL (NewSubnetMa= sk->Addr[0]))) { + =20 + if (NewStationIp !=3D NULL && !NetIp4IsUnicast (NTOHL=20 + (NewStationIp->Addr[0]), NTOHL (NewSubnetMask->Addr[0]))) { return EFI_INVALID_PARAMETER; } =20 -- 2.7.4.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel