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