* [PATCH V2] NetworkPkg: Add check logic for some variable in iSCSI driver.
@ 2017-02-27 9:10 Zhang Lubo
2017-02-28 3:02 ` Wu, Jiaxin
0 siblings, 1 reply; 2+ messages in thread
From: Zhang Lubo @ 2017-02-27 9:10 UTC (permalink / raw)
To: edk2-devel; +Cc: Ye Ting, Fu Siyuan, Wu Jiaxin
v2: need to check the global variable mPrivate before using it in
the Convert AttemptConfigData To IfrNvData by Keyword function.
Add check logic for some attempt variable to enhance code in iSCSI.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Zhang Lubo <lubo.zhang@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>
---
NetworkPkg/IScsiDxe/IScsiConfig.c | 271 ++++++++++++++++++++------------------
NetworkPkg/IScsiDxe/IScsiConfig.h | 2 +-
2 files changed, 143 insertions(+), 130 deletions(-)
diff --git a/NetworkPkg/IScsiDxe/IScsiConfig.c b/NetworkPkg/IScsiDxe/IScsiConfig.c
index b169620..08a49d6 100644
--- a/NetworkPkg/IScsiDxe/IScsiConfig.c
+++ b/NetworkPkg/IScsiDxe/IScsiConfig.c
@@ -628,116 +628,123 @@ IScsiConvertAttemptConfigDataToIfrNvDataByKeyword (
ISCSI_SESSION_CONFIG_NVDATA *SessionConfigData;
ISCSI_CHAP_AUTH_CONFIG_NVDATA *AuthConfigData;
CHAR16 AttemptNameList[ATTEMPT_NAME_LIST_SIZE];
EFI_IP_ADDRESS Ip;
UINTN Index;
+ UINTN StringLen;
ZeroMem (AttemptNameList, sizeof (AttemptNameList));
- NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) {
- Attempt = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);
- //
- // Normal session configuration parameters.
- //
- SessionConfigData = &Attempt->SessionConfigData;
-
- Index = Attempt->AttemptConfigIndex - 1;
+ if ((mPrivate != NULL) && (mPrivate->AttemptCount != 0)) {
+ NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) {
+ Attempt = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);
+ //
+ // Normal session configuration parameters.
+ //
+ SessionConfigData = &Attempt->SessionConfigData;
- //
- // Save the attempt to AttemptNameList as Attempt:1 Attempt:2
- //
- AsciiStrToUnicodeStrS (
- Attempt->AttemptName,
- AttemptNameList + StrLen (AttemptNameList),
- ATTEMPT_NAME_LIST_SIZE
- );
- *(AttemptNameList + StrLen (AttemptNameList) - 2) = L':';
- *(AttemptNameList + StrLen (AttemptNameList)) = L' ';
+ ASSERT ((Attempt->AttemptConfigIndex > 0) && (Attempt->AttemptConfigIndex <= FixedPcdGet8 (PcdMaxIScsiAttemptNumber)));
+ Index = Attempt->AttemptConfigIndex - 1;
- AsciiStrToUnicodeStrS (
- Attempt->AttemptName,
- IfrNvData->ISCSIAttemptName + ATTEMPT_NAME_SIZE * Index,
- ATTEMPT_NAME_SIZE
- );
+ //
+ // Save the attempt to AttemptNameList as Attempt:1 Attempt:2
+ //
+ AsciiStrToUnicodeStrS (
+ Attempt->AttemptName,
+ AttemptNameList + StrLen (AttemptNameList),
+ ATTEMPT_NAME_LIST_SIZE - StrLen (AttemptNameList)
+ );
- IfrNvData->ISCSIBootEnableList[Index] = SessionConfigData->Enabled;
- IfrNvData->ISCSIIpAddressTypeList[Index] = SessionConfigData->IpMode;
+ StringLen = StrLen (AttemptNameList);
+ ASSERT (StringLen > 2);
+ *(AttemptNameList + StringLen - 2) = L':';
+ *(AttemptNameList + StringLen) = L' ';
- IfrNvData->ISCSIInitiatorInfoViaDHCP[Index] = SessionConfigData->InitiatorInfoFromDhcp;
- IfrNvData->ISCSITargetInfoViaDHCP[Index] = SessionConfigData->TargetInfoFromDhcp;
- IfrNvData->ISCSIConnectRetry[Index] = SessionConfigData->ConnectRetryCount;
- IfrNvData->ISCSIConnectTimeout[Index] = SessionConfigData->ConnectTimeout;
- IfrNvData->ISCSITargetTcpPort[Index] = SessionConfigData->TargetPort;
+ AsciiStrToUnicodeStrS (
+ Attempt->AttemptName,
+ IfrNvData->ISCSIAttemptName + ATTEMPT_NAME_SIZE * Index,
+ ATTEMPT_NAME_LIST_SIZE - ATTEMPT_NAME_SIZE * Index
+ );
- if (SessionConfigData->IpMode == IP_MODE_IP4) {
- CopyMem (&Ip.v4, &SessionConfigData->LocalIp, sizeof (EFI_IPv4_ADDRESS));
- IScsiIpToStr (&Ip, FALSE, IfrNvData->Keyword[Index].ISCSIInitiatorIpAddress);
- CopyMem (&Ip.v4, &SessionConfigData->SubnetMask, sizeof (EFI_IPv4_ADDRESS));
- IScsiIpToStr (&Ip, FALSE, IfrNvData->Keyword[Index].ISCSIInitiatorNetmask);
- CopyMem (&Ip.v4, &SessionConfigData->Gateway, sizeof (EFI_IPv4_ADDRESS));
- IScsiIpToStr (&Ip, FALSE, IfrNvData->Keyword[Index].ISCSIInitiatorGateway);
- if (SessionConfigData->TargetIp.v4.Addr[0] != '\0') {
- CopyMem (&Ip.v4, &SessionConfigData->TargetIp, sizeof (EFI_IPv4_ADDRESS));
- IScsiIpToStr (&Ip, FALSE, IfrNvData->Keyword[Index].ISCSITargetIpAddress);
- }
- } else if (SessionConfigData->IpMode == IP_MODE_IP6) {
- ZeroMem (IfrNvData->Keyword[Index].ISCSITargetIpAddress, sizeof (IfrNvData->TargetIp));
- if (SessionConfigData->TargetIp.v6.Addr[0] != '\0') {
- IP6_COPY_ADDRESS (&Ip.v6, &SessionConfigData->TargetIp);
- IScsiIpToStr (&Ip, TRUE, IfrNvData->Keyword[Index].ISCSITargetIpAddress);
+ IfrNvData->ISCSIBootEnableList[Index] = SessionConfigData->Enabled;
+ IfrNvData->ISCSIIpAddressTypeList[Index] = SessionConfigData->IpMode;
+
+ IfrNvData->ISCSIInitiatorInfoViaDHCP[Index] = SessionConfigData->InitiatorInfoFromDhcp;
+ IfrNvData->ISCSITargetInfoViaDHCP[Index] = SessionConfigData->TargetInfoFromDhcp;
+ IfrNvData->ISCSIConnectRetry[Index] = SessionConfigData->ConnectRetryCount;
+ IfrNvData->ISCSIConnectTimeout[Index] = SessionConfigData->ConnectTimeout;
+ IfrNvData->ISCSITargetTcpPort[Index] = SessionConfigData->TargetPort;
+
+ if (SessionConfigData->IpMode == IP_MODE_IP4) {
+ CopyMem (&Ip.v4, &SessionConfigData->LocalIp, sizeof (EFI_IPv4_ADDRESS));
+ IScsiIpToStr (&Ip, FALSE, IfrNvData->Keyword[Index].ISCSIInitiatorIpAddress);
+ CopyMem (&Ip.v4, &SessionConfigData->SubnetMask, sizeof (EFI_IPv4_ADDRESS));
+ IScsiIpToStr (&Ip, FALSE, IfrNvData->Keyword[Index].ISCSIInitiatorNetmask);
+ CopyMem (&Ip.v4, &SessionConfigData->Gateway, sizeof (EFI_IPv4_ADDRESS));
+ IScsiIpToStr (&Ip, FALSE, IfrNvData->Keyword[Index].ISCSIInitiatorGateway);
+ if (SessionConfigData->TargetIp.v4.Addr[0] != '\0') {
+ CopyMem (&Ip.v4, &SessionConfigData->TargetIp, sizeof (EFI_IPv4_ADDRESS));
+ IScsiIpToStr (&Ip, FALSE, IfrNvData->Keyword[Index].ISCSITargetIpAddress);
+ }
+ } else if (SessionConfigData->IpMode == IP_MODE_IP6) {
+ ZeroMem (IfrNvData->Keyword[Index].ISCSITargetIpAddress, sizeof (IfrNvData->TargetIp));
+ if (SessionConfigData->TargetIp.v6.Addr[0] != '\0') {
+ IP6_COPY_ADDRESS (&Ip.v6, &SessionConfigData->TargetIp);
+ IScsiIpToStr (&Ip, TRUE, IfrNvData->Keyword[Index].ISCSITargetIpAddress);
+ }
}
- }
- AsciiStrToUnicodeStrS (
- SessionConfigData->TargetName,
- IfrNvData->Keyword[Index].ISCSITargetName,
- ISCSI_NAME_MAX_SIZE
- );
-
- if (SessionConfigData->DnsMode) {
AsciiStrToUnicodeStrS (
- SessionConfigData->TargetUrl,
- IfrNvData->TargetIp,
- sizeof (IfrNvData->TargetIp) / sizeof (IfrNvData->TargetIp[0])
+ SessionConfigData->TargetName,
+ IfrNvData->Keyword[Index].ISCSITargetName,
+ ISCSI_NAME_MAX_SIZE
);
- }
- IScsiLunToUnicodeStr (SessionConfigData->BootLun, IfrNvData->Keyword[Index].ISCSILun);
- IScsiConvertIsIdToString (IfrNvData->Keyword[Index].ISCSIIsId, SessionConfigData->IsId);
+ if (SessionConfigData->DnsMode) {
+ AsciiStrToUnicodeStrS (
+ SessionConfigData->TargetUrl,
+ IfrNvData->TargetIp,
+ sizeof (IfrNvData->TargetIp) / sizeof (IfrNvData->TargetIp[0])
+ );
+ }
- IfrNvData->ISCSIAuthenticationMethod[Index] = Attempt->AuthenticationType;
+ IScsiLunToUnicodeStr (SessionConfigData->BootLun, IfrNvData->Keyword[Index].ISCSILun);
+ IScsiConvertIsIdToString (IfrNvData->Keyword[Index].ISCSIIsId, SessionConfigData->IsId);
- if (Attempt->AuthenticationType == ISCSI_AUTH_TYPE_CHAP) {
- AuthConfigData = &Attempt->AuthConfigData.CHAP;
- IfrNvData->ISCSIChapType[Index] = AuthConfigData->CHAPType;
- AsciiStrToUnicodeStrS (
- AuthConfigData->CHAPName,
- IfrNvData->Keyword[Index].ISCSIChapUsername,
- ISCSI_CHAP_NAME_STORAGE
- );
+ IfrNvData->ISCSIAuthenticationMethod[Index] = Attempt->AuthenticationType;
- AsciiStrToUnicodeStrS (
- AuthConfigData->CHAPSecret,
- IfrNvData->Keyword[Index].ISCSIChapSecret,
- ISCSI_CHAP_SECRET_STORAGE
- );
+ if (Attempt->AuthenticationType == ISCSI_AUTH_TYPE_CHAP) {
+ AuthConfigData = &Attempt->AuthConfigData.CHAP;
+ IfrNvData->ISCSIChapType[Index] = AuthConfigData->CHAPType;
+ AsciiStrToUnicodeStrS (
+ AuthConfigData->CHAPName,
+ IfrNvData->Keyword[Index].ISCSIChapUsername,
+ ISCSI_CHAP_NAME_STORAGE
+ );
- AsciiStrToUnicodeStrS (
- AuthConfigData->ReverseCHAPName,
- IfrNvData->Keyword[Index].ISCSIReverseChapUsername,
- ISCSI_CHAP_NAME_STORAGE
- );
+ AsciiStrToUnicodeStrS (
+ AuthConfigData->CHAPSecret,
+ IfrNvData->Keyword[Index].ISCSIChapSecret,
+ ISCSI_CHAP_SECRET_STORAGE
+ );
- AsciiStrToUnicodeStrS (
- AuthConfigData->ReverseCHAPSecret,
- IfrNvData->Keyword[Index].ISCSIReverseChapSecret,
- ISCSI_CHAP_SECRET_STORAGE
- );
+ AsciiStrToUnicodeStrS (
+ AuthConfigData->ReverseCHAPName,
+ IfrNvData->Keyword[Index].ISCSIReverseChapUsername,
+ ISCSI_CHAP_NAME_STORAGE
+ );
+
+ AsciiStrToUnicodeStrS (
+ AuthConfigData->ReverseCHAPSecret,
+ IfrNvData->Keyword[Index].ISCSIReverseChapSecret,
+ ISCSI_CHAP_SECRET_STORAGE
+ );
+ }
}
- }
- CopyMem(IfrNvData->ISCSIDisplayAttemptList, AttemptNameList, ATTEMPT_NAME_LIST_SIZE);
+ CopyMem(IfrNvData->ISCSIDisplayAttemptList, AttemptNameList, ATTEMPT_NAME_LIST_SIZE);
+ }
}
/**
Convert the IFR data to iSCSI configuration data.
@@ -1199,10 +1206,11 @@ IScsiConvertlfrNvDataToAttemptConfigDataByKeyword (
EFI_IP_ADDRESS Gateway;
EFI_INPUT_KEY Key;
UINT64 Lun;
EFI_STATUS Status;
+ Attempt = NULL;
ZeroMem (IScsiName, sizeof (IScsiName));
if (OffSet < ATTEMPT_BOOTENABLE_VAR_OFFSET) {
return EFI_SUCCESS;
@@ -1726,11 +1734,11 @@ IScsiConvertlfrNvDataToAttemptConfigDataByKeyword (
//
// Record the user configuration information in NVR.
//
-
+ ASSERT (Attempt != NULL);
UnicodeSPrint (mPrivate->PortString, (UINTN) ISCSI_NAME_IFR_MAX_SIZE, L"Attempt %d", Attempt->AttemptConfigIndex);
return gRT->SetVariable (
mPrivate->PortString,
&gEfiIScsiInitiatorNameProtocolGuid,
ISCSI_CONFIG_VAR_ATTR,
@@ -2705,10 +2713,11 @@ IScsiConfigProcessDefault (
UINT8 *AttemptConfigOrder;
UINTN AttemptConfigOrderSize;
UINTN Index;
EFI_INPUT_KEY Key;
+ AttemptConfigData = NULL;
//
// Is User creating a new attempt?
//
NewAttempt = FALSE;
@@ -2749,41 +2758,40 @@ IScsiConfigProcessDefault (
L"InitialAttemptOrder",
&gIScsiConfigGuid,
&AttemptConfigOrderSize
);
- if (AttemptConfigOrder != NULL) {
-
- for (Index = 0; Index < AttemptConfigOrderSize / sizeof (UINT8); Index++) {
- UnicodeSPrint (
- mPrivate->PortString,
- (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
- L"Attempt %d",
- (UINTN) AttemptConfigOrder[Index]
- );
- GetVariable2 (
- mPrivate->PortString,
- &gEfiIScsiInitiatorNameProtocolGuid,
- (VOID**)&AttemptConfigData,
- NULL
- );
- if (AttemptConfigData == NULL || AttemptConfigData->Actived == ISCSI_ACTIVE_ENABLED) {
- continue;
- }
-
- break;
- }
+ ASSERT (AttemptConfigOrder != NULL);
- if (Index > PcdGet8 (PcdMaxIScsiAttemptNumber)) {
- CreatePopUp (
- EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
- &Key,
- L"Can not create more attempts, Please configure the PcdMaxIScsiAttemptNumber if needed!",
- NULL
- );
- return EFI_UNSUPPORTED;
+ for (Index = 0; Index < AttemptConfigOrderSize / sizeof (UINT8); Index++) {
+ UnicodeSPrint (
+ mPrivate->PortString,
+ (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
+ L"Attempt %d",
+ (UINTN) AttemptConfigOrder[Index]
+ );
+ GetVariable2 (
+ mPrivate->PortString,
+ &gEfiIScsiInitiatorNameProtocolGuid,
+ (VOID**)&AttemptConfigData,
+ NULL
+ );
+ if (AttemptConfigData == NULL || AttemptConfigData->Actived == ISCSI_ACTIVE_ENABLED) {
+ continue;
}
+
+ break;
+ }
+
+ if (Index > PcdGet8 (PcdMaxIScsiAttemptNumber)) {
+ CreatePopUp (
+ EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+ &Key,
+ L"Can not create more attempts, Please configure the PcdMaxIScsiAttemptNumber if needed!",
+ NULL
+ );
+ return EFI_UNSUPPORTED;
}
if (AttemptConfigOrder != NULL) {
FreePool (AttemptConfigOrder);
}
@@ -2796,10 +2804,11 @@ IScsiConfigProcessDefault (
NicInfo->HwAddressSize,
NicInfo->VlanId,
MacString
);
+ ASSERT (AttemptConfigData != NULL);
UnicodeStrToAsciiStrS (MacString, AttemptConfigData->MacString, sizeof (AttemptConfigData->MacString));
AttemptConfigData->NicIndex = NicIndex;
AttemptConfigData->Actived = ISCSI_ACTIVE_ENABLED;
//
@@ -3126,10 +3135,11 @@ IScsiFormRouteConfig (
Index = 0;
Index2 = 0;
NicInfo = NULL;
AttemptList = NULL;
+ Status = EFI_SUCCESS;
if (This == NULL || Configuration == NULL || Progress == NULL) {
return EFI_INVALID_PARAMETER;
}
@@ -3182,18 +3192,27 @@ IScsiFormRouteConfig (
NULL
);
goto Exit;
}
} else {
- Status = gIScsiInitiatorName.Get (&gIScsiInitiatorName, &BufferSize, InitiatorName);
+ Status = IScsiGetValue (Configuration, L"&OFFSET=", &OffSet);
if (EFI_ERROR (Status)) {
- CreatePopUp (
- EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
- &Key,
- L"Error: please configure iSCSI initiator name first!",
- NULL
- );
+ goto Exit;
+ }
+
+ if (OffSet >= ATTEMPT_MAC_ADDR_VAR_OFFSET) {
+ Status = gIScsiInitiatorName.Get (&gIScsiInitiatorName, &BufferSize, InitiatorName);
+ if (EFI_ERROR (Status)) {
+ CreatePopUp (
+ EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+ &Key,
+ L"Error: please configure iSCSI initiator name first!",
+ NULL
+ );
+ goto Exit;
+ }
+ } else {
goto Exit;
}
if (IfrNvData->ISCSIAddAttemptList[0] != L'\0') {
Status =IScsiGetAttemptIndexList (IfrNvData->ISCSIAddAttemptList, IfrNvData->AddAttemptList, TRUE);
@@ -3288,25 +3307,19 @@ IScsiFormRouteConfig (
Status = EFI_NOT_FOUND;
goto Exit;
}
} else {
- Status = IScsiGetValue (Configuration, L"&OFFSET=", &OffSet);
- if (EFI_ERROR (Status)) {
- goto Exit;
- }
Status = IScsiConvertlfrNvDataToAttemptConfigDataByKeyword (IfrNvData, OffSet);
if (EFI_ERROR (Status)) {
goto Exit;
}
}
}
IScsiConfigUpdateAttempt ();
- Status = EFI_SUCCESS;
-
Exit:
if (InitiatorName != NULL) {
FreePool (InitiatorName);
}
diff --git a/NetworkPkg/IScsiDxe/IScsiConfig.h b/NetworkPkg/IScsiDxe/IScsiConfig.h
index 21db3c3..7793d52 100644
--- a/NetworkPkg/IScsiDxe/IScsiConfig.h
+++ b/NetworkPkg/IScsiDxe/IScsiConfig.h
@@ -29,11 +29,10 @@ extern ISCSI_FORM_CALLBACK_INFO *mCallbackInfo;
((UINT16) ((UINTN) &(((ISCSI_CONFIG_IFR_NVDATA *) 0)->Field)))
#define QUESTION_ID(Field) \
((UINT16) (VAR_OFFSET (Field) + CONFIG_OPTION_OFFSET))
-
#define DYNAMIC_ONE_OF_VAR_OFFSET VAR_OFFSET (Enabled)
#define DYNAMIC_ORDERED_LIST_QUESTION_ID QUESTION_ID (DynamicOrderedList)
#define DYNAMIC_ORDERED_LIST_VAR_OFFSET VAR_OFFSET (DynamicOrderedList)
#define ATTEMPT_DEL_QUESTION_ID QUESTION_ID (DeleteAttemptList)
#define ATTEMPT_DEL_VAR_OFFSET VAR_OFFSET (DeleteAttemptList)
@@ -41,10 +40,11 @@ extern ISCSI_FORM_CALLBACK_INFO *mCallbackInfo;
#define ATTEMPT_ADD_VAR_OFFSET VAR_OFFSET (AddAttemptList)
//
// Define QuestionId and OffSet for Keywords.
//
+#define ATTEMPT_MAC_ADDR_VAR_OFFSET VAR_OFFSET (ISCSIMacAddr)
#define ATTEMPT_ATTEMPT_NAME_QUESTION_ID QUESTION_ID (ISCSIAttemptName)
#define ATTEMPT_ATTEMPT_NAME_VAR_OFFSET VAR_OFFSET (ISCSIAttemptName)
#define ATTEMPT_BOOTENABLE_QUESTION_ID QUESTION_ID (ISCSIBootEnableList)
#define ATTEMPT_BOOTENABLE_VAR_OFFSET VAR_OFFSET (ISCSIBootEnableList)
#define ATTEMPT_ADDRESS_TYPE_QUESTION_ID QUESTION_ID (ISCSIIpAddressTypeList)
--
1.9.5.msysgit.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH V2] NetworkPkg: Add check logic for some variable in iSCSI driver.
2017-02-27 9:10 [PATCH V2] NetworkPkg: Add check logic for some variable in iSCSI driver Zhang Lubo
@ 2017-02-28 3:02 ` Wu, Jiaxin
0 siblings, 0 replies; 2+ messages in thread
From: Wu, Jiaxin @ 2017-02-28 3:02 UTC (permalink / raw)
To: Zhang, Lubo, edk2-devel@lists.01.org; +Cc: Ye, Ting, Fu, Siyuan
Hi Lubo,
In IScsiConfigProcessDefault, we'd better replace the ASSERT for AttemptConfigOrder/AttemptConfigData with "if error" condition.
Others is good to me.
Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>
Thanks,
Jiaxin
> -----Original Message-----
> From: Zhang, Lubo
> Sent: Monday, February 27, 2017 5:10 PM
> To: edk2-devel@lists.01.org
> Cc: Ye, Ting <ting.ye@intel.com>; Fu, Siyuan <siyuan.fu@intel.com>; Wu,
> Jiaxin <jiaxin.wu@intel.com>
> Subject: [PATCH V2] NetworkPkg: Add check logic for some variable in iSCSI
> driver.
>
> v2: need to check the global variable mPrivate before using it in
> the Convert AttemptConfigData To IfrNvData by Keyword function.
>
> Add check logic for some attempt variable to enhance code in iSCSI.
>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Zhang Lubo <lubo.zhang@intel.com>
> Cc: Ye Ting <ting.ye@intel.com>
> Cc: Fu Siyuan <siyuan.fu@intel.com>
> Cc: Wu Jiaxin <jiaxin.wu@intel.com>
> ---
> NetworkPkg/IScsiDxe/IScsiConfig.c | 271 ++++++++++++++++++++-----------
> -------
> NetworkPkg/IScsiDxe/IScsiConfig.h | 2 +-
> 2 files changed, 143 insertions(+), 130 deletions(-)
>
> diff --git a/NetworkPkg/IScsiDxe/IScsiConfig.c
> b/NetworkPkg/IScsiDxe/IScsiConfig.c
> index b169620..08a49d6 100644
> --- a/NetworkPkg/IScsiDxe/IScsiConfig.c
> +++ b/NetworkPkg/IScsiDxe/IScsiConfig.c
> @@ -628,116 +628,123 @@
> IScsiConvertAttemptConfigDataToIfrNvDataByKeyword (
> ISCSI_SESSION_CONFIG_NVDATA *SessionConfigData;
> ISCSI_CHAP_AUTH_CONFIG_NVDATA *AuthConfigData;
> CHAR16 AttemptNameList[ATTEMPT_NAME_LIST_SIZE];
> EFI_IP_ADDRESS Ip;
> UINTN Index;
> + UINTN StringLen;
>
> ZeroMem (AttemptNameList, sizeof (AttemptNameList));
>
> - NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) {
> - Attempt = NET_LIST_USER_STRUCT (Entry,
> ISCSI_ATTEMPT_CONFIG_NVDATA, Link);
> - //
> - // Normal session configuration parameters.
> - //
> - SessionConfigData = &Attempt->SessionConfigData;
> -
> - Index = Attempt->AttemptConfigIndex - 1;
> + if ((mPrivate != NULL) && (mPrivate->AttemptCount != 0)) {
> + NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) {
> + Attempt = NET_LIST_USER_STRUCT (Entry,
> ISCSI_ATTEMPT_CONFIG_NVDATA, Link);
> + //
> + // Normal session configuration parameters.
> + //
> + SessionConfigData = &Attempt->SessionConfigData;
>
> - //
> - // Save the attempt to AttemptNameList as Attempt:1 Attempt:2
> - //
> - AsciiStrToUnicodeStrS (
> - Attempt->AttemptName,
> - AttemptNameList + StrLen (AttemptNameList),
> - ATTEMPT_NAME_LIST_SIZE
> - );
> - *(AttemptNameList + StrLen (AttemptNameList) - 2) = L':';
> - *(AttemptNameList + StrLen (AttemptNameList)) = L' ';
> + ASSERT ((Attempt->AttemptConfigIndex > 0) && (Attempt-
> >AttemptConfigIndex <= FixedPcdGet8 (PcdMaxIScsiAttemptNumber)));
> + Index = Attempt->AttemptConfigIndex - 1;
>
> - AsciiStrToUnicodeStrS (
> - Attempt->AttemptName,
> - IfrNvData->ISCSIAttemptName + ATTEMPT_NAME_SIZE * Index,
> - ATTEMPT_NAME_SIZE
> - );
> + //
> + // Save the attempt to AttemptNameList as Attempt:1 Attempt:2
> + //
> + AsciiStrToUnicodeStrS (
> + Attempt->AttemptName,
> + AttemptNameList + StrLen (AttemptNameList),
> + ATTEMPT_NAME_LIST_SIZE - StrLen (AttemptNameList)
> + );
>
> - IfrNvData->ISCSIBootEnableList[Index] = SessionConfigData->Enabled;
> - IfrNvData->ISCSIIpAddressTypeList[Index] = SessionConfigData-
> >IpMode;
> + StringLen = StrLen (AttemptNameList);
> + ASSERT (StringLen > 2);
> + *(AttemptNameList + StringLen - 2) = L':';
> + *(AttemptNameList + StringLen) = L' ';
>
> - IfrNvData->ISCSIInitiatorInfoViaDHCP[Index] = SessionConfigData-
> >InitiatorInfoFromDhcp;
> - IfrNvData->ISCSITargetInfoViaDHCP[Index] = SessionConfigData-
> >TargetInfoFromDhcp;
> - IfrNvData->ISCSIConnectRetry[Index] = SessionConfigData-
> >ConnectRetryCount;
> - IfrNvData->ISCSIConnectTimeout[Index] = SessionConfigData-
> >ConnectTimeout;
> - IfrNvData->ISCSITargetTcpPort[Index] = SessionConfigData-
> >TargetPort;
> + AsciiStrToUnicodeStrS (
> + Attempt->AttemptName,
> + IfrNvData->ISCSIAttemptName + ATTEMPT_NAME_SIZE * Index,
> + ATTEMPT_NAME_LIST_SIZE - ATTEMPT_NAME_SIZE * Index
> + );
>
> - if (SessionConfigData->IpMode == IP_MODE_IP4) {
> - CopyMem (&Ip.v4, &SessionConfigData->LocalIp, sizeof
> (EFI_IPv4_ADDRESS));
> - IScsiIpToStr (&Ip, FALSE, IfrNvData-
> >Keyword[Index].ISCSIInitiatorIpAddress);
> - CopyMem (&Ip.v4, &SessionConfigData->SubnetMask, sizeof
> (EFI_IPv4_ADDRESS));
> - IScsiIpToStr (&Ip, FALSE, IfrNvData-
> >Keyword[Index].ISCSIInitiatorNetmask);
> - CopyMem (&Ip.v4, &SessionConfigData->Gateway, sizeof
> (EFI_IPv4_ADDRESS));
> - IScsiIpToStr (&Ip, FALSE, IfrNvData-
> >Keyword[Index].ISCSIInitiatorGateway);
> - if (SessionConfigData->TargetIp.v4.Addr[0] != '\0') {
> - CopyMem (&Ip.v4, &SessionConfigData->TargetIp, sizeof
> (EFI_IPv4_ADDRESS));
> - IScsiIpToStr (&Ip, FALSE, IfrNvData-
> >Keyword[Index].ISCSITargetIpAddress);
> - }
> - } else if (SessionConfigData->IpMode == IP_MODE_IP6) {
> - ZeroMem (IfrNvData->Keyword[Index].ISCSITargetIpAddress, sizeof
> (IfrNvData->TargetIp));
> - if (SessionConfigData->TargetIp.v6.Addr[0] != '\0') {
> - IP6_COPY_ADDRESS (&Ip.v6, &SessionConfigData->TargetIp);
> - IScsiIpToStr (&Ip, TRUE, IfrNvData-
> >Keyword[Index].ISCSITargetIpAddress);
> + IfrNvData->ISCSIBootEnableList[Index] = SessionConfigData-
> >Enabled;
> + IfrNvData->ISCSIIpAddressTypeList[Index] = SessionConfigData-
> >IpMode;
> +
> + IfrNvData->ISCSIInitiatorInfoViaDHCP[Index] = SessionConfigData-
> >InitiatorInfoFromDhcp;
> + IfrNvData->ISCSITargetInfoViaDHCP[Index] = SessionConfigData-
> >TargetInfoFromDhcp;
> + IfrNvData->ISCSIConnectRetry[Index] = SessionConfigData-
> >ConnectRetryCount;
> + IfrNvData->ISCSIConnectTimeout[Index] = SessionConfigData-
> >ConnectTimeout;
> + IfrNvData->ISCSITargetTcpPort[Index] = SessionConfigData-
> >TargetPort;
> +
> + if (SessionConfigData->IpMode == IP_MODE_IP4) {
> + CopyMem (&Ip.v4, &SessionConfigData->LocalIp, sizeof
> (EFI_IPv4_ADDRESS));
> + IScsiIpToStr (&Ip, FALSE, IfrNvData-
> >Keyword[Index].ISCSIInitiatorIpAddress);
> + CopyMem (&Ip.v4, &SessionConfigData->SubnetMask, sizeof
> (EFI_IPv4_ADDRESS));
> + IScsiIpToStr (&Ip, FALSE, IfrNvData-
> >Keyword[Index].ISCSIInitiatorNetmask);
> + CopyMem (&Ip.v4, &SessionConfigData->Gateway, sizeof
> (EFI_IPv4_ADDRESS));
> + IScsiIpToStr (&Ip, FALSE, IfrNvData-
> >Keyword[Index].ISCSIInitiatorGateway);
> + if (SessionConfigData->TargetIp.v4.Addr[0] != '\0') {
> + CopyMem (&Ip.v4, &SessionConfigData->TargetIp, sizeof
> (EFI_IPv4_ADDRESS));
> + IScsiIpToStr (&Ip, FALSE, IfrNvData-
> >Keyword[Index].ISCSITargetIpAddress);
> + }
> + } else if (SessionConfigData->IpMode == IP_MODE_IP6) {
> + ZeroMem (IfrNvData->Keyword[Index].ISCSITargetIpAddress, sizeof
> (IfrNvData->TargetIp));
> + if (SessionConfigData->TargetIp.v6.Addr[0] != '\0') {
> + IP6_COPY_ADDRESS (&Ip.v6, &SessionConfigData->TargetIp);
> + IScsiIpToStr (&Ip, TRUE, IfrNvData-
> >Keyword[Index].ISCSITargetIpAddress);
> + }
> }
> - }
>
> - AsciiStrToUnicodeStrS (
> - SessionConfigData->TargetName,
> - IfrNvData->Keyword[Index].ISCSITargetName,
> - ISCSI_NAME_MAX_SIZE
> - );
> -
> - if (SessionConfigData->DnsMode) {
> AsciiStrToUnicodeStrS (
> - SessionConfigData->TargetUrl,
> - IfrNvData->TargetIp,
> - sizeof (IfrNvData->TargetIp) / sizeof (IfrNvData->TargetIp[0])
> + SessionConfigData->TargetName,
> + IfrNvData->Keyword[Index].ISCSITargetName,
> + ISCSI_NAME_MAX_SIZE
> );
> - }
>
> - IScsiLunToUnicodeStr (SessionConfigData->BootLun, IfrNvData-
> >Keyword[Index].ISCSILun);
> - IScsiConvertIsIdToString (IfrNvData->Keyword[Index].ISCSIIsId,
> SessionConfigData->IsId);
> + if (SessionConfigData->DnsMode) {
> + AsciiStrToUnicodeStrS (
> + SessionConfigData->TargetUrl,
> + IfrNvData->TargetIp,
> + sizeof (IfrNvData->TargetIp) / sizeof (IfrNvData->TargetIp[0])
> + );
> + }
>
> - IfrNvData->ISCSIAuthenticationMethod[Index] = Attempt-
> >AuthenticationType;
> + IScsiLunToUnicodeStr (SessionConfigData->BootLun, IfrNvData-
> >Keyword[Index].ISCSILun);
> + IScsiConvertIsIdToString (IfrNvData->Keyword[Index].ISCSIIsId,
> SessionConfigData->IsId);
>
> - if (Attempt->AuthenticationType == ISCSI_AUTH_TYPE_CHAP) {
> - AuthConfigData = &Attempt->AuthConfigData.CHAP;
> - IfrNvData->ISCSIChapType[Index] = AuthConfigData->CHAPType;
> - AsciiStrToUnicodeStrS (
> - AuthConfigData->CHAPName,
> - IfrNvData->Keyword[Index].ISCSIChapUsername,
> - ISCSI_CHAP_NAME_STORAGE
> - );
> + IfrNvData->ISCSIAuthenticationMethod[Index] = Attempt-
> >AuthenticationType;
>
> - AsciiStrToUnicodeStrS (
> - AuthConfigData->CHAPSecret,
> - IfrNvData->Keyword[Index].ISCSIChapSecret,
> - ISCSI_CHAP_SECRET_STORAGE
> - );
> + if (Attempt->AuthenticationType == ISCSI_AUTH_TYPE_CHAP) {
> + AuthConfigData = &Attempt->AuthConfigData.CHAP;
> + IfrNvData->ISCSIChapType[Index] = AuthConfigData->CHAPType;
> + AsciiStrToUnicodeStrS (
> + AuthConfigData->CHAPName,
> + IfrNvData->Keyword[Index].ISCSIChapUsername,
> + ISCSI_CHAP_NAME_STORAGE
> + );
>
> - AsciiStrToUnicodeStrS (
> - AuthConfigData->ReverseCHAPName,
> - IfrNvData->Keyword[Index].ISCSIReverseChapUsername,
> - ISCSI_CHAP_NAME_STORAGE
> - );
> + AsciiStrToUnicodeStrS (
> + AuthConfigData->CHAPSecret,
> + IfrNvData->Keyword[Index].ISCSIChapSecret,
> + ISCSI_CHAP_SECRET_STORAGE
> + );
>
> - AsciiStrToUnicodeStrS (
> - AuthConfigData->ReverseCHAPSecret,
> - IfrNvData->Keyword[Index].ISCSIReverseChapSecret,
> - ISCSI_CHAP_SECRET_STORAGE
> - );
> + AsciiStrToUnicodeStrS (
> + AuthConfigData->ReverseCHAPName,
> + IfrNvData->Keyword[Index].ISCSIReverseChapUsername,
> + ISCSI_CHAP_NAME_STORAGE
> + );
> +
> + AsciiStrToUnicodeStrS (
> + AuthConfigData->ReverseCHAPSecret,
> + IfrNvData->Keyword[Index].ISCSIReverseChapSecret,
> + ISCSI_CHAP_SECRET_STORAGE
> + );
> + }
> }
> - }
>
> - CopyMem(IfrNvData->ISCSIDisplayAttemptList, AttemptNameList,
> ATTEMPT_NAME_LIST_SIZE);
> + CopyMem(IfrNvData->ISCSIDisplayAttemptList, AttemptNameList,
> ATTEMPT_NAME_LIST_SIZE);
> + }
> }
>
> /**
> Convert the IFR data to iSCSI configuration data.
>
> @@ -1199,10 +1206,11 @@
> IScsiConvertlfrNvDataToAttemptConfigDataByKeyword (
> EFI_IP_ADDRESS Gateway;
> EFI_INPUT_KEY Key;
> UINT64 Lun;
> EFI_STATUS Status;
>
> + Attempt = NULL;
> ZeroMem (IScsiName, sizeof (IScsiName));
>
> if (OffSet < ATTEMPT_BOOTENABLE_VAR_OFFSET) {
> return EFI_SUCCESS;
>
> @@ -1726,11 +1734,11 @@
> IScsiConvertlfrNvDataToAttemptConfigDataByKeyword (
>
>
> //
> // Record the user configuration information in NVR.
> //
> -
> + ASSERT (Attempt != NULL);
> UnicodeSPrint (mPrivate->PortString, (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
> L"Attempt %d", Attempt->AttemptConfigIndex);
> return gRT->SetVariable (
> mPrivate->PortString,
> &gEfiIScsiInitiatorNameProtocolGuid,
> ISCSI_CONFIG_VAR_ATTR,
> @@ -2705,10 +2713,11 @@ IScsiConfigProcessDefault (
> UINT8 *AttemptConfigOrder;
> UINTN AttemptConfigOrderSize;
> UINTN Index;
> EFI_INPUT_KEY Key;
>
> + AttemptConfigData = NULL;
> //
> // Is User creating a new attempt?
> //
> NewAttempt = FALSE;
>
> @@ -2749,41 +2758,40 @@ IScsiConfigProcessDefault (
> L"InitialAttemptOrder",
> &gIScsiConfigGuid,
> &AttemptConfigOrderSize
> );
>
> - if (AttemptConfigOrder != NULL) {
> -
> - for (Index = 0; Index < AttemptConfigOrderSize / sizeof (UINT8); Index++)
> {
> - UnicodeSPrint (
> - mPrivate->PortString,
> - (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
> - L"Attempt %d",
> - (UINTN) AttemptConfigOrder[Index]
> - );
> - GetVariable2 (
> - mPrivate->PortString,
> - &gEfiIScsiInitiatorNameProtocolGuid,
> - (VOID**)&AttemptConfigData,
> - NULL
> - );
> - if (AttemptConfigData == NULL || AttemptConfigData->Actived ==
> ISCSI_ACTIVE_ENABLED) {
> - continue;
> - }
> -
> - break;
> - }
> + ASSERT (AttemptConfigOrder != NULL);
>
> - if (Index > PcdGet8 (PcdMaxIScsiAttemptNumber)) {
> - CreatePopUp (
> - EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
> - &Key,
> - L"Can not create more attempts, Please configure the
> PcdMaxIScsiAttemptNumber if needed!",
> - NULL
> - );
> - return EFI_UNSUPPORTED;
> + for (Index = 0; Index < AttemptConfigOrderSize / sizeof (UINT8); Index++)
> {
> + UnicodeSPrint (
> + mPrivate->PortString,
> + (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
> + L"Attempt %d",
> + (UINTN) AttemptConfigOrder[Index]
> + );
> + GetVariable2 (
> + mPrivate->PortString,
> + &gEfiIScsiInitiatorNameProtocolGuid,
> + (VOID**)&AttemptConfigData,
> + NULL
> + );
> + if (AttemptConfigData == NULL || AttemptConfigData->Actived ==
> ISCSI_ACTIVE_ENABLED) {
> + continue;
> }
> +
> + break;
> + }
> +
> + if (Index > PcdGet8 (PcdMaxIScsiAttemptNumber)) {
> + CreatePopUp (
> + EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
> + &Key,
> + L"Can not create more attempts, Please configure the
> PcdMaxIScsiAttemptNumber if needed!",
> + NULL
> + );
> + return EFI_UNSUPPORTED;
> }
>
> if (AttemptConfigOrder != NULL) {
> FreePool (AttemptConfigOrder);
> }
> @@ -2796,10 +2804,11 @@ IScsiConfigProcessDefault (
> NicInfo->HwAddressSize,
> NicInfo->VlanId,
> MacString
> );
>
> + ASSERT (AttemptConfigData != NULL);
> UnicodeStrToAsciiStrS (MacString, AttemptConfigData->MacString, sizeof
> (AttemptConfigData->MacString));
> AttemptConfigData->NicIndex = NicIndex;
> AttemptConfigData->Actived = ISCSI_ACTIVE_ENABLED;
>
> //
> @@ -3126,10 +3135,11 @@ IScsiFormRouteConfig (
>
> Index = 0;
> Index2 = 0;
> NicInfo = NULL;
> AttemptList = NULL;
> + Status = EFI_SUCCESS;
>
> if (This == NULL || Configuration == NULL || Progress == NULL) {
> return EFI_INVALID_PARAMETER;
> }
>
> @@ -3182,18 +3192,27 @@ IScsiFormRouteConfig (
> NULL
> );
> goto Exit;
> }
> } else {
> - Status = gIScsiInitiatorName.Get (&gIScsiInitiatorName, &BufferSize,
> InitiatorName);
> + Status = IScsiGetValue (Configuration, L"&OFFSET=", &OffSet);
> if (EFI_ERROR (Status)) {
> - CreatePopUp (
> - EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
> - &Key,
> - L"Error: please configure iSCSI initiator name first!",
> - NULL
> - );
> + goto Exit;
> + }
> +
> + if (OffSet >= ATTEMPT_MAC_ADDR_VAR_OFFSET) {
> + Status = gIScsiInitiatorName.Get (&gIScsiInitiatorName, &BufferSize,
> InitiatorName);
> + if (EFI_ERROR (Status)) {
> + CreatePopUp (
> + EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
> + &Key,
> + L"Error: please configure iSCSI initiator name first!",
> + NULL
> + );
> + goto Exit;
> + }
> + } else {
> goto Exit;
> }
>
> if (IfrNvData->ISCSIAddAttemptList[0] != L'\0') {
> Status =IScsiGetAttemptIndexList (IfrNvData->ISCSIAddAttemptList,
> IfrNvData->AddAttemptList, TRUE);
> @@ -3288,25 +3307,19 @@ IScsiFormRouteConfig (
> Status = EFI_NOT_FOUND;
> goto Exit;
> }
>
> } else {
> - Status = IScsiGetValue (Configuration, L"&OFFSET=", &OffSet);
> - if (EFI_ERROR (Status)) {
> - goto Exit;
> - }
> Status = IScsiConvertlfrNvDataToAttemptConfigDataByKeyword
> (IfrNvData, OffSet);
> if (EFI_ERROR (Status)) {
> goto Exit;
> }
> }
> }
>
> IScsiConfigUpdateAttempt ();
>
> - Status = EFI_SUCCESS;
> -
> Exit:
> if (InitiatorName != NULL) {
> FreePool (InitiatorName);
> }
>
> diff --git a/NetworkPkg/IScsiDxe/IScsiConfig.h
> b/NetworkPkg/IScsiDxe/IScsiConfig.h
> index 21db3c3..7793d52 100644
> --- a/NetworkPkg/IScsiDxe/IScsiConfig.h
> +++ b/NetworkPkg/IScsiDxe/IScsiConfig.h
> @@ -29,11 +29,10 @@ extern ISCSI_FORM_CALLBACK_INFO
> *mCallbackInfo;
> ((UINT16) ((UINTN) &(((ISCSI_CONFIG_IFR_NVDATA *) 0)->Field)))
>
> #define QUESTION_ID(Field) \
> ((UINT16) (VAR_OFFSET (Field) + CONFIG_OPTION_OFFSET))
>
> -
> #define DYNAMIC_ONE_OF_VAR_OFFSET VAR_OFFSET (Enabled)
> #define DYNAMIC_ORDERED_LIST_QUESTION_ID QUESTION_ID
> (DynamicOrderedList)
> #define DYNAMIC_ORDERED_LIST_VAR_OFFSET VAR_OFFSET
> (DynamicOrderedList)
> #define ATTEMPT_DEL_QUESTION_ID QUESTION_ID
> (DeleteAttemptList)
> #define ATTEMPT_DEL_VAR_OFFSET VAR_OFFSET
> (DeleteAttemptList)
> @@ -41,10 +40,11 @@ extern ISCSI_FORM_CALLBACK_INFO
> *mCallbackInfo;
> #define ATTEMPT_ADD_VAR_OFFSET VAR_OFFSET (AddAttemptList)
>
> //
> // Define QuestionId and OffSet for Keywords.
> //
> +#define ATTEMPT_MAC_ADDR_VAR_OFFSET VAR_OFFSET
> (ISCSIMacAddr)
> #define ATTEMPT_ATTEMPT_NAME_QUESTION_ID QUESTION_ID
> (ISCSIAttemptName)
> #define ATTEMPT_ATTEMPT_NAME_VAR_OFFSET VAR_OFFSET
> (ISCSIAttemptName)
> #define ATTEMPT_BOOTENABLE_QUESTION_ID QUESTION_ID
> (ISCSIBootEnableList)
> #define ATTEMPT_BOOTENABLE_VAR_OFFSET VAR_OFFSET
> (ISCSIBootEnableList)
> #define ATTEMPT_ADDRESS_TYPE_QUESTION_ID QUESTION_ID
> (ISCSIIpAddressTypeList)
> --
> 1.9.5.msysgit.1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-02-28 3:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-27 9:10 [PATCH V2] NetworkPkg: Add check logic for some variable in iSCSI driver Zhang Lubo
2017-02-28 3:02 ` Wu, Jiaxin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox