summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaloni Kasbekar <saloni.kasbekar@intel.com>2022-12-16 18:57:23 +0100
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2025-03-13 00:34:01 +0000
commit69b0bed49e391d48ad5920f7dda03f4fb34e1ae1 (patch)
tree832f57f458bde46cbd8add1535e3a4053a6ca8eb
parentcd397f16a5b74692a8438a65c613edced3a09263 (diff)
downloadedk2-69b0bed49e391d48ad5920f7dda03f4fb34e1ae1.zip
edk2-69b0bed49e391d48ad5920f7dda03f4fb34e1ae1.tar.gz
edk2-69b0bed49e391d48ad5920f7dda03f4fb34e1ae1.tar.bz2
Network/HttpBootDxe: Modify device path parser to detect Proxy URI node.
Update device path parser to detect device path with Proxy URI Implementation based on UEFI Specification v2.11 Section 24.7.3.1 Signed-off-by: Saloni Kasbekar <saloni.kasbekar@intel.com>
-rw-r--r--NetworkPkg/HttpBootDxe/HttpBootSupport.c154
-rw-r--r--NetworkPkg/HttpBootDxe/HttpBootSupport.h13
2 files changed, 122 insertions, 45 deletions
diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.c b/NetworkPkg/HttpBootDxe/HttpBootSupport.c
index 236ef25..9af6cf0 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootSupport.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootSupport.c
@@ -552,70 +552,144 @@ HttpBootCheckUriScheme (
}
/**
+ 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 path.
+
+ @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 == NULL) || (Uri == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ UriStrLength = DevicePathNodeLength (Node) - sizeof (EFI_DEVICE_PATH_PROTOCOL);
+
+ if (UriStrLength == 0) {
+ // Invalid URI, return.
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *Uri = AllocatePool (UriStrLength + 1);
+ if (*Uri == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ CopyMem (*Uri, Node->Uri, UriStrLength);
+ (*Uri)[UriStrLength] = '\0';
+
+ return EFI_SUCCESS;
+}
+
+/**
Get the URI address string from the input device path.
- Caller need to free the buffer in the UriAddress pointer.
+ Caller needs to free the buffers returned by this function.
- @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 device path.
+ @param[in] FilePath Pointer to the device path which contains a URI device path node.
+ @param[out] ProxyUriAddress The proxy URI address string extract from the device path (if it exists)
+ @param[out] EndPointUriAddress The endpoint URI address string for the endpoint host.
@retval EFI_SUCCESS The URI string is returned.
+ @retval EFI_INVALID_PARAMETER Parameters are NULL or device path is invalid.
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
**/
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 == NULL) {
+ EFI_STATUS Status;
+ EFI_DEVICE_PATH_PROTOCOL *Node[2];
+ EFI_DEVICE_PATH_PROTOCOL *TempNode;
+ BOOLEAN NodeIsUri[2];
+ UINTN Index;
+
+ if ((FilePath == NULL) ||
+ (ProxyUriAddress == NULL) ||
+ (EndPointUriAddress == NULL))
+ {
return EFI_INVALID_PARAMETER;
}
- *UriAddress = NULL;
+ *ProxyUriAddress = NULL;
+ *EndPointUriAddress = NULL;
+ ZeroMem (Node, sizeof (Node));
+ // Obtain last 2 device path nodes.
+ // Looking for sequences:
+ // 1) //....../Mac(...)[/Vlan(...)][/Wi-Fi(...)]/IPv6(...)[/Dns(...)]/Uri(ProxyServer)/Uri(EndPointServer/FilePath)
+ // 2) //....../Mac(...)[/Vlan(...)][/Wi-Fi(...)]/IPv6(...)[/Dns(...)]/Uri(EndPointServer/FilePath)
//
- // Extract the URI address from the FilePath
- //
- TempDevicePath = FilePath;
- while (!IsDevicePathEnd (TempDevicePath)) {
- if ((DevicePathType (TempDevicePath) == MESSAGING_DEVICE_PATH) &&
- (DevicePathSubType (TempDevicePath) == MSG_URI_DP))
- {
- UriDevicePath = (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 = DevicePathNodeLength (UriDevicePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL);
- if (UriStrLength == 0) {
- //
- // return a NULL UriAddress if it's a empty URI device path node.
- //
- break;
- }
-
- Uri = AllocatePool (UriStrLength + 1);
- if (Uri == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
+ // Expected:
+ // Node[1] - Uri(EndPointServer/FilePath)
+ // Node[0] - Either Uri(EndPointServer/FilePath) or other.
+ TempNode = FilePath;
+
+ while (!IsDevicePathEnd (TempNode)) {
+ Node[0] = Node[1];
+ Node[1] = TempNode;
+ TempNode = NextDevicePathNode (TempNode);
+ }
+
+ // Verify if device path nodes are of type MESSAGING + URI.
+ for (Index = 0; Index < 2; Index++) {
+ if (Node[Index] == NULL) {
+ NodeIsUri[Index] = FALSE;
+ } else {
+ NodeIsUri[Index] = ((DevicePathType (Node[Index]) == MESSAGING_DEVICE_PATH) &&
+ (DevicePathSubType (Node[Index]) == MSG_URI_DP));
+ }
+ }
- CopyMem (Uri, UriDevicePath->Uri, DevicePathNodeLength (UriDevicePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL));
- Uri[DevicePathNodeLength (UriDevicePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL)] = '\0';
+ // If exists, obtain endpoint URI string.
+ if (NodeIsUri[1]) {
+ Status = HttpBootUriFromDevicePath (
+ (URI_DEVICE_PATH *)Node[1],
+ EndPointUriAddress
+ );
- *UriAddress = Uri;
+ if (EFI_ERROR (Status)) {
+ return Status;
}
- TempDevicePath = NextDevicePathNode (TempDevicePath);
+ // If exists, obtain proxy URI string.
+ if (NodeIsUri[0]) {
+ Status = HttpBootUriFromDevicePath (
+ (URI_DEVICE_PATH *)Node[0],
+ ProxyUriAddress
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto ErrorExit;
+ }
+ }
}
return EFI_SUCCESS;
+
+ErrorExit:
+ ASSERT (*EndPointUriAddress != NULL);
+ FreePool (*EndPointUriAddress);
+ *EndPointUriAddress = NULL;
+
+ return Status;
}
/**
diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.h b/NetworkPkg/HttpBootDxe/HttpBootSupport.h
index 3698e55..5a46894 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.
- Caller need to free the buffer in the UriAddress pointer.
+ Caller needs to free the buffers returned by this function.
- @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 device path.
+ @param[in] FilePath Pointer to the device path which contains a URI device path node.
+ @param[out] ProxyUriAddress The proxy URI address string extract from the device path (if it exists)
+ @param[out] EndPointUriAddress The endpoint URI address string for the endpoint host.
@retval EFI_SUCCESS The URI string is returned.
+ @retval EFI_INVALID_PARAMETER Parameters are NULL or device path is invalid.
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
**/
EFI_STATUS
HttpBootParseFilePath (
- IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
- OUT CHAR8 **UriAddress
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
+ OUT CHAR8 **ProxyUriAddress,
+ OUT CHAR8 **EndPointUriAddress
);
/**