From: Robert W. <wrw...@us...> - 2006-12-11 18:01:27
|
Update of /cvsroot/linuxisns/iscsiClient/src In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv30127/src Modified Files: comm.c initiator.c isns.c target.c util.c Log Message: create a common config file Index: isns.c =================================================================== RCS file: /cvsroot/linuxisns/iscsiClient/src/isns.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** isns.c 11 Dec 2006 00:24:22 -0000 1.2 --- isns.c 11 Dec 2006 18:01:08 -0000 1.3 *************** *** 32,42 **** /***********************************************************************/ - /* Contribuing authors: - *Tom McSweeney <rf4...@us...>, - *Curt du Laney <du...@us...> - *IBM Research Triangle Park - * - /***********************************************************************/ - #include "isns.h" [...1288 lines suppressed...] - currentLen2=ntohl(p_attr->len); } } - else - { - currentTag=0; - } } - void - SaveDb(void) - { - ISNSCreateHdr (ISNS_SAVE_DB_REQ, &cmd, sizeof (cmd), 0); - ISNSAppendAttr (&cmd, ISNS_COMPANY_OUI, ISNS_COMPANY_OUI_SIZE, NULL, NISHAN_OUI); - ISNSSendCmd(&cmd); - } - - - --- 334,342 ---- Index: util.c =================================================================== RCS file: /cvsroot/linuxisns/iscsiClient/src/util.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** util.c 11 Dec 2006 00:42:28 -0000 1.2 --- util.c 11 Dec 2006 18:01:09 -0000 1.3 *************** *** 68,78 **** #include "util.h" #include "parse.h" - #ifdef TARGET - #include "parse.c" - #endif - - #ifdef INITIATOR - #include "parse.c" - #endif #ifndef HEX_DUMP_BYTES_PER_LINE --- 68,71 ---- *************** *** 80,87 **** #endif ! int hexDumpFlag=TRUE; int parserFlag=TRUE; - /*************************************************** _DumpHex: Prints out the contents of a ptr in hex. --- 73,79 ---- #endif ! int hexDumpFlag=FALSE; int parserFlag=TRUE; /*************************************************** _DumpHex: Prints out the contents of a ptr in hex. *************** *** 144,157 **** /***********************************************************************/ - /* Pauses until a key is pressed. */ - /***********************************************************************/ - void - WaitForKey (void) - { - printf ("Press ENTER to continue.\n"); - getchar (); - } - - /***********************************************************************/ /* Converts hex to ascii */ /***********************************************************************/ --- 136,139 ---- *************** *** 183,316 **** } - /***********************************************************************/ - /* Converts the time to hex-ascii */ - /***********************************************************************/ - void - GetHexTime (char *buffer) - { - char cstr[256]; - char two[3]; - time_t t; - - memset (cstr, 0, sizeof (cstr)); - time (&t); - strcpy (cstr, ctime (&t) + 11); - printf ("Time: %s", ctime (&t) + 11); - - memset (two, 0, sizeof (two)); - memcpy (two, cstr, 2); - sscanf (two, "%x", &buffer[0]); - - memset (two, 0, sizeof (two)); - memcpy (two, cstr + 3, 2); - sscanf (two, "%x", &buffer[1]); - - memset (two, 0, sizeof (two)); - memcpy (two, cstr + 6, 2); - sscanf (two, "%x", &buffer[2]); - - memset (two, 0, sizeof (two)); - memcpy (two, cstr + 9, 2); - sscanf (two, "%x", &buffer[3]); - - memset (two, 0, sizeof (two)); - memcpy (two, cstr + 12, 2); - sscanf (two, "%x", &buffer[4]); - } - - /***********************************************************************/ - /* Prompts for input. The input should be in ascii-hex. Stores it in - hex. */ - /***********************************************************************/ - int - GetHexInput (char *cmdLine, char *prompt, char *cDefault, int c_size) - { - char buffer[256]; - char buffer2[8]; - char two[3]; - char *ptr; - int count; - char *sptr; - - memset (buffer, 0, sizeof (buffer)); - memset (buffer2, 0, sizeof (buffer)); - memset (cmdLine, 0, c_size); - printf ("%s [%s] >", prompt, - cDefault != NULL ? HexToAscii (cDefault, 8, buffer2) : "(none)"); - fgets (buffer, sizeof(buffer), stdin); - sptr = strtok(buffer, TOKENS); - - ptr = sptr; - count = 0; - while (*ptr) - { - memset (two, 0, sizeof (two)); - memcpy (two, ptr, 2); - sscanf (two, "%x", &cmdLine[count]); - count++; - ptr = (char *) ptr + 2; - } - - return count; - } - - /***********************************************************************/ - /* Prompts for an ascii-input */ - /***********************************************************************/ - int - GetInput (char *cmdLine, char *prompt, char *cDefault, int c_size) - { - int rval; - char *sptr; - - memset (cmdLine, 0, c_size); - printf ("%s [%s] >", prompt, cDefault != NULL ? cDefault : "(none)"); - fgets (cmdLine, c_size, stdin); - sptr = strtok(cmdLine, TOKENS); - rval = sptr?strlen (sptr):0; - - return (rval); - } - - /***********************************************************************/ - /* Prompts for yes/no. Returns TRUE if yes. */ - /***********************************************************************/ - int - GetYesNo (char *cmdLine, char *prompt, int dvalue, int c_size) - { - int rval; - char *sptr; - - memset (cmdLine, 0, c_size); - printf ("%s [%s] >", prompt, dvalue == TRUE ? "*y/n" : "*n/y"); - fgets (cmdLine, c_size, stdin); - sptr = strtok(cmdLine, TOKENS); - - if (sptr == NULL || strlen (sptr) == 0) - rval = dvalue; - else if ((0 == strcmp (cmdLine, "Yes")) || - (0 == strcmp (cmdLine, "y")) || - (0 == strcmp (cmdLine, "yes")) || (0 == strcmp (cmdLine, "YES"))) - rval = TRUE; - else - rval = FALSE; - - return (rval); - } - - /***********************************************************************/ - /* Prints the commnd and returns input. */ - /***********************************************************************/ - int - GetCommand (void) - { - char buffer[256]={0}; - int item; - GetInput(buffer, "Please select an option", "0 for Help", sizeof(buffer)); - - item = atoi (buffer); - return (item); - } - - - --- 165,166 ---- Index: initiator.c =================================================================== RCS file: /cvsroot/linuxisns/iscsiClient/src/initiator.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** initiator.c 11 Dec 2006 04:27:37 -0000 1.4 --- initiator.c 11 Dec 2006 18:01:08 -0000 1.5 *************** *** 38,42 **** #include "isns.h" ! #include "initiator.h" #define CLIENT_VERSION "1.1" --- 38,42 ---- #include "isns.h" ! #include "config.h" #define CLIENT_VERSION "1.1" *************** *** 54,68 **** ********************************/ extern int isns_port; - extern struct sockaddr_in their_addr; - extern struct sockaddr_in my_addr; extern int tcpFlag; - extern SOCKET fd; extern ISNS_CMD cmd; - int - TCPReceiveMain (DWORD lparam); - /******************************** ********************************/ /***********************************************************************/ --- 54,63 ---- ********************************/ extern int isns_port; extern int tcpFlag; extern ISNS_CMD cmd; /******************************** ********************************/ + void ParseQuery (char *buffer, configuration *current); /***********************************************************************/ *************** *** 73,77 **** int c; int tcpFlag; ! initiator junk; memset (p_ip, 0, sizeof (p_ip)); --- 68,72 ---- int c; int tcpFlag; ! configuration config; memset (p_ip, 0, sizeof (p_ip)); *************** *** 99,103 **** } ! hb_flag = InitInitiator (&junk, p_ip); /* Init the Communications sockets */ --- 94,98 ---- } ! hb_flag = config_init ("init.cfg",&config, p_ip); /* Init the Communications sockets */ *************** *** 105,191 **** exit(-1); ! RegInitiator (&junk); return (0); } - /************************************************************************* *************************************************************************/ ! int InitInitiator (initiator* current, char ip[]) ! { ! FILE* InitiatorFile; ! ! current->hb_flag = TRUE; ! memset (current->InitID, (int) NULL, 256); ! memset (current->Alias, (int) NULL, 256); ! memset (current->PortalIP, (int) NULL, 256); ! current->Port = 0; ! current->portalFlag = FALSE; ! current->EntityPeriod = 0; ! memset (current->EntityID, (int) NULL, 256); ! ! /* Open the file for reading */ ! InitiatorFile = fopen ("init.cfg", "r"); ! ! /* Read in the target information */ ! ReadFile (InitiatorFile, current, ip); ! ! fclose (InitiatorFile); ! ! return current->hb_flag; ! } ! ! ! /*********************************************************************** ! Accepts a pointer to an open file and a target object - see initiator.h ! /***********************************************************************/ ! void ReadFile (FILE* ifp, initiator* thisInit, char ip_addr[]) ! { ! char temp, word[256], line[256]; ! int ii = 0; ! ! while (fscanf(ifp, "%c" , &temp) != EOF) ! { ! switch (temp) ! { ! /* This line is a comment */ ! case '*': ! fgets (line, 80, ifp); ! break; ! /* This line has the IP address of the iSNS Server */ ! case '1': ! fscanf (ifp, "%s", line); ! strcpy (ip_addr, line); ! thisInit->hb_flag = FALSE; ! break; ! /* This line has the Initiator ID and the Initiator Alias */ ! case '2': ! fscanf (ifp, "%s", line); ! strcpy (thisInit->InitID, line); ! fscanf (ifp, "%s", line); ! strcpy (thisInit->Alias, line); ! break; ! /* This line has the portal IP address and the port number */ ! case '3': ! fscanf (ifp, "%s", line); ! strcpy (thisInit->PortalIP, line); ! fscanf (ifp, "%d", &(thisInit->Port)); ! thisInit->portalFlag = TRUE; ! break; ! case '5': ! fscanf (ifp, "%d", &(thisInit->EntityPeriod)); ! break; ! ! default: ! break; ! } ! } ! } ! ! ! /************************************************************************* ! *************************************************************************/ ! void RegInitiator (initiator* current) { /* Register the initiator */ --- 100,111 ---- exit(-1); ! RegInitiator (&config); return (0); } /************************************************************************* *************************************************************************/ ! void RegInitiator (configuration *current) { /* Register the initiator */ *************** *** 207,216 **** This will register the iSCSI Initiator Node. **********************************************************************/ ! void InitiatorRegISCSI (initiator* input) { ! char buffer[2048]; ! /* type 2 means initiator */ int type = 2; ! SOIP_Ver ver; printf ("Registering ISCSI Node.\n"); --- 127,136 ---- This will register the iSCSI Initiator Node. **********************************************************************/ ! void InitiatorRegISCSI (configuration* input) { ! char buffer[2048]; ! /* type 2 means initiator */ int type = 2; ! SOIP_Ver ver; printf ("Registering ISCSI Node.\n"); *************** *** 234,255 **** ISNSAppendAttr ((struct cmd *)&cmd, ISNS_PROT_VER, 4, (char *)&ver, 0); } ! /* Add the Entity Period */ ISNSAppendAttr (&cmd, ISNS_ENTITY_PERIOD, 4, NULL, input->EntityPeriod); ! printf ("ID [%s] > %s\n", input->InitID, input->InitID); ! /* Add the Target ID to the PDU */ ! ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (input->InitID)), ! input->InitID, 0); /* Get Alias */ printf ("Alias [%s] > %s\n", input->Alias, input->Alias); ! /* Add the alias to the PDU */ ISNSAppendAttr (&cmd, ISNS_ISCSI_ALIAS, PAD4 (strlen (input->Alias)), input->Alias, 0); ! /* Add the type (iSCSI Node) to the PDU */ ISNSAppendAttr (&cmd, ISNS_ISCSI_TYPE, 4, NULL, type); --- 154,178 ---- ISNSAppendAttr ((struct cmd *)&cmd, ISNS_PROT_VER, 4, (char *)&ver, 0); } ! /* Add the Entity Period */ ISNSAppendAttr (&cmd, ISNS_ENTITY_PERIOD, 4, NULL, input->EntityPeriod); + /* Add the Entity */ + ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4 (strlen(input->EntityID)), + input->EntityID, 0); ! printf ("ID [%s] > %s\n", input->iscsiID, input->iscsiID); ! /* Add the Target ID to the PDU */ ! ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (input->iscsiID)), ! input->iscsiID, 0); /* Get Alias */ printf ("Alias [%s] > %s\n", input->Alias, input->Alias); ! /* Add the alias to the PDU */ ISNSAppendAttr (&cmd, ISNS_ISCSI_ALIAS, PAD4 (strlen (input->Alias)), input->Alias, 0); ! /* Add the type (iSCSI Node) to the PDU */ ISNSAppendAttr (&cmd, ISNS_ISCSI_TYPE, 4, NULL, type); *************** *** 260,269 **** } - - /***********************************************************************/ /* Registers a portal */ /***********************************************************************/ ! void InitiatorRegPortal (initiator* current) { int ip; --- 183,190 ---- } /***********************************************************************/ /* Registers a portal */ /***********************************************************************/ ! void InitiatorRegPortal (configuration *current) { int ip; *************** *** 310,314 **** This will query for iSCSI Node(s) that the initiator can access. ***************************************************************/ ! void GetTargets (initiator* current) { char buffer[2048]; --- 231,235 ---- This will query for iSCSI Node(s) that the initiator can access. ***************************************************************/ ! void GetTargets (configuration *current) { char buffer[2048]; *************** *** 323,330 **** ISNSCreateHdr (ISNS_DEV_ATTR_QRY_REQ, &cmd, sizeof (cmd), 0); ! ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (current->InitID)), current->InitID, 0); ! /* Get only Targets or Mixed Targets/Initiators */ ! ISNSAppendAttr (&cmd, ISNS_ISCSI_TYPE, 4, NULL, (uint32_t) 1); /* Delimiter */ --- 244,251 ---- ISNSCreateHdr (ISNS_DEV_ATTR_QRY_REQ, &cmd, sizeof (cmd), 0); ! ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (current->iscsiID)), current->iscsiID, 0); ! /* Get only Targets or Mixed Targets/Initiators */ ! ISNSAppendAttr (&cmd, ISNS_ISCSI_TYPE, 4, NULL, (uint32_t) 1); /* Delimiter */ *************** *** 353,365 **** query msg. ***********************************************/ ! void ParseQuery (char *buffer, initiator* current) { ISNS_Attr *p_attr; ISNS_HDR *pdu; char *ptr; ! char ipstring[100]; ! FILE* OutputFile; ! ! OutputFile = fopen ("Targets.txt", "w"); pdu = (struct isns_hdr *)buffer; --- 274,286 ---- query msg. ***********************************************/ ! void ParseQuery (char *buffer, configuration *current) { ISNS_Attr *p_attr; ISNS_HDR *pdu; char *ptr; ! char ipstring[100]; ! FILE* OutputFile; ! ! OutputFile = fopen ("Targets.txt", "w"); pdu = (struct isns_hdr *)buffer; Index: target.c =================================================================== RCS file: /cvsroot/linuxisns/iscsiClient/src/target.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** target.c 11 Dec 2006 04:27:37 -0000 1.4 --- target.c 11 Dec 2006 18:01:08 -0000 1.5 *************** *** 33,37 **** /***********************************************************************/ - /*********************************************************************** This file goes through the process of initializing a target --- 33,36 ---- *************** *** 48,53 **** #include "isns.h" ! #include "target.h" ! /*************************************** --- 47,51 ---- #include "isns.h" ! #include "config.h" /*************************************** *************** *** 60,71 **** ********************************/ extern int isns_port; - extern struct sockaddr_in their_addr; - extern struct sockaddr_in my_addr; extern int tcpFlag; - extern SOCKET fd; extern ISNS_CMD cmd; ! int ! TCPReceiveMain (DWORD lparam); /****************************************************************/ --- 58,65 ---- ********************************/ extern int isns_port; extern int tcpFlag; extern ISNS_CMD cmd; ! void ParseQuery (char *buffer, configuration * current); /****************************************************************/ *************** *** 77,81 **** int c; int tcpFlag; ! target junk; memset (p_ip, 0, sizeof (p_ip)); --- 71,75 ---- int c; int tcpFlag; ! configuration config; memset (p_ip, 0, sizeof (p_ip)); *************** *** 94,101 **** { case 'f': ! printf ("optarg: %s\n", optarg); strcpy (filename, optarg); ! printf ("filename: %s\n", filename); ! filename[MAX_FILENAME_SIZE - 1] = '\0'; break; --- 88,95 ---- { case 'f': ! printf ("optarg: %s\n", optarg); strcpy (filename, optarg); ! printf ("filename: %s\n", filename); ! filename[MAX_FILENAME_SIZE - 1] = '\0'; break; *************** *** 110,114 **** } ! hb_flag = Read_cfg (&junk, (char*)&p_ip); /* Init the Communications sockets */ --- 104,108 ---- } ! hb_flag = config_init (filename, &config, (char*)&p_ip); /* Init the Communications sockets */ *************** *** 118,224 **** printf ("Using iSNS IP: %s.\n", p_ip); ! RegTarget (&junk); return (0); } - - /***********************************************************************/ - /* Opens the config file, reads in the values, returns whether we are - Waiting for a heartbeat or not */ - /***********************************************************************/ - int Read_cfg (target* Target, char* ip) - { - FILE* targetFile; - - /* Set the target values to appropriate defaults */ - Target->listPtr = NULL; - Target->DDmember = 0; - Target->DDSmember = 0; - Target->Port = 0; - Target->hb_flag = TRUE; - Target->EntityPeriod = 0; - memset (Target->DDAlias, (int) NULL, 256); - memset (Target->DDSAlias, (int) NULL, 256); - memset (Target->EntityID, (int) NULL, 256); - memset (Target->PortalIP, (int) NULL, 256); - memset (Target->TargetID, (int) NULL, 256); - memset (Target->Alias, (int) NULL, 256); - memset (Target->Initiator, (int) NULL, 256); - - /* Open the file for reading */ - targetFile = fopen (filename, "r"); - - /* Read in the target information*/ - ReadFile (targetFile, Target, ip); - - fclose (targetFile); - - /* Return whether we are waiting for a heartbeat or not */ - return Target->hb_flag; - } - - /*********************************************************************** - Accepts a pointer to an open file and a target object - see target.h - /***********************************************************************/ - void ReadFile (FILE* ifp, target* thisTarget, char* ip_addr) - { - char temp, word[256], line[256]; - int ii = 0; - - while (fscanf(ifp, "%c" , &temp) != EOF) - { - switch (temp) - { - /* This line is a comment */ - case '*': - fgets (line, 80, ifp); - break; - /* This line has the IP address of the iSNS Server - it is optional*/ - case '1': - /* Read in one line */ - fgetline (ifp, line, 256); - /* copy that line into our target's IP address */ - strcpy (ip_addr, line); - /* a iSNS server IP address is specified so we do not wait for a heatbeat */ - thisTarget->hb_flag = FALSE; - break; - /* This line has the Target ID and Alias - it is mandatory */ - case '2': - fscanf (ifp, "%s", line); - strcpy (thisTarget->TargetID, line); - fscanf (ifp, "%s", line); - strcpy (thisTarget->Alias, line); - break; - /* This line has the target's portal IP address and the port number */ - case '3': - fscanf (ifp, "%s", line); - strcpy (thisTarget->PortalIP, line); - fscanf (ifp, "%d", &(thisTarget->Port)); - break; - /* This line has the name of one initiator - you can have 0 to N of these*/ - case '4': - fgetline (ifp, line, 256); - /* formating only - gets rid of a newline */ - for (ii = 0; ii < 256; ii++) - if (line[ii] == '\n') - line[ii] = '\0'; - thisTarget->listPtr = AddItem (thisTarget->listPtr, line); - break; - /* This line is an optional line. It has the Entity Period */ - case '5': - fscanf (ifp, "%d", &(thisTarget->EntityPeriod)); - break; - - default: break; - } - } - } - - - /***********************************************************************/ /***********************************************************************/ ! void RegTarget (target* holding) { /* Temporary to keep track of head of list */ --- 112,123 ---- printf ("Using iSNS IP: %s.\n", p_ip); ! RegTarget (&config); return (0); } /***********************************************************************/ /***********************************************************************/ ! void RegTarget (configuration *holding) { /* Temporary to keep track of head of list */ *************** *** 229,233 **** /* Register the portal */ ! TargetRegPortal (holding); /* Update an old or register a new DD */ --- 128,132 ---- /* Register the portal */ ! TargetRegPortal (holding); /* Update an old or register a new DD */ *************** *** 262,270 **** This will register the iSCSI Target Node. Intended for the 200i **********************************************************************/ ! void TargetRegISCSI (target* input) { ! char buffer[2048]; int type = 1; ! SOIP_Ver ver; printf ("Registering ISCSI Node.\n"); --- 161,169 ---- This will register the iSCSI Target Node. Intended for the 200i **********************************************************************/ ! void TargetRegISCSI (configuration *input) { ! char buffer[2048]; int type = 1; ! SOIP_Ver ver; printf ("Registering ISCSI Node.\n"); *************** *** 276,285 **** ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ! memset (&ver, 0, sizeof (ver)); ! /* MAX_VERSION and MIN_VERSION are global constants set above */ ! ver.max = MAX_VERSION; ! ver.min = MIN_VERSION; ! ! if (ver.max || ver.min) { ver.max = htons (ver.max); --- 175,184 ---- ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ! memset (&ver, 0, sizeof (ver)); ! /* MAX_VERSION and MIN_VERSION are global constants set above */ ! ver.max = MAX_VERSION; ! ver.min = MIN_VERSION; ! ! if (ver.max || ver.min) { ver.max = htons (ver.max); *************** *** 288,314 **** ISNSAppendAttr ((struct cmd *)&cmd, ISNS_PROT_VER, 4, (char *)&ver, 0); } - /* Add the Entity Period */ - /* Even though we don't specify an entity we can append an entity period */ - ISNSAppendAttr (&cmd, ISNS_ENTITY_PERIOD, 4, NULL, input->EntityPeriod); ! printf ("ID [%s] > %s\n", input->TargetID, input->TargetID); ! /* Add the Target ID to the PDU */ ! ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (input->TargetID)), ! input->TargetID, 0); /* Get Alias */ printf ("Alias [%s] > %s\n", input->Alias, input->Alias); ! /* Add the alias to the PDU */ ! ISNSAppendAttr (&cmd, ISNS_ISCSI_ALIAS, PAD4 (strlen (input->Alias)), ! input->Alias, 0); ! /* Add the type (iSCSI Node) to the PDU */ ISNSAppendAttr (&cmd, ISNS_ISCSI_TYPE, 4, NULL, type); ! /* Send the command, parse the response. We will get the entity ID back from this */ ! if (0 == ISNSSendCmd2 (&cmd, buffer, sizeof (buffer))) ParseQuery (buffer, input); --- 187,213 ---- ISNSAppendAttr ((struct cmd *)&cmd, ISNS_PROT_VER, 4, (char *)&ver, 0); } + /* Add the Entity ID */ + printf("EntityID is %s\n",input->EntityID); + ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4(strlen(input->EntityID)),input->EntityID,0); + + /* Add the Entity Period */ + ISNSAppendAttr (&cmd, ISNS_ENTITY_PERIOD, 4, NULL, input->EntityPeriod); ! printf ("ID [%s] > %s\n", input->iscsiID, input->iscsiID); ! /* Add the Target ID to the PDU */ ! ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen(input->iscsiID)),input->iscsiID,0); /* Get Alias */ printf ("Alias [%s] > %s\n", input->Alias, input->Alias); ! /* Add the alias to the PDU */ ! ISNSAppendAttr (&cmd, ISNS_ISCSI_ALIAS, PAD4 (strlen (input->Alias)), input->Alias, 0); ! /* Add the type (iSCSI Node) to the PDU */ ISNSAppendAttr (&cmd, ISNS_ISCSI_TYPE, 4, NULL, type); ! /* Send the command, parse the response. We will get the entity ID back from this */ if (0 == ISNSSendCmd2 (&cmd, buffer, sizeof (buffer))) ParseQuery (buffer, input); *************** *** 319,326 **** /* Registers a portal */ /***********************************************************************/ ! void TargetRegPortal (target* current) { int ip; int port_type; /* Insert Header */ --- 218,226 ---- /* Registers a portal */ /***********************************************************************/ ! void TargetRegPortal (configuration *current) { int ip; int port_type; + char buffer[2048]; /* Insert Header */ *************** *** 353,359 **** current->Port | (port_type == 1 ? 0 : 0x10000)); ! /* Send the command, don't parse the reply */ ! ISNSSendCmd (&cmd); ! } --- 253,259 ---- current->Port | (port_type == 1 ? 0 : 0x10000)); ! /* Send the command, don't parse the reply */ ! if (0 == ISNSSendCmd2 (&cmd, buffer, sizeof (buffer))) ! ParseQuery (buffer, current); } *************** *** 362,383 **** /* Registers a DD */ /*********************************************************************/ ! int TargetRegDD (target* current) { char buffer[2048]; ! int* pmember = &(current->DDmember); printf ("Registering DD.\n"); ISNSCreateHdr (ISNS_REG_DD_REQ, &cmd, sizeof (cmd), ISNS_FLAG_REPLACE_REG); ! /* The source type is iSCSI node and the name is the name of the target */ ! ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (current->TargetID)), current->TargetID, 0); ! ! /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ! /* We do not request a particular DD ID */ ! ISNSAppendAttr (&cmd, ISNS_DD_ID, 0, NULL, 0); /* The DD Symbolic Name is the Target ID */ ! ISNSAppendAttr (&cmd, ISNS_DD_SYM_NAME, PAD4 (strlen ((char*)current->TargetID)), (char*)current->TargetID, 0); if(0 == ISNSSendCmd2 (&cmd, buffer, sizeof (buffer))) --- 262,284 ---- /* Registers a DD */ /*********************************************************************/ ! int TargetRegDD (configuration *current) { char buffer[2048]; ! int* pmember = &(current->DDmember); printf ("Registering DD.\n"); ISNSCreateHdr (ISNS_REG_DD_REQ, &cmd, sizeof (cmd), ISNS_FLAG_REPLACE_REG); + /* The source type is iSCSI node and the name is the name of the target */ + ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (current->iscsiID)), current->iscsiID, 0); ! /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ! ! /* We do not request a particular DD ID */ ! ISNSAppendAttr (&cmd, ISNS_DD_ID, 0, NULL, 0); ! /* The DD Symbolic Name is the Target ID */ ! ISNSAppendAttr (&cmd, ISNS_DD_SYM_NAME, PAD4 (strlen ((char*)current->iscsiID)), (char*)current->iscsiID, 0); if(0 == ISNSSendCmd2 (&cmd, buffer, sizeof (buffer))) *************** *** 391,395 **** /* Registers DDS */ /*********************************************************************/ ! int TargetRegDDS (target* current) { char buffer[2048]={0}; --- 292,296 ---- /* Registers DDS */ /*********************************************************************/ ! int TargetRegDDS (configuration *current) { char buffer[2048]={0}; *************** *** 403,408 **** /* The source type is iSCSI node and the name is the name of the target */ ! ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (current->TargetID)), ! current->TargetID, 0); /* Delimiter */ --- 304,309 ---- /* The source type is iSCSI node and the name is the name of the target */ ! ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (current->iscsiID)), ! current->iscsiID, 0); /* Delimiter */ *************** *** 413,417 **** /* The DDS Symbolic Name is the Target ID */ ! ISNSAppendAttr (&cmd, ISNS_DDS_SYM_NAME, PAD4 (strlen ((char*)current->TargetID)), (char*)current->TargetID, 0); /* Turn the status to ON by default */ --- 314,318 ---- /* The DDS Symbolic Name is the Target ID */ ! ISNSAppendAttr (&cmd, ISNS_DDS_SYM_NAME, PAD4 (strlen ((char*)current->iscsiID)), (char*)current->iscsiID, 0); /* Turn the status to ON by default */ *************** *** 427,431 **** /* Adds a DD to a DDS */ /*********************************************************************/ ! void TargetAdd_DD_to_DDS (target* current) { listelement* temp; --- 328,332 ---- /* Adds a DD to a DDS */ /*********************************************************************/ ! void TargetAdd_DD_to_DDS (configuration *current) { listelement* temp; *************** *** 452,456 **** This will add the iSCSI target node to the DD. *****************************************************/ ! void TargetAdd_ISCSI_to_DD (target* current) { char buffer[2048]; --- 353,357 ---- This will add the iSCSI target node to the DD. *****************************************************/ ! void TargetAdd_ISCSI_to_DD (configuration *current) { char buffer[2048]; *************** *** 475,479 **** /* Add the target ID */ ! ISNSAppendAttr (&cmd, ISNS_DD_ISCSI_MEMBER, PAD4 (strlen (current->TargetID)), current->TargetID, 0); /* Send the command, do not parse the reply */ --- 376,380 ---- /* Add the target ID */ ! ISNSAppendAttr (&cmd, ISNS_DD_ISCSI_MEMBER, PAD4 (strlen (current->iscsiID)), current->iscsiID, 0); /* Send the command, do not parse the reply */ *************** *** 486,490 **** This will add the iSCSI initiator node(s) to a DD. *****************************************************/ ! void TargetAdd_ISCSI_to_DD2 (target* current) { char buffer[2048]; --- 387,391 ---- This will add the iSCSI initiator node(s) to a DD. *****************************************************/ ! void TargetAdd_ISCSI_to_DD2 (configuration *current) { char buffer[2048]; *************** *** 516,520 **** /* Parses a Query Response */ /*********************************************************************/ ! void ParseQuery (char *buffer, target* current) { ISNS_Attr *p_attr; --- 417,421 ---- /* Parses a Query Response */ /*********************************************************************/ ! void ParseQuery (char *buffer, configuration *current) { ISNS_Attr *p_attr; *************** *** 585,603 **** } - - /*****************************************************************/ - /*****************************************************************/ - int fgetline(FILE *fp, char s[], int lim) - { - int c, i; - - for (i = 0; i < lim-1 && (c = fgetc(fp)) != EOF && c != '\n'; i++) - s[i-1] = c; - - while (i < lim - 1) - s[i++ - 1] = '\0'; - - - return i; - } - --- 486,487 ---- Index: comm.c =================================================================== RCS file: /cvsroot/linuxisns/iscsiClient/src/comm.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** comm.c 11 Dec 2006 00:42:28 -0000 1.2 --- comm.c 11 Dec 2006 18:01:08 -0000 1.3 *************** *** 31,59 **** / /***********************************************************************/ - - /* Contribuing authors: - *Tom McSweeney <rf4...@us...>, - *Curt du Laney <du...@us...> - *IBM Research Triangle Park - * - /***********************************************************************/ #include <stdlib.h> ! #include <stdio.h> ! #include "isns.h" - - #ifndef SNS_LINUX - #include <io.h> - #include <winsock2.h> - #include <Ws2tcpip.h> - #else - #define Sleep(a) sleep(a) - #endif - - #include <time.h> - #include "util.h" #include "comm.h" - #include "parse.h" MSG_CB msg_q[MSG_Q_SIZE]; /* TCP msg Q */ --- 31,39 ---- / /***********************************************************************/ #include <stdlib.h> ! #include <time.h> #include "isns.h" #include "comm.h" MSG_CB msg_q[MSG_Q_SIZE]; /* TCP msg Q */ *************** *** 62,69 **** int msgCurrentHead = 0; - #ifndef SNS_LINUX - WSADATA g_WsaData; - #endif - SOCKET fd; --- 42,45 ---- *************** *** 89,99 **** { tcpFlag=t_flag; - #ifndef SNS_LINUX - /* Start up the winsock proprietary Stuff */ - if (WSAStartup (MAKEWORD (0x02, 0x00), &g_WsaData) == SOCKET_ERROR) - { - exit(-1); - } - #endif if (hb_flag) --- 65,68 ---- *************** *** 133,145 **** /* Spawn TCP Recv Thread*/ { - #ifdef SNS_LINUX pthread_t junk; if (0 != pthread_create (&junk, NULL, (void*) (TCPReceiveMain) , NULL)) printf ("\n\nThread Creation Failed!\n\n"); - #else - DWORD junk; - CreateThread ((LPSECURITY_ATTRIBUTES)0, 0, (LPTHREAD_START_ROUTINE) TCPReceiveMain, NULL, 0, &junk); - Sleep (10); - #endif } --- 102,108 ---- *************** *** 240,244 **** { /* Loops until we receive a msg */ ! Sleep (1); } --- 203,207 ---- { /* Loops until we receive a msg */ ! sleep (1); } *************** *** 299,358 **** /***********************************************************************/ - /* This will send a PDU and wait for a rsp. The rsp will be ignored. */ - /***********************************************************************/ - extern void ParsePDU (char* buffer); - int - ISNSSendCmd (ISNS_CMD * cmd) - { - int e; - char buffer[1500]; - int len = cmd->hdr.len + sizeof (ISNS_HDR); - int errorCode; - - cmd->hdr.len = htons (cmd->hdr.len); - e = SendPDU (cmd, len); - if (e < 0) - { - printf ("Error Sending.\n"); - return (e); - } - printf("PDU sent-->\n"); - DumpHex (cmd, len); - len = sizeof (their_addr); - e = RcvPDU ((struct cmd *)buffer, sizeof (buffer)); - if (e < 0) - { - printf ("Error Receiving.\n"); - } - printf("PDU rcv-->\n"); - DumpHex (buffer, e); - - { - char *ptr = (char *) buffer + sizeof (ISNS_HDR); - errorCode = ntohl (*(uint32_t *) ptr); - } - if (errorCode != 0) - { - printf ("***WARNING: iSNS returned an error, error=%#x, \"%s\"\n", errorCode, errorText(errorCode)); - } - else - { - ISNS_HDR *p_cmd; - - p_cmd = (struct isns_hdr *)buffer; - - /* Convert fields */ - p_cmd->flags = ntohs (p_cmd->flags); - p_cmd->func_id = ntohs (p_cmd->func_id); - p_cmd->len = ntohs (p_cmd->len); - p_cmd->seq = ntohs (p_cmd->seq); - p_cmd->version = ntohs (p_cmd->version); - p_cmd->xid = ntohs (p_cmd->xid); - } - - return (errorCode); - } - - /***********************************************************************/ /* This will send a PDU and wait for a rsp. The rsp will be returned. */ /***********************************************************************/ --- 262,265 ---- *************** *** 527,535 **** if (iRet < 0) { printf ("setsockopt() IP_ADD_MEMBERSHIP failed, Err: %d\n", - #ifdef SNS_LINUX 0); - #else - WSAGetLastError()); - #endif } --- 434,438 ---- *************** *** 580,588 **** /* Thread used for listening and responding to UDP ESI/SCN messages. */ /***********************************************************************/ - #ifdef SNS_LINUX int - #else - DWORD WINAPI - #endif ESIListener (DWORD lparam) { --- 483,487 ---- *************** *** 686,722 **** } } - /***********************************************************************/ - /* Sends an ESI response message. */ - /***********************************************************************/ - void - SendESIRsp (void) - { - char cmdLine[256]; - ISNS_CMD cmd; - - memset (cmdLine, 0, sizeof (cmdLine)); - - printf ("Sending ESI Response.\n"); - ISNSCreateHdr (ISNS_REG_DEV_ATTR_REQ, &cmd, sizeof (cmd), 0); - /* Get an entity ID */ - if (0 == GetInput(cmdLine, "Entity ID", NULL, sizeof(cmdLine))) - { - printf ("***ERROR: Cmd Line required.\n"); - exit (-1); - } - - ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4 (strlen (cmdLine)), cmdLine, 0); - - ISNSJustSendCmd (&cmd); - } /***********************************************************************/ /* Thread used to receive ALL TCP messages */ /***********************************************************************/ - #ifdef SNS_LINUX int - #else - DWORD WINAPI - #endif TCPReceiveMain (DWORD lparam) { --- 585,593 ---- *************** *** 777,780 **** --- 648,652 ---- } } + /***********************************************************************/ /* Used to retrieve messages from the TCP message Q. */ |