]> git.proxmox.com Git - mirror_edk2.git/commitdiff
NetworkPkg: Add dns support for target URL configuration in ISCSI.
authorZhang Lubo <lubo.zhang@intel.com>
Thu, 8 Dec 2016 11:26:24 +0000 (19:26 +0800)
committerJiaxin Wu <jiaxin.wu@intel.com>
Thu, 19 Jan 2017 03:31:57 +0000 (11:31 +0800)
v2:
*1. Add IScsiDnsIsConfigured function in IScsiSupported to check
attempt using DNS protocol or not.2. Fix wrongs typos in IScsiDns.c
and .uni file.3. define a macro for the length of target URL.4.
update the Copyright to 2017.

Add DNS support for target URL directly configuration in UI.

Besides, When we enable the option (Get target info via DHCP) ,
the dhcp server will return target info include the  rootpath,
like the format
"iscsi:"<servername>":"<protocol>":"<port>":"<LUN>":"<targetname>
According to the RFC 4173,the server name region is expressed as
IPv4(192.168.10.20 )or IPv6 ([2000:bbbb::3]) or domain name,
but currently we only support the IP address format.
To enable this feature, we can support both.

Another enhancement is that we can deal with the data received from
the iSCSI login response with an target redirection status,
in which contains the Target Address in the format
domainname[:port][,portal-group-tag] required by RFC 3720.

Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Zhang Lubo <lubo.zhang@intel.com>
Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
14 files changed:
NetworkPkg/IScsiDxe/IScsiConfig.c
NetworkPkg/IScsiDxe/IScsiConfigNVDataStruc.h
NetworkPkg/IScsiDxe/IScsiConfigStrings.uni
NetworkPkg/IScsiDxe/IScsiConfigVfr.vfr
NetworkPkg/IScsiDxe/IScsiDhcp.c
NetworkPkg/IScsiDxe/IScsiDhcp6.c
NetworkPkg/IScsiDxe/IScsiDns.c [new file with mode: 0644]
NetworkPkg/IScsiDxe/IScsiDns.h [new file with mode: 0644]
NetworkPkg/IScsiDxe/IScsiDriver.c
NetworkPkg/IScsiDxe/IScsiDxe.inf
NetworkPkg/IScsiDxe/IScsiImpl.h
NetworkPkg/IScsiDxe/IScsiMisc.c
NetworkPkg/IScsiDxe/IScsiMisc.h
NetworkPkg/IScsiDxe/IScsiProto.c

