]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/IScsiDxe/IScsiDhcp.c
NetworkPkg/IScsiDxe: Remove redundant call to StrLen
[mirror_edk2.git] / NetworkPkg / IScsiDxe / IScsiDhcp.c
index 0e42805c03d52cedb9a531a2446809368e417144..6587a05993535ba6391d82ca91919db6d2aba019 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
@@ -358,6 +371,50 @@ IScsiParseDhcpAck (
   return Status;\r
 }\r
 \r
+/**\r
+  This function will switch the IP4 configuration policy to Static.\r
+\r
+  @param[in]  Ip4Config2          Pointer to the IP4 configuration protocol.\r
+\r
+  @retval     EFI_SUCCESS         The policy is already configured to static.\r
+  @retval     Others              Other error as indicated.\r
+\r
+**/\r
+EFI_STATUS\r
+IScsiSetIp4Policy (\r
+  IN EFI_IP4_CONFIG2_PROTOCOL        *Ip4Config2\r
+  )\r
+{\r
+  EFI_IP4_CONFIG2_POLICY          Policy;\r
+  EFI_STATUS                      Status;\r
+  UINTN                           DataSize;\r
+\r
+  DataSize = sizeof (EFI_IP4_CONFIG2_POLICY);\r
+  Status = Ip4Config2->GetData (\r
+                         Ip4Config2,\r
+                         Ip4Config2DataTypePolicy,\r
+                         &DataSize,\r
+                         &Policy\r
+                         );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if (Policy != Ip4Config2PolicyStatic) {\r
+    Policy = Ip4Config2PolicyStatic;\r
+    Status= Ip4Config2->SetData (\r
+                          Ip4Config2,\r
+                          Ip4Config2DataTypePolicy,\r
+                          sizeof (EFI_IP4_CONFIG2_POLICY),\r
+                          &Policy\r
+                          );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    } \r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
 \r
 /**\r
   Parse the DHCP ACK to get the address configuration and DNS information.\r
@@ -380,6 +437,7 @@ IScsiDoDhcp (
   )\r
 {\r
   EFI_HANDLE                    Dhcp4Handle;\r
+  EFI_IP4_CONFIG2_PROTOCOL      *Ip4Config2;\r
   EFI_DHCP4_PROTOCOL            *Dhcp4;\r
   EFI_STATUS                    Status;\r
   EFI_DHCP4_PACKET_OPTION       *ParaList;\r
@@ -388,6 +446,7 @@ IScsiDoDhcp (
   BOOLEAN                       MediaPresent;\r
 \r
   Dhcp4Handle = NULL;\r
+  Ip4Config2  = NULL;\r
   Dhcp4       = NULL;\r
   ParaList    = NULL;\r
 \r
@@ -400,6 +459,21 @@ IScsiDoDhcp (
     return EFI_NO_MEDIA;\r
   }\r
 \r
+  //\r
+  // DHCP4 service allows only one of its children to be configured in  \r
+  // the active state, If the DHCP4 D.O.R.A started by IP4 auto  \r
+  // configuration and has not been completed, the Dhcp4 state machine \r
+  // will not be in the right state for the iSCSI to start a new round D.O.R.A. \r
+  // So, we need to switch it's policy to static.\r
+  //\r
+  Status = gBS->HandleProtocol (Controller, &gEfiIp4Config2ProtocolGuid, (VOID **) &Ip4Config2);\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = IScsiSetIp4Policy (Ip4Config2);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
   //\r
   // Create a DHCP4 child instance and get the protocol.\r
   //\r