X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=NetworkPkg%2FIScsiDxe%2FIScsiProto.c;h=7619360568d8efd6de55f41764b1bf7a79bc8d02;hb=233ffa90ccd852a8c6a478eb0426731d64598316;hp=29b3c24997ea7231c8ea06005ffebf0e0a534820;hpb=0b10bb6f4387fd0587329d43e768a90371d63491;p=mirror_edk2.git diff --git a/NetworkPkg/IScsiDxe/IScsiProto.c b/NetworkPkg/IScsiDxe/IScsiProto.c index 29b3c24997..7619360568 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 - 2013, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.
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 @@ -17,7 +17,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. UINT32 mDataSegPad = 0; /** - Attach the iSCSI connection to the iSCSI session. + Attach the iSCSI connection to the iSCSI session. @param[in, out] Session The iSCSI session. @param[in, out] Conn The iSCSI connection. @@ -35,7 +35,7 @@ IScsiAttatchConnection ( } /** - Detach the iSCSI connection from the session it belongs to. + Detach the iSCSI connection from the session it belongs to. @param[in, out] Conn The iSCSI connection. @@ -52,7 +52,7 @@ IScsiDetatchConnection ( /** - Check the sequence number according to RFC3720. + Check the sequence number according to RFC3720. @param[in, out] ExpSN The currently expected sequence number. @param[in] NewSN The sequence number to check. @@ -124,7 +124,7 @@ IScsiUpdateCmdSN ( @retval EFI_SUCCESS The iSCSI connection is logged into the iSCSI target. @retval EFI_TIMEOUT Timeout occurred during the login procedure. - @retval Others Other errors as indicated. + @retval Others Other errors as indicated. **/ EFI_STATUS @@ -138,7 +138,11 @@ IScsiConnLogin ( // // Start the timer, and wait Timeout seconds to establish the TCP connection. // - Status = gBS->SetTimer (Conn->TimeoutEvent, TimerRelative, Timeout * TICKS_PER_MS); + Status = gBS->SetTimer ( + Conn->TimeoutEvent, + TimerRelative, + MultU64x32 (Timeout, TICKS_PER_MS) + ); if (EFI_ERROR (Status)) { return Status; } @@ -251,9 +255,26 @@ 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; - + CopyMem (&Tcp4IoConfig->LocalIp, &NvData->LocalIp, sizeof (EFI_IPv4_ADDRESS)); CopyMem (&Tcp4IoConfig->SubnetMask, &NvData->SubnetMask, sizeof (EFI_IPv4_ADDRESS)); CopyMem (&Tcp4IoConfig->Gateway, &NvData->Gateway, sizeof (EFI_IPv4_ADDRESS)); @@ -264,7 +285,7 @@ IScsiCreateConnection ( Tcp4IoConfig->StationPort = 0; } else { Tcp6IoConfig = &TcpIoConfig.Tcp6IoConfigData; - + CopyMem (&Tcp6IoConfig->RemoteIp, &NvData->TargetIp, sizeof (EFI_IPv6_ADDRESS)); Tcp6IoConfig->RemotePort = NvData->TargetPort; Tcp6IoConfig->ActiveFlag = TRUE; @@ -317,7 +338,7 @@ IScsiDestroyConnection ( @retval EFI_SUCCESS Get the NIC information successfully. @retval Others Other errors as indicated. - + **/ EFI_STATUS IScsiGetIp6NicInfo ( @@ -423,14 +444,14 @@ IScsiSessionLogin ( VOID *Tcp; EFI_GUID *ProtocolGuid; UINT8 RetryCount; - BOOLEAN MediaPresent; + EFI_STATUS MediaStatus; // // Check media status before session login. // - MediaPresent = TRUE; - NetLibDetectMedia (Session->Private->Controller, &MediaPresent); - if (!MediaPresent) { + MediaStatus = EFI_SUCCESS; + NetLibDetectMediaWaitTimeout (Session->Private->Controller, ISCSI_CHECK_MEDIA_LOGIN_WAITING_TIME, &MediaStatus); + if (MediaStatus != EFI_SUCCESS) { return EFI_NO_MEDIA; } @@ -473,7 +494,7 @@ IScsiSessionLogin ( Session->State = SESSION_STATE_LOGGED_IN; if (!Conn->Ipv6Flag) { - ProtocolGuid = &gEfiTcp4ProtocolGuid; + ProtocolGuid = &gEfiTcp4ProtocolGuid; } else { ProtocolGuid = &gEfiTcp6ProtocolGuid; } @@ -484,7 +505,7 @@ IScsiSessionLogin ( (VOID **) &Tcp, Session->Private->Image, Session->Private->ExtScsiPassThruHandle, - EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER + EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER ); ASSERT_EFI_ERROR (Status); @@ -591,7 +612,7 @@ IScsiSendLoginReq ( Receive and process the iSCSI login response. @param[in] Conn The connection in the iSCSI login phase. - + @retval EFI_SUCCESS The iSCSI login response PDU is received and processed. @retval Others Other errors as indicated. @@ -604,6 +625,8 @@ IScsiReceiveLoginRsp ( EFI_STATUS Status; NET_BUF *Pdu; + Pdu = NULL; + // // Receive the iSCSI login response. // @@ -729,7 +752,10 @@ IScsiPrepareLoginReq ( } LoginReq = (ISCSI_LOGIN_REQUEST *) NetbufAllocSpace (Nbuf, sizeof (ISCSI_LOGIN_REQUEST), NET_BUF_TAIL); - ASSERT (LoginReq != NULL); + if (LoginReq == NULL) { + NetbufFree (Nbuf); + return NULL; + } ZeroMem (LoginReq, sizeof (ISCSI_LOGIN_REQUEST)); // @@ -767,7 +793,7 @@ IScsiPrepareLoginReq ( case ISCSI_SECURITY_NEGOTIATION: // // Both none authentication and CHAP authentication share the CHAP path. - // + // // if (Session->AuthType != ISCSI_AUTH_TYPE_KRB) { Status = IScsiCHAPToSendReq (Conn, Nbuf); @@ -777,12 +803,12 @@ IScsiPrepareLoginReq ( case ISCSI_LOGIN_OPERATIONAL_NEGOTIATION: // - // Only negotiate the paramter once. + // Only negotiate the parameter once. // if (!Conn->ParamNegotiated) { IScsiFillOpParams (Conn, Nbuf); } - + ISCSI_SET_FLAG (LoginReq, ISCSI_LOGIN_REQ_PDU_FLAG_TRANSIT); break; @@ -938,7 +964,7 @@ IScsiProcessLoginRsp ( // the value presented in CmdSN as the target value for ExpCmdSN. // if ((Session->State == SESSION_STATE_FREE) && (Session->CmdSN != LoginRsp->ExpCmdSN)) { - return EFI_PROTOCOL_ERROR; + return EFI_PROTOCOL_ERROR; } // @@ -1046,7 +1072,7 @@ IScsiProcessLoginRsp ( @param[in] Data The data segment that should contain the TargetAddress key-value list. @param[in] Len Length of the data. - + @retval EFI_SUCCESS The target address is updated. @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. @retval EFI_NOT_FOUND The TargetAddress key is not found. @@ -1060,12 +1086,13 @@ IScsiUpdateTargetAddress ( IN UINT32 Len ) { - LIST_ENTRY *KeyValueList; - CHAR8 *TargetAddress; - CHAR8 *IpStr; - EFI_STATUS Status; - UINTN Number; - UINT8 IpMode; + LIST_ENTRY *KeyValueList; + CHAR8 *TargetAddress; + CHAR8 *IpStr; + EFI_STATUS Status; + UINTN Number; + UINT8 IpMode; + ISCSI_SESSION_CONFIG_NVDATA *NvData; KeyValueList = IScsiBuildKeyValueList (Data, Len); if (KeyValueList == NULL) { @@ -1073,6 +1100,7 @@ IScsiUpdateTargetAddress ( } Status = EFI_NOT_FOUND; + NvData = &Session->ConfigData->SessionConfigData; while (TRUE) { TargetAddress = IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_TARGET_ADDRESS); @@ -1080,24 +1108,60 @@ IScsiUpdateTargetAddress ( break; } - if (!NET_IS_DIGIT (TargetAddress[0])) { + // + // RFC 3720 defines format of the TargetAddress=domainname[:port][,portal-group-tag] + // The domainname can be specified as either a DNS host name, adotted-decimal IPv4 address, + // or a bracketed IPv6 address as specified in [RFC2732]. + // + if (NET_IS_DIGIT (TargetAddress[0])) { // - // The domainname of the target may be presented in three formats: a DNS host name, - // a dotted-decimal IPv4 address, or a bracketed IPv6 address. Only accept dotted - // IPv4 address. + // The domainname of the target is presented in a dotted-decimal IPv4 address format. // - continue; - } + IpStr = TargetAddress; + + while ((*TargetAddress != '\0') && (*TargetAddress != ':') && (*TargetAddress != ',')) { + // + // NULL, ':', or ',' ends the IPv4 string. + // + TargetAddress++; + } + } else if (*TargetAddress == ISCSI_REDIRECT_ADDR_START_DELIMITER){ + // + // The domainname of the target is presented in a bracketed IPv6 address format. + // + TargetAddress ++; + IpStr = TargetAddress; + while ((*TargetAddress != '\0') && (*TargetAddress != ISCSI_REDIRECT_ADDR_END_DELIMITER)) { + // + // ']' ends the IPv6 string. + // + TargetAddress++; + } + + if (*TargetAddress != ISCSI_REDIRECT_ADDR_END_DELIMITER) { + continue; + } - IpStr = TargetAddress; + *TargetAddress = '\0'; + TargetAddress ++; - while ((*TargetAddress != 0) && (*TargetAddress != ':') && (*TargetAddress != ',')) { + } else { // - // NULL, ':', or ',' ends the IPv4 string. + // The domainname of the target is presented in the format of a DNS host name. // - TargetAddress++; + IpStr = TargetAddress; + + while ((*TargetAddress != '\0') && (*TargetAddress != ':') && (*TargetAddress != ',')) { + TargetAddress++; + } + NvData->DnsMode = TRUE; } + // + // Save the origial user setting which specifies the proxy/virtual iSCSI target. + // + NvData->OriginalTargetPort = NvData->TargetPort; + if (*TargetAddress == ',') { // // Comma and the portal group tag MUST be ommitted if the TargetAddress is sent @@ -1113,33 +1177,51 @@ IScsiUpdateTargetAddress ( if (Number > 0xFFFF) { continue; } else { - Session->ConfigData->SessionConfigData.TargetPort = (UINT16) Number; + NvData->TargetPort = (UINT16) Number; } } else { // - // The string only contains the IPv4 address. Use the well-known port. + // The string only contains the Target address. Use the well-known port. // - Session->ConfigData->SessionConfigData.TargetPort = ISCSI_WELL_KNOWN_PORT; + NvData->TargetPort = ISCSI_WELL_KNOWN_PORT; } + + // + // Save the origial user setting which specifies the proxy/virtual iSCSI target. + // + CopyMem (&NvData->OriginalTargetIp, &NvData->TargetIp, sizeof (EFI_IP_ADDRESS)); + // // Update the target IP address. // - if (Session->ConfigData->SessionConfigData.IpMode < IP_MODE_AUTOCONFIG) { - IpMode = Session->ConfigData->SessionConfigData.IpMode; + if (NvData->IpMode < IP_MODE_AUTOCONFIG) { + IpMode = NvData->IpMode; } else { 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 { - break; + Status = IScsiAsciiStrToIp ( + IpStr, + IpMode, + &Session->ConfigData->SessionConfigData.TargetIp + ); + + if (EFI_ERROR (Status)) { + continue; + } else { + NvData->RedirectFlag = TRUE; + break; + } } } @@ -1243,7 +1325,10 @@ IScsiReceivePdu ( } Header = NetbufAllocSpace (PduHdr, Len, NET_BUF_TAIL); - ASSERT (Header != NULL); + if (Header == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto ON_EXIT; + } InsertTailList (NbufList, &PduHdr->List); // @@ -1280,7 +1365,7 @@ IScsiReceivePdu ( switch (ISCSI_GET_OPCODE (Header)) { case ISCSI_OPCODE_SCSI_DATA_IN: // - // To reduce memory copy overhead, try to use the buffer described by Context + // To reduce memory copy overhead, try to use the buffer described by Context // if the PDU is an iSCSI SCSI data. // InDataOffset = ISCSI_GET_BUFFER_OFFSET (Header); @@ -1628,7 +1713,7 @@ IScsiCheckOpParams ( IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_TARGET_ALIAS); IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_TARGET_PORTAL_GROUP_TAG); - + // // Remove the key-value that may not needed for result function is OR. // @@ -2091,7 +2176,7 @@ IScsiNewDataSegment ( @param[in] Packet The EXT SCSI PASS THRU request packet containing the SCSI command. @param[in] Lun The LUN. - @param[in] Tcb The tcb assocated with this SCSI command. + @param[in] Tcb The tcb associated with this SCSI command. @return The created iSCSI SCSI command PDU. @retval NULL Other errors as indicated. @@ -2143,7 +2228,7 @@ IScsiNewScsiCmdPdu ( if (ScsiCmd == NULL) { NetbufFree (PduHeader); return NULL; - } + } Header = (ISCSI_ADDITIONAL_HEADER *) (ScsiCmd + 1); ZeroMem (ScsiCmd, Length); @@ -2314,7 +2399,10 @@ IScsiNewDataOutPdu ( InsertTailList (NbufList, &PduHdr->List); DataOutHdr = (ISCSI_SCSI_DATA_OUT *) NetbufAllocSpace (PduHdr, sizeof (ISCSI_SCSI_DATA_OUT), NET_BUF_TAIL); - ASSERT (DataOutHdr != NULL); + if (DataOutHdr == NULL) { + IScsiFreeNbufList (NbufList); + return NULL; + } XferContext = &Tcb->XferContext; ZeroMem (DataOutHdr, sizeof (ISCSI_SCSI_DATA_OUT)); @@ -2814,12 +2902,13 @@ IScsiOnNopInRcvd ( @param[in] Lun The LUN. @param[in, out] Packet The request packet containing IO request, SCSI command buffer and buffers to read/write. - - @retval EFI_SUCCES The SCSI command is executed and the result is updated to + + @retval EFI_SUCCES The SCSI command is executed and the result is updated to the Packet. @retval EFI_DEVICE_ERROR Session state was not as required. @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. @retval EFI_PROTOCOL_ERROR There is no such data in the net buffer. + @retval EFI_NOT_READY The target can not accept new commands. @retval Others Other errors as indicated. **/ @@ -2998,15 +3087,6 @@ ON_EXIT: IScsiDelTcb (Tcb); } - if ((Status != EFI_SUCCESS) && (Status != EFI_NOT_READY)) { - // - // Reinstate the session. - // - if (EFI_ERROR (IScsiSessionReinstatement (Session))) { - Status = EFI_DEVICE_ERROR; - } - } - return Status; } @@ -3117,7 +3197,7 @@ IScsiSessionAbort ( if (!Conn->Ipv6Flag) { ProtocolGuid = &gEfiTcp4ProtocolGuid; } else { - ProtocolGuid = &gEfiTcp6ProtocolGuid; + ProtocolGuid = &gEfiTcp6ProtocolGuid; } gBS->CloseProtocol (