Browse Source

Handle TargetAddress

tags/v0.9.3
Michael Brown 17 years ago
parent
commit
6842dd3222
2 changed files with 36 additions and 0 deletions
  1. 6
    0
      src/include/gpxe/iscsi.h
  2. 30
    0
      src/net/tcp/iscsi.c

+ 6
- 0
src/include/gpxe/iscsi.h View File

@@ -221,6 +221,12 @@ struct iscsi_bhs_login_response {
221 221
 /** Login response opcode */
222 222
 #define ISCSI_OPCODE_LOGIN_RESPONSE 0x23
223 223
 
224
+/* Login response status codes */
225
+#define ISCSI_STATUS_SUCCESS		0x00
226
+#define ISCSI_STATUS_REDIRECT		0x01
227
+#define ISCSI_STATUS_INITIATOR_ERROR	0x02
228
+#define ISCSI_STATUS_TARGET_ERROR	0x03
229
+
224 230
 /**
225 231
  * iSCSI SCSI command basic header segment
226 232
  *

+ 30
- 0
src/net/tcp/iscsi.c View File

@@ -505,6 +505,27 @@ static void iscsi_tx_login_request ( struct iscsi_session *iscsi,
505 505
 		   len - iscsi->tx_offset );
506 506
 }
507 507
 
508
+/**
509
+ * Handle iSCSI TargetAddress text value
510
+ *
511
+ * @v iscsi		iSCSI session
512
+ * @v value		TargetAddress value
513
+ */
514
+static void iscsi_handle_targetaddress_value ( struct iscsi_session *iscsi,
515
+					       const char *value ) {
516
+	struct in_addr address;
517
+	struct sockaddr_in *sin = ( struct sockaddr_in * ) &iscsi->tcp.peer;
518
+
519
+	if ( inet_aton ( value, &address ) == 0 ) {
520
+		DBG ( "iSCSI %p received invalid TargetAddress \"%s\"\n",
521
+		      iscsi, value );
522
+		return;
523
+	}
524
+
525
+	DBG ( "iSCSI %p will redirect to %s\n", iscsi, value );
526
+	sin->sin_addr = address;
527
+}
528
+
508 529
 /**
509 530
  * Handle iSCSI AuthMethod text value
510 531
  *
@@ -629,6 +650,7 @@ struct iscsi_string_type {
629 650
 
630 651
 /** iSCSI text strings that we want to handle */
631 652
 struct iscsi_string_type iscsi_string_types[] = {
653
+	{ "TargetAddress=", iscsi_handle_targetaddress_value },
632 654
 	{ "AuthMethod=", iscsi_handle_authmethod_value },
633 655
 	{ "CHAP_A=", iscsi_handle_chap_a_value },
634 656
 	{ "CHAP_I=", iscsi_handle_chap_i_value },
@@ -710,6 +732,14 @@ static void iscsi_rx_login_response ( struct iscsi_session *iscsi, void *data,
710 732
 	iscsi_handle_strings ( iscsi, iscsi->rx_buffer, iscsi->rx_len );
711 733
 	iscsi_rx_buffered_data_done ( iscsi );
712 734
 
735
+	/* Check for login redirection */
736
+	if ( response->status_class == ISCSI_STATUS_REDIRECT ) {
737
+		DBG ( "iSCSI %p redirecting to new server\n", iscsi );
738
+		iscsi_close ( iscsi, -EINPROGRESS );
739
+		tcp_connect ( &iscsi->tcp );
740
+		return;
741
+	}
742
+
713 743
 	/* Check for fatal errors */
714 744
 	if ( response->status_class != 0 ) {
715 745
 		printf ( "iSCSI login failure: class %02x detail %02x\n",

Loading…
Cancel
Save