index 57571ad17b7d8c81fd892b327741fb730f4819d2..40ea75ae3a2941af06f43f29795a580c9718e956 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Helper functions for configuring or getting the parameters relating to iSCSI.\r
 \r
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -366,6 +366,7 @@ IScsiConvertAttemptConfigDataToIfrNvData (
   ISCSI_SESSION_CONFIG_NVDATA   *SessionConfigData;\r
   ISCSI_CHAP_AUTH_CONFIG_NVDATA *AuthConfigData;\r
   EFI_IP_ADDRESS                Ip;\r
+  BOOLEAN                       DnsMode;\r
 \r
   //\r
   // Normal session configuration parameters.\r
@@ -373,6 +374,7 @@ IScsiConvertAttemptConfigDataToIfrNvData (
   SessionConfigData                 = &Attempt->SessionConfigData;\r
   IfrNvData->Enabled                = SessionConfigData->Enabled;\r
   IfrNvData->IpMode                 = SessionConfigData->IpMode;\r
+  DnsMode                           = SessionConfigData->DnsMode;\r
 \r
   IfrNvData->InitiatorInfoFromDhcp  = SessionConfigData->InitiatorInfoFromDhcp;\r
   IfrNvData->TargetInfoFromDhcp     = SessionConfigData->TargetInfoFromDhcp;\r
@@ -385,12 +387,17 @@ IScsiConvertAttemptConfigDataToIfrNvData (
     IScsiIpToStr (&Ip, FALSE, IfrNvData->SubnetMask);\r
     CopyMem (&Ip.v4, &SessionConfigData->Gateway, sizeof (EFI_IPv4_ADDRESS));\r
     IScsiIpToStr (&Ip, FALSE, IfrNvData->Gateway);\r
-    CopyMem (&Ip.v4, &SessionConfigData->TargetIp, sizeof (EFI_IPv4_ADDRESS));\r
-    IScsiIpToStr (&Ip, FALSE, IfrNvData->TargetIp);\r
+    if (SessionConfigData->TargetIp.v4.Addr[0] != '\0') {\r
+      CopyMem (&Ip.v4, &SessionConfigData->TargetIp, sizeof (EFI_IPv4_ADDRESS));\r
+      IScsiIpToStr (&Ip, FALSE, IfrNvData->TargetIp);\r
+    }\r
+\r
   } else if (IfrNvData->IpMode == IP_MODE_IP6) {\r
     ZeroMem (IfrNvData->TargetIp, sizeof (IfrNvData->TargetIp));\r
-    IP6_COPY_ADDRESS (&Ip.v6, &SessionConfigData->TargetIp);\r
-    IScsiIpToStr (&Ip, TRUE, IfrNvData->TargetIp);\r
+    if (SessionConfigData->TargetIp.v6.Addr[0] != '\0') {\r
+      IP6_COPY_ADDRESS (&Ip.v6, &SessionConfigData->TargetIp);\r
+      IScsiIpToStr (&Ip, TRUE, IfrNvData->TargetIp);\r
+    }\r
   }\r
 \r
   AsciiStrToUnicodeStrS (\r
@@ -398,6 +405,15 @@ IScsiConvertAttemptConfigDataToIfrNvData (
     IfrNvData->TargetName,\r
     sizeof (IfrNvData->TargetName) / sizeof (IfrNvData->TargetName[0])\r
     );\r
+\r
+  if (DnsMode) {\r
+    AsciiStrToUnicodeStrS (\r
+      SessionConfigData->TargetUrl,\r
+      IfrNvData->TargetIp,\r
+      sizeof (IfrNvData->TargetIp) / sizeof (IfrNvData->TargetIp[0])\r
+      );\r
+  }\r
+\r
   IScsiLunToUnicodeStr (SessionConfigData->BootLun, IfrNvData->BootLun);\r
   IScsiConvertIsIdToString (IfrNvData->IsId, SessionConfigData->IsId);\r
 \r
@@ -559,14 +575,26 @@ IScsiConvertIfrNvDataToAttemptConfigData (
     // Validate target configuration if DHCP isn't deployed.\r
     //\r
     if (!Attempt->SessionConfigData.TargetInfoFromDhcp && Attempt->SessionConfigData.IpMode < IP_MODE_AUTOCONFIG) {\r
-      if (!IpIsUnicast (&Attempt->SessionConfigData.TargetIp, IfrNvData->IpMode)) {\r
-        CreatePopUp (\r
-          EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
-          &Key,\r
-          L"Target IP is invalid!",\r
-          NULL\r
-          );\r
-        return EFI_INVALID_PARAMETER;\r
+      if (!Attempt->SessionConfigData.DnsMode) {\r
+        if (!IpIsUnicast (&Attempt->SessionConfigData.TargetIp, IfrNvData->IpMode)) {\r
+          CreatePopUp (\r
+            EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
+            &Key,\r
+            L"Target IP is invalid!",\r
+            NULL\r
+            );\r
+          return EFI_INVALID_PARAMETER;\r
+        }\r
+      } else {\r
+        if (Attempt->SessionConfigData.TargetUrl[0] == '\0') {\r
+          CreatePopUp (\r
+            EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
+            &Key,\r
+            L"iSCSI target Url should not be NULL!",\r
+            NULL\r
+            );\r
+          return EFI_INVALID_PARAMETER;\r
+        }\r
       }\r
 \r
       //\r
@@ -2136,7 +2164,7 @@ IScsiFormCallback (
   ISCSI_FORM_CALLBACK_INFO    *Private;\r
   UINTN                       BufferSize;\r
   CHAR8                       *IScsiName;\r
-  CHAR8                       IpString[IP_STR_MAX_SIZE];\r
+  CHAR8                       IpString[ISCSI_NAME_MAX_SIZE];\r
   CHAR8                       LunString[ISCSI_LUN_STR_MAX_LEN];\r
   UINT64                      Lun;\r
   EFI_IP_ADDRESS              HostIp;\r
@@ -2335,14 +2363,8 @@ IScsiFormCallback (
     case KEY_IP_MODE:\r
       switch (Value->u8) {\r
       case IP_MODE_IP6:\r
-        ZeroMem (IfrNvData->TargetIp, sizeof (IfrNvData->TargetIp));\r
-        IScsiIpToStr (&Private->Current->SessionConfigData.TargetIp, TRUE, IfrNvData->TargetIp);\r
-        Private->Current->AutoConfigureMode = 0;\r
-        break;\r
-\r
       case IP_MODE_IP4:\r
         ZeroMem (IfrNvData->TargetIp, sizeof (IfrNvData->TargetIp));\r
-        IScsiIpToStr (&Private->Current->SessionConfigData.TargetIp, FALSE, IfrNvData->TargetIp);\r
         Private->Current->AutoConfigureMode = 0;\r
 \r
         break;\r
@@ -2408,15 +2430,15 @@ IScsiFormCallback (
     case KEY_TARGET_IP:\r
       UnicodeStrToAsciiStrS (IfrNvData->TargetIp, IpString, sizeof (IpString));\r
       Status = IScsiAsciiStrToIp (IpString, IfrNvData->IpMode, &HostIp);\r
-      if (EFI_ERROR (Status) || IP4_IS_LOCAL_BROADCAST (EFI_NTOHL(HostIp.v4)) || IP4_IS_UNSPECIFIED (EFI_NTOHL(HostIp.v4))) {\r
-        CreatePopUp (\r
-          EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
-          &Key,\r
-          L"Invalid IP address!",\r
-          NULL\r
-          );       \r
-        Status = EFI_INVALID_PARAMETER;\r
+      if (EFI_ERROR (Status) || !IpIsUnicast (&HostIp, IfrNvData->IpMode)) {\r
+      //\r
+      // The target is expressed in URL format or an invalid Ip address, just save.\r
+      //\r
+      Private->Current->SessionConfigData.DnsMode = TRUE;\r
+      ZeroMem (&Private->Current->SessionConfigData.TargetIp, sizeof (Private->Current->SessionConfigData.TargetIp));\r
+      UnicodeStrToAsciiStrS (IfrNvData->TargetIp, Private->Current->SessionConfigData.TargetUrl, ISCSI_NAME_MAX_SIZE);\r
       } else {\r
+        Private->Current->SessionConfigData.DnsMode = FALSE;\r
         CopyMem (&Private->Current->SessionConfigData.TargetIp, &HostIp, sizeof (HostIp));\r
       }\r
 \r
index 56ebb503c00b0cab130c97805be7f5718eea650f..5f22767644edf8276d78f9ccaf3d2cbb5451a62e 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Define NVData structures used by the iSCSI configuration component.\r
 \r
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -135,6 +135,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define ISID_CONFIGURABLE_MAX_LEN 12\r
 #define ISID_CONFIGURABLE_STORAGE 13\r
 \r
+///\r
+/// Macro used for target Url.\r
+///\r
+#define ISCSI_TARGET_URI_MIN_SIZE     0\r
+#define ISCSI_TARGET_URI_MAX_SIZE     255\r
+\r
 #pragma pack(1)\r
 typedef struct _ISCSI_CONFIG_IFR_NVDATA {\r
   CHAR16  InitiatorName[ISCSI_NAME_MAX_SIZE];\r
@@ -154,7 +160,7 @@ typedef struct _ISCSI_CONFIG_IFR_NVDATA {
   CHAR16  Gateway[IP4_STR_MAX_SIZE];\r
 \r
   CHAR16  TargetName[ISCSI_NAME_MAX_SIZE];\r
-  CHAR16  TargetIp[IP_STR_MAX_SIZE];\r
+  CHAR16  TargetIp[ISCSI_TARGET_URI_MAX_SIZE];\r
   UINT16  TargetPort;\r
   CHAR16  BootLun[ISCSI_LUN_STR_MAX_LEN];\r
 \r
index 7a80fab0ad265af4ca4e4604b3eb76b061858908..11e8b09f99d68c3f5b1e94209a5e12a7611cd711 100644 (file)
@@ -1,6 +1,6 @@
 // *++\r
 //\r
-// Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
+// Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
 // This program and the accompanying materials\r
 // are licensed and made available under the terms and conditions of the BSD License\r
 // which accompanies this distribution.  The full text of the license may be found at\r
@@ -63,7 +63,8 @@
 #string STR_ISCSI_IP_ADDRESS_HELP       #language en-US "Enter IP address in dotted-decimal notation."\r
 #string STR_ISCSI_TARGET_NAME           #language en-US "  Target Name"\r
 #string STR_ISCSI_TARGET_NAME_HELP      #language en-US "The worldwide unique name of the target. Only iqn. format is accepted."\r
-#string STR_ISCSI_TARGET_IP_ADDRESS     #language en-US "  Target IP Address"\r
+#string STR_ISCSI_TARGET_ADDRESS        #language en-US "  Target Address"\r
+#string STR_ISCSI_TARGET_ADDRESS_HELP   #language en-US "Enter Target address in IPv4,IPv6 or URL format.You need to configure DNS server address in advance if input a URL string."\r
 #string STR_ISCSI_TARGET_PORT           #language en-US "  Target Port"\r
 #string STR_ISCSI_BOOT_LUN              #language en-US "  Boot LUN"\r
 #string STR_ISCSI_BOOT_LUN_HELP         #language en-US "Hexadecimal representation of the LU number. Examples are: 4752-3A4F-6b7e-2F99, 6734-9-156f-127, 4186-9"\r
index db77c0f2156158fc37d853a889d77fe470128d6b..c469a78cdabfa606dca32f8962d20ae18e68d863 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   VFR file used by the iSCSI configuration component.\r
   \r
-Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -249,12 +249,12 @@ formset
     endstring;\r
 \r
     string  varid   = ISCSI_CONFIG_IFR_NVDATA.TargetIp,\r
-            prompt  = STRING_TOKEN(STR_ISCSI_TARGET_IP_ADDRESS),\r
-            help    = STRING_TOKEN(STR_ISCSI_IP_ADDRESS_HELP),\r
+            prompt  = STRING_TOKEN(STR_ISCSI_TARGET_ADDRESS),\r
+            help    = STRING_TOKEN(STR_ISCSI_TARGET_ADDRESS_HELP),\r
             flags   = INTERACTIVE,\r
             key     = KEY_TARGET_IP,\r
-            minsize = IP_MIN_SIZE,\r
-            maxsize = IP_MAX_SIZE,\r
+            minsize = ISCSI_TARGET_URI_MIN_SIZE,\r
+            maxsize = ISCSI_TARGET_URI_MAX_SIZE,\r
     endstring;\r
 \r
     numeric varid   = ISCSI_CONFIG_IFR_NVDATA.TargetPort,\r
index 0e42805c03d52cedb9a531a2446809368e417144..43ae50bbffacaf23f1d41f0d42034a7fda0255cc 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   iSCSI DHCP4 related configuration routines.\r
 \r
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -123,11 +123,24 @@ IScsiDhcpExtractRootPath (
     IpMode = ConfigData->AutoConfigureMode;\r
   }\r
 \r
-  Status = IScsiAsciiStrToIp (Field->Str, IpMode, &Ip);\r
-  CopyMem (&ConfigNvData->TargetIp, &Ip, sizeof (EFI_IP_ADDRESS));\r
+  //\r
+  // Server name is expressed as domain name, just save it.\r
+  //\r
+  if ((!NET_IS_DIGIT (*(Field->Str))) && (*(Field->Str) != '[')) {\r
+    ConfigNvData->DnsMode = TRUE;\r
+    if (Field->Len > sizeof (ConfigNvData->TargetUrl)) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    CopyMem (&ConfigNvData->TargetUrl, Field->Str, Field->Len);\r
+    ConfigNvData->TargetUrl[Field->Len + 1] = '\0';\r
+  } else {\r
+    ZeroMem(ConfigNvData->TargetUrl, sizeof (ConfigNvData->TargetUrl));\r
+    Status = IScsiAsciiStrToIp (Field->Str, IpMode, &Ip);\r
+    CopyMem (&ConfigNvData->TargetIp, &Ip, sizeof (EFI_IP_ADDRESS));\r
 \r
-  if (EFI_ERROR (Status)) {\r
-    goto ON_EXIT;\r
+    if (EFI_ERROR (Status)) {\r
+      goto ON_EXIT;\r
+    }\r
   }\r
   //\r
   // Check the protocol type.\r
index 0cd0bd88032fa01f7da81f570a6e8889c6b6370a..d3535d57cb5a2eb646118f7c447400a75b2cfa20 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   iSCSI DHCP6 related configuration routines.\r
 \r
-Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -150,13 +150,26 @@ IScsiDhcp6ExtractRootPath (
     IpMode = ConfigData->AutoConfigureMode;\r
   }\r
 \r
-  Status = IScsiAsciiStrToIp (Field->Str, IpMode, &Ip);\r
-  CopyMem (&ConfigNvData->TargetIp, &Ip, sizeof (EFI_IP_ADDRESS));\r
-\r
+  //\r
+  // Server name is expressed as domain name, just save it.\r
+  //\r
+  if ((!NET_IS_DIGIT (*(Field->Str))) && (*(Field->Str) != '[')) {\r
+    ConfigNvData->DnsMode = TRUE;\r
+    if (Field->Len > sizeof (ConfigNvData->TargetUrl)) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    CopyMem (&ConfigNvData->TargetUrl, Field->Str, Field->Len);\r
+    ConfigNvData->TargetUrl[Field->Len + 1] = '\0';\r
+  } else {\r
+    ZeroMem(&ConfigNvData->TargetUrl, sizeof (ConfigNvData->TargetUrl));\r
+    Status = IScsiAsciiStrToIp (Field->Str, IpMode, &Ip);\r
+    CopyMem (&ConfigNvData->TargetIp, &Ip, sizeof (EFI_IP_ADDRESS));\r
 \r
-  if (EFI_ERROR (Status)) {\r
-    goto ON_EXIT;\r
+    if (EFI_ERROR (Status)) {\r
+      goto ON_EXIT;\r
+    }\r
   }\r
+\r
   //\r
   // Check the protocol type.\r
   //\r
diff --git a/NetworkPkg/IScsiDxe/IScsiDns.c b/NetworkPkg/IScsiDxe/IScsiDns.c
new file mode 100644 (file)
index 0000000..0ddfcbd
--- /dev/null
@@ -0,0 +1,435 @@
+/** @file\r
+ Perform DNS resolution based on UEFI DNS protocols.\r
+\r
+Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "IScsiImpl.h"\r
+\r
+/**\r
+  Notify the callback function when an event is triggered.\r
+\r
+  @param[in]  Event           The triggered event.\r
+  @param[in]  Context         The opaque parameter to the function.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+IScsiCommonNotify (\r
+  IN EFI_EVENT           Event,\r
+  IN VOID                *Context\r
+  )\r
+{\r
+  *((BOOLEAN *) Context) = TRUE;\r
+}\r
+\r
+/**\r
+  Retrieve the host address using the EFI_DNS4_PROTOCOL.\r
+\r
+  @param[in]  Image               The handle of the driver image.\r
+  @param[in]  Controller          The handle of the controller.\r
+  @param[in, out]  NvData         The Session config data structure.\r
+\r
+  @retval EFI_SUCCESS             Operation succeeded.\r
+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate needed resources.\r
+  @retval EFI_DEVICE_ERROR        An unexpected network error occurred.\r
+  @retval Others                  Other errors as indicated.\r
+\r
+**/\r
+EFI_STATUS\r
+IScsiDns4 (\r
+  IN     EFI_HANDLE                      Image,\r
+  IN     EFI_HANDLE                      Controller,\r
+  IN OUT ISCSI_SESSION_CONFIG_NVDATA     *NvData\r
+  )\r
+{\r
+  EFI_STATUS                      Status;\r
+  EFI_DNS4_PROTOCOL               *Dns4;\r
+  EFI_DNS4_CONFIG_DATA            Dns4CfgData;\r
+  EFI_DNS4_COMPLETION_TOKEN       Token;\r
+  BOOLEAN                         IsDone;\r
+  EFI_HANDLE                      Dns4Handle;\r
+  EFI_IP4_CONFIG2_PROTOCOL        *Ip4Config2;\r
+  EFI_IPv4_ADDRESS                *DnsServerList;\r
+  UINTN                           DnsServerListCount;\r
+  UINTN                           DataSize;\r
+  CHAR16                          *HostName;\r
+\r
+  DnsServerList      = NULL;\r
+  DnsServerListCount = 0;\r
+  Dns4Handle         = NULL;\r
+  Dns4               = NULL;\r
+  ZeroMem (&Token, sizeof (EFI_DNS4_COMPLETION_TOKEN));\r
+\r
+  //\r
+  // Get DNS server list from EFI IPv4 Configuration II protocol.\r
+  //\r
+  Status = gBS->HandleProtocol (Controller, &gEfiIp4Config2ProtocolGuid, (VOID **) &Ip4Config2);\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Get the required size.\r
+    //\r
+    DataSize = 0;\r
+    Status   = Ip4Config2->GetData (Ip4Config2, Ip4Config2DataTypeDnsServer, &DataSize, NULL);\r
+    if (Status == EFI_BUFFER_TOO_SMALL) {\r
+      DnsServerList = AllocatePool (DataSize);\r
+      if (DnsServerList == NULL) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+\r
+      Status   = Ip4Config2->GetData (Ip4Config2, Ip4Config2DataTypeDnsServer, &DataSize, DnsServerList);\r
+      if (EFI_ERROR (Status)) {\r
+        FreePool (DnsServerList);\r
+        DnsServerList = NULL;\r
+      } else {\r
+        DnsServerListCount = DataSize / sizeof (EFI_IPv4_ADDRESS);\r
+      }\r
+    }\r
+  }\r
+\r
+\r
+  //\r
+  // Create a DNS child instance and get the protocol.\r
+  //\r
+  Status = NetLibCreateServiceChild (\r
+             Controller,\r
+             Image,\r
+             &gEfiDns4ServiceBindingProtocolGuid,\r
+             &Dns4Handle\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Exit;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  Dns4Handle,\r
+                  &gEfiDns4ProtocolGuid,\r
+                  (VOID **) &Dns4,\r
+                  Image,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Exit;\r
+  }\r
+\r
+  //\r
+  // Configure DNS4 instance for the DNS server address and protocol.\r
+  //\r
+  ZeroMem (&Dns4CfgData, sizeof (Dns4CfgData));\r
+  Dns4CfgData.DnsServerListCount = DnsServerListCount;\r
+  Dns4CfgData.DnsServerList      = DnsServerList;\r
+  Dns4CfgData.EnableDnsCache     = TRUE;\r
+  IP4_COPY_ADDRESS (&Dns4CfgData.StationIp, &NvData->LocalIp);\r
+  IP4_COPY_ADDRESS (&Dns4CfgData.SubnetMask, &NvData->SubnetMask);\r
+  Dns4CfgData.Protocol           = EFI_IP_PROTO_UDP;\r
+  Status = Dns4->Configure (\r
+                   Dns4,\r
+                   &Dns4CfgData\r
+                   );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Exit;\r
+  }\r
+\r
+  //\r
+  // Create event to set the is done flag when name resolution is finished.\r
+  //\r
+  ZeroMem (&Token, sizeof (Token));\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  IScsiCommonNotify,\r
+                  &IsDone,\r
+                  &Token.Event\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Exit;\r
+  }\r
+\r
+  //\r
+  // Start asynchronous name resolution.\r
+  //\r
+  Token.Status = EFI_NOT_READY;\r
+  IsDone       = FALSE;\r
+\r
+  HostName = (CHAR16 *) AllocateZeroPool (ISCSI_NAME_MAX_SIZE);\r
+  if (HostName == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  AsciiStrToUnicodeStrS (\r
+    NvData->TargetUrl,\r
+    HostName,\r
+    ISCSI_NAME_MAX_SIZE\r
+    );\r
+\r
+  Status = Dns4->HostNameToIp (Dns4, HostName, &Token);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Exit;\r
+  }\r
+\r
+  while (!IsDone) {\r
+    Dns4->Poll (Dns4);\r
+  }\r
+\r
+  //\r
+  // Name resolution is done, check result.\r
+  //\r
+  Status = Token.Status;\r
+  if (!EFI_ERROR (Status)) {\r
+    if (Token.RspData.H2AData == NULL) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto Exit;\r
+    }\r
+    if (Token.RspData.H2AData->IpCount == 0 || Token.RspData.H2AData->IpList == NULL) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto Exit;\r
+    }\r
+    //\r
+    // We just return the first IP address from DNS protocol.\r
+    //\r
+    IP4_COPY_ADDRESS (&NvData->TargetIp.v4, Token.RspData.H2AData->IpList);\r
+    Status = EFI_SUCCESS;\r
+  }\r
+\r
+Exit:\r
+\r
+  if (Token.Event != NULL) {\r
+    gBS->CloseEvent (Token.Event);\r
+  }\r
+  if (Token.RspData.H2AData != NULL) {\r
+    if (Token.RspData.H2AData->IpList != NULL) {\r
+      FreePool (Token.RspData.H2AData->IpList);\r
+    }\r
+    FreePool (Token.RspData.H2AData);\r
+  }\r
+\r
+  if (Dns4 != NULL) {\r
+    Dns4->Configure (Dns4, NULL);\r
+\r
+    gBS->CloseProtocol (\r
+           Dns4Handle,\r
+           &gEfiDns4ProtocolGuid,\r
+           Image,\r
+           Controller\r
+           );\r
+  }\r
+\r
+  if (Dns4Handle != NULL) {\r
+    NetLibDestroyServiceChild (\r
+      Controller,\r
+      Image,\r
+      &gEfiDns4ServiceBindingProtocolGuid,\r
+      Dns4Handle\r
+      );\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Retrieve the host address using the EFI_DNS6_PROTOCOL.\r
+\r
+  @param[in]  Image               The handle of the driver image.\r
+  @param[in]  Controller          The handle of the controller.\r
+  @param[in, out]  NvData         The Session config data structure.\r
+\r
+  @retval EFI_SUCCESS             Operation succeeded.\r
+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate needed resources.\r
+  @retval EFI_DEVICE_ERROR        An unexpected network error occurred.\r
+  @retval Others                  Other errors as indicated.\r
+\r
+**/\r
+EFI_STATUS\r
+IScsiDns6 (\r
+  IN     EFI_HANDLE                      Image,\r
+  IN     EFI_HANDLE                      Controller,\r
+  IN OUT ISCSI_SESSION_CONFIG_NVDATA     *NvData\r
+  )\r
+{\r
+  EFI_STATUS                      Status;\r
+  EFI_DNS6_PROTOCOL               *Dns6;\r
+  EFI_DNS6_CONFIG_DATA            Dns6ConfigData;\r
+  EFI_DNS6_COMPLETION_TOKEN       Token;\r
+  EFI_HANDLE                      Dns6Handle;\r
+  EFI_IP6_CONFIG_PROTOCOL         *Ip6Config;\r
+  EFI_IPv6_ADDRESS                *DnsServerList;\r
+  UINTN                           DnsServerListCount;\r
+  UINTN                           DataSize;\r
+  BOOLEAN                         IsDone;\r
+  CHAR16                          *HostName;\r
+\r
+  DnsServerList       = NULL;\r
+  DnsServerListCount  = 0;\r
+  Dns6                = NULL;\r
+  Dns6Handle          = NULL;\r
+  ZeroMem (&Token, sizeof (EFI_DNS6_COMPLETION_TOKEN));\r
+\r
+  //\r
+  // Get DNS server list from EFI IPv6 Configuration protocol.\r
+  //\r
+  Status = gBS->HandleProtocol (Controller, &gEfiIp6ConfigProtocolGuid, (VOID **) &Ip6Config);\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Get the required size.\r
+    //\r
+    DataSize = 0;\r
+    Status = Ip6Config->GetData (Ip6Config, Ip6ConfigDataTypeDnsServer, &DataSize, NULL);\r
+    if (Status == EFI_BUFFER_TOO_SMALL) {\r
+      DnsServerList = AllocatePool (DataSize);\r
+      if (DnsServerList == NULL) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+\r
+      Status = Ip6Config->GetData (Ip6Config, Ip6ConfigDataTypeDnsServer, &DataSize, DnsServerList);\r
+      if (EFI_ERROR (Status)) {\r
+        FreePool (DnsServerList);\r
+        DnsServerList = NULL;\r
+      } else {\r
+        DnsServerListCount = DataSize / sizeof (EFI_IPv6_ADDRESS);\r
+      }\r
+    }\r
+  }\r
+\r
+  //\r
+  // Create a DNSv6 child instance and get the protocol.\r
+  //\r
+  Status = NetLibCreateServiceChild (\r
+             Controller,\r
+             Image,\r
+             &gEfiDns6ServiceBindingProtocolGuid,\r
+             &Dns6Handle\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Exit;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  Dns6Handle,\r
+                  &gEfiDns6ProtocolGuid,\r
+                  (VOID **) &Dns6,\r
+                  Image,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Exit;\r
+  }\r
+\r
+  //\r
+  // Configure DNS6 instance for the DNS server address and protocol.\r
+  //\r
+  ZeroMem (&Dns6ConfigData, sizeof (EFI_DNS6_CONFIG_DATA));\r
+  Dns6ConfigData.DnsServerCount = (UINT32)DnsServerListCount;\r
+  Dns6ConfigData.DnsServerList  = DnsServerList;\r
+  Dns6ConfigData.EnableDnsCache = TRUE;\r
+  Dns6ConfigData.Protocol       = EFI_IP_PROTO_UDP;\r
+  Status = Dns6->Configure (\r
+                   Dns6,\r
+                   &Dns6ConfigData\r
+                   );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Exit;\r
+  }\r
+\r
+  Token.Status = EFI_NOT_READY;\r
+  IsDone       = FALSE;\r
+  //\r
+  // Create event to set the  IsDone flag when name resolution is finished.\r
+  //\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  IScsiCommonNotify,\r
+                  &IsDone,\r
+                  &Token.Event\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Exit;\r
+  }\r
+\r
+  //\r
+  // Start asynchronous name resolution.\r
+  //\r
+  HostName = (CHAR16 *) AllocateZeroPool (ISCSI_NAME_MAX_SIZE);\r
+  if (HostName == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  AsciiStrToUnicodeStrS (\r
+    NvData->TargetUrl,\r
+    HostName,\r
+    ISCSI_NAME_MAX_SIZE\r
+    );\r
+  Status = Dns6->HostNameToIp (Dns6, HostName, &Token);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Exit;\r
+  }\r
+\r
+  while (!IsDone) {\r
+    Dns6->Poll (Dns6);\r
+  }\r
+\r
+  //\r
+  // Name resolution is done, check result.\r
+  //\r
+  Status = Token.Status;\r
+  if (!EFI_ERROR (Status)) {\r
+    if (Token.RspData.H2AData == NULL) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto Exit;\r
+    }\r
+    if (Token.RspData.H2AData->IpCount == 0 || Token.RspData.H2AData->IpList == NULL) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto Exit;\r
+    }\r
+    //\r
+    // We just return the first IPv6 address from DNS protocol.\r
+    //\r
+    IP6_COPY_ADDRESS (&NvData->TargetIp.v6, Token.RspData.H2AData->IpList);\r
+    Status = EFI_SUCCESS;\r
+  }\r
+\r
+Exit:\r
+\r
+  if (Token.Event != NULL) {\r
+    gBS->CloseEvent (Token.Event);\r
+  }\r
+  if (Token.RspData.H2AData != NULL) {\r
+    if (Token.RspData.H2AData->IpList != NULL) {\r
+      FreePool (Token.RspData.H2AData->IpList);\r
+    }\r
+    FreePool (Token.RspData.H2AData);\r
+  }\r
+\r
+  if (Dns6 != NULL) {\r
+    Dns6->Configure (Dns6, NULL);\r
+\r
+    gBS->CloseProtocol (\r
+           Dns6Handle,\r
+           &gEfiDns6ProtocolGuid,\r
+           Image,\r
+           Controller\r
+           );\r
+  }\r
+\r
+  if (Dns6Handle != NULL) {\r
+    NetLibDestroyServiceChild (\r
+      Controller,\r
+      Image,\r
+      &gEfiDns6ServiceBindingProtocolGuid,\r
+      Dns6Handle\r
+      );\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
diff --git a/NetworkPkg/IScsiDxe/IScsiDns.h b/NetworkPkg/IScsiDxe/IScsiDns.h
new file mode 100644 (file)
index 0000000..0b7ff86
--- /dev/null
@@ -0,0 +1,59 @@
+/** @file\r
+ The header file of routines for IScsi driver to perform DNS\r
+ resolution based on UEFI DNS protocols.\r
+\r
+Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef _ISCSI_DNS_H_\r
+#define _ISCSI_DNS_H_\r
+\r
+/**\r
+  Retrieve the host address using the EFI_DNS4_PROTOCOL.\r
+\r
+  @param[in]  Image               The handle of the driver image.\r
+  @param[in]  Controller          The handle of the controller.\r
+  @param[in, out]  NvData         The Session config data structure.\r
+\r
+  @retval EFI_SUCCESS             Operation succeeded.\r
+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate needed resources.\r
+  @retval EFI_DEVICE_ERROR        An unexpected network error occurred.\r
+  @retval Others                  Other errors as indicated.\r
+\r
+**/\r
+EFI_STATUS\r
+IScsiDns4 (\r
+  IN     EFI_HANDLE                      Image,\r
+  IN     EFI_HANDLE                      Controller,\r
+  IN OUT ISCSI_SESSION_CONFIG_NVDATA     *NvData\r
+  );\r
+\r
+/**\r
+  Retrieve the host address using the EFI_DNS6_PROTOCOL.\r
+\r
+  @param[in]  Image               The handle of the driver image.\r
+  @param[in]  Controller          The handle of the controller.\r
+  @param[in, out]  NvData         The Session config data structure.\r
+\r
+  @retval EFI_SUCCESS             Operation succeeded.\r
+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate needed resources.\r
+  @retval EFI_DEVICE_ERROR        An unexpected network error occurred.\r
+  @retval Others                  Other errors as indicated.\r
+\r
+**/\r
+EFI_STATUS\r
+IScsiDns6 (\r
+  IN     EFI_HANDLE                      Image,\r
+  IN     EFI_HANDLE                      Controller,\r
+  IN OUT ISCSI_SESSION_CONFIG_NVDATA     *NvData\r
+  );\r
+\r
+#endif
\ No newline at end of file
index ac10fa26d1b94d5a142eee72841115f08007585b..78c93ba66ca9dad6ca18d5712e8eced27908abbd 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The entry point of IScsi driver.\r
 \r
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -252,15 +252,19 @@ IScsiSupported (
   EFI_GUID                  *IScsiServiceBindingGuid;\r
   EFI_GUID                  *TcpServiceBindingGuid;\r
   EFI_GUID                  *DhcpServiceBindingGuid;\r
+  EFI_GUID                  *DnsServiceBindingGuid;\r
 \r
   if (IpVersion == IP_VERSION_4) {\r
     IScsiServiceBindingGuid  = &gIScsiV4PrivateGuid;\r
     TcpServiceBindingGuid    = &gEfiTcp4ServiceBindingProtocolGuid;\r
     DhcpServiceBindingGuid   = &gEfiDhcp4ServiceBindingProtocolGuid;\r
+    DnsServiceBindingGuid    = &gEfiDns4ServiceBindingProtocolGuid;\r
+\r
   } else {\r
     IScsiServiceBindingGuid  = &gIScsiV6PrivateGuid;\r
     TcpServiceBindingGuid    = &gEfiTcp6ServiceBindingProtocolGuid;\r
     DhcpServiceBindingGuid   = &gEfiDhcp6ServiceBindingProtocolGuid;\r
+    DnsServiceBindingGuid    = &gEfiDns6ServiceBindingProtocolGuid;\r
   }\r
 \r
   Status = gBS->OpenProtocol (\r
@@ -305,7 +309,21 @@ IScsiSupported (
       return EFI_UNSUPPORTED;\r
     }\r
   }\r
-  \r
+\r
+  if (IScsiDnsIsConfigured (ControllerHandle)) {\r
+    Status = gBS->OpenProtocol (\r
+                    ControllerHandle,\r
+                    DnsServiceBindingGuid,\r
+                    NULL,\r
+                    This->DriverBindingHandle,\r
+                    ControllerHandle,\r
+                    EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+  }\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
index 89521209b7cff3a2f6067637365a685a338711eb..699ffd1103238ab63d3df5d3cefb3214c797b1df 100644 (file)
@@ -4,7 +4,7 @@
 #  The iSCSI driver provides iSCSI service in the preboot environment and supports\r
 #  booting over iSCSI.\r
 #                                                    \r
-# Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution.  The full text of the license may be found at\r
@@ -50,6 +50,8 @@
   IScsiDhcp.h\r
   IScsiDhcp6.c\r
   IScsiDhcp6.h\r
+  IScsiDns.c\r
+  IScsiDns.h\r
   IScsiDriver.c\r
   IScsiDriver.h\r
   IScsiExtScsiPassThru.c\r
   gEfiAcpiTableProtocolGuid                     ## SOMETIMES_CONSUMES ## SystemTable\r
   gEfiDriverBindingProtocolGuid                 ## SOMETIMES_PRODUCES\r
   gEfiPciIoProtocolGuid                         ## SOMETIMES_CONSUMES\r
-  gEfiDhcp4ProtocolGuid                         ## TO_START\r
-  gEfiDhcp6ProtocolGuid                         ## TO_START  \r
-  gEfiDhcp4ServiceBindingProtocolGuid           ## TO_START\r
-  gEfiDhcp6ServiceBindingProtocolGuid           ## TO_START  \r
+  gEfiDhcp4ProtocolGuid                         ## SOMETIMES_CONSUMES\r
+  gEfiDhcp6ProtocolGuid                         ## SOMETIMES_CONSUMES\r
+  gEfiDhcp4ServiceBindingProtocolGuid           ## SOMETIMES_CONSUMES\r
+  gEfiDhcp6ServiceBindingProtocolGuid           ## SOMETIMES_CONSUMES\r
+  gEfiDns4ServiceBindingProtocolGuid            ## SOMETIMES_CONSUMES\r
+  gEfiDns4ProtocolGuid                          ## SOMETIMES_CONSUMES\r
+  gEfiDns6ServiceBindingProtocolGuid            ## SOMETIMES_CONSUMES\r
+  gEfiDns6ProtocolGuid                          ## SOMETIMES_CONSUMES\r
+  gEfiIp4Config2ProtocolGuid                    ## SOMETIMES_CONSUMES\r
+  gEfiIp6ConfigProtocolGuid                     ## SOMETIMES_CONSUMES\r
   gEfiTcp4ProtocolGuid                          ## TO_START\r
-  gEfiTcp6ProtocolGuid                          ## TO_START  \r
+  gEfiTcp6ProtocolGuid                          ## TO_START\r
   gEfiTcp4ServiceBindingProtocolGuid            ## TO_START\r
-  gEfiTcp6ServiceBindingProtocolGuid            ## TO_START  \r
+  gEfiTcp6ServiceBindingProtocolGuid            ## TO_START\r
   gEfiExtScsiPassThruProtocolGuid               ## BY_START\r
   gEfiHiiConfigAccessProtocolGuid               ## PRODUCES\r
   ## TO_START\r
index af468719c53d6cab29b9cb81985519fd438b79c8..741c49784adee4db83f318cc05b1149b3cfb845c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The shared head file for iSCSI driver.\r
 \r
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -28,8 +28,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Protocol/Ip6.h>\r
 #include <Protocol/Dhcp4.h>\r
 #include <Protocol/Dhcp6.h>\r
+#include <Protocol/Dns4.h>\r
+#include <Protocol/Dns6.h>\r
 #include <Protocol/Tcp4.h>\r
 #include <Protocol/Tcp6.h>\r
+#include <Protocol/Ip4Config2.h>\r
+#include <Protocol/Ip6Config.h>\r
 \r
 #include <Protocol/AuthenticationInfo.h>\r
 #include <Protocol/IScsiInitiatorName.h>\r
@@ -62,8 +66,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include "IScsiCHAP.h"\r
 #include "IScsiDhcp.h"\r
 #include "IScsiDhcp6.h"\r
+\r
 #include "IScsiIbft.h"\r
 #include "IScsiMisc.h"\r
+#include "IScsiDns.h"\r
 #include "IScsiConfig.h"\r
 \r
 #define ISCSI_AUTH_INITIAL        0\r
index 11a80f2e10e455d8bb707bc71f835918d2265f15..e8e8f9c9efa1e0a77dfaac3498154f49aa077d57 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Miscellaneous routines for iSCSI driver.\r
 \r
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -1001,6 +1001,94 @@ IScsiDhcpIsConfigured (
   return FALSE;\r
 }\r
 \r
+/**\r
+  Check wheather the Controller handle is configured to use DNS protocol.\r
+\r
+  @param[in]  Controller           The handle of the controller.\r
+  \r
+  @retval TRUE                     The handle of the controller need the Dns protocol.\r
+  @retval FALSE                    The handle of the controller does not need the Dns protocol.\r
+  \r
+**/\r
+BOOLEAN\r
+IScsiDnsIsConfigured (\r
+  IN EFI_HANDLE  Controller\r
+  )\r
+{\r
+  ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptTmp;\r
+  UINT8                       *AttemptConfigOrder;\r
+  UINTN                       AttemptConfigOrderSize;\r
+  UINTN                       Index;\r
+  EFI_STATUS                  Status;\r
+  EFI_MAC_ADDRESS             MacAddr;\r
+  UINTN                       HwAddressSize;\r
+  UINT16                      VlanId;\r
+  CHAR16                      MacString[ISCSI_MAX_MAC_STRING_LEN];\r
+  CHAR16                      AttemptName[ISCSI_NAME_IFR_MAX_SIZE];\r
+  \r
+  AttemptConfigOrder = IScsiGetVariableAndSize (\r
+                         L"AttemptOrder",\r
+                         &gIScsiConfigGuid,\r
+                         &AttemptConfigOrderSize\r
+                         );\r
+  if (AttemptConfigOrder == NULL || AttemptConfigOrderSize == 0) {\r
+    return FALSE;\r
+  }\r
+  \r
+  //\r
+  // Get MAC address of this network device.\r
+  //\r
+  Status = NetLibGetMacAddress (Controller, &MacAddr, &HwAddressSize);\r
+  if(EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  }\r
+  //\r
+  // Get VLAN ID of this network device.\r
+  //\r
+  VlanId = NetLibGetVlanId (Controller);\r
+  IScsiMacAddrToStr (&MacAddr, (UINT32) HwAddressSize, VlanId, MacString);\r
+  \r
+  for (Index = 0; Index < AttemptConfigOrderSize / sizeof (UINT8); Index++) {\r
+    UnicodeSPrint (\r
+      AttemptName,\r
+      (UINTN) 128,\r
+      L"%s%d",\r
+      MacString,\r
+      (UINTN) AttemptConfigOrder[Index]\r
+      );\r
+    Status = GetVariable2 (\r
+               AttemptName,\r
+               &gEfiIScsiInitiatorNameProtocolGuid,\r
+               (VOID**)&AttemptTmp,\r
+               NULL\r
+               );\r
+    if(AttemptTmp == NULL || EFI_ERROR (Status)) {\r
+      continue;\r
+    }\r
+    \r
+    ASSERT (AttemptConfigOrder[Index] == AttemptTmp->AttemptConfigIndex);\r
+\r
+    if (AttemptTmp->SessionConfigData.Enabled == ISCSI_DISABLED) {\r
+      FreePool (AttemptTmp);\r
+      continue;\r
+    }\r
+    \r
+    if (AttemptTmp->SessionConfigData.DnsMode) {\r
+      FreePool (AttemptTmp);\r
+      FreePool (AttemptConfigOrder);\r
+      return TRUE;\r
+    } else {\r
+      FreePool (AttemptTmp);\r
+      continue;\r
+    }\r
+\r
+  }\r
+\r
+  FreePool (AttemptConfigOrder);\r
+  return FALSE;\r
+\r
+}\r
+\r
 /**\r
   Get the various configuration data.\r
 \r
index 912a8711fab3de1d7077868b91fba97c5686362a..2c0fe07fdb60a54da82d8c3199f6a5db492da1e9 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Miscellaneous definitions for iSCSI driver.\r
 \r
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -33,6 +33,7 @@ typedef struct _ISCSI_DRIVER_DATA ISCSI_DRIVER_DATA;
 ///\r
 #define IP6_OLD_IPADDRESS_OFFSET      42\r
 \r
+\r
 #pragma pack(1)\r
 typedef struct _ISCSI_SESSION_CONFIG_NVDATA {\r
   UINT16            TargetPort;\r
@@ -45,6 +46,7 @@ typedef struct _ISCSI_SESSION_CONFIG_NVDATA {
 \r
   BOOLEAN           InitiatorInfoFromDhcp;\r
   BOOLEAN           TargetInfoFromDhcp;\r
+\r
   CHAR8             TargetName[ISCSI_NAME_MAX_SIZE];\r
   EFI_IP_ADDRESS    TargetIp;\r
   UINT8             PrefixLength;\r
@@ -57,6 +59,9 @@ typedef struct _ISCSI_SESSION_CONFIG_NVDATA {
   BOOLEAN           RedirectFlag;\r
   UINT16            OriginalTargetPort;     // The port of proxy/virtual target.\r
   EFI_IP_ADDRESS    OriginalTargetIp;       // The address of proxy/virtual target.\r
+\r
+  BOOLEAN           DnsMode;  // Flag indicate whether the Target address is expressed as URL format.\r
+  CHAR8             TargetUrl[ISCSI_TARGET_URI_MAX_SIZE];\r
   \r
 } ISCSI_SESSION_CONFIG_NVDATA;\r
 #pragma pack()\r
@@ -338,6 +343,20 @@ IScsiDhcpIsConfigured (
   IN UINT8       IpVersion\r
   );\r
 \r
+/**\r
+  Check wheather the Controller handle is configured to use DNS protocol.\r
+\r
+  @param[in]  Controller           The handle of the controller.\r
+  \r
+  @retval TRUE                     The handle of the controller need the DNS protocol.\r
+  @retval FALSE                    The handle of the controller does not need the DNS protocol.\r
+  \r
+**/\r
+BOOLEAN\r
+IScsiDnsIsConfigured (\r
+  IN EFI_HANDLE  Controller\r
+  );\r
+\r
 /**\r
   Get the various configuration data of this iSCSI instance.\r
 \r
index a67bbd5c8700ad98b06eb67a4dcac4a4a830ad32..1602a26132a90bdafcb46db2073152079bb43556 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The implementation of iSCSI protocol based on RFC3720.\r
 \r
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -255,6 +255,23 @@ IScsiCreateConnection (
   Conn->HeaderDigest              = IScsiDigestNone;\r
   Conn->DataDigest                = IScsiDigestNone;\r
 \r
+  if (NvData->DnsMode) {\r
+    //\r
+    // perform dns process if target address expressed by domain name.\r
+    //\r
+    if (!Conn->Ipv6Flag) {\r
+      Status = IScsiDns4 (Private->Image, Private->Controller, NvData);\r
+    } else {\r
+      Status = IScsiDns6 (Private->Image, Private->Controller, NvData);\r
+    }\r
+\r
+    if (EFI_ERROR(Status)) {\r
+      DEBUG ((EFI_D_ERROR, "The configuration of Target address or DNS server address is invalid!\n"));\r
+      FreePool (Conn);\r
+      return NULL;\r
+    }\r
+  }\r
+\r
   if (!Conn->Ipv6Flag) {\r
     Tcp4IoConfig = &TcpIoConfig.Tcp4IoConfigData;\r
     \r
@@ -1131,8 +1148,13 @@ IScsiUpdateTargetAddress (
     } else {\r
       //\r
       // The domainname of the target is presented in the format of a DNS host name.\r
-      // Temporary not supported.\r
-      continue;\r
+      //\r
+      IpStr = TargetAddress;\r
+\r
+      while ((*TargetAddress != '\0') && (*TargetAddress != ':') && (*TargetAddress != ',')) {\r
+        TargetAddress++;\r
+      }\r
+      NvData->DnsMode = TRUE;\r
     }\r
 \r
     //\r
@@ -1178,17 +1200,28 @@ IScsiUpdateTargetAddress (
       IpMode = Session->ConfigData->AutoConfigureMode;\r
     }\r
 \r
-    Status = IScsiAsciiStrToIp (\r
-               IpStr,\r
-               IpMode,\r
-               &Session->ConfigData->SessionConfigData.TargetIp\r
-               );\r
-\r
-    if (EFI_ERROR (Status)) {\r
-      continue;\r
+    if (NvData->DnsMode) {\r
+      //\r
+      // Target address is expressed as URL format, just save it and\r
+      // do DNS resolution when creating a TCP connection.\r
+      //\r
+      if (AsciiStrSize (IpStr) > sizeof (Session->ConfigData->SessionConfigData.TargetUrl)){\r
+        return EFI_INVALID_PARAMETER;\r
+      }\r
+      CopyMem (&Session->ConfigData->SessionConfigData.TargetUrl, IpStr, AsciiStrSize (IpStr));\r
     } else {\r
-      NvData->RedirectFlag = TRUE;\r
-      break;\r
+      Status = IScsiAsciiStrToIp (\r
+                 IpStr,\r
+                 IpMode,\r
+                 &Session->ConfigData->SessionConfigData.TargetIp\r
+                 );\r
+\r
+      if (EFI_ERROR (Status)) {\r
+        continue;\r
+      } else {\r
+        NvData->RedirectFlag = TRUE;\r
+        break;\r
+      }\r
     }\r
   }\r
 \r