public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Jiaxin Wu <jiaxin.wu@intel.com>
To: edk2-devel@lists.01.org
Cc: Ye Ting <ting.ye@intel.com>, Fu Siyuan <siyuan.fu@intel.com>,
	Wu Jiaxin <jiaxin.wu@intel.com>
Subject: [Patch 4/4] NetworkPkg/HttpBootDxe: Update device path node to include DNS information
Date: Tue, 25 Jul 2017 20:12:45 +0800	[thread overview]
Message-ID: <1500984765-8040-5-git-send-email-jiaxin.wu@intel.com> (raw)
In-Reply-To: <1500984765-8040-1-git-send-email-jiaxin.wu@intel.com>

Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
---
 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/HttpBootDxe/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, EITHER EXPRESS OR IMPLIED.
 **/
 
 #include "HttpBootDxe.h"
 
 /**
-  Update the IP and URL device path node to include the boot resource information.
+  Update the device path node to include the boot resource information.
 
   @param[in]    Private            The pointer to the driver's private data.
 
   @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;
 
-  TmpDevicePath = NULL;
+  TmpIpDevicePath  = NULL;
+  TmpDnsDevicePath = NULL;
   
   //
   // Update the IP node with DHCP assigned information.
   //
   if (!Private->UsingIpv6) {
@@ -70,33 +72,69 @@ HttpBootUpdateDevicePath (
     CopyMem (&Node->Ipv6.LocalIpAddress, &Private->StationIp.v6, sizeof (EFI_IPv6_ADDRESS));
     CopyMem (&Node->Ipv6.RemoteIpAddress, &Private->ServerIp.v6, sizeof (EFI_IPv6_ADDRESS));
     CopyMem (&Node->Ipv6.GatewayIpAddress, &Private->GatewayIp.v6, sizeof (EFI_IPv6_ADDRESS));
   }
   
-  TmpDevicePath = AppendDevicePathNode (Private->ParentDevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node);
+  TmpIpDevicePath = AppendDevicePathNode (Private->ParentDevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node);
   FreePool (Node);
-  if (TmpDevicePath == NULL) {
+  if (TmpIpDevicePath == NULL) {
     return EFI_OUT_OF_RESOURCES;
   }
 
   //
+  // Update the DNS node with DNS server IP list if existed.
+  //
+  if (Private->DnsServerIp != NULL) {
+    Length = sizeof (EFI_DEVICE_PATH_PROTOCOL) + sizeof (Node->Dns.IsIPv6) + Private->DnsServerCount * sizeof (EFI_IP_ADDRESS);
+    Node = AllocatePool (Length);
+    if (Node == NULL) {
+      FreePool (TmpIpDevicePath);
+      return EFI_OUT_OF_RESOURCES;
+    }
+    Node->DevPath.Type    = MESSAGING_DEVICE_PATH;
+    Node->DevPath.SubType = MSG_DNS_DP;
+    SetDevicePathNodeLength (Node, Length);
+    Node->Dns.IsIPv6 = Private->UsingIpv6 ? 0x01 : 0x00;
+    CopyMem ((UINT8*) Node + sizeof (EFI_DEVICE_PATH_PROTOCOL) + sizeof (Node->Dns.IsIPv6), Private->DnsServerIp, Private->DnsServerCount * sizeof (EFI_IP_ADDRESS));
+    
+    TmpDnsDevicePath = AppendDevicePathNode (TmpIpDevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node);
+    FreePool (Node);
+    FreePool (TmpIpDevicePath);
+    TmpIpDevicePath = NULL;
+    if (TmpDnsDevicePath == NULL) {
+      return EFI_OUT_OF_RESOURCES;
+    }
+  }
+
+  //
   // Update the URI node with the boot file URI.
   //
   Length = sizeof (EFI_DEVICE_PATH_PROTOCOL) + AsciiStrSize (Private->BootFileUri);
   Node = AllocatePool (Length);
   if (Node == NULL) {
-    FreePool (TmpDevicePath);
+    if (TmpIpDevicePath != NULL) {
+      FreePool (TmpIpDevicePath);
+    }
+    if (TmpDnsDevicePath != NULL) {
+      FreePool (TmpDnsDevicePath);
+    }
     return EFI_OUT_OF_RESOURCES;
   }
   Node->DevPath.Type    = MESSAGING_DEVICE_PATH;
   Node->DevPath.SubType = MSG_URI_DP;
   SetDevicePathNodeLength (Node, Length);
   CopyMem ((UINT8*) Node + sizeof (EFI_DEVICE_PATH_PROTOCOL), Private->BootFileUri, AsciiStrSize (Private->BootFileUri));
-  
-  NewDevicePath = AppendDevicePathNode (TmpDevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node);
+
+  if (TmpDnsDevicePath != NULL) {
+    NewDevicePath = AppendDevicePathNode (TmpDnsDevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node);
+    FreePool (TmpDnsDevicePath);
+  } else {
+    ASSERT (TmpIpDevicePath != NULL);
+    NewDevicePath = AppendDevicePathNode (TmpIpDevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node);
+    FreePool (TmpIpDevicePath);
+  }
   FreePool (Node);
-  FreePool (TmpDevicePath);
   if (NewDevicePath == NULL) {
     return EFI_OUT_OF_RESOURCES;
   }
 
   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;
 
   ASSERT (Private != NULL);
   ASSERT (Private->SelectIndex != 0);
   SelectIndex = Private->SelectIndex - 1;
   ASSERT (SelectIndex < HTTP_BOOT_OFFER_MAX_NUM);
 
+  DnsServerIndex = 0;
+  
   Status = EFI_SUCCESS;
 
   //
   // SelectOffer contains the IP address configuration and name server configuration.
   // 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;
   }
 
-  //
-  // Configure the default DNS server if server assigned.
-  //
   if ((SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns) || 
       (SelectOffer->OfferType == HttpOfferTypeDhcpDns) ||
       (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns)) {
     Option = SelectOffer->OptList[HTTP_BOOT_DHCP4_TAG_INDEX_DNS_SERVER];
     ASSERT (Option != NULL);
+
+    //
+    // Record the Dns Server address list.
+    //
+    Private->DnsServerCount = (Option->Length) / sizeof (EFI_IPv4_ADDRESS);
+
+    Private->DnsServerIp = AllocateZeroPool (Private->DnsServerCount * sizeof (EFI_IP_ADDRESS));
+    if (Private->DnsServerIp == NULL) {
+      return EFI_OUT_OF_RESOURCES;
+    }
+
+    for (DnsServerIndex = 0; DnsServerIndex < Private->DnsServerCount; DnsServerIndex++) {
+      CopyMem (&(Private->DnsServerIp[DnsServerIndex].v4), &(((EFI_IPv4_ADDRESS *) Option->Data)[DnsServerIndex]), sizeof (EFI_IPv4_ADDRESS));
+    }
+    
+    //
+    // Configure the default DNS server if server assigned.
+    //    
     Status = HttpBootRegisterIp4Dns (
                Private,
                Option->Length,
                Option->Data
                );
     if (EFI_ERROR (Status)) {
+      FreePool (Private->DnsServerIp);
+      Private->DnsServerIp = NULL;
       return Status;
     }
   }
 
   //
@@ -233,13 +291,17 @@ HttpBootDhcp4ExtractUriInfo (
   //
   // All boot informations are valid here.
   //
 
   //
-  // Update the device path to include the IP and boot URI information.
+  // Update the device path to include the boot resource information.
   //
   Status = HttpBootUpdateDevicePath (Private);
+  if (EFI_ERROR (Status) && Private->DnsServerIp != NULL) {
+    FreePool (Private->DnsServerIp);
+    Private->DnsServerIp = NULL;
+  }
 
   return Status;
 }
 
 /**
@@ -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 != NULL);
   ASSERT (Private->SelectIndex != 0);
   SelectIndex = Private->SelectIndex - 1;
   ASSERT (SelectIndex < HTTP_BOOT_OFFER_MAX_NUM);
 
+  DnsServerIndex = 0;
+
   Status   = EFI_SUCCESS;
   HostName = NULL;
   //
   // SelectOffer contains the IP address configuration and name server configuration.
   // HttpOffer contains the boot file URL.
@@ -324,26 +389,41 @@ HttpBootDhcp6ExtractUriInfo (
   //
   Status = HttpBootSetIp6Gateway (Private);
   if (EFI_ERROR (Status)) {
     return Status;
   }
-  
-  //
-  // Configure the default DNS server if server assigned.
-  //
+
   if ((SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns) || 
       (SelectOffer->OfferType == HttpOfferTypeDhcpDns) ||
       (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns)) {
     Option = SelectOffer->OptList[HTTP_BOOT_DHCP6_IDX_DNS_SERVER];
     ASSERT (Option != NULL);
+
+    //
+    // Record the Dns Server address list.
+    //
+    Private->DnsServerCount = HTONS (Option->OpLen) / sizeof (EFI_IPv6_ADDRESS);
+
+    Private->DnsServerIp = AllocateZeroPool (Private->DnsServerCount * sizeof (EFI_IP_ADDRESS));
+    if (Private->DnsServerIp == NULL) {
+      return EFI_OUT_OF_RESOURCES;
+    }
+
+    for (DnsServerIndex = 0; DnsServerIndex < Private->DnsServerCount; DnsServerIndex++) {
+      CopyMem (&(Private->DnsServerIp[DnsServerIndex].v6), &(((EFI_IPv6_ADDRESS *) Option->Data)[DnsServerIndex]), sizeof (EFI_IPv6_ADDRESS));
+    }
+
+    //
+    // Configure the default DNS server if server assigned.
+    //
     Status = HttpBootSetIp6Dns (
                Private,
                HTONS (Option->OpLen),
                Option->Data
                );
     if (EFI_ERROR (Status)) {
-      return Status;
+      goto Error;
     }
   }
   
   //
   // Extract the HTTP server Ip frome URL. This is used to Check route table 
@@ -363,21 +443,26 @@ HttpBootDhcp6ExtractUriInfo (
                Private->BootFileUri,
                Private->BootFileUriParser,
                &HostName
                );
     if (EFI_ERROR (Status)) {
-      return Status;
+      goto Error;
     }
 
     HostNameSize = AsciiStrSize (HostName);
     HostNameStr = AllocateZeroPool (HostNameSize * sizeof (CHAR16));
     if (HostNameStr == NULL) {
       Status = EFI_OUT_OF_RESOURCES;
       goto Error;
     }
     
     AsciiStrToUnicodeStrS (HostName, HostNameStr, HostNameSize);
+
+    if (HostName != NULL) {
+      FreePool (HostName);
+    }
+    
     Status = HttpBootDns (Private, HostNameStr, &IpAddr);
     FreePool (HostNameStr);
     if (EFI_ERROR (Status)) {
       goto Error;
     }  
@@ -400,20 +485,25 @@ HttpBootDhcp6ExtractUriInfo (
   //
   // All boot informations are valid here.
   //
 
   //
-  // Update the device path to include the IP and boot URI information.
+  // Update the device path to include the boot resource information.
   //
   Status = HttpBootUpdateDevicePath (Private);
+  if (EFI_ERROR (Status)) {
+    goto Error;
+  }
+  
+  return Status;
 
 Error:
-  
-  if (HostName != NULL) {
-    FreePool (HostName);
+  if (Private->DnsServerIp != NULL) {
+    FreePool (Private->DnsServerIp);
+    Private->DnsServerIp = NULL;
   }
-    
+  
   return Status;
 }
 
 
 /**
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;
 
   //
   // 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.
 
-Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
 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 full text of the license may be found at
 http://opensource.org/licenses/bsd-license.php.                                          
@@ -463,10 +463,15 @@ HttpBootStop (
         HttpUrlFreeParser (Private->OfferBuffer[Index].Dhcp6.UriParser);
       }
     }
   }
 
+  if (Private->DnsServerIp != NULL) {
+    FreePool (Private->DnsServerIp);
+    Private->DnsServerIp = NULL;
+  }
+
   if (Private->FilePathUri!= NULL) {
     FreePool (Private->FilePathUri);
     HttpUrlFreeParser (Private->FilePathUriParser);
     Private->FilePathUri = NULL;
     Private->FilePathUriParser = NULL;
-- 
1.9.5.msysgit.1



  parent reply	other threads:[~2017-07-25 12:10 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-25 12:12 [Patch 0/4] Add DNS device path node Jiaxin Wu
2017-07-25 12:12 ` [Patch 1/4] MdePkg/DevicePath.h: Add DNS Device Path definition Jiaxin Wu
2017-07-25 12:12 ` [Patch 2/4] MdePkg/UefiDevicePathLib: Add DevPathFromTextDns and DevPathToTextDns libraries Jiaxin Wu
2017-07-26  0:42   ` Fu, Siyuan
2017-07-26  2:08     ` Wu, Jiaxin
2017-07-26  2:12       ` Fu, Siyuan
2017-07-26  2:29         ` Wu, Jiaxin
2017-07-26  3:00         ` Wu, Jiaxin
2017-07-25 12:12 ` [Patch 3/4] MdeModulePkg/UefiBootManagerLib: Support DNS device path description Jiaxin Wu
2017-07-25 12:12 ` Jiaxin Wu [this message]
2017-08-14  3:28 ` [Patch 0/4] Add DNS device path node Ye, Ting

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1500984765-8040-5-git-send-email-jiaxin.wu@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox