Module Name:    src
Committed By:   sborrill
Date:           Tue Feb 22 13:10:55 UTC 2011

Modified Files:
        src/external/bsd/iscsi/dist/src/lib: initiator.c protocol.c

Log Message:
Skip target if TargetName is empty.
Use relevant TargetAddress, not just first one we happen to find.

Following improvement based on feedback from Daisuke Aoyama (author of istgt):
Handle NOP-OUT CmdSN and immediate bit.
Handle NOP-IN TransferTag=0xffffffff.
Interim solution for dealing with Underflow bit in iSCSI response.

iscsi-initiator now talks to istgt and other targets.

Remaining issues:
CHAP support will not work with most targets (maximum 16 octet challenge is
used, but other initiators use up to 1024). However, CHAP can now be
bypassed by not specifying a username.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/external/bsd/iscsi/dist/src/lib/initiator.c
cvs rdiff -u -r1.1 -r1.2 src/external/bsd/iscsi/dist/src/lib/protocol.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/bsd/iscsi/dist/src/lib/initiator.c
diff -u src/external/bsd/iscsi/dist/src/lib/initiator.c:1.4 src/external/bsd/iscsi/dist/src/lib/initiator.c:1.5
--- src/external/bsd/iscsi/dist/src/lib/initiator.c:1.4	Mon Feb 21 17:48:43 2011
+++ src/external/bsd/iscsi/dist/src/lib/initiator.c	Tue Feb 22 13:10:55 2011
@@ -630,6 +630,7 @@
         iscsi_parameter_t	*ip;
         char			*text = NULL;
         int			 text_len = 0;
+        int			 pos = 0;
 
         if ((text = iscsi_malloc_atomic(DISCOVERY_PHASE_TEXT_LEN)) == NULL) {
                 iscsi_err(__FILE__, __LINE__, "iscsi_malloc_atomic() failed\n");
@@ -651,13 +652,23 @@
         }       
         for (ip = sess->params ; ip ; ip = ip->next) {
                 if (strcmp(ip->key, "TargetName") == 0) {
-                        for (vp = ip->value_l ; vp ; vp = vp->next) {
+                	pos = 0;
+                        for (vp = ip->value_l ; vp ; vp = vp->next, pos++) {
+                        	/*
+                        	 * Skip items which have no name,
+                        	 * these have been blocked by the target
+                        	 */
+                        	if (!strlen(vp->value))
+                        		continue;
+				
                                 ALLOC(char *, svp->v, svp->size, svp->c, 10,
 						10, "igt", return -1);
                                 svp->v[svp->c++] = strdup(vp->value);
                                 ALLOC(char *, svp->v, svp->size, svp->c, 10,
 						10, "igt2", return -1);
-                                svp->v[svp->c++] = strdup(param_val(sess->params, "TargetAddress"));
+                                svp->v[svp->c++] =
+                                     strdup(param_val_which(sess->params,
+                                     "TargetAddress", pos));
                         }
                 }
         }
@@ -2466,7 +2477,8 @@
 	/* Encapsulate and send NOP */
 
 	nop_out->ExpStatSN = sess->ExpStatSN;
-	/* nop_out->CmdSN = sess->CmdSN++; */
+	nop_out->immediate = 1;
+	nop_out->CmdSN = sess->CmdSN;
 	nop_out->transfer_tag = 0xffffffff;
 	if (iscsi_nop_out_encap(header, nop_out) != 0) {
 		iscsi_err(__FILE__, __LINE__, "iscsi_nop_out_encap() failed\n");
@@ -2901,6 +2913,16 @@
 		iscsi_err(__FILE__, __LINE__, "iscsi_nop_in() failed\n");
 		return -1;
 	}
+	if (nop_in.transfer_tag == 0xffffffff) {
+		if (nop_in.length != 0) {
+			iscsi_err(__FILE__, __LINE__,
+				"nop_in.length %u not 0\n",
+				nop_in.length);
+			NO_CLEANUP;
+			return -1;
+		}
+		return 0;
+	}
 	if (cmd) {
 #if 0
 		RETURN_NOT_EQUAL("nop_in.length", nop_in.length, nop_out->length, NO_CLEANUP, -1);
@@ -3400,12 +3422,14 @@
 	errmsg = NULL;
 	if (data.overflow != 0) {
 		errmsg = "Overflow bit";
-	} else if (data.underflow != 0) {
-		errmsg = "Underflow bit";
 	} else if (data.task_tag != scsi_cmd->tag) {
 		errmsg = "Tag";
-	} else if (data.task_tag != scsi_cmd->tag) {
-		errmsg = "Residual Count";
+	} else if (!data.underflow) {
+		if (data.res_count != 0) {
+			errmsg = "Residual Count";
+		}
+	} else {
+		iscsi_warn(__FILE__, __LINE__, "Underflow %s\n", data.res_count);
 	}
 	if (errmsg) {
 		iscsi_err(__FILE__, __LINE__, errmsg);

Index: src/external/bsd/iscsi/dist/src/lib/protocol.c
diff -u src/external/bsd/iscsi/dist/src/lib/protocol.c:1.1 src/external/bsd/iscsi/dist/src/lib/protocol.c:1.2
--- src/external/bsd/iscsi/dist/src/lib/protocol.c:1.1	Tue Jun 30 02:44:52 2009
+++ src/external/bsd/iscsi/dist/src/lib/protocol.c	Tue Feb 22 13:10:55 2011
@@ -1457,7 +1457,7 @@
 		errmsg = "Byte 4";
 	} else if (memcmp(header + 8, zeros, 8) != 0) {
 		errmsg = "Bytes 8-15";
-	} else if (memcmp(header + 44, zeros, 4) != 0) {
+	} else if (!cmd->underflow && memcmp(header + 44, zeros, 4) != 0) {
 		errmsg = "Bytes 44-47";
 	}
 	if (errmsg) {

Reply via email to