]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c
MdeModulePkg: Update IP4 stack drivers for classless address unicast check.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / IScsiDxe / IScsiConfig.c
index f8ae161b4c68215030527b2cae39384b76130610..77ccd6717835a355a20f5e797445b60400f9964d 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Helper functions for configuring or getting the parameters relating to iSCSI.\r
 \r
-Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2016, 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
@@ -684,7 +684,7 @@ IScsiFormCallback (
 \r
   Private   = ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This);\r
   //\r
-  // Retrive uncommitted data from Browser\r
+  // Retrieve uncommitted data from Browser\r
   //\r
   IfrNvData = AllocateZeroPool (sizeof (ISCSI_CONFIG_IFR_NVDATA));\r
   ASSERT (IfrNvData != NULL);\r
@@ -727,7 +727,9 @@ IScsiFormCallback (
     case KEY_LOCAL_IP:\r
       IScsiUnicodeStrToAsciiStr (IfrNvData->LocalIp, Ip4String);\r
       Status = IScsiAsciiStrToIp (Ip4String, &HostIp.v4);\r
-      if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
+      if (EFI_ERROR (Status) || \r
+          ((Private->Current->SessionConfigData.SubnetMask.Addr[0] != 0) && \r
+           !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), NTOHL(*(UINT32*)Private->Current->SessionConfigData.SubnetMask.Addr)))) {\r
         CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);\r
         Status = EFI_INVALID_PARAMETER;\r
       } else {\r
@@ -751,7 +753,10 @@ IScsiFormCallback (
     case KEY_GATE_WAY:\r
       IScsiUnicodeStrToAsciiStr (IfrNvData->Gateway, Ip4String);\r
       Status = IScsiAsciiStrToIp (Ip4String, &Gateway.v4);\r
-      if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), 0))) {\r
+      if (EFI_ERROR (Status) || \r
+          ((Gateway.Addr[0] != 0) && \r
+           (Private->Current->SessionConfigData.SubnetMask.Addr[0] != 0) && \r
+           !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), NTOHL(*(UINT32*)Private->Current->SessionConfigData.SubnetMask.Addr)))) {\r
         CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL);\r
         Status = EFI_INVALID_PARAMETER;\r
       } else {\r
@@ -763,7 +768,7 @@ IScsiFormCallback (
     case KEY_TARGET_IP:\r
       IScsiUnicodeStrToAsciiStr (IfrNvData->TargetIp, Ip4String);\r
       Status = IScsiAsciiStrToIp (Ip4String, &HostIp.v4);\r
-      if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
+      if (EFI_ERROR (Status) || IP4_IS_LOCAL_BROADCAST (EFI_NTOHL(HostIp.v4)) || IP4_IS_UNSPECIFIED (EFI_NTOHL(HostIp.v4))) {\r
         CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);\r
         Status = EFI_INVALID_PARAMETER;\r
       } else {\r
@@ -778,7 +783,7 @@ IScsiFormCallback (
       if (EFI_ERROR (Status)) {\r
         CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid iSCSI Name!", NULL);\r
       } else {\r
-        AsciiStrCpy (Private->Current->SessionConfigData.TargetName, IScsiName);\r
+        AsciiStrCpyS (Private->Current->SessionConfigData.TargetName, ISCSI_NAME_MAX_SIZE, IScsiName);\r
       }\r
 \r
       break;\r
@@ -867,11 +872,28 @@ IScsiFormCallback (
         //\r
         if (!Private->Current->SessionConfigData.TargetInfoFromDhcp) {\r
           CopyMem (&HostIp.v4, &Private->Current->SessionConfigData.TargetIp, sizeof (HostIp.v4));\r
-          if (!NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
+          if (IP4_IS_UNSPECIFIED (NTOHL (HostIp.Addr[0])) || IP4_IS_LOCAL_BROADCAST (NTOHL (HostIp.Addr[0]))) {\r
             CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Target IP is invalid!", NULL);\r
             Status = EFI_INVALID_PARAMETER;\r
             break;\r
           }\r
+\r
+          //\r
+          // Validate iSCSI target name configuration again:\r
+          // The format of iSCSI target name is already verified when user input the name;\r
+          // here we only check the case user does not input the name.\r
+          //\r
+          if (Private->Current->SessionConfigData.TargetName[0] == '\0') {\r
+            CreatePopUp (\r
+              EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
+              &Key,\r
+              L"iSCSI target name is NULL!",\r
+              NULL\r
+              );\r
+            Status = EFI_INVALID_PARAMETER;\r
+            break;\r
+          }\r
+\r
         }\r
 \r
         if (IfrNvData->CHAPType != ISCSI_CHAP_NONE) {\r