From nobody Fri Dec 27 20:15:43 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1500984786077958.9747622582539; Tue, 25 Jul 2017 05:13:06 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 23F3321C9126A; Tue, 25 Jul 2017 05:10:55 -0700 (PDT) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 9800221C91269 for ; Tue, 25 Jul 2017 05:10:52 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jul 2017 05:12:54 -0700 Received: from jiaxinwu-mobl2.ccr.corp.intel.com ([10.255.27.40]) by orsmga001.jf.intel.com with ESMTP; 25 Jul 2017 05:12:52 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,411,1496127600"; d="scan'208";a="1155145673" From: Jiaxin Wu To: edk2-devel@lists.01.org Date: Tue, 25 Jul 2017 20:12:45 +0800 Message-Id: <1500984765-8040-5-git-send-email-jiaxin.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1500984765-8040-1-git-send-email-jiaxin.wu@intel.com> References: <1500984765-8040-1-git-send-email-jiaxin.wu@intel.com> Subject: [edk2] [Patch 4/4] NetworkPkg/HttpBootDxe: Update device path node to include DNS information X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ye Ting , Fu Siyuan , Wu Jiaxin MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Cc: Ye Ting Cc: Fu Siyuan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin --- NetworkPkg/HttpBootDxe/HttpBootClient.c | 138 ++++++++++++++++++++++++++--= ---- NetworkPkg/HttpBootDxe/HttpBootDxe.h | 2 + NetworkPkg/HttpBootDxe/HttpBootImpl.c | 7 +- 3 files changed, 122 insertions(+), 25 deletions(-) diff --git a/NetworkPkg/HttpBootDxe/HttpBootClient.c b/NetworkPkg/HttpBootD= xe/HttpBootClient.c index 68f5a49..5c87171 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootClient.c +++ b/NetworkPkg/HttpBootDxe/HttpBootClient.c @@ -14,11 +14,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITH= ER EXPRESS OR IMPLIED. **/ =20 #include "HttpBootDxe.h" =20 /** - Update the IP and URL device path node to include the boot resource info= rmation. + Update the device path node to include the boot resource information. =20 @param[in] Private The pointer to the driver's private dat= a. =20 @retval EFI_SUCCESS Device patch successfully updated. @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources. @@ -29,16 +29,18 @@ EFI_STATUS HttpBootUpdateDevicePath ( IN HTTP_BOOT_PRIVATE_DATA *Private ) { EFI_DEV_PATH *Node; - EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath; + EFI_DEVICE_PATH_PROTOCOL *TmpIpDevicePath; + EFI_DEVICE_PATH_PROTOCOL *TmpDnsDevicePath; EFI_DEVICE_PATH_PROTOCOL *NewDevicePath; UINTN Length; EFI_STATUS Status; =20 - TmpDevicePath =3D NULL; + TmpIpDevicePath =3D NULL; + TmpDnsDevicePath =3D NULL; =20 // // Update the IP node with DHCP assigned information. // if (!Private->UsingIpv6) { @@ -70,33 +72,69 @@ HttpBootUpdateDevicePath ( CopyMem (&Node->Ipv6.LocalIpAddress, &Private->StationIp.v6, sizeof (E= FI_IPv6_ADDRESS)); CopyMem (&Node->Ipv6.RemoteIpAddress, &Private->ServerIp.v6, sizeof (E= FI_IPv6_ADDRESS)); CopyMem (&Node->Ipv6.GatewayIpAddress, &Private->GatewayIp.v6, sizeof = (EFI_IPv6_ADDRESS)); } =20 - TmpDevicePath =3D AppendDevicePathNode (Private->ParentDevicePath, (EFI_= DEVICE_PATH_PROTOCOL*) Node); + TmpIpDevicePath =3D AppendDevicePathNode (Private->ParentDevicePath, (EF= I_DEVICE_PATH_PROTOCOL*) Node); FreePool (Node); - if (TmpDevicePath =3D=3D NULL) { + if (TmpIpDevicePath =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; } =20 // + // Update the DNS node with DNS server IP list if existed. + // + if (Private->DnsServerIp !=3D NULL) { + Length =3D sizeof (EFI_DEVICE_PATH_PROTOCOL) + sizeof (Node->Dns.IsIPv= 6) + Private->DnsServerCount * sizeof (EFI_IP_ADDRESS); + Node =3D AllocatePool (Length); + if (Node =3D=3D NULL) { + FreePool (TmpIpDevicePath); + return EFI_OUT_OF_RESOURCES; + } + Node->DevPath.Type =3D MESSAGING_DEVICE_PATH; + Node->DevPath.SubType =3D MSG_DNS_DP; + SetDevicePathNodeLength (Node, Length); + Node->Dns.IsIPv6 =3D Private->UsingIpv6 ? 0x01 : 0x00; + CopyMem ((UINT8*) Node + sizeof (EFI_DEVICE_PATH_PROTOCOL) + sizeof (N= ode->Dns.IsIPv6), Private->DnsServerIp, Private->DnsServerCount * sizeof (E= FI_IP_ADDRESS)); + =20 + TmpDnsDevicePath =3D AppendDevicePathNode (TmpIpDevicePath, (EFI_DEVIC= E_PATH_PROTOCOL*) Node); + FreePool (Node); + FreePool (TmpIpDevicePath); + TmpIpDevicePath =3D NULL; + if (TmpDnsDevicePath =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + } + + // // Update the URI node with the boot file URI. // Length =3D sizeof (EFI_DEVICE_PATH_PROTOCOL) + AsciiStrSize (Private->Bo= otFileUri); Node =3D AllocatePool (Length); if (Node =3D=3D NULL) { - FreePool (TmpDevicePath); + if (TmpIpDevicePath !=3D NULL) { + FreePool (TmpIpDevicePath); + } + if (TmpDnsDevicePath !=3D NULL) { + FreePool (TmpDnsDevicePath); + } return EFI_OUT_OF_RESOURCES; } Node->DevPath.Type =3D MESSAGING_DEVICE_PATH; Node->DevPath.SubType =3D MSG_URI_DP; SetDevicePathNodeLength (Node, Length); CopyMem ((UINT8*) Node + sizeof (EFI_DEVICE_PATH_PROTOCOL), Private->Boo= tFileUri, AsciiStrSize (Private->BootFileUri)); - =20 - NewDevicePath =3D AppendDevicePathNode (TmpDevicePath, (EFI_DEVICE_PATH_= PROTOCOL*) Node); + + if (TmpDnsDevicePath !=3D NULL) { + NewDevicePath =3D AppendDevicePathNode (TmpDnsDevicePath, (EFI_DEVICE_= PATH_PROTOCOL*) Node); + FreePool (TmpDnsDevicePath); + } else { + ASSERT (TmpIpDevicePath !=3D NULL); + NewDevicePath =3D AppendDevicePathNode (TmpIpDevicePath, (EFI_DEVICE_P= ATH_PROTOCOL*) Node); + FreePool (TmpIpDevicePath); + } FreePool (Node); - FreePool (TmpDevicePath); if (NewDevicePath =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; } =20 if (!Private->UsingIpv6) { @@ -151,18 +189,21 @@ HttpBootDhcp4ExtractUriInfo ( { HTTP_BOOT_DHCP4_PACKET_CACHE *SelectOffer; HTTP_BOOT_DHCP4_PACKET_CACHE *HttpOffer; UINT32 SelectIndex; UINT32 ProxyIndex; + UINT32 DnsServerIndex; EFI_DHCP4_PACKET_OPTION *Option; EFI_STATUS Status; =20 ASSERT (Private !=3D NULL); ASSERT (Private->SelectIndex !=3D 0); SelectIndex =3D Private->SelectIndex - 1; ASSERT (SelectIndex < HTTP_BOOT_OFFER_MAX_NUM); =20 + DnsServerIndex =3D 0; + =20 Status =3D EFI_SUCCESS; =20 // // SelectOffer contains the IP address configuration and name server con= figuration. // HttpOffer contains the boot file URL. @@ -198,24 +239,41 @@ HttpBootDhcp4ExtractUriInfo ( if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "HttpBootDhcp4ExtractUriInfo: %r.\n", Status)); return Status; } =20 - // - // Configure the default DNS server if server assigned. - // if ((SelectOffer->OfferType =3D=3D HttpOfferTypeDhcpNameUriDns) ||=20 (SelectOffer->OfferType =3D=3D HttpOfferTypeDhcpDns) || (SelectOffer->OfferType =3D=3D HttpOfferTypeDhcpIpUriDns)) { Option =3D SelectOffer->OptList[HTTP_BOOT_DHCP4_TAG_INDEX_DNS_SERVER]; ASSERT (Option !=3D NULL); + + // + // Record the Dns Server address list. + // + Private->DnsServerCount =3D (Option->Length) / sizeof (EFI_IPv4_ADDRES= S); + + Private->DnsServerIp =3D AllocateZeroPool (Private->DnsServerCount * s= izeof (EFI_IP_ADDRESS)); + if (Private->DnsServerIp =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + for (DnsServerIndex =3D 0; DnsServerIndex < Private->DnsServerCount; D= nsServerIndex++) { + CopyMem (&(Private->DnsServerIp[DnsServerIndex].v4), &(((EFI_IPv4_AD= DRESS *) Option->Data)[DnsServerIndex]), sizeof (EFI_IPv4_ADDRESS)); + } + =20 + // + // Configure the default DNS server if server assigned. + // =20 Status =3D HttpBootRegisterIp4Dns ( Private, Option->Length, Option->Data ); if (EFI_ERROR (Status)) { + FreePool (Private->DnsServerIp); + Private->DnsServerIp =3D NULL; return Status; } } =20 // @@ -233,13 +291,17 @@ HttpBootDhcp4ExtractUriInfo ( // // All boot informations are valid here. // =20 // - // Update the device path to include the IP and boot URI information. + // Update the device path to include the boot resource information. // Status =3D HttpBootUpdateDevicePath (Private); + if (EFI_ERROR (Status) && Private->DnsServerIp !=3D NULL) { + FreePool (Private->DnsServerIp); + Private->DnsServerIp =3D NULL; + } =20 return Status; } =20 /** @@ -258,10 +320,11 @@ HttpBootDhcp6ExtractUriInfo ( { HTTP_BOOT_DHCP6_PACKET_CACHE *SelectOffer; HTTP_BOOT_DHCP6_PACKET_CACHE *HttpOffer; UINT32 SelectIndex; UINT32 ProxyIndex; + UINT32 DnsServerIndex; EFI_DHCP6_PACKET_OPTION *Option; EFI_IPv6_ADDRESS IpAddr; CHAR8 *HostName; UINTN HostNameSize; CHAR16 *HostNameStr; @@ -270,10 +333,12 @@ HttpBootDhcp6ExtractUriInfo ( ASSERT (Private !=3D NULL); ASSERT (Private->SelectIndex !=3D 0); SelectIndex =3D Private->SelectIndex - 1; ASSERT (SelectIndex < HTTP_BOOT_OFFER_MAX_NUM); =20 + DnsServerIndex =3D 0; + Status =3D EFI_SUCCESS; HostName =3D NULL; // // SelectOffer contains the IP address configuration and name server con= figuration. // HttpOffer contains the boot file URL. @@ -324,26 +389,41 @@ HttpBootDhcp6ExtractUriInfo ( // Status =3D HttpBootSetIp6Gateway (Private); if (EFI_ERROR (Status)) { return Status; } - =20 - // - // Configure the default DNS server if server assigned. - // + if ((SelectOffer->OfferType =3D=3D HttpOfferTypeDhcpNameUriDns) ||=20 (SelectOffer->OfferType =3D=3D HttpOfferTypeDhcpDns) || (SelectOffer->OfferType =3D=3D HttpOfferTypeDhcpIpUriDns)) { Option =3D SelectOffer->OptList[HTTP_BOOT_DHCP6_IDX_DNS_SERVER]; ASSERT (Option !=3D NULL); + + // + // Record the Dns Server address list. + // + Private->DnsServerCount =3D HTONS (Option->OpLen) / sizeof (EFI_IPv6_A= DDRESS); + + Private->DnsServerIp =3D AllocateZeroPool (Private->DnsServerCount * s= izeof (EFI_IP_ADDRESS)); + if (Private->DnsServerIp =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + for (DnsServerIndex =3D 0; DnsServerIndex < Private->DnsServerCount; D= nsServerIndex++) { + CopyMem (&(Private->DnsServerIp[DnsServerIndex].v6), &(((EFI_IPv6_AD= DRESS *) Option->Data)[DnsServerIndex]), sizeof (EFI_IPv6_ADDRESS)); + } + + // + // Configure the default DNS server if server assigned. + // Status =3D HttpBootSetIp6Dns ( Private, HTONS (Option->OpLen), Option->Data ); if (EFI_ERROR (Status)) { - return Status; + goto Error; } } =20 // // Extract the HTTP server Ip frome URL. This is used to Check route tab= le=20 @@ -363,21 +443,26 @@ HttpBootDhcp6ExtractUriInfo ( Private->BootFileUri, Private->BootFileUriParser, &HostName ); if (EFI_ERROR (Status)) { - return Status; + goto Error; } =20 HostNameSize =3D AsciiStrSize (HostName); HostNameStr =3D AllocateZeroPool (HostNameSize * sizeof (CHAR16)); if (HostNameStr =3D=3D NULL) { Status =3D EFI_OUT_OF_RESOURCES; goto Error; } =20 AsciiStrToUnicodeStrS (HostName, HostNameStr, HostNameSize); + + if (HostName !=3D NULL) { + FreePool (HostName); + } + =20 Status =3D HttpBootDns (Private, HostNameStr, &IpAddr); FreePool (HostNameStr); if (EFI_ERROR (Status)) { goto Error; } =20 @@ -400,20 +485,25 @@ HttpBootDhcp6ExtractUriInfo ( // // All boot informations are valid here. // =20 // - // Update the device path to include the IP and boot URI information. + // Update the device path to include the boot resource information. // Status =3D HttpBootUpdateDevicePath (Private); + if (EFI_ERROR (Status)) { + goto Error; + } + =20 + return Status; =20 Error: - =20 - if (HostName !=3D NULL) { - FreePool (HostName); + if (Private->DnsServerIp !=3D NULL) { + FreePool (Private->DnsServerIp); + Private->DnsServerIp =3D NULL; } - =20 + =20 return Status; } =20 =20 /** diff --git a/NetworkPkg/HttpBootDxe/HttpBootDxe.h b/NetworkPkg/HttpBootDxe/= HttpBootDxe.h index 8d89b3e..aa4fc43 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootDxe.h +++ b/NetworkPkg/HttpBootDxe/HttpBootDxe.h @@ -196,10 +196,12 @@ struct _HTTP_BOOT_PRIVATE_DATA { EFI_IP_ADDRESS StationIp; EFI_IP_ADDRESS SubnetMask; EFI_IP_ADDRESS GatewayIp; EFI_IP_ADDRESS ServerIp; UINT16 Port; + UINT32 DnsServerCount; + EFI_IP_ADDRESS *DnsServerIp; =20 // // The URI string attempt to download through HTTP, may point to // the memory in cached DHCP offer, or to the memory in FilePathUri. // diff --git a/NetworkPkg/HttpBootDxe/HttpBootImpl.c b/NetworkPkg/HttpBootDxe= /HttpBootImpl.c index 63cf396..40f7356 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootImpl.c +++ b/NetworkPkg/HttpBootDxe/HttpBootImpl.c @@ -1,9 +1,9 @@ /** @file The implementation of EFI_LOAD_FILE_PROTOCOL for UEFI HTTP boot. =20 -Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.
(C) Copyright 2016 Hewlett Packard Enterprise Development LP
This program and the accompanying materials are licensed and made availabl= e under=20 the terms and conditions of the BSD License that accompanies this distribu= tion. =20 The full text of the license may be found at http://opensource.org/licenses/bsd-license.php. = =20 @@ -463,10 +463,15 @@ HttpBootStop ( HttpUrlFreeParser (Private->OfferBuffer[Index].Dhcp6.UriParser); } } } =20 + if (Private->DnsServerIp !=3D NULL) { + FreePool (Private->DnsServerIp); + Private->DnsServerIp =3D NULL; + } + if (Private->FilePathUri!=3D NULL) { FreePool (Private->FilePathUri); HttpUrlFreeParser (Private->FilePathUriParser); Private->FilePathUri =3D NULL; Private->FilePathUriParser =3D NULL; --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel