Update of /cvsroot/linuxisns/isnsNT/isnsclient/src In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv4250/src Modified Files: custom.c entity.c fcnode.c ifcp.c iscsi.c isns.c parse.c payloads.c portal.c util.c Log Message: move functions to correct modules Index: payloads.c =================================================================== RCS file: /cvsroot/linuxisns/isnsNT/isnsclient/src/payloads.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** payloads.c 23 Aug 2007 02:50:20 -0000 1.6 --- payloads.c 23 Aug 2007 05:21:00 -0000 1.7 *************** *** 34,40 **** #include "comm.h" #include "util.h" ! #include "iscsi.h" ! #include "entity.h" ! #include "portal.h" static ISNS_CMD cmd; --- 34,38 ---- #include "comm.h" #include "util.h" ! #include "parse.h" static ISNS_CMD cmd; Index: portal.c =================================================================== RCS file: /cvsroot/linuxisns/isnsNT/isnsclient/src/portal.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** portal.c 23 Aug 2007 04:00:52 -0000 1.11 --- portal.c 23 Aug 2007 05:21:00 -0000 1.12 *************** *** 34,37 **** --- 34,38 ---- #include "comm.h" #include "util.h" + #include "parse.h" static ISNS_CMD cmd; *************** *** 96,163 **** /***********************************************************************/ - /* Parses a portal response */ - /***********************************************************************/ - void - ParsePortalQuery (char *buffer) - { - ISNS_Attr *p_attr; - ISNS_HDR *pdu; - char *ptr; - - pdu = (struct isns_hdr *)buffer; - ptr = buffer + sizeof (ISNS_HDR) + 4; - while (ptr < buffer + sizeof (ISNS_HDR) + pdu->len) - { - p_attr = (struct ISNS_attr *)ptr; - p_attr->tag = htonl (p_attr->tag); - p_attr->len = htonl (p_attr->len); - switch (p_attr->tag) - { - case ISNS_PORTAL_IP: - { - struct in_addr ip; - printf ("---------------------------------\n"); - ip.s_addr = *(uint32_t *) ((char *) &p_attr->val + 12); - printf ("Portal IP : %s.\n", inet_ntoa (ip)); - } - break; - case ISNS_PORTAL_PORT: - p_attr->val.etype = ntohl (p_attr->val.etype); - printf ("Portal Port : %d.\n", p_attr->val.etype & 0xFFFF); - printf ("Portal Type : %s.\n", - p_attr->val.etype & 0x10000 ? "UDP" : "TCP"); - break; - case ISNS_PORTAL_SYM_NAME: - printf ("Portal Sym Name: %s\n",(char *)&p_attr->val); - break; - case ISNS_ENTITY_ID: - printf ("Entity ID : %s\n",(char *)&p_attr->val); - break; - case ISNS_ENTITY_IDX: - p_attr->val.etype = ntohl (p_attr->val.etype); - printf ("Entity Index: %d.\n", p_attr->val.etype); - break; - case ISNS_ESI_PORT: - p_attr->val.etype = ntohl (p_attr->val.etype); - printf ("ESI/SCN UDP Port : %d.\n", p_attr->val.etype & 0xFFFF); - break; - case ISNS_ESI_INTERVAL: - p_attr->val.etype = ntohl (p_attr->val.etype); - printf ("ESI Interval : %d.\n", p_attr->val.etype); - break; - case ISNS_PORTAL_IDX: - p_attr->val.etype = ntohl (p_attr->val.etype); - printf ("Portal Index: %d.\n", p_attr->val.etype); - break; - case ISNS_DELIMITER: - break; - default: - break; - } - ptr = (char *) ptr + p_attr->len + 8; - } - } - - /***********************************************************************/ /* Queries for portals */ /***********************************************************************/ --- 97,100 ---- Index: fcnode.c =================================================================== RCS file: /cvsroot/linuxisns/isnsNT/isnsclient/src/fcnode.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** fcnode.c 14 Aug 2007 03:43:55 -0000 1.4 --- fcnode.c 23 Aug 2007 05:21:00 -0000 1.5 *************** *** 34,37 **** --- 34,38 ---- #include "comm.h" #include "util.h" + #include "parse.h" extern int replaceFlag; Index: iscsi.c =================================================================== RCS file: /cvsroot/linuxisns/isnsNT/isnsclient/src/iscsi.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** iscsi.c 23 Aug 2007 02:50:20 -0000 1.11 --- iscsi.c 23 Aug 2007 05:21:00 -0000 1.12 *************** *** 37,40 **** --- 37,41 ---- #include "comm.h" #include "util.h" + #include "parse.h" static ISNS_CMD cmd; /* Used for msgs */ *************** *** 373,460 **** } - /*********************************************** - This will parse the response msg from an iSCSI - query msg. - ***********************************************/ - void - ParseISCSIQuery (char *buffer) - { - ISNS_Attr *p_attr; - ISNS_HDR *pdu; - char *ptr; - - pdu = (struct isns_hdr *)buffer; - ptr = buffer + sizeof (ISNS_HDR) + 4 /* Error Code Length */; - - while (ptr < (char *) buffer + sizeof (ISNS_HDR) + pdu->len) - { - p_attr = (struct ISNS_attr *)ptr; - p_attr->tag = htonl (p_attr->tag); - p_attr->len = htonl (p_attr->len); - /*Attributes can come back in any order */ - switch (p_attr->tag) - { - case ISNS_ISCSI_NODE_ID: - printf ("---------------------------------\n"); - printf ("iSCSI ID : %s\n",(char *)&p_attr->val); - break; - case ISNS_ISCSI_IDX: - p_attr->val.etype = ntohl (p_attr->val.etype); - printf ("iSCSI Index: %d\n", p_attr->val.etype); - break; - case ISNS_ISCSI_TYPE: - p_attr->val.etype = ntohl (p_attr->val.etype); - printf ("Type: %#x (", p_attr->val.etype); - if (p_attr->val.etype & 1) - printf ("Target"); - if (p_attr->val.etype & 2) - printf ("Initiator"); - printf (")\n"); - break; - case ISNS_ISCSI_ALIAS: - printf ("Alias : %s\n",(char *)&p_attr->val); - break; - case ISNS_DD_ID: - p_attr->val.etype = ntohl (p_attr->val.etype); - printf ("DD ID : %d\n", p_attr->val.etype); - break; - case ISNS_ENTITY_ID: - printf ("Entity ID : %s\n",(char *)&p_attr->val); - break; - case ISNS_ENTITY_IDX: - p_attr->val.etype = ntohl (p_attr->val.etype); - printf ("Entity Idx : %d\n", p_attr->val.etype); - break; - case ISNS_PORTAL_IP: - { - struct in_addr ip; - ip.s_addr = *(uint32_t *) ((char *) &p_attr->val + 12); - printf ("Portal IP : %s.\n", inet_ntoa (ip)); - } - break; - case ISNS_PORTAL_PORT: - p_attr->val.etype = ntohl (p_attr->val.etype); - printf ("Portal Port : %d.\n", p_attr->val.etype & 0xFFFF); - printf ("Portal Type : %s.\n", - p_attr->val.etype & 0x10000 ? "UDP" : "TCP"); - break; - - case ISNS_PORTAL_IDX: - p_attr->val.etype = ntohl (p_attr->val.etype); - printf ("Portal Idx : %d\n", p_attr->val.etype); - break; - case ISNS_PROT_VER: - p_attr->val.ver.max = ntohs (p_attr->val.ver.max); - p_attr->val.ver.min = ntohs (p_attr->val.ver.min); - printf ("Version: Max=%d, Min=%d.\n", p_attr->val.ver.max, - p_attr->val.ver.min); - break; - default: - break; - } - ptr = (char *) ptr + p_attr->len + 8/* Size of tag and length fields*/; - } - } - /***************************************************** This will add an iSCSI node to a DD. --- 374,377 ---- Index: isns.c =================================================================== RCS file: /cvsroot/linuxisns/isnsNT/isnsclient/src/isns.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** isns.c 23 Aug 2007 04:00:52 -0000 1.13 --- isns.c 23 Aug 2007 05:21:00 -0000 1.14 *************** *** 34,37 **** --- 34,38 ---- #include "comm.h" #include "util.h" + #include "parse.h" *************** *** 39,43 **** static ISNS_CMD cmd; /* Used by functions for msgs. */ - static int currentXid = 0; /* current XID */ int enableESIFlag; /* Set to non-zero when enable ESI reponse. */ --- 40,43 ---- *************** *** 54,82 **** - /* Generates a new transaction id (xid) */ - static int - GetXid (void) - { - currentXid++; - - return (currentXid); - - } - /*********************************************************************/ - /* Zeros out the message and puts a hdr in */ - /*********************************************************************/ - void - ISNSCreateHdr (ISNS_FUNC_ID func_id, ISNS_CMD * cmd, int b_size, int flags) - { - memset (cmd, 0, b_size); - cmd->hdr.len = 0; - cmd->hdr.flags = - htons ((short)(flags | ISNS_FLAG_FIRST_PDU | ISNS_FLAG_LAST_PDU | - ISNS_FLAG_SND_CLIENT)); - cmd->hdr.version = htons ((short)ISNSP_VERSION); - cmd->hdr.func_id = htons ((short)func_id); - cmd->hdr.xid = htons ((short)GetXid ()); - } - /*********************************************************************/ /* Same as ISNSCreateHdr() but also zeros out the src field */ --- 54,57 ---- *************** *** 91,236 **** /*********************************************************************/ - /* Appends an attribute to a msg. Does the necessary, byte - conversions */ - /*********************************************************************/ - void - ISNSAppendAttr (ISNS_CMD * cmd, ISNS_TAG tag, int len, char *ptr, int val) - { - ISNS_TLV_P tlvp = (ISNS_TLV_P)((char *) cmd + cmd->hdr.len + sizeof (ISNS_HDR)); - - /* Attr */ - tlvp->attrib_id = htonl (tag); - tlvp->attrib_len = htonl (len); - if (ptr != NULL) - memcpy (&tlvp->attrib_val, ptr, len); - else - { - switch (len) - { - case 0: - break; - case 2: - *(uint16_t *) & tlvp->attrib_val = htons ((short)val); - break; - case 4: - *(uint32_t *) & tlvp->attrib_val = htonl (val); - break; - default: - break; - } - } - cmd->hdr.len += ISNS_TAG_LEN + ISNS_LEN_LEN + len; - } - - /*********************************************************************/ - /* Appends the SRC field */ - /*********************************************************************/ - int - GetSrc (ISNS_CMD * p_cmd, int flags) - { - char cmdLine[256]; - int src_type; - - src_type = 0; - if (0 != GetInput (cmdLine,"SRC type", - "*1:Control Node 2:iSCSI Node 3:iFCP Node", sizeof (cmdLine))) - { - src_type = atoi (cmdLine); - } - - switch (src_type) - { - case 0: - ISNSAppendAttr (p_cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (CONTROL_NODE)),CONTROL_NODE, 0); - break; - - case 1: - if (0 == GetInput (cmdLine, "SRC: Control Node Id", "(none)",sizeof (cmdLine))) - { - printf ("***ERROR: You must enter an Node Id.\n"); - return (-1); - } - - ISNSAppendAttr (p_cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (cmdLine)),cmdLine, 0); - - break; - - case 2: - if (0 == GetInput (cmdLine, "SRC: iSCSI Node Id", "(none)", sizeof (cmdLine))) - { - printf ("***ERROR: You must enter an iSCSI Node Id.\n"); - return (-1); - } - - ISNSAppendAttr (p_cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (cmdLine)),cmdLine, 0); - - break; - - case 3: - if (0 == GetHexInput (cmdLine, "SRC: iFCP Node WWPN", NULL, sizeof (cmdLine))) - { - printf ("***ERROR: You must enter an iFCP Node WWPN.\n"); - return (-1); - } - ISNSAppendAttr (p_cmd, ISNS_PORT_NAME, 8, cmdLine, 0); - - break; - default: - return (-1); - } - - return (0); - } - - - /*********************************************************************/ - /* Parses a DDS Query */ - /*********************************************************************/ - void - ParseDDSQuery (char *buffer) - { - ISNS_Attr *p_attr; - ISNS_HDR *pdu; - char *ptr; - - pdu = (struct isns_hdr *)buffer; - ptr = buffer + sizeof (ISNS_HDR) + 4; - while (ptr < buffer + sizeof (ISNS_HDR) + pdu->len) - { - p_attr = (struct ISNS_attr *)ptr; - p_attr->tag = ntohl (p_attr->tag); - p_attr->len = ntohl (p_attr->len); - switch (p_attr->tag) - { - case ISNS_DDS_ID: - printf ("---------------------------------\n"); - p_attr->val.etype = ntohl (p_attr->val.etype); - printf ("DDS ID : %d\n", p_attr->val.etype); - break; - case ISNS_DDS_SYM_NAME: - printf ("DDS Sym Name : %s\n",(char *)&p_attr->val); - break; - case ISNS_DDS_STATUS: - p_attr->val.etype = ntohl (p_attr->val.etype); - printf ("Status: %s\n", p_attr->val.etype?"Active":"Disabled"); - break; - case ISNS_DD_ID: - p_attr->val.etype = ntohl (p_attr->val.etype); - printf (" DD ID : %d\n", p_attr->val.etype); - break; - case ISNS_DD_SYM_NAME: - printf (" DD Sym Name : %s\n",(char *)&p_attr->val); - break; - case ISNS_DD_ACTIVE: - p_attr->val.etype = ntohl (p_attr->val.etype); - printf ("Status: %s\n", p_attr->val.etype?"Active":"Disabled"); - default: - break; - } - ptr = (char *) ptr + p_attr->len + 8; - } - } - - /*********************************************************************/ /* Queries for DDS */ /*********************************************************************/ --- 66,69 ---- *************** *** 299,360 **** ParseDDSQuery (buffer); } - /*********************************************************************/ - /* Parses a DD Query Response */ - /*********************************************************************/ - void - ParseDDQuery (char *buffer) - { - ISNS_Attr *p_attr; - ISNS_HDR *pdu; - char *ptr; - - pdu = (struct isns_hdr *)buffer; - ptr = buffer + sizeof (ISNS_HDR) + 4; - if (pdu->len > MAX_PAYLOAD_SIZE) - printf("ERROR pdu->len:%d\n",pdu->len); - - while (ptr < (buffer + sizeof (ISNS_HDR) + pdu->len) ) - { - p_attr = (struct ISNS_attr *)ptr; - p_attr->tag = ntohl (p_attr->tag); - p_attr->len = ntohl (p_attr->len); - switch (p_attr->tag) - { - case ISNS_DD_ID: - printf ("---------------------------------\n"); - p_attr->val.etype = ntohl (p_attr->val.etype); - printf ("DD ID : %d\n", p_attr->val.etype); - break; - case ISNS_DD_SYM_NAME: - printf ("DD Sym Name : %s\n",(char *)&p_attr->val); - break; - case ISNS_DDS_ID: - p_attr->val.etype = ntohl (p_attr->val.etype); - printf (" DDS ID : %d\n", p_attr->val.etype); - break; - case ISNS_DDS_SYM_NAME: - printf (" DDS Sym Name : %s\n",(char *)&p_attr->val); - break; - case ISNS_DD_ISCSI_MEMBER_IDX: - p_attr->val.etype = ntohl (p_attr->val.etype); - printf (" DD iSCSI Member Index : %d\n", p_attr->val.etype); - break; - case ISNS_DD_ISCSI_MEMBER: - printf (" DD iSCSI Member : %s\n",(char *)&p_attr->val); - break; - case ISNS_DD_IFCP_MEMBER: - { - char buffer2[256]; - memset (buffer2, 0, sizeof (buffer2)); - printf (" iFCP WWPN : %s\n", - HexToAscii ((char *)&p_attr->val, p_attr->len, buffer2)); - break; - } - default: - break; - } - ptr = (char *) ptr + p_attr->len + 8; - } - } /*********************************************************************/ --- 132,135 ---- *************** *** 428,431 **** --- 203,207 ---- ParseDDQuery (buffer); } + /*********************************************************************/ /* Registers DDS */ *************** *** 993,1041 **** /*********************************************************************/ - /* Parses an ESI */ - /*********************************************************************/ - void - ParseESI (char *buffer) - { - ISNS_Attr *p_attr; - ISNS_HDR *pdu; - char *ptr; - - printf ("Parsing ESI.\n"); - pdu = (struct isns_hdr *)buffer; - ptr = buffer + sizeof (ISNS_HDR); - pdu->len = htons (pdu->len); - while (ptr < (char *) buffer + sizeof (ISNS_HDR) + pdu->len) - { - p_attr = (struct ISNS_attr *)ptr; - p_attr->tag = ntohl (p_attr->tag); - p_attr->len = ntohl (p_attr->len); - switch (p_attr->tag) - { - case ISNS_ENTITY_ID: - printf ("---------------------------------\n"); - printf ("Entity ID : %s\n",(char *)&p_attr->val); - break; - case ISNS_PORTAL_IP: - { - struct in_addr ip; - ip.s_addr = *(uint32_t *) ((char *) &p_attr->val + 12); - printf ("Portal IP : %s.\n", inet_ntoa (ip)); - } - break; - case ISNS_PORTAL_PORT: - p_attr->val.etype = ntohl (p_attr->val.etype); - printf ("Portal Port : %d.\n", p_attr->val.etype & 0xFFFF); - printf ("Portal Port Type : %s.\n", - p_attr->val.etype & 0x10000 ? "UDP" : "TCP"); - break; - default: - break; - } - ptr = (char *) ptr + p_attr->len + 8; - } - } - - /*********************************************************************/ /* Sends an ESI response */ /*********************************************************************/ --- 769,772 ---- Index: util.c =================================================================== RCS file: /cvsroot/linuxisns/isnsNT/isnsclient/src/util.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** util.c 2 Feb 2007 23:21:38 -0000 1.5 --- util.c 23 Aug 2007 05:21:00 -0000 1.6 *************** *** 276,279 **** --- 276,338 ---- } + /*********************************************************************/ + /* Get the =SRC field */ + /*********************************************************************/ + int + GetSrc (ISNS_CMD * p_cmd, int flags) + { + char cmdLine[256]; + int src_type; + + src_type = 0; + if (0 != GetInput (cmdLine,"SRC type", + "*1:Control Node 2:iSCSI Node 3:iFCP Node", sizeof (cmdLine))) + { + src_type = atoi (cmdLine); + } + + switch (src_type) + { + case 0: + ISNSAppendAttr (p_cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (CONTROL_NODE)),CONTROL_NODE, 0); + break; + + case 1: + if (0 == GetInput (cmdLine, "SRC: Control Node Id", "(none)",sizeof (cmdLine))) + { + printf ("***ERROR: You must enter an Node Id.\n"); + return (-1); + } + + ISNSAppendAttr (p_cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (cmdLine)),cmdLine, 0); + + break; + + case 2: + if (0 == GetInput (cmdLine, "SRC: iSCSI Node Id", "(none)", sizeof (cmdLine))) + { + printf ("***ERROR: You must enter an iSCSI Node Id.\n"); + return (-1); + } + + ISNSAppendAttr (p_cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (cmdLine)),cmdLine, 0); + + break; + + case 3: + if (0 == GetHexInput (cmdLine, "SRC: iFCP Node WWPN", NULL, sizeof (cmdLine))) + { + printf ("***ERROR: You must enter an iFCP Node WWPN.\n"); + return (-1); + } + ISNSAppendAttr (p_cmd, ISNS_PORT_NAME, 8, cmdLine, 0); + + break; + default: + return (-1); + } + + return (0); + } Index: entity.c =================================================================== RCS file: /cvsroot/linuxisns/isnsNT/isnsclient/src/entity.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** entity.c 23 Aug 2007 04:00:52 -0000 1.11 --- entity.c 23 Aug 2007 05:21:00 -0000 1.12 *************** *** 34,37 **** --- 34,38 ---- #include "comm.h" #include "util.h" + #include "parse.h" *************** *** 85,152 **** /***********************************************************************/ - /* Parses an entity query response */ - /***********************************************************************/ - void - ParseEntityQuery (char *buffer) - { - ISNS_Attr *p_attr; - ISNS_HDR *pdu; - char *ptr; - - pdu = (struct isns_hdr *)buffer; - ptr = buffer + sizeof (ISNS_HDR) + 4; - while (ptr < buffer + sizeof (ISNS_HDR) + pdu->len) - { - p_attr = (struct ISNS_attr *)ptr; - p_attr->tag = htonl (p_attr->tag); - p_attr->len = htonl (p_attr->len); - switch (p_attr->tag) - { - case ISNS_ENTITY_ID: - printf ("---------------------------------\n"); - printf ("Entity ID : %s\n",(char *)&p_attr->val); - break; - case ISNS_ENTITY_TYPE: - p_attr->val.etype = ntohl (p_attr->val.etype); - printf ("Entity Type: %d\n", p_attr->val.etype); - break; - case ISNS_MGMT_IP: - { - struct in_addr ip; - ip.s_addr = *(uint32_t *) ((char *) &p_attr->val + 12); - printf ("Mgmt IP: %s.\n", inet_ntoa (ip)); - } - break; - case ISNS_TIMESTAMP: - { - time_t timevalue; - timevalue = ntohl (p_attr->val.timestamp.t_time); - printf ("TimeStamp: %s", ctime (&timevalue)); - break; - } - case ISNS_PROT_VER: - p_attr->val.ver.max = ntohs (p_attr->val.ver.max); - p_attr->val.ver.min = ntohs (p_attr->val.ver.min); - printf ("Version: Max=%d, Min=%d.\n", p_attr->val.ver.max, - p_attr->val.ver.min); - break; - case ISNS_ENTITY_PERIOD: - p_attr->val.etype = ntohl (p_attr->val.etype); - printf ("Period: %d secs.\n", p_attr->val.etype); - break; - case ISNS_ENTITY_IDX: - p_attr->val.etype = ntohl (p_attr->val.etype); - printf ("Entity Index: %d.\n", p_attr->val.etype); - break; - case ISNS_DELIMITER: - break; - default: - break; - } - ptr = (char *) ptr + p_attr->len + 8; - } - } - - /***********************************************************************/ /* Queries for entities */ /***********************************************************************/ --- 86,89 ---- Index: parse.c =================================================================== RCS file: /cvsroot/linuxisns/isnsNT/isnsclient/src/parse.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** parse.c 13 Aug 2007 22:56:44 -0000 1.8 --- parse.c 23 Aug 2007 05:21:00 -0000 1.9 *************** *** 32,37 **** --- 32,100 ---- ***********************************************************************/ #include "isns.h" + #include "util.h" #include "parse.h" + static int currentXid = 0; + + /* Generates a new transaction id (xid) */ + static int + GetXid (void) + { + currentXid++; + + return (currentXid); + + } + + /*********************************************************************/ + /* Zeros out the message and puts a hdr in */ + /*********************************************************************/ + void + ISNSCreateHdr (ISNS_FUNC_ID func_id, ISNS_CMD * cmd, int b_size, int flags) + { + memset (cmd, 0, b_size); + cmd->hdr.len = 0; + cmd->hdr.flags = + htons ((short)(flags | ISNS_FLAG_FIRST_PDU | ISNS_FLAG_LAST_PDU | + ISNS_FLAG_SND_CLIENT)); + cmd->hdr.version = htons ((short)ISNSP_VERSION); + cmd->hdr.func_id = htons ((short)func_id); + cmd->hdr.xid = htons ((short)GetXid ()); + } + + /*********************************************************************/ + /* Appends an attribute to a msg. Does the necessary, byte + conversions */ + /*********************************************************************/ + void + ISNSAppendAttr (ISNS_CMD * cmd, ISNS_TAG tag, int len, char *ptr, int val) + { + ISNS_TLV_P tlvp = (ISNS_TLV_P)((char *) cmd + cmd->hdr.len + sizeof (ISNS_HDR)); + + /* Attr */ + tlvp->attrib_id = htonl (tag); + tlvp->attrib_len = htonl (len); + if (ptr != NULL) + memcpy (&tlvp->attrib_val, ptr, len); + else + { + switch (len) + { + case 0: + break; + case 2: + *(uint16_t *) & tlvp->attrib_val = htons ((short)val); + break; + case 4: + *(uint32_t *) & tlvp->attrib_val = htonl (val); + break; + default: + break; + } + } + cmd->hdr.len += ISNS_TAG_LEN + ISNS_LEN_LEN + len; + } + + void ipaddrchar(void * ipaddrhex, void * ipaddrstr) { *************** *** 346,349 **** --- 409,780 ---- + /******************************************************************** + * Functions to parse and print query results + *********************************************************************/ + + /***********************************************************************/ + /* Parses an entity query response */ + /***********************************************************************/ + void + ParseEntityQuery (char *buffer) + { + ISNS_Attr *p_attr; + ISNS_HDR *pdu; + char *ptr; + + pdu = (struct isns_hdr *)buffer; + ptr = buffer + sizeof (ISNS_HDR) + 4; + while (ptr < buffer + sizeof (ISNS_HDR) + pdu->len) + { + p_attr = (struct ISNS_attr *)ptr; + p_attr->tag = htonl (p_attr->tag); + p_attr->len = htonl (p_attr->len); + switch (p_attr->tag) + { + case ISNS_ENTITY_ID: + printf ("---------------------------------\n"); + printf ("Entity ID : %s\n",(char *)&p_attr->val); + break; + case ISNS_ENTITY_TYPE: + p_attr->val.etype = ntohl (p_attr->val.etype); + printf ("Entity Type: %d\n", p_attr->val.etype); + break; + case ISNS_MGMT_IP: + { + struct in_addr ip; + ip.s_addr = *(uint32_t *) ((char *) &p_attr->val + 12); + printf ("Mgmt IP: %s.\n", inet_ntoa (ip)); + } + break; + case ISNS_TIMESTAMP: + { + time_t timevalue; + timevalue = ntohl (p_attr->val.timestamp.t_time); + printf ("TimeStamp: %s", ctime (&timevalue)); + break; + } + case ISNS_PROT_VER: + p_attr->val.ver.max = ntohs (p_attr->val.ver.max); + p_attr->val.ver.min = ntohs (p_attr->val.ver.min); + printf ("Version: Max=%d, Min=%d.\n", p_attr->val.ver.max, + p_attr->val.ver.min); + break; + case ISNS_ENTITY_PERIOD: + p_attr->val.etype = ntohl (p_attr->val.etype); + printf ("Period: %d secs.\n", p_attr->val.etype); + break; + case ISNS_ENTITY_IDX: + p_attr->val.etype = ntohl (p_attr->val.etype); + printf ("Entity Index: %d.\n", p_attr->val.etype); + break; + case ISNS_DELIMITER: + break; + default: + break; + } + ptr = (char *) ptr + p_attr->len + 8; + } + } + + /*********************************************** + This will parse the response msg from an iSCSI + query msg. + ***********************************************/ + void + ParseISCSIQuery (char *buffer) + { + ISNS_Attr *p_attr; + ISNS_HDR *pdu; + char *ptr; + + pdu = (struct isns_hdr *)buffer; + ptr = buffer + sizeof (ISNS_HDR) + 4 /* Error Code Length */; + + while (ptr < (char *) buffer + sizeof (ISNS_HDR) + pdu->len) + { + p_attr = (struct ISNS_attr *)ptr; + p_attr->tag = htonl (p_attr->tag); + p_attr->len = htonl (p_attr->len); + /*Attributes can come back in any order */ + switch (p_attr->tag) + { + case ISNS_ISCSI_NODE_ID: + printf ("---------------------------------\n"); + printf ("iSCSI ID : %s\n",(char *)&p_attr->val); + break; + case ISNS_ISCSI_IDX: + p_attr->val.etype = ntohl (p_attr->val.etype); + printf ("iSCSI Index: %d\n", p_attr->val.etype); + break; + case ISNS_ISCSI_TYPE: + p_attr->val.etype = ntohl (p_attr->val.etype); + printf ("Type: %#x (", p_attr->val.etype); + if (p_attr->val.etype & 1) + printf ("Target"); + if (p_attr->val.etype & 2) + printf ("Initiator"); + printf (")\n"); + break; + case ISNS_ISCSI_ALIAS: + printf ("Alias : %s\n",(char *)&p_attr->val); + break; + case ISNS_DD_ID: + p_attr->val.etype = ntohl (p_attr->val.etype); + printf ("DD ID : %d\n", p_attr->val.etype); + break; + case ISNS_ENTITY_ID: + printf ("Entity ID : %s\n",(char *)&p_attr->val); + break; + case ISNS_ENTITY_IDX: + p_attr->val.etype = ntohl (p_attr->val.etype); + printf ("Entity Idx : %d\n", p_attr->val.etype); + break; + case ISNS_PORTAL_IP: + { + struct in_addr ip; + ip.s_addr = *(uint32_t *) ((char *) &p_attr->val + 12); + printf ("Portal IP : %s.\n", inet_ntoa (ip)); + } + break; + case ISNS_PORTAL_PORT: + p_attr->val.etype = ntohl (p_attr->val.etype); + printf ("Portal Port : %d.\n", p_attr->val.etype & 0xFFFF); + printf ("Portal Type : %s.\n", + p_attr->val.etype & 0x10000 ? "UDP" : "TCP"); + break; + + case ISNS_PORTAL_IDX: + p_attr->val.etype = ntohl (p_attr->val.etype); + printf ("Portal Idx : %d\n", p_attr->val.etype); + break; + case ISNS_PROT_VER: + p_attr->val.ver.max = ntohs (p_attr->val.ver.max); + p_attr->val.ver.min = ntohs (p_attr->val.ver.min); + printf ("Version: Max=%d, Min=%d.\n", p_attr->val.ver.max, + p_attr->val.ver.min); + break; + default: + break; + } + ptr = (char *) ptr + p_attr->len + 8/* Size of tag and length fields*/; + } + } + + /***********************************************************************/ + /* Parses a portal response */ + /***********************************************************************/ + void + ParsePortalQuery (char *buffer) + { + ISNS_Attr *p_attr; + ISNS_HDR *pdu; + char *ptr; + + pdu = (struct isns_hdr *)buffer; + ptr = buffer + sizeof (ISNS_HDR) + 4; + while (ptr < buffer + sizeof (ISNS_HDR) + pdu->len) + { + p_attr = (struct ISNS_attr *)ptr; + p_attr->tag = htonl (p_attr->tag); + p_attr->len = htonl (p_attr->len); + switch (p_attr->tag) + { + case ISNS_PORTAL_IP: + { + struct in_addr ip; + printf ("---------------------------------\n"); + ip.s_addr = *(uint32_t *) ((char *) &p_attr->val + 12); + printf ("Portal IP : %s.\n", inet_ntoa (ip)); + } + break; + case ISNS_PORTAL_PORT: + p_attr->val.etype = ntohl (p_attr->val.etype); + printf ("Portal Port : %d.\n", p_attr->val.etype & 0xFFFF); + printf ("Portal Type : %s.\n", + p_attr->val.etype & 0x10000 ? "UDP" : "TCP"); + break; + case ISNS_PORTAL_SYM_NAME: + printf ("Portal Sym Name: %s\n",(char *)&p_attr->val); + break; + case ISNS_ENTITY_ID: + printf ("Entity ID : %s\n",(char *)&p_attr->val); + break; + case ISNS_ENTITY_IDX: + p_attr->val.etype = ntohl (p_attr->val.etype); + printf ("Entity Index: %d.\n", p_attr->val.etype); + break; + case ISNS_ESI_PORT: + p_attr->val.etype = ntohl (p_attr->val.etype); + printf ("ESI/SCN UDP Port : %d.\n", p_attr->val.etype & 0xFFFF); + break; + case ISNS_ESI_INTERVAL: + p_attr->val.etype = ntohl (p_attr->val.etype); + printf ("ESI Interval : %d.\n", p_attr->val.etype); + break; + case ISNS_PORTAL_IDX: + p_attr->val.etype = ntohl (p_attr->val.etype); + printf ("Portal Index: %d.\n", p_attr->val.etype); + break; + case ISNS_DELIMITER: + break; + default: + break; + } + ptr = (char *) ptr + p_attr->len + 8; + } + } + + + /*********************************************************************/ + /* Parses an ESI */ + /*********************************************************************/ + void + ParseESI (char *buffer) + { + ISNS_Attr *p_attr; + ISNS_HDR *pdu; + char *ptr; + + printf ("Parsing ESI.\n"); + pdu = (struct isns_hdr *)buffer; + ptr = buffer + sizeof (ISNS_HDR); + pdu->len = htons (pdu->len); + while (ptr < (char *) buffer + sizeof (ISNS_HDR) + pdu->len) + { + p_attr = (struct ISNS_attr *)ptr; + p_attr->tag = ntohl (p_attr->tag); + p_attr->len = ntohl (p_attr->len); + switch (p_attr->tag) + { + case ISNS_ENTITY_ID: + printf ("---------------------------------\n"); + printf ("Entity ID : %s\n",(char *)&p_attr->val); + break; + case ISNS_PORTAL_IP: + { + struct in_addr ip; + ip.s_addr = *(uint32_t *) ((char *) &p_attr->val + 12); + printf ("Portal IP : %s.\n", inet_ntoa (ip)); + } + break; + case ISNS_PORTAL_PORT: + p_attr->val.etype = ntohl (p_attr->val.etype); + printf ("Portal Port : %d.\n", p_attr->val.etype & 0xFFFF); + printf ("Portal Port Type : %s.\n", + p_attr->val.etype & 0x10000 ? "UDP" : "TCP"); + break; + default: + break; + } + ptr = (char *) ptr + p_attr->len + 8; + } + } + + /*********************************************************************/ + /* Parses a DDS Query */ + /*********************************************************************/ + void + ParseDDSQuery (char *buffer) + { + ISNS_Attr *p_attr; + ISNS_HDR *pdu; + char *ptr; + + pdu = (struct isns_hdr *)buffer; + ptr = buffer + sizeof (ISNS_HDR) + 4; + while (ptr < buffer + sizeof (ISNS_HDR) + pdu->len) + { + p_attr = (struct ISNS_attr *)ptr; + p_attr->tag = ntohl (p_attr->tag); + p_attr->len = ntohl (p_attr->len); + switch (p_attr->tag) + { + case ISNS_DDS_ID: + printf ("---------------------------------\n"); + p_attr->val.etype = ntohl (p_attr->val.etype); + printf ("DDS ID : %d\n", p_attr->val.etype); + break; + case ISNS_DDS_SYM_NAME: + printf ("DDS Sym Name : %s\n",(char *)&p_attr->val); + break; + case ISNS_DDS_STATUS: + p_attr->val.etype = ntohl (p_attr->val.etype); + printf ("Status: %s\n", p_attr->val.etype?"Active":"Disabled"); + break; + case ISNS_DD_ID: + p_attr->val.etype = ntohl (p_attr->val.etype); + printf (" DD ID : %d\n", p_attr->val.etype); + break; + case ISNS_DD_SYM_NAME: + printf (" DD Sym Name : %s\n",(char *)&p_attr->val); + break; + case ISNS_DD_ACTIVE: + p_attr->val.etype = ntohl (p_attr->val.etype); + printf ("Status: %s\n", p_attr->val.etype?"Active":"Disabled"); + default: + break; + } + ptr = (char *) ptr + p_attr->len + 8; + } + } + + /*********************************************************************/ + /* Parses a DD Query Response */ + /*********************************************************************/ + void + ParseDDQuery (char *buffer) + { + ISNS_Attr *p_attr; + ISNS_HDR *pdu; + char *ptr; + + pdu = (struct isns_hdr *)buffer; + ptr = buffer + sizeof (ISNS_HDR) + 4; + if (pdu->len > MAX_PAYLOAD_SIZE) + printf("ERROR pdu->len:%d\n",pdu->len); + + while (ptr < (buffer + sizeof (ISNS_HDR) + pdu->len) ) + { + p_attr = (struct ISNS_attr *)ptr; + p_attr->tag = ntohl (p_attr->tag); + p_attr->len = ntohl (p_attr->len); + switch (p_attr->tag) + { + case ISNS_DD_ID: + printf ("---------------------------------\n"); + p_attr->val.etype = ntohl (p_attr->val.etype); + printf ("DD ID : %d\n", p_attr->val.etype); + break; + case ISNS_DD_SYM_NAME: + printf ("DD Sym Name : %s\n",(char *)&p_attr->val); + break; + case ISNS_DDS_ID: + p_attr->val.etype = ntohl (p_attr->val.etype); + printf (" DDS ID : %d\n", p_attr->val.etype); + break; + case ISNS_DDS_SYM_NAME: + printf (" DDS Sym Name : %s\n",(char *)&p_attr->val); + break; + case ISNS_DD_ISCSI_MEMBER_IDX: + p_attr->val.etype = ntohl (p_attr->val.etype); + printf (" DD iSCSI Member Index : %d\n", p_attr->val.etype); + break; + case ISNS_DD_ISCSI_MEMBER: + printf (" DD iSCSI Member : %s\n",(char *)&p_attr->val); + break; + case ISNS_DD_IFCP_MEMBER: + { + char buffer2[256]; + memset (buffer2, 0, sizeof (buffer2)); + printf (" iFCP WWPN : %s\n", + HexToAscii ((char *)&p_attr->val, p_attr->len, buffer2)); + break; + } + default: + break; + } + ptr = (char *) ptr + p_attr->len + 8; + } + } Index: custom.c =================================================================== RCS file: /cvsroot/linuxisns/isnsNT/isnsclient/src/custom.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** custom.c 2 Apr 2002 20:56:54 -0000 1.2 --- custom.c 23 Aug 2007 05:21:00 -0000 1.3 *************** *** 45,48 **** --- 45,49 ---- #include "util.h" #include "comm.h" + #include "parse.h" #include "custom.h" Index: ifcp.c =================================================================== RCS file: /cvsroot/linuxisns/isnsNT/isnsclient/src/ifcp.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ifcp.c 14 Aug 2007 03:43:55 -0000 1.5 --- ifcp.c 23 Aug 2007 05:21:00 -0000 1.6 *************** *** 34,37 **** --- 34,38 ---- #include "comm.h" #include "util.h" + #include "parse.h" |