From nobody Wed May 8 18:06:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+94817+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+94817+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1665178485; cv=none; d=zohomail.com; s=zohoarc; b=Ca/+cugIb9wzwdq6EKba5pQwwXOktFV+ITJZNSgqi5hejRwPqOyHQY9VJIBEClKan4j0ddh9+ycP52IZv9CuQsEetYGgesRcnPH8VjPb7mH8kM0InhRWwRUUMMm8h4gCUGV3OtOx2GgGygb41Tk8Fu0G5j4OwDHUaZw2C+pv1KA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665178485; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=smrRo9gIPNW2MO8sNfHVMmVSu+n7wlv/3BG0mEVD//A=; b=i5xtTPLFHd4R2ZxtTH8B64hA9u6fWGUe0171+bWuCuhPqqMhQAfjoCfTz4/GjFG8DgARv8gUs6ED4UtmgOYRSru72gGOolY5Us4Xd6mcQxU+W14oJ5utM1bH3gu4XZ/A/3d/N74oQHWmb9QnTJpnXpUoQu7oi4lHn4D5zNSgUAo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+94817+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665178485639476.9557079517987; Fri, 7 Oct 2022 14:34:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Let7YY1788612xiYfrpXgFMg; Fri, 07 Oct 2022 14:34:44 -0700 X-Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web11.262.1665178478972669259 for ; Fri, 07 Oct 2022 14:34:43 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10493"; a="287069091" X-IronPort-AV: E=Sophos;i="5.95,167,1661842800"; d="scan'208";a="287069091" X-Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2022 14:34:43 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10493"; a="658479366" X-IronPort-AV: E=Sophos;i="5.95,167,1661842800"; d="scan'208";a="658479366" X-Received: from fmbiosdev02.amr.corp.intel.com ([10.80.127.10]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2022 14:34:42 -0700 From: "Saloni Kasbekar" To: devel@edk2.groups.io Cc: Saloni Kasbekar , Maciej Rabeda , Wu Jiaxin , Siyuan Fu Subject: [edk2-devel] [[edk2-staging/HttpProxy PATCH v2] 3/6] NetworkPkg/HttpBootDxe: Update HTTP Boot Driver with parsed Proxy URL Date: Fri, 7 Oct 2022 14:34:27 -0700 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,saloni.kasbekar@intel.com X-Gm-Message-State: QbjJEEbspzC88nA7JgoPbtsfx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665178484; bh=tOuxvHbDhp/AqEQHG2xWRykZBjvNxK52wbkT4w5h5cU=; h=Cc:Date:From:Reply-To:Subject:To; b=UJiaey5Q2rFROrQseW/49XqnYueUfUwjA/cqnoJ8H/6n1RYyu405nOouXgb0Ki0wkBJ ohNnE2ilbIN8tOC3gt8e+u1rtfo250l9MJEBCmerisuuzFxeHuU84PEMu5cXPAOGi+g99 pNA7Kje4bOrbUBq6kWMfXg8GfeT5GEJ//js= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665178486138100002 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3951 Add ProxyUri to HTTP_BOOT_PRIVATE_DATA Parse HTTP Boot Device path to process Proxy and EndPoint URLs Cc: Maciej Rabeda Cc: Wu Jiaxin Cc: Siyuan Fu Signed-off-by: Saloni Kasbekar --- NetworkPkg/HttpBootDxe/HttpBootClient.c | 30 ++++- NetworkPkg/HttpBootDxe/HttpBootDxe.h | 6 + NetworkPkg/HttpBootDxe/HttpBootImpl.c | 57 +++++---- NetworkPkg/HttpBootDxe/HttpBootSupport.c | 154 +++++++++++++++++------ NetworkPkg/HttpBootDxe/HttpBootSupport.h | 13 +- 5 files changed, 189 insertions(+), 71 deletions(-) diff --git a/NetworkPkg/HttpBootDxe/HttpBootClient.c b/NetworkPkg/HttpBootD= xe/HttpBootClient.c index 40f64fcb6b..b13155b576 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootClient.c +++ b/NetworkPkg/HttpBootDxe/HttpBootClient.c @@ -678,6 +678,10 @@ HttpBootFreeCache ( FreePool (Cache->RequestData->Url); } =20 + if (Cache->RequestData->ProxyUrl !=3D NULL) { + FreePool (Cache->RequestData->ProxyUrl); + } + FreePool (Cache->RequestData); } =20 @@ -950,6 +954,7 @@ HttpBootGetBootFile ( UINT8 *Block; UINTN UrlSize; CHAR16 *Url; + CHAR16 *ProxyUrl; BOOLEAN IdentityMode; UINTN ReceivedSize; CHAR8 BaseAuthValue[80]; @@ -989,6 +994,22 @@ HttpBootGetBootFile ( // Not found in cache, try to download it through HTTP. // =20 + // + // Initialize ProxyUrl - Set to NULL if connecting without Proxy + // + if (Private->ProxyUri !=3D NULL) { + UrlSize =3D AsciiStrSize (Private->ProxyUri); + ProxyUrl =3D AllocatePool (UrlSize * (sizeof (CHAR16))); + if (ProxyUrl =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto ERROR_1; + } + + AsciiStrToUnicodeStrS (Private->ProxyUri, ProxyUrl, UrlSize); + } else { + ProxyUrl =3D NULL; + } + // // 1. Create a temp cache item for the requested URI if caller doesn't p= rovide buffer. // @@ -1106,8 +1127,9 @@ HttpBootGetBootFile ( goto ERROR_3; } =20 - RequestData->Method =3D HeaderOnly ? HttpMethodHead : HttpMethodGet; - RequestData->Url =3D Url; + RequestData->Method =3D HeaderOnly ? HttpMethodHead : HttpMethodGet; + RequestData->Url =3D Url; + RequestData->ProxyUrl =3D ProxyUrl; =20 // // 2.3 Record the request info in a temp cache item. @@ -1441,6 +1463,10 @@ ERROR_2: } =20 ERROR_1: + if (ProxyUrl !=3D NULL) { + FreePool (ProxyUrl); + } + if (Url !=3D NULL) { FreePool (Url); } diff --git a/NetworkPkg/HttpBootDxe/HttpBootDxe.h b/NetworkPkg/HttpBootDxe/= HttpBootDxe.h index 5ff8ad4698..8caf2e9a45 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootDxe.h +++ b/NetworkPkg/HttpBootDxe/HttpBootDxe.h @@ -223,6 +223,12 @@ struct _HTTP_BOOT_PRIVATE_DATA { CHAR8 *FilePathUri; VOID *FilePathUriParser; =20 + // + // URI string for the Proxy host if BootFileUri contains a Proxy + // URI in the path + // + CHAR8 *ProxyUri; + // // Cached HTTP data // diff --git a/NetworkPkg/HttpBootDxe/HttpBootImpl.c b/NetworkPkg/HttpBootDxe= /HttpBootImpl.c index b4c61925b9..5735b96d9e 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootImpl.c +++ b/NetworkPkg/HttpBootDxe/HttpBootImpl.c @@ -115,19 +115,21 @@ HttpBootStart ( { UINTN Index; EFI_STATUS Status; - CHAR8 *Uri; + CHAR8 *ProxyUri; + CHAR8 *EndPointUri; =20 - Uri =3D NULL; + ProxyUri =3D NULL; + EndPointUri =3D NULL; =20 if ((Private =3D=3D NULL) || (FilePath =3D=3D NULL)) { return EFI_INVALID_PARAMETER; } =20 // - // Check the URI in the input FilePath, in order to see whether it is + // Check the URIs in the input FilePath, in order to see whether it is // required to boot from a new specified boot file. // - Status =3D HttpBootParseFilePath (FilePath, &Uri); + Status =3D HttpBootParseFilePath (FilePath, &ProxyUri, &EndPointUri); if (EFI_ERROR (Status)) { return EFI_INVALID_PARAMETER; } @@ -143,28 +145,21 @@ HttpBootStart ( // recorded before. // if ((UsingIpv6 !=3D Private->UsingIpv6) || - ((Uri !=3D NULL) && (AsciiStrCmp (Private->BootFileUri, Uri) !=3D = 0))) + ((EndPointUri !=3D NULL) && (AsciiStrCmp (Private->BootFileUri, En= dPointUri) !=3D 0))) { // // Restart is required, first stop then continue this start function. // Status =3D HttpBootStop (Private); if (EFI_ERROR (Status)) { - if (Uri !=3D NULL) { - FreePool (Uri); - } - - return Status; + goto ERROR; } } else { // // Restart is not required. // - if (Uri !=3D NULL) { - FreePool (Uri); - } - - return EFI_ALREADY_STARTED; + Status =3D EFI_ALREADY_STARTED; + goto ERROR; } } =20 @@ -176,17 +171,16 @@ HttpBootStart ( } else if (!UsingIpv6 && (Private->Ip4Nic !=3D NULL)) { Private->UsingIpv6 =3D FALSE; } else { - if (Uri !=3D NULL) { - FreePool (Uri); - } - - return EFI_UNSUPPORTED; + Status =3D EFI_UNSUPPORTED; + goto ERROR; } =20 // - // Record the specified URI and prepare the URI parser if needed. + // Record the specified URIs and prepare the URI parser if needed. // - Private->FilePathUri =3D Uri; + Private->ProxyUri =3D ProxyUri; + Private->FilePathUri =3D EndPointUri; + if (Private->FilePathUri !=3D NULL) { Status =3D HttpParseUrl ( Private->FilePathUri, @@ -195,8 +189,7 @@ HttpBootStart ( &Private->FilePathUriParser ); if (EFI_ERROR (Status)) { - FreePool (Private->FilePathUri); - return Status; + goto ERROR; } } =20 @@ -228,6 +221,17 @@ HttpBootStart ( Print (L"\n>>Start HTTP Boot over IPv%d", Private->UsingIpv6 ? 6 : 4); =20 return EFI_SUCCESS; + +ERROR: + if (ProxyUri !=3D NULL) { + FreePool (ProxyUri); + } + + if (EndPointUri !=3D NULL) { + FreePool (EndPointUri); + } + + return Status; } =20 /** @@ -522,6 +526,11 @@ HttpBootStop ( Private->FilePathUriParser =3D NULL; } =20 + if (Private->ProxyUri !=3D NULL) { + FreePool (Private->ProxyUri); + Private->ProxyUri =3D NULL; + } + ZeroMem (Private->OfferBuffer, sizeof (Private->OfferBuffer)); Private->OfferNum =3D 0; ZeroMem (Private->OfferCount, sizeof (Private->OfferCount)); diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.c b/NetworkPkg/HttpBoot= Dxe/HttpBootSupport.c index 236ef25931..9af6cf0c69 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootSupport.c +++ b/NetworkPkg/HttpBootDxe/HttpBootSupport.c @@ -551,71 +551,145 @@ HttpBootCheckUriScheme ( return Status; } =20 +/** + Get the URI address string from the URI device path node. + + Caller need to free the buffer in the Uri pointer. + + @param[in] Node Pointer to the URI device path node. + @param[out] Uri URI string extracted from the device pat= h. + + @retval EFI_SUCCESS The URI string is returned. + @retval EFI_INVALID_PARAMETER Parameters are NULL or invalid URI node. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. + +**/ +EFI_STATUS +HttpBootUriFromDevicePath ( + IN URI_DEVICE_PATH *Node, + OUT CHAR8 **Uri + ) +{ + UINTN UriStrLength; + + if ((Node =3D=3D NULL) || (Uri =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + UriStrLength =3D DevicePathNodeLength (Node) - sizeof (EFI_DEVICE_PATH_P= ROTOCOL); + + if (UriStrLength =3D=3D 0) { + // Invalid URI, return. + return EFI_INVALID_PARAMETER; + } + + *Uri =3D AllocatePool (UriStrLength + 1); + if (*Uri =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + CopyMem (*Uri, Node->Uri, UriStrLength); + (*Uri)[UriStrLength] =3D '\0'; + + return EFI_SUCCESS; +} + /** Get the URI address string from the input device path. =20 - Caller need to free the buffer in the UriAddress pointer. + Caller needs to free the buffers returned by this function. =20 - @param[in] FilePath Pointer to the device path which contains = a URI device path node. - @param[out] UriAddress The URI address string extract from the de= vice path. + @param[in] FilePath Pointer to the device path which contain= s a URI device path node. + @param[out] ProxyUriAddress The proxy URI address string extract fro= m the device path (if it exists) + @param[out] EndPointUriAddress The endpoint URI address string for the = endpoint host. =20 @retval EFI_SUCCESS The URI string is returned. + @retval EFI_INVALID_PARAMETER Parameters are NULL or device path is inv= alid. @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. =20 **/ EFI_STATUS HttpBootParseFilePath ( - IN EFI_DEVICE_PATH_PROTOCOL *FilePath, - OUT CHAR8 **UriAddress + IN EFI_DEVICE_PATH_PROTOCOL *FilePath, + OUT CHAR8 **ProxyUriAddress, + OUT CHAR8 **EndPointUriAddress ) { - EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; - URI_DEVICE_PATH *UriDevicePath; - CHAR8 *Uri; - UINTN UriStrLength; - - if (FilePath =3D=3D NULL) { + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *Node[2]; + EFI_DEVICE_PATH_PROTOCOL *TempNode; + BOOLEAN NodeIsUri[2]; + UINTN Index; + + if ((FilePath =3D=3D NULL) || + (ProxyUriAddress =3D=3D NULL) || + (EndPointUriAddress =3D=3D NULL)) + { return EFI_INVALID_PARAMETER; } =20 - *UriAddress =3D NULL; + *ProxyUriAddress =3D NULL; + *EndPointUriAddress =3D NULL; + ZeroMem (Node, sizeof (Node)); =20 + // Obtain last 2 device path nodes. + // Looking for sequences: + // 1) //....../Mac(...)[/Vlan(...)][/Wi-Fi(...)]/IPv6(...)[/Dns(...)]/Ur= i(ProxyServer)/Uri(EndPointServer/FilePath) + // 2) //....../Mac(...)[/Vlan(...)][/Wi-Fi(...)]/IPv6(...)[/Dns(...)]/Ur= i(EndPointServer/FilePath) // - // Extract the URI address from the FilePath - // - TempDevicePath =3D FilePath; - while (!IsDevicePathEnd (TempDevicePath)) { - if ((DevicePathType (TempDevicePath) =3D=3D MESSAGING_DEVICE_PATH) && - (DevicePathSubType (TempDevicePath) =3D=3D MSG_URI_DP)) - { - UriDevicePath =3D (URI_DEVICE_PATH *)TempDevicePath; - // - // UEFI Spec doesn't require the URI to be a NULL-terminated string - // So we allocate a new buffer and always append a '\0' to it. - // - UriStrLength =3D DevicePathNodeLength (UriDevicePath) - sizeof (EFI_= DEVICE_PATH_PROTOCOL); - if (UriStrLength =3D=3D 0) { - // - // return a NULL UriAddress if it's a empty URI device path node. - // - break; - } - - Uri =3D AllocatePool (UriStrLength + 1); - if (Uri =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } + // Expected: + // Node[1] - Uri(EndPointServer/FilePath) + // Node[0] - Either Uri(EndPointServer/FilePath) or other. + TempNode =3D FilePath; + + while (!IsDevicePathEnd (TempNode)) { + Node[0] =3D Node[1]; + Node[1] =3D TempNode; + TempNode =3D NextDevicePathNode (TempNode); + } + + // Verify if device path nodes are of type MESSAGING + URI. + for (Index =3D 0; Index < 2; Index++) { + if (Node[Index] =3D=3D NULL) { + NodeIsUri[Index] =3D FALSE; + } else { + NodeIsUri[Index] =3D ((DevicePathType (Node[Index]) =3D=3D MESSAGING= _DEVICE_PATH) && + (DevicePathSubType (Node[Index]) =3D=3D MSG_URI_= DP)); + } + } =20 - CopyMem (Uri, UriDevicePath->Uri, DevicePathNodeLength (UriDevicePat= h) - sizeof (EFI_DEVICE_PATH_PROTOCOL)); - Uri[DevicePathNodeLength (UriDevicePath) - sizeof (EFI_DEVICE_PATH_P= ROTOCOL)] =3D '\0'; + // If exists, obtain endpoint URI string. + if (NodeIsUri[1]) { + Status =3D HttpBootUriFromDevicePath ( + (URI_DEVICE_PATH *)Node[1], + EndPointUriAddress + ); =20 - *UriAddress =3D Uri; + if (EFI_ERROR (Status)) { + return Status; } =20 - TempDevicePath =3D NextDevicePathNode (TempDevicePath); + // If exists, obtain proxy URI string. + if (NodeIsUri[0]) { + Status =3D HttpBootUriFromDevicePath ( + (URI_DEVICE_PATH *)Node[0], + ProxyUriAddress + ); + + if (EFI_ERROR (Status)) { + goto ErrorExit; + } + } } =20 return EFI_SUCCESS; + +ErrorExit: + ASSERT (*EndPointUriAddress !=3D NULL); + FreePool (*EndPointUriAddress); + *EndPointUriAddress =3D NULL; + + return Status; } =20 /** diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.h b/NetworkPkg/HttpBoot= Dxe/HttpBootSupport.h index 3698e55936..5a46894517 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootSupport.h +++ b/NetworkPkg/HttpBootDxe/HttpBootSupport.h @@ -136,19 +136,22 @@ HttpBootCheckUriScheme ( /** Get the URI address string from the input device path. =20 - Caller need to free the buffer in the UriAddress pointer. + Caller needs to free the buffers returned by this function. =20 - @param[in] FilePath Pointer to the device path which contains = a URI device path node. - @param[out] UriAddress The URI address string extract from the de= vice path. + @param[in] FilePath Pointer to the device path which contain= s a URI device path node. + @param[out] ProxyUriAddress The proxy URI address string extract fro= m the device path (if it exists) + @param[out] EndPointUriAddress The endpoint URI address string for the = endpoint host. =20 @retval EFI_SUCCESS The URI string is returned. + @retval EFI_INVALID_PARAMETER Parameters are NULL or device path is inv= alid. @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. =20 **/ EFI_STATUS HttpBootParseFilePath ( - IN EFI_DEVICE_PATH_PROTOCOL *FilePath, - OUT CHAR8 **UriAddress + IN EFI_DEVICE_PATH_PROTOCOL *FilePath, + OUT CHAR8 **ProxyUriAddress, + OUT CHAR8 **EndPointUriAddress ); =20 /** --=20 2.36.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#94817): https://edk2.groups.io/g/devel/message/94817 Mute This Topic: https://groups.io/mt/94189616/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-