isns-2.1-01/0000755000175000017500000000000010665035160011560 5ustar zobelzobelisns-2.1-01/isnsclient/0000755000175000017500000000000010665065427013744 5ustar zobelzobelisns-2.1-01/isnsclient/src/0000755000175000017500000000000010665035252014524 5ustar zobelzobelisns-2.1-01/isnsclient/src/payloads.c0000644000175000017500000004206710665035160016513 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include "isns.h" #include "comm.h" #include "util.h" #include "parse.h" static ISNS_CMD cmd; /******************************************* Command line support functions *******************************************/ /*********************************************************************/ /* queryDDS */ /*********************************************************************/ void queryDDS (char *id) { char buffer[MAX_PAYLOAD_SIZE]={0}; ISNSCreateHdr (ISNS_DEV_ATTR_QRY_REQ, &cmd, sizeof(cmd), 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (CONTROL_NODE)),CONTROL_NODE, 0); if (strlen(id)) { int ddsid; ddsid = atoi(id); ISNSAppendAttr (&cmd, ISNS_DDS_ID, 4, NULL, ddsid); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DDS_SYM_NAME, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_SYM_NAME, 0, NULL, 0); } else { ISNSAppendAttr (&cmd, ISNS_DDS_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DDS_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DDS_SYM_NAME, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DDS_STATUS, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_SYM_NAME, 0, NULL, 0); } if (0 == ISNSSendCmd2 (&cmd, buffer, sizeof (buffer))) ParseDDSQuery (buffer); } /*********************************************************************/ /* queryDD */ /*********************************************************************/ void queryDD (char *id) { char buffer[MAX_PAYLOAD_SIZE]={0}; ISNSCreateHdr (ISNS_DEV_ATTR_QRY_REQ, &cmd, sizeof(cmd), 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (CONTROL_NODE)),CONTROL_NODE, 0); if (strlen(id)) { int ddid; ddid = atoi(id); ISNSAppendAttr (&cmd, ISNS_DD_ID, 4, NULL, ddid); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_SYM_NAME, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_ISCSI_MEMBER, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_ISCSI_MEMBER_IDX, 0, NULL, 0); } else { ISNSAppendAttr (&cmd, ISNS_DD_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_SYM_NAME, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_ISCSI_MEMBER, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_ISCSI_MEMBER_IDX, 0, NULL, 0); } if (0 == ISNSSendCmd2 (&cmd, buffer, sizeof (buffer))) ParseDDQuery (buffer); } /*********************************************************************/ /* regDDS */ /*********************************************************************/ void regDDS (char * sym) { uint32_t status=0; extern int replaceFlag; ISNSCreateHdr (ISNS_REG_DDS_REQ, &cmd, sizeof (cmd), replaceFlag?ISNS_FLAG_REPLACE_REG:0); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (CONTROL_NODE)),CONTROL_NODE, 0); /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DDS_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DDS_SYM_NAME, PAD4 (strlen (sym)), sym, 0); status = 0x1; ISNSAppendAttr (&cmd, ISNS_DDS_STATUS, 4, NULL, status); ISNSSendCmd (&cmd); } /*********************************************************************/ /* regDDSMember */ /*********************************************************************/ void regDDSMember (char * ddsid, char * ddid ) { int dds_id; int dd_id; dds_id = atoi (ddsid); dd_id = atoi (ddid); ISNSCreateHdr (ISNS_REG_DDS_REQ, &cmd, sizeof (cmd), 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (CONTROL_NODE)),CONTROL_NODE, 0); ISNSAppendAttr (&cmd, ISNS_DDS_ID, 4, NULL, dds_id); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_ID, 4, NULL, dd_id); ISNSSendCmd (&cmd); } /*********************************************************************/ /* regDDMember */ /*********************************************************************/ void regDDMember (char * ddid, char * iscsi_node ) { int dd_id; dd_id = atoi (ddid); ISNSCreateHdr (ISNS_REG_DD_REQ, &cmd, sizeof (cmd), 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (CONTROL_NODE)),CONTROL_NODE, 0); ISNSAppendAttr (&cmd, ISNS_DD_ID, 4, NULL, dd_id); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_ISCSI_MEMBER, PAD4 (strlen(iscsi_node)), iscsi_node, 0); ISNSSendCmd (&cmd); } /*********************************************************************/ /* regDD */ /*********************************************************************/ void regDD (char * sym) { extern int replaceFlag; ISNSCreateHdr (ISNS_REG_DD_REQ, &cmd, sizeof (cmd), replaceFlag?ISNS_FLAG_REPLACE_REG:0); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (CONTROL_NODE)),CONTROL_NODE, 0); /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_SYM_NAME, PAD4 (strlen (sym)), sym, 0); ISNSSendCmd (&cmd); } /*********************************************************************/ /*********************************************************************/ void regISCSI (char * sym, char *id) { extern int replaceFlag; ISNSCreateHdr (ISNS_REG_DEV_ATTR_REQ, &cmd, sizeof (cmd), replaceFlag?ISNS_FLAG_REPLACE_REG:0); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (CONTROL_NODE)),CONTROL_NODE, 0); ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4(strlen(id)),id,0); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4(strlen(sym)),sym,0); ISNSAppendAttr (&cmd, ISNS_ISCSI_TYPE, 4, NULL, 1); ISNSSendCmd (&cmd); } /*********************************************************************/ /*********************************************************************/ void regEntity (char * sym) { extern int replaceFlag; int type; ISNSCreateHdr (ISNS_REG_DEV_ATTR_REQ, &cmd, sizeof (cmd), replaceFlag?ISNS_FLAG_REPLACE_REG:0); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (CONTROL_NODE)),CONTROL_NODE, 0); /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4 (strlen (sym)), sym, 0); type = 2; ISNSAppendAttr (&cmd, ISNS_ENTITY_TYPE, 4, NULL, type); ISNSSendCmd (&cmd); } /*********************************************************************/ /*********************************************************************/ void regPortal (char * ip_address, char * id, char *port_value) { extern int replaceFlag; int port; int portal_type = 1; int ip; char tempb[256]; port = atoi(port_value); printf("port_value:%s\n",port_value); ISNSCreateHdr (ISNS_REG_DEV_ATTR_REQ, &cmd, sizeof (cmd), replaceFlag?ISNS_FLAG_REPLACE_REG:0); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (CONTROL_NODE)),CONTROL_NODE, 0); ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4(strlen(id)),id,0); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); printf("ipaddress:%s\n",ip_address); ip = inet_addr(ip_address); memset (tempb, 0, sizeof(tempb)); tempb[10] = tempb[11] = 0xff; memcpy(tempb + 12, &ip, sizeof(ip)); ISNSAppendAttr (&cmd, ISNS_PORTAL_IP, 16, tempb, 0); ISNSAppendAttr (&cmd, ISNS_PORTAL_PORT, 4, NULL, port | (portal_type == 0 ? 0x10000: 0)); ISNSSendCmd (&cmd); } /*********************************************************************/ /* deregisters a DDS */ /*********************************************************************/ void deregDDS (char *ddsid) { int id; ISNSCreateHdr (ISNS_DEREG_DDS_REQ, &cmd, sizeof (cmd), 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (CONTROL_NODE)),CONTROL_NODE, 0); id = atoi (ddsid); ISNSAppendAttr (&cmd, ISNS_DDS_ID, 4, NULL, id); ISNSSendCmd (&cmd); } /*********************************************************************/ /* deregisters a DD */ /*********************************************************************/ void deregDD (char *ddid) { int id; ISNSCreateHdr (ISNS_DEREG_DD_REQ, &cmd, sizeof (cmd), 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (CONTROL_NODE)),CONTROL_NODE, 0); id = atoi (ddid); ISNSAppendAttr (&cmd, ISNS_DD_ID, 4, NULL, id); ISNSSendCmd (&cmd); } /*********************************************************************/ /*********************************************************************/ void deregISCSI (char *iscsi) { ISNSCreateHdr (ISNS_DEREG_DEV_REQ, &cmd, sizeof (cmd), 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (CONTROL_NODE)),CONTROL_NODE, 0); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4(strlen(iscsi)),iscsi, 0); ISNSSendCmd (&cmd); } /*********************************************************************/ /*********************************************************************/ void deregEntity (char *entity) { ISNSCreateHdr (ISNS_DEREG_DEV_REQ, &cmd, sizeof (cmd), 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (CONTROL_NODE)),CONTROL_NODE, 0); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4(strlen(entity)),entity, 0); ISNSSendCmd (&cmd); } /*********************************************************************/ /*********************************************************************/ void deregPortal (char *ip_address, char * port_value) { extern int replaceFlag; int port; int portal_type = 1; int ip; char tempb[256]; port = atoi(port_value); ISNSCreateHdr (ISNS_DEREG_DEV_REQ, &cmd, sizeof (cmd), 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (CONTROL_NODE)),CONTROL_NODE, 0); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ip = inet_addr(ip_address); memset (tempb, 0, sizeof(tempb)); tempb[10] = tempb[11] = 0xff; memcpy(tempb + 12, &ip, sizeof(ip)); ISNSAppendAttr (&cmd, ISNS_PORTAL_IP, 16, tempb, 0); ISNSAppendAttr (&cmd, ISNS_PORTAL_PORT, 4, NULL, port | (portal_type == 0 ? 0x10000: 0)); ISNSSendCmd (&cmd); } /*********************************************************************/ /* Removes a DD from a DDS */ /*********************************************************************/ void deregDDSMember (char *ddsid, char *ddid) { int dds_id; int dd_id; ISNSCreateHdr (ISNS_DEREG_DDS_REQ, &cmd, sizeof (cmd), 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (CONTROL_NODE)),CONTROL_NODE, 0); dds_id = atoi (ddsid); ISNSAppendAttr (&cmd, ISNS_DDS_ID, 4, NULL, dds_id); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); dd_id = atoi (ddid); ISNSAppendAttr (&cmd, ISNS_DD_ID, 4, NULL, dd_id); ISNSSendCmd (&cmd); } /*********************************************************************/ /* Removes a DD from a DDS */ /*********************************************************************/ void deregDDMember (char *ddid, char * iscsi_node) { int dd_id; ISNSCreateHdr (ISNS_DEREG_DD_REQ, &cmd, sizeof (cmd), 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (CONTROL_NODE)),CONTROL_NODE, 0); dd_id = atoi (ddid); ISNSAppendAttr (&cmd, ISNS_DD_ID, 4, NULL, dd_id); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_ISCSI_MEMBER, PAD4(strlen(iscsi_node)), iscsi_node, 0); ISNSSendCmd (&cmd); } /******************************************** This will query for iSCSI Node(s) attributes. ********************************************/ void queryISCSI (char * id) { char buffer[MAX_PAYLOAD_SIZE]={0}; ISNSCreateHdr (ISNS_DEV_ATTR_QRY_REQ, &cmd, sizeof (cmd), 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (CONTROL_NODE)),CONTROL_NODE, 0); if (strlen(id) ) { ISNSAppendAttr (&cmd, ISNS_ISCSI_IDX, ISNS_INDEX_SIZE, NULL, atoi(id)); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_TYPE, 0, NULL, 0); } else { ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_TYPE, 0, NULL, 0); } if (0 == ISNSSendCmd2 (&cmd, buffer, sizeof (buffer))) { ParseISCSIQuery (buffer); } } /******************************************** queryEntity ********************************************/ void queryEntity (void) { char buffer[MAX_PAYLOAD_SIZE]={0}; ISNSCreateHdr (ISNS_DEV_ATTR_QRY_REQ, &cmd, sizeof (cmd), 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (CONTROL_NODE)),CONTROL_NODE, 0); ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, 0, NULL, 0); if (0 == ISNSSendCmd2 (&cmd, buffer, sizeof (buffer))) { ParseEntityQuery (buffer); } } /******************************************** queryPortal ********************************************/ void queryPortal (void) { char buffer[MAX_PAYLOAD_SIZE]={0}; ISNSCreateHdr (ISNS_DEV_ATTR_QRY_REQ, &cmd, sizeof (cmd), 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (CONTROL_NODE)),CONTROL_NODE, 0); ISNSAppendAttr (&cmd, ISNS_PORTAL_IP, 0, NULL, 0); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PORTAL_IP, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PORTAL_PORT, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, 0, NULL, 0); if (0 == ISNSSendCmd2 (&cmd, buffer, sizeof (buffer))) { ParsePortalQuery (buffer); } } /********************************************************************* commandLineDispatch *********************************************************************/ void CommandLineDispatch (char function, char *command, char *id, char *id2, char *id3) { switch (function) { case 'q': if(0 == strcmp(command,"dds")) queryDDS(id); else if ( 0 == strcmp(command,"dd")) queryDD(id); else if ( 0 == strcmp(command,"iscsi")) queryISCSI(id); else if ( 0 == strcmp(command,"entity")) queryEntity(); else if ( 0 == strcmp(command,"portal")) queryPortal(); else printf("invalid query type\n"); break; case 'r': if(0 == strcmp(command,"dds")) regDDS(id); else if ( 0 == strcmp(command,"dd")) regDD(id); else if ( 0 == strcmp(command,"ddsmember")) regDDSMember(id,id2); else if ( 0 == strcmp(command,"ddmember")) regDDMember(id,id2); else if ( 0 == strcmp(command,"iscsi")) regISCSI(id,id2); else if ( 0 == strcmp(command,"entity")) regEntity(id); else if ( 0 == strcmp(command,"portal")) regPortal(id,id2,id3); else printf("invalid register type\n"); break; case 'd': if(0 == strcmp(command,"dds")) deregDDS(id); else if ( 0 == strcmp(command,"dd")) deregDD(id); else if ( 0 == strcmp(command,"ddsmember")) deregDDSMember (id,id2); else if ( 0 == strcmp(command,"ddmember")) deregDDMember (id,id2); else if ( 0 == strcmp(command,"iscsi")) deregISCSI(id); else if ( 0 == strcmp(command,"entity")) deregEntity(id); else if ( 0 == strcmp(command,"portal")) deregPortal(id,id2); else printf("invalid deregister type\n"); break; } } isns-2.1-01/isnsclient/src/portal.c0000644000175000017500000003254210665035160016175 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include "isns.h" #include "comm.h" #include "util.h" #include "parse.h" static ISNS_CMD cmd; extern int replaceFlag; /***********************************************************************/ /* DeRegisters a portal */ /***********************************************************************/ void DeRegisterPortal (void) { char cmdLine[256]; int port; int ip; int portal_type; char b[256]={0}; /* Insert Header */ ISNSCreateHdr (ISNS_DEREG_DEV_REQ, &cmd, sizeof (cmd), 0); if (-1 == GetSrc (&cmd, 0)) return; /* Add Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ip = inet_addr (DEFAULT_IP_ADDR); if (0 != GetInput ((char *)&cmdLine, "Portal IP", DEFAULT_IP_ADDR, sizeof (cmdLine))) { ip = inet_addr (cmdLine); } { char tempb[256]; memset (tempb, 0, sizeof (tempb)); memcpy (tempb + 12, &ip, sizeof (ip)); ISNSAppendAttr (&cmd, ISNS_PORTAL_IP, 16, tempb, 0); } /* Get Portal Type */ portal_type = 0; if (0 != GetInput (cmdLine, "Portal Type", "*0: UDP 1: TCP", sizeof (cmdLine))) { portal_type = atoi (cmdLine); } /* Get Port */ port = DEFAULT_PORTAL_PORT; itoa(DEFAULT_PORTAL_PORT, b, 10); if (0 != GetInput (cmdLine, "Portal Port", b, sizeof (cmdLine))) { port = atoi (cmdLine); } ISNSAppendAttr (&cmd, ISNS_PORTAL_PORT, 4, NULL, port | (portal_type == 0 ? 0x10000 : 0)); ISNSSendCmd (&cmd); } /***********************************************************************/ /* Queries for portals */ /***********************************************************************/ void GetPortals (void) { char buffer[MAX_PAYLOAD_SIZE]; char cmdLine[256]; int c_size; int portal_type; int key_type; ISNSCreateHdr (ISNS_DEV_ATTR_QRY_REQ, &cmd, sizeof (cmd), 0); /* Src */ if (-1 == GetSrc (&cmd, 0)) return; /* Key */ key_type = 0; if (0 != GetInput (cmdLine, "Key type (1:iSCSI, 2:Entity ID 3:Portal IP/Port 4:Portal Index)>", "(none)", sizeof (cmdLine))) { key_type=atoi(cmdLine); switch (key_type) { case 1: c_size = GetInput (cmdLine, "iSCSI Node ID >", "(none)", sizeof (cmdLine)); if (c_size != 0) { ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (cmdLine)), cmdLine, 0); } break; case 2: c_size = GetInput (cmdLine, "Entity ID >", "(none)", sizeof (cmdLine)); if (c_size != 0) { ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4 (strlen (cmdLine)), cmdLine, 0); } break; case 3: c_size = GetInput (cmdLine, "Portal IP", NULL, sizeof (cmdLine)); if (c_size != 0) { char tempb[256]; int ip; int port; ip = inet_addr (cmdLine); memset (tempb, 0, sizeof (tempb)); memcpy (tempb + 12, &ip, sizeof (ip)); ISNSAppendAttr (&cmd, ISNS_PORTAL_IP, 16, tempb, 0); portal_type = 0; if (GetInput (cmdLine, "Portal Type", "*0:UDP 1:TCP", sizeof (cmdLine))) { portal_type = atoi (cmdLine); } c_size = GetInput (cmdLine, "Portal PORT", NULL, sizeof (cmdLine)); if (c_size == 0) { printf ("***ERROR: You must enter a Portal Port."); return; } port = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_PORTAL_PORT, 4, NULL, port | (portal_type == 0 ? 0x10000 : 0)); } break; case 4: c_size = GetInput (cmdLine, "Portal Index", "(none)", sizeof (cmdLine)); if (c_size != 0) { ISNSAppendAttr (&cmd, ISNS_PORTAL_IDX, ISNS_INDEX_SIZE, NULL, atoi(cmdLine)); } break; default: ISNSAppendAttr (&cmd, ISNS_PORTAL_IP, 0, NULL, 0); break; } } else ISNSAppendAttr (&cmd, ISNS_PORTAL_IP, 0, NULL, 0); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PORTAL_IP, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PORTAL_IDX, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PORTAL_PORT, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PORTAL_SYM_NAME, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ESI_PORT, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ESI_INTERVAL, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ENTITY_IDX, 0, NULL, 0); if (0 == ISNSSendCmd2 (&cmd, buffer, sizeof (buffer))) { ParsePortalQuery (buffer); } } /***********************************************************************/ /* Registers a portal */ /***********************************************************************/ void RegPortalI (void) { char cmdLine[256]; char eid[256]; char sym[256]; int port; int ip; int esi_interval; int port_type; int portal_group; char b[256]={0}; int flag; /* Insert Header */ printf ("Registering Portal.\n"); ISNSCreateHdr (ISNS_REG_DEV_ATTR_REQ, &cmd, sizeof (cmd), replaceFlag?ISNS_FLAG_REPLACE_REG:0); /* Get Entity ID */ flag = FALSE; if (-1 ==GetSrc(&cmd,0)) return; if (0 != GetInput (cmdLine, "Entity ID", "(none)", sizeof (cmdLine))) { memset (eid, 0, sizeof (eid)); strcpy (eid, cmdLine); ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4 (strlen (cmdLine)), cmdLine, 0); flag = TRUE; } if (!flag) { printf("Error: You must enter at least one Entity ID.\n"); return; } /* Add Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* Get IP */ ip = inet_addr (DEFAULT_IP_ADDR); if (0 != GetInput (cmdLine, "Portal IP", DEFAULT_IP_ADDR, sizeof (cmdLine))) { ip = inet_addr (cmdLine); } { char tempb[256]; memset (tempb, 0, sizeof (tempb)); tempb[10] = tempb[11] = 0xff; memcpy (tempb + 12, &ip, sizeof (ip)); ISNSAppendAttr (&cmd, ISNS_PORTAL_IP, 16, tempb, 0); } /* Get Port Type */ port_type = 0; if (0 != GetInput (cmdLine, "Portal Type", "*0:UDP 1:TCP", sizeof (cmdLine))) { port_type = atoi (cmdLine); if (port_type > 1) { printf ("***ERROR: Port type is wrong.\n"); return; } } /* Get Port */ port = DEFAULT_PORTAL_PORT; itoa(DEFAULT_PORTAL_PORT, b, 10); if (0 != GetInput (cmdLine, "Portal Port", b, sizeof (cmdLine))) { port = atoi (cmdLine); } ISNSAppendAttr (&cmd, ISNS_PORTAL_PORT, 4, NULL, port | (port_type == 1 ? 0 : 0x10000)); /* Get an Portal Sym Name */ memset (sym, 0, sizeof (sym)); if (0 != GetInput (cmdLine, "Portal Sym Name", NULL, sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_PORTAL_SYM_NAME, PAD4 (strlen (cmdLine)), cmdLine, 0); strcpy (cmdLine, sym); } /* Get Portal Group */ if (0 != GetInput (cmdLine, "Portal Group Tag", NULL, sizeof (cmdLine))) { portal_group = atoi (cmdLine); memset (cmdLine, 0, sizeof (cmdLine)); ISNSAppendAttr (&cmd, ISNS_PORTAL_GROUP_TAG, 4, NULL, portal_group); } /* Get Interval */ esi_interval = 0; if (0 != GetInput (cmdLine, "ESI Interval", "0", sizeof (cmdLine))) { esi_interval = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_ESI_INTERVAL, 4, NULL, esi_interval); /* Get ESI Port */ port = 0; if (0 != GetInput (cmdLine, "ESI/SCN UDP Port", NULL, sizeof (cmdLine))) { port = atoi (cmdLine); } ISNSAppendAttr (&cmd, ISNS_ESI_PORT, 4, NULL, port); if (port && esi_interval) { #ifndef SNS_LINUX DWORD junk; #endif LISTENER_CB_P p_cb = NULL; HANDLE hdle; #ifdef SNS_LINUX hdle = (void *)malloc (sizeof (pthread_t)); #else p_cb = malloc (sizeof (LISTENER_CB)); #endif memset (p_cb, 0, sizeof (LISTENER_CB)); strcpy (p_cb->eid, eid); p_cb->port = port; p_cb->ip = ip; #ifdef SNS_LINUX if (pthread_create (hdle, NULL, (void*) (ESIListener), p_cb) != 0) printf ("Could not create ESI Listener thread\n"); else #else hdle = CreateThread ((LPSECURITY_ATTRIBUTES)0, 0, (LPTHREAD_START_ROUTINE)ESIListener, p_cb, 0, &junk); #endif AddESIPortal (sym, port, hdle); } } ISNSSendCmd (&cmd); } /***********************************************************************/ /* Updates an existing portal */ /***********************************************************************/ void UpdatePortal (void) { char cmdLine[256]; char sym[256]={0}; int port; int ip; int esi_interval; int port_type; /* Insert Header */ printf ("Updating Portal.\n"); ISNSCreateHdr (ISNS_REG_DEV_ATTR_REQ, &cmd, sizeof (cmd), 0); /* Get IP */ if (0 == GetInput (cmdLine, "Portal IP", NULL, sizeof (cmdLine))) { printf ("***ERROR: You must enter an IP address.\n"); return; } ip = inet_addr (cmdLine); { char tempb[256]; memset (tempb, 0, sizeof (tempb)); memcpy (tempb + 12, &ip, sizeof (ip)); ISNSAppendAttr (&cmd, ISNS_PORTAL_IP, 16, tempb, 0); } /* Get Port Type */ port_type = 0; if (0 != GetInput (cmdLine, "Portal Type", "*0:UDP 1:TCP", sizeof (cmdLine))) { port_type = atoi (cmdLine); if (port_type > 1) { printf ("***ERROR: Port type is wrong.\n"); return; } } /* Get Port */ if (0 == GetInput (cmdLine, "Portal Port", NULL, sizeof (cmdLine))) { printf ("***ERROR: You must enter a port.\n"); return; } port = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_PORTAL_PORT, 4, NULL, port | (port_type == 1 ? 0 : 0x10000)); /* Add Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* Get an Portal Sym Name */ if (0 != GetInput (cmdLine, "Portal Sym Name", "(none)", sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_PORTAL_SYM_NAME, PAD4 (strlen (cmdLine)), cmdLine, 0); memset (sym, 0, sizeof (sym)); strcpy (cmdLine, sym); } /* Get Interval */ esi_interval = 0; if (0 != GetInput (cmdLine, "ESI Interval", NULL, sizeof (cmdLine))) { esi_interval = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_ESI_INTERVAL, 4, NULL, esi_interval); /* Get ESI Port */ port = 0; if (0 != GetInput (cmdLine, "ESI/SCN UDP Port", NULL, sizeof (cmdLine))) { port = atoi (cmdLine); } ISNSAppendAttr (&cmd, ISNS_ESI_PORT, 4, NULL, port); if (port && esi_interval) { #ifndef SNS_LINUX DWORD junk; #endif LISTENER_CB_P p_cb = NULL; HANDLE hdle; #ifdef SNS_LINUX hdle = (void *)malloc (sizeof (pthread_t)); #else p_cb = malloc (sizeof (LISTENER_CB)); #endif memset (p_cb, 0, sizeof (LISTENER_CB)); memset (p_cb->eid, 0, sizeof (p_cb->eid)); p_cb->port = port; p_cb->ip = ip; #ifdef SNS_LINUX if (pthread_create (hdle, NULL, (void*) (ESIListener), p_cb) != 0) printf ("Could not create ESI Listener thread\n"); else #else hdle = CreateThread ((LPSECURITY_ATTRIBUTES)0, 0, (LPTHREAD_START_ROUTINE)ESIListener, p_cb, 0, &junk); #endif AddESIPortal (sym, port, hdle); } } ISNSSendCmd (&cmd); } isns-2.1-01/isnsclient/src/custom.c0000644000175000017500000001771310665035160016211 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include "isns.h" #ifdef SNS_LINUX #include #else #include "getarg.h" #endif #include "iscsi.h" #include "portal.h" #include "entity.h" #include "ifcp.h" #include "fcnode.h" #include "util.h" #include "comm.h" #include "parse.h" #include "custom.h" static ISNS_CMD cmd; extern int replaceFlag; /* Custom registrations */ void RegCustom1 (void) { char buffer[ 256 ]; memset (buffer, 0, sizeof (buffer)); ISNSCreateHdr (ISNS_REG_DEV_ATTR_REQ, &cmd, sizeof (cmd), replaceFlag?ISNS_FLAG_REPLACE_REG:0); /* Add Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); memcpy (buffer, "Entity 1", sizeof (buffer)); ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4 (strlen (buffer)), buffer, 0); ISNSAppendAttr (&cmd, ISNS_ENTITY_TYPE, 4, NULL, 1); ISNSAppendAttr (&cmd, ISNS_ENTITY_CERT, 4, "1234", 0); ISNSSendCmd (&cmd); } void RegCustom2 (void) { char buffer[256]; memset (buffer, 0, sizeof (buffer)); /* Register Entity 1 */ ISNSCreateHdr (ISNS_REG_DEV_ATTR_REQ, &cmd, sizeof (cmd), replaceFlag?ISNS_FLAG_REPLACE_REG:0); /* Add Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); memcpy (buffer, "Entity 1", sizeof (buffer)); ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4 (strlen (buffer)), buffer, 0); ISNSAppendAttr (&cmd, ISNS_ENTITY_TYPE, 4, NULL, 1); /* Register iSCSI Node 1 */ memset (buffer, 0, sizeof (buffer)); strcpy (buffer, "iSCSI Node 1"); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (buffer)), buffer, 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_TYPE, 4, NULL, 1); ISNSAppendAttr (&cmd, ISNS_ISCSI_SCN_BITMAP, 4, NULL, 0x1F); /* Register iSCSI Node 2 */ memset (buffer, 0, sizeof (buffer)); strcpy (buffer, "iSCSI Node 2"); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (buffer)), buffer, 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_TYPE, 4, NULL, 1); ISNSAppendAttr (&cmd, ISNS_ISCSI_SCN_BITMAP, 4, NULL, 0x1f); /* Register iSCSI Node 3 */ memset (buffer, 0, sizeof (buffer)); strcpy (buffer, "iSCSI Node 3"); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (buffer)), buffer, 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_TYPE, 4, NULL, 1); ISNSAppendAttr (&cmd, ISNS_ISCSI_SCN_BITMAP, 4, NULL, 0x1f); /* Register iSCSI Node 4 */ memset (buffer, 0, sizeof (buffer)); strcpy (buffer, "iSCSI Node 4"); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (buffer)), buffer, 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_TYPE, 4, NULL, 1); ISNSAppendAttr (&cmd, ISNS_ISCSI_SCN_BITMAP, 4, NULL, 0x1f); ISNSSendCmd (&cmd); WaitForKey (); /* Register DD */ ISNSCreateHdr (ISNS_REG_DD_REQ, &cmd, sizeof (cmd), 0); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_ID, 4, NULL, 1); memset (buffer, 0, sizeof (buffer)); strcpy (buffer, "DD 1"); ISNSAppendAttr (&cmd, ISNS_DD_SYM_NAME, PAD4 (strlen (buffer)), buffer, 0); memset (buffer, 0, sizeof (buffer)); strcpy (buffer, "iSCSI Node 1"); ISNSAppendAttr (&cmd, ISNS_DD_ISCSI_MEMBER, PAD4 (strlen (buffer)), buffer, 0); memset (buffer, 0, sizeof (buffer)); strcpy (buffer, "iSCSI Node 2"); ISNSAppendAttr (&cmd, ISNS_DD_ISCSI_MEMBER, PAD4 (strlen (buffer)), buffer, 0); strcpy (buffer, "iSCSI Node 3"); ISNSAppendAttr (&cmd, ISNS_DD_ISCSI_MEMBER, PAD4 (strlen (buffer)), buffer, 0); memset (buffer, 0, sizeof (buffer)); strcpy (buffer, "iSCSI Node 4"); ISNSAppendAttr (&cmd, ISNS_DD_ISCSI_MEMBER, PAD4 (strlen (buffer)), buffer, 0); ISNSSendCmd (&cmd); WaitForKey (); ISNSCreateHdr (ISNS_REG_DD_REQ, &cmd, sizeof (cmd), 0); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_ID, 4, NULL, 2); memset (buffer, 0, sizeof (buffer)); strcpy (buffer, "DD 2"); ISNSAppendAttr (&cmd, ISNS_DD_SYM_NAME, PAD4 (strlen (buffer)), buffer, 0); ISNSSendCmd (&cmd); WaitForKey (); /* Register DDS */ printf ("Registering DDS.\n"); ISNSCreateHdr (ISNS_REG_DDS_REQ, &cmd, sizeof (cmd), 0); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DDS_ID, 4, NULL, 1); memset (buffer, 0, sizeof (buffer)); strcpy (buffer, "DDS 1"); ISNSAppendAttr (&cmd, ISNS_DDS_SYM_NAME, PAD4 (strlen (buffer)), buffer, 0); ISNSAppendAttr (&cmd, ISNS_DDS_STATUS, 4, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_ID, 4, NULL, 1); ISNSSendCmd (&cmd); WaitForKey (); ISNSCreateHdr (ISNS_REG_DDS_REQ, &cmd, sizeof (cmd), 0); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DDS_ID, 4, NULL, 2); memset (buffer, 0, sizeof (buffer)); strcpy (buffer, "DDS 2"); ISNSAppendAttr (&cmd, ISNS_DDS_SYM_NAME, PAD4 (strlen (buffer)), buffer, 0); ISNSAppendAttr (&cmd, ISNS_DDS_STATUS, 4, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_ID, 4, NULL, 2); ISNSSendCmd (&cmd); WaitForKey (); } void RegCustom3 (void) { char buffer[256]; memset (buffer, 0, sizeof (buffer)); /* Register Entity 1 */ ISNSCreateHdr (ISNS_REG_DEV_ATTR_REQ, &cmd, sizeof (cmd), 0); /* Add Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); memcpy (buffer, "Entity 1", sizeof (buffer)); ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4 (strlen (buffer)), buffer, 0); ISNSAppendAttr (&cmd, ISNS_ENTITY_TYPE, 4, NULL, 2); /* Register iFCP Node 1 */ memset (buffer, 0, sizeof (buffer)); strcpy (buffer, "PORTNAM1"); ISNSAppendAttr (&cmd, ISNS_PORT_NAME, 8, buffer, 0); ISNSAppendAttr (&cmd, ISNS_PORT_ID, 4, "PID1", 1); ISNSAppendAttr (&cmd, ISNS_PORT_TYPE, 4, NULL, 0xFF12); ISNSAppendAttr (&cmd, ISNS_FABRIC_PORT_NAME, 8, "FP_NAME1", 0); ISNSAppendAttr (&cmd, ISNS_FC_HARD_ADDR, 4, "HRD1", 0); { char tempip[16]; memset (tempip, 0, sizeof (tempip)); *(uint32_t *) & tempip[12] = inet_addr (DEFAULT_IP_ADDR); ISNSAppendAttr (&cmd, ISNS_FC_PORT_IP, 16, tempip, 0); } ISNSAppendAttr (&cmd, ISNS_FC_COS, 4, "COS 1", 0); ISNSAppendAttr (&cmd, ISNS_IFCP_SCN_BITMAP, 4, NULL, 0x1f); ISNSSendCmd (&cmd); WaitForKey (); return; } isns-2.1-01/isnsclient/src/comm.c0000644000175000017500000005431010665035160015624 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include "isns.h" #ifndef SNS_LINUX #include #include #include #else #define Sleep(a) sleep(a) #endif #include #include "util.h" #include "comm.h" #include "parse.h" #include #include #include #include MSG_CB msg_q[MSG_Q_SIZE]; /* TCP msg Q */ int msgInitFlag = FALSE; int msgCurrentIndex = 0; int msgCurrentHead = 0; #ifndef SNS_LINUX WSADATA g_WsaData; #endif SOCKET fd; struct sockaddr_in their_addr; struct sockaddr_in my_addr; int tcpFlag; /* TRUE if using TCP */ int isns_port; /* iSNS port */ extern int parserFlag; extern char *optarg; extern int enableESIFlag; extern char p_ip[256]; char multicast_addr[20]; struct addrinfo hints, *res; /***********************************************************************/ /* Initializes communications */ /***********************************************************************/ int InitComm( int hb_flag, /* Set to non-zero if using heartbeat to find iSNS */ int l3_hb_flag, int t_flag /* Set to non-zero if using TCP */) { tcpFlag=t_flag; int flags = 0; int rc = 0; int timeout = 5; // # seconds struct pollfd fds; char port[16]; #ifndef SNS_LINUX /* Start up the winsock proprietary Stuff */ if (WSAStartup (MAKEWORD (0x02, 0x00), &g_WsaData) == SOCKET_ERROR) { exit(-1); } #endif if (hb_flag) { if (-1==HeartBeatListener()) exit(-1); } else if (l3_hb_flag) { if (-1==L3_HeartBeatListener()) exit(-1); } memset(&hints,0,sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; sprintf(port,"%i",isns_port); rc = getaddrinfo(p_ip,port,&hints,&res); if (rc != 0) { printf("Failed to resolve host:%i %s\n",rc,strerror(errno)); return rc; } if (tcpFlag) { /* TCP Mode */ if ((fd = socket (AF_INET, SOCK_STREAM, 0)) < 0) { perror ("TCP Fatal Error while calling socket"); exit(-1); } /* setup socket to nonblocking so we can do a timeout on the connect call */ flags = fcntl(fd, F_GETFL,0); fcntl (fd, F_SETFL, flags | O_NONBLOCK); printf ("Connecting to %s...\n", p_ip); rc = connect (fd, res->ai_addr, res->ai_addrlen); if (rc < 0) { if (!(errno == EINTR || errno == EINPROGRESS || errno == EWOULDBLOCK)) { printf ("TCP Fatal Error connecting: %s\n",strerror(errno)); exit(-1); } /* because we have nonblocking connection, we have to poll to find out when */ /* the connection actually occurs. If it can't connect, then a timeout occurs */ fds.fd = fd; fds.events = 0XFFFF; //POLLOUT; for (;;) { fds.revents = 0; rc = poll(&fds, 1, timeout * 5000); if (rc < 0) { printf("errno is:%i %s\n",errno,strerror(errno)); if (!(errno == EINTR || errno == EAGAIN)) break; } else if (rc == 0) { printf ("TCP Fatal Error Timeout occured trying to Connect\n"); exit(-1); } else if (fds.revents & POLLERR) { printf ("TCP error on connection\n"); exit(-1); } printf("We have a connection:0x%x\n",fds.revents); break; } } /* set socket back to blocking */ fcntl (fd, F_SETFL, flags ); // printf("Spawn TCPReceiveMain\n"); /* 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 } } else { /* UDP Mode */ if ((fd = socket (AF_INET, SOCK_DGRAM, 0)) < 0) { perror ("UDP Fatal Error while calling socket"); exit(-1); } rc = connect (fd, res->ai_addr, res->ai_addrlen); if (rc < 0) { printf ("UDP Fatal Error: Bind: %s\n",strerror(errno)); exit(-1); } /* setup socket to nonblocking so we can do a timeout on the connect call */ flags = fcntl(fd, F_GETFL,0); fcntl (fd, F_SETFL, flags | O_NONBLOCK); } //freeaddrinfo(res); return (0); } /***********************************************************************/ /* Used to store PDU which comes on a TCP session */ /***********************************************************************/ int AddMsg (void *p_msg, int size) { int i; if (FALSE == msgInitFlag) { for (i = 0; i < MSG_Q_SIZE; i++) { msg_q[i].p_msg = NULL; } msgCurrentIndex = 0; msgCurrentHead = 0; msgInitFlag = TRUE; } msg_q[msgCurrentIndex].p_msg = (void *)malloc (size); msg_q[msgCurrentIndex].size = size; memcpy (msg_q[msgCurrentIndex].p_msg, p_msg, size); msgCurrentIndex = (msgCurrentIndex + 1) % MSG_Q_SIZE; return (0); } /***********************************************************************/ /* Sends a msg to the iSNS without waiting for a response */ /***********************************************************************/ int ISNSJustSendCmd (ISNS_CMD * cmd) { int e; int len = cmd->hdr.len + sizeof (ISNS_HDR); cmd->hdr.len = htons (cmd->hdr.len); e = SendPDU (cmd, len); if (parserFlag) printf("PDU sent-->\n"); DumpHex (cmd, e); if (e < 0) { printf ("Error Sending.\n"); return (-1); } return (0); } /***********************************************************************/ /* Called to receive a PDU from the iSNS */ /***********************************************************************/ int RcvPDU (ISNS_CMD * cmd, int size) { int e; int rcvSize; socklen_t len; if (tcpFlag) { /* Using TCP */ rcvSize = 0; while ((e = TCPGetMsg (cmd, size)) == -1) { /* Loops until we receive a msg */ usleep(100); } } else { /* Using UDP */ len = sizeof (their_addr); e = recvfrom (fd, (char *)cmd, size, 0, res->ai_addr, &res->ai_addrlen); if (e < 0) { printf ("Error Receiving.\n"); return (e); } } return (e); } /***********************************************************************/ /* Sends a PDU. This function will actually call send() or sento(). */ /***********************************************************************/ int SendPDU (ISNS_CMD * cmd, int len) { int e; fd_set read_set; struct timeval timeout; int nb; if (tcpFlag) { /* Using TCP */ e = send (fd, (char *)cmd, len, 0); if (e < 0) { printf ("Error Sending TCP request.\n"); return (-1); } } else { e = sendto (fd, (char *) cmd, len, 0, res->ai_addr, res->ai_addrlen); if (e < 0) { printf ("Error Sending UDP request.\n"); return (e); } /* setup a timer to check for results */ FD_ZERO(&read_set); FD_SET(fd, &read_set); timeout.tv_sec = 5; // seconds timeout.tv_usec = 0; // microseconds nb = select(fd+1, &read_set, NULL, NULL, &timeout); if (nb < 0 ) printf ("Error setting up socket\n"); if (nb == 0) { printf ("Unable to connect - timedout\n"); exit (-1); } } return (e); } /***********************************************************************/ /* This will send a PDU and wait for a rsp. The rsp will be ignored. */ /***********************************************************************/ int ISNSSendCmd (ISNS_CMD * cmd) { int e; char buffer[MAX_PAYLOAD_SIZE]; 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); } if (parserFlag) 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"); } if (parserFlag) 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. */ /***********************************************************************/ int ISNSSendCmd2 (ISNS_CMD * cmd, char *rcvBuffer, int rcvSize) { int e; 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; } if (parserFlag) printf("PDU sent-->\n"); DumpHex (cmd, len); len = sizeof (their_addr); e = RcvPDU ((struct cmd *)rcvBuffer, rcvSize); if (e < 0) { printf ("Error Receiving.\n"); } if (parserFlag) printf("PDU rcv-->\n"); DumpHex (rcvBuffer, e); { char *ptr = (char *) rcvBuffer + 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 *)rcvBuffer; /* 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 listen for a heartbeat and using the heartbeat message to initialize some variables. */ /***********************************************************************/ int HeartBeatListener (void) { SNS_Hb *hb_ptr; SOCKET fd; struct sockaddr_in their_addr; struct sockaddr_in my_addr; ISNS_CMD cmd; int e; socklen_t len; if ((fd = socket (AF_INET, SOCK_DGRAM, 0)) < 0) { perror ("Fatal Error while calling socket"); return (-1); } /* setup for the bind */ my_addr.sin_family = AF_INET; my_addr.sin_port = htons ((short) ISNS_HEARTBEAT_PORT); my_addr.sin_addr.s_addr = INADDR_ANY; /* Do a Bind */ if (bind (fd, (struct sockaddr *) &my_addr, sizeof (my_addr)) < 0) { printf ("Fatal Error while Binding using heartbeat.\n"); return (-1); } len = sizeof (their_addr); printf ("Waiting for a heartbeat...\n"); while (1) { len = sizeof (their_addr); e = recvfrom (fd, (char *)&cmd, sizeof (cmd) - sizeof (ISNS_HDR), 0, (struct sockaddr *) &their_addr, &len); if (e < 0) { printf ("***ERROR: recvfrom().\n"); } if (ntohs (cmd.hdr.func_id) != ISNS_HEART_BEAT) continue; printf ("RCVd: Heart beat-->"); DumpHex (&cmd, e); hb_ptr = (struct sns_hb_payload *)((char *) &cmd + sizeof (ISNS_HDR)); hb_ptr->counter = ntohl (hb_ptr->counter); hb_ptr->interval = ntohl (hb_ptr->interval); hb_ptr->tcp_port = ntohs (hb_ptr->tcp_port); hb_ptr->udp_port = ntohs (hb_ptr->udp_port); isns_port = hb_ptr->udp_port; { struct in_addr ip; ip.s_addr = *(uint32_t *) ((char *) hb_ptr->ip_ptr + 12); printf ("SNS IP: %s.\n", inet_ntoa (ip)); strcpy (p_ip, inet_ntoa (ip)); } printf ("Heartbeat counter: %u.\n", hb_ptr->counter); printf ("Heartbeat interval: %u.\n", hb_ptr->interval); printf ("Heartbeat tcp_port: %u.\n", hb_ptr->tcp_port); printf ("Heartbeat udp_port: %u.\n", hb_ptr->udp_port); break; } return (0); } int L3_HeartBeatListener (void) { SNS_Hb *hb_ptr; SOCKET fd; struct sockaddr_in their_addr; struct sockaddr_in my_addr; ISNS_CMD cmd; int e; socklen_t len; struct ip_mreq stMreq; int iRet; if ((fd = socket (AF_INET, SOCK_DGRAM, 0)) < 0) { perror ("Fatal Error while calling socket"); return (-1); } /* setup for the bind */ my_addr.sin_family = AF_INET; my_addr.sin_port = htons ((short) ISNS_HEARTBEAT_PORT); my_addr.sin_addr.s_addr = INADDR_ANY; /* Do a Bind */ if (bind (fd, (struct sockaddr *) &my_addr, sizeof (my_addr)) < 0) { printf ("Fatal Error while Binding.\n"); return (-1); } /* join the multicast group */ stMreq.imr_multiaddr.s_addr = inet_addr(multicast_addr); stMreq.imr_interface.s_addr = INADDR_ANY; iRet = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&stMreq, sizeof(stMreq)); if (iRet < 0) { printf ("setsockopt() IP_ADD_MEMBERSHIP failed, Err: %d\n", #ifdef SNS_LINUX 0); #else WSAGetLastError()); #endif } len = sizeof (their_addr); printf ("Waiting for a heartbeat...\n"); while (1) { e = recvfrom (fd, (char *)&cmd, sizeof (cmd) - sizeof (ISNS_HDR), 0, (struct sockaddr *) &their_addr, &len); if (e < 0) { printf ("***ERROR: recvfrom().\n"); } if (ntohs (cmd.hdr.func_id) != ISNS_HEART_BEAT) continue; printf ("RCVd: Heart beat-->"); DumpHex (&cmd, e); hb_ptr = (struct sns_hb_payload *)((char *) &cmd + sizeof (ISNS_HDR)); hb_ptr->counter = ntohl (hb_ptr->counter); hb_ptr->interval = ntohl (hb_ptr->interval); hb_ptr->tcp_port = ntohs (hb_ptr->tcp_port); hb_ptr->udp_port = ntohs (hb_ptr->udp_port); isns_port = hb_ptr->udp_port; { struct in_addr ip; ip.s_addr = *(uint32_t *) ((char *) hb_ptr->ip_ptr + 12); printf ("SNS IP: %s.\n", inet_ntoa (ip)); strcpy (p_ip, inet_ntoa (ip)); } printf ("Heartbeat counter: %u.\n", hb_ptr->counter); printf ("Heartbeat interval: %u.\n", hb_ptr->interval); printf ("Heartbeat tcp_port: %u.\n", hb_ptr->tcp_port); printf ("Heartbeat udp_port: %u.\n", hb_ptr->udp_port); break; } return (0); } /***********************************************************************/ /* Thread used for listening and responding to UDP ESI/SCN messages. */ /***********************************************************************/ #ifdef SNS_LINUX int #else DWORD WINAPI #endif ESIListener (DWORD lparam) { char eid[256]; char buffer[1048]; char rbuffer[1048]; LISTENER_CB_P p_cb = (LISTENER_CB_P)&lparam; int ip = p_cb->ip; int port = p_cb->port; int e; socklen_t len; struct sockaddr_in their_addr; struct sockaddr_in my_addr; ISNS_Attr *p_attr; SOCKET fd; ISNS_CMD *p_cmd; ISNS_CMD *p_rcmd; printf ("ESI Listener thread started for EID=%s.\n", p_cb->eid); strcpy (eid, p_cb->eid); free (p_cb); if ((fd = socket (AF_INET, SOCK_DGRAM, 0)) < 0) { perror ("Fatal Error while calling socket"); return (0); } /* setup for the bind */ my_addr.sin_family = AF_INET; my_addr.sin_port = htons ((short) port); my_addr.sin_addr.s_addr = INADDR_ANY; /* Do a Bind */ if (bind (fd, (struct sockaddr *) &my_addr, sizeof (my_addr)) < 0) { printf ("Fatal Error while Binding.\n"); return (0); } /* Setup Variables, Addresses, Etc. */ their_addr.sin_family = AF_INET; /* host byte order */ their_addr.sin_port = htons ((short) isns_port); /* short, network byte order */ their_addr.sin_addr.s_addr = ip; len = sizeof (their_addr); p_cmd = (struct cmd *)buffer; p_attr = (struct ISNS_attr *)((char *) buffer + sizeof (ISNS_HDR)); while (1) { /* Listen for ESI */ e = recvfrom (fd, buffer, sizeof (buffer), 0, (struct sockaddr *) &their_addr, &len); if (e < 0) { printf ("Error Receiving.\n"); return (-1); } printf ("RCV ESI for %s via UDP-->",(char *)&p_attr->val); DumpHex (buffer, e); p_cmd->hdr.func_id = ntohs (p_cmd->hdr.func_id); /* Verify Msg */ if (p_cmd->hdr.func_id == ISNS_SCN) { printf ("***RCV: SCN.\n"); Process_SCN (p_cmd, e); continue; } if (p_cmd->hdr.func_id != ISNS_ESI) { printf ("***ERROR: Expected ESI, recv %#x.\n", p_cmd->hdr.func_id); continue; } /* Send response */ memset (rbuffer, 0, sizeof (rbuffer)); ISNSCreateHdr (ISNS_ESI_RSP, (struct cmd *)rbuffer, sizeof (rbuffer), 0); memcpy ((char *) rbuffer + sizeof (ISNS_HDR) + 4, buffer + sizeof (ISNS_HDR), ntohs (p_cmd->hdr.len)); p_rcmd = (struct cmd *)rbuffer; p_rcmd->hdr.len = ntohs (p_cmd->hdr.len) + 4; p_rcmd->hdr.xid = p_cmd->hdr.xid; ParseESI (buffer); if (FALSE == enableESIFlag) { printf ("ESI Response is disabled.\n"); continue; } printf ("esi rsp--->"); ISNSJustSendCmd ((struct cmd *)rbuffer); } } /***********************************************************************/ /* 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) { int e; char buffer[MAX_PAYLOAD_SIZE]; ISNS_CMD *p_cmd; int msg_size; int pending; int startIndex; int endIndex; startIndex = 0; endIndex = 0; while (1) { e = recv (fd, &buffer[endIndex], sizeof (buffer), 0); if (e < 0) { printf ("***ERROR: recv().\n"); exit(-1); } else if (e == 0) { printf("\nConnection closed by isns server\n"); exit(-1); } endIndex += e; pending = endIndex - startIndex; /* Check to see if we received all the message. */ while (pending > sizeof (ISNS_HDR)) { p_cmd = (struct cmd *)&buffer[startIndex]; msg_size = ntohs (p_cmd->hdr.len) + sizeof (ISNS_HDR); if (pending < msg_size) break; switch (ntohs (p_cmd->hdr.func_id)) { case ISNS_ESI: printf ("Rcv ESI via TCP-->\n"); DumpHex (p_cmd, msg_size); Send_ESI_Response (p_cmd, msg_size); break; case ISNS_SCN: printf ("Rcv SCN via TCP-->\n"); Process_SCN (p_cmd, msg_size); break; default: AddMsg (p_cmd, msg_size); break; } startIndex += msg_size; pending -= msg_size; } if (pending == 0) { startIndex = 0; endIndex = 0; } } } /***********************************************************************/ /* Used to retrieve messages from the TCP message Q. */ /***********************************************************************/ int TCPGetMsg (void *buffer, int b_size) { int size; if (NULL == (msg_q[msgCurrentHead].p_msg)) return (-1); size = msg_q[msgCurrentHead].size; memcpy (buffer, msg_q[msgCurrentHead].p_msg, msg_q[msgCurrentHead].size); free (msg_q[msgCurrentHead].p_msg); msg_q[msgCurrentHead].p_msg = NULL; msgCurrentHead = (msgCurrentHead + 1) % MSG_Q_SIZE; return (size); } isns-2.1-01/isnsclient/src/getarg.c0000644000175000017500000001525710665035160016151 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include /* for EOF */ #include /* for strchr() */ /* static (global) variables that are specified as exported by getopt() */ char *optarg = NULL; /* pointer to the start of the option argument */ int optind = 1; /* number of the next argv[] to be evaluated */ int opterr = 1; /* non-zero if a question mark should be returned when a non-valid option character is detected */ /* handle possible future character set concerns by putting this in a macro */ #define _next_char(string) (char)(*(string+1)) int getopt (int argc, char *argv[], char *opstring) { static char *pIndexPosition = NULL; /* place inside current argv string */ char *pArgString = NULL; /* where to start from next */ char *pOptString; /* the string in our program */ if (pIndexPosition != NULL) { /* we last left off inside an argv string */ if (*(++pIndexPosition)) { /* there is more to come in the most recent argv */ pArgString = pIndexPosition; } } if (pArgString == NULL) { /* we didn't leave off in the middle of an argv string */ if (optind >= argc) { /* more command-line arguments than the argument count */ pIndexPosition = NULL; /* not in the middle of anything */ return EOF; /* used up all command-line arguments */ } /*--------------------------------------------------------------------- * If the next argv[] is not an option, there can be no more options. *-------------------------------------------------------------------*/ pArgString = argv[optind++]; /* set this to the next argument ptr */ if (('/' != *pArgString) && /* doesn't start with a slash or a dash? */ ('-' != *pArgString)) { --optind; /* point to current arg once we're done */ optarg = NULL; /* no argument follows the option */ pIndexPosition = NULL; /* not in the middle of anything */ return EOF; /* used up all the command-line flags */ } /* check for special end-of-flags markers */ if ((strcmp (pArgString, "-") == 0) || (strcmp (pArgString, "--") == 0)) { optarg = NULL; /* no argument follows the option */ pIndexPosition = NULL; /* not in the middle of anything */ return EOF; /* encountered the special flag */ } pArgString++; /* look past the / or - */ } if (':' == *pArgString) { /* is it a colon? */ /*--------------------------------------------------------------------- * Rare case: if opterr is non-zero, return a question mark; * otherwise, just return the colon we're on. *-------------------------------------------------------------------*/ return (opterr ? (int) '?' : (int) ':'); } else if ((pOptString = strchr (opstring, *pArgString)) == 0) { /*--------------------------------------------------------------------- * The letter on the command-line wasn't any good. *-------------------------------------------------------------------*/ optarg = NULL; /* no argument follows the option */ pIndexPosition = NULL; /* not in the middle of anything */ return (opterr ? (int) '?' : (int) *pArgString); } else { /*--------------------------------------------------------------------- * The letter on the command-line matches one we expect to see *-------------------------------------------------------------------*/ if (':' == _next_char (pOptString)) { /* is the next letter a colon? */ /* It is a colon. Look for an argument string. */ if ('\0' != _next_char (pArgString)) { /* argument in this argv? */ optarg = &pArgString[1]; /* Yes, it is */ } else { /*------------------------------------------------------------- * The argument string must be in the next argv. * But, what if there is none (bad input from the user)? * In that case, return the letter, and optarg as NULL. *-----------------------------------------------------------*/ if (optind < argc) optarg = argv[optind++]; else { optarg = NULL; return (opterr ? (int) '?' : (int) *pArgString); } } pIndexPosition = NULL; /* not in the middle of anything */ } else { /* it's not a colon, so just return the letter */ optarg = NULL; /* no argument follows the option */ pIndexPosition = pArgString; /* point to the letter we're on */ } return (int) *pArgString; /* return the letter that matched */ } } isns-2.1-01/isnsclient/src/ifcp.c0000644000175000017500000004653710665035160015626 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include "isns.h" #include "comm.h" #include "util.h" #include "parse.h" static ISNS_CMD cmd; extern int replaceFlag; /*********************************************************************** Parses an iFCP query response msg. ***********************************************************************/ void ParseIFCPQuery (char *buffer) { char buffer2[MAX_PAYLOAD_SIZE]; ISNS_Attr *p_attr; ISNS_HDR *pdu; char *ptr; pdu = (struct isns_hdr *)buffer; ptr = (char *)buffer + sizeof (ISNS_HDR) + 4; 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); switch (p_attr->tag) { case ISNS_PORT_NAME: memset (buffer2, 0, sizeof (buffer2)); printf ("---------------------------------\n"); printf ("iFCP WWPN : %s\n", HexToAscii ((char *)&p_attr->val, p_attr->len, buffer2)); break; case ISNS_PORT_SYM_NAME: printf ("Alias : %s\n",(char *)&p_attr->val); break; case ISNS_PORT_TYPE: p_attr->val.etype = ntohl (p_attr->val.etype); printf ("Port Type : %#x\n", p_attr->val.etype); break; case ISNS_FABRIC_PORT_NAME: printf ("Fabric Port--->\n"); DumpHex (&p_attr->val, p_attr->len); break; case ISNS_FC_HARD_ADDR: printf ("Hard Addr--->\n"); DumpHex (&p_attr->val, p_attr->len); break; case ISNS_FC_PORT_IP: printf ("FC PORT IP--->\n"); DumpHex (&p_attr->val, p_attr->len); break; case ISNS_FC_COS: printf ("FC COS--->\n"); DumpHex (&p_attr->val, p_attr->len); break; case ISNS_FC4_TYPE: printf ("FC4 Type--->\n"); DumpHex (&p_attr->val, p_attr->len); break; case ISNS_FC4_DESC: printf ("FC4 Descriptor--->\n"); DumpHex (&p_attr->val, p_attr->len); break; case ISNS_FC4_FEATURE: printf ("FC4 Feature--->\n"); DumpHex (&p_attr->val, p_attr->len); break; case ISNS_IFCP_SCN_BITMAP: printf ("iFCP SCN Bitmap: %#x.\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; default: break; } ptr = (char *) ptr + p_attr->len + 8; } } /*********************************************************************** Example of a multi attribute iFCP Node registration. ***********************************************************************/ void MRegIFCP (void) { char cmdLine[256]; char eid[256]; char sym[256]; int port; int ip; int esi_interval; int port_type; int portal_group; char nodeAlias[256]; int c_size; char b[256]={0}; printf ("Multi-attr iFCP Node Registration.\n"); ISNSCreateHdr (ISNS_REG_DEV_ATTR_REQ, &cmd, sizeof (cmd), 0); /* Get Entity ID */ memset (eid, 0, sizeof (eid)); if (GetInput(cmdLine, "Entity ID", NULL, sizeof(cmdLine)) != 0) { strcpy (eid, cmdLine); ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4 (strlen (eid)), eid, 0); } ISNSAppendAttr (&cmd, 0, 0, NULL, 0); if (strlen (cmdLine) == 0) { /* Get Version */ { SOIP_Ver ver; memset (&ver, 0, sizeof (ver)); if (0 != GetInput (cmdLine, "Protocol Version Max", "(none)", sizeof (cmdLine))) { ver.max = atoi (cmdLine); } if (0 != GetInput (cmdLine, "Protocol Version Min", "(none)", sizeof (cmdLine))) { ver.min = atoi (cmdLine); } if (ver.max || ver.min) { ver.max = htons (ver.max); ver.min = htons (ver.min); ISNSAppendAttr ((struct cmd *)&cmd, ISNS_PROT_VER, 4, (char *)&ver, 0); } } } do { /* Get iFCP Node */ if (0 == GetHexInput (cmdLine, "iFCP Node WWPN", NULL, sizeof (cmdLine))) break; ISNSAppendAttr (&cmd, ISNS_PORT_NAME, 8, cmdLine, 0); /* Get Port Sym Name */ memset (nodeAlias, 0, sizeof (nodeAlias)); strcpy (nodeAlias, "Port Name"); c_size = GetInput (cmdLine, "iFCP Port Sym Name", nodeAlias, sizeof (cmdLine)); if (c_size != 0) { memcpy (nodeAlias, cmdLine, sizeof (cmdLine)); } ISNSAppendAttr (&cmd, ISNS_PORT_SYM_NAME, PAD4 (strlen (nodeAlias)), nodeAlias, 0); /* Get Port ID */ if (0 != GetInput (cmdLine, "iFCP Port ID", NULL, sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_PORT_ID, 4, cmdLine, 0); } /* Get Port Type */ if (0 != GetInput (cmdLine, "iFCP Port Type", NULL, sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_PORT_TYPE, 4, NULL, atoi (cmdLine)); } if (0 != GetHexInput (cmdLine, "FC Node WWNN", NULL, sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_NODE_NAME, 8, cmdLine, 0); } } while (1); /* Get IP */ do { if (0 == GetInput (cmdLine, "Portal IP", NULL, sizeof (cmdLine))) break; ip = inet_addr (cmdLine); { char tempb[256]; memset (tempb, 0, sizeof (tempb)); memcpy (tempb + 12, &ip, sizeof (ip)); ISNSAppendAttr (&cmd, ISNS_PORTAL_IP, 16, tempb, 0); } /* Get Port Type */ port_type = 0; if (0 != GetInput (cmdLine, "Portal Type", "*0:UDP 1:TCP", sizeof (cmdLine))) { port_type = atoi (cmdLine); if (port_type > 1) { printf ("***ERROR: Port type is wrong.\n"); return; } } /* Get Port */ port = DEFAULT_PORTAL_PORT; itoa(DEFAULT_PORTAL_PORT, b, 10); if (0 != GetInput (cmdLine, "Portal Port", b, sizeof (cmdLine))) { port = atoi (cmdLine); } ISNSAppendAttr (&cmd, ISNS_PORTAL_PORT, 4, NULL, port | (port_type == 1 ? 0 : 0x10000)); /* Get an Portal Sym Name */ memset (sym, 0, sizeof (sym)); if (0 != GetInput (cmdLine, "Portal Sym Name", NULL, sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_PORTAL_SYM_NAME, PAD4 (strlen (cmdLine)), cmdLine, 0); strcpy (cmdLine, sym); } /* Get Portal Group */ if (0 != GetInput (cmdLine, "Portal Group Tag", NULL, sizeof (cmdLine))) { portal_group = atoi (cmdLine); if (portal_group > 255 || portal_group == 0) { printf ("***ERROR: Invalid portal group.\n"); return; } memset (cmdLine, 0, sizeof (cmdLine)); ISNSAppendAttr (&cmd, ISNS_PORTAL_GROUP_TAG, 4, NULL, portal_group); } /* Get Interval */ esi_interval = 0; if (0 != GetInput (cmdLine, "ESI Interval", "(0)", sizeof (cmdLine))) { esi_interval = atoi (cmdLine); /* Get ESI Port */ ISNSAppendAttr (&cmd, ISNS_ESI_INTERVAL, 4, NULL, esi_interval); port = 0; if (0 != GetInput (cmdLine, "ESI/SCN Port", NULL, sizeof (cmdLine))) { port = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_ESI_PORT, 4, NULL, port); } if (port && esi_interval) { #ifndef SNS_LINUX DWORD junk; #endif LISTENER_CB_P p_cb; HANDLE hdle; #ifdef SNS_LINUX hdle = (void *)malloc (sizeof (pthread_t)); #endif p_cb = (void *)malloc (sizeof (LISTENER_CB)); memset (p_cb, 0, sizeof (LISTENER_CB)); strcpy (p_cb->eid, eid); p_cb->port = port; p_cb->ip = ip; #ifdef SNS_LINUX if (pthread_create (hdle, NULL, (void*) (ESIListener), p_cb) != 0) printf ("Could not create ESI Listener thread\n"); else #else hdle = CreateThread ((LPSECURITY_ATTRIBUTES)0, 0, (LPTHREAD_START_ROUTINE)ESIListener, p_cb, 0, &junk); #endif AddESIPortal (sym, port, hdle); } } } while (1); ISNSSendCmd (&cmd); } /*********************************************************************** Registers iFCP nodes. ***********************************************************************/ void RegIFCP (void) { char cmdLine[256]; char nodeID[256]; char eid[256]; char nodeAlias[256]; time_t t; int c_size; printf ("Registering iFCP Node.\n"); ISNSCreateHdr (ISNS_REG_DEV_ATTR_REQ, &cmd, sizeof (cmd), replaceFlag?ISNS_FLAG_REPLACE_REG:0); /* Get Entity ID */ c_size = GetInput (eid, "Entity ID", "(none)", sizeof (eid)); if (c_size != 0) { ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4 (strlen (eid)), eid, 0); } /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); if (strlen (eid) == 0) { /* Get Version */ { SOIP_Ver ver; memset (&ver, 0, sizeof (ver)); if (0 != GetInput (cmdLine, "Protocol Version Max", "(none)", sizeof (cmdLine))) { ver.max = atoi (cmdLine); } if (0 != GetInput (cmdLine, "Protocol Version Min", "(none)", sizeof (cmdLine))) { ver.min = atoi (cmdLine); } if (ver.max || ver.min) { ver.max = htons (ver.max); ver.min = htons (ver.min); ISNSAppendAttr ((struct cmd *)&cmd, ISNS_PROT_VER, 4, (char *)&ver, 0); } } } /* Get iFCP Node */ do { memset (nodeID, 0, sizeof (nodeID)); strcpy (nodeID, "iFCP "); time (&t); nodeID[0] = 0x02; GetHexTime ((char *) nodeID + 1); c_size = GetHexInput (cmdLine, "iFCP Node WWPN", nodeID, sizeof (cmdLine)); if (c_size != 0) { memcpy (nodeID, cmdLine, sizeof (cmdLine)); } ISNSAppendAttr (&cmd, ISNS_PORT_NAME, 8, nodeID, 0); /* Get Port Sym Name */ memset (nodeAlias, 0, sizeof (nodeAlias)); strcpy (nodeAlias, "Port Name"); c_size = GetInput (cmdLine, "iFCP Port Sym Name", nodeAlias, sizeof (cmdLine)); if (c_size != 0) { memcpy (nodeAlias, cmdLine, sizeof (cmdLine)); } ISNSAppendAttr (&cmd, ISNS_PORT_SYM_NAME, PAD4 (strlen (nodeAlias)), nodeAlias, 0); /* Get Port ID */ if (0 != GetInput (cmdLine, "iFCP Port ID", NULL, sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_PORT_ID, 4, cmdLine, 0); } /* Get Port Type */ if (0 != GetInput (cmdLine, "iFCP Port Type", NULL, sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_PORT_TYPE, 4, NULL, atoi (cmdLine)); } if (0 != GetHexInput (cmdLine, "FC Node WWNN", NULL, sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_NODE_NAME, 8, cmdLine, 0); } } while (GetYesNo (cmdLine, "More iFCP Node?", FALSE, sizeof (cmdLine))); ISNSSendCmd (&cmd); } /*********************************************************************** Update an iFCP node. ***********************************************************************/ void UpdateIFCP (void) { char cmdLine[256]; printf ("Updating iFCP Node.\n"); ISNSCreateHdr (ISNS_REG_DEV_ATTR_REQ, &cmd, sizeof (cmd), 0); /* Get iFCP Node */ if (0 != GetHexInput (cmdLine, "iFCP Node WWPN", NULL, sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_PORT_NAME, 8, cmdLine, 0); } /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* Get Port Sym Name */ if (0 != GetInput (cmdLine, "iFCP Port Sym Name", NULL, sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_PORT_SYM_NAME, PAD4 (strlen (cmdLine)), cmdLine, 0); } ISNSSendCmd (&cmd); } /*********************************************************************** Query for iFCP node(s). ***********************************************************************/ void GetIFCP (void) { char buffer[MAX_PAYLOAD_SIZE]; char cmdLine[256]; int c_size; int key_type; int ip; int port; /* Query for Node */ printf ("Query for IFCP Nodes.\n"); ISNSCreateHdr (ISNS_DEV_ATTR_QRY_REQ, &cmd, sizeof (cmd), 0); /* Src */ if (-1 == GetSrc (&cmd, 0)) return; /* Keys */ key_type = 0; if (0 != GetInput (cmdLine, "Key type (1:iFCP, 2:Entity ID 3:Portal IP/Port 4:FC Node WWNN 5:iFCP Index)>", "(none)", sizeof (cmdLine))) { key_type = atoi (cmdLine); if (key_type == 1) { do { c_size = GetHexInput (cmdLine, "iFCP Node WWPN", NULL, sizeof (cmdLine)); if (c_size != 0) { ISNSAppendAttr (&cmd, ISNS_PORT_NAME, 8, cmdLine, 0); } } while (c_size != 0); } else if (key_type == 2) { do { c_size = GetInput (cmdLine, "Entity ID >", "(none)", sizeof (cmdLine)); if (c_size != 0) { ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4 (strlen (cmdLine)), cmdLine, 0); } } while (c_size != 0); } else if (key_type == 3) { c_size = GetInput (cmdLine, "Portal IP >", "(none)", sizeof (cmdLine)); if (c_size != 0) { char b[16]; memset (b, 0, sizeof (b)); ip = inet_addr (cmdLine); memcpy ((char *) b + 12, &ip, sizeof (ip)); ISNSAppendAttr (&cmd, ISNS_PORTAL_IP, 16, b, 0); } c_size = GetInput (cmdLine, "Portal Port >", "(none)", sizeof (cmdLine)); if (c_size != 0) { port = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_PORTAL_PORT, 4, NULL, port); } } else if (key_type == 4) { c_size = GetHexInput (cmdLine, "FC Node WWNN", NULL, sizeof (cmdLine)); if (c_size != 0) { ISNSAppendAttr (&cmd, ISNS_NODE_NAME, 8, cmdLine, 0); } } else if (key_type == 5) { c_size = GetInput (cmdLine, "Portal Idx", "(none)", sizeof (cmdLine)); if (c_size != 0) { port = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_PORTAL_IDX, 4, NULL, port); } } else { printf ("***ERROR: Invalid key_type.\n"); return; } } ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PORT_NAME, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ENTITY_IDX, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PORT_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PORT_TYPE, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PORT_SYM_NAME, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_FABRIC_PORT_NAME, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_FC_HARD_ADDR, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_FC_PORT_IP, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_FC_COS, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_FC4_TYPE, 0, NULL, 0); // ISNSAppendAttr(&cmd, ISNS_FC4_DESC, 0, NULL, 0); // ISNSAppendAttr(&cmd, ISNS_FC4_FEATURE, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_IFCP_SCN_BITMAP, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_IFCP_NODE_CERT, 0, NULL, 0); if (0 == ISNSSendCmd2 (&cmd, buffer, sizeof (buffer))) { ParseIFCPQuery (buffer); } } /*********************************************************************** Adds one or more iFCP Nodes to a DD. ***********************************************************************/ void Add_IFCP_to_DD (void) { char cmdLine[256]; int dd_id; int iscsi_flag; int c_size; printf ("Adding IFCP to DD.\n"); ISNSCreateHdr (ISNS_REG_DD_REQ, &cmd, sizeof (cmd), 0); /* SRC */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* Get DD ID */ if (0==GetInput(cmdLine, "DD ID", NULL, sizeof(cmdLine))) { printf ("***ERROR: You must enter a DD.\n"); return; } dd_id = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_DD_ID, 4, NULL, dd_id); /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* Get iFCP Node WWPN */ iscsi_flag = FALSE; do { c_size = GetHexInput (cmdLine, "iFCP Node WWPN", NULL, sizeof (cmdLine)); if (c_size != 0) { ISNSAppendAttr (&cmd, ISNS_DD_IFCP_MEMBER, 8, cmdLine, 0); iscsi_flag = TRUE; } } while (c_size != 0); if (iscsi_flag) ISNSSendCmd (&cmd); else printf ("***ERROR: You must enter at least ONE iFCP Node.\n"); } /*********************************************************************** Deregisters one or more iFCP node. ***********************************************************************/ void DeRegisterPort (void) { char cmdLine[256]; int c_size; int nodeFlag; printf ("DeRegistering iFCP Node.\n"); ISNSCreateHdr (ISNS_DEREG_DEV_REQ, &cmd, sizeof (cmd), 0); if (-1 == GetSrc (&cmd, 0)) return; /* Get iFCP Node */ nodeFlag = FALSE; do { c_size = GetHexInput (cmdLine, "iFCP Node WWPN", NULL, sizeof (cmdLine)); if (c_size != 0) { ISNSAppendAttr (&cmd, ISNS_PORT_NAME, 8, cmdLine, 0); nodeFlag = TRUE; } } while (c_size != 0); if (!nodeFlag) { printf ("***ERROR: At least one node is required.\n"); return; } ISNSSendCmd (&cmd); } isns-2.1-01/isnsclient/src/fcnode.c0000644000175000017500000001663110665035160016133 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include "isns.h" #include "comm.h" #include "util.h" #include "parse.h" extern int replaceFlag; void DeRegisterNode (void) { char cmdLine[256]; int c_size; int nodeFlag; ISNS_CMD cmd; printf ("DeRegistering Port.\n"); /* Register Portal */ ISNSCreateHdr (ISNS_DEREG_DEV_REQ, &cmd, sizeof (cmd), 0); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* Get iFCP Node */ nodeFlag = FALSE; do { c_size = GetHexInput (cmdLine, "FC Node WWNN", NULL, sizeof (cmdLine)); if (c_size != 0) { ISNSAppendAttr (&cmd, ISNS_NODE_NAME, 8, cmdLine, 0); nodeFlag = TRUE; } } while (c_size != 0); if (!nodeFlag) { printf ("***ERROR: At least one node is required.\n"); return; } ISNSSendCmd (&cmd); } static int currentNode = 0; void RegisterNode (void) { int len; char buffer[MAX_PAYLOAD_SIZE]; ISNS_CMD cmd; currentNode++; printf ("Registering Node Name.\n"); ISNSCreateHdr (ISNS_REG_DEV_ATTR_REQ, &cmd, sizeof (cmd), 0); memset (buffer, 0, sizeof (buffer)); strcpy (buffer, "WWNN "); itoa (currentNode, (char *) buffer + strlen (buffer), sizeof (buffer)); ISNSAppendAttr (&cmd, ISNS_NODE_NAME, 8, buffer, 0); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_NODE_NAME, 8, buffer, 0); memset (buffer, 0, sizeof (buffer)); strcpy (buffer, "Node Sym Name "); itoa (currentNode, (char *) buffer + strlen (buffer), sizeof (buffer)); len = PAD4 (strlen (buffer)); ISNSAppendAttr (&cmd, ISNS_NODE_SYM_NAME, len, buffer, 0); ISNSAppendAttr (&cmd, ISNS_FC_NODE_IP, 16, "FC NODE IP000000", 0); ISNSAppendAttr (&cmd, ISNS_FC_NODE_IPA, 8, "FC NODE0", 0); ISNSSendCmd (&cmd); } void GetAllNodes (void) { ISNS_CMD cmd; /* Query for all Node */ printf ("Query for all Node Name.\n"); ISNSInsertQryHdr (ISNS_DEV_ATTR_QRY_REQ, &cmd); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_NODE_NAME, 8, NULL, 0); ISNSAppendAttr (&cmd, ISNS_NODE_SYM_NAME, 4, NULL, 0); ISNSAppendAttr (&cmd, ISNS_FC_NODE_IP, 16, NULL, 0); ISNSAppendAttr (&cmd, ISNS_FC_NODE_IPA, 8, NULL, 0); ISNSSendCmd (&cmd); } void ParseFCNodeQuery (char *buffer) { char buffer2[MAX_PAYLOAD_SIZE]; ISNS_Attr *p_attr; ISNS_HDR *pdu; char *ptr; pdu = (struct isns_hdr *)buffer; ptr = buffer + sizeof (ISNS_HDR) + 4; 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); switch (p_attr->tag) { case ISNS_NODE_NAME: memset (buffer2, 0, sizeof (buffer2)); printf ("---------------------------------\n"); printf ("FC WWNN : %s\n", HexToAscii ((char *)&p_attr->val, p_attr->len, buffer2)); break; case ISNS_NODE_SYM_NAME: printf ("Sym Name: %s\n",(char *)&p_attr->val); break; case ISNS_PORT_TYPE: p_attr->val.etype = ntohl (p_attr->val.etype); printf ("Port Type : %#x\n", p_attr->val.etype); break; case ISNS_FC_NODE_IP: printf ("FC PORT IP--->\n"); DumpHex (&p_attr->val, p_attr->len); break; case ISNS_FC_NODE_IPA: printf ("FC PORT IP--->\n"); DumpHex (&p_attr->val, p_attr->len); break; case ISNS_FC_NODE_CERT: printf ("FC PORT IP--->\n"); DumpHex (&p_attr->val, p_attr->len); break; default: break; } ptr = (char *) ptr + p_attr->len + 8; } } void RegFCNode (void) { char cmdLine[256]; char nodeID[256]; char nodeAlias[256]; int c_size; ISNS_CMD cmd; printf ("Registering FC Node.\n"); ISNSCreateHdr (ISNS_REG_DEV_ATTR_REQ, &cmd, sizeof (cmd), replaceFlag?ISNS_FLAG_REPLACE_REG:0); /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* Get FC Node */ nodeID[0] = 0x05; GetHexTime ((char *) nodeID + 1); c_size = GetHexInput (cmdLine, "FC Node WWNN", nodeID, sizeof (cmdLine)); if (c_size != 0) { memcpy (nodeID, cmdLine, sizeof (cmdLine)); } ISNSAppendAttr (&cmd, ISNS_NODE_NAME, 8, nodeID, 0); /* Get Port Sym Name */ memset (nodeAlias, 0, sizeof (nodeAlias)); strcpy (nodeAlias, "Port Name"); c_size = GetInput (cmdLine, "FC Device Sym Name", nodeAlias, sizeof (cmdLine)); if (c_size != 0) { memcpy (nodeAlias, cmdLine, sizeof (cmdLine)); } ISNSAppendAttr (&cmd, ISNS_NODE_SYM_NAME, PAD4 (strlen (nodeAlias)), nodeAlias, 0); ISNSSendCmd (&cmd); } void GetFCNode (void) { char buffer[MAX_PAYLOAD_SIZE]; ISNS_CMD cmd; printf ("Querying for All FC Node.\n"); ISNSCreateHdr (ISNS_DEV_ATTR_QRY_REQ, &cmd, sizeof (cmd), 0); /* SRC */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* DELIM */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* Get FC Node */ ISNSAppendAttr (&cmd, ISNS_NODE_NAME, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_NODE_SYM_NAME, 0, NULL, 0); if (0 == ISNSSendCmd2 (&cmd, buffer, sizeof (buffer))) { ParseFCNodeQuery (buffer); } } void UpdateFCNode (void) { char cmdLine[256]; ISNS_CMD cmd; printf ("Updating FC Node.\n"); ISNSCreateHdr (ISNS_REG_DEV_ATTR_REQ, &cmd, sizeof (cmd), 0); /* Get iFCP Node */ if (0 != GetHexInput (cmdLine, "FC Node WWNN", NULL, sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_NODE_NAME, 8, cmdLine, 0); } /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* Get Port Sym Name */ if (0 != GetInput (cmdLine, "iFCP Port Sym Name", NULL, sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_NODE_SYM_NAME, PAD4 (strlen (cmdLine)), cmdLine, 0); } ISNSSendCmd (&cmd); } isns-2.1-01/isnsclient/src/isns.c0000644000175000017500000010670310665035160015651 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include "isns.h" #include "comm.h" #include "util.h" #include "parse.h" #define MAX_ESI_ENTRIES (100) static ISNS_CMD cmd; /* Used by functions for msgs. */ int enableESIFlag; /* Set to non-zero when enable ESI reponse. */ typedef struct _esi_table_entry { char portal_name[256]; int port; HANDLE t_hdle; } ESI_TBL_ENTRY; /* ESI Table */ ESI_TBL_ENTRY esi_tble[MAX_ESI_ENTRIES]; /*********************************************************************/ /* Same as ISNSCreateHdr() but also zeros out the src field */ /*********************************************************************/ void ISNSInsertQryHdr (ISNS_FUNC_ID func_id, ISNS_CMD * cmd) { ISNSCreateHdr (func_id, cmd, sizeof(ISNS_CMD), 0); /* Insert a SRC ATTR of NULL */ ISNSAppendAttr (cmd, 0, 0, NULL, 0); } /*********************************************************************/ /* Queries for DDS */ /*********************************************************************/ void GetDDS (void) { char buffer[MAX_PAYLOAD_SIZE]; char cmdLine[256]; int id; int key_type; printf ("Get DDS.\n"); ISNSCreateHdr (ISNS_DEV_ATTR_QRY_REQ, &cmd, sizeof(cmd), 0); if (-1==GetSrc(&cmd, 0)) return; /* Get Key */ key_type = 0; if (0 != GetInput (cmdLine, "Key Type", "*0:none 1:DDS ID 2:DD ID 3:iSCSI Node", sizeof (cmdLine))) { key_type = atoi (cmdLine); } switch (key_type) { case 1: if (0 != GetInput (cmdLine, "DDS ID", NULL, sizeof (cmdLine))) { id = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_DDS_ID, 4, NULL, id); } break; case 2: if (0 != GetInput (cmdLine, "DD ID", NULL, sizeof (cmdLine))) { id = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_DD_ID, 4, NULL, id); } break; case 3: if (0 != GetInput (cmdLine, "iSCSI Node ID", NULL, sizeof (cmdLine))) { id = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (cmdLine)), cmdLine, 0); } break; default: ISNSAppendAttr (&cmd, ISNS_DDS_ID, 0, NULL, 0); break; } /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DDS_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DDS_SYM_NAME, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DDS_STATUS, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_SYM_NAME, 0, NULL, 0); if (0 == ISNSSendCmd2 (&cmd, buffer, sizeof (buffer))) ParseDDSQuery (buffer); } /*********************************************************************/ /* Query for DD */ /*********************************************************************/ void GetDD (void) { char buffer[MAX_PAYLOAD_SIZE]; char cmdLine[256]; int id; int key_type; printf ("Get DD.\n"); ISNSCreateHdr (ISNS_DEV_ATTR_QRY_REQ, &cmd, sizeof(cmd), 0); if (-1==GetSrc(&cmd, 0)) return; /* Get Key */ key_type = 0; if (0 != GetInput (cmdLine, "Key Type", "*0:none 1:DDS ID 2:DD ID 3:iSCSI Node", sizeof (cmdLine))) { key_type = atoi (cmdLine); } switch (key_type) { case 1: if (0 != GetInput (cmdLine, "DDS ID", NULL, sizeof (cmdLine))) { id = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_DDS_ID, 4, NULL, id); } break; case 2: if (0 != GetInput (cmdLine, "DD ID", NULL, sizeof (cmdLine))) { id = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_DD_ID, 4, NULL, id); } break; case 3: if (0 != GetInput (cmdLine, "iSCSI Node ID", NULL, sizeof (cmdLine))) { id = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (cmdLine)), cmdLine, 0); } break; default: ISNSAppendAttr (&cmd, ISNS_DD_ID, 0, NULL, 0); break; } /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_SYM_NAME, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_FEATURE_BITMAP, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_ISCSI_MEMBER, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_IFCP_MEMBER, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_ISCSI_MEMBER_IDX, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DDS_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DDS_SYM_NAME, 0, NULL, 0); if (0 == ISNSSendCmd2 (&cmd, buffer, sizeof (buffer))) ParseDDQuery (buffer); } /*********************************************************************/ /* Registers DDS */ /*********************************************************************/ void RegDDS (void) { static int sym_integer=0; char buffer[256]={0}; char sym[256]={0}; char cmdLine[256]={0}; uint32_t status=0; int id; extern int replaceFlag; printf ("Registering DDS.\n"); ISNSCreateHdr (ISNS_REG_DDS_REQ, &cmd, sizeof (cmd), replaceFlag?ISNS_FLAG_REPLACE_REG:0); /* Src */ if (-1==GetSrc(&cmd, 0)) return; /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); do { id = 0; /* Get DDS */ if (0 != GetInput (cmdLine, "DDS ID", NULL, sizeof (cmdLine))) { id = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_DDS_ID, 4, NULL, id); } else { ISNSAppendAttr (&cmd, ISNS_DDS_ID, 0, NULL, 0); } /* Get Sym Name */ memset (buffer, 0, sizeof (buffer)); strcpy (buffer, "DDS Sym Name "); if (id) itoa (id, buffer + strlen (buffer), 10); else itoa (sym_integer++, buffer + strlen (buffer), 10); if (0 == GetInput (cmdLine, "DDS Sym Name", buffer, sizeof (cmdLine))) { strcpy (cmdLine, buffer); } memset(sym, 0, sizeof(sym)); strcpy (sym, cmdLine); ISNSAppendAttr (&cmd, ISNS_DDS_SYM_NAME, PAD4 (strlen (sym)), sym, 0); /* Get Status */ status=0; if (0 != GetInput (cmdLine, "Enable", "*0/1", sizeof (cmdLine))) { if (1 == atoi (cmdLine)) status = 0x1; } ISNSAppendAttr (&cmd, ISNS_DDS_STATUS, 4, NULL, status); } while (GetYesNo (cmdLine, "More DDS?", FALSE, sizeof (cmdLine))); ISNSSendCmd (&cmd); } /*********************************************************************/ /* Updates a DDS */ /*********************************************************************/ void UpdateDDS (void) { char cmdLine[256]; uint32_t status = 0; int id; printf ("Updating DDS.\n"); ISNSCreateHdr (ISNS_REG_DDS_REQ, &cmd, sizeof (cmd), 0); if (-1==GetSrc(&cmd, 0)) return; /* Get DDS */ if (0 == GetInput (cmdLine, "DDS ID", NULL, sizeof (cmdLine))) { printf ("***ERROR: Required.\n"); return; } id = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_DDS_ID, 4, NULL, id); /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* Get Sym Name */ if (0 != GetInput (cmdLine, "DDS Sym Name", NULL, sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_DDS_SYM_NAME, PAD4 (strlen (cmdLine)), cmdLine, 0); } /* Get Status */ if (0 != GetInput (cmdLine, "Status Enable", "*0/1", sizeof (cmdLine))) { status = atoi (cmdLine) == 1 ? 0x1 : 0; ISNSAppendAttr (&cmd, ISNS_DDS_STATUS, 4, NULL, status); } ISNSSendCmd (&cmd); } /*********************************************************************/ /* Deregisters a DDS */ /*********************************************************************/ void DeRegDDS (void) { char cmdLine[256]; int id; printf ("DeRegistering DDS.\n"); ISNSCreateHdr (ISNS_DEREG_DDS_REQ, &cmd, sizeof (cmd), 0); /* Get SRC */ if (-1 == GetSrc (&cmd, 0)) return; /* Get DDS */ if (GetInput(cmdLine, "DDS ID", NULL, sizeof(cmdLine)) == 0) { printf ("***ERROR: You must enter a DDS ID.\n"); return; } id = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_DDS_ID, 4, NULL, id); /* Delimiter */ /* ISNSAppendAttr (&cmd, 0, 0, NULL, 0); */ ISNSSendCmd (&cmd); } /*********************************************************************/ /* Removes a DD from a DDS */ /*********************************************************************/ void Remove_DD_from_DDS (void) { char cmdLine[256]; int id; int c_size; int flag; printf ("DeRegister DD from DDS.\n"); ISNSCreateHdr (ISNS_DEREG_DDS_REQ, &cmd, sizeof (cmd), 0); /* Insert SRC */ if (-1 == GetSrc (&cmd, 0)) return; /* Get DDS */ if (GetInput(cmdLine, "DDS ID", NULL, sizeof(cmdLine)) == 0) { printf ("***ERROR: You must enter a DDS ID.\n"); return; } id = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_DDS_ID, 4, NULL, id); /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); flag = FALSE; do { c_size = GetInput (cmdLine, "DD ID", "(none)", sizeof (cmdLine)); if (0 != c_size) { ISNSAppendAttr (&cmd, ISNS_DD_ID, 4, NULL, atoi (cmdLine)); flag = TRUE; } } while (c_size); if (!flag) { printf ("***ERROR: You must enter at least 1 DD.\n"); return; } ISNSSendCmd (&cmd); } /*********************************************************************/ /* Registers a DD */ /*********************************************************************/ void RegDD (void) { static int sym_integer=0; char buffer[MAX_PAYLOAD_SIZE]; char cmdLine[256]; int id; printf ("Registering DD.\n"); ISNSCreateHdr (ISNS_REG_DD_REQ, &cmd, sizeof (cmd), 0); /* SRC */ if (-1==GetSrc(&cmd, 0)) return; /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* Get DD */ do { id =0; if (0==GetInput(cmdLine, "DD ID", NULL, sizeof(cmdLine))) { ISNSAppendAttr (&cmd, ISNS_DD_ID, 0, NULL, 0); } else { id = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_DD_ID, 4, NULL, id); } /* Get Sym Name */ memset (buffer, 0, sizeof (cmdLine)); strcpy (buffer, "DD Sym Name "); if (id) itoa (id, buffer + strlen (buffer), 10); else itoa (sym_integer++, buffer + strlen (buffer), 10); if (0 == GetInput (cmdLine, "DD Sym Name", buffer, sizeof (cmdLine))) { strcpy (cmdLine, buffer); } ISNSAppendAttr (&cmd, ISNS_DD_SYM_NAME, PAD4 (strlen (cmdLine)), cmdLine, 0); if (0 != GetInput (cmdLine, "DD Feature Bitmap", NULL, sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_DD_FEATURE_BITMAP, ISNS_DD_FEATURE_BITMAP_SIZE, NULL, atoi(cmdLine)); } } while (GetYesNo (cmdLine, "More DD?", FALSE, sizeof (cmdLine))); ISNSSendCmd (&cmd); } /*********************************************************************/ /* Updates a DD */ /*********************************************************************/ void UpdateDD (void) { char cmdLine[256]; int id; printf ("Updating DD.\n"); ISNSCreateHdr (ISNS_REG_DD_REQ, &cmd, sizeof (cmd), 0); if (-1==GetSrc(&cmd, 0)) return; if (GetInput (cmdLine, "DD ID", NULL, sizeof (cmdLine))) { id = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_DD_ID, 4, NULL, id); } else { printf ("***ERROR: Required.\n"); } /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* Get Sym Name */ if (GetInput (cmdLine, "DD Sym Name", NULL, sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_DD_SYM_NAME, PAD4 (strlen (cmdLine)), cmdLine, 0); } ISNSSendCmd (&cmd); } /*********************************************************************/ /* Deregisters a DD */ /*********************************************************************/ void DeRegDD (void) { char cmdLine[256]; int id; printf ("DeReg DD.\n"); ISNSCreateHdr (ISNS_DEREG_DD_REQ, &cmd, sizeof (cmd), 0); /* Insert SRC */ if (-1 == GetSrc (&cmd, 0)) return; if (0==GetInput(cmdLine, "DD ID", NULL, sizeof(cmdLine))) { printf ("***ERROR: You must enter a DD.\n"); return; } id = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_DD_ID, 4, NULL, id); /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSSendCmd (&cmd); } /*********************************************************************/ /* Removes a member from a DD */ /*********************************************************************/ void Remove_Member_from_DD (void) { char cmdLine[256]; int id; int mem_type; int flag; int c_size; printf ("Deregister DD Member.\n"); ISNSCreateHdr (ISNS_DEREG_DD_REQ, &cmd, sizeof (cmd), 0); /* Insert SRC */ if (-1 == GetSrc (&cmd, 0)) return; if (0==GetInput(cmdLine, "DD ID", NULL, sizeof(cmdLine))) { printf ("***ERROR: You must enter a DD.\n"); return; } id = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_DD_ID, 4, NULL, id); /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* Get Member */ mem_type = 1; if (0 != GetInput (cmdLine, "DD MEMBER type (1:iSCSI 2:iFCP)", "(none)", sizeof (cmdLine))) { mem_type = atoi (cmdLine); } flag = FALSE; do { switch (mem_type) { case (1): c_size = GetInput (cmdLine, "iSCSI Node ID", "(none)", sizeof (cmdLine)); if (c_size != 0) { ISNSAppendAttr (&cmd, ISNS_DD_ISCSI_MEMBER, PAD4 (strlen (cmdLine)), cmdLine, 0); flag = TRUE; } break; case (2): c_size = GetInput (cmdLine, "iFCP WWPN", "(none)", sizeof (cmdLine)); if (c_size != 0) { ISNSAppendAttr (&cmd, ISNS_DD_IFCP_MEMBER, 8, cmdLine, 0); flag = TRUE; } break; default: return; } } while (c_size != 0); if (!flag) { printf ("***ERROR: At least one node is required.\n"); return; } ISNSSendCmd (&cmd); } /*********************************************************************/ /* Adds a DD to a DDS */ /*********************************************************************/ void Add_DD_to_DDS (void) { char cmdLine[256]; int dd_id; int c_size; int dd_flag; printf ("Adding DD(s) to DDS.\n"); ISNSCreateHdr (ISNS_REG_DDS_REQ, &cmd, sizeof (cmd), 0); /* SRC */ if (-1 == GetSrc (&cmd, 0)) return; ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* Get DDS ID */ if (GetInput (cmdLine, "DDS ID", NULL, sizeof (cmdLine)) == 0) { printf ("***ERROR: You must enter a DDS ID.\n"); return; } dd_id = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_DDS_ID, 4, NULL, dd_id); /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* Get DD ID */ dd_flag = FALSE; do { c_size = GetInput (cmdLine, "DD ID", NULL, sizeof (cmdLine)); if (c_size) { dd_id = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_DD_ID, 4, NULL, dd_id); dd_flag = TRUE; } } while (c_size != 0); if (!dd_flag) { printf ("***ERROR: You must enter at least one DD ID.\n"); return; } ISNSSendCmd (&cmd); } /*********************************************************************/ /* Disable an ESI */ /*********************************************************************/ void DisableESI (void) { enableESIFlag = FALSE; } /*********************************************************************/ /* Enable an ESI */ /*********************************************************************/ void EnableESI (void) { enableESIFlag = TRUE; } /*********************************************************************/ /* Sends a SCN Event */ /*********************************************************************/ void Send_SCN_Event (void) { int scn_bitmap_type=0; int scn_bitmap=0; char cmdLine[256]; int key_type; int c_size; printf ("Sending SCN Event.\n"); ISNSCreateHdr (ISNS_SCN_EVENT, &cmd, sizeof (cmd), 0); /* Get SRC */ if (-1 == GetSrc (&cmd, 0)) return; key_type = 3; if (0 != GetInput (cmdLine, "Key type (1:iFCP, 2:Entity ID *3:iSCSI)", "(none)", sizeof (cmdLine))) { key_type = atoi (cmdLine); if (key_type == 1) { c_size = GetHexInput (cmdLine, "iFCP Node WWPN", NULL, sizeof (cmdLine)); if (c_size == 0) { printf ("***ERROR: You must enter a node id.\n"); return; } ISNSAppendAttr (&cmd, ISNS_PORT_NAME, 8, cmdLine, 0); scn_bitmap_type = ISNS_ISCSI_SCN_BITMAP; } // else if (key_type == 2) // { // c_size = // GetInput (cmdLine, "Entity ID", "(none)", sizeof (cmdLine)); // if (c_size == 0) // { // printf ("***ERROR: You must enter a node id.\n"); // return; // } // // ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4 (strlen (cmdLine)), // cmdLine, 0); // // scn_bitmap_type = ISNS_ENTITY_SCN_BITMAP; // } else if (key_type == 3) { c_size = GetInput (cmdLine, "iSCSI Node ID", "(none)", sizeof (cmdLine)); if (c_size == 0) { printf ("***ERROR: You must enter a node id.\n"); return; } ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (cmdLine)), cmdLine, 0); scn_bitmap_type = ISNS_ISCSI_SCN_BITMAP; } else { printf ("***ERROR: Invalid key_type.\n"); return; } } ISNSAppendAttr (&cmd, 0, 0, NULL, 0); scn_bitmap = 0x1F; c_size = GetInput (cmdLine, "SCN Bitmap", "(0x1F)", sizeof (cmdLine)); scn_bitmap = atoi (cmdLine); ISNSAppendAttr (&cmd, scn_bitmap_type, 4, NULL, scn_bitmap); ISNSSendCmd (&cmd); } /*********************************************************************/ /* Sends an ESI response */ /*********************************************************************/ int Send_ESI_Response (ISNS_CMD * p_cmd, int size) { char rbuffer[MAX_PAYLOAD_SIZE]; ISNS_CMD *p_rcmd; if (FALSE == enableESIFlag) { printf ("ESI Response is disabled.\n"); return (0); } /* Verify Msg */ if (ntohs (p_cmd->hdr.func_id) != ISNS_ESI) { printf ("***ERROR: Expected ESI, recv %#x.\n", p_cmd->hdr.func_id); return (-1); } /* Send response */ memset (rbuffer, 0, sizeof (rbuffer)); ISNSCreateHdr (ISNS_ESI_RSP, (struct cmd *)rbuffer, sizeof (rbuffer), 0); p_rcmd = (struct cmd *)rbuffer; p_rcmd->hdr.len = ntohs (p_cmd->hdr.len) + 4; p_rcmd->hdr.xid = p_cmd->hdr.xid; memcpy ((char *) rbuffer + sizeof (ISNS_HDR) + 4, (char *) p_cmd + sizeof (ISNS_HDR), ntohs (p_cmd->hdr.len)); ParseESI ((char *)p_cmd); printf ("Rsp --->\n"); ISNSJustSendCmd ((struct cmd *)rbuffer); return (0); } /*********************************************************************/ /* Process a SCN and sends a response */ /*********************************************************************/ void Process_SCN (ISNS_CMD * p_msg, int size) { ISNS_Attr *p_attr; char *ptr; // printf ("RCV SCN.\n"); DumpHex (p_msg, size); ptr = (char *) p_msg + sizeof (ISNS_HDR); printf ("---------------------------------\n"); while (ptr < (char *) p_msg + sizeof (ISNS_HDR) + ntohs (p_msg->hdr.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_PORT_NAME: { char buffer2[256] = { 0 }; memset (buffer2, 0, sizeof (buffer2)); printf ("iFCP WWPN : %s\n", HexToAscii ((char *)&p_attr->val, p_attr->len, buffer2)); break; } case ISNS_ENTITY_ID: case ISNS_ISCSI_NODE_ID: printf ("iSCSI ID : %s\n",(char *)&p_attr->val); break; case ISNS_TIMESTAMP: { time_t time_value; time_value = ntohl (p_attr->val.timestamp.t_time); printf ("TimeStamp: %s", ctime (&time_value)); break; } case ISNS_IFCP_SCN_BITMAP: case ISNS_ISCSI_SCN_BITMAP: p_attr->val.etype=ntohl(p_attr->val.etype); printf ("Bitmap: %#x.\n", p_attr->val.etype); break; default: break; } ptr = (char *) ptr + p_attr->len + 8; } /* Send a response */ { ISNSCreateHdr(ISNS_SCN_RES, &cmd, sizeof(cmd), 0); /* Append Dest Addr */ p_attr = (struct ISNS_attr *)((char *) p_msg + sizeof (ISNS_HDR)); /* Insert error code */ cmd.hdr.len=4; cmd.hdr.xid=p_msg->hdr.xid; ISNSAppendAttr(&cmd, p_attr->tag, p_attr->len, (char *)&p_attr->val, 0); printf("Sending SCN rsp-->\n"); ISNSJustSendCmd ((struct cmd *)&cmd); } } /*********************************************************************/ /* Registers a SCN */ /*********************************************************************/ int RegSCN (void) { char cmdLine[256]; int src_type; int scn_bitmap; /* Register SCN */ printf ("Register SCN.\n"); ISNSCreateHdr (ISNS_SCN_REG_REQ, &cmd, sizeof (cmd), 0); if (-1 == GetSrc (&cmd, 0)) return (-1); /* Src Type */ if (0 == GetInput (cmdLine, "Node type (1:iSCSI, 2:iFCP 3:Entity ID)>", "(req)", sizeof (cmdLine))) { printf ("***ERROR: You must enter a node type.\n"); return (-1); } src_type = atoi (cmdLine); scn_bitmap = 0x1F; if (src_type == 1) { if (0 == GetInput (cmdLine, "KEY: iSCSI Node ID", "(none)", sizeof (cmdLine))) { return (-1); } ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (cmdLine)), cmdLine, 0); if (0 != GetInput (cmdLine, "Event Bitmap (dec)", "0x1F", sizeof (cmdLine))) { scn_bitmap = atoi (cmdLine); } ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_SCN_BITMAP, 4, NULL, scn_bitmap); } else if (src_type == 2) { if (0 == GetHexInput (cmdLine, "KEY: iFCP WWPN", NULL, sizeof (cmdLine))) { return (-1); } ISNSAppendAttr (&cmd, ISNS_PORT_NAME, 8, cmdLine, 0); if (0 != GetInput (cmdLine, "Event Bitmap (int)", "0x1F", sizeof (cmdLine))) { scn_bitmap = atoi (cmdLine); } ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_IFCP_SCN_BITMAP, 4, NULL, scn_bitmap); } else if (src_type == 3) { // if (0 == // GetInput (cmdLine, "KEY: Entity ID", "(none)", // sizeof (cmdLine))) // { // return (-1); // } // // ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4 (strlen (cmdLine)), cmdLine, // 0); // // if (0 != // GetInput (cmdLine, "Event Bitmap (int)", "0x1F", sizeof (cmdLine))) // { // scn_bitmap = atoi (cmdLine); // } // // ISNSAppendAttr (&cmd, 0, 0, NULL, 0); // // ISNSAppendAttr (&cmd, ISNS_ENTITY_SCN_BITMAP, 4, NULL, scn_bitmap); } else { printf ("***ERROR: Invalid Node type.\n"); return (-1); } ISNSSendCmd (&cmd); return (0); } /*********************************************************************/ /* Deregisters a SCN */ /*********************************************************************/ void DeRegSCN (void) { char cmdLine[256]; int src_type; /* Register SCN */ printf ("DeRegister SCN.\n"); ISNSCreateHdr (ISNS_SCN_DEREG_REQ, &cmd, sizeof (cmd), 0); /* Src Type */ if (0 == GetInput (cmdLine, "SRC type (1:iSCSI, 2:iFCP 3:Entity ID)>", "(none)", sizeof (cmdLine))) { printf ("***ERROR: You must enter a SRC type.\n"); return; } src_type = atoi (cmdLine); if (src_type == 1) { if (0 == GetInput (cmdLine, "SRC: iSCSI Node ID", "(none)", sizeof (cmdLine))) { return; } ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (cmdLine)), cmdLine, 0); if (0 == GetInput (cmdLine, "KEY: iSCSI Node ID", "(none)", sizeof (cmdLine))) { return; } ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (cmdLine)), cmdLine, 0); } else if (src_type == 2) { if (0 == GetInput (cmdLine, "SRC: iFCP WWPN", "(none)", sizeof (cmdLine))) { return; } ISNSAppendAttr (&cmd, ISNS_PORT_NAME, 8, cmdLine, 0); if (0 == GetInput (cmdLine, "KEY: iFCP WWPN", "(none)", sizeof (cmdLine))) { return; } ISNSAppendAttr (&cmd, ISNS_PORT_NAME, 8, cmdLine, 0); } else if (src_type == 3) { if (0 == GetInput (cmdLine, "SRC: Entity ID", "(none)", sizeof (cmdLine))) { return; } ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4 (strlen (cmdLine)), cmdLine, 0); if (0 == GetInput (cmdLine, "KEY: Entity ID", "(none)", sizeof (cmdLine))) { return; } ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4 (strlen (cmdLine)), cmdLine, 0); } else { printf ("***ERROR: Invalid src type.\n"); return; } ISNSSendCmd (&cmd); } /*********************************************************************/ /* Initializes the ESI Table. This table contains the ESI thread handles and other relevant information. */ /*********************************************************************/ void InitESITable (void) { memset (esi_tble, 0, sizeof (esi_tble)); } /*********************************************************************/ /* Adds an ESI Entry to the table */ /*********************************************************************/ void AddESIPortal (char *p_name, int port, HANDLE hdle) { int i; for (i = 0; i < MAX_ESI_ENTRIES; i++) { if (esi_tble[i].t_hdle == 0) { strcpy (esi_tble[i].portal_name, p_name); esi_tble[i].port = port; esi_tble[i].t_hdle = hdle; break; } } } /*********************************************************************/ /* Kills all ESI Threads */ /*********************************************************************/ void KillESIThreads (void) { int i; printf ("Disabling ALL ESI reponses.\n"); for (i = 0; i < MAX_ESI_ENTRIES; i++) { if (esi_tble[i].t_hdle != 0) { #ifdef SNS_LINUX pthread_cancel(*(esi_tble[i].t_hdle)); free(esi_tble[i].t_hdle); esi_tble[i].t_hdle = 0; #else TerminateThread (esi_tble[i].t_hdle, -1); #endif } } } /*********************************************************************/ /* Implements a Get Next */ /*********************************************************************/ void GetNext(void) { static int currentTag=0; static int currentLen=0; static char currentValue[256]={0}; static int currentTag2=0; static int currentLen2=0; static char currentValue2[256]={0}; char buffer[MAX_PAYLOAD_SIZE]={0}; char cmdLine[256]={0}; int type=0; /* Register SCN */ printf ("Get Next Attr.\n"); ISNSCreateHdr (ISNS_DEV_GET_NXT_REQ, &cmd, sizeof (cmd), 0); if (-1==GetSrc(&cmd, 0)) return; /* Enter Type */ if (0!=GetInput(cmdLine, "Object type", "*0:Get Next 1:iSCSI ID 2:Entity ID\ 3:iFCP 4:Portal IP/PORT 5:iSCSI Idx 6:Entity Idx \ 7:Portal Idx 8:DD ID 9:DDS ID", sizeof(cmdLine))) { type=atoi(cmdLine); } switch (type) { case (0): if (currentTag==0) { printf("Object Type needed for first iteration.\n"); return; } else { ISNSAppendAttr(&cmd, currentTag, currentLen, currentValue, 0); if (currentTag==ISNS_PORTAL_IP || currentTag==ISNS_PORTAL_PORT) { ISNSAppendAttr(&cmd, currentTag2, currentLen2, currentValue2, 0); } } break; case (1): if (0 == GetInput (cmdLine, "KEY: iSCSI Node Id", "(none)", sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_ALIAS, 0, NULL, 0); } else { ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (cmdLine)), cmdLine, 0); } break; case (2): if (0 == GetInput (cmdLine, "KEY: Entity ID", "(none)", sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, 0, NULL, 0); } else { ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4 (strlen (cmdLine)), cmdLine, 0); } break; case (3): if (0 == GetHexInput (cmdLine, "KEY: iFCP Node WWPN", NULL, sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_PORT_NAME, 0, NULL, 0); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PORT_SYM_NAME, 0, NULL, 0); } else { ISNSAppendAttr (&cmd, ISNS_PORT_NAME, 8, cmdLine, 0); } break; case (4): /* Get IP */ if (0 != GetInput (cmdLine, "Portal IP", NULL, sizeof (cmdLine))) { int port; int port_type; int ip; ip = inet_addr (cmdLine); { char tempb[256]; memset (tempb, 0, sizeof (tempb)); memcpy (tempb + 12, &ip, sizeof (ip)); ISNSAppendAttr (&cmd, ISNS_PORTAL_IP, 16, tempb, 0); } /* Get Port Type */ port_type = 0; if (0 != GetInput (cmdLine, "Portal Type", "*0:UDP 1:TCP", sizeof (cmdLine))) { port_type = atoi (cmdLine); if (port_type > 1) { printf ("***ERROR: Port type is wrong.\n"); return; } } /* Get Port */ if (0 == GetInput (cmdLine, "Portal Port", NULL, sizeof (cmdLine))) { printf ("***ERROR: You must enter a port.\n"); return; } port = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_PORTAL_PORT, 4, NULL, port | (port_type == 1 ? 0 : 0x10000)); } else { ISNSAppendAttr (&cmd, ISNS_PORTAL_IP, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PORTAL_PORT, 0, NULL, 0); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PORTAL_SYM_NAME, 0, NULL, 0); } break; case 5: if (0 == GetInput (cmdLine, "KEY: iSCSI Index", "(none)", sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_ISCSI_IDX, 0, NULL, 0); } else { ISNSAppendAttr (&cmd, ISNS_ISCSI_IDX, ISNS_INDEX_SIZE, NULL, atoi(cmdLine)); } ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_ALIAS, 0, NULL, 0); break; case 6: if (0 == GetInput (cmdLine, "KEY: Entity Index", "(none)", sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_ENTITY_IDX, 0, NULL, 0); } else { ISNSAppendAttr (&cmd, ISNS_ENTITY_IDX, ISNS_INDEX_SIZE, NULL, atoi(cmdLine)); } break; case 7: if (0 != GetInput (cmdLine, "Key: Portal Index", NULL, sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_PORTAL_IDX, ISNS_INDEX_SIZE, NULL, atoi(cmdLine)); } else { ISNSAppendAttr (&cmd, ISNS_PORTAL_IDX, ISNS_INDEX_SIZE, NULL, 0); } ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PORTAL_SYM_NAME, 0, NULL, 0); break; case 8: if (0 != GetInput (cmdLine, "Key: DD ID", NULL, sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_DD_ID, ISNS_INDEX_SIZE, NULL, atoi(cmdLine)); } else { ISNSAppendAttr (&cmd, ISNS_DD_ID, 0, NULL, 0); } ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_ID, 0, NULL, 0); break; case 9: if (0 != GetInput (cmdLine, "Key: DDS ID", NULL, sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_DDS_ID, ISNS_INDEX_SIZE, NULL, atoi(cmdLine)); } else { ISNSAppendAttr (&cmd, ISNS_DDS_ID, 0, NULL, 0); } ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DDS_ID, 0, NULL, 0); break; default: printf("Invalid type.\n"); return; break; } /* Call ParseGetNext */ if (0 == ISNSSendCmd2 (&cmd, buffer, sizeof (buffer))) { ISNS_Attr *p_attr; p_attr=(struct ISNS_attr *)((char *)buffer+sizeof(ISNS_HDR)+4); memset(currentValue, 0, sizeof(currentValue)); memcpy(currentValue, &p_attr->val, ntohl(p_attr->len)); currentTag=ntohl(p_attr->tag); currentLen=ntohl(p_attr->len); if (currentTag==ISNS_PORTAL_IP || currentTag==ISNS_PORTAL_PORT) { p_attr=(struct ISNS_attr *)((char *)p_attr + 8 + ntohl(p_attr->len)); memset(currentValue2, 0, sizeof(currentValue2)); memcpy(currentValue2, &p_attr->val, ntohl(p_attr->len)); currentTag2=ntohl(p_attr->tag); currentLen2=ntohl(p_attr->len); } } else { currentTag=0; } } isns-2.1-01/isnsclient/src/main.c0000644000175000017500000001414510665035160015617 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifdef SNS_LINUX #include #else #include "getarg.h" #endif #include "isns.h" #include "iscsi.h" #include "portal.h" #include "entity.h" #include "ifcp.h" #include "fcnode.h" #include "util.h" #include "comm.h" #include "menu.h" extern void CommandLineDispatch (char , char *, char *, char *,char *); /*************************************** Globals **************************************/ char p_ip[256]; extern int isns_port; extern int enableESIFlag; extern char multicast_addr[20]; /******************************** Locals ********************************/ static char query[100]=""; static char reg[100]=""; static char dereg[100]=""; static char idvalue[100]=""; static char idvaluemember[256]=""; static char id3[256]=""; /***************** Usage Message *****************/ char Usage[] = "\ Usage: isnsadm [options] \n\ Options:\n\ -h Listen for L2 heartbeat from an iSNS.\n\ -? Help.\n\ \n\ -a ip iSNS Address.\n\ -p port Port used for sending. Default is port 3205.\n\ -q type Query\n\ type: dds\n\ type: dd\n\ type: iscsi\n\ type: entity\n\ type: portal\n\ -r type -n name -m member -v portvalue \n\ Register\n\ type:dds name:id\n\ type:dd name:id\n\ type:ddsmember name:ddsid member:ddid\n\ type:ddmember name:ddid member:iscsinode\n\ type:entity name:id\n\ type:iscsi name:iqnvalue member:entityid\n\ type:portal name:ipvalue member:entityid -v port\n\ -d type -n name -m member\n\ Deregister\n\ type:dds name=index\n\ type:dd name=index\n\ type:ddsmember name=ddsid member:ddid\n\ type:ddmember name:ddid member:iscsinode\n\ type:entity name:id\n\ type:iscsi name:iqnvalue\n\ type:portal name:ipvalue member:port\n\ \n\ "; /***********************************************************************/ int main (int argc, char **argv) { int l3_hb_flag; int hb_flag; int c; int tcpFlag; memset (p_ip, 0, sizeof (p_ip)); printf ("IETF iSNS Open Source Client, v%s.\n", ISNS_VERSION); if (argc < 1) { fprintf (stderr, Usage); exit (0); } /* init ESI */ InitESITable (); /* Default Values */ isns_port = ISNS_SERVER_PORT; //tcpFlag = FALSE; tcpFlag = TRUE; enableESIFlag = TRUE; hb_flag = FALSE; l3_hb_flag = FALSE; /* Parse Command Line arguments */ while (optind != argc) { c = getopt (argc, argv, "htd:p:a:m:q:r:n:e:v:"); switch (c) { case EOF: optarg = argv[optind]; optind++; break; case 't': tcpFlag = TRUE; break; case 'p': isns_port = atoi (optarg); break; case 'a': strcpy (p_ip, optarg); break; case 'h': hb_flag=TRUE; break; case 'c': l3_hb_flag=TRUE; strcpy (multicast_addr, optarg); break; case 'q': strcpy (query, optarg); break; case 'r': strcpy (reg, optarg); break; case 'd': strcpy (dereg, optarg); break; case 'n': strcpy (idvalue, optarg); break; case 'm': strcpy (idvaluemember, optarg); break; case 'v': strcpy (id3, optarg); break; case '?': default: fprintf (stderr, Usage); exit (0); } } if (0 == strlen (p_ip) && hb_flag==FALSE && l3_hb_flag==FALSE) { fprintf (stderr, Usage); exit (0); } /* Init the Communications sockets */ if (-1==InitComm(hb_flag, l3_hb_flag, tcpFlag)) exit(-1); if (strcmp(query,"")) CommandLineDispatch ('q',query,idvalue,idvaluemember,id3); else if (strcmp(reg,"")) { if ( 0 == strlen(idvalue)) printf ("-n parameter required\n"); else CommandLineDispatch ('r',reg,idvalue,idvaluemember,id3); } else if (strcmp(dereg,"")) { if ( 0 == strlen(idvalue)) printf ("-n parameter required\n"); else CommandLineDispatch ('d',dereg,idvalue,idvaluemember,id3); } return (0); } isns-2.1-01/isnsclient/src/menu.c0000644000175000017500000001537410665035160015644 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include "isns.h" #include "iscsi.h" #include "portal.h" #include "entity.h" #include "ifcp.h" #include "fcnode.h" #include "util.h" #include "comm.h" #include "menu.h" #include "custom.h" extern int hexDumpFlag; extern int parserFlag; void HexDumpToggle(void); void ParserToggle(void); void ReplaceSet(void); /* Number of menu options */ #define MENU_SIZE (48) int replaceFlag = TRUE; /***********************************************************************/ /* These are all the menu options. The 1st field is the option name. 2nd is a unique ID, 3rd is the function call. */ /***********************************************************************/ MENU_ITEM menu[MENU_SIZE] = { {"Register an Entity", 1, (void *)RegEntityI}, {"Register a Portal", 2, RegPortalI}, {"Register iSCSI Node", 3, RegisterISCSI_I}, {"Register iFCP Node", 4, RegIFCP}, {"Register FC Node", 5, RegFCNode}, {"Register DDS", 6, RegDDS}, {"Register DD", 7, RegDD}, {"Query for Entities", 10, GetEntities}, {"Query for Portals", 11, GetPortals}, {"Query for iSCSI Node", 12, GetISCSI}, {"Query for iFCP Node", 13, GetIFCP}, {"Query for FC Node", 14, GetFCNode}, {"Query for DDS", 15, GetDDS}, {"Query for DD", 16, GetDD}, {"Get Next Attr", 17, GetNext}, {"DeRegister an Entity", 20, DeRegisterEntity}, {"DeRegister a Portal", 21, DeRegisterPortal}, {"DeRegister an iSCSI Node", 22, DeRegisterISCSI}, {"DeRegister iFCP Node(s)", 23, DeRegisterPort}, {"DeRegister FC Node(s)", 24, DeRegisterNode}, {"DeRegister a DDS", 25, DeRegDDS}, {"DeRegister a DD", 26, DeRegDD}, {"Disable All ESI Response", 30, DisableESI}, {"Enable All ESI Response", 31, EnableESI}, {"Add DD to DDS", 60, Add_DD_to_DDS}, {"Add ISCSI Node to DD", 61, Add_ISCSI_to_DD}, {"Add IFCP Node to DD", 62, Add_IFCP_to_DD}, {"Remove member from DD", 63, Remove_Member_from_DD}, {"Remove DD from DDS", 64, Remove_DD_from_DDS}, {"Register SCN", 70, (void *)RegSCN}, {"DeRegister SCN", 71, DeRegSCN}, {"Send SCN Event", 72, Send_SCN_Event}, {"Update Entity", 80, (void *)UpdateEntity}, {"Update Portal", 81, UpdatePortal}, {"Update iSCSI Node", 82, UpdateISCSI}, {"Update iFCP Node", 83, UpdateIFCP}, {"Update FC Node", 84, UpdateFCNode}, {"Update DDS", 85, UpdateDDS}, {"Update DD", 86, UpdateDD}, {"Multi-Attr iSCSI Registration", 90, MRegISCSI}, {"Multi-Attr iFCP Registration", 91, MRegIFCP}, {"Custom Register 1", 100, RegCustom1}, {"Custom Register 2", 101, RegCustom2}, {"Custom Register 3", 102, RegCustom3}, {"Toggle Hex Dump On/Off", 300, HexDumpToggle}, {"Toggle PDU Parser On/Off", 301, ParserToggle}, {"Enable/Disable REPLACE FLAG", 302, ReplaceSet} }; void ReplaceSet(void) { char cmdLine[ 256 ]; if ( GetYesNo(cmdLine, "Enable REPLACE flag", replaceFlag, sizeof(cmdLine))) { replaceFlag = TRUE; } else { replaceFlag = FALSE; } printf ("Replace bit is %s!\n", replaceFlag?"ENABLED":"DISABLED"); } void HexDumpToggle(void) { hexDumpFlag = hexDumpFlag?FALSE:TRUE; printf("Hex dump is now %s.\n", hexDumpFlag?"ON":"OFF"); } void ParserToggle(void) { parserFlag = parserFlag?FALSE:TRUE; printf("PDU Parser is now %s.\n", parserFlag?"ON":"OFF"); } /***********************************************************************/ /* Displays the menu */ /***********************************************************************/ void DisplayMenu (void) { int i; printf ("Item\t Menu Name\n"); printf ("----\t ---------\n"); printf ("-1)\t exit.\n"); printf ("0)\t Display Menu\n"); for (i = 0; i < MENU_SIZE; i++) { printf ("%d)\t %s.\n", menu[i].id, menu[i].name); } } /***********************************************************************/ /* Prompt the user for a menu selection and calls the menu function. */ /***********************************************************************/ void Interact (void) { int i; int selection; DisplayMenu (); while (1) { selection = GetCommand (); if (selection == 0) { DisplayMenu (); } else if (selection == -1) break; else { for (i = 0; i < MENU_SIZE; i++) { if (selection == menu[i].id) { if (menu[i].func == NULL) { printf ("Selection not implemented.\n"); break; } menu[i].func (); break; } } } } } isns-2.1-01/isnsclient/src/entity.c0000644000175000017500000002166210665035160016211 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include "isns.h" #include "comm.h" #include "util.h" #include "parse.h" extern int replaceFlag; /***********************************************************************/ /* Deregisters an entity */ /***********************************************************************/ void DeRegisterEntity (void) { char cmdLine[256]; int c_size; int flag; ISNS_CMD cmd; printf ("DeRegistering Entity.\n"); /* Register Portal */ ISNSCreateHdr (ISNS_DEREG_DEV_REQ, &cmd, sizeof (cmd), 0); /* Get SRC */ if (-1 == GetSrc (&cmd, 0)) return; /* Add Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* Get Node */ flag = FALSE; do { c_size = GetInput (cmdLine, "Entity ID", "(none)", sizeof (cmdLine)); if (c_size != 0) { ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4 (strlen (cmdLine)), cmdLine, 0); flag = TRUE; } } while (c_size != 0); if (!flag) { printf ("***ERROR: At least one node is required.\n"); return; } ISNSSendCmd (&cmd); } /***********************************************************************/ /* Queries for entities */ /***********************************************************************/ void GetEntities (void) { int c_size; char buffer[MAX_PAYLOAD_SIZE]; char cmdLine[256]; ISNS_CMD cmd; int key_type = 0; int added = FALSE; printf ("Query For Entities.\n"); ISNSCreateHdr (ISNS_DEV_ATTR_QRY_REQ, &cmd, sizeof (cmd), 0); /* Src */ if (-1 == GetSrc (&cmd, 0)) return; if (0 != GetInput (cmdLine, "Key Type", "*0:Entity Id 1: Entity Index", sizeof (cmdLine))) { key_type = atoi (cmdLine); } do { switch (key_type) { case 1: c_size = GetInput (cmdLine, "Enitity ID", "(All)", sizeof (cmdLine)); if (c_size != 0) { ISNSAppendAttr (&cmd, ISNS_ENTITY_IDX, ISNS_INDEX_SIZE, NULL, atoi(cmdLine)); } break; default: c_size = GetInput (cmdLine, "Enitity ID", "(All)", sizeof (cmdLine)); if (c_size != 0) { ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4 (strlen (cmdLine)), cmdLine, 0); added = TRUE; } else if (!added) ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, 0, NULL, 0); } } while (c_size != 0); /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ENTITY_IDX, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ENTITY_TYPE, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_MGMT_IP, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_TIMESTAMP, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PROT_VER, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ENTITY_PERIOD, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PORTAL_IP, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PORTAL_PORT, 0, NULL, 0); if (0 == ISNSSendCmd2 (&cmd, buffer, sizeof (buffer))) ParseEntityQuery (buffer); } /***********************************************************************/ /* Register entities */ /***********************************************************************/ int RegEntityI (void) { char cmdLine[256]; int ip; int type; ISNS_CMD cmd; printf ("Registering Entity.\n"); /* Insert Header */ printf("replaceFlag:%i\n",replaceFlag); printf("hdr replace:%i\n",replaceFlag?ISNS_FLAG_REPLACE_REG:0); ISNSCreateHdr (ISNS_REG_DEV_ATTR_REQ, &cmd, sizeof (cmd), replaceFlag?ISNS_FLAG_REPLACE_REG:0); if (-1==GetSrc(&cmd,0)) return 0; /* Add Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* Get an entity ID */ if (0 != GetInput (cmdLine, "Entity ID", "(none)", sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4 (strlen (cmdLine)), cmdLine,0); } /* Get Type */ type = 2; if (0 != GetInput (cmdLine, "Entity Type", "*2(iSCSI)/3(iFCP)", sizeof (cmdLine))) { type = atoi (cmdLine); } ISNSAppendAttr (&cmd, ISNS_ENTITY_TYPE, 4, NULL, type); /* Get IP */ ip = inet_addr (DEFAULT_IP_ADDR); if (0 != GetInput (cmdLine, "Mgt Ip-Address", DEFAULT_IP_ADDR, sizeof (cmdLine))) { ip = inet_addr (cmdLine); } { char tempb[256]; memset (tempb, 0, sizeof (tempb)); memcpy (tempb + 12, &ip, sizeof (ip)); ISNSAppendAttr (&cmd, ISNS_MGMT_IP, 16, tempb, 0); } /* Get Version */ { SOIP_Ver ver; memset (&ver, 0, sizeof (ver)); if (0 != GetInput (cmdLine, "Protocol Version Max", "(none)", sizeof (cmdLine))) { ver.max = atoi (cmdLine); } if (0 != GetInput (cmdLine, "Protocol Version Min", "(none)", sizeof (cmdLine))) { ver.min = atoi (cmdLine); } if (ver.max || ver.min) { ver.max = htons (ver.max); ver.min = htons (ver.min); ISNSAppendAttr (&cmd, ISNS_PROT_VER, 4, (char *)&ver, 0); } } if (0 != GetInput (cmdLine, "Entity Period", "(none)", sizeof( cmdLine ))) { int period; period = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_ENTITY_PERIOD, 4, NULL, period); } ISNSSendCmd (&cmd); return (0); } /***********************************************************************/ /* Updates an existing entity */ /***********************************************************************/ int UpdateEntity (void) { char cmdLine[256]; int ip; ISNS_CMD cmd; printf ("Updating Entity.\n"); /* Insert Header */ ISNSCreateHdr (ISNS_REG_DEV_ATTR_REQ, &cmd, sizeof (cmd), 0); /* Get an entity ID */ if (0 == GetInput (cmdLine, "Entity ID", "(none)", sizeof (cmdLine))) { printf ("***ERROR: You must enter an Entity ID.\n"); return (-1); } ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4 (strlen (cmdLine)), cmdLine, 0); /* Add Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* Get IP */ if (0 != GetInput (cmdLine, "Mgt Ip-Address", "(none)", sizeof (cmdLine))) { ip = inet_addr (cmdLine); { char tempb[256]; memset (tempb, 0, sizeof (tempb)); memcpy (tempb + 12, &ip, sizeof (ip)); ISNSAppendAttr (&cmd, ISNS_MGMT_IP, 16, tempb, 0); } } /* Get Version */ { SOIP_Ver ver; memset (&ver, 0, sizeof (ver)); if (0 != GetInput (cmdLine, "Protocol Version Max", "(none)", sizeof (cmdLine))) { ver.max = atoi (cmdLine); } if (0 != GetInput (cmdLine, "Protocol Version Min", "(none)", sizeof (cmdLine))) { ver.min = atoi (cmdLine); } if (ver.max || ver.min) { ver.max = htons (ver.max); ver.min = htons (ver.min); ISNSAppendAttr (&cmd, ISNS_PROT_VER, 4, (char *)&ver, 0); } } if (0 != GetInput (cmdLine, "Entity Period", "(none)", sizeof( cmdLine ))) { int period; period = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_ENTITY_PERIOD, 4, NULL, period); } ISNSSendCmd (&cmd); return (0); } isns-2.1-01/isnsclient/src/util.c0000644000175000017500000002223210665035160015644 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include "isns.h" #include "util.h" #include "parse.h" #ifndef HEX_DUMP_BYTES_PER_LINE #define HEX_DUMP_BYTES_PER_LINE (16) #endif int hexDumpFlag; int parserFlag=FALSE; /*************************************************** _DumpHex: Prints out the contents of a ptr in hex. ****************************************************/ void DumpHex (void *data, int size) { int count = 0; int count2 = 0; char ascii[HEX_DUMP_BYTES_PER_LINE + 1]; if (hexDumpFlag) { while (count < size) { printf ("%2.2x ", *((unsigned char *) data + count)); if ((*((char *) data + count) >= 0x20) && (*((char *) data + count) <= 0x7E)) { ascii[count2] = *((char *) data + count); } else { ascii[count2] = 0x2E; } count++; count2++; if ((count % HEX_DUMP_BYTES_PER_LINE) == 0) { ascii[HEX_DUMP_BYTES_PER_LINE] = '\0'; printf ("*%s*\n", ascii); count2 = 0; } } ascii[count2] = '\0'; if ((count % HEX_DUMP_BYTES_PER_LINE) != 0) { while ((count % HEX_DUMP_BYTES_PER_LINE) != 0) { count++; printf (" "); } printf ("*%s", ascii); while (count2 < HEX_DUMP_BYTES_PER_LINE) { count2++; printf (" "); } printf ("*\n"); } printf ("\n"); } if (parserFlag) ParsePDU(data); } /***********************************************************************/ /* Pauses until a key is pressed. */ /***********************************************************************/ void WaitForKey (void) { printf ("Press ENTER to continue.\n"); getchar (); } /***********************************************************************/ /* Converts hex to ascii */ /***********************************************************************/ char * HexToAscii (char *srcbuffer, int size, char *dstbuffer) { unsigned char *ptr; int count; unsigned int two; ptr = (unsigned char *)srcbuffer; count = 0; while (ptr < (unsigned char *) srcbuffer + size) { two = *(unsigned char *) ptr; if (two < 0x10) { dstbuffer[count] = '0'; itoa (two, &dstbuffer[count + 1], 16); } else { itoa (two, &dstbuffer[count], 16); } ptr = ptr + 1; count = count + 2; } return dstbuffer; } /***********************************************************************/ /* 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", (int *)&buffer[0]); memset (two, 0, sizeof (two)); memcpy (two, cstr + 3, 2); sscanf (two, "%x", (int *)&buffer[1]); memset (two, 0, sizeof (two)); memcpy (two, cstr + 6, 2); sscanf (two, "%x", (int *)&buffer[2]); memset (two, 0, sizeof (two)); memcpy (two, cstr + 9, 2); sscanf (two, "%x", (int *)&buffer[3]); memset (two, 0, sizeof (two)); memcpy (two, cstr + 12, 2); sscanf (two, "%x", (int *)&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; char *result; memset (buffer, 0, sizeof (buffer)); memset (buffer2, 0, sizeof (buffer2)); memset (cmdLine, 0, c_size); printf ("%s [%s] >", prompt, cDefault != NULL ? HexToAscii (cDefault, 8, buffer2) : "(none)"); result = fgets (buffer, sizeof(buffer), stdin); sptr = strtok(buffer, TOKENS); ptr = sptr; count = 0; if (ptr) { while (*ptr) { memset (two, 0, sizeof (two)); memcpy (two, ptr, 2); sscanf (two, "%x", (int *)&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; char *result; memset (cmdLine, 0, c_size); printf ("%s [%s] >", prompt, cDefault != NULL ? cDefault : "(none)"); result = 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; char *result; memset (cmdLine, 0, c_size); printf ("%s [%s] >", prompt, dvalue == TRUE ? "*y/n" : "*n/y"); result = 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); } /*********************************************************************/ /* 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); } isns-2.1-01/isnsclient/src/parse.c0000644000175000017500000007041710665035160016011 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #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) { uint32_t x1,x2,x3,x4,*xp; xp = (uint32_t *)ipaddrhex; x1 = ntohl(*xp++); x2 = ntohl(*xp++); x3 = ntohl(*xp++); x4 = ntohl(*xp); if (x1==0 && x2==0 && x3==0) { unsigned char *cp = (unsigned char *)xp; x1 = *cp++; x2 = *cp++; x3 = *cp++; x4 = *cp; } sprintf(ipaddrstr,"%d.%d.%d.%d",x1,x2,x3,x4); } char * FuncIDText (uint16_t funcid) { switch (funcid) { case ISNS_REG_DEV_ATTR_REQ : return("Register Device Attribute Request"); case ISNS_DEV_ATTR_QRY_REQ : return("Device Attribute Query Request"); case ISNS_DEV_GET_NXT_REQ : return("Device Get Next Request"); case ISNS_DEREG_DEV_REQ : return("Deregister Device Request"); case ISNS_SCN_REG_REQ : return("SCN Register Request"); case ISNS_SCN_DEREG_REQ : return("SCN Deregister Request"); case ISNS_SCN_EVENT : return("SCN Event"); case ISNS_SCN : return("State Change Notification"); case ISNS_REG_DD_REQ : return("Discovery Domain Register"); case ISNS_DEREG_DD_REQ : return("Discovery Domain Deregister"); case ISNS_REG_DDS_REQ : return("Discovery Domain Set Register"); case ISNS_DEREG_DDS_REQ : return("Discovery Domain Set Deregister"); case ISNS_ESI : return("Entity Status Inquiry"); case ISNS_HEART_BEAT : return("Name Service Heartbeat"); case ISNS_REQ_SW_ID_REQ : return("Request Switch ID Request"); case ISNS_REL_SW_ID_REQ : return("Release Switch ID Request"); case ISNS_GET_SW_ID_REQ : return("Get Switch ID Request"); case ISNS_REG_DEV_ATTR_RES : return("Register Device Attribute Response"); case ISNS_DEV_ATTR_QRY_RES : return("Device Attribute Query Response"); case ISNS_DEV_GET_NXT_RES : return("Device Get Next Response"); case ISNS_DEREG_DEV_RES : return("Deregister Device Response"); case ISNS_SCN_REG_RES : return("SCN Register Response"); case ISNS_SCN_DEREG_RES : return("SCN Degregister Response"); case ISNS_SCN_EVENT_RES : return("SCN Event Response"); case ISNS_SCN_RES : return("SCN Response"); case ISNS_REG_DD_RES : return("Discovery Domain Register Response"); case ISNS_DEREG_DD_RES : return("Discovery Domain Deregister Response"); case ISNS_REG_DDS_RES : return("Discovery Domain Set Register Response"); case ISNS_DEREG_DDS_RES : return("Discovery Domain Set Deregister Response"); case ISNS_ESI_RSP : return("Entity Status Inquiry Response"); case ISNS_REQ_SW_ID_RES : return("Request Switch ID Response"); case ISNS_REL_SW_ID_RES : return("Release Switch ID Response"); case ISNS_GET_SW_ID_RES : return("Get Switch ID Response"); default : return(""); } } char * isnsTagText (uint32_t tagid) { switch (tagid) { case ISNS_DELIMITER : return("Delimiter"); case ISNS_ENTITY_ID : return("Entity Identifier"); case ISNS_ENTITY_TYPE : return("Entity Protocol"); case ISNS_MGMT_IP : return("Mgmt IP Address"); case ISNS_TIMESTAMP : return("Timestamp"); case ISNS_PROT_VER : return("Protocol Version Range"); case ISNS_ENTITY_PERIOD : return("Entity Period"); case ISNS_ENTITY_CERT : return("Entity Certificate"); case ISNS_PORTAL_IP : return("Portal IP-Address"); case ISNS_PORTAL_PORT : return("Portal TCP/UDP Port"); case ISNS_PORTAL_SYM_NAME : return("Portal Symbolic Name"); case ISNS_ESI_INTERVAL : return("ESI Interval"); case ISNS_ESI_PORT : return("ESI/SCN UDP Port"); case ISNS_PORTAL_CERT : return("Portal Certificate"); case ISNS_ISCSI_NODE_ID : return("iSCSI Name"); case ISNS_ISCSI_TYPE : return("iSCSI Node Type"); case ISNS_ISCSI_ALIAS : return("iSCSI Node Alias"); case ISNS_ISCSI_SCN_BITMAP : return("iSCSI SCN Bitmap"); case ISNS_ISCSI_CERT : return("iSCSI Node Certificate"); case ISNS_PORT_NAME : return("Port Name"); case ISNS_PORT_ID : return("Port_ID"); case ISNS_PORT_TYPE : return("Port_Type"); case ISNS_PORT_SYM_NAME : return("Port_Symbolic Name"); case ISNS_FABRIC_PORT_NAME : return("FC Fabric Port Name"); case ISNS_FC_HARD_ADDR : return("FC Hard Address"); case ISNS_FC_PORT_IP : return("FC Port IP-Address"); case ISNS_FC_COS : return("FC Class of Service"); case ISNS_FC4_TYPE : return("FC FC-4 Types"); case ISNS_FC4_DESC : return("FC FC-4 Descriptor"); case ISNS_FC4_FEATURE : return("FC FC-4 Features"); case ISNS_IFCP_SCN_BITMAP : return("iFCP Node SCN bitmap"); case ISNS_IFCP_NODE_CERT : return("iFCP Node Certificate"); case iSNS_FC4_TYPE_QUERY_KEY : return("FC-4 Type Code"); case ISNS_NODE_NAME : return("FC Device WWNN"); case ISNS_NODE_SYM_NAME : return("FC Device Sym Node Name"); case ISNS_FC_NODE_IP : return("FC Device IP-Address"); case ISNS_FC_NODE_IPA : return("FC Device IPA"); case ISNS_FC_NODE_CERT : return("FC Device Certificate"); case ISNS_DDS_ID : return("Discovery Domain Set ID"); case ISNS_DDS_SYM_NAME : return("Discovery Domain Set Symbolic Name"); case ISNS_DDS_STATUS : return("Discovery Domain Set Status"); case ISNS_DD_ID : return("Discovery Domain ID"); case ISNS_DD_FEATURE_BITMAP : return("Discovery Domain Feature Bitmap"); case ISNS_DD_SYM_NAME : return("Discovery Domain Symbolic Name"); case ISNS_DD_ISCSI_MEMBER : return("Discovery Domain iSCSI Member"); case ISNS_DD_IFCP_MEMBER : return("Discovery Domain iFCP Member"); case ISNS_COMPANY_OUI : return("Company OUI"); case ISNS_ENTITY_IDX : return("Entity Index"); case ISNS_ISCSI_IDX : return("iSCSI Index"); case ISNS_PORTAL_IDX : return("Portal Index"); case ISNS_DD_ISCSI_MEMBER_IDX: return("Discovery Domain iSCSI Member Index"); case ISNS_PORTAL_GROUP_ISCSI_NAME : return("Portal Group ISCSI Name"); case ISNS_PORTAL_GROUP_IP : return("Portal Group IP Address"); case ISNS_PORTAL_GROUP_PORT : return("Portal Group Port"); case ISNS_PORTAL_GROUP_TAG : return("Portal Group Tag"); default : return("Unknown TAG code"); } } char * errorText(int errorCode) { switch (errorCode) { case 0: return ("No error detected"); case 1: return ("Unknown error."); case 2: return ("Message format error."); case 3: return ("Invalid registration."); case 4: return ("Requested ESI period too short."); case 5: return ("Invalid query."); case 6: return ("Authentication unknown."); case 7: return ("Authentication absent."); case 8: return ("Authentication failed."); case 9: return ("No such entry."); case 10: return ("Version not supported."); case 11: return ("Internal bus error."); case 12: return ("Busy now."); case 13: return ("Option not understood"); case 14: return ("Invalid update."); case 15: return ("Message not supported"); case 16: return ("SCN event rejected."); case 17: return ("SCN registration rejected."); case 18: return ("Attribute not implemented."); case 19: return ("SWITCH_ID not available."); case 20: return ("SWITCH_ID not allocated."); default: return ("Unknown error code."); } } /*********************************************************************/ /* Parses a PDU */ /*********************************************************************/ void ParsePDU (char *buffer) { ISNS_Attr *p_attr; ISNS_HDR *pdu; char *ptr; uint16_t pdufunc, pdulen, pduflags; uint32_t attrtag, attrlen; int i=0, *valword; pdu = (struct isns_hdr *)buffer; printf("PDU Header: Version(%d) Func(%04X=%s) Len(%d) Flags(%04X) XID(%04X) Seq(%04X)\n", ntohs(pdu->version), pdufunc = ntohs(pdu->func_id), FuncIDText(ntohs(pdu->func_id)), pdulen = ntohs(pdu->len ), pduflags = ntohs(pdu->flags ), ntohs(pdu->xid ), ntohs(pdu->seq )); ptr = buffer + sizeof (ISNS_HDR); if (pdufunc >= ISNS_START_VALID_RES_FUNC_ID) { printf ("Error Code = %08X, \"%s\"\n", ntohl (*(uint32_t *) ptr), errorText(ntohl (*(uint32_t *) ptr))); ptr += 4; } if (pdufunc == ISNS_HEART_BEAT) { SNS_Hb * hb = (SNS_Hb *)ptr; char ipaddr[45]; ipaddrchar(hb->ip_ptr,ipaddr); printf("IP address = %s\n",ipaddr); printf("UDP port = %d\n",ntohs(hb->udp_port)); printf("TCP port = %d\n",ntohs(hb->tcp_port)); printf("Interval = %d\n",ntohl(hb->interval)); printf("Counter = %d\n",ntohl(hb->counter)); } else while (ptr < buffer + sizeof (ISNS_HDR) + pdulen) { p_attr = (struct ISNS_attr *)ptr; attrtag = ntohl (p_attr->tag); attrlen = ntohl (p_attr->len); printf("%08X %08X ",attrtag,attrlen); if (attrlen==0) printf("Tag: %s (empty)\n", isnsTagText(attrtag)); else switch (attrtag) { case ISNS_ENTITY_PERIOD : case ISNS_PORTAL_PORT : case ISNS_PORTAL_GROUP_PORT : case ISNS_ESI_INTERVAL : case ISNS_ESI_PORT : case ISNS_DDS_ID : case ISNS_DD_ID : case ISNS_DD_FEATURE_BITMAP : printf ("Tag: %s = %d\n", isnsTagText(attrtag), ntohl(p_attr->val.etype)); break; case ISNS_ENTITY_ID : case ISNS_PORTAL_SYM_NAME : case ISNS_DDS_SYM_NAME : case ISNS_DD_SYM_NAME : case ISNS_ISCSI_NODE_ID : case ISNS_ISCSI_ALIAS : case ISNS_PORT_NAME : case ISNS_PORT_SYM_NAME : case ISNS_FABRIC_PORT_NAME : case ISNS_NODE_SYM_NAME : case ISNS_DD_ISCSI_MEMBER : case ISNS_DD_IFCP_MEMBER : case ISNS_PORTAL_GROUP_ISCSI_NAME : printf ("Tag: %s = \"%s\"\n", isnsTagText(attrtag),(char *)&p_attr->val); break; case ISNS_PORT_TYPE : printf ("Tag: %s = %08X (%s)\n", isnsTagText(attrtag), ntohl(p_attr->val.etype), ntohl(p_attr->val.etype)?"TCP":"UDP"); break; case ISNS_MGMT_IP : case ISNS_PORTAL_IP : case ISNS_FC_PORT_IP : case ISNS_FC_NODE_IP : case ISNS_PORTAL_GROUP_IP : { char ipaddr[45]; ipaddrchar(&p_attr->val,&ipaddr); printf ("Tag: %s = %s\n", isnsTagText(attrtag),ipaddr); } break; case ISNS_TIMESTAMP : { time_t timevalue; timevalue = ntohl(p_attr->val.timestamp.t_time); printf ("Tag: %s = %s", isnsTagText(attrtag), ctime(&timevalue)); break; } case ISNS_PROT_VER : printf ("Tag: %s = %04X-%04X\n", isnsTagText(attrtag), ntohs(p_attr->val.ver.min),ntohs(p_attr->val.ver.max)); break; case ISNS_ISCSI_TYPE : { char iscsi_type_str[256]={0}; uint32_t type = ntohl(p_attr->val.etype); if (type & ISNS_ISCSI_TYPE_TARGET) strcat(iscsi_type_str, " Target"); if (type & ISNS_ISCSI_TYPE_INITIATOR) strcat(iscsi_type_str, " Initiator"); if (type & ISNS_ISCSI_TYPE_CONTROL) strcat(iscsi_type_str, " Control"); if (type & ISNS_ISCSI_TYPE_REMOTE) strcat(iscsi_type_str, " Remote"); printf ("Tag: %s = %08lX (%s)\n", isnsTagText(attrtag), (long)type, iscsi_type_str); } break; case ISNS_ENTITY_TYPE : { char * entity_type_str; switch (ntohl(p_attr->val.etype)) { case ENTITY_TYPE_ISCSI: entity_type_str="iSCSI"; break; case ENTITY_TYPE_IFCP : entity_type_str="iFCP"; break; default: entity_type_str="unrecognized Entity type"; } printf ("Tag: %s = %08X (%s)\n", isnsTagText(attrtag), ntohl(p_attr->val.etype), entity_type_str); } break; case ISNS_DDS_STATUS: printf ("Tag: %s = %08X (%s)\n", isnsTagText(attrtag), ntohl(p_attr->val.etype), ntohl(p_attr->val.etype)?"Enabled":"Disabled"); break; case ISNS_ENTITY_CERT : case ISNS_PORTAL_CERT : case ISNS_ISCSI_SCN_BITMAP : case ISNS_ISCSI_CERT : case ISNS_PORT_ID : case ISNS_FC_HARD_ADDR : case ISNS_FC_COS : case ISNS_FC4_TYPE : case ISNS_FC4_DESC : case ISNS_FC4_FEATURE : case ISNS_IFCP_SCN_BITMAP : case ISNS_IFCP_NODE_CERT : case iSNS_FC4_TYPE_QUERY_KEY : case ISNS_NODE_NAME : case ISNS_FC_NODE_CERT : case ISNS_COMPANY_OUI : printf ("Tag: %s = ", isnsTagText(attrtag)); for (valword=(int *)&p_attr->val.etype, i = 0; ilen) { 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; } } isns-2.1-01/isnsclient/src/main_ui.c0000644000175000017500000001064110665035160016311 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifdef SNS_LINUX #include #else #include "getarg.h" #endif #include "isns.h" #include "iscsi.h" #include "portal.h" #include "entity.h" #include "ifcp.h" #include "fcnode.h" #include "util.h" #include "comm.h" #include "menu.h" /*************************************** Globals **************************************/ char p_ip[256]; extern int isns_port; extern int enableESIFlag; extern char multicast_addr[20]; /******************************** Locals ********************************/ static char query[100]=""; static char reg[100]=""; static char dereg[100]=""; static char idvalue[100]=""; static char idvaluemember[256]=""; /***************** Usage Message *****************/ char Usage[] = "\ Usage: isnsclient [options] \n\ Options:\n\ -h Listen for L2 heartbeat from an iSNS.\n\ -a ip iSNS Address.\n\ //-u TCP mode.\n\ -p port Port used for sending. Default is port 3205.\n\ -? Help.\n\ \n\ "; /***********************************************************************/ int main (int argc, char **argv) { int l3_hb_flag; int hb_flag; int c; int tcpFlag; memset (p_ip, 0, sizeof (p_ip)); printf ("IETF iSNS Open Source Client, v%s.\n", ISNS_VERSION); if (argc < 1) { fprintf (stderr, Usage); exit (0); } /* init ESI */ InitESITable (); /* Default Values */ isns_port = ISNS_SERVER_PORT; // tcpFlag = FALSE; tcpFlag = TRUE; enableESIFlag = TRUE; hb_flag = FALSE; l3_hb_flag = FALSE; /* Parse Command Line arguments */ while (optind != argc) { c = getopt (argc, argv, "htd:p:a:m:q:r:n:e:"); switch (c) { case EOF: optarg = argv[optind]; optind++; break; case 't': tcpFlag = TRUE; break; case 'p': isns_port = atoi (optarg); break; case 'a': strcpy (p_ip, optarg); break; case 'h': hb_flag=TRUE; break; case 'c': l3_hb_flag=TRUE; strcpy (multicast_addr, optarg); break; case 'q': strcpy (query, optarg); break; case 'r': strcpy (reg, optarg); break; case 'd': strcpy (dereg, optarg); break; case 'n': strcpy (idvalue, optarg); break; case 'm': strcpy (idvaluemember, optarg); break; case '?': default: fprintf (stderr, Usage); exit (0); } } if (0 == strlen (p_ip) && hb_flag==FALSE && l3_hb_flag==FALSE) { /* Error case: No IP */ fprintf (stderr, Usage); exit (0); } /* Init the Communications sockets */ if (-1==InitComm(hb_flag, l3_hb_flag, tcpFlag)) exit(-1); Interact (); return (0); } isns-2.1-01/isnsclient/src/iscsi.c0000644000175000017500000004222410665035160016004 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* This file contains sample code for iSCSI devices */ #include "isns.h" #include "iscsi.h" #include "comm.h" #include "util.h" #include "parse.h" static ISNS_CMD cmd; /* Used for msgs */ extern int replaceFlag; /********************************************************************** This will register iSCSI Nodes. **********************************************************************/ void RegisterISCSI_I (void) { char cmdLine[256]; char nodeID[256]; char eid[256]; char nodeAlias[256]; time_t t; int type; int rval; printf ("Registering ISCSI Node.\n"); ISNSCreateHdr (ISNS_REG_DEV_ATTR_REQ, &cmd, sizeof (cmd), replaceFlag?ISNS_FLAG_REPLACE_REG:0); /* Get Entity ID */ memset (eid, 0, sizeof (eid)); if (-1==GetSrc(&cmd,0)) return; if ( (rval = GetInput(cmdLine, "Entity ID", NULL, sizeof(cmdLine))) ) { strcpy (eid, cmdLine); ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4 (strlen (eid)), eid, 0); } /* delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); if (rval == 0) { /* Get Version */ { SOIP_Ver ver; memset (&ver, 0, sizeof (ver)); if (0 != GetInput (cmdLine, "Entity Period", NULL, sizeof (cmdLine))) { ISNSAppendAttr ((struct cmd *)&cmd, ISNS_ENTITY_PERIOD, 4, NULL, atoi(cmdLine)); } if (0 != GetInput (cmdLine, "Protocol Version Max", "(none)", sizeof (cmdLine))) { ver.max = atoi (cmdLine); } if (0 != GetInput (cmdLine, "Protocol Version Min", "(none)", sizeof (cmdLine))) { ver.min = atoi (cmdLine); } if (ver.max || ver.min) { ver.max = htons (ver.max); ver.min = htons (ver.min); ISNSAppendAttr ((struct cmd *)&cmd, ISNS_PROT_VER, 4, (char *)&ver, 0); } } } /* Get iSCSI Node ID */ do { memset (nodeID, 0, sizeof (nodeID)); strcpy (nodeID, "isns.iscsi.node."); time (&t); strncat (nodeID + strlen (nodeID), ctime (&t) + 11, 8); if (GetInput(cmdLine, "ID", nodeID, sizeof(cmdLine))!= 0) { memset (nodeID, 0, sizeof (nodeID)); strcpy (nodeID, cmdLine); } ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (nodeID)), nodeID, 0); /* Get Alias */ memset (nodeAlias, 0, sizeof (nodeAlias)); strcpy (nodeAlias, nodeID); if (GetInput(cmdLine, "Alias", nodeID, sizeof(cmdLine))!= 0) { memset (nodeAlias, 0, sizeof (nodeAlias)); strcpy (nodeAlias, cmdLine); } ISNSAppendAttr (&cmd, ISNS_ISCSI_ALIAS, PAD4 (strlen (nodeAlias)), nodeAlias, 0); /* Get Type */ type = 1; if (GetInput(cmdLine, "Node Type Bitmask", "*1:Target, 2:Initiator, 3:Target/Initiator", sizeof(cmdLine)) != 0) { type = atoi (cmdLine); } ISNSAppendAttr (&cmd, ISNS_ISCSI_TYPE, 4, NULL, type); } while (GetYesNo (cmdLine, "More iSCSI Node?", FALSE, sizeof (cmdLine))); ISNSSendCmd (&cmd); } /***************************************************** This will update an existing iSCSI Node. *****************************************************/ void UpdateISCSI (void) { char cmdLine[256]; int type; printf ("Updating ISCSI Node.\n"); ISNSCreateHdr (ISNS_REG_DEV_ATTR_REQ, &cmd, sizeof (cmd), 0); /* Get iSCSI Node ID */ if (0 == GetInput (cmdLine, "iSCSI Node", NULL, sizeof (cmdLine))) { printf ("***ERROR: You must enter an iSCSI Node.\n"); return; } ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (cmdLine)), cmdLine, 0); ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* Get Alias */ if (0 != GetInput (cmdLine, "iSCSI Node Alias", NULL, sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_ISCSI_ALIAS, PAD4 (strlen (cmdLine)), cmdLine, 0); } /* Get Type */ if (0 != GetInput (cmdLine, "Node Type Bitmask", "1:Target, 2:Initiator, 3:Target/Initiator", sizeof (cmdLine))) { type = atoi (cmdLine); if (type < 1 || type > 3) { printf ("***ERROR: Type is wrong."); exit (-1); } ISNSAppendAttr (&cmd, ISNS_ISCSI_TYPE, 4, NULL, type); } ISNSSendCmd (&cmd); } /******************************************** This will query for iSCSI Node(s) attributes. ********************************************/ void GetISCSI (void) { char buffer[MAX_PAYLOAD_SIZE]; char cmdLine[256]; int c_size; int key_type; int ip; int port; /* Query for all Node */ printf ("Query for ISCSI Nodes.\n"); ISNSCreateHdr (ISNS_DEV_ATTR_QRY_REQ, &cmd, sizeof (cmd), 0); /* Append Src field*/ if (-1 == GetSrc (&cmd, 0)) return; /* Keys */ key_type = 0; if (0 != GetInput (cmdLine, "Key type (1:iSCSI, 2:Entity ID 3:Portal IP/Port 4:Node Type Bitmask 5:iSCSI Idx)>", "(none)", sizeof (cmdLine))) { key_type = atoi (cmdLine); if (key_type == 1) { do { c_size = GetInput (cmdLine, "iSCSI Node ID >", "(none)", sizeof (cmdLine)); if (c_size != 0) { ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (cmdLine)), cmdLine, 0); } } while (c_size != 0); } else if (key_type == 2) { do { c_size = GetInput (cmdLine, "Entity ID >", "(none)", sizeof (cmdLine)); if (c_size != 0) { ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4 (strlen (cmdLine)), cmdLine, 0); } } while (c_size != 0); } else if (key_type == 3) { c_size = GetInput (cmdLine, "Portal IP >", "(none)", sizeof (cmdLine)); if (c_size != 0) { char b[16]; memset (b, 0, sizeof (b)); ip = inet_addr (cmdLine); memcpy ((char *) b + 12, &ip, sizeof (ip)); ISNSAppendAttr (&cmd, ISNS_PORTAL_IP, 16, b, 0); } c_size = GetInput (cmdLine, "Portal Port >", "(none)", sizeof (cmdLine)); if (c_size != 0) { port = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_PORTAL_PORT, 4, NULL, port); } } else if (key_type == 4) { uint32_t iscsi_type=0; c_size = GetInput (cmdLine, "Node Type Bitmask", "1:Target, 2:Initiator, 3:Target/Initiator", sizeof (cmdLine)); if (c_size != 0) { iscsi_type=atoi(cmdLine); ISNSAppendAttr (&cmd, ISNS_ISCSI_TYPE, 4, NULL, iscsi_type); } } else if (key_type == 5) { uint32_t iscsi_type=0; c_size = GetInput (cmdLine, "iSCSI Index", NULL, sizeof (cmdLine)); if (c_size != 0) { iscsi_type=atoi(cmdLine); ISNSAppendAttr (&cmd, ISNS_ISCSI_IDX, 4, NULL, iscsi_type); } } else { printf ("***ERROR: Invalid key_type.\n"); return; } } else ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, 0, NULL, 0); /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* These are the operational attributes */ /* These will be returned in a response */ /* Note order does not matter, but to query for an iSCSI device, put an iSCSI attribute as the the first op attr */ ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_IDX, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_TYPE, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ISCSI_ALIAS, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_DD_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_ENTITY_IDX, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PROT_VER, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PORTAL_IDX, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PORTAL_IP, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PORTAL_PORT, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PORTAL_GROUP_ISCSI_NAME, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PORTAL_GROUP_PORT, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PORTAL_GROUP_IP, 0, NULL, 0); ISNSAppendAttr (&cmd, ISNS_PORTAL_GROUP_TAG, 0, NULL, 0); if (0 == ISNSSendCmd2 (&cmd, buffer, sizeof (buffer))) { /* This will parse the query rsp msg into a human readable format. */ ParseISCSIQuery (buffer); } } /*********************************************** This will deregister an iSCSI Node. ***********************************************/ void DeRegisterISCSI (void) { char cmdLine[256]; /* Insert Header */ ISNSCreateHdr (ISNS_DEREG_DEV_REQ, &cmd, sizeof (cmd), 0); /* Insert SRC */ if (-1 == GetSrc (&cmd, 0)) return; /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* Get iSCSI Node ID */ if (0 == GetInput (cmdLine, "KEY: iSCSI Node Id", NULL, sizeof (cmdLine))) { printf ("***ERROR: required.\n"); return; } ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (cmdLine)), cmdLine, 0); ISNSSendCmd (&cmd); } /***************************************************** This will add an iSCSI node to a DD. *****************************************************/ void Add_ISCSI_to_DD (void) { char cmdLine[256]; int dd_id; int iscsi_flag; int c_size; printf ("Adding ISCSI to DD.\n"); ISNSCreateHdr (ISNS_REG_DD_REQ, &cmd, sizeof (cmd), 0); /* Insert SRC */ if (-1 == GetSrc (&cmd, 0)) return; /* Get DD ID */ if (GetInput(cmdLine, "DD ID", NULL, sizeof(cmdLine)) == 0) { printf ("***ERROR: You must enter a DD ID.\n"); return; } dd_id = atoi (cmdLine); /* Insert as a key */ ISNSAppendAttr (&cmd, ISNS_DD_ID, 4, NULL, dd_id); /* Delimiter */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* Get iSCSI Node ID */ iscsi_flag = FALSE; do { /* You can put multiple members in single msg. */ c_size = GetInput (cmdLine, "iSCSI Node ID", NULL, sizeof (cmdLine)); if (c_size != 0) { ISNSAppendAttr (&cmd, ISNS_DD_ISCSI_MEMBER, PAD4 (strlen (cmdLine)), cmdLine, 0); iscsi_flag = TRUE; } } while (c_size != 0); if (iscsi_flag) ISNSSendCmd (&cmd); else printf ("***ERROR: You must enter at least ONE iSCSI Node.\n"); } /******************************************************************* Sample Multi Attribute ISCSI registration. This sample will register one or more iSCSI Nodes along with one or more Portals. An entity may also be created during the registration process. *******************************************************************/ void MRegISCSI (void) { char cmdLine[256]; char eid[256]; char sym[256]; int port; int ip; int esi_interval; int port_type; int portal_group; int type; char b[256]={0}; printf ("Multi-attr ISCSI Node Registration.\n"); ISNSCreateHdr (ISNS_REG_DEV_ATTR_REQ, &cmd, sizeof (cmd), 0); /* Get Entity ID */ memset (eid, 0, sizeof (eid)); if (GetInput(cmdLine, "Entity ID", NULL, sizeof(cmdLine)) != 0) { strcpy (eid, cmdLine); ISNSAppendAttr (&cmd, ISNS_ENTITY_ID, PAD4 (strlen (eid)), eid, 0); } /* Delimiter */ /* This seperates the keys from the op attr */ ISNSAppendAttr (&cmd, 0, 0, NULL, 0); /* Get all iSCSI Nodes to be registered*/ do { /* Get iSCSI Node ID */ if (0 == GetInput (cmdLine, "iSCSI Node", NULL, sizeof (cmdLine))) break; ISNSAppendAttr (&cmd, ISNS_ISCSI_NODE_ID, PAD4 (strlen (cmdLine)), cmdLine, 0); /* Get Alias */ if (0 != GetInput (cmdLine, "iSCSI Alias", NULL, sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_ISCSI_ALIAS, PAD4 (strlen (cmdLine)), cmdLine, 0); } /* Get Type */ type = 1; if (0 != GetInput (cmdLine, "Node Type Bitmask", "1:Target, 2:Initiator, 3:Target/Initiator", sizeof (cmdLine))) { type = atoi (cmdLine); if (type < 1 || type > 3) { printf ("***ERROR: Type is wrong."); return; } } ISNSAppendAttr (&cmd, ISNS_ISCSI_TYPE, 4, NULL, type); } while (1); /* Get all portals to be registered */ do { if (0 == GetInput (cmdLine, "Portal IP", NULL, sizeof (cmdLine))) break; ip = inet_addr (cmdLine); { char tempb[256]; memset (tempb, 0, sizeof (tempb)); memcpy (tempb + 12, &ip, sizeof (ip)); ISNSAppendAttr (&cmd, ISNS_PORTAL_IP, 16, tempb, 0); } /* Get Port Type */ port_type = 0; if (0 != GetInput (cmdLine, "Portal Type", "*0:UDP 1:TCP", sizeof (cmdLine))) { port_type = atoi (cmdLine); if (port_type > 1) { printf ("***ERROR: Port type is wrong.\n"); return; } } /* Get Port */ port = DEFAULT_PORTAL_PORT; itoa(DEFAULT_PORTAL_PORT, b, 10); if (0 != GetInput (cmdLine, "Portal Port", b, sizeof (cmdLine))) { port = atoi (cmdLine); } ISNSAppendAttr (&cmd, ISNS_PORTAL_PORT, 4, NULL, port | (port_type == 1 ? 0 : 0x10000)); /* Get an Portal Sym Name */ memset (sym, 0, sizeof (sym)); if (0 != GetInput (cmdLine, "Portal Sym Name", NULL, sizeof (cmdLine))) { ISNSAppendAttr (&cmd, ISNS_PORTAL_SYM_NAME, PAD4 (strlen (cmdLine)), cmdLine, 0); strcpy (cmdLine, sym); } /* Get Portal Group */ if (0 != GetInput (cmdLine, "Portal Group Tag", NULL, sizeof (cmdLine))) { portal_group = atoi (cmdLine); if (portal_group > 255 || portal_group == 0) { printf ("***ERROR: Invalid portal group tag.\n"); return; } memset (cmdLine, 0, sizeof (cmdLine)); ISNSAppendAttr (&cmd, ISNS_PORTAL_GROUP_TAG, 4, NULL, portal_group); } /* Get Interval */ esi_interval = 0; if (0 != GetInput (cmdLine, "ESI Interval", "(0)", sizeof (cmdLine))) { esi_interval = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_ESI_INTERVAL, 4, NULL, esi_interval); /* Get ESI Port */ port = 0; if (0 != GetInput (cmdLine, "ESI/SCN UDP Port", NULL, sizeof (cmdLine))) { port = atoi (cmdLine); ISNSAppendAttr (&cmd, ISNS_ESI_PORT, 4, NULL, port); } if (port && esi_interval) { #ifndef SNS_LINUX DWORD junk; #endif LISTENER_CB_P p_cb; HANDLE hdle; #ifdef SNS_LINUX hdle = (void *)malloc (sizeof (pthread_t)); #endif p_cb = (void *)malloc (sizeof (LISTENER_CB)); memset (p_cb, 0, sizeof (LISTENER_CB)); strcpy (p_cb->eid, eid); p_cb->port = port; p_cb->ip = ip; #ifdef SNS_LINUX if (pthread_create (hdle, NULL, (void*) (ESIListener), p_cb) != 0) printf ("Could not create ESI Listener thread\n"); else #else hdle = CreateThread ((LPSECURITY_ATTRIBUTES)0, 0, (LPTHREAD_START_ROUTINE)ESIListener, p_cb, 0, &junk); #endif AddESIPortal (sym, port, hdle); } } } while (1); ISNSSendCmd (&cmd); } isns-2.1-01/isnsclient/Makefile0000644000175000017500000000575210665035160015404 0ustar zobelzobel# # The contents of this file are subject to the Nishan Systems, Inc. Public # License Version 1.0 (the "License"); you may not use this file except in # compliance with the License included with the distribution. You may # obtain a copy of the License at www.NishanSystems.com. # # Software distributed under the License is distributed on an "AS IS" # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See # the License for the specific language governing rights and limitations # under the License. # # The Original Software is Release 1.0 of the iSNS Example Client and # Server. Portions created by Nishan Systems are Copyright 2001 Nishan # Systems, Inc. All Rights Reserved. # # This Original Software is subject to a standard specification issued # by the IETF. The Specification is titled iSNS Internet Storage Name # Service. # # The Initial Contributor of the Original Software is Nishan Systems, Inc. # Revision Contributor(s) are listed below: # # Submitted Revision Contributor Name and Date # # SHELL = /bin/sh CC = gcc -g SRCDIR = ./src/ INCDIR = ./include/ INCDIR += -I../isnsserver/include/ INCDIR += -I/usr/include/ OBJECTS = getarg.o OBJECTS += comm.o OBJECTS += entity.o OBJECTS += iscsi.o OBJECTS += parse.o OBJECTS += isns.o OBJECTS += payloads.o OBJECTS += ifcp.o OBJECTS += fcnode.o OBJECTS += custom.o OBJECTS += portal.o OBJECTS += util.o OBJECTS += menu.o PROG1 = main.o PROG2 = main_ui.o WARNFLAGS = -Wall OPTFLAGS ?= -g -O2 CFLAGS += $(OPTFLAGS) $(WARNFLAGS) CFLAGS += -DSNS_LINUX CFLAGS += -DSNS_DEBUG LIBS = -lpthread DESTDIR ?= INSTALL = install sbindir = $(exec_prefix)/sbin PROGRAMS = isnsc isnsadm all : $(PROGRAMS) isnsc: $(PROG2) $(OBJECTS) $(CC) $^ -o $@ $(LIBS) isnsadm: $(PROG1) $(OBJECTS) $(CC) $^ -o $@ $(LIBS) getarg.o : $(SRCDIR)getarg.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ main.o : $(SRCDIR)main.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ main_ui.o : $(SRCDIR)main_ui.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ comm.o : $(SRCDIR)comm.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ menu.o : $(SRCDIR)menu.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ entity.o : $(SRCDIR)entity.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ parse.o : $(SRCDIR)parse.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ util.o : $(SRCDIR)util.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ isns.o : $(SRCDIR)isns.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ payloads.o : $(SRCDIR)payloads.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ ifcp.o : $(SRCDIR)ifcp.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ fcnode.o : $(SRCDIR)fcnode.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ custom.o : $(SRCDIR)custom.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ portal.o : $(SRCDIR)portal.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ iscsi.o : $(SRCDIR)iscsi.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ clean : rm $(PROG1) $(PROG2) $(OBJECTS) isnsc isnsadm install: install_programs install_programs: $(PROGRAMS) $(INSTALL) -d $(DESTDIR)$(sbindir) $(INSTALL) -m 755 $^ $(DESTDIR)$(sbindir) isns-2.1-01/isnsclient/LICENSE.TXT0000644000175000017500000000275110665035160015423 0ustar zobelzobelCopyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. isns-2.1-01/isnsclient/README.txt0000644000175000017500000001304710665035160015436 0ustar zobelzobelREADME.TXT ______________________ iSNS Release Version 2.0 ______________________ Introduction 1) Please read and accept the "LICENSE.TXT" before use 2) The client and server application can be built with For Linux: make SLSE 10 was used during test 3) Pre-built executable for both client and server are provided for 32-bit 3a) The server executable is isnsd 3b) The client executable is isnsc 4) The tested OS platforms are: SLES 10 32 and 64 bit ______________________ To Build The C source code can be built using Linux. The option for building the code is to use the Linux makefile, make make install ______________________ To Provide Feedback Please provide feedback to the development mail list for the isns server ______________________ To Uninstall 1) Delete the top-level directory that the iSNS code was installed in. _____________________ Server Options If the server executable is run without command line options, or the "-?" option is on the command line, the following supported options are listed: iSNSserver>isnss Usage: isnsd [options] NOTES: IP-Addresses must be in IP dotted notation. Options: [-a addr] IP-Address for SNSP traffic. [-b addr] Broadcast Address for SNSP traffic. [-p port] primary port for SNSP traffic. [-d] Full debug options on. [-f] Foreground and not as a daemon. [-?] Help. _____________________ Client Options If the client executable is run without command line options, or the "-?" option is on the command line, the following supported options are listed: iSNSclient>isnsc IETF iSNS Client, v1.1. Usage: isnsc [options] Options: [-h] Listen for L2 heartbeat from an iSNS. [-a ip] iSNS Address. [-t] TCP mode. [-p port] Port used for sending. Default is port 3205. [-?] Help. For the client to connect with the iSNS server, one of two options needs to be used, "-h" or "-a". The "-h" option allows for discovery using L2 broadcast heartbeats from the server. The "-a" option allows for static configuration of the iSNS server IP-Address. _____________________ About Discovery Domains and Discovery Domain Sets A Discovery Domain Set (DDS) is a collection of Discovery Domains. A DDS can be either Enabled or Disabled. A Discovery Domain (DD) is a collection of storage devices in the storage area network which will be allowed to query for information about each other. These queries will only be successful if the DD is a member of an Enabled DDS. A device does not necessarily know which DD it is a member of. Also, a device may belong to more than one DD. A DD can be a member of more then one DDS. The SOURCE field of every iSNS query and registration message identifies the storage device that sent the request. The iSNS Server uses this field to scope the operation to the set of DDs that the origin iSNS client is a member of. If the SOURCE field contains NULL, the iSNS message is assumed to have originated from an administrative iSNS client, so the message SHALL BE scoped to the entire contents of the iSNS, regardless of the configuration of Discovery Domains. If, after registering storage nodes, queries are done with the source of the message specified, then at least one DD should have been created and placed into an enabled DDS for the query to return results. Each device that is to be visible to each other needs to be placed into the same DD, and the DD needs to be placed in an enabled DDS. For more discussion on Discovery Domains please refer to the iSNS Specification. _____________________ About Registering Access Control Lists (ACLs) For an iSCSI Target ACLs map directly to an iSNS DD. If a target has a set of iSCSI Nodes that have access rights to it, then it can register a DD containing the iSCSI Node ID of the target and the set of iSCSI Node IDs of the initiators that have access to it. Additionally, the DD must be in an enabled DDS for it to be enforced by the iSNS. An example showing a simple ACL registration is shown below. _____________________ Getting Started The best way to start is to run the server and client in separate console windows on a Linux, NT or Windows 2000 based workstation. Then practice registering and querying several nodes without creating any Discovery Domains or Discovery Domain Sets. NOTE: it is important to leave the source field of any registration or query messages as NULL if no Discovery Domains and Discovery Domains Sets are created. Otherwise the queries will return with an error stating no matching nodes found. After doing registrations without DD/DDS's, create discovery domains and place nodes in the DD's to see how ACL's can registered and modified in the iSNS. _____________________ Example Test The interactive client generates iSNS registration and query messages that are sent to the server. The server responds with the appropriate messages to satisfy the registration and query messages. The PDU stream is printed to the console to facilitate testing and integration of the iSNS with storage products. The PDU's are documented in the iSNS Specification. The current version as of this specification is included in the iSNSserver directory of this release. 1) Open two console windows, possibly on separate workstations 2) Assuming a server with an interface having IP-Address 192.100.100.116 Broadcast Address 192.100.100.255 3) Launch the server >isnsd -f 4) Launch the client and use TCP for communication >isnsc -a 192.100.100.116 -t Or, to demonstrate the autodetection of the server in a layer 2 network, enter >isnsc -h -t isns-2.1-01/isnsclient/include/0000755000175000017500000000000010665035244015361 5ustar zobelzobelisns-2.1-01/isnsclient/include/portal.h0000644000175000017500000000351410665035160017033 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef __PORTAL_H #define __PORTAL_H void DeRegisterPortal(void); void GetPortals(void); void RegPortalI(void); void UpdatePortal(void); #endif isns-2.1-01/isnsclient/include/custom.h0000644000175000017500000000345710665035160017052 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef __CUSTOM_H #define __CUSTOM_H void RegCustom1 (void); void RegCustom2 (void); void RegCustom3 (void); #endif isns-2.1-01/isnsclient/include/comm.h0000644000175000017500000000440510665035160016465 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef __COMM_H #define __COMM_H int AddMsg(void *p_msg, int size); int InitComm(int hb_flag, int l3_hd_flag, int t_flag); int HeartBeatListener(void); int L3_HeartBeatListener(void); #ifdef SNS_LINUX int #else DWORD WINAPI #endif ESIListener(DWORD lparam); void SendESIRsp(void); #ifdef SNS_LINUX int #else DWORD WINAPI #endif TCPReceiveMain(DWORD lparam); int TCPGetMsg(void *buffer, int b_size); int ISNSSendCmd(ISNS_CMD *cmd); int SendPDU(ISNS_CMD *cmd, int len); int ISNSSendCmd2(ISNS_CMD *cmd, char *rcvBuffer, int rcvSize); int ISNSJustSendCmd (ISNS_CMD * cmd); #endif isns-2.1-01/isnsclient/include/getarg.h0000644000175000017500000000351010665035160016777 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef __GETARG_H #define __GETARG_H extern char * optarg; extern int optind; int getopt ( int argc, char **argv, char *optstring); #endif isns-2.1-01/isnsclient/include/ifcp.h0000644000175000017500000000362610665035160016457 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef __IFCP_H #define __IFCP_H void ParseIFCPQuery(char *buffer); void MRegIFCP(void); void RegIFCP(void); void UpdateIFCP(void); void GetIFCP(void); void Add_IFCP_to_DD(void); void DeRegisterPort (void); #endif isns-2.1-01/isnsclient/include/fcnode.h0000644000175000017500000000364310665035160016773 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef __FCNODE_H #define __FCNODE_H void DeRegisterNode(void); void RegisterNode(void); void GetAllNodes(void); void ParseFCNodeQuery(char *buffer); void RegFCNode (void); void GetFCNode (void); void UpdateFCNode(void); #endif isns-2.1-01/isnsclient/include/isns.h0000644000175000017500000001320610665035160016505 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef _isns_h #define _isns_h #ifdef SNS_LINUX #include #include #include #include #include #include #include #include #include #include #define WINAPI #define HANDLE pthread_t* #define LPVOID void* typedef unsigned int DWORD; #define FALSE 0 #define TRUE 1 #define SOCKET int #define itoa(a,b,c) (((c)==10)?sprintf(b,"%d",a):sprintf(b,"%x",a)) #else // #include #include #include #include #include #define uint16_t unsigned short #define uint32_t unsigned long #endif #include #include #include "iSNSdefs.h" #ifndef MIN #define MIN(a,b) ((a) <= (b) ? (a) : (b)) #endif #ifndef MAX #define MAX(a,b) ((a) >= (b) ? (a) : (b)) #endif #ifndef PAD4 #define PAD4(a) ((a%4)?(4-a%4)+a:(a+4)) #endif #define DEFAULT_PORTAL_PORT (8000) #define DEFAULT_IP_ADDR "127.0.0.1" #define MAX_PAYLOAD_SIZE (8*1024) #define MAX_VALUE_LENGTH (8) #define ISNS_TAG_LEN (4) #define ISNS_LEN_LEN (4) #define ISNS_INDEX_SIZE (4) #define NISHAN_OUI (0x010F) typedef struct sns_hb_payload { char ip_ptr[16]; uint16_t udp_port; uint16_t tcp_port; uint32_t interval; /* heartbeat interval */ uint32_t counter; /* incremental hb counter */ } SNS_Hb; typedef struct isns_hdr { uint16_t version; uint16_t func_id; uint16_t len; uint16_t flags; uint16_t xid; uint16_t seq; } ISNS_HDR, *ISNS_HDR_P; typedef struct _soip_time { uint32_t t_pad; uint32_t t_time; } SOIP_Time; typedef struct _soip_ver { uint16_t max; uint16_t min; } SOIP_Ver; typedef struct _soip_grp { char pad[3]; char val; } SOIP_GRP; typedef struct ISNS_attr { uint32_t tag; uint32_t len; union { char c; uint32_t etype; uint32_t integer; SOIP_Time timestamp; SOIP_Ver ver; SOIP_GRP p_grp; } val; } ISNS_Attr; typedef struct isns_tlv { uint32_t attrib_id; uint32_t attrib_len; char attrib_val[MAX_VALUE_LENGTH]; } ISNS_TLV, *ISNS_TLV_P; typedef struct cmd { ISNS_HDR hdr; char buffer[MAX_PAYLOAD_SIZE]; } ISNS_CMD; typedef struct sns_esi_rsp_payload { char entity_id[256]; char portal_ip[16]; int portal_port; } SNS_ESI_RSP_PAYLOAD; typedef struct sns_esi_payload { char entity_id[256]; char portal_ip[16]; int portal_port; } SNS_ESI_PAYLOAD; typedef struct _listener_cb { int port; int ip; char eid[256]; } LISTENER_CB, *LISTENER_CB_P; typedef struct _msg_cb { int size; void *p_msg; } MSG_CB; #define MSG_Q_SIZE (100) #ifdef SNS_LINUX int #else DWORD WINAPI #endif ESIListener(DWORD lparam); #ifndef BUFFER_SIZE #define BUFFER_SIZE (16*1024*10) #endif #define PAYLOAD_OFFSET (8) #define CLIENT_CFG_FILE "client.cfg\0" #define SERVER_CFG_FILE "server.cfg\0" #define TOKENS "\n\r" #define MAX_SEND (1024*1024) #define ISNS_SERVER_PORT (3205) #define ISNS_HEARTBEAT_PORT (3206) /* This should be a string */ #define ISNS_VERSION "1.2.0" #define CONTROL_NODE "iqn.control.node" /* This should be an integer, and is the protocol version */ #define ISNSP_VERSION 1 void ISNSInsertQryHdr(ISNS_FUNC_ID func_id, ISNS_CMD *cmd); void GetDDS(void); void GetDD(void); void RegDDS(void); void UpdateDDS(void); void DeRegDDS(void); void Remove_DD_from_DDS(void); void RegDD(void); void UpdateDD(void); void DeRegDD(void); void Remove_Member_from_DD(void); void Add_DD_to_DDS(void); void DisableESI(void); void EnableESI(void); void Send_SCN_Event(void); int Send_ESI_Response(ISNS_CMD *p_cmd, int size); void Process_SCN(ISNS_CMD *p_msg, int size); int RegSCN(void); void DeRegSCN(void); void InitESITable(void); void AddESIPortal(char *p_name, int port, HANDLE hdle); void KillESIThreads(void); void GetNext(void); void SaveDb(void); #endif isns-2.1-01/isnsclient/include/menu.h0000644000175000017500000000355210665035160016500 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef __MENU_H #define __MENU_H typedef struct _menu_item { char *name; int id; void (*func) (); } MENU_ITEM; void DisplayMenu (void); void Interact (void); #endif isns-2.1-01/isnsclient/include/entity.h0000644000175000017500000000354710665035160017054 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef __ENTITY_H #define __ENTITY_H void DeRegisterEntity(void); void GetEntities(void); int RegEntityI(void); int UpdateEntity(void); void Add_FCIP_to_DD(void); #endif isns-2.1-01/isnsclient/include/util.h0000644000175000017500000000423010665035160016503 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef __UTIL_H #define __UTIL_H void DumpHex (void *data, int size); void WaitForKey(void); char * HexToAscii(char *srcbuffer, int size, char *dstbuffer); void GetHexTime(char *buffer); int GetHexInput(char *cmdLine, char *prompt, char *cDefault, int c_size); int GetInput(char *cmdLine, char *prompt, char *cDefault, int c_size); int GetYesNo(char *cmdLine, char *prompt, int dvalue, int c_size); int GetCommand(void); int GetSrc(ISNS_CMD *p_cmd, int flags); #endif isns-2.1-01/isnsclient/include/parse.h0000644000175000017500000000443010665035160016642 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef __PARSE_H #define __PARSE_H void ISNSCreateHdr(ISNS_FUNC_ID func_id, ISNS_CMD *cmd, int b_size, int flags); void ISNSAppendAttr(ISNS_CMD *cmd, ISNS_TAG tag, int len, char *ptr, int val); void ipaddrchar(void * ipaddrhex, void * ipaddrstr); char * FuncIDText (uint16_t funcid); char * isnsTagText (uint32_t tagid); char * errorText(int errorCode); void ParsePDU (char *buffer); void ParseEntityQuery (char *buffer); void ParseISCSIQuery (char *buffer); void ParsePortalQuery (char *buffer); void ParseESI (char *buffer); void ParseDDQuery (char *buffer); void ParseDDSQuery (char *buffer); #endif isns-2.1-01/isnsclient/include/iscsi.h0000644000175000017500000000363510665035160016650 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef __ISCSI_H #define __ISCSI_H void RegisterISCSI_I(void); void UpdateISCSI(void); void MRegISCSI(void); void MDeRegisterISCSI(void); void DeRegisterISCSI(void); void GetISCSI(void); void Add_ISCSI_to_DD(void); #endif isns-2.1-01/isnsclient/ReleaseNotes.txt0000644000175000017500000000460610665035160017073 0ustar zobelzobelRelease 2.0.3 02/07/2007 ------------------------- created isnsadm - command line utility Release 2.0 01/04/2007 ------------------------- Updated to work with 2.0 release of the isns server Release 1.2.1 4/2/2002 ------------------------- Update to public release BUG FIX: corrected reported issues Release 1.2.0 10/3/2001 ------------------------- Update to public release FEATURE: this version supports both Linux v7.1/v6.2 and Windows NT4.0/2000 FEATURE: added entity, node and portal indexes to allow use with SNMP CHANGE: added replace bit functionality BUG FIX: corrected many issues in DD/DDS/Node and SCN processing Release 1.1.5 8/22/2001 ------------------------- Update to public release CHANGE: Modified Open Source License Release 1.1.4 8/6/2001 ------------------------- Update to public release CHANGE: Modified DD/DDS description in the README documentation of the release. (client) BUG FIX: Portal ports of type UDP were not registered correctly. (server) BUG FIX: Portals from different entities were not correctly returned in a query. Release 1.1.3 6/22/2001 ------------------------- Update to public release CHANGE: Added more text to the README documentation of the release. FEATURE: Added control type node support to the server. Release 1.1.2 6/19/2001 ------------------------- Update to public release (server) CHANGE : Added msg type "SAVE_DB_REQ" to enum to test out save/load feature. FEATURE: iSNS now will save and load DD/DDS information on startup use the [-l] option. BUG FIX: SCN was not sent out for all DDS updates. BUG FIX: Many other small SCN problems. (client) FEATURE: Added Save DD/DDS option to the menu. BUG FIX: Removed some unnecessary enum. Release 1.1.1 6/6/2001 ------------------------- Update to public release (server) FEATURE: Entity ID and iSCSI ID can be the same name. BUG FIX: Entity timestamp wasn't being updated during some updates. BUG FIX: DD/DDS ID of 0 is being rejected. BUG FIX: iSCSI Node Query with iSCSI Node key has been fixed. BUG FIX: Removed "-c" from server help. BUG FIX: Queries with certain src returned wrong nodes. (client) CHANGE : replaced all occurrances of "iSCSI Type" with "Node Type Bitmask." CHANGE : removed option to have source of type Entity ID CHANGE : Clarified the wording for iSCSI Node queries FEATURE: Added PORTAL/ENTITY attr to iSCSI queries. Release 1.1.0 5/29/2001 ------------------------- Public Distribution Release isns-2.1-01/isnsserver/0000755000175000017500000000000010712373162013763 5ustar zobelzobelisns-2.1-01/isnsserver/etc/0000755000175000017500000000000010665402432014536 5ustar zobelzobelisns-2.1-01/isnsserver/etc/initd.suse0000644000175000017500000000231110665402432016543 0ustar zobelzobel#!/bin/bash # # /etc/init.d/isns # ### BEGIN INIT INFO # Provides: isns # Required-Start: $network # Should-Start: # Required-Stop: # Should-Stop: # Default-Start: 3 5 # Default-Stop: # Short-Description: Starts and stops the isns server # ### END INIT INFO PID_FILE=/var/run/isns.pid CONFIG_FILE=/etc/isns/isns.conf DAEMON=/usr/sbin/isnsd ARGS="" #ARGS="-c $CONFIG_FILE -p $PID_FILE" # Source LSB init functions . /etc/rc.status # Reset status of this service rc_reset case "$1" in start) if checkproc $DAEMON ; then RETVAL=0 else echo -n "Starting iSNS Internet Storage Naming Service: " startproc $DAEMON $ARGS RETVAL=$? rc_status -v fi ;; stop) echo -n "Stopping iSNS Internet Storage Naming Service: " if checkproc $DAEMON ; then killproc -KILL $DAEMON rc_status -v else rc_failed 1 rc_status -v fi ;; status) echo -n "Checking for iSNS Internet Storage Naming Service: " if checkproc $DAEMON ; then rc_status -v else rc_failed 3 rc_status -v fi ;; restart) $0 stop sleep 1 $0 start ;; *) echo "Usage: $0 {start|stop|status|restart}" exit 1 ;; esac rc_exit isns-2.1-01/isnsserver/src/0000755000175000017500000000000010665040361014551 5ustar zobelzobelisns-2.1-01/isnsserver/src/iSNSLinux.c0000644000175000017500000002437110665040341016556 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include #include #include #include #include #include "iSNSLinux.h" #include "iSNS.h" #include "iSNScomm.h" #include "iSNSdb.h" #include "iSNSmsg.h" #include "iSNSqueue.h" #include "iSNSfsm.h" #include "iSNScomm.h" #include "iSNSbuffer.h" #include "iSNSipc.h" #include "iSNSdebug.h" #ifndef SNS_LINUX #define SNS_LINUX #endif extern int sns_ready; extern int sns_local_priority; extern int sns_local_version; extern int sns_heartbeat_interval; extern int sns_esi_interval; extern int sns_request_timeout; extern int sns_comm_main_port_set; /* Linux */ extern pthread_cond_t esi_cond; extern pthread_cond_t fsm_cond; extern pthread_cond_t resync_cond; extern pthread_mutex_t sns_request_timer; extern pthread_cond_t request_cond; extern pthread_mutex_t sns_resync_timer; extern pthread_mutex_t sns_fsm_timer; extern pthread_mutex_t sns_esi_timer; /* log */ int daemon_state = TRUE; /* debug */ extern int sns_bcast_debug; extern int sns_cb_debug; extern int sns_fsm_debug; extern int sns_hb_debug; extern int isns_main_debug; extern int sns_recv_debug; extern int sns_rsync_debug; extern int sns_scn_debug; extern int sns_comm_debug; extern int isns_db_debug; extern int isns_list_debug; extern int isns_parse_debug; extern int sns_tcp_debug; extern int isns_query_debug; extern int isns_reg_debug; extern int isns_dereg_debug; extern int isns_esi_debug; int pauseFlag = FALSE; int snsServiceFlag = FALSE; extern void SNSReqTimeoutHdlr(void); HANDLE init_ipc_rcv (void); void DebugOn (char *); void taskDelay (int time) { sleep (time); } int sysClkRateGet (void) { return (1); } void taskDelete (pthread_t task) { if (task == 0) return; if ((void *)task != NULL) { pthread_cancel (task); } } void taskSuspend (void) { return; } int taskIdSelf (void) { return (0); } /* Linux */ int LinuxTaskSpawn (char *taskName, void *funcPtr) { int result; pthread_t athread; result = (pthread_create (&athread, NULL, (void*) funcPtr, NULL)); if (result != 0) perror ("taskSpawn"); return (result); } char Usage[] = "\ Usage: isnss [options] -i IP -b BROADCAST IP\n\ NOTES: IP-Addresses must be in IP dotted notation.\n\ Options:\n\ [-a addr] IP-Address for SNSP traffic.\n\ [-b addr] Broadcast Address for SNSP traffic.\n\ [-p port] primary port for SNSP traffic.\n\ [-d switch] debug options: parse,db,list,reg,fsm,esi,scn,all \n\ [-f] Foreground - no daemon.\n\ [-?] Help.\n"; int main (int argc, char **argv) { int rc; pid_t pid; int c; char sfilename[256] = { 0 }; ISNS_Entity role = ISNS_SECONDARY_SERVER; /* Don't forget to init the rest */ while (optind != argc) { c = getopt (argc, argv, "fa:b:p:c:d:"); switch (c) { case EOF: optarg = argv[optind]; optind++; break; case 'a': strcpy (snsp_ip, optarg); break; case 'b': strcpy (snsp_bip, optarg); break; case 'c': strcpy (sfilename, optarg); break; case 'p': sns_comm_main_port_set = atoi (optarg); break; case 'd': DebugOn(optarg); break; case 'f': daemon_state = FALSE; break; case '?': default: fprintf(stderr,Usage); exit (0); } } rc = mkdir("/var/isns",0777); rc = chdir("/var/isns"); if (daemon_state == TRUE) { pid = fork(); if (pid < 0) { __LOG_ERROR("starting daemon failed\n"); exit(1); } else if (pid) { exit(0); } else { int fd_pid; char buf[64]; char *pid_file = "/var/run/isnss.pid"; int rc; fd_pid = open(pid_file, O_WRONLY | O_CREAT, 0644); if (lockf(fd_pid, F_TLOCK, 0) < 0) { __LOG_ERROR("unable to lock pid file already is use\n"); __LOG_INFO("isnss daemon not started\n"); exit (1); } rc = ftruncate(fd_pid, 0); sprintf(buf,"%d\n",getpid()); rc = write(fd_pid, buf, strlen(buf)); __LOG_INFO ("isns daemon started as pid:%i",getpid()); setsid(); } } SNSMain (role); /* Never should hit this. */ exit (-1); } /********************************************************* SNSReqTimeoutThread *********************************************************/ int SNSReqTimeoutThread () { struct timeval now; struct timespec timeout; int rc; __DEBUG ( isns_main_debug & 16,"SNSReqTimeoutHdlr Started."); while (1) { pthread_mutex_lock(&sns_request_timer); gettimeofday(&now, NULL); timeout.tv_sec = now.tv_sec + sns_request_timeout; timeout.tv_nsec = now.tv_usec * 1000; rc = pthread_cond_timedwait (&request_cond,&sns_request_timer,&timeout); if (rc != ETIMEDOUT) perror ("Error in Timeout Request in SNSReqTimeoutThread"); pthread_mutex_unlock(&sns_request_timer); SNSReqTimeoutHdlr (); if (pauseFlag) return (0); } return (0); } /*********************************************************** SSNSFSMTimeoutThread ***********************************************************/ /* Linux */ int SNSFSMTimeoutThread () { struct timeval now; struct timespec timeout; int rc; __DEBUG (isns_main_debug & 1666666,"SNSFSMTimeoutHdlr thread started."); while (1) { pthread_mutex_lock(&sns_fsm_timer); gettimeofday(&now, NULL); timeout.tv_sec = now.tv_sec + sns_heartbeat_interval; timeout.tv_nsec = now.tv_usec * 1000; rc = pthread_cond_timedwait(&fsm_cond, &sns_fsm_timer, &timeout); if (rc != ETIMEDOUT) perror ("Error in Timeout Request in SNSFSMTimeoutThread"); SNSFSMTimeoutHdlr (); pthread_mutex_unlock(&sns_fsm_timer); if (pauseFlag) return (0); } return (0); } /********************************************************* SNSESITimeoutThread *********************************************************/ /* Linux */ int SNSESITimeoutThread () { struct timeval now; struct timespec timeout; int rc; __DEBUG (isns_main_debug & 16,"SNSESITimeoutHdlr thread started."); while (1) { pthread_mutex_lock(&sns_esi_timer); gettimeofday(&now, NULL); timeout.tv_sec = now.tv_sec + sns_esi_interval; timeout.tv_nsec = now.tv_usec * 1000; rc = pthread_cond_timedwait(&esi_cond, &sns_esi_timer, &timeout); if (rc != ETIMEDOUT) perror ("Error in Timeout Request in SNSESITimeoutThread"); SNSESITimeoutHdlr (); pthread_mutex_unlock(&sns_esi_timer); if (pauseFlag) return (0); } return (0); } /*********************************************************** SNSResyncTimeoutThread ***********************************************************/ int SNSResyncTimeoutThread () { struct timeval now; struct timespec timeout; int rc; while (1) { pthread_mutex_lock(&sns_resync_timer); gettimeofday(&now, NULL); timeout.tv_sec = now.tv_sec + 60; //sns_resync_interval; timeout.tv_nsec = now.tv_usec * 1000; rc = pthread_cond_timedwait(&resync_cond, &sns_resync_timer, &timeout); if (rc != ETIMEDOUT) perror ("Error in Timeout Request in SNSResyncTimeoutThread"); pthread_mutex_unlock(&sns_resync_timer); if (pauseFlag) return (0); } return (0); } void DebugOn (char * type) { if (!strcmp(type,"parse")) { isns_parse_debug = -1; isns_main_debug = -1; sns_comm_debug = -1; sns_tcp_debug = -1; } else if (!strcmp(type,"tcp")) { sns_comm_debug = -1; sns_tcp_debug = -1; } else if (!strcmp(type,"db")) { isns_db_debug = -1; } else if (!strcmp(type,"list")) { isns_list_debug = -1; } else if (!strcmp(type,"query")) { isns_query_debug = -1; } else if (!strcmp(type,"reg")) { isns_reg_debug = -1; isns_dereg_debug = -1; } else if (!strcmp(type,"fsm")) { sns_fsm_debug = -1; sns_hb_debug = -1; sns_cb_debug = -1; } else if (!strcmp(type,"esi")) { isns_esi_debug = -1; } else if (!strcmp(type,"scn")) { sns_scn_debug = -1; } else if (!strcmp(type,"all")) { sns_bcast_debug = -1; sns_cb_debug = -1; sns_comm_debug = -1; isns_db_debug = -1; sns_fsm_debug = -1; sns_hb_debug = -1; isns_main_debug = -1; sns_recv_debug = -1; sns_rsync_debug = -1; sns_scn_debug = -1; isns_parse_debug = -1; sns_tcp_debug = -1; isns_list_debug = -1; isns_query_debug = -1; isns_reg_debug = -1; isns_dereg_debug = -1; isns_esi_debug = -1; } } isns-2.1-01/isnsserver/src/iSNSbuffer.c0000644000175000017500000000436010665040341016724 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include "iSNStypes.h" #include "iSNSbuffer.h" #include "iSNSipc.h" #include "iSNS.h" #include "iSNSmsg.h" #include "iSNSdebug.h" char * ISNSAllocBuffer (uint32_t size) { void *tmp; tmp = malloc(size); return (tmp); } void ISNSFreeBuffer (char *p_buf) { if (p_buf!=NULL) free(p_buf); } int SNSCreateBufferPool (uint8_t bpool_id) { return (SUCCESS); } void SNSInitBufferPool (void *buf_space, uint32_t max_buffers, uint32_t qtype) { } int SNSMDBBufCount (uint32_t qtype) { return (10); } isns-2.1-01/isnsserver/src/iSNSresponse.c0000644000175000017500000001454710665040341017321 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This file contains source code for managing the responses back to clients. */ #include "iSNS.h" #include "iSNStypes.h" #include "iSNSmsg.h" #include "iSNSdebug.h" /********************************************************************* _ISNSAppendAttr Appends the attribute to the message in the TLV format. *********************************************************************/ int ISNSAppendAttr (ISNS_Msg * msg, int tag, int size, char *p_value, int value) { ISNS_Attr *attr; if (msg == NULL) { __LOG_ERROR ("Message is NULL"); return (ERROR); } /* add room for error code */ if (msg->hdr.msg_len == 0) { msg->hdr.msg_len = 4; msg->hdr.msg_len += ISNS_SIZEOF_TAG; // add delimiter } /* Jump to the end */ attr = (ISNS_Attr *)((char *) &msg->payload + msg->hdr.msg_len); /* insert */ attr->tag = tag; attr->len = size; if (p_value) { __ISNS_COPY (&attr->val, sizeof(attr->val), p_value, attr->len); } else if (attr->len == 8) { /* Special time format */ attr->val.timestamp.t_pad = 0; attr->val.timestamp.t_time = htonl (value); } else { *(uint32_t *) & attr->val = value; } msg->hdr.msg_len += attr->len + ISNS_SIZEOF_TAG; attr = (ISNS_Attr *)((char *) attr + attr->len + ISNS_SIZEOF_TAG); return (ISNS_NO_ERR); } int ISNSAppendTimeStamp ( ISNS_Msg *msg ) { ISNS_Attr *attr; time_t t; if ( msg == NULL ) return ( ERROR ); /* Jump to end */ attr = (ISNS_Attr *)((char *) &msg->payload + msg->hdr.msg_len); /* AppendTime */ attr->tag = ISNS_TIMESTAMP; attr->len = 8; attr->val.timestamp.t_pad = 0; attr->val.timestamp.t_time = htonl (time(&t)); msg->hdr.msg_len += attr->len + ISNS_SIZEOF_TAG; return (SUCCESS); } /********************************************************************* _ISNSAppendKey Appends the attribute to the message in the TLV format. *********************************************************************/ int ISNSAppendKey (ISNS_Msg * msg, int tag, int size, char *p_value, int value) { ISNS_Attr *attr; if (msg == NULL) return (ERROR); if (msg->hdr.msg_len == 0 && msg->hdr.type != ISNS_SCN && msg->hdr.type != ISNS_ESI && msg->hdr.type != ISNS_SCN_REG_REQ) { msg->hdr.msg_len = 4; /* Error Code */ } /* Jump to end */ attr = (ISNS_Attr *)((char *) &msg->payload + msg->hdr.msg_len); /* insert the key(s) */ attr->tag = tag; attr->len = size; if (p_value) { __ISNS_COPY (&attr->val, sizeof(attr->val), p_value, attr->len); } else if (attr->len == 8) { /* Special time format */ attr->val.timestamp.t_pad = 0; attr->val.timestamp.t_time = htonl (value); } else { *(uint32_t *) & attr->val = value; } msg->hdr.msg_len += attr->len + ISNS_SIZEOF_TAG; return (ISNS_NO_ERR); } /********************************************************************* Finds a tag in the response msg. *********************************************************************/ ISNS_Attr * ISNSFindAttrInResponseMsg ( int key, ISNS_Msg *msg ) { ISNS_Attr *attr; /* Find Delimiter */ attr = (ISNS_Attr *)((char *) &msg->payload + 4); while ((char *)attr < (char *)&msg->payload + msg->hdr.msg_len) { if ( attr->tag == key ) return ( attr ); attr = (ISNS_Attr *)((char *) attr + attr->len + ISNS_SIZEOF_TAG); } return ( NULL ); } /********************************************************************* Finds a tag in the response msg. *********************************************************************/ ISNS_Attr * ISNSFindKeyInResponseMsg (int key, ISNS_Msg * msg) { ISNS_Attr *attr; /* Find Delimiter */ attr = (ISNS_Attr *)((char *) &msg->payload + 4); while ((char *)attr < (char *)&msg->payload + msg->hdr.msg_len && attr->tag != ISNS_DELIMITER) { if (attr->tag == key) return (attr); attr = (ISNS_Attr *)((char *) attr + attr->len + ISNS_SIZEOF_TAG); } return (NULL); } /********************************************************************* _ISNSAppendTLV Appends a TLV to a spot in memory at an offset. *********************************************************************/ int ISNSAppendTLV(void *ptr, int *offset, int tag, int len, char *p_value, int value) { ISNS_Attr *attr; attr = (ISNS_Attr *)((char *)ptr+(*offset)); /* insert */ attr->tag = tag; attr->len = len; if (p_value) { __ISNS_COPY (&attr->val, sizeof(attr->val), p_value, attr->len); } else { *(uint32_t *) & attr->val = value; } *offset += ISNS_SIZEOF_TAG + attr->len; return (ISNS_NO_ERR); } isns-2.1-01/isnsserver/src/iSNSparse.c0000644000175000017500000005046510665040341016574 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include #include "iSNStypes.h" #include "iSNSdb.h" #include "iSNSmsg.h" #include "iSNSparse.h" #include "iSNSdebug.h" extern int isns_parse_debug; /*** local function prototypes ***/ static int ISNSProfileKeysAttr (ISNS_Msg * msg, ISNS_Attr **attr_index, int *num_attrs, ISNS_Attr **key_index, int *num_keys, ISNS_Attr **src_attr); /************************************************************* * ISNSParseMsg *************************************************************/ int ISNSParseMsg (ISNS_Msg * msg, ISNS_Attr **attr_index, ISNS_Attr **key_index, ISNS_Attr **src_attr) { int ii; int parse_status = SUCCESS; int num_attrs; int num_keys; /* verify input parameters */ if ((msg == NULL) || (attr_index == NULL)) return (ERROR); for (ii = 0; ii < SNS_MAX_ATTRS; ii++) attr_index[ii] = NULL; for (ii = 0; ii < SNS_MAX_ATTRS; ii++) key_index[ii] = NULL; //if ((msg->hdr.type > ISNS_END_VALID_REQ_FUNC_ID) // && (msg->hdr.type < ISNS_START_VALID_RES_FUNC_ID)) // return (SUCCESS); // //if (msg->hdr.type == ISNS_HEART_BEAT) // return (SUCCESS); switch (msg->hdr.type) { case ISNS_HEART_BEAT: return (SUCCESS); case ISNS_REG_DEV_ATTR_REQ: case ISNS_ESI: case ISNS_SCN: case ISNS_DEV_GET_NXT_REQ: case ISNS_REG_DDS_REQ: case ISNS_REG_DD_REQ: case ISNS_DEREG_DDS_REQ: case ISNS_DEREG_DD_REQ: case ISNS_SCN_EVENT: case ISNS_DEREG_DEV_REQ: case ISNS_SCN_REG_REQ: case ISNS_SCN_DEREG_REQ: case ISNS_DEV_ATTR_QRY_REQ: case ISNS_DDS_GET_NXT_MEMBER_REQ: case ISNS_DD_GET_NXT_ISCSI_MEMBER_REQ: case ISNS_ENTITY_GET_NXT_PORTAL_REQ: case ISNS_REG_DEV_ATTR_RES: case ISNS_DEV_ATTR_QRY_RES: case ISNS_DEV_GET_NXT_RES: case ISNS_DEREG_DEV_RES: case ISNS_SCN_REG_RES: case ISNS_SCN_DEREG_RES: case ISNS_SCN_EVENT_RES: case ISNS_SCN_RES: case ISNS_REG_DD_RES: case ISNS_DEREG_DD_RES: case ISNS_REG_DDS_RES: case ISNS_DEREG_DDS_RES: case ISNS_ESI_RSP: case ISNS_DDS_GET_NXT_MEMBER_RES: case ISNS_DD_GET_NXT_ISCSI_MEMBER_RES: case ISNS_ENTITY_GET_NXT_PORTAL_RES: parse_status = ISNSProfileKeysAttr (msg, attr_index, &num_attrs, key_index, &num_keys, (ISNS_Attr **)src_attr); if(parse_status) __LOG_ERROR ("ISNSParseMSG error for msg->hdr.type=0x%x\n",msg->hdr.type); break; default: //if (msg->hdr.type & 0x8000) // return (SUCCESS); parse_status = ERROR; __LOG_ERROR ("ISNSParseMSG error for msg->hdr.type=0x%x unimplemented message type\n",msg->hdr.type); break; } return parse_status; } /******************************************************************** This will verify the len of tags to make sure they are correct. ********************************************************************/ int ISNSVerifyTag(int srcFlag, uint32_t tag, uint32_t len, void *ptr) { int rval = TRUE; char src[4]; if (srcFlag) strcpy(src,"SRC"); else strcpy(src," "); switch ( tag ) { case ISNS_DELIMITER: if (len != ISNS_DELIMITER_SIZE) { rval = FALSE; __LOG_WARNING ("%sTag:%i (%s) len=%i",src,tag,isnsTagText(tag),len); } __DEBUG (isns_parse_debug &1,%sTag:%i (%s) len=%i,src,tag,isnsTagText(tag),len); break; /* Variable Length */ case ISNS_ENTITY_ID: case ISNS_ISCSI_NODE_ID: case ISNS_DDS_SYM_NAME: case ISNS_ISCSI_ALIAS: case ISNS_NODE_SYM_NAME: case ISNS_DD_SYM_NAME: case ISNS_PORT_SYM_NAME: case ISNS_PORTAL_SYM_NAME: case ISNS_DD_ISCSI_MEMBER: case ISNS_PORTAL_GROUP_ISCSI_NAME: if ( len == 0) __DEBUG (isns_parse_debug &1,%sTag:%i (%s),src,tag,isnsTagText(tag)); else __DEBUG (isns_parse_debug &1,%sTag:%i (%s) %s,src,tag,isnsTagText(tag),(char *)ptr); break; case ISNS_MGMT_IP: case ISNS_PORTAL_IP: case ISNS_PORTAL_GROUP_IP: if (len != ISNS_IP_SIZE && len != 0) { rval = FALSE; __LOG_WARNING ("%sTag:%i (%s) %s",src,tag,isnsTagText(tag), inet_ntoa(*(struct in_addr *)(ptr+12)) ); } __DEBUG (isns_parse_debug &1,%sTag:%i (%s) %s,src,tag,isnsTagText(tag), inet_ntoa(*(struct in_addr *)(ptr+12)) ); break; case ISNS_TIMESTAMP: if (len != ISNS_TIMESTAMP_SIZE && len != 0 ) { rval = FALSE; __LOG_WARNING ("%sTag:%i (%s)",src,tag,isnsTagText(tag)); } __DEBUG (isns_parse_debug &1,%sTag:%i (%s),src,tag,isnsTagText(tag)); break; case ISNS_ENTITY_TYPE: case ISNS_PROT_VER: case ISNS_ENTITY_PERIOD: case ISNS_ENTITY_IDX: case ISNS_ENTITY_CERT: case ISNS_PORTAL_PORT: case ISNS_ESI_INTERVAL: case ISNS_ESI_PORT: case ISNS_SCN_PORT: case ISNS_PORTAL_IDX: case ISNS_ISCSI_TYPE: case ISNS_ISCSI_SCN_BITMAP: case ISNS_ISCSI_IDX: case ISNS_PORT_TYPE: case ISNS_DDS_ID: case ISNS_DDS_STATUS: case ISNS_DD_ID: case ISNS_DD_ISCSI_MEMBER_IDX: case ISNS_DD_ACTIVE: case ISNS_NODE_ACTIVE: case ISNS_PORT_ID: case ISNS_IFCP_SCN_BITMAP: case ISNS_DD_FEATURE_BITMAP: case ISNS_PORTAL_GROUP: case ISNS_PORTAL_GROUP_TAG: case ISNS_PORTAL_SECURITY_BITMAP: case ISNS_PORTAL_GROUP_PORT: if (len != 4 && len != 0) { rval = FALSE; if (len == 0) __LOG_WARNING ("%sTag:%i (%s)",src,tag,isnsTagText(tag)); else __LOG_WARNING ("%sTag:%i (%s) %i",src,tag,isnsTagText(tag),*(uint32_t *)ptr); } if (len == 0) __DEBUG (isns_parse_debug &1,%sTag:%i (%s),src,tag,isnsTagText(tag)); else __DEBUG (isns_parse_debug &1,%sTag:%i (%s) %i,src,tag,isnsTagText(tag),*(uint32_t *)ptr); break; case ISNS_PORT_NAME: case ISNS_NODE_NAME: case ISNS_DD_IFCP_MEMBER: if (len != 8 && len != 0) { rval = FALSE; if (len == 0) __LOG_WARNING ("%sTag:%i (%s)",src,tag,isnsTagText(tag)); else __LOG_WARNING ("%sTag:%i (%s) %s",src,tag,isnsTagText(tag),(char *)ptr); } if (len == 0) __DEBUG (isns_parse_debug &1,%sTag:%i (%s),src,tag,isnsTagText(tag)); else __DEBUG (isns_parse_debug &1,%sTag:%i (%s) %s,src,tag,isnsTagText(tag),(char *)ptr); break; case ISNS_FABRIC_PORT_NAME: case ISNS_FC_HARD_ADDR: case ISNS_FC_PORT_IP: case ISNS_FC_COS: case ISNS_FC4_TYPE: case ISNS_FC4_DESC: case ISNS_FC4_FEATURE: case ISNS_IFCP_NODE_CERT: case iSNS_FC4_TYPE_QUERY_KEY: case ISNS_FC_NODE_IP: case ISNS_FC_NODE_IPA: case ISNS_COMPANY_OUI: case ISNS_SCN_CALLBACK: case ISNS_PORTAL_CERT: case ISNS_ISCSI_CERT: case ISNS_FC_NODE_CERT: if (len == 0) __DEBUG (isns_parse_debug &1,%sTag:%i (%s),src,tag,isnsTagText(tag)); else __DEBUG (isns_parse_debug &1,%sTag:%i (%s) %i,src,tag,isnsTagText(tag),*(uint32_t *)ptr); break; default: __DEBUG (isns_parse_debug &1,(Tag not Defined:%i),tag); break; } if (!rval) __LOG_WARNING ("VerifyTag rc:%i",rval); return (rval); } static int ISNSProfileKeysAttr (ISNS_Msg * msg, ISNS_Attr **attr_index, int *num_attrs, ISNS_Attr **key_index, int *num_keys, ISNS_Attr **src_attr) { int ii, jj; int len; int sns_attr_len; ISNS_Attr *attr; ISNS_Attr *ptr; int offset; /* * verify input parameters */ if ((msg == NULL) || (msg->hdr.msg_len > sizeof (ISNS_Msg))) { __LOG_ERROR ("Invalid msg header length: %i\n",msg->hdr.msg_len); return (ERROR); } __DEBUG (isns_parse_debug &1,%s:0x%x flags:%x msg_len:%i, FuncIDText(msg->hdr.type), msg->hdr.type, msg->hdr.flags, msg->hdr.msg_len); /* Store Keys */ if (msg->hdr.type & 0x8000) // response messages with status code { __DEBUG (isns_parse_debug &1,"response status code:0x%x",msg->payload); offset = 4; } else offset = 0; ptr = attr = (ISNS_Attr *)((char *)&msg->payload+offset); if (src_attr != NULL) { if (!ISNSVerifyTag(TRUE,ptr->tag, ptr->len, (void *)&ptr->val)) return (ERROR); /* Store the src attr */ *src_attr = attr; /* Skip the src attr */ ptr = (struct ISNS_attr *)((char *) attr + attr->len + ISNS_SIZEOF_TAG); offset = attr->len + ISNS_SIZEOF_TAG; } jj = 0; while ((char *)ptr < (char *) &msg->payload + msg->hdr.msg_len) { if (!ISNSVerifyTag(FALSE,ptr->tag, ptr->len, (void *)&ptr->val)) return (ERROR); if (ptr->tag == ISNS_DELIMITER) { ptr = (struct ISNS_attr *)((char *) ptr + ISNS_SIZEOF_TAG); offset += ISNS_SIZEOF_TAG; break; } key_index[jj] = ptr; jj++; offset += ISNS_SIZEOF_TAG + ptr->len; ptr = (struct ISNS_attr *)((char *) ptr + ISNS_SIZEOF_TAG + ptr->len); } *num_keys = jj; /* Skip to the Operational Attributes */ ii = 0; len = offset; sns_attr_len = msg->hdr.msg_len; attr = (ISNS_Attr *) ptr; /* * Go through the message's attributes and parse them */ jj = 0; while (len < sns_attr_len && ii < SNS_MAX_ATTRS) { /* * Find a match with any required or optional attributes * for that op_code. */ if (!ISNSVerifyTag(FALSE,attr->tag, attr->len, (void *)&attr->val)) return (ERROR); attr_index[ii] = attr; ii++; len += ISNS_SIZEOF_TAG + attr->len; attr = (ISNS_Attr *) ((char *) attr + ISNS_SIZEOF_TAG + attr->len); } *num_attrs = ii; return SUCCESS; } int SNSConvertPayloadNTOH (ISNS_Msg_Descp * msg) { void *ptr; ptr = msg->msg.payload.payload_data; if (msg->cb.sender != ISNS_REMOTE) { return (SUCCESS); } if (msg->msg.hdr.msg_len == 0) { return (SUCCESS); } if (msg->msg.hdr.type == ISNS_HEART_BEAT) { msg->msg.payload.heartbeat.tcp_port = ntohs (msg->msg.payload.heartbeat.tcp_port); msg->msg.payload.heartbeat.udp_port = ntohs (msg->msg.payload.heartbeat.udp_port); msg->msg.payload.heartbeat.counter = ntohl (msg->msg.payload.heartbeat.counter); msg->msg.payload.heartbeat.interval = ntohl (msg->msg.payload.heartbeat.interval); return (SUCCESS); } switch (msg->msg.hdr.type) { case ISNS_SCN_RES: case ISNS_ESI_RSP: msg->msg.payload.error_code = ntohl (msg->msg.payload.error_code); ptr = (char *) ptr + 4; default: while ( ptr < (void *)(msg->msg.payload.payload_data + msg->msg.hdr.msg_len)) { ISNS_Attr *pattr = (ISNS_Attr *)ptr; if ((pattr->tag < 5000) && (pattr->tag != 0)) { __LOG_WARNING ("**** Warning: Tag is incorrect tag=0x%x (%u).\n", pattr->tag, pattr->tag); } else { pattr->tag = ntohl (pattr->tag); } //__DEBUG (isns_parse_debug &1,"Processing msg type=0x%x, tag=%i",msg->msg.hdr.type,pattr->tag); /* length */ ptr = (void *)(ptr + 4); if ((pattr->len < 5000) && (pattr->len != 0)) { __LOG_WARNING ("Warning: Length is incorrect tag=0x%x, len=0x%x.", pattr->tag, pattr->len); } else { pattr->len = ntohl (pattr->len); } ptr = (void *)(ptr + 4); switch (pattr->tag) { /* These we convert. */ case ISNS_ENTITY_IDX: case ISNS_ISCSI_IDX: case ISNS_PORTAL_IDX: case ISNS_DD_ISCSI_MEMBER_IDX: case ISNS_DDS_ID: case ISNS_DD_ID: case ISNS_ENTITY_TYPE: case ISNS_ESI_INTERVAL: case ISNS_ESI_PORT: case ISNS_COMPANY_OUI: case ISNS_PORTAL_PORT: case ISNS_PORT_ID: case ISNS_PORT_TYPE: case ISNS_DDS_STATUS: case ISNS_ISCSI_SCN_BITMAP: case ISNS_IFCP_SCN_BITMAP: case ISNS_ISCSI_TYPE: case ISNS_ENTITY_PERIOD: case ISNS_DD_FEATURE_BITMAP: case ISNS_PORTAL_SECURITY_BITMAP: case ISNS_PORTAL_GROUP_PORT: case ISNS_PORTAL_GROUP_TAG: case ISNS_PORTAL_GROUP: if (pattr->len != 0) { *(uint32_t *) & pattr->val = ntohl (*(uint32_t *) & pattr->val); } ptr = (uint8_t *) ptr + pattr->len; break; case ISNS_PROT_VER: if (pattr->len != 0) { pattr->val.prot_ver.ver_max = htons (pattr->val.prot_ver.ver_max); pattr->val.prot_ver.ver_min = htons (pattr->val.prot_ver.ver_min); } ptr = (uint8_t *) ptr + pattr->len; break; /* These we leave alone. */ case ISNS_PORT_NAME: case ISNS_DDS_SYM_NAME: case ISNS_DD_SYM_NAME: case ISNS_DD_ISCSI_MEMBER: case ISNS_DD_IFCP_MEMBER: case ISNS_FC4_TYPE: case ISNS_PORTAL_IP: case ISNS_FC_NODE_IP: case ISNS_FC_NODE_IPA: case ISNS_NODE_SYM_NAME: case ISNS_ENTITY_ID: case ISNS_DELIMITER: case ISNS_FC4_FEATURE: case ISNS_NODE_NAME: case ISNS_PORTAL_SYM_NAME: case ISNS_ISCSI_NODE_ID: case ISNS_FABRIC_PORT_NAME: case ISNS_FC4_DESC: case ISNS_FC_NODE_CERT: case ISNS_MGMT_IP: case ISNS_TIMESTAMP: case ISNS_FC_HARD_ADDR: case ISNS_FC_PORT_IP: case ISNS_FC_COS: case ISNS_PORT_SYM_NAME: case ISNS_ENTITY_CERT: case ISNS_PORTAL_CERT: case ISNS_IFCP_NODE_CERT: case ISNS_ISCSI_CERT: case ISNS_ISCSI_ALIAS: case ISNS_SCN_PORT: case ISNS_PORTAL_GROUP_ISCSI_NAME: case ISNS_PORTAL_GROUP_IP: ptr = (uint8_t *) ptr + pattr->len; break; default: __LOG_ERROR ("Warning: Unknown tag. tag=0x%x.",pattr->tag); ptr = (uint8_t *) ptr + msg->msg.hdr.msg_len; return (ERROR); break; } /* End switch */ } break; } return (SUCCESS); } void SNSConvertPayloadHTON (ISNS_Msg * msg) { int len; void *ptr = msg->payload.payload_data; if (msg->hdr.type == ISNS_HEART_BEAT) { msg->payload.heartbeat.tcp_port = ntohs (msg->payload.heartbeat.tcp_port); msg->payload.heartbeat.udp_port = ntohs (msg->payload.heartbeat.udp_port); msg->payload.heartbeat.interval = htonl (msg->payload.heartbeat.interval); msg->payload.heartbeat.counter = htonl (msg->payload.heartbeat.counter); return; } /* Check to see if this is a response */ if (msg->hdr.type & 0x8000) { /* Convert the Error CODE */ *(uint32_t *) ptr = htonl (*(uint32_t *) ptr); ptr = (char *) ptr + 4; } while ( ptr < (void *)(msg->payload.payload_data + msg->hdr.msg_len)) { ISNS_Attr *pattr = (ISNS_Attr *)ptr; int tag; if (pattr->tag > 5000) { __LOG_ERROR ("Warning: Tag is incorrect. tag=0x%x",pattr->tag); tag = ntohl (pattr->tag); } else { tag = pattr->tag; pattr->tag = ntohl (pattr->tag); } /* length */ ptr = (void *)(ptr + 4); if (pattr->len > 5000) { __LOG_ERROR("Warning: Length is incorrect. tag=0x%x, len=0x%x",pattr->tag,pattr->len); len = htonl (pattr->len); } else { len = pattr->len; pattr->len = ntohl (pattr->len); } ptr = (void *)(ptr + 4); switch (tag) { /* These we convert. */ case ISNS_ENTITY_IDX: case ISNS_ISCSI_IDX: case ISNS_PORTAL_IDX: case ISNS_DD_ISCSI_MEMBER_IDX: case ISNS_DDS_ID: case ISNS_DD_ID: case ISNS_ENTITY_TYPE: case ISNS_ESI_PORT: case ISNS_ESI_INTERVAL: case ISNS_COMPANY_OUI: case ISNS_PORTAL_PORT: case ISNS_PORTAL_GROUP_PORT: case ISNS_PORTAL_GROUP_TAG: case ISNS_PORT_TYPE: case ISNS_DDS_STATUS: case ISNS_ISCSI_SCN_BITMAP: case ISNS_IFCP_SCN_BITMAP: case ISNS_ISCSI_TYPE: case ISNS_ENTITY_PERIOD: case ISNS_DD_FEATURE_BITMAP: *(uint32_t *) & pattr->val = ntohl (*(uint32_t *) & pattr->val); ptr = (uint8_t *) ptr + len; break; case ISNS_PROT_VER: pattr->val.prot_ver.ver_min = htons (pattr->val.prot_ver.ver_min); pattr->val.prot_ver.ver_max = htons (pattr->val.prot_ver.ver_max); ptr = (uint8_t *) ptr + len; break; /* These we leave alone. */ case ISNS_PORT_NAME: case ISNS_DDS_SYM_NAME: case ISNS_DD_SYM_NAME: case ISNS_DD_ISCSI_MEMBER: case ISNS_DD_IFCP_MEMBER: case ISNS_FC4_TYPE: case ISNS_PORTAL_IP: case ISNS_PORTAL_GROUP_IP: case ISNS_PORT_ID: case ISNS_FC_NODE_IP: case ISNS_FC_NODE_IPA: case ISNS_NODE_SYM_NAME: case ISNS_ENTITY_ID: case ISNS_DELIMITER: case ISNS_FC4_FEATURE: case ISNS_NODE_NAME: case ISNS_PORTAL_SYM_NAME: case ISNS_ISCSI_NODE_ID: case ISNS_FABRIC_PORT_NAME: case ISNS_FC4_DESC: case ISNS_FC_NODE_CERT: case ISNS_MGMT_IP: case ISNS_TIMESTAMP: case ISNS_FC_HARD_ADDR: case ISNS_FC_PORT_IP: case ISNS_FC_COS: case ISNS_PORT_SYM_NAME: case ISNS_ENTITY_CERT: case ISNS_PORTAL_CERT: case ISNS_IFCP_NODE_CERT: case ISNS_ISCSI_CERT: case ISNS_ISCSI_ALIAS: case ISNS_PORTAL_GROUP_ISCSI_NAME: ptr = (uint8_t *) ptr + len; break; default: __LOG_WARNING ("Warning: Unknown tag. tag=0x%x",pattr->tag); ptr = (uint8_t *) ptr + msg->hdr.msg_len; break; } /* End switch */ } return; } int SNSParseTransOpcode (int op_code) { return (-1); } /********************************************************************* Finds a tag. *********************************************************************/ int ISNSFindTag (int startIndex, int key, ISNS_Attr **attr_indx) { int ii; ISNS_Attr *attr; for (ii = startIndex; ii < SNS_MAX_ATTRS && attr_indx[ii]; ii++) { attr = (ISNS_Attr *) attr_indx[ii]; if (attr->tag == key) { return (ii); } } return (-1); } isns-2.1-01/isnsserver/src/iSNSInit.c0000644000175000017500000001057010665040341016356 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This file contains source code for initializing * iSNS task. * */ #include "iSNS.h" #include "iSNScomm.h" #include "iSNSdb.h" #include "iSNSmsg.h" #include "iSNSqueue.h" #include "iSNSfsm.h" #include "iSNSipc.h" #include "iSNSbuffer.h" #include "iSNSreg.h" #include "iSNSdebug.h" #ifndef SNS_LINUX HANDLE trcv_pid; #endif char sns_errmsg[256]; STATUS SNSInit (ISNS_Entity sns_role) { /* * The Process ID of the UDP receive task. */ if (CreateIPCEndPoint(SNS_EP) == ERROR) { sprintf (sns_errmsg, "%s:%d - Error creating SNS_EP IPC endpoint\n", __FILE__,__LINE__); __LOG_ERROR("Error creating SNS_EP IPC endpoint"); taskDelete(taskIdSelf()); } /* * Create a message queue for sending messages * to other software entities in the switch. */ if (CreateIPCEndPoint(DEVICE_MGMT_EP) == ERROR) { __LOG_ERROR("Error creating DEVICE_MGMT_EP IPC endpoint"); taskDelete(taskIdSelf()); } /* * Initialize database envirnoment and resources */ if (ISNSdbOpen() == ERROR) { __LOG_ERROR("Error in opening iSNS DB file"); taskDelete(taskIdSelf()); } /* * Setup socket for talking to SoIP entities. */ if (SNSCommInit(sns_role) == -1) { __LOG_ERROR ("Error in Initialing socket communication"); /* * clean up and bail out */ ISNSdbClose(); taskDelete(taskIdSelf()); } /* * Setup the queue for staging iSNS requests that require * a response */ if (SNSQInit(SNS_TRANSACTION_QUEUE) == ERROR) { __LOG_ERROR("Error initing queue IPC msgs"); ISNSdbClose(); taskDelete(taskIdSelf()); } /* * Start the procefor receiving UDP messages. * */ #ifdef SNS_LINUX if ((taskSpawn("tsns_rx", 67, 0, 8192, SNSReceiveMain, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)) != 0) #else if ((trcv_pid = (void *)taskSpawn("tsns_rx", 67, 0, 8192, SNSReceiveMain, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)) == NULL) #endif { __LOG_ERROR("Error spawning iSNS UDP receive task"); ISNSdbClose(); taskDelete(taskIdSelf()); } /* * Start the heartbeat interval timer. */ ISNSInitDBTables(); Create_Default_DD(); strcpy(isns_control_node, CONTROL_NODE); if ( SNSStartFSM() == ERROR ) { __LOG_ERROR("Unable to Start iSNS FSM"); ISNSdbClose(); taskDelete(taskIdSelf()); } return (OK); } isns-2.1-01/isnsserver/src/iSNSList.c0000644000175000017500000005547410665040341016402 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include "iSNS.h" #include "iSNStypes.h" #include "iSNSList.h" #include "iSNSdb.h" #include "iSNSbuffer.h" #include "iSNSdebug.h" int isns_list_debug = 0; /******************************************************************** Initializes a doubly linked list structure. The linked list has a dummy node at the head of the list. ********************************************************************/ int InitList(int list_id, void * record) { ISNS_LIST *plist=NULL; switch (list_id) { case ISCSI_DD_LIST: { SOIP_Iscsi *p_entry; p_entry = record; plist = &p_entry->dd_id_list; plist->p_entry = p_entry; break; } case DDS_DD_LIST: { SOIP_Dds *p_entry; p_entry = record; plist = &p_entry->dd_list; plist->p_entry = p_entry; break; } case DD_DDS_LIST: { SOIP_Dd *p_entry; p_entry = record; plist = &p_entry->dds_list; plist->p_entry = p_entry; break; } case DD_MEMBER_LIST: { SOIP_Dd *p_entry; p_entry = record; plist = &p_entry->member_list; plist->p_entry = p_entry; break; } case ENTITY_PORTAL_LIST: { SOIP_Entity *p_entry; p_entry = record; plist = &p_entry->iportal_list; plist->p_entry = p_entry; break; } case ENTITY_ISCSI_LIST: { SOIP_Entity *p_entry; p_entry = record; plist = &p_entry->iscsi_node_list; plist->p_entry = p_entry; break; } case ENTITY_FCP_LIST: { SOIP_Entity *p_entry; p_entry = record; plist = &p_entry->ifcp_node_list; plist->p_entry = p_entry; break; } case FCP_PORTAL_LIST: { SOIP_Fc_Node *p_entry; p_entry = record; plist = &p_entry->port_list; plist->p_entry = p_entry; break; } case FCP_DD_LIST: { SOIP_Ifcp *p_entry; p_entry = record; plist = &p_entry->dd_id_list; plist->p_entry = p_entry; break; } case SCN_CALLBACK_LIST: { ISNS_LIST *p_entry; p_entry = record; plist = p_entry; plist->p_entry = p_entry; break; } case SCN_LIST: { ISNS_LIST *p_entry; p_entry = record; plist = p_entry; plist->p_entry = p_entry; break; } } plist->list_id = list_id; plist->first_index = 0; plist->last_index = 0; plist->node_count = 0; __DEBUG (isns_list_debug &1,InitList list_id:%i,plist->list_id); __DEBUG (isns_list_debug &1,InitList node_count:%i,plist->node_count); return ( SUCCESS ); } /******************************************************************** Deletes a list. ********************************************************************/ int DeleteList(ISNS_LIST *plist) { ISNS_LIST_NODE pnode; __DEBUG (isns_list_debug &1,DeleteList list_id:%i,plist->list_id); while (!IsEmptyList(plist)) { pnode.index = plist->first_index; RemoveNode(plist, &pnode); } return (SUCCESS); } /******************************************************************** Removes a node from a list. ********************************************************************/ int RemoveNode(ISNS_LIST *plist, ISNS_LIST_NODE *pnode) { int foundFlag; ISNS_LIST_NODE *curr_node; int rval; ISNS_DBKey key; SOIP_DB_Entry entry; int next_index; int prev_index; SOIP_Entity *p_entity; SOIP_Iscsi *p_iscsi; SOIP_Dds *p_dds; SOIP_Dd *p_dd; SOIP_Portal *p_portal; SOIP_Fc_Node *p_ifcp; ISNS_LIST *p_list; __DEBUG (isns_list_debug &1,Remove Node); foundFlag = FALSE; curr_node = NULL; curr_node = GetNextNode(plist, curr_node); while ( curr_node != NULL ) { __DEBUG (isns_list_debug &1, curr_node:%i pnode:%i,curr_node->index,pnode->index); if (curr_node->index == pnode->index ) { foundFlag = TRUE; break; } curr_node = GetNextNode(plist, curr_node); } if ( (curr_node == NULL) && (plist->node_count > 0) ) { __DEBUG (isns_list_debug &1,Remove Node FAILURE node_count:%i,plist->node_count); plist->node_count--; return ERROR; /* we should have found a node in this case */ } __DEBUG (isns_list_debug &1, Remove Node FoundFlag: %i,foundFlag); if ( foundFlag ) { __DEBUG (isns_list_debug &1, FoundFlag); /* read current node */ memset(&key,0,sizeof(ISNS_DBKey)); key.tag = LIST_KEY; key.val.list.list_id = plist->list_id; key.val.list.list_index = pnode->index; memset(&entry,0,sizeof(SOIP_DB_Entry)); if (plist->list_id == ENTITY_ISCSI_LIST) { p_entity = plist->p_entry; strcpy(key.val.list.key.node_name.v,p_entity->eid.id); } else if (plist->list_id == ENTITY_FCP_LIST) { p_entity = plist->p_entry; strcpy(key.val.list.key.node_name.v,p_entity->eid.id); } else if (plist->list_id == ENTITY_PORTAL_LIST) { p_entity = plist->p_entry; strcpy(key.val.list.key.node_name.v,p_entity->eid.id); } else if (plist->list_id == ISCSI_DD_LIST) { p_iscsi = plist->p_entry; strcpy(key.val.list.key.node_name.v,p_iscsi->id.v); } else if (plist->list_id == DDS_DD_LIST) { p_dds = plist->p_entry; key.val.list.key.dds.id = p_dds->id; } else if (plist->list_id == DD_DDS_LIST) { p_dd = plist->p_entry; key.val.list.key.dd.id = p_dd->id; } else if (plist->list_id == DD_MEMBER_LIST) { p_dd = plist->p_entry; key.val.list.key.dd.id = p_dd->id; } else if (plist->list_id == FCP_PORTAL_LIST) { p_ifcp = plist->p_entry; strcpy (key.val.list.key.node_name.v,p_ifcp->node_name.v); } else if (plist->list_id == FCP_DD_LIST) { p_ifcp = plist->p_entry; strcpy (key.val.list.key.node_name.v,p_ifcp->node_name.v); } else if (plist->list_id == PORTAL_ENTITY_LIST) { p_portal = plist->p_entry; __ISNS_COPY (&key.val.list.key.portal.ip_addr, sizeof(key.val.list.key.portal.ip_addr), &p_portal->ip_addr, sizeof(IP_Address)); key.val.list.key.portal.ip_port = p_portal->ip_port; } else if (plist->list_id == SCN_LIST) { p_list = plist->p_entry; strcpy (key.val.list.key.node_name.v,"scn_list"); } else if (plist->list_id == SCN_CALLBACK_LIST) { p_list = plist->p_entry; strcpy (key.val.list.key.node_name.v,"scn_callback_list"); } rval = ISNSdbRead(&key,&entry); next_index = entry.data.list.next_index; prev_index = entry.data.list.prev_index; /*delete current node*/ rval = ISNSdbDelete(&key); /*pdate first_index if necessary*/ if (plist->first_index == key.val.list.list_index ) { plist->first_index = next_index; } /*update last_index if necessary*/ if (plist->last_index == key.val.list.list_index ) { plist->last_index = prev_index; } /*update previous node*/ if (prev_index != 0) { key.val.list.list_index = prev_index; rval = ISNSdbRead(&key,&entry); entry.data.list.next_index = next_index; rval = ISNSdbWrite(&key,entry); } /*update next node*/ if (next_index != 0) { key.val.list.list_index = next_index; rval = ISNSdbRead(&key,&entry); entry.data.list.prev_index = prev_index; rval = ISNSdbWrite(&key,entry); } /*update node_count*/ __DEBUG (isns_list_debug &1, RemoveNode - node_count:%i,plist->node_count); plist->node_count--; } return ( SUCCESS ); } /******************************************************************** Retrieves the data pointer from a node. ********************************************************************/ void * GetNodeData(ISNS_LIST_NODE *pnode ) { __DEBUG (isns_list_debug &1, GetNodeData); return ( pnode->data ); } /******************************************************************** Finds an object in the list. ********************************************************************/ ISNS_LIST_NODE * FindNode(ISNS_LIST *plist, char *pdata, int data_size) { ISNS_LIST_NODE *ptr; __DEBUG (isns_list_debug &1,FindNode); ptr = NULL; while ( (ptr=GetNextNode(plist, ptr)) ) { if (ptr->data_size == data_size && !memcmp(ptr->data, pdata, data_size)) { return (ptr); } } return ( NULL ); } /******************************************************************** Adds a node to a list. ********************************************************************/ int AddNode(ISNS_LIST *plist, char *pdata, int data_size) { ISNS_DBKey key; SOIP_DB_Entry entry; int rval; SOIP_Entity *p_entity; SOIP_Iscsi *p_iscsi; SOIP_Dds *p_dds; SOIP_Dd *p_dd; SOIP_Portal *p_portal; SOIP_Fc_Node *p_ifcp; __DEBUG (isns_list_debug &1, AddNode - list_id:%i,plist->list_id); memset(&key,0,sizeof(ISNS_DBKey)); key.tag = LIST_KEY; key.val.list.list_id = plist->list_id; memset(&entry,0,sizeof(SOIP_DB_Entry)); if (plist->list_id == ENTITY_ISCSI_LIST) { p_entity = plist->p_entry; strcpy(key.val.list.key.node_name.v,p_entity->eid.id); __ISNS_COPY (entry.data.list.key.node_name.v, sizeof(entry.data.list.key.node_name.v), pdata, data_size); } else if (plist->list_id == ENTITY_FCP_LIST) { p_entity = plist->p_entry; strcpy(key.val.list.key.node_name.v,p_entity->eid.id); __ISNS_COPY (entry.data.list.key.node_name.v, sizeof(entry.data.list.key.node_name.v), pdata, data_size); } else if (plist->list_id == ENTITY_PORTAL_LIST) { p_entity = plist->p_entry; strcpy(key.val.list.key.node_name.v,p_entity->eid.id); __ISNS_COPY (&entry.data.list.key.portalmember, sizeof(entry.data.list.key.portalmember), pdata, data_size); } else if (plist->list_id == ISCSI_DD_LIST) { p_iscsi = plist->p_entry; strcpy(key.val.list.key.node_name.v,p_iscsi->id.v); __ISNS_COPY (&entry.data.list.key.dd, sizeof(entry.data.list.key.dd), pdata, data_size); } else if (plist->list_id == DDS_DD_LIST) { p_dds = plist->p_entry; key.val.list.key.dds.id = p_dds->id; __ISNS_COPY (&entry.data.list.key.dd, sizeof(entry.data.list.key.dd), pdata, data_size); } else if (plist->list_id == DD_DDS_LIST) { p_dd = plist->p_entry; key.val.list.key.dd.id = p_dd->id; __ISNS_COPY (&entry.data.list.key.dds, sizeof(entry.data.list.key.dds), pdata, data_size); } else if (plist->list_id == DD_MEMBER_LIST) { p_dd = plist->p_entry; key.val.list.key.dd.id = p_dd->id; __ISNS_COPY (&entry.data.list.key.ddmember, sizeof(entry.data.list.key.ddmember), pdata, data_size); } else if (plist->list_id == FCP_PORTAL_LIST) { p_ifcp = plist->p_entry; strcpy (key.val.list.key.node_name.v,p_ifcp->node_name.v); __ISNS_COPY (&entry.data.list.key.portal, sizeof(entry.data.list.key.portal), pdata, data_size); } else if (plist->list_id == FCP_DD_LIST) { p_ifcp = plist->p_entry; strcpy (key.val.list.key.node_name.v,p_ifcp->node_name.v); __ISNS_COPY (&entry.data.list.key.dd, sizeof(entry.data.list.key.dd), pdata, data_size); } else if (plist->list_id == PORTAL_ENTITY_LIST) { p_portal = plist->p_entry; __ISNS_COPY (&key.val.list.key.portal.ip_addr, sizeof(key.val.list.key.portal.ip_addr), &p_portal->ip_addr, sizeof(IP_Address)); key.val.list.key.portal.ip_port = p_portal->ip_port; __ISNS_COPY (&entry.data.list.key.portal, sizeof(entry.data.list.key.portal), pdata, data_size); } else if (plist->list_id == SCN_LIST) { strcpy (key.val.list.key.node_name.v,"scn_list"); __ISNS_COPY (&entry.data.list.key.node_name.v, sizeof(entry.data.list.key.node_name.v), pdata, data_size); } else if (plist->list_id == SCN_CALLBACK_LIST) { strcpy (key.val.list.key.node_name.v,"scn_callback_list"); __ISNS_COPY (&entry.data.list.key.node_name.v, sizeof(entry.data.list.key.node_name.v), pdata,data_size); } __DEBUG (isns_list_debug &1, update last_index); plist->last_index++; key.val.list.list_index = plist->last_index; entry.data_type = LIST_KEY; entry.data.list.index = plist->last_index; entry.data.list.prev_index = plist->last_index-1; entry.data.list.next_index = 0; if (plist->first_index == 0) plist->first_index = plist->last_index; rval = ISNSdbWrite(&key,entry); if (entry.data.list.prev_index != 0 ) { key.val.list.list_index = entry.data.list.prev_index; rval = ISNSdbRead(&key,&entry); entry.data.list.next_index = plist->last_index; rval = ISNSdbWrite(&key,entry); } plist->node_count++; __DEBUG (isns_list_debug &1, AddNode node_count:%i,plist->node_count); return ( SUCCESS ); } /******************************************************************** Returns true if the list is empty. ********************************************************************/ int IsEmptyList(ISNS_LIST *plist) { __DEBUG (isns_list_debug &1,IsEmptyList node_count:%i,plist->node_count); if (plist->node_count == 0) return (TRUE); else return (FALSE); } /******************************************************************** Returns the next node in a list. ********************************************************************/ ISNS_LIST_NODE * GetNextNode(ISNS_LIST *plist, ISNS_LIST_NODE *pnode) { ISNS_LIST_NODE *node; ISNS_DBKey key; SOIP_DB_Entry entry; int rval; SOIP_Entity *p_entity; SOIP_Iscsi *p_iscsi; SOIP_Dds *p_dds; SOIP_Dd *p_dd; SOIP_Portal *p_portal; SOIP_Fc_Node *p_ifcp; ISNS_LIST *p_list; __DEBUG (isns_list_debug &1,GetNextNode list_id:%i node_count:%i, plist->list_id,plist->node_count); if (!plist || plist->node_count == 0) { return ( NULL ); } memset(&key,0,sizeof(ISNS_DBKey)); key.tag = LIST_KEY; key.val.list.list_id = plist->list_id; memset(&entry,0,sizeof(SOIP_DB_Entry)); if ( pnode == NULL) { __DEBUG (isns_list_debug &1, AllocBuffer for first node); node = (ISNS_LIST_NODE *)ISNSAllocBuffer(sizeof(ISNS_LIST_NODE)); key.val.list.list_index = plist->first_index; if (key.val.list.list_index == 0 ) { __DEBUG (isns_list_debug &1,Error condition node count>0 but first_index is 0); plist->node_count = 0; return NULL; } } else { node = pnode; __DEBUG (isns_list_debug &1, next_index:%i,node->next_index); key.val.list.list_index = node->next_index; } if (key.val.list.list_index == 0) { __DEBUG (isns_list_debug &1, No More Entries in list); return NULL; } __DEBUG (isns_list_debug &1,Now Read entry); if (plist->list_id == ENTITY_ISCSI_LIST) { p_entity = plist->p_entry; strcpy(key.val.list.key.node_name.v,p_entity->eid.id); __DEBUG (isns_list_debug &1, read list entry); rval = ISNSdbRead(&key,&entry); if (rval != SUCCESS) { plist->node_count--; return NULL; } node->data_size = strlen(entry.data.list.key.node_name.v); node->data = (char *)ISNSAllocBuffer(node->data_size+1); __ISNS_COPY (node->data, node->data_size+1, entry.data.list.key.node_name.v, node->data_size); __DEBUG (isns_list_debug &1, Successfully read list entry); } else if (plist->list_id == ENTITY_FCP_LIST) { p_entity = plist->p_entry; strcpy(key.val.list.key.node_name.v,p_entity->eid.id); rval = ISNSdbRead(&key,&entry); if (rval != SUCCESS) return NULL; node->data_size = strlen(entry.data.list.key.node_name.v); node->data = (char *)ISNSAllocBuffer(node->data_size+1); __ISNS_COPY (node->data, node->data_size+1, entry.data.list.key.node_name.v,node->data_size); } else if (plist->list_id == ENTITY_PORTAL_LIST) { p_entity = plist->p_entry; strcpy(key.val.list.key.node_name.v,p_entity->eid.id); rval = ISNSdbRead(&key,&entry); if (rval != SUCCESS) return NULL; node->data_size = sizeof(entry.data.list.key.portal); node->data = (char *)ISNSAllocBuffer(node->data_size+1); __ISNS_COPY (node->data, node->data_size +1, &entry.data.list.key.portal,node->data_size); } else if (plist->list_id == ISCSI_DD_LIST) { p_iscsi = plist->p_entry; strcpy(key.val.list.key.node_name.v,p_iscsi->id.v); rval = ISNSdbRead(&key,&entry); if (rval != SUCCESS) return NULL; node->data_size = sizeof(entry.data.list.key.dd); node->data = (char *)ISNSAllocBuffer(node->data_size+1); __ISNS_COPY (node->data, node->data_size + 1, &entry.data.list.key.dd,node->data_size); } else if (plist->list_id == DDS_DD_LIST) { p_dds = plist->p_entry; key.val.list.key.dds.id = p_dds->id; rval = ISNSdbRead(&key,&entry); if (rval != SUCCESS) return NULL; node->data_size = sizeof(entry.data.list.key.dd); node->data = (char *)ISNSAllocBuffer(node->data_size+1); __ISNS_COPY (node->data, node->data_size + 1, &entry.data.list.key.dd,node->data_size); } else if (plist->list_id == DD_DDS_LIST) { p_dd = plist->p_entry; key.val.list.key.dd.id = p_dd->id; rval = ISNSdbRead(&key,&entry); if (rval != SUCCESS) return NULL; node->data_size = sizeof(entry.data.list.key.dds); node->data = (char *)ISNSAllocBuffer(node->data_size+1); __ISNS_COPY (node->data, node->data_size+1, &entry.data.list.key.dds,node->data_size); } else if (plist->list_id == DD_MEMBER_LIST) { p_dd = plist->p_entry; key.val.list.key.dd.id = p_dd->id; rval = ISNSdbRead(&key,&entry); if (rval != SUCCESS) return NULL; node->data_size = sizeof(entry.data.list.key.ddmember); node->data = (char *)ISNSAllocBuffer(node->data_size+1); __ISNS_COPY (node->data, node->data_size+1, &entry.data.list.key.ddmember,node->data_size); } else if (plist->list_id == FCP_PORTAL_LIST) { p_ifcp = plist->p_entry; strcpy (key.val.list.key.node_name.v,p_ifcp->node_name.v); rval = ISNSdbRead(&key,&entry); if (rval != SUCCESS) return NULL; node->data_size = sizeof(entry.data.list.key.portal); node->data = (char *)ISNSAllocBuffer(node->data_size+1); __ISNS_COPY (node->data, node->data_size+1, &entry.data.list.key.portal,node->data_size); } else if (plist->list_id == FCP_DD_LIST) { p_ifcp = plist->p_entry; strcpy (key.val.list.key.node_name.v,p_ifcp->node_name.v); rval = ISNSdbRead(&key,&entry); if (rval != SUCCESS) return NULL; node->data_size = sizeof(entry.data.list.key.dd); node->data = (char *)ISNSAllocBuffer(node->data_size+1); __ISNS_COPY (node->data, node->data_size + 1, &entry.data.list.key.dd,node->data_size); } else if (plist->list_id == PORTAL_ENTITY_LIST) { p_portal = plist->p_entry; __ISNS_COPY (&key.val.list.key.portal.ip_addr, sizeof(key.val.list.key.portal.ip_addr), &p_portal->ip_addr,sizeof(IP_Address)); key.val.list.key.portal.ip_port = p_portal->ip_port; rval = ISNSdbRead(&key,&entry); if (rval != SUCCESS) return NULL; node->data_size = sizeof(entry.data.list.key.portal); node->data = (char *)ISNSAllocBuffer(node->data_size+1); __ISNS_COPY (node->data, node->data_size+1, &entry.data.list.key.portal,node->data_size); } else if (plist->list_id == SCN_LIST) { p_list = (ISNS_LIST *)plist->p_entry; strcpy (key.val.list.key.node_name.v,"scn_list"); rval = ISNSdbRead(&key,&entry); if (rval != SUCCESS) return NULL; node->data_size = sizeof(SOIP_Scn_Entry); node->data = (char *)ISNSAllocBuffer(node->data_size+1); __ISNS_COPY (node->data, node->data_size+1, &entry.data.list.key.entity_id.id,node->data_size); } else if (plist->list_id == SCN_CALLBACK_LIST) { p_list = (ISNS_LIST *)plist->p_entry; strcpy (key.val.list.key.node_name.v,"scn_callback_list"); rval = ISNSdbRead(&key,&entry); if (rval != SUCCESS) return NULL; node->data_size = sizeof(SOIP_Scn_Callback_Entry); node->data = (char *)ISNSAllocBuffer(node->data_size+1); __ISNS_COPY (node->data, node->data_size+1, &entry.data.list.key.entity_id.id,node->data_size); } node->next_index = entry.data.list.next_index; node->prev_index = entry.data.list.prev_index; node->index = entry.data.list.index; node->list_id= plist->list_id; node->p_entry = plist->p_entry; __DEBUG (isns_list_debug &1, return GetNextNode node); return node; } /******************************************************************** Returns the previous node in a list. ********************************************************************/ ISNS_LIST_NODE * GetPrevNode(ISNS_LIST *plist, ISNS_LIST_NODE *pnode) { //return ( pnode?pnode->prev:NULL ); return NULL; } isns-2.1-01/isnsserver/src/iSNSMain.c0000644000175000017500000006055710665040341016351 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This file contains source code for implementing the * main processing loop for the SoIP service task. * */ #ifdef SNS_LINUX #include #include #include #include #include #include "iSNSLinux.h" #endif #include "iSNS.h" #include "iSNScomm.h" #include "iSNSmsg.h" #include "iSNSqueue.h" #include "iSNSfsm.h" #include "iSNSbuffer.h" #include "iSNSipc.h" #include "iSNSparse.h" #include "iSNStbl.h" #include "iSNSdb.h" #include "iSNSreg.h" #include "iSNSquery.h" #include "iSNSesi.h" #include "iSNSscn.h" #include "iSNSdebug.h" ISNS_Entity isns_role = 0; /* * flags to control debug trace output of iSNS */ int isns_pdu_debug = 0; int isns_main_debug = 0; /* SNSMain misc debugging */ int sns_hb_debug = 0; /* heartbeat debugging */ int sns_cb_debug = 0; /* callback debugging */ int sns_scn_debug = 0; /* state change debugging */ int sns_rsync_debug = 0; /* resync debugging. 1-brief. 2-detail */ int sns_hb_counter = 0; int sns_cb_msg_filter = 0; int sns_scn_msg_filter = 0xf; /* init non-zero since 0 is FLOGI */ int sns_request_retries = SNS_REQUEST_RETRIES; int sns_request_timeout = 0; extern int sns_fsm_timeout; /* * Timer used for retransmitting iSNS requests and for timing out * requests awaiting a response. */ #ifdef SNS_LINUX pthread_mutex_t sns_request_timer; pthread_cond_t request_cond = PTHREAD_COND_INITIALIZER; extern pthread_mutex_t sns_fsm_timer; extern pthread_mutex_t sns_resync_timer; extern pthread_mutex_t sns_esi_timer; #else DWORD junk; DWORD request_id; void *sns_request_timer; #endif /* * the current main message descriptor being processed */ static ISNS_Msg_Descp main_md; /* * client request msg */ static ISNS_Msg_Descp query_md; /* * Local function prototypes. */ static void regCallback(ISNS_Msg_Descp* p_md); static void SNSProcessRequest (ISNS_Msg_Descp *); void SNSReqTimeoutHdlr (void); int SNSExecCallback (ISNS_Msg_Descp *, int status); void SNSCheckTxQueue (); void SNSCheckInitTxQueue (ISNS_Msg_Descp * p_md); int TCP_RecvMain(); static int ISNSdbExec( ISNS_Msg_Descp *p_md, ISNS_Msg_Descp *p_rsp_md); extern void ISNSNotReady (); /******************************************************************** * Function Name: SNSMain * * Synopsis: void SNSMain(); * * Description: SNSMain is the entry-point of the SoIP * service task. * * Return value: If task is successfully initialized, * SNSMain() will not return. If an error * occurs during initialization SNSMain() * returns ERROR (-1). * * ********************************************************************/ int SNSMain (ISNS_Entity role) { int rc; pthread_t athread; ISNS_Msg_Descp *p_md; __LOG_INFO ("started IETF iSNS Open Source, v%s.", ISNS_VERSION); isns_role = ISNS_SECONDARY_SERVER; if (pthread_create (&athread, NULL, (void*) TCP_RecvMain, NULL) != 0) perror("Creating TCP_RecvMain"); if (SNSInit (role) == ERROR) taskDelete (taskIdSelf ()); #ifdef SNS_LINUX { int res; res = pthread_mutex_init (&sns_request_timer, NULL); /* Create AND initialize the request condition */ if (res != 0) { __LOG_ERROR ("Mutex initialization failed!"); exit (-1); } res = pthread_mutex_init (&sns_fsm_timer, NULL); if (res != 0) { __LOG_ERROR ("Mutex initialization failed!"); exit (-1); } res = pthread_mutex_init (&sns_esi_timer, NULL); if (res != 0) { __LOG_ERROR ("Mutex initialization failed!"); exit (-1); } res = pthread_mutex_init (&sns_resync_timer, NULL); if (res != 0) { __LOG_ERROR ("Mutex initialization failed!"); exit (-1); } pthread_t hdle; rc =(int)pthread_create (&hdle, NULL, (void *)SNSReqTimeoutThread, NULL); if (rc != 0){ __LOG_ERROR ("Thread creation failed."); exit (-1); } } #else { /* * Create the sns request timer */ sns_request_timer = CreateWaitableTimer (NULL, FALSE, NULL); request_pid = CreateThread (0, 0, SNSReqTimeoutThread, &junk, 0, &request_id); } #endif /* * Wait for a message to arrive. */ p_md = &main_md; for (;;) { if (SUCCESS == ReceiveIPCMessage (SNS_EP, (void *) p_md, sizeof (ISNS_Msg_Descp), 0)) { SNSConvertPayloadNTOH (p_md); SNSProcessRequest (p_md); } if (sns_request_timeout) SNSCheckTxQueue (); if (sns_fsm_timeout) SNSCheckInitTxQueue (p_md); } return (SUCCESS); } /* End SNSMain */ /******************************************************************** * Function Name: SNSProcessRequest * * Synopsis: void SNSProcessRequest(p_md); * * Arguments: p_md - pointer to the received iSNS message descriptor. * * Description: Validate and process a received iSNS message. * * ********************************************************************/ static void SNSProcessRequest (ISNS_Msg_Descp * p_md) { struct in_addr source_ip; struct in_addr null_addr = { 0 }; char dot_not_addr[INET_ADDR_LEN]; ISNS_Msg_Descp *tcb_md; ISNS_FUNC_ID msg_type; ISNS_Msg *msg; int errorCode; int timeout; ISNS_Msg_Descp *unparsed_md = NULL; ISNS_Msg_Descp *p_req_md; /* make a copy to forward to the primary */ if (isns_role != ISNS_PRIMARY_SERVER) { unparsed_md = (ISNS_Msg_Descp *) ISNSAllocBuffer(sizeof(ISNS_Msg_Cb) + sizeof(ISNS_Msg_Hdr) + p_md->msg.hdr.msg_len); if (unparsed_md == NULL) { __LOG_WARNING("ProcessRequest out of buffs (size:%i)", (int)(sizeof(ISNS_Msg_Cb) + sizeof(ISNS_Msg_Hdr) + p_md->msg.hdr.msg_len)); return; } memcpy(unparsed_md, p_md, sizeof(ISNS_Msg_Cb) + sizeof(ISNS_Msg_Hdr) + p_md->msg.hdr.msg_len); } msg = &p_md->msg; msg_type = msg->hdr.type; tcb_md = NULL; source_ip.s_addr = p_md->cb.sock.addr.sin_addr.s_addr; inet_ntoa_b (source_ip, dot_not_addr); __DEBUG(isns_main_debug &1,"ProcessRequest type:0x%x-%s",msg_type,FuncIDText(msg_type)); switch (msg_type) { case ESI_TIMEOUT_EVENT: /*ISNS_SendESI (p_md);*/ ISNS_SendESI (); break; case ISNS_ESI_RSP: ISNS_ProcessESI (p_md); break; case ISNS_SCN_RES: __LOG_INFO ("Received SCN response."); break; case FSM_TIMEOUT_EVENT: if (sns_fsm_timeout) { SNSCheckInitTxQueue (p_md); ISNS_CheckEntities (); } break; case REQ_TIMEOUT_EVENT: { __DEBUG (isns_main_debug & 32,"Received a REQ_TIMEOUT_EVENT"); /* SNSCheckTxQueue (); */ } break; case ISNS_HEART_BEAT: break; case ISNS_REG_DDS_REQ: case ISNS_REG_DD_REQ: case ISNS_SCN_EVENT: case ISNS_REG_DEV_ATTR_REQ: case ISNS_DEREG_DEV_REQ: case ISNS_DEREG_DD_REQ: case ISNS_DEREG_DDS_REQ: case ISNS_SCN_DEREG_REQ: case ISNS_SCN_REG_REQ: case ISNS_DEV_GET_NXT_REQ: case ISNS_DDS_GET_NXT_MEMBER_REQ: case ISNS_DD_GET_NXT_ISCSI_MEMBER_REQ: case ISNS_ENTITY_GET_NXT_PORTAL_REQ: case ISNS_DEV_ATTR_QRY_REQ: { extern struct sockaddr_in server_sock; __DEBUG (isns_main_debug & 16, (Received %s), FuncIDText((short)msg_type)); if (isns_pdu_debug & 1) { ParsePDU((char *)&p_md->msg); } /* register callback functions for local operations */ if (p_md->cb.sender == DEVICE_MGMT_EP) regCallback(p_md); memset(&query_md, 0, sizeof(query_md)); errorCode = SUCCESS; if (isns_role == ISNS_PRIMARY_SERVER) { errorCode = ISNSdbExec(p_md, &query_md); } if (errorCode == SUCCESS) { __DEBUG (isns_main_debug & 16, (%s), "Attribute Registered in Local iSNS Database"); if ( msg_type == ISNS_SCN_REG_REQ && p_md->cb.sender == DEVICE_MGMT_EP ) { ISNS_RegisterSCNCallback( p_md ); } /* * If running as a client then register the attributes with * the primary server. */ if (isns_role == ISNS_CLIENT || isns_role == ISNS_SECONDARY_SERVER) { inet_ntoa_b (server_sock.sin_addr, dot_not_addr); __DEBUG(isns_main_debug & 16, (%s, %s 0x%xu), "The server socket is: ", dot_not_addr, (uint32_t)server_sock.sin_addr.s_addr); if ( server_sock.sin_addr.s_addr == 0x0 ) { p_md->cb.init_rmsg = 1; __DEBUG (isns_main_debug & 16, "(%s %d)", "Set the init reg msg", p_md->cb.init_rmsg); } /* * Enqueue the request pending a response, start a * response timer and forward the request to the server. */ __DEBUG (isns_main_debug & 16, "(%s %d)", "Forwarding reg request: XID is: ", msg->hdr.xid); /* * set initial msg control block time-to-live */ unparsed_md->cb.ttl = sns_request_retries; ISNSEnqReq ( SNS_TRANSACTION_QUEUE, unparsed_md ); if ( ISNSSendMsg2Server( &unparsed_md->msg ) == SUCCESS ) { __DEBUG (isns_main_debug & 16, "(%s %d)", "Message forwarded : XID is: ", unparsed_md->msg.hdr.xid); #ifndef SNS_LINUX wdCancel(sns_request_timer); #endif #ifdef SNS_LINUX timeout = (int)((ISNSQHead(SNS_TRANSACTION_QUEUE))->cb.resp_timeout - time ((time_t*) 0) ); #else timeout = (int)((ISNSQHead(SNS_TRANSACTION_QUEUE))->cb.resp_timeout - tickGet()); #endif __DEBUG (isns_main_debug & 16, "(%s %d)", "Device registration timeout value", timeout); if (timeout < 1) timeout = 1; #ifndef SNS_LINUX wdStart(sns_request_timer, timeout, SNSReqTimeoutHdlr, NULL); #endif } else { /* Error Case while forwarding to primary */ ISNSCommUpdate(&null_addr); ISNSNotReady(); /* * send a response back to the originator * of the request. */ msg->hdr.type = 0x8000 | msg_type; msg->hdr.flags = 0; msg->hdr.msg_len = 4; msg->payload.errorCode = ISNS_UNKNOWN_ERR; ISNSDeqReq (SNS_TRANSACTION_QUEUE, msg->hdr.xid, 0); SNSExecCallback( p_md, ISNS_UNKNOWN_ERR ); if ( unparsed_md ) ISNSFreeBuffer( (char*)unparsed_md ); } return; } } else { /* Error registering */ __DEBUG (isns_main_debug & 16, (Error: %s), FuncIDText((short)msg_type)); } /* * Send a response back to the originator of the request */ __DEBUG (isns_main_debug &16,Send response back to originator); msg->hdr.type = 0x8000 | msg_type; msg->hdr.flags = 0; /* Copy the response message back */ memcpy (&p_md->msg.payload, &query_md.msg.payload, query_md.msg.hdr.msg_len); p_md->msg.hdr.msg_len = query_md.msg.hdr.msg_len==0 ? 4:query_md.msg.hdr.msg_len; p_md->msg.hdr.flags = 0; p_md->msg.payload.errorCode = errorCode; if (p_md->cb.sender == DEVICE_MGMT_EP) { SNSExecCallback(p_md, errorCode); } else { /* * Send the registration response back to the client. */ __DEBUG (isns_main_debug &16,Call ISNSSendMsg); ISNSSendMsg(p_md); } if (unparsed_md) ISNSFreeBuffer((char*)unparsed_md); __DEBUG (isns_main_debug & 0x400, (Process Request Complete)); } break; case ISNS_SCN: { __DEBUG (isns_main_debug & 16, (Received %s), FuncIDText((short)msg_type)); errorCode = ISNSdbExec(p_md, &query_md); /* Send back a response */ memcpy(&p_md->msg.payload, &query_md.msg.payload, query_md.msg.hdr.msg_len); p_md->msg.hdr.msg_len = query_md.msg.hdr.msg_len; p_md->msg.hdr.type = ISNS_SCN_RES; p_md->msg.payload.errorCode = errorCode; ISNSSendMsg(p_md); break; } case ISNS_REG_DEV_ATTR_RES: case ISNS_DEV_ATTR_QRY_RES: case ISNS_DDS_GET_NXT_MEMBER_RES: case ISNS_DD_GET_NXT_ISCSI_MEMBER_RES: case ISNS_ENTITY_GET_NXT_PORTAL_RES: case ISNS_DEV_GET_NXT_RES: case ISNS_DEREG_DEV_RES: case ISNS_SCN_REG_RES: case ISNS_SCN_DEREG_RES: case ISNS_SCN_EVENT_RES: case ISNS_REG_DD_RES: case ISNS_REG_DDS_RES: case ISNS_DEREG_DD_RES: case ISNS_DEREG_DDS_RES: { __DEBUG (isns_main_debug & 16, (Received %s), FuncIDText((short)msg_type)); __DEBUG (isns_main_debug & 16, (Received iSNS response for xid %d), msg->hdr.xid); /* * Remove the corresponding request from the request queue */ p_req_md = ISNSDeqReq (SNS_TRANSACTION_QUEUE, msg->hdr.xid, 0); if (p_req_md != NULL) { __DEBUG (isns_main_debug & 16, (%s %d qid %d), "Received transaction msg id : ", msg->hdr.xid, p_req_md->msg.hdr.xid); /* * Check if this is and async or sync operation. Send back the * appropriate response. */ if ((tcb_md = ISNSQHead(ISNS_CALLBACK_QUEUE)) != NULL) { if (msg->payload.errorCode == ISNS_NO_ERR) { SNSExecCallback (p_md, SUCCESS); } else { SNSExecCallback (p_md, msg->payload.errorCode); } } /* * Free up buffer resources being used by the queued request */ ISNSFreeBuffer((char *)p_req_md); } /* * release the response message buffer */ if (unparsed_md) ISNSFreeBuffer((char*)unparsed_md); } break; default: __LOG_WARNING("Received unknown message type %#x from %s", msg_type, dot_not_addr); break; } /* switch - msg_type */ } /******************************************************************** ********************************************************************/ void SNSReqTimeoutHdlr (void) { sns_request_timeout = 1; } /******************************************************************** * Function Name: SNSExecCallback * * Synopsis: void SNSExecCallback(); * * Description: SNSExecCallback executes a users callback. * * Return value: SUCCESS or ERROR. * ********************************************************************/ int SNSExecCallback (ISNS_Msg_Descp * p_md, int status) { uint32_t xid; ISNS_Msg_Descp *tcb_md; int rval; int display_debug; ISNS_ATTR_VALS_CB *attr_vals_cb; /* * Exec the appropriate callbacks. */ xid = 0; rval = ERROR; tcb_md = NULL; attr_vals_cb = NULL; if (p_md != NULL) { xid = p_md->msg.hdr.xid; tcb_md = ISNSDeqReq (ISNS_CALLBACK_QUEUE, (uint16_t)xid, 0); /* * Validate the callback. */ display_debug = 0; if (sns_cb_debug == 1) display_debug = (sns_cb_msg_filter != p_md->msg.hdr.type); else if ((sns_cb_debug == 2) || (sns_cb_debug == 3)) display_debug = (sns_cb_msg_filter == p_md->msg.hdr.type); switch (p_md->msg.hdr.type) { default: { /* * These are requests that never went to the primary, * so free the callback buffer. */ __DEBUG (sns_cb_debug, (Registration response:Unknown message)); if (tcb_md != NULL) rval = SUCCESS; } } } if (rval == SUCCESS) { tcb_md->msg.payload.rcb_req.func_val.qfunc = NULL; ISNSFreeBuffer ((char *) tcb_md); if (attr_vals_cb != NULL) { ISNSFreeBuffer ((char *) attr_vals_cb->attr_val_sptr); ISNSFreeBuffer ((char *) attr_vals_cb); } } return (rval); } /******************************************************************** ********************************************************************/ void SNSCheckTxQueue () { ISNS_Msg_Descp *p_md, *tcb_md; int timeout = 1; uint32_t xid; sns_request_timeout = 0; /* * Release all the message that may have been held in the tx queue. */ while ((p_md = ISNSQHead (SNS_TRANSACTION_QUEUE)) != NULL) { if (p_md->cb.ttl > 0) { /* retry sending all timeout out msgs */ #ifdef SNS_LINUX while ((p_md) && ((unsigned) p_md->cb.resp_timeout < (long double)time ((time_t*) 0) )) #else while ((p_md) && ((unsigned) p_md->cb.resp_timeout < tickGet ())) #endif { __DEBUG (isns_main_debug & 32, (%s % d % d), "iSNS retrying to forward msg, xid", p_md->msg.hdr.type, p_md->msg.hdr.xid); if (ISNSSendMsg2Server (&p_md->msg) == SUCCESS) #ifdef SNS_LINUX p_md->cb.resp_timeout = (long double)time ((time_t*) 0) + timeout; #else p_md->cb.resp_timeout = tickGet () + timeout; #endif /* decrement ttl */ p_md->cb.ttl--; p_md = p_md->cb.next; } if (timeout < 1) timeout = 1; return; } /* * Remove the message from the request queue. */ tcb_md = ISNSQHead (ISNS_CALLBACK_QUEUE); xid = p_md->msg.hdr.xid; p_md = ISNSDeqReq (SNS_TRANSACTION_QUEUE, (uint16_t)xid, 0); __LOG_WARNING ("retry timeout (msg id, xid)", p_md->msg.hdr.type, p_md->msg.hdr.xid); /* * Send a response back to the originator of the request */ p_md->msg.hdr.type = SNSParseTransOpcode (p_md->msg.hdr.type); p_md->msg.hdr.flags = SOIP_OPERATION_FAILURE; __DEBUG (isns_main_debug & 32, (%s %d), "Checking the transaction: ", xid); /* * Check if this is an async or sync operation. Send back the * appropriate response. */ if (tcb_md != NULL) { SNSExecCallback (p_md, ERROR); } /* release the message buffer after sending response */ ISNSFreeBuffer ((char *) p_md); } } /******************************************************************** ********************************************************************/ void SNSCheckInitTxQueue (ISNS_Msg_Descp * p_md) { SNS_FSM_Event event; sns_fsm_timeout = 0; event = SNS_HEARTBEAT_TIMEOUT; SNSProcFSM (event, NULL); } /******************************************************************** ********************************************************************/ static void regCallback(ISNS_Msg_Descp* p_md) { ISNS_Msg_Descp *reg_callback; /* * This message is small, so we only need to allocate * from the smaller buffer pool */ reg_callback = (ISNS_Msg_Descp*)ISNSAllocBuffer(sizeof(ISNS_Msg_Descp)); if (reg_callback == NULL) { __LOG_WARNING("regCallback out of buffs (size%i)", (int)sizeof(ISNS_Msg_Descp) ); return; } memcpy(&(reg_callback->cb), &(p_md->cb), sizeof(p_md->cb)); reg_callback->msg.hdr.xid = p_md->msg.hdr.xid; reg_callback->msg.hdr.type = p_md->msg.hdr.type; reg_callback->msg.hdr.msg_len = (uint16_t) sizeof (p_md->cb.callback_func); reg_callback->msg.hdr.flags = 0; reg_callback->msg.payload.rcb_req.func_val.rfunc = p_md->cb.callback_func.reg_func; ISNSEnqReq (ISNS_CALLBACK_QUEUE, reg_callback); } /******************************************************************** ********************************************************************/ static int ISNSdbExec( ISNS_Msg_Descp *p_md, ISNS_Msg_Descp *p_rsp_md) { int errorCode = ISNS_UNKNOWN_ERR; if (!p_md) return ( ISNS_UNKNOWN_ERR ); switch ( p_md->msg.hdr.type ) { case ISNS_SCN_REG_REQ: { errorCode = ISNS_RegisterSCN (p_md, &p_rsp_md->msg); break; } case ISNS_SCN_DEREG_REQ: { errorCode = ISNS_DeRegisterSCN (p_md, &p_rsp_md->msg); break; } case ISNS_REG_DDS_REQ: { errorCode = ISNSdbAddAttrDDS (p_md, &p_rsp_md->msg); break; } case ISNS_REG_DD_REQ: { errorCode = ISNSdbAddAttrDD ( p_md, &p_rsp_md->msg ); break; } case ISNS_SCN_EVENT: { errorCode = ISNS_Process_SCN_Event ( &p_md->msg ); break; } case ISNS_REG_DEV_ATTR_REQ: { errorCode = ISNSdbAddAttr (p_md, &p_rsp_md->msg); break; } case ISNS_DEREG_DEV_REQ: { errorCode = ISNSdbRemoveAttr( p_md, &p_rsp_md->msg); break; } case ISNS_DEREG_DDS_REQ: { errorCode = ISNSdbRemoveAttrDDS( p_md, &p_rsp_md->msg ); break; } case ISNS_DEREG_DD_REQ: { errorCode = ISNSdbRemoveAttrDD ( p_md, &p_rsp_md->msg ); break; } case ISNS_SCN: { errorCode = ISNS_Process_SCN(p_md, &p_rsp_md->msg); break; } case ISNS_DEV_ATTR_QRY_REQ: { errorCode = ISNSdbGetAttr ( p_md, &p_rsp_md->msg); break; } case ISNS_DEV_GET_NXT_REQ: { errorCode = ISNSGetNextAttr ( p_md, &p_rsp_md->msg); break; } case ISNS_DDS_GET_NXT_MEMBER_REQ: { errorCode = ISNSGetNextDDSMember ( p_md, &p_rsp_md->msg); break; } case ISNS_DD_GET_NXT_ISCSI_MEMBER_REQ: { errorCode = ISNSGetNextDDIscsiMember ( p_md, &p_rsp_md->msg ); break; } case ISNS_ENTITY_GET_NXT_PORTAL_REQ: { errorCode = ISNSGetNextEntityPortal ( p_md, &p_rsp_md->msg ); break; } case ISNS_ESI_RSP: { errorCode = ISNS_ProcessESI( p_md ); break; } default: { __DEBUG (1, (Error Unknown msg %d), p_md->msg.hdr.type); break; } } return ( errorCode ); } isns-2.1-01/isnsserver/src/iSNSdereg.c0000644000175000017500000013447110665040341016550 0ustar zobelzobel/************************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This file contains source code for registering objects with the * iSNS database. * */ #include "iSNS.h" #include "iSNSmsg.h" #include "iSNSList.h" #include "iSNSdb.h" #include "iSNSobjects.h" #include "iSNSdb.h" #include "iSNSreg.h" #include "iSNSquery.h" #include "iSNSscn.h" #include "iSNSresponse.h" #include "iSNStypes.h" #include "iSNScomm.h" #include "iSNSbuffer.h" #include "iSNStbl.h" #include "iSNSparse.h" #include "iSNSdebug.h" /* Global */ extern int isns_dereg_debug;; extern uint32_t isns_esi_interval; extern uint32_t *dlist_node; /*[MAX_DD_PER_LIST];*/ extern ISNS_LIST scn_callback_list; extern ISNS_Msg *p_scn_msg_buffer; extern ISNS_Msg *p_scn_all_msg_buffer; extern ISNS_Msg_Descp *p_scn_md; extern ISNS_Msg_Descp *p_rspMd; extern dbStats iSNS_stats; /* * static common variables for gdbm fetches * entry is for common registrations and queries * scn_entry is for state change notifications * opn_entry is for access control */ static SOIP_DB_Entry entry; /* top level fetches ONLY */ static SOIP_DB_Entry entry2; /* secondary fetches */ static SOIP_DB_Entry entry3; static SOIP_DB_Entry entry4; static SOIP_DB_Entry entry5; /********************************************************************* _SNSdbRemoveAttr This will call the more specific remove procedures. *********************************************************************/ int ISNSdbRemoveAttr ( ISNS_Msg_Descp * p_md, ISNS_Msg * p_rspmsg) { ISNS_Attr *p_attr; int status; int i; int deregEnitityFlag; int deregFCNodeFlag; int deregFCPortFlag; int deregPortalFlag; int deregISCSIFlag; ISNS_Attr *attr_indx[SNS_MAX_ATTRS]; ISNS_Attr *key_indx[SNS_MAX_ATTRS]; ISNS_Attr *src_attr; ISNSParseMsg( &p_md->msg, attr_indx, key_indx, &src_attr ); /* Search the operation Attributes */ deregEnitityFlag = FALSE; deregFCNodeFlag = FALSE; deregFCPortFlag = FALSE; deregISCSIFlag = FALSE; deregPortalFlag = FALSE; for (i = 0; i < MAX_PARSE_ATTRS && attr_indx[i]; i++) { p_attr = (ISNS_Attr *)(attr_indx[i]); switch (p_attr->tag) { case ISNS_ENTITY_PERIOD: case ISNS_ENTITY_ID: case ISNS_ENTITY_TYPE: case ISNS_PROT_VER: case ISNS_MGMT_IP: case ISNS_ESI_INTERVAL: case ISNS_ESI_PORT: case ISNS_TIMESTAMP: case ISNS_ENTITY_CERT: deregEnitityFlag = TRUE; break; case ISNS_PORTAL_IP: case ISNS_PORTAL_PORT: case ISNS_PORTAL_SYM_NAME: deregPortalFlag = TRUE; break; case ISNS_NODE_NAME: case ISNS_NODE_SYM_NAME: case ISNS_FC_NODE_IP: case ISNS_FC_NODE_IPA: case ISNS_FC_NODE_CERT: deregFCNodeFlag = TRUE; break; case ISNS_PORT_NAME: case ISNS_PORT_ID: case ISNS_PORT_TYPE: case ISNS_PORT_SYM_NAME: case ISNS_FABRIC_PORT_NAME: case ISNS_FC_HARD_ADDR: case ISNS_FC_PORT_IP: case ISNS_FC_COS: case ISNS_FC4_TYPE: case ISNS_FC4_DESC: case ISNS_FC4_FEATURE: deregFCPortFlag = TRUE; break; case ISNS_ISCSI_NODE_ID: case ISNS_ISCSI_TYPE: case ISNS_ISCSI_ALIAS: deregISCSIFlag = TRUE; break; default: break; } } status = ISNS_NO_ERR; if (deregEnitityFlag) status = SNSdbRemoveAttrEntity (attr_indx, src_attr, p_md, &p_rspMd->msg); if (deregPortalFlag && status == ISNS_NO_ERR) status = SNSdbRemoveAttrPortal (attr_indx, src_attr, p_md, &p_rspMd->msg); if (deregFCNodeFlag && status == ISNS_NO_ERR) status = SNSdbRemoveAttrNode (attr_indx, src_attr, p_md, &p_rspMd->msg); if (deregFCPortFlag && status == ISNS_NO_ERR) status = SNSdbRemoveAttrPort (attr_indx, src_attr, p_md, &p_rspMd->msg); if (deregISCSIFlag && status == ISNS_NO_ERR) status = SNSdbRemoveAttrISCSI (attr_indx, src_attr, p_md, &p_rspMd->msg); return status; } /********************************************************************* _SNSdbRemoveAttr_DDS_Entry Removes a DDS entry from the database. *********************************************************************/ int SNSdbRemoveAttrDDS_Entry (int id, ISNS_Attr * src_attr, ISNS_Msg * p_rspmsg) { SOIP_Dds *p_dds; SOIP_DDS_Key dds_key; int isActiveFlag; int rval; int count; ISNS_LIST_NODE *pnode; SOIP_DD_Key dd_key; SOIP_Dd *p_dd; ISNS_LIST_NODE *pnode2; int updated_dd_list_size; int memberRemovedFlag; __DEBUG (isns_dereg_debug &1, RemoveAttrDSS_Entry); dds_key.id = id; rval = read_DDSObject(id, &p_dds, &entry); if (rval != SUCCESS) return (rval); /* Remove DDS from DD's DDS List */ memberRemovedFlag = FALSE; memset(dlist_node, 0, MAX_DD_PER_LIST*sizeof(uint32_t)); updated_dd_list_size = 0; pnode = NULL; while ( (pnode=GetNextNode(&p_dds->dd_list, pnode)) ) { dd_key.id = *(uint32_t *)GetNodeData(pnode); rval = read_DDObject(dd_key.id, &p_dd, &entry2); if (rval != SUCCESS) return (rval); isActiveFlag = IsDDActive( dd_key.id, p_dds->id ); if (p_dd->activeFlag && !isActiveFlag) { dlist_node[updated_dd_list_size]=p_dd->id; updated_dd_list_size++; } if ((pnode2=FindNode(&p_dd->dds_list, (char *)&p_dds->id, sizeof(p_dds->id)))) { RemoveNode(&p_dd->dds_list, pnode2); } if ( !isActiveFlag ) p_dd->activeFlag = FALSE; memberRemovedFlag = TRUE; /* Store Entry */ write_DDObject(dd_key.id,entry2); } for ( count = 0; countdd_list); if ( delete_DDSObject (dds_key.id) != SUCCESS) { __DEBUG (isns_dereg_debug & 1, (DDS Removal failed, %u), dds_key.id); return (ISNS_UNKNOWN_ERR); } iSNS_stats.num_dds--; /* Is DD Still active */ return (ISNS_NO_ERR); } /********************************************************************* _SNSdbRemoveAttrDDS_Member Removes a DD from a DDS. *********************************************************************/ int SNSdbRemoveAttrDDS_Member (int id, ISNS_Attr **attr_indx, ISNS_Attr * src_attr, ISNS_Msg * p_rspmsg) { int kk; int rval; ISNS_Key *key; SOIP_Dds *p_dds; SOIP_DD_Key dds_key; ISNS_LIST_NODE *pnode; SOIP_DD_Key dd_key; SOIP_Dd *p_dd; int updated_dd_list_size; int memberRemovedFlag; __DEBUG (isns_dereg_debug &1, RemoveAttrDDS_Member); dds_key.id = id; rval = read_DDSObject(dds_key.id, &p_dds, &entry); if (rval != SUCCESS) return (rval); /* Remove DDS from DD's DDS List */ memberRemovedFlag = FALSE; memset(dlist_node, 0, MAX_DD_PER_LIST*sizeof(uint32_t)); updated_dd_list_size = 0; for (kk = 0; kk < MAX_PARSE_ATTRS && attr_indx[kk]; kk++) { key = (ISNS_Key *)(attr_indx[kk]); if (key->tag == ISNS_DD_ID) { if (ISNS_NO_ERR != Remove_dd_from_dds (p_dds, key->val.dd_id)) { return (ISNS_UNKNOWN_ERR); } dd_key.id = key->val.dd_id; rval = read_DDObject(dd_key.id, &p_dd, &entry2); if (rval != SUCCESS) return (rval); pnode=NULL; if ((pnode=FindNode(&p_dd->dds_list, (char *)&p_dds->id, sizeof(p_dds->id)))) { RemoveNode(&p_dd->dds_list, pnode); } memberRemovedFlag = TRUE; if (p_dd->activeFlag && !IsDDActive( p_dd->id, p_dds->id )) { dlist_node[updated_dd_list_size] = p_dd->id; p_dd->activeFlag = FALSE; } /* Store Entry */ write_DDObject(dd_key.id,entry2); } } for (kk = 0; kk msg, attr_indx, key_indx, &src_attr); rval = Check_Authorization (src_attr); if (rval != SUCCESS) { return (ISNS_AUTH_FAILED_ERR); } ddKeyIndex = ISNSFindTag (0, ISNS_DDS_ID, key_indx); keyRemovedFlag = FALSE; while (ddKeyIndex != -1) { key = (ISNS_Key *)(key_indx[ddKeyIndex]); if (attr_indx[0] != NULL) { if (ISNS_NO_ERR != (rval = SNSdbRemoveAttrDDS_Member (key->val.dd_id, attr_indx, (ISNS_Attr *)src_attr, p_rspmsg))) return (rval); } else if (ISNS_NO_ERR != (rval = SNSdbRemoveAttrDDS_Entry (key->val.dd_id, (ISNS_Attr *)src_attr, p_rspmsg))) { return (rval); } keyRemovedFlag = TRUE; ddKeyIndex = ISNSFindTag (ddKeyIndex + 1, ISNS_DDS_ID, key_indx); } if (keyRemovedFlag != TRUE) { __DEBUG (isns_dereg_debug & 1, (No DDS deregistered)); return (ISNS_UNKNOWN_ERR); } return (ISNS_NO_ERR); } /********************************************************************* _SNSdbRemoveAttrDD Removes one or more DD from the database. *********************************************************************/ int ISNSdbRemoveAttrDD ( ISNS_Msg_Descp * p_md, ISNS_Msg * p_rspmsg ) { int rval; ISNS_Key *key; int flag; int ddKeyIndex; ISNS_Attr *src_attr; ISNS_Attr *attr_indx[SNS_MAX_ATTRS]; ISNS_Attr *key_indx[SNS_MAX_ATTRS]; __DEBUG (isns_dereg_debug & 1, "Entering RemoveAttrDD()\n"); ISNSParseMsg( &p_md->msg, attr_indx, key_indx, &src_attr ); rval = Check_Authorization (src_attr); if (rval != SUCCESS) { return (ISNS_AUTH_FAILED_ERR); } ddKeyIndex = ISNSFindTag (0, ISNS_DD_ID, key_indx); flag = FALSE; while (ddKeyIndex != -1) { key = (ISNS_Key *)(key_indx[ddKeyIndex]); if (attr_indx[0] != NULL) { /* Remove DD MEMBER */ if (ISNS_NO_ERR != (rval = SNSdbRemoveDD_Member (key->val.dd_id, attr_indx, (ISNS_Attr *)src_attr, p_rspmsg))) { return (rval); } } else if (ISNS_NO_ERR != (rval = SNSdbRemoveDD_Entry (key->val.dd_id, (ISNS_Attr *)src_attr, p_rspmsg))) { return (rval); } flag = TRUE; /* Next round */ ddKeyIndex = ISNSFindTag (ddKeyIndex + 1, ISNS_DD_ID, key_indx); } if (FALSE == flag) { __DEBUG (isns_dereg_debug & 1, (Key not found)); return (ISNS_MSG_FMT_ERR); } return (ISNS_NO_ERR); } /********************************************************************* _SNSdbRemoveAttrEntityEntry Removes an entity from the database. *********************************************************************/ int ISNSdbRemoveAttrEntityEntry ( char *p_entity_id, ISNS_Attr * src_attr, ISNS_Msg * p_rspmsg ) { SOIP_Entity *p_entity; int rval; ISNS_LIST_NODE *pnode; __DEBUG ( isns_dereg_debug & 1, (Deregistering Entity %s),p_entity_id); /* read entity from database */ rval = read_EntityObject(p_entity_id, &p_entity, &entry); if (rval != SUCCESS) return rval; /* Remove Portals */ __DEBUG (isns_dereg_debug &1,Remove iportal_list); pnode = NULL; while ((pnode = GetNextNode(&p_entity->iportal_list, pnode))) { rval = SNSRemovePortalEntry (GetNodeData(pnode), NULL, p_rspmsg); } DeleteList( &p_entity->iportal_list ); /* Remove nodes */ if ( p_entity->eid_type == ENTITY_TYPE_IFCP ) { /* Remove IFCP Nodes */ __DEBUG (isns_dereg_debug &1,Remove ifcp_node_list); pnode = NULL; while ((pnode = GetNextNode(&p_entity->ifcp_node_list, pnode))) { rval = SNSRemoveIFCPNodeEntry (GetNodeData(pnode), NULL, p_rspmsg); } DeleteList( &p_entity->ifcp_node_list ); } else if (p_entity->eid_type == ENTITY_TYPE_ISCSI) { /* Remove ISCSI Nodes */ __DEBUG (isns_dereg_debug &1,Remove iscsi_node_list); pnode = NULL; while ((pnode = GetNextNode(&p_entity->iscsi_node_list, pnode))) { __DEBUG (isns_dereg_debug &1, Call SNSRemoveISCSINodeEntry); rval = SNSRemoveISCSINodeEntry (GetNodeData(pnode), NULL, p_rspmsg); if (rval) break; } DeleteList( &p_entity->iscsi_node_list ); } else { __DEBUG (isns_dereg_debug & 1, (Entity Type invalid %u), p_entity->eid_type); } RemoveCert (&p_entity->ptr_cert); /* Remove Entity In Entity Index Database */ delete_EntityidxObject(p_entity->entity_index); /* Remove Entity */ rval = delete_EntityObject(p_entity_id); iSNS_stats.num_entity--; __DEBUG (isns_dereg_debug &1,(Prepare response for: %s),p_entity_id); ISNSAppendKey (p_rspmsg, ISNS_ENTITY_ID, PAD4 (strlen (p_entity_id)), p_entity_id, 0); return ( rval ); } /********************************************************************* _SNSRemoveIFCPNodeEntry Removes an iFCP entry from the database. *********************************************************************/ int SNSRemoveIFCPNodeEntry (char *ifcp_node_key, ISNS_Attr * src_attr, ISNS_Msg * p_rspmsg) { int rval; char buffer[PORT_NAME_SIZE]; SOIP_DB_Node_Name db_node_name; SOIP_Entity *p_entity; SOIP_Fc_Node *p_fc_node; SOIP_Ifcp *p_ifcp_node; SOIP_Dd *p_dd; SOIP_DD_Key dd_key; ISNS_LIST_NODE *pnode; __DEBUG (isns_dereg_debug & 1, (Deregistering IFCP WWPN)); /* Validate the src attr has permission to delete the node If the src node is an iscsi node, verify that it is the same as the iscsi node. If the src is an entity verify that iscsi node belongs to the entity */ memset (buffer, 0, PORT_NAME_SIZE); __ISNS_COPY (buffer, sizeof(buffer), ifcp_node_key, PORT_NAME_SIZE); rval = read_FCPortObject((char *)buffer, &p_ifcp_node, &entry2); if (rval != SUCCESS) return rval; /* Remove from all DD */ pnode=NULL; while ((pnode=GetNextNode(&p_ifcp_node->dd_id_list, pnode))) { dd_key.id = *(uint32_t *) GetNodeData(pnode); rval = read_DDObject(dd_key.id, &p_dd, &entry5); if (rval != SUCCESS) return rval; if (ISNS_NO_ERR != Disable_DD_Member (p_dd, p_ifcp_node->port_name.v, ISNS_DD_IFCP_MEMBER)) return (ISNS_UNKNOWN_ERR); /* Store Entry */ rval = write_DDObject(dd_key.id,entry5); } /* Remove from the FC4 Types port list. */ /* Remove Node Name */ { char zero[ISNS_NODE_NAME_SIZE]; memset (zero, 0, sizeof (zero)); if (memcmp (p_ifcp_node->node_name.v, zero, ISNS_NODE_NAME_SIZE)) { /* Valid Node Name */ /* FC Node's IFCP Node List */ memset (&db_node_name, 0, sizeof (db_node_name)); __ISNS_COPY (db_node_name.v, sizeof(db_node_name.v), p_ifcp_node->node_name.v, ISNS_NODE_NAME_SIZE); db_node_name.v[8] = (char)SOIP_DB_Node_Id; read_FCNodeObject(db_node_name.v, &p_fc_node, &entry3); if (rval != SUCCESS) return rval; /* Remove IFCP Node from FC Node's List */ if ((pnode=FindNode(&p_fc_node->port_list, ifcp_node_key, PORT_NAME_SIZE))) { RemoveNode(&p_fc_node->port_list, pnode); } rval = write_FCNodeObject(db_node_name.v, entry3); if (IsEmptyList(&p_fc_node->port_list)) { SNSRemoveFCNodeEntry (p_fc_node->node_name.v, NULL); } } } RemoveCert (&p_ifcp_node->ptr_cert); /* Remove Port from entity's List */ rval = read_EntityObject(p_ifcp_node->entity_id.id, &p_entity, &entry4); if (rval != SUCCESS) return rval; pnode=NULL; if ((pnode=FindNode(&p_entity->ifcp_node_list, ifcp_node_key, PORT_NAME_SIZE))) { RemoveNode(&p_entity->ifcp_node_list, pnode); } rval = write_EntityObject(p_ifcp_node->entity_id.id, entry4); if (IsEmptyList(&p_entity->ifcp_node_list) && src_attr != NULL) { int more_esi_portals; SOIP_Portal *p_portal; /* Anymore Portals w/ ESI */ more_esi_portals = FALSE; pnode=NULL; while ((pnode=GetNextNode(&p_entity->iportal_list, pnode))) { /* Fetch Portal */ rval = read_PortalObject(GetNodeData(pnode), &p_portal, &entry3); if (rval != SUCCESS) return rval; if (p_portal->esi_interval != 0) { more_esi_portals = TRUE; break; } } if (!more_esi_portals) { /* remove entity */ ISNSdbRemoveAttrEntityEntry (p_entity->eid.id, NULL, NULL); } } /* Delete the iFCP Node */ DeleteList(&p_ifcp_node->dd_id_list); iSNS_stats.num_ifcp--; rval = delete_FCPortObject(buffer); if (rval != SUCCESS) { __LOG_ERROR ("ERROR: IFCP NODE Removal failed."); return (ERROR); } __DEBUG (isns_dereg_debug &1,(Prepare response for: %s),buffer); ISNSAppendKey (p_rspmsg, ISNS_PORT_NAME, ISNS_IFCP_NODE_NAME_SIZE, buffer, 0); return (ISNS_NO_ERR); } /********************************************************************* Removes one or more portals from the database. This will loop through all the keys and call helper functions. *********************************************************************/ int SNSdbRemoveAttrPortal (ISNS_Attr **key_indx, ISNS_Attr *src_attr, ISNS_Msg_Descp * p_md, ISNS_Msg * rspmsg) { int foundFlag; SOIP_Portal_Key db_portal; int ii; int portalIpIndex; int portalPortIndex; ISNS_Key *key; int saveIndex; int rval; __DEBUG (isns_dereg_debug &1, SSNSdbRemoveAttrPortal); foundFlag = FALSE; saveIndex = 0; portalIpIndex = -1; portalPortIndex = -1; while (1) { for (ii = saveIndex; ii < SNS_MAX_ATTRS && key_indx[ii] && (portalIpIndex == -1 || portalPortIndex == -1); ii++) { key = (ISNS_Key *)(key_indx[ii]); switch (key->tag) { case ISNS_PORTAL_IP: /* Check to see if we already had an IP */ if (portalIpIndex != -1) { __LOG_ERROR ("ERROR: PORTAL_IP tag found twice."); return (ERROR); } portalIpIndex = ii; break; case ISNS_PORTAL_PORT: /* Check to see if we already had a PORT */ if (portalPortIndex != -1) { __LOG_ERROR ("ERROR: PORTAL_PORT tag found twice."); return (ERROR); } portalPortIndex = ii; break; default: break; } } saveIndex = ii; if (portalIpIndex == -1 || portalPortIndex == -1) { break; } /* Call Remove Entry */ key = (ISNS_Key *)(key_indx[portalIpIndex]); __ISNS_COPY (db_portal.ip_addr.v, sizeof(db_portal.ip_addr.v), &key->val, ISNS_PORTAL_IP_SIZE); key = (ISNS_Key *)(key_indx[portalPortIndex]); db_portal.ip_port=key->val.ip_port; if (SUCCESS != (rval = SNSRemovePortalEntry (&db_portal, src_attr, rspmsg))) return (rval); foundFlag = TRUE; portalIpIndex = -1; portalPortIndex = -1; } if (!foundFlag) { __LOG_ERROR ("ERROR: Missing Keys."); return (ERROR); } return (ISNS_NO_ERR); } /********************************************************************* Removes one or more iFCP nodes from the database. This will loop through all the keys and call helper functions. *********************************************************************/ int SNSdbRemoveAttrPort (ISNS_Attr **key_indx, ISNS_Attr *src_attr, ISNS_Msg_Descp * p_md, ISNS_Msg * rspmsg) { ISNS_Key *key; int iFCPNodeKeyIndex; int rval; iFCPNodeKeyIndex = ISNSFindTag (0, ISNS_PORT_NAME, key_indx); if (iFCPNodeKeyIndex == -1) { __LOG_ERROR ("ERROR: iFCP Node key not found."); return (ERROR); } while (iFCPNodeKeyIndex != -1) { key = (ISNS_Key *)(key_indx[iFCPNodeKeyIndex]); if (SUCCESS != (rval = SNSRemoveIFCPNodeEntry ((char *)&key->val, (ISNS_Attr *)src_attr, rspmsg))) return (rval); iFCPNodeKeyIndex = ISNSFindTag (iFCPNodeKeyIndex + 1, ISNS_PORT_NAME, key_indx); } return (ISNS_NO_ERR); } /********************************************************************* Removes one or more iSCSI Nodes. This will loop through all the iSCSI node keys and call helper functions which will do all the brute work. *********************************************************************/ int SNSdbRemoveAttrISCSI (ISNS_Attr **key_indx, ISNS_Attr *src_attr, ISNS_Msg_Descp * p_md, ISNS_Msg * rspmsg) { ISNS_Key *key; int nodeKeyIndex; int rval; nodeKeyIndex = ISNSFindTag (0, ISNS_ISCSI_NODE_ID, key_indx); if (nodeKeyIndex == -1) { __DEBUG (isns_dereg_debug & 1, (Entity Key not found)); return (ISNS_MSG_FMT_ERR); } while (nodeKeyIndex != -1) { key = (ISNS_Key *)(key_indx[nodeKeyIndex]); if (SUCCESS != (rval = SNSRemoveISCSINodeEntry ((char *)&key->val, (ISNS_Attr *)src_attr, rspmsg))) return (rval); nodeKeyIndex = ISNSFindTag (nodeKeyIndex + 1, ISNS_ISCSI_NODE_ID, key_indx); } return (ISNS_NO_ERR); } /********************************************************************* Removes one or more FC Node from the database. The brute work is done in helper functions. *********************************************************************/ int SNSdbRemoveAttrNode (ISNS_Attr **key_indx, ISNS_Attr *src_attr, ISNS_Msg_Descp * p_md, ISNS_Msg * rspmsg) { ISNS_Key *key; int FCNodeKeyIndex; int rval; FCNodeKeyIndex = ISNSFindTag (0, ISNS_NODE_NAME, key_indx); if (FCNodeKeyIndex == -1) { __DEBUG (isns_dereg_debug & 1, (Entity Key not found)); return (ISNS_MSG_FMT_ERR); } while (FCNodeKeyIndex != -1) { key = (ISNS_Key *)(key_indx[FCNodeKeyIndex]); if (SUCCESS != (rval = SNSRemoveFCNodeEntry ((char *)&key->val, rspmsg))) return (rval); FCNodeKeyIndex = ISNSFindTag (FCNodeKeyIndex + 1, ISNS_NODE_NAME, key_indx); } return (ISNS_NO_ERR); } /********************************************************************* Removes one or more entities from the database. *********************************************************************/ int SNSdbRemoveAttrEntity (ISNS_Attr **key_indx, ISNS_Attr *src_attr, ISNS_Msg_Descp * p_md, ISNS_Msg * rspmsg) { ISNS_Key *key; int rval; int entityKeyIndex; char buffer[MAX_ENTITY_ID_SIZE] = { 0 }; rval = ERROR; entityKeyIndex = ISNSFindTag (0, ISNS_ENTITY_ID, key_indx); if (entityKeyIndex == -1) { __DEBUG (isns_dereg_debug & 1, (Entity Key not found)); return (ISNS_MSG_FMT_ERR); } while (entityKeyIndex != -1) { key = (ISNS_Key *)(key_indx[entityKeyIndex]); __ISNS_COPY (buffer, sizeof(buffer), &key->val, key->len); rval = ISNSdbRemoveAttrEntityEntry (buffer, src_attr, rspmsg); if (rval != ISNS_NO_ERR) return (rval); entityKeyIndex = ISNSFindTag (entityKeyIndex + 1, ISNS_ENTITY_ID, key_indx); } return (rval); } /********************************************************************* Removes an iSCSI Node from the database. *********************************************************************/ int SNSRemoveISCSINodeEntry (char *iscsi_node_key, ISNS_Attr * src_attr, ISNS_Msg * p_rspmsg) { int rval; int scn_bitmap; SOIP_Iscsi *p_node; SOIP_Entity *p_entity; SOIP_Dd *p_dd; SOIP_DD_Key dd_key; ISNS_LIST_NODE *pnode; __DEBUG (isns_dereg_debug & 1, (Deregistering iSCSI Node:%s),iscsi_node_key); memset(p_scn_all_msg_buffer, 0, sizeof(ISNS_Msg)); p_scn_all_msg_buffer->hdr.type = ISNS_SCN; scn_bitmap = 0; rval = read_ISCSIObject(iscsi_node_key, &p_node, &entry2); if (rval != SUCCESS) return rval; /* Validate the src attr has permission to delete the node If the src node is an iscsi node, verify that it is the same as the iscsi node. If the src is an entity verify that iscsi node belongs to the entity */ RemoveCert (&p_node->ptr_cert); /* Remove ISCSI Node from DD */ pnode=NULL; while ((pnode=GetNextNode(&p_node->dd_id_list, pnode))) { dd_key.id = *(uint32_t *)GetNodeData(pnode); rval = read_DDObject(dd_key.id, &p_dd, &entry5); if (rval == SUCCESS) { Disable_DD_Member (p_dd, p_node->id.v, ISNS_DD_ISCSI_MEMBER); /* Store Entry */ write_DDObject(dd_key.id, entry5); } } /* read entity from database */ rval = read_EntityObject(p_node->entity_id.id, &p_entity, &entry4); if (rval != SUCCESS) return ERROR; /* Remove ISCSI Node from ENTITY */ if ((pnode = FindNode(&p_entity->iscsi_node_list, iscsi_node_key, PAD4(strlen(iscsi_node_key))))) { RemoveNode(&p_entity->iscsi_node_list, pnode); } /* update entity in database by doing a write */ rval = write_EntityObject(p_node->entity_id.id, entry4); /* Delete the iSCSI Node */ delete_ISCSIidxObject(p_node->iscsi_index); RemoveCert (&p_node->ptr_cert); DeleteList(&p_node->dd_id_list); ISNSAppendKey( p_scn_all_msg_buffer, ISNS_ISCSI_NODE_ID, PAD4(strlen(iscsi_node_key)),iscsi_node_key, 0); send_iscsi_scn_to_members ( NULL, iscsi_node_key, p_scn_all_msg_buffer, ISNS_SCN_OBJ_REMOVED ); rval = delete_ISCSIObject(iscsi_node_key); if (rval != SUCCESS) { __DEBUG (isns_dereg_debug & 1, (ISCSI NODE Removal failed %s), iscsi_node_key); return (ERROR); } iSNS_stats.num_iscsi--; return ( ISNS_NO_ERR ); } /********************************************************************* Removes an FC Node entry from the database. *********************************************************************/ int SNSRemoveFCNodeEntry (char *p_key, ISNS_Msg * p_rspmsg) { int rval; SOIP_Fc_Node *p_fc_node; SOIP_DB_Node_Name db_node_name; ISNS_LIST_NODE *pnode; ISNS_DBKey read_key; __DEBUG (isns_dereg_debug & 1, (Deregistering FC Node)); memset (&db_node_name, 0, sizeof (db_node_name)); __ISNS_COPY (db_node_name.v, sizeof(db_node_name.v), p_key, ISNS_NODE_NAME_SIZE); db_node_name.v[8] = (char)SOIP_DB_Node_Id; rval = read_FCNodeObject(db_node_name.v, &p_fc_node, &entry4); if (rval != SUCCESS) return rval; pnode=NULL; while ((pnode=GetNextNode(&p_fc_node->port_list, pnode))) { strcpy(read_key.val.node_key.v,GetNodeData(pnode)); rval = read_FCNodeObject(GetNodeData(pnode), &p_fc_node, &entry5); if (rval != SUCCESS) return rval; memset (p_fc_node->node_name.v, 0, ISNS_NODE_NAME_SIZE); rval = write_FCNodeObject(db_node_name.v, entry5); } __ISNS_COPY (db_node_name.v, sizeof(db_node_name.v), p_key, ISNS_NODE_NAME_SIZE); db_node_name.v[8] = (char)SOIP_DB_Node_Id; delete_FCNodeObject(db_node_name.v); __DEBUG (isns_dereg_debug &1,(Prepare response for: %s),p_key); ISNSAppendKey (p_rspmsg, ISNS_NODE_NAME, ISNS_NODE_NAME_SIZE, p_key, 0); return (ISNS_NO_ERR); } /********************************************************************* Removes a portal entry from the database. *********************************************************************/ int SNSRemovePortalEntry (SOIP_Portal_Key *portal_key, ISNS_Attr * src_attr, ISNS_Msg * p_rspmsg) { SOIP_Portal *p_portal; SOIP_Entity *p_entity; int rval; ISNS_LIST_NODE *pnode; ISNS_LIST_NODE *pnode2; PORTAL_LIST_ENTRY portalListEntry; char *p_iscsi_name; __DEBUG (isns_dereg_debug & 1, (Deregistering Portal)); memset(p_scn_all_msg_buffer, 0, sizeof(ISNS_Msg)); p_scn_all_msg_buffer->hdr.type = ISNS_SCN; rval = read_PortalObject(portal_key, &p_portal, &entry2); if (rval != SUCCESS) { __DEBUG(isns_dereg_debug &1, Portal not found:%i,rval); return rval; } /* Validate the src attr has permission to delete the node If the src node is an iscsi node, verify that it is the same as the iscsi node. If the src is an entity verify that iscsi node belongs to the entity */ __DEBUG (isns_dereg_debug &1,(Remove Cert)); RemoveCert (&p_portal->ptr_cert); delete_PortalidxObject(p_portal->portal_index); iSNS_stats.num_portals--; rval = read_EntityObject(p_portal->entity_id.id, &p_entity, &entry4); if (rval != SUCCESS) return rval; /* Remove Portals */ __ISNS_COPY (&portalListEntry.portal_ip_port, sizeof(portalListEntry.portal_ip_port), portal_key, sizeof(portalListEntry.portal_ip_port)); portalListEntry.portal_idx = p_portal->portal_index; pnode = NULL; if ((pnode=FindNode(&p_entity->iportal_list, (char *)&portalListEntry, sizeof (portalListEntry)))) { RemoveNode(&p_entity->iportal_list, pnode); } rval = write_EntityObject(p_portal->entity_id.id, entry4); /* Send detailed SCN */ pnode2 = NULL; while ( (pnode2 = GetNextNode( &p_entity->iscsi_node_list, pnode2)) ) { p_iscsi_name = (char *) GetNodeData( pnode2 ); send_iscsi_scn_to_members ( NULL, p_iscsi_name, p_scn_all_msg_buffer, ISNS_SCN_OBJ_REMOVED ); } rval = delete_PortalObject(portal_key); if ( rval != SUCCESS) __LOG_ERROR ("ERROR: Portal DEREG Failed."); return (rval); } /********************************************************************* _Remove_dd_from_dds Remove a DD from the DDS's DD List. *********************************************************************/ int Remove_dd_from_dds ( SOIP_Dds * p_dds, int id ) { ISNS_LIST_NODE *pnode; if ((pnode=FindNode(&p_dds->dd_list, (char *)&id, sizeof(id)))) { RemoveNode(&p_dds->dd_list, pnode); } return (ISNS_NO_ERR); } /********************************************************************* _SNSdbRemoveDD_Entry PURPOSE: This will remove a DD ID from the database. PARAMETER(S): 1. DD ID. 2. SRC ATTR. RETURN: Error Code. *********************************************************************/ int SNSdbRemoveDD_Entry ( int id, ISNS_Attr * src_attr, ISNS_Msg * p_rspmsg ) { int rval; SOIP_Dd *p_dd; SOIP_DD_Key dd_key; SOIP_Dd_Member *p_member; ISNS_LIST_NODE *pnode; int memberRemovedFlag; SOIP_Dds *p_dds; SOIP_DD_Key dds_key; ISNS_LIST_NODE *pnode2; dd_key.id = id; rval = read_DDObject(dd_key.id, &p_dd, &entry); if (rval != SUCCESS) return rval; /* Remove DD Members */ pnode = NULL; memberRemovedFlag = FALSE; while ( (pnode = GetNextNode(&p_dd->member_list, NULL)) ) { p_member=(SOIP_Dd_Member *) GetNodeData(pnode); if ( p_member->type != 0 && p_member->status != ISNS_DD_MEMBER_DISABLE ) { char member_name[256]; memset (member_name, 0, sizeof (member_name)); switch (p_member->type) { case ISNS_DD_ISCSI_MEMBER: strncpy (member_name, p_member->node_id, sizeof(member_name)); if (ISNS_NO_ERR != Remove_DD_from_ISCSI_Node (p_dd, p_member->node_id)) { return ( ISNS_UNKNOWN_ERR ); } memberRemovedFlag = TRUE; break; case ISNS_DD_IFCP_MEMBER: __ISNS_COPY (member_name, sizeof(member_name), p_member->node_id, ISNS_PORT_NAME_SIZE); if (ISNS_NO_ERR != Remove_DD_from_IFCP_Node (p_dd->id, p_member->node_id)) { return ( ISNS_UNKNOWN_ERR ); } memberRemovedFlag = TRUE; break; default: __LOG_ERROR ("Error, dd member type=%u incorrect.", p_member->type); /* return (ISNS_MSG_FMT_ERR); */ break; } } RemoveNode( &p_dd->member_list, pnode ); } pnode = NULL; while ( (pnode = GetNextNode( &p_dd->dds_list, pnode )) ) { dds_key.id = *(uint32_t *) GetNodeData(pnode); rval = read_DDSObject(dds_key.id, &p_dds, &entry2); if (rval != SUCCESS) return rval; if ((pnode2 = FindNode(&p_dds->dd_list, (char *)&p_dd->id, sizeof(p_dd->id)))) { RemoveNode(&p_dds->dd_list, pnode2); } /* Store Entry */ rval = write_DDSObject(dds_key.id, entry2); } DeleteList( &p_dd->member_list ); DeleteList( &p_dd->dds_list ); if ( delete_DDObject(dd_key.id) != SUCCESS ) { __DEBUG ( isns_dereg_debug & 1, (DD Removal failed %u), dd_key.id ); return ( ERROR ); } iSNS_stats.num_dd--; return ( ISNS_NO_ERR ); } /********************************************************************* _SNSdbRemoveDD_Member Removes a member from a DD. *********************************************************************/ int SNSdbRemoveDD_Member (int id, ISNS_Attr **attr_indx, ISNS_Attr * src_attr, ISNS_Msg * p_rspmsg) { int ii, rval; ISNS_Attr *p_attr; SOIP_Dd *p_dd; SOIP_DD_Key dd_key; int removeMemberFlag; __DEBUG (isns_dereg_debug & 1, "Entering RemoveDD_Member()\n"); dd_key.id = id; rval = read_DDObject(dd_key.id, &p_dd, &entry); if (rval !=SUCCESS) return rval; /* Prepare the SCN */ memset(p_scn_all_msg_buffer, 0, sizeof(ISNS_Msg)); p_scn_all_msg_buffer->hdr.type = ISNS_SCN; /* Remove the DD_ID Members */ removeMemberFlag = FALSE; for (ii = 0; ii < SNS_MAX_ATTRS && attr_indx[ii]; ii++) { p_attr = (ISNS_Attr *)(attr_indx[ii]); switch (p_attr->tag) { case ISNS_DD_ISCSI_MEMBER: Remove_DD_from_ISCSI_Node (p_dd, (char *)&p_attr->val); Remove_DD_Member (p_dd, (char *)&p_attr->val, ISNS_DD_ISCSI_MEMBER); ISNSAppendKey( p_scn_all_msg_buffer, ISNS_DD_ID, ISNS_DD_ID_SIZE, NULL, p_dd->id); ISNSAppendKey( p_scn_all_msg_buffer, ISNS_DD_ISCSI_MEMBER, PAD4(strlen((char *)&p_attr->val)), (char *)&p_attr->val, 0); ISNSAppendKey( p_scn_all_msg_buffer, ISNS_ISCSI_SCN_BITMAP, ISNS_SCN_BITMAP_SIZE, NULL, ISNS_SCN_MEMBER_REMOVED); removeMemberFlag = TRUE; send_iscsi_scn_to_members ( NULL,(char *)&p_attr->val, p_scn_all_msg_buffer, ISNS_SCN_OBJ_REMOVED ); break; case ISNS_DD_IFCP_MEMBER: if (ISNS_NO_ERR != Remove_DD_from_IFCP_Node (p_dd->id, (char *)&p_attr->val)) { return (ERROR); } Remove_DD_Member (p_dd, (char *)&p_attr->val, ISNS_DD_IFCP_MEMBER); ISNSAppendKey( p_scn_all_msg_buffer, ISNS_DD_ID, ISNS_DD_ID_SIZE, NULL, p_dd->id); ISNSAppendKey( p_scn_all_msg_buffer, ISNS_DD_IFCP_MEMBER, PAD4(strlen((char *)&p_attr->val)), (char *)&p_attr->val, 0); ISNSAppendKey( p_scn_all_msg_buffer, ISNS_IFCP_SCN_BITMAP, ISNS_SCN_BITMAP_SIZE, NULL, ISNS_SCN_MEMBER_REMOVED); send_iscsi_scn_to_members ( NULL, (char *)&p_attr->val, p_scn_all_msg_buffer, ISNS_SCN_OBJ_REMOVED ); removeMemberFlag = TRUE; break; default: return (ERROR); break; } } /* Store Entry */ write_DDObject(dd_key.id, entry); return ( ISNS_NO_ERR ); } /********************************************************************* _Remove_DD_Member Removes a member from a DD. Returns ISNS_NO_ERR if successful. *********************************************************************/ int Remove_DD_Member (SOIP_Dd *p_dd, char *ptr, uint32_t type) { ISNS_LIST_NODE *pnode; SOIP_Dd_Member *p_member; pnode=NULL; while ((pnode=GetNextNode(&p_dd->member_list, pnode))) { p_member=(SOIP_Dd_Member *)GetNodeData(pnode); if (p_member->type!=type) /* Type doesn't match */ continue; if (p_member->type==ISNS_DD_IFCP_MEMBER && memcmp(p_member->node_id, ptr, PORT_NAME_SIZE)) /* Comparing port name doesn't match */ continue; if (strcmp(p_member->node_id, ptr)) /* Comparing FCIP or iSCSI names don't match */ continue; RemoveNode(&p_dd->member_list, pnode); break; } return (ISNS_NO_ERR); } /********************************************************************* _Remove_DD_from_ISCSI_Node Remove the DD from an iSCSI Node. *********************************************************************/ int Remove_DD_from_ISCSI_Node (SOIP_Dd *p_dd, char *p_node_name) { SOIP_Iscsi *p_node; SOIP_DB_Entry lentry; SOIP_DB_Entry lentry2; ISNS_LIST_NODE *p_lnode; SOIP_Dd *p_dd2; int activeFlag; SOIP_DD_Key dd_key; int rval; rval = read_ISCSIObject(p_node_name, &p_node, &lentry); if (rval != SUCCESS) return rval; if ((p_lnode=FindNode(&p_node->dd_id_list, (char *)&p_dd->id, sizeof(p_dd->id)))) { RemoveNode(&p_node->dd_id_list, p_lnode); /* Scan all DD, check for at least one active DD */ p_lnode = NULL; activeFlag = FALSE; while ( p_node->activeFlag && (p_lnode = GetNextNode(&p_node->dd_id_list, p_lnode)) ) { uint32_t id; id = *(uint32_t *)GetNodeData(p_lnode); if (id == p_dd->id) continue; dd_key.id = id; rval = read_DDObject(dd_key.id, &p_dd2, &lentry2); if (rval == SUCCESS) if (p_dd2->activeFlag) { activeFlag = TRUE; } } p_node->activeFlag = activeFlag; } write_ISCSIObject(p_node_name, lentry); return (ISNS_NO_ERR); } /********************************************************************* _Remove_DD_from_IFCP_Node Removes the DD from the iFCP's DD list. *********************************************************************/ int Remove_DD_from_IFCP_Node (int id, char *p_node_name) { SOIP_Ifcp *p_node; SOIP_DB_Entry lentry; ISNS_LIST_NODE *p_lnode; int rval; rval = read_FCPortObject(p_node_name, &p_node, &lentry); if (rval != SUCCESS) return rval; if ((p_lnode=FindNode(&p_node->dd_id_list, (char *)&id, sizeof(id)))) { RemoveNode(&p_node->dd_id_list, p_lnode); } write_FCPortObject(p_node_name, lentry); return (ISNS_NO_ERR); } /********************************************************************* _Disable_DD_Member Disables a DD member. This gets called when a node is deleted. *********************************************************************/ int Disable_DD_Member (SOIP_Dd * p_dd, char *ptr, uint32_t type) { ISNS_LIST_NODE *pnode; SOIP_Dd_Member *p_member; __DEBUG (isns_dereg_debug &1, Disable_DD_Member); pnode=NULL; while ((pnode=GetNextNode(&p_dd->member_list, pnode))) { p_member=(SOIP_Dd_Member *)GetNodeData(pnode); if (p_member->type != type) { __DEBUG (isns_dereg_debug &1, p_member->type:%i not equal to type:%i,p_member->type,type); continue; } if (p_member->type == ISNS_DD_ISCSI_MEMBER && 0 != strcmp (p_member->node_id, ptr)) { __DEBUG (isns_dereg_debug &1, p_member->type not equal to type); continue; } if (p_member->type == ISNS_DD_IFCP_MEMBER && 0 != memcmp (p_member->node_id, ptr, ISNS_PORT_NAME_SIZE)) { continue; } /* Match found */ p_member->status = ISNS_DD_MEMBER_DISABLE; return (ISNS_NO_ERR); } __DEBUG (isns_dereg_debug &1, Disable_DD_Member return error); return (ERROR); } /********************************************************************* Deregisters a SCN. *********************************************************************/ int ISNS_DeRegisterSCN ( ISNS_Msg_Descp * p_md, ISNS_Msg * rspmsg ) { int ii; int iscsiKeyIndex; int entityKeyIndex; int ifcpKeyIndex; int rval; ISNS_Key *key; SOIP_Iscsi *p_node; SOIP_ISCSI_Node_Id db_node_name; SOIP_Entity *p_entity; SOIP_Ifcp *p_ifcp_node; ISNS_Attr *src_attr; ISNS_Attr *attr_indx[SNS_MAX_ATTRS]; ISNS_Attr *key_indx[SNS_MAX_ATTRS]; rval = ISNS_UNKNOWN_ERR; ISNSParseMsg( &p_md->msg, attr_indx, key_indx, &src_attr ); /* Scan the keys */ iscsiKeyIndex = -1; ifcpKeyIndex = -1; entityKeyIndex = -1; for (ii = 0; ii < MAX_PARSE_ATTRS && key_indx[ii]; ii++) { key = (ISNS_Key *)(key_indx[ii]); switch (key->tag) { case ISNS_ISCSI_NODE_ID: iscsiKeyIndex = ii; break; case ISNS_ENTITY_ID: entityKeyIndex = ii; break; case ISNS_PORT_NAME: ifcpKeyIndex = ii; break; default: /* Error condition */ break; } } if (iscsiKeyIndex != -1) { key = (ISNS_Key *)(key_indx[iscsiKeyIndex]); /* Fetch the node */ memset (&db_node_name, 0, sizeof (db_node_name)); __ISNS_COPY (db_node_name.v, sizeof(db_node_name.v), &key->val, key->len); rval = read_ISCSIObject(db_node_name.v, &p_node, &entry); if (rval != SUCCESS) return rval; p_node->scn_bitmap=0; p_node->scn_sockfd = 0; /* Store the node */ write_ISCSIObject(db_node_name.v, entry); } else if (ifcpKeyIndex != -1) { key = (ISNS_Key *)(key_indx[ifcpKeyIndex]); rval = read_FCPortObject((char *)&key->val, &p_ifcp_node, &entry); if (rval != SUCCESS) return rval; p_ifcp_node->scn_bitmap=0; p_ifcp_node->scn_sockfd = 0; /* Store the node */ rval = write_FCPortObject((char *)&key->val, entry); return (ISNS_NO_ERR); } else if (entityKeyIndex != -1) { key = (ISNS_Key *)(key_indx[entityKeyIndex]); /* Fetch entity from hash */ if (ISNS_NO_ERR != read_EntityObject ((char *) &key->val, &p_entity, &entry)) { return (ISNS_NO_SUCH_ENTRY_ERR); } p_entity->scn_bitmap=0; p_entity->scn_sockfd = 0; /* Store the node */ write_EntityObject(p_entity->eid.id, entry); return (ISNS_NO_ERR); } else { __DEBUG (isns_dereg_debug & 1, (No valid key in SCN request)); return (ISNS_MSG_FMT_ERR); } return (ISNS_NO_ERR); } /********************************************************************* _RemoveCert Deallocates the cert space. *********************************************************************/ int RemoveCert ( void **ptr ) { if (*ptr) { ISNSFreeBuffer (*ptr); *ptr = NULL; } return (SUCCESS); } /************************************************** Cycles through the entities. If the entity's period has expired, deregister. **************************************************/ void ISNS_CheckEntities (void) { ISNS_DBKey key = { 0 }; SOIP_Entity *p_entity; time_t t; int secs; /* Get first entity id */ key.tag = ENTITY_ID_KEY; key.len = 0; /* Get Time */ secs = time (&t); while (SNSdbGetNextOfKey (&key) == SUCCESS) { /* Fetch entity from hash */ if (ISNS_NO_ERR != read_EntityObject (key.val.entity_key.id, &p_entity, &entry)) { return; } if (p_entity->period == 0) continue; if (secs<(int)p_entity->period+(int)p_entity->timestamp.t_time) continue; /* Period has expired, deregister */ ISNSdbRemoveAttrEntityEntry (p_entity->eid.id, NULL, NULL); } } isns-2.1-01/isnsserver/src/getarg.c0000644000175000017500000001532010665040341016165 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include /* for EOF */ #include /* for strchr() */ /* static (global) variables that are specified as exported by getopt() */ char *optarg = NULL; /* pointer to the start of the option argument */ int optind = 1; /* number of the next argv[] to be evaluated */ int opterr = 1; /* non-zero if a question mark should be returned when a non-valid option character is detected */ /* handle possible future character set concerns by putting this in a macro */ #define _next_char(string) (char)(*(string+1)) int getopt(int argc, char *argv[], char *opstring) { static char *pIndexPosition = NULL; /* place inside current argv string */ char *pArgString = NULL; /* where to start from next */ char *pOptString; /* the string in our program */ if (pIndexPosition != NULL) { /* we last left off inside an argv string */ if (*(++pIndexPosition)) { /* there is more to come in the most recent argv */ pArgString = pIndexPosition; } } if (pArgString == NULL) { /* we didn't leave off in the middle of an argv string */ if (optind >= argc) { /* more command-line arguments than the argument count */ pIndexPosition = NULL; /* not in the middle of anything */ return EOF; /* used up all command-line arguments */ } /*--------------------------------------------------------------------- * If the next argv[] is not an option, there can be no more options. *-------------------------------------------------------------------*/ pArgString = argv[optind++]; /* set this to the next argument ptr */ if (('/' != *pArgString) && /* doesn't start with a slash or a dash? */ ('-' != *pArgString)) { --optind; /* point to current arg once we're done */ optarg = NULL; /* no argument follows the option */ pIndexPosition = NULL; /* not in the middle of anything */ return EOF; /* used up all the command-line flags */ } /* check for special end-of-flags markers */ if ((strcmp(pArgString, "-") == 0) || (strcmp(pArgString, "--") == 0)) { optarg = NULL; /* no argument follows the option */ pIndexPosition = NULL; /* not in the middle of anything */ return EOF; /* encountered the special flag */ } pArgString++; /* look past the / or - */ } if (':' == *pArgString) { /* is it a colon? */ /*--------------------------------------------------------------------- * Rare case: if opterr is non-zero, return a question mark; * otherwise, just return the colon we're on. *-------------------------------------------------------------------*/ return (opterr ? (int)'?' : (int)':'); } else if ((pOptString = strchr(opstring, *pArgString)) == 0) { /*--------------------------------------------------------------------- * The letter on the command-line wasn't any good. *-------------------------------------------------------------------*/ optarg = NULL; /* no argument follows the option */ pIndexPosition = NULL; /* not in the middle of anything */ return (opterr ? (int)'?' : (int)*pArgString); } else { /*--------------------------------------------------------------------- * The letter on the command-line matches one we expect to see *-------------------------------------------------------------------*/ if (':' == _next_char(pOptString)) { /* is the next letter a colon? */ /* It is a colon. Look for an argument string. */ if ('\0' != _next_char(pArgString)) { /* argument in this argv? */ optarg = &pArgString[1]; /* Yes, it is */ } else { /*------------------------------------------------------------- * The argument string must be in the next argv. * But, what if there is none (bad input from the user)? * In that case, return the letter, and optarg as NULL. *-----------------------------------------------------------*/ if (optind < argc) optarg = argv[optind++]; else { optarg = NULL; return (opterr ? (int)'?' : (int)*pArgString); } } pIndexPosition = NULL; /* not in the middle of anything */ } else { /* it's not a colon, so just return the letter */ optarg = NULL; /* no argument follows the option */ pIndexPosition = pArgString; /* point to the letter we're on */ } return (int)*pArgString; /* return the letter that matched */ } } isns-2.1-01/isnsserver/src/iSNSdb.c0000644000175000017500000007746010665040341016053 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This file contains source code for managing the * iSNS database. * */ #include "iSNS.h" #include "iSNSdb.h" //#include "ndb.h" #include #include "iSNStypes.h" #include "iSNSmsg.h" #include "iSNSbuffer.h" #include "iSNStbl.h" #include "iSNSList.h" #include "iSNSdebug.h" //#define ndb_store_sns(a,b,c,d) ndb_store(dbfp,b,c,d) #define ndb_fetch(a,b) gdbm_fetch(dbfp[a],b) #define ndb_fetch_sns(a,b,c) gdbm_fetch(dbfp[a],b); memcpy(c,d.dptr,d.dsize) #define ndb_store_sns(a,b,c,d) gdbm_store(dbfp[a],b,c,d) #define ndb_delete(a,b) gdbm_delete(dbfp[a],b) #define ndb_nextkey(a,b) gdbm_nextkey (dbfp[a],b) #define ndb_firstkey(a) gdbm_firstkey (dbfp[a]) /* Global */ extern int isns_db_debug; /* * SoIP service Database file descriptor */ //static NDB_FILE dbfp; static GDBM_FILE dbfp[25]; /* * GDBM errno */ //extern ndb_error ndb_errno; extern int gdbm_errno; /* * static common variables for gdbm fetches * entry is for common registrations and queries * scn_entry is for state change notifications * opn_entry is for access control */ uint32_t *dlist_src; /*[MAX_DD_PER_LIST];*/ uint32_t *dlist_node; /*[MAX_DD_PER_LIST];*/ SOIP_Dd_Member *ddmem; /* [100]; */ ISNS_LIST scn_callback_list; ISNS_Msg *p_scn_msg_buffer; ISNS_Msg *p_scn_all_msg_buffer; ISNS_Msg_Descp *p_scn_md; ISNS_Msg_Descp *p_rspMd; dbStats iSNS_stats; void ISNSExceptionHdlr1(char * string); void ISNSExceptionHdlr2(char * string); void ISNSExceptionHdlr3(char * string); void ISNSExceptionHdlr4(char * string); void ISNSExceptionHdlr5(char * string); void ISNSExceptionHdlr6(char * string); void ISNSExceptionHdlr7(char * string); void ISNSExceptionHdlr8(char * string); void ISNSExceptionHdlr9(char * string); void ISNSExceptionHdlr10(char * string); void ISNSExceptionHdlr11(char * string); void ISNSExceptionHdlr12(char * string); /********************************************************************* Read Entry from Database referenced by key *********************************************************************/ int ISNSdbRead (ISNS_DBKey *key, SOIP_DB_Entry *entry) { datum k; datum d; k.dsize = 0; d.dsize = sizeof (SOIP_DB_Entry); switch (key->tag) { case DDS_ID_KEY: __DEBUG (isns_db_debug & 1,(read DDS %i),key->val.dds_key.id); k.dptr = (char *)&key->val.dds_key.id; k.dsize = DDS_KEY_SIZE; d = ndb_fetch_sns (DDS_ID_KEY, k, (char *)entry); if (d.dptr == NULL) { __DEBUG (isns_db_debug & 1, (read failed DDS %u),key->val.dds_key.id); return (ISNS_NO_SUCH_ENTRY_ERR); } if (entry->data_type != DDS_ID_KEY) return (ISNS_UNKNOWN_ERR); entry->data.dds.dd_list.p_entry = &entry->data.dds; break; case DD_ID_KEY: __DEBUG (isns_db_debug & 1,(read DD %i),key->val.dd_key.id); k.dptr = (char *)&key->val.dd_key.id; k.dsize = DD_KEY_SIZE; d = ndb_fetch_sns (DD_ID_KEY, k, (char *)entry); if (d.dptr == NULL) { __DEBUG (isns_db_debug & 1, (read failed DD %u),key->val.dd_key.id); return (ISNS_NO_SUCH_ENTRY_ERR); } if (entry->data_type != DD_ID_KEY) return (ISNS_UNKNOWN_ERR); entry->data.dd.member_list.p_entry = &entry->data.dd; entry->data.dd.dds_list.p_entry = &entry->data.dd; __DEBUG (isns_db_debug &1,read dd - dds list_id:%i,entry->data.dd.dds_list.list_id); break; case ISCSI_ID_KEY: __DEBUG (isns_db_debug & 1,(read ISCSI node %s),key->val.node_key.v); k.dptr = (char *)key->val.node_key.v; k.dsize = strlen(key->val.node_key.v); d = ndb_fetch_sns (ISCSI_ID_KEY, k, (char *)entry); if (d.dptr == NULL) { __DEBUG (isns_db_debug & 1, (read failed ISCSI node %s),key->val.node_key.v); return (ISNS_NO_SUCH_ENTRY_ERR); } if (entry->data_type != ISCSI_ID_KEY) return (ISNS_UNKNOWN_ERR); entry->data.scsi_node.dd_id_list.p_entry = &entry->data.scsi_node; break; case ENTITY_ID_KEY: __DEBUG (isns_db_debug & 1,(read ENTITY node %s),key->val.entity_key.id); k.dptr = (char *)key->val.entity_key.id; k.dsize = strlen(key->val.entity_key.id); d = ndb_fetch_sns (ENTITY_ID_KEY, k, (char *)entry); if (d.dptr == NULL) { __DEBUG (isns_db_debug & 1, (read failed ENTITY node %s),key->val.entity_key.id); return (ISNS_NO_SUCH_ENTRY_ERR); } if (entry->data_type != ENTITY_ID_KEY) { __DEBUG (isns_db_debug & 1, (read failed ENTITY node - invalid data in database %s),key->val.entity_key.id); return (ISNS_UNKNOWN_ERR); } entry->data.entity.iportal_list.p_entry = &entry->data.entity; entry->data.entity.iscsi_node_list.p_entry = &entry->data.entity; entry->data.entity.ifcp_node_list.p_entry = &entry->data.entity; break; case PORT_NAME_KEY: k.dptr = (char *)key->val.port_key.v; k.dsize = strlen(key->val.port_key.v); d = ndb_fetch_sns (PORT_NAME_KEY, k, (char *)entry); if (d.dptr == NULL) { __DEBUG (isns_db_debug & 1, (read failed PORT_NAME %s),key->val.port_key.v); return (ISNS_NO_SUCH_ENTRY_ERR); } if (entry->data_type != PORT_NAME_KEY) return (ISNS_UNKNOWN_ERR); entry->data.port.dd_id_list.p_entry = &entry->data.port; break; case NODE_NAME_KEY: k.dptr = (char *)key->val.node_key.v; k.dsize = strlen(key->val.node_key.v); d = ndb_fetch_sns (NODE_NAME_KEY, k, (char *)entry); if (d.dptr == NULL) { __DEBUG (isns_db_debug & 1, (read failed Node Name %s),key->val.node_key.v); return (ISNS_NO_SUCH_ENTRY_ERR); } if (entry->data_type != NODE_NAME_KEY) return (ISNS_UNKNOWN_ERR); entry->data.node.port_list.p_entry = &entry->data.node; break; case PORTAL_ID_KEY: { SOIP_Portal_Key db_portal; __ISNS_COPY (&db_portal, sizeof(db_portal), &key->val, sizeof(SOIP_Portal_Key)); __DEBUG (isns_db_debug &1,read Portal ip_addr:%s port:%i, inet_ntoa(*(struct in_addr *)(db_portal.ip_addr.v+12)),db_portal.ip_port); k.dptr = (char *)&key->val; k.dsize = sizeof(SOIP_Portal_Key); d = ndb_fetch_sns (PORTAL_ID_KEY, k, (char *)entry); if (d.dptr == NULL) { __DEBUG (isns_db_debug &1,read failure Portal ip_addr:%s port:%i, inet_ntoa(*(struct in_addr *)(db_portal.ip_addr.v+12)),db_portal.ip_port); return (ISNS_NO_SUCH_ENTRY_ERR); } if (entry->data_type != PORTAL_ID_KEY) return (ISNS_UNKNOWN_ERR); break; } case PORTAL_GROUP_ID_KEY: { SOIP_Portal_Group_Key db_portal; __ISNS_COPY (&db_portal, sizeof(db_portal), &key->val, sizeof(SOIP_Portal_Group_Key)); __DEBUG (isns_db_debug &1,read Portal Group name:%s ip_addr:%s port:%i, db_portal.id.v, inet_ntoa(*(struct in_addr *)(db_portal.ip_addr.v+12)), db_portal.ip_port); k.dptr = (char *)&key->val; k.dsize = sizeof(SOIP_Portal_Group_Key); d = ndb_fetch_sns (PORTAL_GROUP_ID_KEY, k, (char *)entry); if (d.dptr == NULL) { __DEBUG (isns_db_debug &1,read Portal Group name:%s ip_addr:%s port:%i, db_portal.id.v, inet_ntoa(*(struct in_addr *)(db_portal.ip_addr.v+12)), db_portal.ip_port); return (ISNS_NO_SUCH_ENTRY_ERR); } if (entry->data_type != PORTAL_GROUP_ID_KEY) return (ISNS_UNKNOWN_ERR); break; } case ENTITY_IDX_KEY: case ISCSI_IDX_KEY: case PORTAL_IDX_KEY: k.dptr = (char *)&key->val; k.dsize = sizeof(SOIP_IDX_Key); d = ndb_fetch_sns (key->tag, k, (char *)entry); if (d.dptr == NULL) { __DEBUG (isns_db_debug & 1, (read failed index:%i),*(int *)&key->val); return (ISNS_NO_SUCH_ENTRY_ERR); } if (entry->data_type != key->tag) return (ISNS_UNKNOWN_ERR); break; case LIST_KEY: __DEBUG (isns_db_debug & 1,(read listid:%i index:%i),key->val.list.list_id,key->val.list.list_index); k.dptr = (char *)&key->val; switch (key->val.list.list_id) { case ENTITY_ISCSI_LIST: __DEBUG (isns_db_debug & 1, (read list:%s),(char *)&key->val.list.key.entity_id.id); k.dsize = LIST_KEY_SIZE + strlen(key->val.list.key.entity_id.id); break; case ENTITY_FCP_LIST: __DEBUG (isns_db_debug & 1, (read list:%s),(char *)&key->val.list.key.entity_id.id); k.dsize = LIST_KEY_SIZE + strlen(key->val.list.key.entity_id.id); break; case ENTITY_PORTAL_LIST: __DEBUG (isns_db_debug & 1, (read list:%s),(char *)&key->val.list.key.entity_id.id); k.dsize = LIST_KEY_SIZE + strlen(key->val.list.key.entity_id.id); break; case PORTAL_ENTITY_LIST: __DEBUG (isns_db_debug & 1, (read list:%i),key->val.list.key.portal.ip_port); k.dsize = LIST_KEY_SIZE + sizeof(SOIP_Portal_Key); break; case ISCSI_DD_LIST: k.dsize = LIST_KEY_SIZE + strlen(key->val.list.key.node_name.v); break; case FCP_PORTAL_LIST: k.dsize = LIST_KEY_SIZE + strlen(key->val.list.key.node_name.v); break; case FCP_DD_LIST: k.dsize = LIST_KEY_SIZE + strlen(key->val.list.key.node_name.v); break; case DD_MEMBER_LIST: case DD_DDS_LIST: case DDS_DD_LIST: k.dsize = 4 + LIST_KEY_SIZE; break; case SCN_LIST: case SCN_CALLBACK_LIST: k.dsize = LIST_KEY_SIZE + strlen(key->val.list.key.node_name.v); break; } d = ndb_fetch_sns (key->tag, k, (char *)entry); if (d.dptr == NULL) { __DEBUG (isns_db_debug & 1, (read failed list:%s),(char *)&key->val.list.key.entity_id.id); return (ISNS_NO_SUCH_ENTRY_ERR); } if (entry->data_type != key->tag) return (ISNS_UNKNOWN_ERR); break; default: __LOG_ERROR ("Undefined read database key key->tag:%i",key->tag); return ERROR; break; } if (entry->data_type != key->tag) { __LOG_ERROR ("Invalid record type:%i read from database key->tag:%i",entry->data_type,key->tag); return (ISNS_UNKNOWN_ERR); } return SUCCESS; } /********************************************************************* Write Entry in Database referenced by key *********************************************************************/ int ISNSdbWrite (ISNS_DBKey *key, SOIP_DB_Entry entry) { datum k; datum d; int rc; d.dptr = (char *) &entry; d.dsize = sizeof (SOIP_DB_Entry); k.dsize = 0; entry.data_type = key->tag; switch (key->tag) { case DDS_ID_KEY: __DEBUG (isns_db_debug &1,(Write DDS Entry:%i),key->val.dds_key.id); k.dptr = (char *)&key->val.dds_key.id; k.dsize = DDS_KEY_SIZE; rc = ndb_store_sns (key->tag, k, d, GDBM_REPLACE); if (rc == ERROR) __DEBUG (isns_db_debug &1,DDS Write failed); break; case DD_ID_KEY: __DEBUG (isns_db_debug &1,(Write DD Entry:%i),key->val.dd_key.id); __DEBUG (isns_db_debug &1,write dd - dds list_id:%i,entry.data.dd.dds_list.list_id); k.dptr = (char *)&key->val.dd_key.id; k.dsize = DD_KEY_SIZE; rc = ndb_store_sns (key->tag, k, d, GDBM_REPLACE); if (rc == ERROR) __DEBUG (isns_db_debug &1,DD Write failed); break; case ISCSI_ID_KEY: __DEBUG (isns_db_debug &1,ISCSI write:%s,key->val.node_key.v); k.dptr = (char *)key->val.node_key.v; k.dsize = strlen(key->val.node_key.v); rc = ndb_store_sns (key->tag, k, d, GDBM_REPLACE); if (rc == ERROR) __DEBUG (isns_db_debug &1,ISCSI Write failed); break; case ENTITY_ID_KEY: { SOIP_Entity * p_entity; p_entity = &entry.data.entity; __DEBUG (isns_db_debug &1,Entity write:%s,key->val.entity_key.id); __DEBUG (isns_db_debug &1,Entity write:%s,p_entity->eid.id); k.dptr = (char *)key->val.entity_key.id; k.dsize = strlen(key->val.entity_key.id); rc = ndb_store_sns (key->tag, k, d, GDBM_REPLACE); if (rc == ERROR) __DEBUG (isns_db_debug &1,ENTITY Write failed errno:%i,gdbm_errno); //ISNSDisplay_Entity (&entry.data.entity,HI_DETAIL); break; } case PORT_NAME_KEY: k.dptr = (char *)key->val.port_key.v; k.dsize = strlen(key->val.port_key.v); rc = ndb_store_sns (key->tag, k, d, GDBM_REPLACE); if (rc == ERROR) __DEBUG (isns_db_debug &1,PORT_NAME Write failed); break; case NODE_NAME_KEY: k.dptr = (char *)key->val.node_key.v; k.dsize = strlen(key->val.node_key.v); rc = ndb_store_sns (key->tag, k, d, GDBM_REPLACE); if (rc == ERROR) __DEBUG (isns_db_debug &1,FC NODE_NAME Write failed); break; case PORTAL_ID_KEY: { SOIP_Portal_Key db_portal; __ISNS_COPY (&db_portal, sizeof(db_portal), &key->val, sizeof(SOIP_Portal_Key)); __DEBUG (isns_db_debug &1,write Portal ip_addr:%s port:%i, inet_ntoa(*(struct in_addr *)(db_portal.ip_addr.v+12)),db_portal.ip_port); k.dptr = (char *)&key->val; k.dsize = sizeof(SOIP_Portal_Key); rc = ndb_store_sns (key->tag, k, d, GDBM_REPLACE); if (rc == ERROR) __DEBUG (isns_db_debug &1,PORTAL Name Write failed); break; } case PORTAL_GROUP_ID_KEY: __DEBUG (isns_db_debug &1,PORTAL Group Write); k.dptr = (char *)&key->val; k.dsize = sizeof(SOIP_Portal_Group_Key); rc = ndb_store_sns (key->tag, k, d, GDBM_REPLACE); if (rc == ERROR) __DEBUG (isns_db_debug &1,PORTAL Group Write failed); break; case ENTITY_IDX_KEY: case ISCSI_IDX_KEY: case PORTAL_IDX_KEY: k.dptr = (char *)&key->val; k.dsize = sizeof(SOIP_IDX_Key); rc = ndb_store_sns (key->tag, k, d, GDBM_REPLACE); if (rc == ERROR) __DEBUG (isns_db_debug &1,Index Write failed); break; case LIST_KEY: k.dptr = (char *)&key->val; __DEBUG (isns_db_debug & 1,(write listid:%i index:%i),key->val.list.list_id,key->val.list.list_index); k.dptr = (char *)&key->val; switch (key->val.list.list_id) { case ENTITY_ISCSI_LIST: __DEBUG (isns_db_debug & 1, (write list:%s),(char *)&key->val.list.key.entity_id.id); k.dsize = LIST_KEY_SIZE + strlen(key->val.list.key.entity_id.id); break; case ENTITY_FCP_LIST: __DEBUG (isns_db_debug & 1, (write list:%s),(char *)&key->val.list.key.entity_id.id); k.dsize = LIST_KEY_SIZE + strlen(key->val.list.key.entity_id.id); break; case ENTITY_PORTAL_LIST: __DEBUG (isns_db_debug & 1, (write list:%s),(char *)&key->val.list.key.entity_id.id); k.dsize = LIST_KEY_SIZE + strlen(key->val.list.key.entity_id.id); break; case PORTAL_ENTITY_LIST: __DEBUG (isns_db_debug & 1, (write list:%i),key->val.list.key.portal.ip_port); k.dsize = LIST_KEY_SIZE + sizeof(SOIP_Portal_Key); break; case ISCSI_DD_LIST: k.dsize = LIST_KEY_SIZE + strlen(key->val.list.key.node_name.v); break; case FCP_PORTAL_LIST: k.dsize = LIST_KEY_SIZE + strlen(key->val.list.key.node_name.v); break; case FCP_DD_LIST: k.dsize = LIST_KEY_SIZE + strlen(key->val.list.key.node_name.v); break; case DD_MEMBER_LIST: case DD_DDS_LIST: case DDS_DD_LIST: k.dsize = 4 + LIST_KEY_SIZE; break; case SCN_LIST: case SCN_CALLBACK_LIST: k.dsize = LIST_KEY_SIZE + strlen(key->val.list.key.node_name.v); break; } rc = ndb_store_sns (key->tag, k, d, GDBM_REPLACE); if (rc == ERROR) __DEBUG (isns_db_debug &1,List Write failed); break; default: __LOG_ERROR ("When writing -- Undefined database key->tag:%i",key->tag); break; } return SUCCESS; } /********************************************************************* Delete Entry in Database referenced by key *********************************************************************/ int ISNSdbDelete (ISNS_DBKey *key) { datum k; int rc; rc = SUCCESS; k.dsize = 0; switch (key->tag) { case DDS_ID_KEY: __DEBUG (isns_db_debug &1,Remove DDS Entry:%i,key->val.dds_key.id); k.dptr = (char *)&key->val.dds_key.id; k.dsize = DDS_KEY_SIZE; rc = ndb_delete (key->tag, k); if (rc == ERROR) __DEBUG (isns_db_debug &1,DDS Delete failed); break; case DD_ID_KEY: __DEBUG (isns_db_debug &1,Remove DD Entry:%i,key->val.dd_key.id); k.dptr = (char *)&key->val.dd_key.id; k.dsize = DD_KEY_SIZE; rc = ndb_delete (key->tag, k); if (rc == ERROR) __DEBUG (isns_db_debug &1,DD Delete failed); break; case ISCSI_ID_KEY: k.dptr = (char *)key->val.node_key.v; k.dsize = strlen(key->val.node_key.v); rc = ndb_delete (key->tag, k); if (rc == ERROR) __DEBUG (isns_db_debug &1,ISCSI Delete failed); break; case ENTITY_ID_KEY: __DEBUG (isns_db_debug &1,Delete ENTITY:%s,key->val.entity_key.id); k.dptr = (char *)key->val.entity_key.id; k.dsize = strlen(key->val.entity_key.id); rc = ndb_delete (key->tag, k); if (rc == ERROR) __DEBUG (isns_db_debug &1,ENTITY Delete failed); break; case PORT_NAME_KEY: k.dptr = (char *)key->val.port_key.v; k.dsize = strlen(key->val.port_key.v); rc = ndb_delete (key->tag, k); if (rc == ERROR) __DEBUG (isns_db_debug &1,PORT_NAME Delete failed); break; case NODE_NAME_KEY: k.dptr = (char *)key->val.node_key.v; k.dsize = strlen(key->val.node_key.v); rc = ndb_delete (key->tag, k); if (rc == ERROR) __DEBUG (isns_db_debug &1,FC NODE_NAME Delete failed); break; case PORTAL_ID_KEY: k.dptr = (char *)&key->val; k.dsize = sizeof(SOIP_Portal_Key); rc = ndb_delete (key->tag, k); if (rc == ERROR) __DEBUG (isns_db_debug &1,PORTAL Name Delete failed); break; case PORTAL_GROUP_ID_KEY: __DEBUG (isns_db_debug &1,PORTAL Group Delete); k.dptr = (char *)&key->val; k.dsize = sizeof(SOIP_Portal_Group_Key); rc = ndb_delete (key->tag, k); if (rc == ERROR) __DEBUG (isns_db_debug &1,PORTAL Group Delete failed); break; case ENTITY_IDX_KEY: case ISCSI_IDX_KEY: case PORTAL_IDX_KEY: k.dptr = (char *)&key->val; k.dsize = sizeof(SOIP_IDX_Key); rc = ndb_delete (key->tag, k); if (rc == ERROR) __DEBUG (isns_db_debug &1, Index Delete failed); break; case LIST_KEY: k.dptr = (char *)&key->val; switch (key->val.list.list_id) { case ENTITY_ISCSI_LIST: __DEBUG (isns_db_debug & 1, (write list:%s),(char *)&key->val.list.key.entity_id.id); k.dsize = LIST_KEY_SIZE + strlen(key->val.list.key.entity_id.id); break; case ENTITY_FCP_LIST: __DEBUG (isns_db_debug & 1, (write list:%s),(char *)&key->val.list.key.entity_id.id); k.dsize = LIST_KEY_SIZE + strlen(key->val.list.key.entity_id.id); break; case ENTITY_PORTAL_LIST: __DEBUG (isns_db_debug & 1, (write list:%s),(char *)&key->val.list.key.entity_id.id); k.dsize = LIST_KEY_SIZE + strlen(key->val.list.key.entity_id.id); break; case PORTAL_ENTITY_LIST: k.dsize = LIST_KEY_SIZE + sizeof(SOIP_Portal_Key); break; case ISCSI_DD_LIST: k.dsize = LIST_KEY_SIZE + strlen(key->val.list.key.node_name.v); break; case FCP_PORTAL_LIST: k.dsize = LIST_KEY_SIZE + strlen(key->val.list.key.node_name.v); break; case FCP_DD_LIST: k.dsize = LIST_KEY_SIZE + strlen(key->val.list.key.node_name.v); break; case DD_MEMBER_LIST: case DD_DDS_LIST: case DDS_DD_LIST: k.dsize = 4 + LIST_KEY_SIZE; break; case SCN_LIST: case SCN_CALLBACK_LIST: k.dsize = LIST_KEY_SIZE + strlen(key->val.list.key.node_name.v); break; } rc = ndb_delete (key->tag, k); if (rc == ERROR) __DEBUG (isns_db_debug &1, List Delete failed); break; default: __LOG_ERROR("Undefined Delete key->tag:%i",key->tag); break; } return SUCCESS; } /********************************************************************* Returns a new entity Index. *********************************************************************/ uint32_t ISNSGetNewEntityIdx( void ) { static uint32_t indx = 0; ISNS_DBKey key; int index = 0; key.tag = ENTITY_IDX_KEY; key.len = 0; if (indx == 0) { while (SNSdbGetNextOfKey (&key) == SUCCESS) { index = key.val.idx.index; if ( index > indx ) indx = index; } } indx++; return ( indx ); } /********************************************************************* Returns a new iSCSI Index. *********************************************************************/ uint32_t ISNSGetNewISCSIIdx( void ) { static uint32_t indx = 0; ISNS_DBKey key; int index = 0; key.tag = ISCSI_IDX_KEY; key.len = 0; if (indx == 0) { while (SNSdbGetNextOfKey (&key) == SUCCESS) { index = key.val.idx.index; if ( index > indx ) indx = index; } } indx++; return ( indx ); } /********************************************************************* Returns a new Portal Index. *********************************************************************/ uint32_t ISNSGetNewPortalIdx( void ) { static uint32_t indx = 0; ISNS_DBKey key; int index = 0; key.tag = PORTAL_IDX_KEY; key.len = 0; if (indx == 0) { while (SNSdbGetNextOfKey (&key) == SUCCESS) { index = key.val.idx.index; if ( index > indx ) indx = index; } } indx++; return ( indx ); } /********************************************************************* Database initialization. *********************************************************************/ int ISNSdbOpen( void ) { /* * Initialize database envirnoment and resources */ //dbfp = ndb_open(NULL, 0, 0, 0, ISNSExceptionHdlr); dbfp[NODE_NAME_KEY] = gdbm_open("isns1.db",1024,GDBM_WRCREAT,0666, ISNSExceptionHdlr1); dbfp[PORT_NAME_KEY] = gdbm_open("isns2.db",1024,GDBM_WRCREAT,0666, ISNSExceptionHdlr2); dbfp[ENTITY_ID_KEY] = gdbm_open("isns3.db",1024,GDBM_WRCREAT,0666, ISNSExceptionHdlr3); dbfp[PORTAL_ID_KEY] = gdbm_open("isns4.db",1024,GDBM_WRCREAT,0666, ISNSExceptionHdlr4); dbfp[DDS_ID_KEY] = gdbm_open("isns5.db",1024,GDBM_WRCREAT,0666, ISNSExceptionHdlr5); dbfp[DD_ID_KEY] = gdbm_open("isns6.db",1024,GDBM_WRCREAT,0666, ISNSExceptionHdlr6); dbfp[ISCSI_ID_KEY] = gdbm_open("isns7.db",1024,GDBM_WRCREAT,0666, ISNSExceptionHdlr7); dbfp[PORTAL_GROUP_ID_KEY] = gdbm_open("isns8.db",1024,GDBM_WRCREAT,0666, ISNSExceptionHdlr8); dbfp[ENTITY_IDX_KEY] = gdbm_open("isns9.db",1024,GDBM_WRCREAT,0666, ISNSExceptionHdlr9); dbfp[ISCSI_IDX_KEY] = gdbm_open("isns10.db",1024,GDBM_WRCREAT,0666, ISNSExceptionHdlr10); dbfp[PORTAL_IDX_KEY] = gdbm_open("isns11.db",1024,GDBM_WRCREAT,0666, ISNSExceptionHdlr11); dbfp[LIST_KEY] = gdbm_open("isns12.db",1024,GDBM_WRCREAT,0666, ISNSExceptionHdlr12); ddmem=(SOIP_Dd_Member *)calloc( MAX_MEMBER_PER_DD, sizeof(SOIP_Dd_Member) ); dlist_src=(uint32_t *)calloc(MAX_DD_PER_LIST, sizeof(uint32_t)); dlist_node=(uint32_t *)calloc(MAX_DD_PER_LIST, sizeof(uint32_t)); p_scn_msg_buffer=(ISNS_Msg *)calloc(1, sizeof(ISNS_Msg)); p_scn_all_msg_buffer=(ISNS_Msg *)calloc(1, sizeof(ISNS_Msg)); p_scn_md=(ISNS_Msg_Descp *)calloc(1, sizeof(ISNS_Msg_Descp)); p_rspMd=(ISNS_Msg_Descp *)calloc(1, sizeof(ISNS_Msg_Descp)); return (SUCCESS); } /********************************************************************* Closes the Database. *********************************************************************/ void ISNSdbClose(void) { //ndb_close (dbfp); gdbm_close(dbfp[ISCSI_ID_KEY]); gdbm_close(dbfp[ENTITY_ID_KEY]); gdbm_close(dbfp[PORTAL_ID_KEY]); gdbm_close(dbfp[DDS_ID_KEY]); gdbm_close(dbfp[DD_ID_KEY]); gdbm_close(dbfp[NODE_NAME_KEY]); gdbm_close(dbfp[PORT_NAME_KEY]); gdbm_close(dbfp[PORTAL_GROUP_ID_KEY]); gdbm_close(dbfp[ENTITY_IDX_KEY]); gdbm_close(dbfp[ISCSI_IDX_KEY]); gdbm_close(dbfp[PORTAL_IDX_KEY]); gdbm_close(dbfp[LIST_KEY]); } /********************************************************************* Gets the next object after the passed in key. *********************************************************************/ int SNSdbGetNextOfKey (ISNS_DBKey * key) { datum k, d, next; ISNS_DBKey null_key = { 0 }; SOIP_DB_Entry *p_entry; if ( (key->len == 0) || (key->len != 0 && memcmp (&key->val, &null_key.val, key->len) == 0)) { k = ndb_firstkey (key->tag); if (k.dptr == NULL) return (ERROR); } else if (key->tag == NODE_NAME_KEY) { k.dptr = (char *) ISNSAllocBuffer (DB_NODE_NAME_SIZE); __ISNS_COPY (k.dptr, DB_NODE_NAME_SIZE, &key->val, key->len); k.dsize = DB_NODE_NAME_SIZE; next = ndb_nextkey (key->tag, k); ISNSFreeBuffer ((char *) k.dptr); if (next.dptr == NULL) return (ERROR); k = next; } else if (key->tag == PORT_NAME_KEY) { k.dptr = (char *) ISNSAllocBuffer (PORT_NAME_SIZE+1); __ISNS_COPY (k.dptr, PORT_NAME_SIZE+1, &key->val, key->len); k.dsize = PORT_NAME_SIZE; next = ndb_nextkey (key->tag, k); ISNSFreeBuffer ((char *) k.dptr); if (next.dptr == NULL) return (ERROR); k = next; } else if (key->tag == DDS_ID_KEY) { k.dptr = (char *) ISNSAllocBuffer (DDS_KEY_SIZE); __ISNS_COPY (k.dptr, DDS_KEY_SIZE, &key->val, key->len); k.dsize = DDS_KEY_SIZE; next = ndb_nextkey (key->tag, k); ISNSFreeBuffer ((char *) k.dptr); if (next.dptr == NULL) return (ERROR); k = next; } else if (key->tag == DD_ID_KEY) { k.dptr = (char *) ISNSAllocBuffer (DD_KEY_SIZE); __ISNS_COPY (k.dptr, DD_KEY_SIZE, &key->val, key->len); k.dsize = DD_KEY_SIZE; next = ndb_nextkey (key->tag, k); ISNSFreeBuffer ((char *) k.dptr); if (next.dptr == NULL) return (ERROR); k = next; } else if (key->tag == ISCSI_ID_KEY) { k.dptr = (char *) ISNSAllocBuffer (key->len +1 ); memset (k.dptr,0,key->len+1); __ISNS_COPY (k.dptr, key->len+1, &key->val, key->len); k.dsize = strlen(k.dptr); next = ndb_nextkey (key->tag, k); ISNSFreeBuffer ((char *) k.dptr); if (next.dptr == NULL) { __DEBUG (isns_db_debug &1,(next is null)); return (ERROR); } k = next; } else if (key->tag == ENTITY_ID_KEY) { k.dptr = (char *) ISNSAllocBuffer (key->len +1 ); memset (k.dptr,0,key->len+1); __ISNS_COPY (k.dptr, key->len+1, &key->val, key->len); k.dsize = strlen(k.dptr); next = ndb_nextkey (key->tag, k); ISNSFreeBuffer ((char *) k.dptr); if (next.dptr == NULL) { return (ERROR); } k = next; } else { k.dptr = (char *) ISNSAllocBuffer (key->len +1 ); memset (k.dptr,0,key->len+1); __ISNS_COPY (k.dptr, key->len+1, &key->val, key->len); k.dsize = key->len; next = ndb_nextkey (key->tag, k); ISNSFreeBuffer ((char *) k.dptr); if (next.dptr == NULL) { return (ERROR); } k = next; } while (k.dptr) { d = ndb_fetch (key->tag, k); /* check data type for match */ p_entry = (SOIP_DB_Entry *) d.dptr; if ((p_entry) && ((int)p_entry->data_type == (int)key->tag)) { /* copy new key */ memset (&key->val,0,k.dsize+1); __ISNS_COPY (&key->val, sizeof(key->val), k.dptr, k.dsize); key->len = k.dsize; /* free buffers */ free (k.dptr); free (d.dptr); return (ISNS_NO_ERR); } else { /* else, keep searching */ next = ndb_nextkey (key->tag, k); if (d.dptr) free (d.dptr); free (k.dptr); k = next; } } /* not found, return ERROR */ return (ERROR); } /******************************************************************** ********************************************************************/ void ISNSExceptionHdlr1(char * string) { __LOG_INFO ("Database 1 ISNSExceptionHdlr:%s",string); } void ISNSExceptionHdlr2(char * string) { __LOG_INFO ("Database 2 ISNSExceptionHdlr:%s",string); } void ISNSExceptionHdlr3(char * string) { __LOG_INFO ("Database 3 ISNSExceptionHdlr:%s",string); } void ISNSExceptionHdlr4(char * string) { __LOG_INFO ("Database 4 ISNSExceptionHdlr:%s",string); } void ISNSExceptionHdlr5(char * string) { __LOG_INFO ("Database 5 ISNSExceptionHdlr:%s",string); } void ISNSExceptionHdlr6(char * string) { __LOG_INFO ("Database 6 ISNSExceptionHdlr:%s",string); } void ISNSExceptionHdlr7(char * string) { __LOG_INFO ("Database 7 ISNSExceptionHdlr:%s",string); } void ISNSExceptionHdlr8(char * string) { __LOG_INFO ("Database 8 ISNSExceptionHdlr:%s",string); } void ISNSExceptionHdlr9(char * string) { __LOG_INFO ("Database 9 ISNSExceptionHdlr:%s",string); } void ISNSExceptionHdlr10(char * string) { __LOG_INFO ("Database 10 ISNSExceptionHdlr:%s",string); } void ISNSExceptionHdlr11(char * string) { __LOG_INFO ("Database 11 ISNSExceptionHdlr:%s",string); } void ISNSExceptionHdlr12(char * string) { __LOG_INFO ("Database 12 ISNSExceptionHdlr:%s",string); } /************************************************** **************************************************/ void ISNSInitDBTables(void) { __DEBUG (isns_db_debug &1, ISNSInitDBTables); InitList(SCN_CALLBACK_LIST, &scn_callback_list); } isns-2.1-01/isnsserver/src/iSNSnt.c0000644000175000017500000002211410665040341016071 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include "iSNSnt.h" #include "iSNS.h" #include "iSNScomm.h" #include "iSNSdb.h" #include "iSNSmsg.h" #include "iSNSqueue.h" #include "iSNSfsm.h" #include "iSNScomm.h" #include "iSNSbuffer.h" #include "iSNSipc.h" #include "iSNSparse.h" #include "getarg.h" WSADATA g_WsaData; extern int sns_ready; extern int sns_local_priority; extern int sns_local_version; int pauseFlag = TRUE; int snsServiceFlag = FALSE; int loadFlag = FALSE; void NTDebugOn (void); void SNSReqTimeoutHdlr (void); void taskDelay (int time) { Sleep (time); } int sysClkRateGet (void) { return (1); } #define _SECOND 10000000 LARGE_INTEGER l; LARGE_INTEGER * ConvertTime (int sec, LARGE_INTEGER * pl) { __int64 qwDueTime; qwDueTime = -sec * _SECOND; /* Copy the relative time into a LARGE_INTEGER. */ pl->LowPart = (DWORD) (qwDueTime & 0xFFFFFFFF); pl->HighPart = (LONG) (qwDueTime >> 32); return (pl); } int wdStart (void *sns_request_timer, int next_timeout, void *nptr1, void *nptr2) { int results; int timeout; timeout = next_timeout; if (timeout < 1) timeout = 1; results = SetWaitableTimer ((void *) sns_request_timer, ConvertTime (timeout, &l), 0, NULL, NULL, FALSE); return (!results); } void wdCancel (void *timer) { if (timer) CancelWaitableTimer ((void *) timer); } void taskDelete (int task) { if (task == 0) return; if ((void *)task != NULL) { TerminateThread ((void *)task, 0); } } void taskSuspend (void) { return; } int taskIdSelf (void) { return (0); } void * NTtaskSpawn (char *taskName, void *funcPtr) { void *result; DWORD junk; result = NULL; result = CreateThread (0, 0, funcPtr, &junk, 0, &junk); return (result); } DWORD WINAPI NTtimertaskWrapper (LPVOID lparam) { /* Run Task */ return (0); } HANDLE init_ipc_rcv (void); char Usage[] = "\ Usage: isnss [options] -i IP -b BROADCAST IP\n\ NOTES: IP-Addresses must be in IP dotted notation.\n\ Options:\n\ [-a addr] IP-Address for SNSP traffic.\n\ [-b addr] Broadcast Address for SNSP traffic.\n\ [-p port] primary port for SNSP traffic.\n\ [-d] Full debug options on.\n\ [-?] Help.\n\ \n\ "; DWORD WINAPI TCP_RecvMain (LPVOID l); extern int sns_comm_main_port_set; int main (int argc, char **argv) { DWORD junk; int c; char sfilename[256] = { 0 }; ISNS_Entity role = ISNS_SECONDARY_SERVER; memset (snsp_ip, 0, sizeof (snsp_ip)); if (argc < 3) { __LOG_ERROR (Usage); exit (0); } /* Don't forget to init the rest */ while (optind != argc) { c = getopt (argc, argv, "da:b:p:c:"); switch (c) { case EOF: optarg = argv[optind]; optind++; break; case 'a': strcpy (snsp_ip, optarg); break; case 'b': strcpy (snsp_bip, optarg); break; case 'c': strcpy (sfilename, optarg); break; case 'p': sns_comm_main_port_set = atoi (optarg); break; case 'd': NTDebugOn(); break; case '?': default: __LOG_ERROR (Usage); exit (0); } } if (strlen (snsp_ip) == 0 ) { __LOG_ERROR (Usage); exit (0); } pauseFlag = FALSE; while (pauseFlag) Sleep (10); if (WSAStartup (MAKEWORD (0x02, 0x00), &g_WsaData) == SOCKET_ERROR) { return (0); } CreateThread (0, 0, TCP_RecvMain, &junk, 0, &junk); SNSMain (role); /* Never should hit this. */ WSACleanup (); exit (-1); } extern void *sns_request_timer; DWORD WINAPI SNSReqTimeoutThread (LPVOID lparam) { DWORD results; __LOG_INFO ("SNSReqTimeoutHdlr Started.\n"); while (1) { results = WaitForSingleObject ((HANDLE)sns_request_timer, INFINITE); SNSReqTimeoutHdlr (); if (pauseFlag) return (0); } return (0); } extern int sns_fsm_timer; DWORD WINAPI SNSFSMTimeoutThread (LPVOID lparam) { DWORD results; __LOG_INFO ("SNSFSMTimeoutHdlr thread started.\n"); while (1) { results = WaitForSingleObject ((HANDLE)sns_fsm_timer, INFINITE); SNSFSMTimeoutHdlr (); if (pauseFlag) return (0); } return (0); } extern int sns_esi_timer; DWORD WINAPI SNSESITimeoutThread (LPVOID lparam) { DWORD results; __LOG_INFO ("SNSESITimeoutHdlr thread started.\n"); while (1) { results = WaitForSingleObject ((HANDLE)sns_esi_timer, INFINITE); SNSESITimeoutHdlr (); if (pauseFlag) return (0); } return (0); } extern int sns_resync_timer; DWORD WINAPI SNSResyncTimeoutThread (LPVOID lparam) { DWORD results; while (1) { results = WaitForSingleObject ((HANDLE)sns_resync_timer, INFINITE); if (pauseFlag) return (0); } return (0); } void SNSTrap (void) { } /***********************************************/ void NTDebugOn (void) { extern int sns_bcast_debug; extern int sns_cb_debug; extern int sns_fsm_debug; extern int sns_hb_debug; extern int isns_main_debug; extern int sns_recv_debug; extern int sns_rsync_debug; extern int sns_scn_debug; extern int sns_comm_debug; extern int isns_db_debug; sns_bcast_debug = -1; sns_cb_debug = -1; sns_comm_debug = -1; isns_db_debug = -1; sns_fsm_debug = -1; sns_hb_debug = -1; isns_main_debug = -1; sns_recv_debug = -1; sns_rsync_debug = -1; sns_scn_debug = -1; } int NTReadFromFile(int *lenPtr, void *ptr) { HANDLE hFile; int bResult; hFile = CreateFile("iSNS.DAT", // open ONE.TXT GENERIC_READ, // open for reading 0, // do not share NULL, // no security OPEN_EXISTING, // existing file only FILE_ATTRIBUTE_NORMAL, // normal file NULL); // no attr. template if (hFile == INVALID_HANDLE_VALUE) { __LOG_ERROR ("iSNS: Unable to read data file.\n"); CloseHandle(hFile); return(ERROR); } bResult = ReadFile(hFile, ptr, 1024*10, lenPtr, NULL) ; if (!bResult) { __LOG_ERROR("iSNS: Unable to read data file.\n"); CloseHandle(hFile); return(ERROR); } CloseHandle(hFile); return(SUCCESS); } void NTWriteToFile(int len, void *ptr) { HANDLE hFile; int bResult; int nBytesWrote; hFile = CreateFile("iSNS.DAT", // create MYFILE.TXT GENERIC_WRITE, // open for writing 0, // do not share 0, // no security CREATE_ALWAYS, // overwrite existing 0, // asynchronous I/O 0); // no attr. template if (hFile == INVALID_HANDLE_VALUE) { __LOG_INFO ("iSNS: Unable to write data file.\n"); CloseHandle(hFile); return; } // attempt an asynchronous read operation bResult = WriteFile(hFile, ptr, len, &nBytesWrote, NULL) ; if (!bResult) { __LOG_ERROR ("iSNS: Unable to write data file.\n"); CloseHandle(hFile); return; } if (nBytesWrote!=len) { __LOG_ERROR ("iSNS: Error writing data file.\n"); CloseHandle(hFile); return; } CloseHandle(hFile); return; } isns-2.1-01/isnsserver/src/iSNSquery.c0000644000175000017500000030501510665040341016621 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This file contains source code for managing the * iSNS database. * */ #include "iSNS.h" #include "iSNSmsg.h" #include "iSNSList.h" #include "iSNSdb.h" #include "iSNSobjects.h" #include "iSNSquery.h" #include "iSNSresponse.h" #include "iSNSreg.h" #include "iSNStypes.h" #include "iSNScomm.h" #include "iSNSbuffer.h" #include "iSNStbl.h" #include "iSNSparse.h" #include "iSNSdebug.h" /* Global */ extern int isns_query_debug; extern uint32_t *dlist_src; /*[MAX_DD_PER_LIST];*/ extern uint32_t *dlist_node; /*[MAX_DD_PER_LIST];*/ extern SOIP_Dd_Member *ddmem; /* [100]; */ extern ISNS_Msg_Descp *p_rspMd; /* * static common variables for gdbm fetches * entry is for common registrations and queries * scn_entry is for state change notifications * opn_entry is for access control */ static SOIP_DB_Entry entry; /* top level fetches ONLY */ static SOIP_DB_Entry entry2; /* secondary fetches */ static SOIP_DB_Entry entry3; static SOIP_DB_Entry entry4; static SOIP_DB_Entry entry5; /* local prototypes */ static int SNSdbGetAttrNode (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Msg_Descp * md, ISNS_Msg * p_rspmsg); static int SNSdbGetAttrPort (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Attr * src_attr, ISNS_Msg_Descp * md, ISNS_Msg * p_rspmsg); static int SNSdbGetAttrPortal (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Attr * src_attr, ISNS_Msg_Descp * md, ISNS_Msg * p_rsp_msg); static int SNSdbGetAttrDDEntry (int id, ISNS_Attr **attr_indx, ISNS_Msg * p_msg); int ISNSGetNextAttr( ISNS_Msg_Descp *p_md, ISNS_Msg * p_rspmsg ); static int SNSdbGetAttrDD (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Attr * src_attr, ISNS_Msg_Descp * md, ISNS_Msg * p_rspmsg); static int SNSdbGetAttrDDSEntry (int id, ISNS_Attr **attr_indx, ISNS_Msg * p_msg); static int SNSdbGetAttrDDS (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Attr * src_attr, ISNS_Msg_Descp * md, ISNS_Msg * p_rspmsg); static int ISNSdbGetAttrISCSI (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Attr * src_attr, ISNS_Msg_Descp * md, ISNS_Msg * p_rspmsg); static int SNSdbGetAttrEntity (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Attr * src_attr, ISNS_Msg_Descp * md, ISNS_Msg * p_rspmsg); /********************************************************************* _SNSdbGetAttr Calls the more specific get routines. *********************************************************************/ int ISNSdbGetAttr ( ISNS_Msg_Descp *p_md, ISNS_Msg * p_rspmsg ) { int status = ISNS_UNKNOWN_ERR; ISNS_Key *key; ISNS_Attr *src_attr; ISNS_Attr *attr_indx[SNS_MAX_ATTRS]; ISNS_Attr *key_indx[SNS_MAX_ATTRS]; ISNSParseMsg( &p_md->msg, attr_indx, key_indx, &src_attr ); key = (ISNS_Key *)(key_indx[0]); if (key == NULL) { __DEBUG (isns_query_debug & 1, (No attr in query msg)); return ( ISNS_MSG_FMT_ERR ); } switch ( key->tag ) { case ISNS_ENTITY_ID: case ISNS_ENTITY_TYPE: case ISNS_MGMT_IP: case ISNS_PROT_VER: case ISNS_TIMESTAMP: case ISNS_ENTITY_CERT: case ISNS_ENTITY_PERIOD: case ISNS_ENTITY_IDX: /* Search entity table */ status = SNSdbGetAttrEntity ( attr_indx, key_indx, (ISNS_Attr *)src_attr, NULL, p_rspmsg); break; case ISNS_ESI_PORT: case ISNS_ESI_INTERVAL: case ISNS_PORTAL_IP: case ISNS_PORTAL_PORT: case ISNS_PORTAL_SYM_NAME: case ISNS_PORTAL_IDX: status = SNSdbGetAttrPortal ( attr_indx, key_indx, (ISNS_Attr *)src_attr, NULL, p_rspmsg ); break; case ISNS_NODE_NAME: case ISNS_NODE_SYM_NAME: case ISNS_FC_NODE_IP: case ISNS_FC_NODE_IPA: case ISNS_FC_NODE_CERT: status = SNSdbGetAttrNode ( attr_indx, key_indx, NULL, p_rspmsg ); break; case ISNS_PORT_NAME: case ISNS_PORT_ID: case ISNS_PORT_TYPE: case ISNS_PORT_SYM_NAME: case ISNS_FABRIC_PORT_NAME: case ISNS_FC_HARD_ADDR: case ISNS_FC_PORT_IP: case ISNS_FC_COS: case ISNS_FC4_TYPE: case ISNS_FC4_DESC: case ISNS_FC4_FEATURE: status = SNSdbGetAttrPort ( attr_indx, key_indx, (ISNS_Attr *)src_attr, NULL, p_rspmsg ); break; case ISNS_ISCSI_TYPE: case ISNS_ISCSI_NODE_ID: case ISNS_ISCSI_ALIAS: case ISNS_ISCSI_SCN_BITMAP: case ISNS_ISCSI_IDX: status = ISNSdbGetAttrISCSI ( attr_indx, key_indx, (ISNS_Attr *)src_attr, NULL, p_rspmsg ); break; case ISNS_DDS_ID: case ISNS_DDS_SYM_NAME: case ISNS_DDS_STATUS: status = SNSdbGetAttrDDS ( attr_indx, key_indx, (ISNS_Attr *)src_attr, NULL, p_rspmsg ); break; case ISNS_DD_ID: case ISNS_DD_SYM_NAME: case ISNS_DD_ISCSI_MEMBER: case ISNS_DD_IFCP_MEMBER: case ISNS_DD_FEATURE_BITMAP: case ISNS_DD_ACTIVE: status = SNSdbGetAttrDD ( attr_indx, key_indx, (ISNS_Attr *)src_attr, NULL, p_rspmsg ); break; default: break; } return ( status ); } /********************************************************************* _SNSdbGetAttrEntity Gets one or more entity attributes. The attributes will be appended to p_rspmsg. *********************************************************************/ static int SNSdbGetAttrEntity (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Attr * src_attr, ISNS_Msg_Descp * md, ISNS_Msg * p_rspmsg) { int ii; int entityIdxFlag; int entityKeyFlag; int entityTypeKeyFlag; int portalIpKeyFlag; int portalPortKeyFlag; int iSCSINodeKeyFlag; int iSCSINodeIdxKeyFlag; int iFCPNodeKeyFlag; int foundFlag; ISNS_Key *key; ISNS_Attr *attr; /* query attr, response attr */ SOIP_Entity *p_entity; SOIP_Portal *p_portal; SOIP_Ifcp *p_port; SOIP_Portal_Key db_portal; int rval; foundFlag = FALSE; entityIdxFlag = -1; entityKeyFlag = -1; entityTypeKeyFlag = -1; portalIpKeyFlag = -1; portalPortKeyFlag = -1; iSCSINodeKeyFlag = -1; iFCPNodeKeyFlag = -1; iSCSINodeIdxKeyFlag = -1; __DEBUG (isns_query_debug &1,(GetAttrEntity)); ISNSTouchEntity( src_attr ); for (ii = 0; ii < MAX_PARSE_ATTRS && key_indx[ii]; ii++) { key = (ISNS_Key *)(key_indx[ii]); switch (key->tag) { case ISNS_ENTITY_ID: if (key->len > 0) entityKeyFlag = ii; break; case ISNS_ENTITY_IDX: entityIdxFlag = ii; break; case ISNS_ENTITY_TYPE: entityTypeKeyFlag = ii; break; case ISNS_PORT_NAME: iFCPNodeKeyFlag = ii; break; case ISNS_ISCSI_NODE_ID: iSCSINodeKeyFlag = ii; break; case ISNS_ISCSI_IDX: iSCSINodeIdxKeyFlag = ii; break; case ISNS_PORTAL_IP: portalIpKeyFlag = ii; break; case ISNS_PORTAL_PORT: portalPortKeyFlag = ii; break; default: break; } } if ( entityKeyFlag != -1 ) { entityKeyFlag = ISNSFindTag (0, ISNS_ENTITY_ID, key_indx); while (entityKeyFlag != -1) { /* Entity ID found in key */ SOIP_Entity_Id db_entity_id; key = (ISNS_Key *)(key_indx[entityKeyFlag]); __ISNS_COPY (db_entity_id.id, sizeof(db_entity_id.id), &key->val, key->len); if (ISNS_NO_ERR != read_EntityObject (db_entity_id.id, &p_entity, &entry)) { return (ISNS_INVALID_QUERY_ERR); } rval = Check_Permission (src_attr, ENTITY_ID_KEY, p_entity); if (rval == SUCCESS) { foundFlag = TRUE; ISNSdbProcessEntityOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_entity); } entityKeyFlag = ISNSFindTag (entityKeyFlag + 1, ISNS_ENTITY_ID, key_indx); } } else if ( entityIdxFlag != -1 ) { entityKeyFlag = ISNSFindTag (0, ISNS_ENTITY_IDX, key_indx); while (entityKeyFlag != -1) { void *ptr; /* Entity ID found in key */ key = (ISNS_Key *)(key_indx[entityKeyFlag]); __DEBUG (isns_query_debug &1,(Find Entity Index:%i),key->val.index); rval = read_EntityidxObject(key->val.index, &ptr, &entry3); if (rval != SUCCESS) return rval; /* Fetch entity from hash */ if (ISNS_NO_ERR != read_EntityObject ((char *)ptr, &p_entity, &entry )) { return (ISNS_INVALID_QUERY_ERR); } rval = Check_Permission (src_attr, ENTITY_ID_KEY, p_entity); if (rval == SUCCESS) { foundFlag = TRUE; ISNSdbProcessEntityOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_entity); } entityKeyFlag = ISNSFindTag (entityKeyFlag + 1, ISNS_ENTITY_IDX, key_indx); } } else if ((portalIpKeyFlag != -1) || (portalPortKeyFlag != -1)) { if ((portalIpKeyFlag == -1) || (portalPortKeyFlag == -1)) { __LOG_ERROR ("***Located only one required portal key."); return (ISNS_MSG_FMT_ERR); } attr = (ISNS_Attr *) key_indx[portalPortKeyFlag]; __ISNS_COPY (db_portal.ip_addr.v, sizeof(db_portal.ip_addr.v), &attr->val, attr->len); attr = (ISNS_Attr *) key_indx[portalIpKeyFlag]; db_portal.ip_port=attr->val.ip_port; rval = read_PortalObject(&db_portal, &p_portal, &entry2); if (rval != SUCCESS) return rval; /* Fetch entity from hash */ if (ISNS_NO_ERR != read_EntityObject (p_portal->entity_id.id, &p_entity, &entry)) { return (ISNS_INVALID_QUERY_ERR); } rval = Check_Permission (src_attr, ENTITY_ID_KEY, p_entity); if (rval == SUCCESS) { foundFlag = TRUE; ISNSdbProcessEntityOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_entity); } } else if (iFCPNodeKeyFlag != -1) { /* Fetch iFCP Node */ key = (ISNS_Key *) key_indx[iFCPNodeKeyFlag]; rval = read_FCPortObject((char *)&key->val, &p_port, &entry); if (rval != SUCCESS) return rval; /* Fetch entity from hash */ if (ISNS_NO_ERR != read_EntityObject (p_port->entity_id.id, &p_entity, &entry)) { return (ISNS_NO_SUCH_ENTRY_ERR); } rval = Check_Permission (src_attr, ENTITY_ID_KEY, p_entity); if (rval == SUCCESS) { foundFlag = TRUE; ISNSdbProcessEntityOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_entity); } } else if (iSCSINodeKeyFlag != -1 || iSCSINodeIdxKeyFlag != -1) { SOIP_ISCSI_Node_Id db_node_name; SOIP_Iscsi *p_node; void *ptr; memset (&db_node_name, 0, sizeof (db_node_name)); if (iSCSINodeIdxKeyFlag != -1) { key = (ISNS_Key *)(key_indx[iSCSINodeIdxKeyFlag]); rval = read_ISCSIidxObject(key->val.index, &ptr, &entry3); if (rval != SUCCESS) return rval; strncpy ((char *) db_node_name.v, (char *) ptr, sizeof(db_node_name.v)); } else { /* Fetch iSCSI Node */ key = (ISNS_Key *)(key_indx[iSCSINodeKeyFlag]); memset (&db_node_name, 0, sizeof (db_node_name)); __ISNS_COPY (db_node_name.v, sizeof(db_node_name.v), &key->val, key->len); } rval = read_ISCSIObject(db_node_name.v, &p_node, &entry); if (rval != SUCCESS) return rval; rval = read_EntityObject (p_node->entity_id.id, &p_entity, &entry); if (rval != SUCCESS) return rval; rval = Check_Permission (src_attr, ENTITY_ID_KEY, p_entity); if (rval == SUCCESS) { foundFlag = TRUE; ISNSdbProcessEntityOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_entity); } } else { /* Return all entity */ ISNS_DBKey key = { 0 }; key.tag = ENTITY_ID_KEY; while (SNSdbGetNextOfKey (&key) == SUCCESS) { if (ISNS_NO_ERR != read_EntityObject (key.val.entity_key.id, &p_entity, &entry)) { return (ISNS_NO_SUCH_ENTRY_ERR); } rval = Check_Permission (src_attr, ENTITY_ID_KEY, p_entity); if (rval == SUCCESS) { foundFlag = TRUE; ISNSdbProcessEntityOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_entity); } } } if (foundFlag) return (ISNS_NO_ERR); else return (ISNS_NO_SUCH_ENTRY_ERR); } /********************************************************************* _SNSdbGetAttrDDSEntry Retrieves the DDS entry from the database. *********************************************************************/ static int SNSdbGetAttrDDSEntry (int id, ISNS_Attr **attr_indx, ISNS_Msg * p_msg) { SOIP_Dds *p_dds; int rval; rval = read_DDSObject(id, &p_dds, &entry); if (rval != SUCCESS) return rval; ISNSdbProcessDDSOpAttr(p_msg, (ISNS_Attr **) attr_indx, p_dds); return (ISNS_NO_ERR); } /********************************************************************* _SNSdbGetAttrDDS Determines what needs to be done to return the DDS attributes. *********************************************************************/ static int SNSdbGetAttrDDS (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Attr * src_attr, ISNS_Msg_Descp * md, ISNS_Msg * p_rspmsg) { int ii; int rval; int ddsKeyIndex; int ddKeyIndex; int iscsiKeyIndex; int ifcpKeyIndex; int ddsSymIndex; int found; ISNS_Key *key; ISNS_Attr *p_attr; SOIP_Dds *p_dds; rval = Check_Authorization (src_attr); if (rval != SUCCESS) return (ISNS_AUTH_FAILED_ERR); ISNSTouchEntity( src_attr ); found = FALSE; ddsKeyIndex = -1; ddKeyIndex = -1; iscsiKeyIndex = -1; ifcpKeyIndex = -1; ddsSymIndex = -1; for (ii = 0; ii < MAX_PARSE_ATTRS && key_indx[ii]; ii++) { key = (ISNS_Key *)(key_indx[ii]); switch (key->tag) { case ISNS_ISCSI_NODE_ID: iscsiKeyIndex = ii; break; case ISNS_PORT_NAME: ifcpKeyIndex = ii; break; case ISNS_DD_ID: if (key->val.dd_id) ddKeyIndex = ii; break; case ISNS_DDS_ID: if (key->val.dds_id) ddsKeyIndex = ii; break; case ISNS_DDS_SYM_NAME: ddsSymIndex = ii; break; default: break; } } if (ddsKeyIndex != -1) { key = (ISNS_Key *)(key_indx[ddsKeyIndex]); rval = SNSdbGetAttrDDSEntry (*(uint32_t *) & key->val, attr_indx, p_rspmsg); if (!rval) found = TRUE; } else if (ddKeyIndex != -1) { __DEBUG(isns_query_debug & 1, (Not implemented)); } else if (ifcpKeyIndex != -1) { __DEBUG (isns_query_debug & 1, (Not implemented)); } else if (iscsiKeyIndex != -1) { __DEBUG (isns_query_debug & 1, (Not implemented)); } else { /* retrieve all DDS */ ISNS_DBKey key = { 0 }; key.tag = DDS_ID_KEY; while (SNSdbGetNextOfKey (&key) == SUCCESS) { if (ddsSymIndex!=-1) { rval = read_DDSObject(key.val.dds_key.id, &p_dds, &entry); if (rval != SUCCESS) return rval; p_attr = (ISNS_Attr *)attr_indx[ddsSymIndex]; if (strcmp(p_dds->sym_name, (char *)&p_attr->val)) continue; } if (ERROR == SNSdbGetAttrDDSEntry (key.val.dd_key.id, attr_indx, p_rspmsg)) return (ERROR); found = TRUE; } } if (found != TRUE) { return (ISNS_NO_SUCH_ENTRY_ERR); } return (ISNS_NO_ERR); } /********************************************************************* _SNSdbGetAttrDDEntry Retrieves a DD entry from the database. *********************************************************************/ static int SNSdbGetAttrDDEntry (int id, ISNS_Attr **attr_indx, ISNS_Msg * p_msg) { SOIP_Dd *p_dd; int rval; __DEBUG (isns_query_debug &1, SNSdbGetAttrDDEntry); rval = read_DDObject(id, &p_dd, &entry); if (rval == SUCCESS) ISNSdbProcessDDOpAttr( p_msg, (ISNS_Attr **) attr_indx, p_dd ); return ( rval ); } /********************************************************************* _SNSdbGetAttrDD Determines what to do to retrieve a DD's attributes *********************************************************************/ static int SNSdbGetAttrDD (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Attr * src_attr, ISNS_Msg_Descp * md, ISNS_Msg * p_rspmsg) { int ddKeyIndex; int nodeKeyIndex; int entityKeyIndex; int ifcpKeyIndex; int ddsKeyIndex; int found; ISNS_Key *key; SOIP_Dds *p_dds; int ii; int rval; SOIP_DD_Key dds_key; SOIP_Iscsi *p_node; ISNS_LIST_NODE *pnode; __DEBUG (isns_query_debug &1, SNSdbGetAttrDD); rval = Check_Authorization (src_attr); if (rval != SUCCESS) return (ISNS_AUTH_FAILED_ERR); ISNSTouchEntity( src_attr ); nodeKeyIndex = -1; entityKeyIndex = -1; ifcpKeyIndex = -1; ddKeyIndex = -1; ddsKeyIndex = -1; found = FALSE; for (ii = 0; ii < MAX_PARSE_ATTRS && key_indx[ii]; ii++) { key = (ISNS_Key *)(key_indx[ii]); switch ( key->tag ) { case ISNS_ISCSI_NODE_ID: nodeKeyIndex = ii; break; case ISNS_ENTITY_ID: entityKeyIndex = ii; break; case ISNS_PORT_NAME: ifcpKeyIndex = ii; break; case ISNS_DD_ID: if ( key->val.dd_id ) ddKeyIndex = ii; break; case ISNS_DDS_ID: if ( key->val.dds_id ) ddsKeyIndex = ii; break; default: /* Error condition */ break; } } if (ddKeyIndex != -1) { key = (ISNS_Key *)(key_indx[ddKeyIndex]); if (SUCCESS != (rval = SNSdbGetAttrDDEntry (*(uint32_t *) & key->val, attr_indx, p_rspmsg))) return (rval); found = TRUE; } else if (ddsKeyIndex != -1) { key = (ISNS_Key *)(key_indx[ddsKeyIndex]); dds_key.id = key->val.dd_id; rval = read_DDSObject(dds_key.id, &p_dds, &entry3); if (rval != SUCCESS) return rval; pnode=NULL; while ((pnode=GetNextNode(&p_dds->dd_list, pnode))) { if (SUCCESS != (rval = SNSdbGetAttrDDEntry (*(uint32_t *)GetNodeData(pnode), attr_indx, p_rspmsg))) return (rval); found = TRUE; } } else if (nodeKeyIndex != -1) { key = (ISNS_Key *)(key_indx[nodeKeyIndex]); rval = read_ISCSIObject((char *)&key->val, &p_node, &entry3); if (rval != SUCCESS) return rval; pnode=NULL; while ((pnode=GetNextNode(&p_node->dd_id_list, pnode))) { if (SUCCESS != (rval = SNSdbGetAttrDDEntry (*(uint32_t *)GetNodeData(pnode), attr_indx, p_rspmsg))) return (rval); found = TRUE; } } else { /* retrieve all DD */ ISNS_DBKey key = { 0 }; key.tag = DD_ID_KEY; while (SNSdbGetNextOfKey (&key) == SUCCESS) { if (SUCCESS != (rval = SNSdbGetAttrDDEntry (key.val.dd_key.id, attr_indx, p_rspmsg))) return (rval); found = TRUE; } } if (found != TRUE) { return (ISNS_NO_SUCH_ENTRY_ERR); } return (ISNS_NO_ERR); } /********************************************************************* *********************************************************************/ static int SNSdbGetAttrNode (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Msg_Descp * md, ISNS_Msg * p_rspmsg) { int ii; ISNS_Key *key; SOIP_Fc_Node *p_node; SOIP_Ifcp *p_port; SOIP_DB_Node_Name db_node_name; SOIP_Port_Name db_port_name; char *p_node_name = NULL; int nodeKeyFlag, portKeyFlag; int rval; /* Scan the keys */ nodeKeyFlag = 0; portKeyFlag = 0; for (ii = 0; ii < MAX_PARSE_ATTRS && key_indx[ii]; ii++) { key = (ISNS_Key *)(key_indx[ii]); switch (key->tag) { case ISNS_PORT_NAME: portKeyFlag = TRUE; break; case ISNS_NODE_NAME: p_node_name = (char *)&key->val; nodeKeyFlag = TRUE; break; default: /* Error condition */ break; } } /* Order is important */ if (nodeKeyFlag) { /* Fetch the node */ memset (&db_node_name, 0, sizeof (db_node_name)); __ISNS_COPY (db_node_name.v, sizeof(db_node_name.v), p_node_name, ISNS_NODE_NAME_SIZE); db_node_name.v[8] = (char)SOIP_DB_Node_Id; rval = read_FCNodeObject(db_node_name.v, &p_node, &entry); if (rval != SUCCESS) return rval; ISNSdbProcessFCNodeOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_node); } else if (portKeyFlag) { /* Fetch the port */ memset (&db_port_name, 0, sizeof (db_port_name)); key = (ISNS_Key *)(key_indx[ii]); __ISNS_COPY (db_port_name.v, sizeof(db_port_name.v), &key->val, key->len); rval = read_FCPortObject(db_port_name.v, &p_port, &entry); if (rval != SUCCESS) return rval; key = (ISNS_Key *)(key_indx[nodeKeyFlag]); if (!memcmp (p_port->node_name.v, &key->val, ISNS_NODE_NAME_SIZE)) { /* Match Found */ /* Fetch the Node */ memset (&db_node_name, 0, sizeof (db_node_name)); __ISNS_COPY (db_node_name.v, sizeof(db_node_name.v), p_port->node_name.v, ISNS_NODE_NAME_SIZE); db_node_name.v[8] = (char)SOIP_DB_Node_Id; rval = read_FCNodeObject(db_node_name.v, &p_node, &entry); if (rval != SUCCESS) return rval; ISNSdbProcessFCNodeOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_node); } } else { /* Search the node table */ ISNS_DBKey key = { 0 }; key.tag = NODE_NAME_KEY; while (SNSdbGetNextOfKey (&key) == SUCCESS) { memset (&db_node_name, 0, sizeof (db_node_name)); __ISNS_COPY (db_node_name.v, sizeof(db_node_name.v), key.val.node_key.v, ISNS_NODE_NAME_SIZE); db_node_name.v[8] = (char)SOIP_DB_Node_Id; rval = read_FCNodeObject(db_node_name.v, &p_node, &entry); if (rval != SUCCESS) return rval; ISNSDisplay_FCNode (p_node); ISNSdbProcessFCNodeOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_node); } } return ISNS_NO_ERR; } /********************************************************************* *********************************************************************/ static int SNSdbGetAttrPortal (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Attr * src_attr, ISNS_Msg_Descp * md, ISNS_Msg * p_rsp_msg) { int ii; ISNS_Key *key = NULL; ISNS_Attr *attr; SOIP_Portal *p_portal; SOIP_Entity *p_entity; SOIP_Ifcp *p_port; SOIP_Portal_Key db_portal; int entityKeyFlag; int portalIpKeyFlag; int portalPortKeyFlag; int portalIdxKeyFlag; int iSCSINodeIdKeyFlag; int portNameKeyFlag; int foundFlag; ISNS_LIST_NODE *pnode; char *p_portal_name; ISNS_DBKey key2 = { 0 }; int rval; __DEBUG (isns_query_debug &1, SNSdbGetAttrPortal); foundFlag = FALSE; /* Scan the keys */ entityKeyFlag = -1; portalIpKeyFlag = -1; portalPortKeyFlag = -1; iSCSINodeIdKeyFlag = -1; portNameKeyFlag = -1; portalIdxKeyFlag = -1; for (ii = 0; ii < MAX_PARSE_ATTRS && key_indx[ii]; ii++) { key = (ISNS_Key *)(key_indx[ii]); switch (key->tag) { case ISNS_ENTITY_ID: entityKeyFlag = ii; break; case ISNS_PORTAL_IP: if (key->len > 0) portalIpKeyFlag = ii; break; case ISNS_PORTAL_PORT: portalPortKeyFlag = ii; break; case ISNS_ISCSI_NODE_ID: iSCSINodeIdKeyFlag = ii; break; case ISNS_PORT_NAME: portNameKeyFlag = ii; break; case ISNS_PORTAL_IDX: portalIdxKeyFlag = ii; break; default: break; } } if (portalPortKeyFlag != -1 || portalIpKeyFlag != -1) { /* Fetch Portal */ if (portalPortKeyFlag == -1 || portalIpKeyFlag == -1) { __LOG_ERROR ("***Located only one required portal key."); return (ISNS_MSG_FMT_ERR); } attr = (ISNS_Attr *) key_indx[portalPortKeyFlag]; db_portal.ip_port=attr->val.ip_port; attr = (ISNS_Attr *) key_indx[portalIpKeyFlag]; __ISNS_COPY (db_portal.ip_addr.v, sizeof(db_portal.ip_addr.v), &attr->val, attr->len); rval = read_PortalObject(&db_portal, &p_portal, &entry2); __DEBUG (isns_query_debug &1,Read Portal from database rval:%i,rval); if (rval != SUCCESS) return rval; rval = Check_Permission (src_attr, PORTAL_ID_KEY, p_portal); if (rval == SUCCESS) { SNSProcessPortalOpAttr (p_rsp_msg, (ISNS_Attr **)attr_indx, p_portal); foundFlag = TRUE; } } else if (portalIdxKeyFlag != -1) { void *ptr; /* Fetch Portal */ attr = (ISNS_Attr *) key_indx[portalIdxKeyFlag]; rval = read_PortalidxObject(attr->val.index, &ptr, &entry3); if (rval != SUCCESS) return rval; __ISNS_COPY (&db_portal, sizeof(db_portal), ptr, sizeof(db_portal)); rval = read_PortalObject(&db_portal, &p_portal, &entry2); if (rval != SUCCESS) return rval; rval = Check_Permission (src_attr, PORTAL_ID_KEY, p_portal); if (rval == SUCCESS) { SNSProcessPortalOpAttr (p_rsp_msg, (ISNS_Attr **)attr_indx, p_portal); foundFlag = TRUE; } } else if (entityKeyFlag != -1) { /* Fetch entity from hash */ if (ISNS_NO_ERR != read_EntityObject ((char *)&key->val, &p_entity, &entry)) { return (ISNS_NO_SUCH_ENTRY_ERR); } /* Cycle through all portal */ pnode=NULL; while ((pnode=GetNextNode(&p_entity->iportal_list, pnode))) { rval = read_PortalObject(GetNodeData(pnode), &p_portal, &entry2); if (rval != SUCCESS) return rval; rval = Check_Permission (src_attr, PORTAL_ID_KEY, p_portal); if (rval == SUCCESS) { SNSProcessPortalOpAttr (p_rsp_msg, (ISNS_Attr **)attr_indx, p_portal); foundFlag = TRUE; } } /* end for */ } else if (portNameKeyFlag != -1) { /* Fetch iFCP Node */ key = (ISNS_Key *)(key_indx[portNameKeyFlag]); rval = read_FCPortObject(key->val.port_name.v, &p_port, &entry); if (rval != SUCCESS) return rval; /* Fetch Entity */ if (ISNS_NO_ERR != read_EntityObject (p_port->entity_id.id, &p_entity, &entry)) { return (ERROR); } /* Cycle through all portal */ pnode=NULL; while ((pnode=GetNextNode(&p_entity->iportal_list, pnode))) { rval = read_PortalObject(GetNodeData(pnode), &p_portal, &entry2); if (rval != SUCCESS) return rval; rval = Check_Permission (src_attr, PORTAL_ID_KEY, p_portal); if (rval == SUCCESS) { SNSProcessPortalOpAttr (p_rsp_msg, (ISNS_Attr **)attr_indx, p_portal); foundFlag = TRUE; } } /* end for */ } else if (iSCSINodeIdKeyFlag != -1) { SOIP_ISCSI_Node_Id db_node_name; SOIP_Iscsi *p_node; /* Fetch iSCSI Node */ key = (ISNS_Key *)(key_indx[iSCSINodeIdKeyFlag]); memset (&db_node_name, 0, sizeof (db_node_name)); __ISNS_COPY (db_node_name.v, sizeof(db_node_name.v), &key->val, key->len); rval = read_ISCSIObject(db_node_name.v, &p_node, &entry); if (rval != SUCCESS) return rval; rval = Check_Permission (src_attr, ISCSI_ID_KEY, p_node); if (rval != SUCCESS) { __DEBUG(isns_query_debug & 1, "***ERROR Invalid dd"); return (ISNS_NO_SUCH_ENTRY_ERR); } rval = read_EntityObject (p_node->entity_id.id, &p_entity, &entry); if (rval != SUCCESS) return rval; /* Cycle through all portal */ pnode=NULL; while ((pnode=GetNextNode(&p_entity->iportal_list, pnode))) { rval = read_PortalObject(GetNodeData(pnode), &p_portal, &entry2); if (rval != SUCCESS) return rval; SNSProcessPortalOpAttr (p_rsp_msg, (ISNS_Attr **)attr_indx, p_portal); foundFlag = TRUE; } /* end for */ } else { /* No Key */ SOIP_Portal_Key db_portal_key; p_portal_name = NULL; key2.tag = PORTAL_ID_KEY; key2.len = 0; while (SNSdbGetNextOfKey(&key2) == SUCCESS) { __ISNS_COPY(&db_portal_key, sizeof(SOIP_Portal_Key), &key2.val.portal_key, sizeof(SOIP_Portal_Key)); __DEBUG (isns_query_debug &1,read next portal db entry); rval = read_PortalObject(&db_portal_key, &p_portal, &entry2); if (rval != SUCCESS) return rval; rval = Check_Permission (src_attr, PORTAL_ID_KEY, p_portal); if (rval == SUCCESS) { SNSProcessPortalOpAttr (p_rsp_msg, (ISNS_Attr **)attr_indx, p_portal); foundFlag = TRUE; } } } if (!foundFlag) return (ISNS_NO_SUCH_ENTRY_ERR); return (ISNS_NO_ERR); } /********************************************************************* _SNSdbGetAttrPort Gets the attributes for an iFCP node query. *********************************************************************/ static int SNSdbGetAttrPort (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Attr * src_attr, ISNS_Msg_Descp * md, ISNS_Msg * p_rspmsg) { int ii; ISNS_Key *key; ISNS_Attr *attr; SOIP_Ifcp *p_port; SOIP_Entity *p_entity; SOIP_Portal *p_portal; SOIP_Portal_Key db_portal; int entityKeyFlag; int portKeyFlag; int fc4TypesKeyFlag; int portalIpKeyFlag; int portalPortKeyFlag; int nodeKeyFlag; int foundFlag; ISNS_LIST_NODE *pnode; int rval; SOIP_DB_Node_Name db_node_name; SOIP_Fc_Node *p_node; foundFlag = FALSE; /* Scan the keys */ entityKeyFlag = -1; portKeyFlag = -1; fc4TypesKeyFlag = -1; portalIpKeyFlag = -1; portalPortKeyFlag = -1; nodeKeyFlag = -1; for (ii = 0; ii < MAX_PARSE_ATTRS && key_indx[ii]; ii++) { key = (ISNS_Key *)(key_indx[ii]); switch (key->tag) { case ISNS_ENTITY_ID: entityKeyFlag = ii; break; case ISNS_PORT_NAME: portKeyFlag = ii; break; case ISNS_FC4_TYPE: fc4TypesKeyFlag = ii; break; case ISNS_PORTAL_IP: portalIpKeyFlag = ii; break; case ISNS_PORTAL_PORT: portalPortKeyFlag = ii; break; case ISNS_NODE_NAME: nodeKeyFlag = ii; break; default: break; } } if (portKeyFlag != -1) { portKeyFlag = ISNSFindTag (0, ISNS_PORT_NAME, key_indx); do { key = (ISNS_Key *) key_indx[portKeyFlag]; rval = read_FCPortObject(key->val.port_name.v, &p_port, &entry); if (rval != SUCCESS) return rval; rval = Check_Permission (src_attr, PORT_NAME_KEY, p_port); if (rval == SUCCESS) { ISNSdbProcessPortOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_port); foundFlag = TRUE; } portKeyFlag = ISNSFindTag (portKeyFlag + 1, ISNS_PORT_NAME, key_indx); } while (portKeyFlag != -1); } else if (nodeKeyFlag != -1) { /* Fetch the node */ key = (ISNS_Key *)(key_indx[nodeKeyFlag]); memset (&db_node_name, 0, sizeof (db_node_name)); __ISNS_COPY (db_node_name.v, sizeof(db_node_name.v), &key->val, ISNS_NODE_NAME_SIZE); db_node_name.v[8] = (char)SOIP_DB_Node_Id; rval = read_FCNodeObject(db_node_name.v, &p_node, &entry); if (rval != SUCCESS) return rval; pnode=NULL; while ((pnode=GetNextNode(&p_node->port_list, pnode))) { char *pname=GetNodeData(pnode); rval = read_FCPortObject(pname, &p_port, &entry2); if ( rval != SUCCESS) return rval; rval = Check_Permission (src_attr, PORT_NAME_KEY, p_port); if (rval == SUCCESS) { ISNSdbProcessPortOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_port); foundFlag = TRUE; } } } else if (entityKeyFlag != -1) { SOIP_Entity_Key db_entity_id={{0}}; key = (ISNS_Key *)(key_indx[entityKeyFlag]); strncpy ( db_entity_id.id, (char *)&key->val, sizeof(db_entity_id.id) ); rval = read_EntityObject (db_entity_id.id, &p_entity, &entry); if (rval != SUCCESS) return rval; /* Scan the entity's port list */ pnode=NULL; while ((pnode=GetNextNode(&p_entity->iportal_list, pnode))) { /* Fetch the Port Object */ rval = read_FCPortObject(GetNodeData(pnode), &p_port, &entry2); if (rval != SUCCESS) return rval; rval = Check_Permission (src_attr, PORT_NAME_KEY, p_port); if (rval == SUCCESS) { ISNSdbProcessPortOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_port); foundFlag = TRUE; } } } else if ((portalIpKeyFlag != -1) || (portalPortKeyFlag != -1)) { if ((portalIpKeyFlag == -1) || (portalPortKeyFlag == -1)) { __LOG_ERROR ("***Located only one required portal key."); return (ISNS_INVALID_QUERY_ERR); } attr = (ISNS_Attr *) key_indx[portalPortKeyFlag]; __ISNS_COPY (db_portal.ip_addr.v, sizeof(db_portal.ip_addr.v), &attr->val, attr->len); attr = (ISNS_Attr *) key_indx[portalIpKeyFlag]; db_portal.ip_port=attr->val.ip_port; rval = read_PortalObject(&db_portal, &p_portal, &entry2); if (rval != SUCCESS) return rval; else { rval = read_EntityObject(p_portal->entity_id.id, &p_entity, &entry); if (rval != SUCCESS) return rval; /* Scan the entity's port list */ pnode=NULL; while ((pnode=GetNextNode(&p_entity->ifcp_node_list, pnode))) { rval = read_FCPortObject(GetNodeData(pnode), &p_port, &entry2); if (rval != SUCCESS) return rval; rval = Check_Permission (src_attr, PORT_NAME_KEY, p_port); if (rval == SUCCESS) { ISNSdbProcessPortOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_port); foundFlag = TRUE; } } } } else if (fc4TypesKeyFlag != -1) { __DEBUG (isns_query_debug & 1, (Not Implemented)); return (ERROR); } else { /* Return all Ports */ ISNS_DBKey key = { 0 }; key.tag = PORT_NAME_KEY; while (SNSdbGetNextOfKey (&key) == SUCCESS) { rval = read_FCPortObject(key.val.port_key.v, &p_port, &entry); if (rval != SUCCESS) return rval; ISNSDisplay_iFCPNode (p_port); ISNSdbProcessPortOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_port); foundFlag = TRUE; } } if (!foundFlag) return (ISNS_NO_SUCH_ENTRY_ERR); return ISNS_NO_ERR; } /********************************************************************* This is called during a query for iSCSI attributes. *********************************************************************/ static int ISNSdbGetAttrISCSI (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Attr * src_attr, ISNS_Msg_Descp * md, ISNS_Msg * p_rspmsg) { int foundFlag; int ii; int nodeKeyIndex; int nodeTypeKeyIndex; int nodeIdxKeyIndex; int entityKeyIndex; int portalIpKeyIndex; int portalPortKeyIndex; SOIP_Entity *p_entity; ISNS_Key *key=NULL; SOIP_Iscsi *p_node; SOIP_ISCSI_Node_Id db_node_name; ISNS_LIST_NODE *pnode; int rval; int rc; __DEBUG (isns_query_debug &1,(Attribute Query - ISCSI:%s),(char *)&src_attr->val); foundFlag = FALSE; ISNSTouchEntity( src_attr ); /* Scan the keys */ nodeKeyIndex = -1; nodeTypeKeyIndex = -1; entityKeyIndex = -1; portalIpKeyIndex = -1; portalPortKeyIndex = -1; nodeIdxKeyIndex = -1; for (ii = 0; ii < MAX_PARSE_ATTRS && key_indx[ ii ]; ii++) { key = (ISNS_Key *)(key_indx[ ii ]); switch (key->tag) { case ISNS_ISCSI_NODE_ID: if (key->len > 0) nodeKeyIndex = ii; break; case ISNS_ISCSI_TYPE: nodeTypeKeyIndex = ii; break; case ISNS_ENTITY_ID: entityKeyIndex = ii; break; case ISNS_PORTAL_IP: portalIpKeyIndex = ii; break; case ISNS_PORTAL_PORT: portalPortKeyIndex = ii; break; case ISNS_ISCSI_IDX: nodeIdxKeyIndex = ii; break; default: /* Error condition */ break; } } /* Order is important */ if (nodeKeyIndex != -1) { __DEBUG (isns_query_debug &1,nodeKeyIndex); nodeKeyIndex = ISNSFindTag (0, ISNS_ISCSI_NODE_ID, key_indx); while (nodeKeyIndex != -1) { key = (ISNS_Key *)(key_indx[ nodeKeyIndex ]); /* Fetch the node */ memset (&db_node_name, 0, sizeof (db_node_name)); __ISNS_COPY (db_node_name.v, sizeof(db_node_name.v), &key->val, key->len); rval = read_ISCSIObject(db_node_name.v, &p_node, &entry); if (rval != SUCCESS) return rval; rval = Check_Permission (src_attr, ISCSI_ID_KEY, p_node); if (rval == SUCCESS) { __DEBUG (isns_query_debug &1,call ISNSdbProcessICSCIOpAttr); ISNSdbProcessISCSIOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_node); foundFlag = TRUE; } nodeKeyIndex = ISNSFindTag (nodeKeyIndex + 1, ISNS_ISCSI_NODE_ID, key_indx); } } else if (nodeIdxKeyIndex != -1) { nodeIdxKeyIndex = ISNSFindTag (0, ISNS_ISCSI_IDX, key_indx); while (nodeIdxKeyIndex != -1) { void *ptr; key = (ISNS_Key *)(key_indx[nodeIdxKeyIndex]); rval = read_ISCSIidxObject(key->val.index, &ptr, &entry3); if (rval != SUCCESS) return rval; /* Fetch the node */ memset (&db_node_name, 0, sizeof (db_node_name)); strncpy ((char *) db_node_name.v, ptr, sizeof(db_node_name.v) ); rval = read_ISCSIObject(db_node_name.v, &p_node, &entry); if (rval != SUCCESS) return rval; rval = Check_Permission (src_attr, ISCSI_ID_KEY, p_node); if (rval == SUCCESS) { ISNSdbProcessISCSIOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_node); foundFlag = TRUE; } nodeIdxKeyIndex = ISNSFindTag (nodeIdxKeyIndex + 1, ISNS_ISCSI_IDX, key_indx); } } else if (entityKeyIndex != -1) { int rval; key = (ISNS_Key *) (key_indx[entityKeyIndex]); rval = read_EntityObject((char *)&key->val, &p_entity, &entry); if (rval) return (rval); /* Check to make sure this is an iSCSI Entity */ if (p_entity->eid_type != ENTITY_TYPE_ISCSI) { __LOG_ERROR ("***ERROR: Expected an iSCSI Entity."); return (ERROR); } /* Scan the entity's iSCSI List */ pnode=NULL; while ((pnode=GetNextNode(&p_entity->iscsi_node_list, pnode))) { /* Fetch the iSCSI Node */ rval = read_ISCSIObject(GetNodeData(pnode), &p_node, &entry2); if (rval != SUCCESS) return rval; rval = Check_Permission (src_attr, ISCSI_ID_KEY, p_node); if (rval == SUCCESS) { ISNSdbProcessISCSIOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_node); foundFlag = TRUE; } } } else if (portalPortKeyIndex != -1 || portalIpKeyIndex != -1) { SOIP_Portal_Key db_portal; SOIP_Portal * p_portal; __DEBUG (isns_query_debug &1,(Search for Portal)); memset (&db_portal, 0, sizeof (db_portal)); if (portalPortKeyIndex == -1 || portalIpKeyIndex == -1) { __LOG_ERROR ("***ERROR: Didn't have all the Portal Keys."); return (ERROR); } /* Get Portal */ key = (ISNS_Key *)(key_indx[portalPortKeyIndex]); db_portal.ip_port=key->val.ip_port; key = (ISNS_Key *) key_indx[portalIpKeyIndex]; __ISNS_COPY (db_portal.ip_addr.v, sizeof(db_portal.ip_addr.v), key->val.ip_addr.v, key->len); rval = read_PortalObject(&db_portal, &p_portal, &entry); if (rval != SUCCESS) return rval; else { rval = read_EntityObject(p_portal->entity_id.id, &p_entity, &entry); if (rval != SUCCESS) return rval; /* Scan the entity's iSCSI List */ pnode=NULL; while ((pnode=GetNextNode(&p_entity->iscsi_node_list, pnode))) { /* Fetch the iSCSI Node */ rval = read_ISCSIObject(GetNodeData(pnode), &p_node, &entry2); if (rval != SUCCESS) return rval; rval = Check_Permission (src_attr, ISCSI_ID_KEY, p_node); if (rval == SUCCESS) { ISNSdbProcessISCSIOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_node); foundFlag = TRUE; } } } } else { /* Search the node table */ ISNS_DBKey qkey = { 0 }; __DEBUG (isns_query_debug &1,search node table); qkey.tag = ISCSI_ID_KEY; while (SNSdbGetNextOfKey (&qkey) == SUCCESS) { rval = read_ISCSIObject(qkey.val.iscsi_key.v, &p_node, &entry); if (rval != SUCCESS) __LOG_ERROR ("Error in iscsi node database for key:%s",qkey.val.iscsi_key.v); if (nodeTypeKeyIndex != -1) { key = (ISNS_Key *)(key_indx[nodeTypeKeyIndex]); __DEBUG(isns_query_debug &1, key->val.node_type:%i p_node->type:%i,key->val.node_type,p_node->type); if (!(*(uint32_t *) &key->val & p_node->type)) continue; } rval = Check_Permission (src_attr, ISCSI_ID_KEY, p_node); if (rval == SUCCESS) { /* if the first found entry then add the key attr */ if (!foundFlag) { if (nodeTypeKeyIndex != -1) { ISNSAppendKey(p_rspmsg, ISNS_ISCSI_TYPE, key->len, (char *)&key->val, 0); ISNSAppendKey(p_rspmsg, ISNS_DELIMITER, 0, NULL, 0); } } ISNSdbProcessISCSIOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_node); foundFlag = TRUE; } } } rc = ISNS_NO_ERR; if (!foundFlag) rc = ISNS_NO_SUCH_ENTRY_ERR; __DEBUG (isns_query_debug &1,return from GetAttrISCSI rc:%i,rc); return rc; } /********************************************************************* Implements the GetNextAttr iSNS Command. *********************************************************************/ int ISNSGetNextAttr( ISNS_Msg_Descp *p_md, ISNS_Msg * p_rspmsg ) { int ii; int found; int nodeKeyIndex; int entityKeyIndex; int portalIpKeyIndex; int portalPortKeyIndex; int entityIdxKeyIndex; int portalIdxKeyIndex; int iscsiIdxKeyIndex; int portKeyIndex; int ddKeyIndex; int ddsKeyIndex; ISNS_DBKey qkey = { 0 }; ISNS_Key *key; ISNS_Attr *src_attr; ISNS_Attr *attr_indx[SNS_MAX_ATTRS]; ISNS_Attr *key_indx[SNS_MAX_ATTRS]; SOIP_Iscsi *p_node; int rval; SOIP_Dd *p_dd; SOIP_Dds *p_dds; __DEBUG (isns_query_debug &1, (ISNSGetNextAttr)); ISNSParseMsg( &p_md->msg, attr_indx, key_indx,&src_attr ); /* Scan the keys */ nodeKeyIndex = -1; entityKeyIndex = -1; portalIpKeyIndex = -1; portalPortKeyIndex = -1; portKeyIndex = -1; iscsiIdxKeyIndex = -1; portalIdxKeyIndex = -1; entityIdxKeyIndex = -1; ddKeyIndex = -1; ddsKeyIndex = -1; for (ii = 0; ii < MAX_PARSE_ATTRS && key_indx[ii]; ii++) { key = (ISNS_Key *)(key_indx[ii]); __DEBUG (isns_query_debug &1,(keytag:%i (%s)),key->tag,isnsTagText(key->tag)); switch (key->tag) { case ISNS_ISCSI_NODE_ID: nodeKeyIndex = ii; break; case ISNS_ENTITY_ID: entityKeyIndex = ii; break; case ISNS_PORT_NAME: portKeyIndex = ii; break; case ISNS_PORTAL_IP: portalIpKeyIndex = ii; break; case ISNS_PORTAL_PORT: portalPortKeyIndex = ii; break; case ISNS_ISCSI_IDX: iscsiIdxKeyIndex = ii; break; case ISNS_ENTITY_IDX: entityIdxKeyIndex = ii; break; case ISNS_PORTAL_IDX: portalIdxKeyIndex = ii; break; case ISNS_DD_ID: ddKeyIndex = ii; break; case ISNS_DDS_ID: ddsKeyIndex = ii; break; default: /* Error condition */ break; } } if ( ddKeyIndex != -1 ) { memset(&qkey, 0, sizeof(qkey)); qkey.tag = DD_ID_KEY; key = (ISNS_Key *)(key_indx[ ddKeyIndex ]); if ( key->len && key->val.dd_id) { /* Key is being provided */ qkey.val.dd_key.id = key->val.dd_id; qkey.len = DD_KEY_SIZE; } found=FALSE; while (!found) { if (SNSdbGetNextOfKey (&qkey) != SUCCESS) { return (ISNS_NO_SUCH_ENTRY_ERR); } rval = read_DDObject(qkey.val.dd_key.id, &p_dd, &entry); if (rval != SUCCESS) { __LOG_ERROR("Error in dd database not found id:%i",qkey.val.dd_key.id); return rval; } ISNSAppendKey (p_rspmsg, ISNS_DD_ID, ISNS_DD_ID_SIZE, NULL, p_dd->id); ISNSAppendKey (p_rspmsg, 0, 0, NULL, 0); ISNSdbProcessDDOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_dd); found=TRUE; } } else if ( ddsKeyIndex != -1 ) { memset(&qkey, 0, sizeof(qkey)); qkey.tag = DDS_ID_KEY; key = (ISNS_Key *)(key_indx[ ddsKeyIndex ]); if ( key->len && key->val.dds_id) { /* Key is being provided */ qkey.val.dds_key.id = key->val.dds_id; qkey.len = DDS_KEY_SIZE; } found=FALSE; while (!found) { if (SNSdbGetNextOfKey (&qkey) != SUCCESS) { return (ISNS_NO_SUCH_ENTRY_ERR); } rval = read_DDSObject(qkey.val.dds_key.id, &p_dds, &entry); if (rval != SUCCESS) { __LOG_ERROR("Error dds database missing record:%i",qkey.val.dds_key.id); return rval; } ISNSAppendKey (p_rspmsg, ISNS_DDS_ID,ISNS_DDS_ID_SIZE, NULL, p_dds->id); ISNSAppendKey (p_rspmsg, 0, 0, NULL, 0); ISNSdbProcessDDSOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_dds); found=TRUE; } } else if ( nodeKeyIndex != -1 || iscsiIdxKeyIndex!=-1 ) { __DEBUG (isns_query_debug &1,process nodeKeyIndex); memset(&qkey, 0, sizeof(qkey)); qkey.tag = ISCSI_ID_KEY; if ( nodeKeyIndex !=-1 ) { __DEBUG (isns_query_debug &1,(nodeKeyIndex:%i),nodeKeyIndex); key=(ISNS_Key *)(key_indx[nodeKeyIndex]); __DEBUG (isns_query_debug &1,key length:%i,key->len); __DEBUG (isns_query_debug &1,key:%s,(char *)&key->val); if (key->len) { qkey.len = strlen((char *)&key->val); __ISNS_COPY (&qkey.val, sizeof(qkey.val), &key->val, key->len); } } else if (iscsiIdxKeyIndex != -1) { void *ptr; key=(ISNS_Key *)(key_indx[iscsiIdxKeyIndex]); if (key->len && key->val.index) { rval = read_ISCSIidxObject(key->val.index, &ptr, &entry3); if (rval != SUCCESS) return rval; qkey.len = strlen(ptr); __ISNS_COPY (&qkey.val, sizeof (qkey.val), ptr, qkey.len); } } found=FALSE; while (!found) { __DEBUG (isns_query_debug &1, (GetNextOfKey:%s),(char *)&qkey.val); if (SNSdbGetNextOfKey (&qkey) != SUCCESS) { return (ISNS_NO_SUCH_ENTRY_ERR); } rval = read_ISCSIObject(qkey.val.iscsi_key.v, &p_node, &entry); if (rval != SUCCESS) { __LOG_ERROR ("ERROR reading Key: %s",qkey.val.iscsi_key.v); return rval; } rval = Check_Permission (src_attr, ISCSI_ID_KEY, p_node); if (rval != SUCCESS) { continue; } ISNSAppendKey (p_rspmsg, ISNS_ISCSI_NODE_ID, PAD4 (strlen ((char *)&qkey.val)), (char *)&qkey.val, 0); ISNSAppendKey (p_rspmsg, 0, 0, NULL, 0); ISNSdbProcessISCSIOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_node); found=TRUE; } } else if (entityKeyIndex!=-1 || entityIdxKeyIndex!=-1) { SOIP_Entity *p_entity; memset(&qkey, 0, sizeof(qkey)); qkey.tag = ENTITY_ID_KEY; if (entityKeyIndex !=-1) { key=(ISNS_Key *)(key_indx[entityKeyIndex]); if (key->len) { /* Key is being provided */ strncpy(qkey.val.entity_key.id, (char *)&key->val, sizeof(qkey.val.entity_key.id) ); qkey.len = PAD4(strlen(qkey.val.entity_key.id)); } } else if (entityIdxKeyIndex != -1) { void *ptr; key = (ISNS_Key *)(key_indx[entityIdxKeyIndex]); if (key->len && key->val.index) { rval = read_EntityidxObject(key->val.index, &ptr, &entry3); if (rval != SUCCESS) return rval; strncpy(qkey.val.entity_key.id, (char *)ptr, sizeof(qkey.val.entity_key.id) ); qkey.len = PAD4(strlen(qkey.val.entity_key.id)); } } found=FALSE; while (!found) { if (SNSdbGetNextOfKey (&qkey) != SUCCESS) { return (ISNS_NO_SUCH_ENTRY_ERR); } rval = read_EntityObject(qkey.val.entity_key.id, &p_entity, &entry); if (rval) return (rval); rval = Check_Permission (src_attr, ENTITY_ID_KEY, p_entity); if (rval != SUCCESS) { continue; } ISNSAppendKey (p_rspmsg, ISNS_ENTITY_ID, PAD4 (strlen (p_entity->eid.id)), p_entity->eid.id, 0); ISNSAppendKey (p_rspmsg, 0, 0, NULL, 0); ISNSdbProcessEntityOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_entity); found=TRUE; } } else if (portKeyIndex!=-1) { SOIP_Ifcp *p_port; key=(ISNS_Key *)(key_indx[portKeyIndex]); qkey.tag = PORT_NAME_KEY; qkey.len = key->len; __ISNS_COPY (&qkey.val, sizeof(qkey.val), &key->val, key->len); found=FALSE; while (!found) { if (SNSdbGetNextOfKey (&qkey) != SUCCESS) { return (ISNS_NO_SUCH_ENTRY_ERR); } rval = read_FCPortObject(qkey.val.port_key.v, &p_port, &entry); if (rval != SUCCESS) { __DEBUG (isns_query_debug &1,(Error reading getnext)); return 0; } rval = Check_Permission (src_attr, PORT_NAME_KEY, p_port); if (rval != SUCCESS) { continue; } ISNSAppendKey (p_rspmsg, ISNS_PORT_NAME, ISNS_PORT_NAME_SIZE, (char *)&qkey.val, 0); ISNSAppendKey (p_rspmsg, 0, 0, NULL, 0); ISNSdbProcessPortOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_port); found=TRUE; } } else if ((portalPortKeyIndex!=-1 && portalIpKeyIndex!=-1) || portalIdxKeyIndex != -1) { SOIP_Portal * p_portal; SOIP_Portal_Key db_portal; memset(&db_portal, 0, sizeof(db_portal)); qkey.tag = PORTAL_ID_KEY; qkey.len = 0; if (portalIdxKeyIndex != -1) { void *ptr; key = (ISNS_Key *)(key_indx[portalIdxKeyIndex]); if (key->len && key->val.index) { rval = read_PortalidxObject(key->val.index, &ptr, &entry3); if (rval != SUCCESS) return rval; __ISNS_COPY (&qkey.val, sizeof(qkey.val), ptr, sizeof(db_portal)); qkey.len = sizeof(SOIP_Portal_Key); } } else { key = (ISNS_Key *)(key_indx[portalPortKeyIndex]); db_portal.ip_port=key->val.ip_port; qkey.len += key->len; key = (ISNS_Key *)(key_indx[portalIpKeyIndex]); __ISNS_COPY (db_portal.ip_addr.v, sizeof(db_portal.ip_addr.v), key->val.ip_addr.v, key->len); qkey.len += key->len; __ISNS_COPY (&qkey.val, sizeof(qkey.val), &db_portal, sizeof (SOIP_Portal_Key)); } found=FALSE; while (!found) { if (SNSdbGetNextOfKey (&qkey) != SUCCESS) { return (ISNS_NO_SUCH_ENTRY_ERR); } __ISNS_COPY (&db_portal, sizeof(SOIP_DB_Portal), &qkey.val.portal_key, sizeof(SOIP_DB_Portal)); rval = read_PortalObject(&db_portal, &p_portal, &entry); if (rval != SUCCESS) { __DEBUG (isns_query_debug &1,(getnextkey error)); } rval = Check_Permission (src_attr, PORTAL_ID_KEY, p_portal); if (rval != SUCCESS) { continue; } ISNSAppendKey (p_rspmsg, ISNS_PORTAL_IP,ISNS_PORTAL_IP_SIZE,(char *)&qkey.val, 0); ISNSAppendKey (p_rspmsg, ISNS_PORTAL_PORT, ISNS_PORTAL_PORT_SIZE, (char *)&qkey.val + ISNS_PORTAL_IP_SIZE, 0); ISNSAppendKey (p_rspmsg, 0, 0, NULL, 0); SNSProcessPortalOpAttr (p_rspmsg, (ISNS_Attr **)attr_indx, p_portal); found=TRUE; } } else { /* Error Condition */ return (ISNS_MSG_FMT_ERR); } if (!found) return (ISNS_NO_SUCH_ENTRY_ERR); return (ISNS_NO_ERR); } /******************************************************************** ********************************************************************/ int ISNSGetNextDDSMember ( ISNS_Msg_Descp *p_md, ISNS_Msg * p_rspmsg ) { int ddsKeyIndex; int ddKeyIndex; ISNS_Attr *p_attr; SOIP_Dds *p_dds; SOIP_DD_Key dds_key; ISNS_LIST_NODE *plnode; ISNS_Attr *src_attr; ISNS_Attr *attr_indx[SNS_MAX_ATTRS]; ISNS_Attr *key_indx[SNS_MAX_ATTRS]; int rval; ISNSParseMsg( &p_md->msg, attr_indx, key_indx, &src_attr ); ddsKeyIndex = ISNSFindTag(0, ISNS_DDS_ID, key_indx); ddKeyIndex = ISNSFindTag(0, ISNS_DD_ID, key_indx); if (ddsKeyIndex == -1) { return (ISNS_MSG_FMT_ERR); } p_attr=(ISNS_Attr *)key_indx[ddsKeyIndex]; dds_key.id = p_attr->val.dds_id; rval = read_DDSObject(dds_key.id, &p_dds, &entry); if (rval != SUCCESS) return rval; /* Append Keys */ p_attr = NULL; if ( ddKeyIndex != -1 ) { p_attr = (ISNS_Attr *)key_indx[ ddKeyIndex ]; } plnode = NULL; if (p_attr && p_attr->val.dd_id != 0) { plnode = FindNode( &p_dds->dd_list, (char *)&p_attr->val.dd_id, sizeof(uint32_t) ); if (!plnode) return (ISNS_INVALID_QUERY_ERR); } plnode = GetNextNode(&p_dds->dd_list, plnode); if ( plnode ) { /* Append Attribute */ ISNSAppendAttr(p_rspmsg, ISNS_DD_ID, ISNS_DD_ID_SIZE, NULL, *(uint32_t *)GetNodeData(plnode)); } return ( plnode?ISNS_NO_ERR:ISNS_NO_SUCH_ENTRY_ERR ); } int ISNSGetNextEntityPortal( ISNS_Msg_Descp *p_md, ISNS_Msg * p_rspmsg ) { int portalKeyIndex; int entityKeyIndex; ISNS_Attr *p_attr; ISNS_LIST_NODE *plnode; ISNS_Attr *src_attr; ISNS_Attr *attr_indx[SNS_MAX_ATTRS]; ISNS_Attr *key_indx[SNS_MAX_ATTRS]; int foundFlag; void *ptr; SOIP_Entity *p_entity; PORTAL_LIST_ENTRY *p_portalListEntry; int rval; ISNSParseMsg( &p_md->msg, attr_indx, key_indx, &src_attr ); entityKeyIndex = ISNSFindTag(0, ISNS_ENTITY_IDX, key_indx); portalKeyIndex = ISNSFindTag(0, ISNS_PORTAL_IDX, key_indx); if (entityKeyIndex == -1) { return (ISNS_MSG_FMT_ERR); } /* Entity ID found in key */ p_attr = (ISNS_Attr *)(key_indx[entityKeyIndex]); rval = read_EntityidxObject(p_attr->val.index, &ptr, &entry3); if (rval != SUCCESS) return rval; /* Fetch entity from hash */ if (ISNS_NO_ERR != read_EntityObject ( ptr, &p_entity, &entry )) { return (ISNS_INVALID_QUERY_ERR); } p_attr = NULL; if ( portalKeyIndex != -1 ) { p_attr = (ISNS_Attr *)key_indx[ portalKeyIndex ]; } plnode = NULL; if (p_attr && p_attr->val.index != 0) { foundFlag = FALSE; while ( (plnode = GetNextNode(&p_entity->iportal_list, plnode)) ) { p_portalListEntry = (PORTAL_LIST_ENTRY *)GetNodeData(plnode); if ( p_portalListEntry->portal_idx == p_attr->val.index) { foundFlag = TRUE; break; } } if ( !foundFlag ) return (ISNS_INVALID_QUERY_ERR); } plnode = GetNextNode(&p_entity->iportal_list, plnode); if ( plnode ) { /* Append Attribute */ p_portalListEntry = (PORTAL_LIST_ENTRY *)GetNodeData(plnode); ISNSAppendAttr( p_rspmsg, ISNS_PORTAL_IDX, ISNS_PORTAL_IDX_SIZE, NULL, p_portalListEntry->portal_idx ); } return ( plnode?ISNS_NO_ERR:ISNS_NO_SUCH_ENTRY_ERR ); } /******************************************************************** Gets the next DD iSCSI Member. ********************************************************************/ int ISNSGetNextDDIscsiMember( ISNS_Msg_Descp *p_md, ISNS_Msg * p_rspmsg ) { int ddKeyIndex; int iscsiKeyIndex; ISNS_Attr *p_attr; SOIP_Dd *p_dd; ISNS_LIST_NODE *plnode; ISNS_Attr *src_attr; ISNS_Attr *attr_indx[SNS_MAX_ATTRS]; ISNS_Attr *key_indx[SNS_MAX_ATTRS]; SOIP_Dd_Member *p_member; int foundFlag; int rval; ISNSParseMsg( &p_md->msg, attr_indx, key_indx, &src_attr ); ddKeyIndex = ISNSFindTag(0, ISNS_DD_ID, key_indx); iscsiKeyIndex = ISNSFindTag(0, ISNS_DD_ISCSI_MEMBER_IDX, key_indx); if (ddKeyIndex == -1) { return (ISNS_MSG_FMT_ERR); } p_attr=(ISNS_Attr *)key_indx[ddKeyIndex]; rval = read_DDObject(p_attr->val.dd_id, &p_dd, &entry); if (rval != SUCCESS) return rval; /* Append Keys */ p_attr = NULL; if ( iscsiKeyIndex != -1 ) { p_attr = (ISNS_Attr *)key_indx[ iscsiKeyIndex ]; } plnode = NULL; if (p_attr && p_attr->val.index != 0) { foundFlag = FALSE; while ( (plnode = GetNextNode(&p_dd->member_list, plnode)) ) { p_member = (SOIP_Dd_Member *)GetNodeData(plnode); if ( p_member->type != ISNS_DD_ISCSI_MEMBER ) continue; if ( p_member->node_idx == p_attr->val.index ) { foundFlag = TRUE; break; } } if ( !foundFlag ) return (ISNS_INVALID_QUERY_ERR); } plnode = GetNextNode(&p_dd->member_list, plnode); if ( plnode ) { /* Append Attribute */ p_member = (SOIP_Dd_Member *)GetNodeData(plnode); ISNSAppendAttr(p_rspmsg, ISNS_DD_ISCSI_MEMBER_IDX, ISNS_ISCSI_IDX_SIZE, NULL, p_member->node_idx); } return ( plnode?ISNS_NO_ERR:ISNS_NO_SUCH_ENTRY_ERR ); } int ISNSdbProcessDDSOpAttr (ISNS_Msg * p_msg, ISNS_Attr ** attr_indx, SOIP_Dds *p_dds) { int ii; ISNS_Attr *attr; ISNS_LIST_NODE *pnode; int dd_id_Flag = -1; int dd_sym_Flag = -1; SOIP_Dd *p_dd; SOIP_DB_Entry lentry; int rval; dd_id_Flag = ISNSFindTag (0, ISNS_DD_ID, attr_indx); dd_sym_Flag = ISNSFindTag (0, ISNS_DDS_SYM_NAME, attr_indx); for (ii = 0; (ii < SNS_MAX_ATTRS) && (attr_indx[ii]); ii++) { attr = (ISNS_Attr *) attr_indx[ii]; switch (attr->tag) { case ISNS_DDS_ID: ISNSAppendAttr (p_msg, ISNS_DDS_ID, ISNS_DDS_ID_SIZE, NULL, p_dds->id); break; case ISNS_DDS_SYM_NAME: ISNSAppendAttr (p_msg, ISNS_DDS_SYM_NAME, PAD4 (strlen (p_dds->sym_name)), p_dds->sym_name, 0); break; case ISNS_DDS_STATUS: ISNSAppendAttr (p_msg, ISNS_DDS_STATUS, ISNS_DDS_STATUS_SIZE, NULL, p_dds->status); break; case ISNS_DD_SYM_NAME: pnode=NULL; while ((pnode=GetNextNode(&p_dds->dd_list, pnode))) { if (dd_id_Flag != -1 ) ISNSAppendAttr (p_msg, ISNS_DD_ID, ISNS_DD_ID_SIZE, NULL, *(uint32_t *)GetNodeData(pnode)); rval = read_DDObject(*(uint32_t *)GetNodeData(pnode), &p_dd, &lentry); if (rval == SUCCESS) { ISNSAppendAttr (p_msg, ISNS_DD_SYM_NAME, PAD4 (strlen (p_dd->sym_name)), p_dd->sym_name, 0); } } break; case ISNS_DD_ID: pnode=NULL; if (dd_sym_Flag == -1) { while ((pnode=GetNextNode(&p_dds->dd_list, pnode))) { ISNSAppendAttr (p_msg, ISNS_DD_ID, ISNS_DD_ID_SIZE, NULL, *(uint32_t *)GetNodeData(pnode)); } } break; default: break; } } return (0); } int ISNSdbProcessDDOpAttr (ISNS_Msg * p_msg, ISNS_Attr ** attr_indx, SOIP_Dd *p_dd) { int ii; ISNS_Attr *attr; ISNS_LIST_NODE *pnode; SOIP_Dd_Member *p_member; SOIP_DB_Entry lentry; int index_Flag = -1; int rval; SOIP_Dds *p_dds; for (ii = 0; (ii < SNS_MAX_ATTRS) && (attr_indx[ii]); ii++) { attr = (ISNS_Attr *) attr_indx[ii]; switch (attr->tag) { case ISNS_DD_ID: ISNSAppendAttr (p_msg, ISNS_DD_ID, ISNS_DD_ID_SIZE, NULL, p_dd->id); break; case ISNS_DD_SYM_NAME: ISNSAppendAttr (p_msg, ISNS_DD_SYM_NAME, PAD4 (strlen (p_dd->sym_name)), p_dd->sym_name, 0); break; case ISNS_DD_FEATURE_BITMAP: ISNSAppendAttr (p_msg, ISNS_DD_FEATURE_BITMAP, ISNS_DD_FEATURE_BITMAP_SIZE, NULL, p_dd->feature); break; case ISNS_DDS_ID: pnode=NULL; while ((pnode=GetNextNode(&p_dd->dds_list, pnode))) { ISNSAppendAttr (p_msg, ISNS_DDS_ID, ISNS_DDS_ID_SIZE, NULL, *(uint32_t *)GetNodeData(pnode)); } break; case ISNS_DDS_SYM_NAME: pnode=NULL; while ((pnode=GetNextNode(&p_dd->dds_list, pnode))) { rval = read_DDSObject(*(uint32_t *)GetNodeData(pnode), &p_dds, &lentry); if (rval == SUCCESS) { ISNSAppendAttr (p_msg, ISNS_DDS_SYM_NAME, PAD4(strlen(p_dds->sym_name)),p_dds->sym_name,0); } } break; case ISNS_DD_ISCSI_MEMBER: pnode=NULL; while ((pnode=GetNextNode(&p_dd->member_list, pnode))) { p_member=(SOIP_Dd_Member *)GetNodeData(pnode); if (p_member->type == ISNS_DD_ISCSI_MEMBER) { ISNSAppendAttr (p_msg, ISNS_DD_ISCSI_MEMBER, PAD4 (strlen (p_member->node_id)), p_member->node_id, 0); index_Flag = ISNSFindTag (0, ISNS_DD_ISCSI_MEMBER_IDX, attr_indx); if (index_Flag != -1 ) if (p_member->type == ISNS_DD_ISCSI_MEMBER) ISNSAppendAttr (p_msg, ISNS_DD_ISCSI_MEMBER_IDX, ISNS_DD_ISCSI_MEMBER_IDX_SIZE, NULL, p_member->node_idx); } } break; case ISNS_DD_IFCP_MEMBER: pnode=NULL; while ((pnode=GetNextNode(&p_dd->member_list, pnode))) { p_member=(SOIP_Dd_Member *)GetNodeData(pnode); if (p_member->type == ISNS_DD_IFCP_MEMBER) { ISNSAppendAttr (p_msg, ISNS_DD_IFCP_MEMBER, ISNS_PORT_NAME_SIZE, p_member->node_id, 0); index_Flag = ISNSFindTag (0, ISNS_DD_ISCSI_MEMBER_IDX, attr_indx); if (index_Flag != -1 ) if (p_member->type == ISNS_DD_ISCSI_MEMBER) ISNSAppendAttr (p_msg, ISNS_DD_ISCSI_MEMBER_IDX, ISNS_DD_ISCSI_MEMBER_IDX_SIZE, NULL, p_member->node_idx); } } break; default: break; } } return (0); } /********************************************************************* Appends iSCSI operational attributes to the msg. *********************************************************************/ int ISNSdbProcessISCSIOpAttr (ISNS_Msg * p_msg, ISNS_Attr ** attr_indx, SOIP_Iscsi * p_node) { int ii, jj; int fetchEntityFlag; int fetchPortalFlag; ISNS_Attr *q_attr; ISNS_LIST_NODE *pnode; SOIP_Entity *p_entity; SOIP_Portal *p_portal; SOIP_Portal_Group *p_portal_group = NULL; SOIP_Portal_Group_Key key_portal_group; int rval; p_portal = NULL; p_entity = NULL; fetchEntityFlag = FALSE; fetchPortalFlag = FALSE; /* Look for Any Portal or Entity attributes */ for (ii = 0; (ii < SNS_MAX_ATTRS) && (attr_indx[ii]); ii++) { q_attr = (ISNS_Attr *) attr_indx[ii]; switch (q_attr->tag) { case ISNS_ENTITY_TYPE: case ISNS_MGMT_IP: case ISNS_TIMESTAMP: case ISNS_PROT_VER: case ISNS_ENTITY_CERT: case ISNS_ENTITY_PERIOD: fetchEntityFlag = TRUE; break; case ISNS_PORTAL_IP: case ISNS_PORTAL_PORT: case ISNS_PORTAL_SYM_NAME: case ISNS_ESI_INTERVAL: case ISNS_ESI_PORT: case ISNS_PORTAL_CERT: case ISNS_PORTAL_GROUP_TAG: case ISNS_PORTAL_GROUP_IP: case ISNS_PORTAL_GROUP_PORT: case ISNS_PORTAL_GROUP_ISCSI_NAME: fetchPortalFlag = TRUE; break; default: break; } } /* Fetch Entity */ if ( fetchEntityFlag || fetchPortalFlag ) { if ( SUCCESS != read_EntityObject ( p_node->entity_id.id, &p_entity, &entry4 ) ) return ( ISNS_UNKNOWN_ERR ); } for ( ii = 0; ii < SNS_MAX_ATTRS && attr_indx[ ii ]; ii++ ) { q_attr = (ISNS_Attr *) attr_indx[ ii ]; __DEBUG (isns_query_debug &1, process attribute for iscsi and entity objects (%s),isnsTagText(q_attr->tag)); switch ( q_attr->tag ) { case ISNS_ISCSI_NODE_ID: __DEBUG (isns_query_debug &1,ISCSI NODE ID %s,p_node->id.v); ISNSAppendAttr ( p_msg, ISNS_ISCSI_NODE_ID, PAD4 (strlen (p_node->id.v)), p_node->id.v, 0 ); break; case ISNS_ISCSI_ALIAS: ISNSAppendAttr ( p_msg, ISNS_ISCSI_ALIAS, PAD4 (strlen (p_node->alias)), p_node->alias, 0 ); break; case ISNS_ISCSI_TYPE: ISNSAppendAttr ( p_msg, ISNS_ISCSI_TYPE, ISNS_ISCSI_TYPE_SIZE, NULL, p_node->type ); break; case ISNS_NODE_ACTIVE: ISNSAppendAttr ( p_msg, ISNS_NODE_ACTIVE, ISNS_NODE_ACTIVE_SIZE, NULL, p_node->activeFlag ); break; case ISNS_DD_ID: pnode = NULL; while ( ( pnode = GetNextNode(&p_node->dd_id_list, pnode) ) ) { ISNSAppendAttr ( p_msg, ISNS_DD_ID, ISNS_DD_ID_SIZE, NULL, *(uint32_t *)GetNodeData( pnode ) ); } break; case ISNS_ISCSI_CERT: if ( p_node->ptr_cert ) { ISNSAppendAttr ( p_msg, ISNS_ISCSI_CERT, p_node->cert_size, p_node->ptr_cert, 0 ); } break; case ISNS_ENTITY_ID: ISNSAppendAttr ( p_msg, ISNS_ENTITY_ID, PAD4(strlen(p_node->entity_id.id)), p_node->entity_id.id, 0 ); break; case ISNS_MGMT_IP: ISNSAppendAttr ( (struct ISNS_msg *) p_msg, ISNS_MGMT_IP, ISNS_IP_SIZE, p_entity->mgmt_ip_addr.v, 0 ); break; case ISNS_TIMESTAMP: ISNSAppendAttr ( p_msg, ISNS_TIMESTAMP, ISNS_TIMESTAMP_SIZE, NULL, p_entity->timestamp.t_time ); break; case ISNS_ENTITY_TYPE: ISNSAppendAttr ( p_msg, ISNS_ENTITY_TYPE, ISNS_ENTITY_TYPE_SIZE, NULL, p_entity->eid_type ); break; case ISNS_ENTITY_PERIOD: ISNSAppendAttr ( p_msg, ISNS_ENTITY_PERIOD, ISNS_ENTITY_PERIOD_SIZE, NULL, p_entity->period ); break; case ISNS_PROT_VER: ISNSAppendAttr ( p_msg, ISNS_PROT_VER, ISNS_PROT_VER_SIZE, (char *)&p_entity->prot_ver, 0 ); break; case ISNS_ENTITY_CERT: if (p_entity->ptr_cert) { ISNSAppendAttr ( p_msg, ISNS_ENTITY_CERT, p_entity->cert_size, p_entity->ptr_cert, 0 ); } break; case ISNS_ENTITY_IDX: ISNSAppendAttr ( p_msg, ISNS_ENTITY_IDX, ISNS_ENTITY_IDX_SIZE, NULL, p_entity->entity_index ); break; case ISNS_ISCSI_IDX: ISNSAppendAttr ( p_msg, ISNS_ISCSI_IDX, ISNS_ISCSI_IDX_SIZE, NULL, p_node->iscsi_index ); break; case ISNS_ISCSI_SCN_BITMAP: ISNSAppendAttr ( p_msg, ISNS_ISCSI_SCN_BITMAP, ISNS_SCN_BITMAP_SIZE, NULL, p_node->scn_bitmap); break; default: break; } } /* Fetch Portal */ if ( fetchPortalFlag ) { __DEBUG (isns_query_debug &1, (fetchPortalFlag)); /* Cycle through all portals */ pnode = NULL; while ( (pnode = GetNextNode(&p_entity->iportal_list, pnode)) ) { __DEBUG (isns_query_debug &1, Get portal record ); rval = read_PortalObject(GetNodeData(pnode), &p_portal, &entry5); if (rval != SUCCESS ) return rval; __DEBUG (isns_query_debug &1, Get portal group record ); memset(&key_portal_group, 0, sizeof(SOIP_Portal_Group_Key)); key_portal_group.ip_port = p_portal->ip_port; __ISNS_COPY (key_portal_group.ip_addr.v, sizeof(key_portal_group.ip_addr.v), p_portal->ip_addr.v,ISNS_PORTAL_IP_SIZE); __ISNS_COPY (key_portal_group.id.v, sizeof(key_portal_group.id.v), p_node->id.v,strlen(p_node->id.v)); rval = read_PortalGroupObject(&key_portal_group, &p_portal_group, &entry4); if (rval != SUCCESS ) { __DEBUG (isns_query_debug &1, portal group record not found ); p_portal_group = NULL; } for (jj = 0; (jj < SNS_MAX_ATTRS) && (attr_indx[jj]); jj++) { q_attr = (ISNS_Attr *) attr_indx[jj]; __DEBUG (isns_query_debug &1, process attribute for portal objects (%s),isnsTagText(q_attr->tag)); switch ( q_attr->tag ) { /* Located in the Portal object */ case ISNS_PORTAL_PORT: ISNSAppendAttr (p_msg, ISNS_PORTAL_PORT, ISNS_PORTAL_PORT_SIZE, NULL, p_portal->ip_port); break; case ISNS_PORTAL_IP: __DEBUG (isns_query_debug &1,Add ISNS_PORTAL_IP); ISNSAppendAttr (p_msg, ISNS_PORTAL_IP, ISNS_PORTAL_IP_SIZE, p_portal->ip_addr.v, 0); break; case ISNS_PORTAL_SYM_NAME: ISNSAppendAttr (p_msg, ISNS_PORTAL_SYM_NAME, PAD4 (strlen (p_portal->sym_name)), p_portal->sym_name, 0); break; case ISNS_ESI_PORT: ISNSAppendAttr (p_msg, ISNS_ESI_PORT, ISNS_ESI_PORT_SIZE, NULL, p_portal->esi_port); break; case ISNS_ESI_INTERVAL: ISNSAppendAttr (p_msg, ISNS_ESI_INTERVAL, ISNS_ESI_INTERVAL_SIZE, NULL, p_portal->esi_interval); break; case ISNS_PORTAL_CERT: if (p_portal->ptr_cert) { ISNSAppendAttr (p_msg, ISNS_ISCSI_CERT, p_portal->cert_size, p_portal->ptr_cert, 0); } break; case ISNS_PORTAL_IDX: ISNSAppendAttr (p_msg, ISNS_PORTAL_IDX, ISNS_PORTAL_IDX_SIZE, NULL, p_portal->portal_index); break; case ISNS_PORTAL_GROUP_PORT: if (p_portal_group) { __DEBUG (isns_query_debug &1,ISNS_PORTAL_GROUP_PORT:%i,p_portal_group->ip_port); ISNSAppendAttr (p_msg, ISNS_PORTAL_GROUP_PORT, ISNS_PORTAL_GROUP_PORT_SIZE, NULL, p_portal_group->ip_port); } else { //since portal group doesn't exist use portal instead - workaround for open-iscsiinitiator __DEBUG (isns_query_debug &1,ISNS_PORTAL_GROUP_PORT:%i,p_portal->ip_port); ISNSAppendAttr (p_msg, ISNS_PORTAL_GROUP_PORT, ISNS_PORTAL_GROUP_PORT_SIZE, NULL, p_portal->ip_port); } break; case ISNS_PORTAL_GROUP_IP: if (p_portal_group) { __DEBUG (isns_query_debug &1,Add ISNS_PORTAL_GROUP_IP); ISNSAppendAttr (p_msg, ISNS_PORTAL_GROUP_IP, ISNS_PORTAL_GROUP_IP_SIZE, p_portal_group->ip_addr.v, 0); } else { //since portal group doesn't exist use portal instead - workaround for open-iscsiinitiator __DEBUG (isns_query_debug &1,Add ISNS_PORTAL_GROUP_IP); ISNSAppendAttr (p_msg, ISNS_PORTAL_GROUP_IP, ISNS_PORTAL_GROUP_IP_SIZE, p_portal->ip_addr.v, 0); } break; case ISNS_PORTAL_GROUP_ISCSI_NAME: ISNSAppendAttr (p_msg, ISNS_PORTAL_GROUP_ISCSI_NAME, PAD4 (strlen (p_node->id.v)), p_node->id.v, 0); break; case ISNS_PORTAL_GROUP_TAG: if (p_portal_group) { __DEBUG (isns_query_debug &1,Add ISNS_PORTAL_GROUP_TAG from portal group object); ISNSAppendAttr (p_msg, ISNS_PORTAL_GROUP_TAG, ISNS_PORTAL_GROUP_TAG_SIZE, NULL, p_portal_group->portal_tag); } else { __DEBUG (isns_query_debug &1,Add ISNS_PORTAL_GROUP_TAG from default tag in portal object); ISNSAppendAttr (p_msg, ISNS_PORTAL_GROUP_TAG, ISNS_PORTAL_GROUP_TAG_SIZE, NULL, p_portal->default_portal_tag); } break; default: break; } /* end for */ } } /* end for */ } return ( SUCCESS ); } /********************************************************************* *********************************************************************/ int SNSProcessPortalOpAttr ( ISNS_Msg * p_msg, ISNS_Attr ** attr_indx, SOIP_Portal * p_portal ) { int ii; ISNS_Attr *q_attr; for (ii = 0; ii < MAX_PARSE_ATTRS && attr_indx[ii]; ii++) { q_attr = attr_indx[ii]; switch (q_attr->tag) { case ISNS_ENTITY_ID: ISNSAppendAttr ( p_msg, ISNS_ENTITY_ID, PAD4 (strlen (p_portal->entity_id.id)), p_portal->entity_id.id, 0 ); break; case ISNS_PORTAL_PORT: ISNSAppendAttr ( p_msg, ISNS_PORTAL_PORT, ISNS_PORTAL_PORT_SIZE, NULL, p_portal->ip_port ); break; case ISNS_PORTAL_IP: ISNSAppendAttr ( p_msg, ISNS_PORTAL_IP, ISNS_PORTAL_IP_SIZE, p_portal->ip_addr.v, 0 ); break; case ISNS_PORTAL_SYM_NAME: ISNSAppendAttr ( p_msg, ISNS_PORTAL_SYM_NAME, PAD4 (strlen (p_portal->sym_name)), p_portal->sym_name, 0 ); break; case ISNS_ESI_PORT: ISNSAppendAttr ( p_msg, ISNS_ESI_PORT, ISNS_ESI_PORT_SIZE, NULL, p_portal->esi_port ); break; case ISNS_ESI_INTERVAL: ISNSAppendAttr ( p_msg, ISNS_ESI_INTERVAL, ISNS_ESI_INTERVAL_SIZE, NULL, p_portal->esi_interval ); break; case ISNS_PORTAL_CERT: if ( p_portal->ptr_cert ) { ISNSAppendAttr ( p_msg, ISNS_ISCSI_CERT, p_portal->cert_size, p_portal->ptr_cert, 0 ); } break; case ISNS_ENTITY_IDX: ISNSAppendAttr ( p_msg, ISNS_ENTITY_IDX, ISNS_ENTITY_IDX_SIZE, NULL, p_portal->entity_index ); break; case ISNS_PORTAL_IDX: ISNSAppendAttr ( p_msg, ISNS_PORTAL_IDX, ISNS_PORTAL_IDX_SIZE, NULL, p_portal->portal_index ); break; default: break; } } return ( ISNS_NO_ERR ); } /********************************************************************* Appends the opperational attributes for an entity. *********************************************************************/ int ISNSdbProcessEntityOpAttr (ISNS_Msg * p_msg, ISNS_Attr ** attr_indx, SOIP_Entity *p_entity) { int ii; ISNS_Attr *q_attr; __DEBUG (isns_query_debug &1, ISNSdbProcessEntityOpAttr); for (ii = 0; ii < MAX_PARSE_ATTRS && attr_indx[ii]; ii++) { q_attr = attr_indx[ii]; switch (q_attr->tag) { case ISNS_ENTITY_ID: ISNSAppendAttr (p_msg, ISNS_ENTITY_ID, PAD4 (strlen (p_entity->eid.id)), p_entity->eid.id, 0); break; case ISNS_MGMT_IP: ISNSAppendAttr (p_msg, ISNS_MGMT_IP, ISNS_IP_SIZE, p_entity->mgmt_ip_addr.v, 0); break; case ISNS_TIMESTAMP: ISNSAppendAttr (p_msg, ISNS_TIMESTAMP, ISNS_TIMESTAMP_SIZE, NULL, p_entity->timestamp.t_time); break; case ISNS_ENTITY_TYPE: ISNSAppendAttr (p_msg, ISNS_ENTITY_TYPE, ISNS_ENTITY_TYPE_SIZE, NULL, p_entity->eid_type); break; case ISNS_PROT_VER: ISNSAppendAttr (p_msg, ISNS_PROT_VER, ISNS_PROT_VER_SIZE, (char *)&p_entity->prot_ver, 0); break; /* The following are not currently implemented. */ case ISNS_ENTITY_PERIOD: ISNSAppendAttr (p_msg, ISNS_ENTITY_PERIOD, ISNS_ENTITY_PERIOD_SIZE, NULL, p_entity->period); break; case ISNS_ENTITY_CERT: if (p_entity->ptr_cert) { ISNSAppendAttr (p_msg, ISNS_ENTITY_CERT, p_entity->cert_size, p_entity->ptr_cert, 0); } break; case ISNS_ENTITY_IDX: ISNSAppendAttr ( p_msg, ISNS_ENTITY_IDX, ISNS_ENTITY_IDX_SIZE, NULL, p_entity->entity_index); break; default: break; } } return (ISNS_NO_ERR); } /********************************************************************* Appends the operational attributes for an iFCP node. *********************************************************************/ int ISNSdbProcessPortOpAttr (ISNS_Msg * p_msg, ISNS_Attr ** attr_indx, SOIP_Ifcp * p_port) { int ii; ISNS_Attr *q_attr; ISNS_LIST_NODE *pnode; for (ii = 0; (ii < SNS_MAX_ATTRS) && (attr_indx[ii]); ii++) { q_attr = (ISNS_Attr *) attr_indx[ii]; switch (q_attr->tag) { case ISNS_PORT_NAME: ISNSAppendAttr (p_msg, ISNS_PORT_NAME, PORT_NAME_SIZE, p_port->port_name.v, 0); break; case ISNS_PORT_ID: ISNSAppendAttr (p_msg, ISNS_PORT_ID, ISNS_PORT_ID_SIZE, (char *)&p_port->id, 0); break; case ISNS_PORT_TYPE: ISNSAppendAttr (p_msg, ISNS_PORT_TYPE, ISNS_PORT_TYPE_SIZE, NULL, p_port->type); break; case ISNS_PORT_SYM_NAME: ISNSAppendAttr (p_msg, ISNS_PORT_SYM_NAME, PAD4 (strlen (p_port->sym_name)), p_port->sym_name, 0); break; case ISNS_FABRIC_PORT_NAME: ISNSAppendAttr (p_msg, ISNS_FABRIC_PORT_NAME, ISNS_FABRIC_PORT_NAME_SIZE, p_port->fabric_port_name.v, 0); break; case ISNS_FC_HARD_ADDR: ISNSAppendAttr (p_msg, ISNS_FC_HARD_ADDR, ISNS_FC_HARD_ADDR_SIZE, p_port->hard_addr.v, 0); break; case ISNS_FC_PORT_IP: ISNSAppendAttr (p_msg, ISNS_FC_PORT_IP, ISNS_FC_PORT_IP_SIZE, p_port->ip_addr.v, 0); break; case ISNS_FC_COS: ISNSAppendAttr (p_msg, ISNS_FC_COS, ISNS_FC_COS_SIZE, NULL, p_port->cos); break; case ISNS_FC4_TYPE: ISNSAppendAttr (p_msg, ISNS_FC4_TYPE, ISNS_FC4_TYPE_SIZE, (char *)&p_port->fc4_types.bitmap, 0); break; case ISNS_FC4_DESC: ISNSAppendAttr (p_msg, ISNS_FC4_DESC, PAD4 (strlen ((char *)&p_port->fc_descr)), (char *)&p_port->fc_descr.v, FC_DESCRIPTOR_SIZE); break; case ISNS_FC4_FEATURE: ISNSAppendAttr (p_msg, ISNS_FC4_FEATURE, ISNS_FC4_FEATURE_SIZE, (char *)&p_port->fc_feature.v, FC_FEATURE_SIZE); break; case ISNS_DD_ID: pnode=NULL; while ((pnode=GetNextNode(&p_port->dd_id_list, pnode))) { ISNSAppendAttr (p_msg, ISNS_DD_ID, ISNS_DD_ID_SIZE, NULL, *(uint32_t *)GetNodeData(pnode)); } break; case ISNS_IFCP_NODE_CERT: if (p_port->ptr_cert) { ISNSAppendAttr (p_msg, ISNS_IFCP_NODE_CERT, p_port->cert_size, p_port->ptr_cert, 0); } break; default: break; } } return (ISNS_NO_ERR); } /********************************************************************* _ISNSdbProcessFCNodeOpAttr This will append all the FC Node's attributes to the msg. *********************************************************************/ int ISNSdbProcessFCNodeOpAttr (ISNS_Msg * p_msg, ISNS_Attr ** attr_indx, SOIP_Fc_Node * p_node) { int ii; ISNS_Attr *q_attr; int attr_len; ISNS_LIST_NODE *pnode; for (ii = 0; (ii < SNS_MAX_ATTRS) && (attr_indx[ii]); ii++) { q_attr = (ISNS_Attr *) attr_indx[ii]; switch (q_attr->tag) { case ISNS_NODE_NAME: ISNSAppendAttr (p_msg, ISNS_NODE_NAME, ISNS_NODE_NAME_SIZE, p_node->node_name.v, 0); break; case ISNS_NODE_SYM_NAME: ISNSAppendAttr (p_msg, ISNS_NODE_SYM_NAME, PAD4 (strlen (p_node->sym_name)), p_node->sym_name, 0); break; case ISNS_FC_NODE_IPA: ISNSAppendAttr (p_msg, ISNS_FC_NODE_IPA, ISNS_FC_NODE_IPA_SIZE, p_node->node_ipa.v, 0); break; case ISNS_FC_NODE_IP: ISNSAppendAttr (p_msg, ISNS_FC_NODE_IP, ISNS_FC_NODE_IP_SIZE, p_node->ip_addr.v, 0); break; case ISNS_PORT_NAME: attr_len = PORT_NAME_SIZE; pnode=NULL; while ((pnode=GetNextNode(&p_node->port_list, pnode))) { ISNSAppendAttr (p_msg, ISNS_PORT_NAME, ISNS_PORT_NAME_SIZE, GetNodeData(pnode), 0); } break; case ISNS_FC_NODE_CERT: ISNSAppendAttr (p_msg, ISNS_FC_NODE_CERT, p_node->cert_size, p_node->ptr_cert, 0); break; default: break; } } return (SUCCESS); } /******************************************************************** ********************************************************************/ int IsDDSActive(int dds_id) { SOIP_Dds *p_dds; SOIP_DB_Entry lentry; int rval; rval = read_DDSObject(dds_id, &p_dds, &lentry); if (rval != SUCCESS) return rval; return (p_dds->status); } /******************************************************************** ********************************************************************/ int IsDDActive(int dd_id, int exclude_dds_id) { SOIP_Dd *p_dd; SOIP_DB_Entry lentry; int rval; ISNS_LIST_NODE *pnode; if (SUCCESS != read_DDObject (dd_id, &p_dd, &lentry)) return (FALSE); pnode = NULL; rval = FALSE; while ((pnode=GetNextNode(&p_dd->dds_list, pnode))) { int dds_id; dds_id = *(uint32_t *)GetNodeData(pnode); if (exclude_dds_id && dds_id == exclude_dds_id) continue; if (IsDDSActive(dds_id)) { rval = TRUE; break; } } return (rval); } /********************************************************************* FLAG should be set to 0 if you only want the active DD, else set it to 1 and it will return ALL DD. *********************************************************************/ int Get_Active_DD_List (ISNS_LIST *dd_list, ISNS_DD_LIST p_dlist, int flag) { SOIP_Dd *p_dd; SOIP_DD_Key dd_key; SOIP_DB_Entry lentry2; ISNS_LIST_NODE *pnode; int rval; pnode = NULL; __DEBUG (isns_query_debug &1,(Get_Active_DD_list)); while ( (pnode=GetNextNode(dd_list, pnode)) ) { __DEBUG (isns_query_debug &1,(Get_Active_DD_List - node data)); /* First, look at the Node's Local DD_LIST. */ if (flag) { Append_DD_to_List (p_dlist, *(uint32_t *)GetNodeData(pnode)); continue; } dd_key.id = *(uint32_t *)GetNodeData(pnode); rval = read_DDObject(dd_key.id, &p_dd, &lentry2); if (rval != SUCCESS) return rval; if (p_dd->activeFlag || flag) Append_DD_to_List (p_dlist, dd_key.id); } return (ISNS_NO_ERR); } /********************************************************************* Gets a DD list from an iFCP node. flag=0 for active DD, else flag=1 for all DD. *********************************************************************/ int Get_Active_DD_List_From_IFCP_Node (char *nodename, ISNS_DD_LIST p_dlist, int flag) { SOIP_Ifcp *p_node; SOIP_DB_Entry lentry; int rval; rval = read_FCPortObject(nodename, &p_node, &lentry); if (rval != SUCCESS) return rval; Get_Active_DD_List (&p_node->dd_id_list, p_dlist, flag); return (ISNS_NO_ERR); } int Get_Active_DD_List_From_ENTITY_Node (char *p_entity_name, SOIP_Entity * p_entity, ISNS_DD_LIST p_list, int flag) { int rval = ISNS_NO_ERR; SOIP_DB_Entry lentry; ISNS_LIST_NODE *pnode; if (p_entity == NULL) { /* Fetch entity from hash */ if (ISNS_NO_ERR != read_EntityObject (p_entity_name, &p_entity, &lentry)) { return (ERROR); } } if (p_entity->eid_type == ENTITY_TYPE_ISCSI) { /* For each iSCSI Node */ pnode=NULL; while ((pnode=GetNextNode(&p_entity->iscsi_node_list, pnode))) { Get_Active_DD_List_From_ISCSI_Node (GetNodeData(pnode), p_list, flag); } } else if (p_entity->eid_type == ENTITY_TYPE_IFCP) { /* For each iFCP Node */ pnode=NULL; while ((pnode=GetNextNode(&p_entity->ifcp_node_list, pnode))) { /*Append DD */ Get_Active_DD_List_From_IFCP_Node (GetNodeData(pnode), p_list, flag); } } else { rval = ERROR; } return (rval); } /********************************************************************* Gets the DD from an iSCSI node. flag=0 for active DD, else flag=1 for all DD. *********************************************************************/ int Get_Active_DD_List_From_ISCSI_Node (char *nodename, ISNS_DD_LIST p_dlist, int flag) { SOIP_Iscsi *p_node; SOIP_DB_Entry lentry; int rval; __DEBUG(isns_query_debug & 1, (Get_Active_DD_List_From_ISCSI_Node nodename=%s),nodename); rval = read_ISCSIObject(nodename, &p_node, &lentry); if (rval != SUCCESS) return rval; Get_Active_DD_List (&p_node->dd_id_list, p_dlist, flag); return (ISNS_NO_ERR); } /********************************************************************* Appends the active DD from a node. *********************************************************************/ int SNSGet_Active_DD_List_From_Src (ISNS_Attr * src_attr, ISNS_DD_LIST p_dlist_src, int flag) { int rval; /* Validate the src attr */ if (src_attr == NULL || src_attr->tag == 0) { /* Do nothing */ } else if (src_attr->tag == ISNS_ISCSI_NODE_ID) { /* This will retrieve all the ACTIVE DD_ID for the src. */ if (SUCCESS != (rval=Get_Active_DD_List_From_ISCSI_Node ((char *)&src_attr->val, p_dlist_src, flag))) return (rval); } else if (src_attr->tag == ISNS_PORT_NAME) { if (SUCCESS != (rval=Get_Active_DD_List_From_IFCP_Node ((char *)&src_attr->val, p_dlist_src, flag))) return (rval); } else if (src_attr->tag == ENTITY_ID_KEY) { if (SUCCESS != (rval=Get_Active_DD_List_From_ENTITY_Node ((char *)&src_attr->val, NULL, p_dlist_src, flag))) return (rval); } else { __LOG_ERROR ("***ERROR: Invalid SOURCE Tag."); return (ISNS_MSG_FMT_ERR); } return (SUCCESS); } int ISNSTouchEntity( ISNS_Attr *src_attr ) { SOIP_DB_Entry lentry; SOIP_DB_Entry lentry2; SOIP_Entity *p_entity; SOIP_ISCSI_Node_Id db_node_name; SOIP_Iscsi *p_node; time_t t; int rval; if (!src_attr || src_attr->tag == 0) return (SUCCESS); if ( src_attr->tag == ISNS_ISCSI_NODE_ID ) { memset ( &db_node_name, 0, sizeof (db_node_name) ); strncpy ( (char *) db_node_name.v, (char *)&src_attr->val, sizeof(db_node_name.v) ); rval = read_ISCSIObject(db_node_name.v, &p_node, &lentry); if (rval != SUCCESS) return (ERROR); rval = read_EntityObject (p_node->entity_id.id, &p_entity, &lentry2); if (rval != SUCCESS) return ( ERROR ); /* Update Time Stamp */ p_entity->timestamp.t_time = time (&t); write_EntityObject(p_node->entity_id.id, lentry2); } else { __LOG_INFO ("src_attr->tag is not a iSCSI node and should be"); return (ERROR); } return ( SUCCESS ); } /********************************************************************* Returns TRUE if the src and node dd list overlap. *********************************************************************/ int Check_Overlap_DD (ISNS_DD_LIST p_dlist_src, ISNS_DD_LIST p_dlist_node) { int ii, jj; for (ii = 0; ii < MAX_DD_PER_LIST; ii++) { if (p_dlist_src[ii]==0) break; for (jj = 0; jj < MAX_DD_PER_LIST; jj++) { if (p_dlist_node[jj]==0) break; if (p_dlist_src[ii] == p_dlist_node[jj]) return (TRUE); } } return (FALSE); } /********************************************************************* *********************************************************************/ int Check_Permission (ISNS_Attr *src_attr, int rectype, void * ptr) { int rval; ISNS_LIST_NODE * pnode; SOIP_Dds * p_dds; SOIP_Dd *p_dd; SOIP_Entity *p_entity; SOIP_Portal *p_portal; __DEBUG (isns_query_debug &1,(Check_Permission src_node_name=%s),src_attr->val.node_name.v); /* check if control node */ if ( 0 == strcmp (src_attr->val.node_name.v, isns_control_node) ) return SUCCESS; memset (dlist_src, 0, MAX_DD_PER_LIST*sizeof(uint32_t)); rval = SNSGet_Active_DD_List_From_Src (src_attr, dlist_src, 0); if (rval !=SUCCESS) { return (ISNS_AUTH_FAILED_ERR); } switch (rectype) { case ISCSI_ID_KEY: if (src_attr->tag) { SOIP_Iscsi * pnode; pnode = (SOIP_Iscsi *)ptr; memset (dlist_node, 0, MAX_DD_PER_LIST*sizeof(uint32_t)); __DEBUG (isns_query_debug &1, call Get_Active_DD_List); Get_Active_DD_List (&pnode->dd_id_list, dlist_node, 0); if (FALSE == Check_Overlap_DD (dlist_src, dlist_node)) { __DEBUG(isns_query_debug & 1,"src attribute not found in a Discovery Domain"); return (ISNS_AUTH_FAILED_ERR); } } break; case ENTITY_ID_KEY: if (src_attr->tag) { p_entity = ptr; memset (dlist_node, 0, MAX_DD_PER_LIST*sizeof(uint32_t)); rval = Get_Active_DD_List_From_ENTITY_Node (NULL, p_entity,dlist_node,0); if (ISNS_NO_ERR != rval) { return (ISNS_INVALID_QUERY_ERR); } if (FALSE == Check_Overlap_DD (dlist_src, dlist_node)) { __DEBUG(isns_query_debug & 1,"src attribute not found in a Discovery Domain"); return (ISNS_AUTH_FAILED_ERR); } } break; case PORTAL_ID_KEY: if (src_attr->tag) { p_portal = ptr; Get_Active_DD_List_From_ENTITY_Node (p_portal->entity_id.id, NULL, dlist_node, 0); if (FALSE == Check_Overlap_DD (dlist_src, dlist_node)) { __DEBUG(isns_query_debug & 1,"src attribute not found in a Discovery Domain"); return (ISNS_AUTH_FAILED_ERR); } } break; case PORT_NAME_KEY: if (src_attr->tag) { SOIP_Ifcp *p_port; p_port = (SOIP_Ifcp *)ptr; memset (dlist_node, 0, MAX_DD_PER_LIST*sizeof(uint32_t)); __DEBUG (isns_query_debug &1, Get_Active_DD_List); Get_Active_DD_List (&p_port->dd_id_list, dlist_node, 0); if (FALSE == Check_Overlap_DD (dlist_src, dlist_node)) { __DEBUG(isns_query_debug & 1,"src attribute not found in a Discovery Domain"); return (ISNS_AUTH_FAILED_ERR); } } break; case DDS_ID_KEY: { p_dds = ptr; int jj; pnode=NULL; while ((pnode=GetNextNode(&p_dds->dd_list, pnode))) { for (jj = 0; jj < MAX_DD_PER_LIST && dlist_src[jj]!=0; jj++) { if (dlist_src[jj]==*(uint32_t *)GetNodeData(pnode)) { return (SUCCESS); break; } } } } break; case DD_ID_KEY: { p_dd = ptr; int ii; for (ii = 0; ii < MAX_DD_PER_LIST && dlist_src[ii]!=0; ii++) { if (dlist_src[ii] == p_dd->id) { return (SUCCESS); break; } } } break; default: return (ISNS_AUTH_FAILED_ERR); break; } return SUCCESS; } isns-2.1-01/isnsserver/src/iSNSqueue.c0000644000175000017500000001547510665040341016610 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This file contains source code for managing * queues of iSNS requests pending a response from * other SOIP service entities. * */ #include "iSNS.h" #include "iSNStypes.h" #include "iSNSqueue.h" static int sns_retry_timeout = SNS_REQUEST_TIMEOUT; /* * iSNS message queues. There are two queues used for * staging requests that require a response. One queue * is used for staging transaction messages like * attribute registeration, query etc. The other * queue is used for staging FSM messages like * DISCOVERY, CLAIM etc. * */ static struct SNS_Msg_Descp_Q sns_q[SNS_NUM_QUEUES] = { {NULL, NULL}, {NULL, NULL} }; int SNSQInit (SNS_Queue_Name name) { if (name > SNS_NUM_QUEUES) return (ERROR); sns_q[name].head = sns_q[name].tail = NULL; return (SUCCESS); } void ISNSEnqReq (SNS_Queue_Name name, ISNS_Msg_Descp *p_md) { ISNS_Msg_Descp *p_tmp; int current_time; if (name > SNS_NUM_QUEUES) return; /* * Add the message to the end of the request queue */ if (sns_q[name].tail != NULL) { p_tmp = sns_q[name].tail; sns_q[name].tail = p_md; p_md->cb.next = NULL; p_md->cb.prev = p_tmp; p_tmp->cb.next = p_md; /* * Compute the timeout based on other elements in the queue */ #ifdef SNS_LINUX current_time = (long double)time ((time_t*) 0); #else current_time = tickGet(); #endif p_md->cb.resp_timeout = current_time + (sns_retry_timeout * sysClkRateGet()); } else { sns_q[name].head = p_md; sns_q[name].tail = p_md; p_md->cb.next = NULL; p_md->cb.prev = NULL; #ifdef SNS_LINUX current_time = (long double)time ((time_t*) 0); #else current_time = tickGet(); #endif p_md->cb.resp_timeout = current_time + (sns_retry_timeout * sysClkRateGet()); } } ISNS_Msg_Descp * ISNSQHead (SNS_Queue_Name name) { if (name > SNS_NUM_QUEUES) return (NULL); return(sns_q[name].head); } ISNS_Msg_Descp * ISNSDeqReq (SNS_Queue_Name name, uint16_t xid, int tid) { ISNS_Msg_Descp *p_md; ISNS_Msg_Descp *p_tmp; if (name > SNS_NUM_QUEUES) return (NULL); if (sns_q[name].head == NULL) return(NULL); for (p_md = sns_q[name].head; p_md != NULL; p_md = p_md->cb.next) { /* * Check the task id queue. If there is a task id * in here it means that the async function is active for this task. * Get the iSNS info from the tid queue. Otherwise its the sync * function that is active. Get the info from the transaction queue. */ if (name == ISNS_CALLBACK_QUEUE && tid != 0) { if (p_md->cb.task_id == tid) break; } else { if (p_md->msg.hdr.xid == xid) break; if (ntohs(p_md->msg.hdr.xid) == xid) break; } } /* * remove the queued request */ if (p_md != NULL) { /* * Is this the only element in the queue */ if (sns_q[name].head == sns_q[name].tail) { sns_q[name].head = NULL; sns_q[name].tail = NULL; return (p_md); } else { p_tmp = p_md->cb.prev; if (p_tmp != NULL) p_tmp->cb.next = p_md->cb.next; else sns_q[name].head = p_md->cb.next; p_tmp = p_md->cb.next; if (p_tmp != NULL) p_tmp->cb.prev = p_md->cb.prev; else sns_q[name].tail = p_md->cb.prev; } } return (p_md); } ISNS_Msg_Descp * SNSGetReq (SNS_Queue_Name name, int xid, int tid) { ISNS_Msg_Descp *p_md; /* * Init the local vars. */ p_md = NULL; /* * Validate the queue. */ if (name > SNS_NUM_QUEUES) return (NULL); if (sns_q[name].head == NULL) return(NULL); /* * Go through the list and find the entry. */ for (p_md = sns_q[name].head; p_md != NULL; p_md = p_md->cb.next) { /* * Check the task id queue. If there is a task id * in here it means that the async function is active for this task. * Get the iSNS info from the tid queue. Otherwise its the sync * function that is active. Get the info from the transaction queue. */ if (name == ISNS_CALLBACK_QUEUE && tid != 0) { if (p_md->cb.task_id == tid) { if (p_md->cb.xid_status == XID_BEGIN) { p_md->cb.xid_status = XID_IN_PROGRESS; break; } else continue; } } else if (name == ISNS_CALLBACK_QUEUE && xid != 0) { if (p_md->msg.hdr.xid == xid) break; } } return (p_md); } isns-2.1-01/isnsserver/src/iSNSUtil.c0000644000175000017500000013017210665040341016371 0ustar zobelzobel/********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include "iSNS.h" #include "iSNScomm.h" #include "iSNSdb.h" #include "iSNSmsg.h" #include "iSNSqueue.h" #include "iSNSfsm.h" #include "iSNScomm.h" #include "iSNSbuffer.h" #include "iSNSipc.h" #include "iSNSList.h" #include "iSNSdebug.h" static char *p_name = "Port Name"; /******************************************************************** ********************************************************************/ void ISNSDisplayMsg (ISNS_Msg *msg) { #if 0 SNS_Msg_Type msg_type; SOIP_Port_Name *p_port; /* * Validate the received message */ msg_type = msg->hdr.type; switch (msg_type) { case DEREG_DEVI_REQ: { __LOG_INFO ("\n ********** DEREGISTRATION MESSAGE *************** \n"); ISNSDisplay_Hdr_Info(msg); __LOG_INFO ("PAYLOAD \n"); p_port = &msg->payload.sns_req.key.val.port_name; ISNSDisplay_Port_Name(p_port, p_name); __LOG_INFO ("\n ********************** EOM ********************** \n"); } break; default: __LOG_INFO ("\nReceived an unknown message.\n"); break; } #endif } /******************************************************************** ********************************************************************/ void ISNSDisplay_Hdr_Info(ISNS_Msg *msg) { __LOG_INFO ("HEADER \n"); __LOG_INFO ("Message Type : %d \n", msg->hdr.type); __LOG_INFO ("Message Xid : %d \n", msg->hdr.xid); __LOG_INFO ("Message Length : %d \n", msg->hdr.msg_len); __LOG_INFO ("Message Flags : %d \n", msg->hdr.flags); } /******************************************************************** ********************************************************************/ void ISNSDisplay_DbData(ISNS_Key *p_key, SOIP_DB_Entry *p_entry, int detail) { #if 0 if (detail == HI_DETAIL || ((p_key->tag != PORT_NAME_KEY) && (p_key->tag != NODE_NAME_KEY))) { SNSDisplay_Attr((SNS_Attr *)p_key, detail); __LOG_INFO("\n"); } if (p_key->next) { __LOG_INFO ("*************** PORT LIST RECORD **************\n"); SNSDisplay_PortList (&p_entry->data.port_list); __LOG_INFO ("***********************************************\n"); return; } #endif switch ( p_entry->data_type ) { case ISCSI_ID_KEY: ISNSDisplay_ISCSINode ( &p_entry->data.scsi_node, detail ); break; case ENTITY_ID_KEY: ISNSDisplay_Entity ( &p_entry->data.entity, detail ); break; case PORTAL_ID_KEY: ISNSDisplay_Portal ( &p_entry->data.portal, detail ); break; case DDS_ID_KEY: ISNSDisplay_DDS (&p_entry->data.dds, detail); break; case DD_ID_KEY: ISNSDisplay_DD (&p_entry->data.dd, detail); break; #if 0 case NODE_NAME_KEY: SNSDisplay_DbNode (&p_entry->data.node, detail); break; case PORT_NAME_KEY: SNSDisplay_DbPort (&p_entry->data.port, detail); break; case PORT_TYPE_KEY: case FC4_TYPE_KEY: case AREA_ID_KEY: __LOG_INFO ("*************** PORT LIST RECORD **************\n"); SNSDisplay_PortList (&p_entry->data.port_list); __LOG_INFO ("***********************************************\n"); break; case ZONE_TAG_KEY: SNSDisplay_DbZone (&p_entry->data.zone); break; case RSCN_TYPE_KEY: SNSDisplay_RscnList (&p_entry->data.rscn); break; case SPACE_ID_KEY: SNSDisplay_DbSpace (&p_entry->data.area); break; case IP_ADDR_KEY: case NX_PORT_TYPE_KEY: case ENTITY_ID_KEY: case PORTAL_ID_KEY: case END_SNS_DEVI_KEY: break; #endif default: __LOG_INFO("\nUnknown table entry (data_type %d)\n", p_entry->data_type); break; } } /******************************************************************** ********************************************************************/ void ISNSDisplay_Port_Name ( SOIP_Port_Name *p_port, char *p_name ) { int indx; if (p_port != NULL) { __LOG_INFO ("%-19s : ", p_name); for (indx = 0; indx < PORT_NAME_SIZE; indx++) __LOG_INFO ("%02x", p_port->v[indx]); __LOG_INFO ("\n"); } } /******************************************************************** ********************************************************************/ void ISNSDisplay_Node_Name ( SOIP_Node_Name *p_node ) { int indx; __LOG_INFO ("Node Name : "); for (indx = 0; indx < ISNS_NODE_NAME_SIZE; indx++) __LOG_INFO ("%02x", p_node->v[indx]); __LOG_INFO ("\n"); } /******************************************************************** ********************************************************************/ void ISNSDisplay_Port_Id ( SOIP_Port_Id *p_id ) { int indx; SOIP_Port_Id null_id = {{0, 0, 0}}; if ((p_id == NULL) || memcmp(p_id, &null_id, PORT_ID_SIZE) == 0) return; __LOG_INFO ("Port Id : "); for (indx = 0; indx < PORT_ID_SIZE; indx++) __LOG_INFO ("%02X", p_id->v[indx]); __LOG_INFO ("\n"); } /******************************************************************** ********************************************************************/ void ISNSDisplay_IPAddress ( IP_Address *ip_addr ) { char ip_saddr[INET_ADDR_LEN+1]; struct in_addr i_addr; /* Assumes a IPv4 Address */ __ISNS_COPY (&i_addr.s_addr, sizeof(i_addr.s_addr), ip_addr->v+12, IP_ADDR_SIZE_V4); inet_ntoa_b (i_addr, ip_saddr); ip_saddr[INET_ADDR_LEN] = '\0'; __LOG_INFO ("IP Address : %s \n", ip_saddr); } /******************************************************************** ********************************************************************/ void ISNSDisplay_Port ( SOIP_Ifcp *p_port ) { int ii; SOIP_COS unreg_cos; __LOG_INFO ("******************** PORT RECORD **************\n"); ISNSDisplay_Port_Name (&p_port->port_name, p_name); ISNSDisplay_Port_Name (&p_port->fabric_port_name, "Fabric Port"); __LOG_INFO ("Symbolic Port Name : %s \n", p_port->sym_name); ISNSDisplay_Node_Name (&p_port->node_name); ISNSDisplay_IPAddress (&p_port->ip_addr); ISNSDisplay_HardAddr (&p_port->hard_addr); ISNSDisplay_Port_Id (&p_port->id); if (p_port->type != SNS_UNREGISTERED) __LOG_INFO ("Port Type : %d \n", p_port->type); for (ii = 0; ii < 32; ii++) if (p_port->fc4_types.bitmap[ii]) __LOG_INFO ("FC-4 Types : 0x%2x [%d] \n", p_port->fc4_types.bitmap[ii], ii); memset(&unreg_cos, SNS_UNREGISTERED, sizeof(SOIP_COS)); if (memcmp(&p_port->cos, &unreg_cos, sizeof(SOIP_COS)) != 0) __LOG_INFO ("Port COS : %08X \n", (unsigned int)p_port->cos); __LOG_INFO ("Port priority : %d \n", p_port->priority); for (ii = 0; ii < ZONE_BITMAP_SIZE; ii++) if (p_port->zone_bitmap[ii]) __LOG_INFO ("Zone bitmap : 0x%2x [%d] \n", p_port->zone_bitmap[ii], ii); __LOG_INFO ("Remote flag : %d \n", p_port->remote); __LOG_INFO ("Device type : %0lx \n", *(long *)&p_port->dev_type); __LOG_INFO ("\n***********************************************\n"); } /******************************************************************** ********************************************************************/ void ISNSDisplay_Node ( SOIP_Node *p_node ) { int ii; __LOG_INFO ("******************** NODE RECORD **************\n"); ISNSDisplay_Node_Name (&p_node->node_name); for (ii = 0; ii < NODE_SYM_NAME_SIZE; ii++) if (p_node->sym_name[ii] == (char)SNS_UNREGISTERED) p_node->sym_name[ii] = '\0'; __LOG_INFO ("Symbolic Node Name : %s \n", p_node->sym_name); ISNSDisplay_NodeIPA (&p_node->node_ipa); ISNSDisplay_IPAddress (&p_node->ip_addr); __LOG_INFO ("Port map : %08X \n", p_node->port_map); for (ii = 0; ii < MAX_PORTS_PER_NODE; ii++) if (p_node->port_map & (1 << ii)) ISNSDisplay_Port_Name (&p_node->port_name[ii], p_name); __LOG_INFO ("***********************************************\n"); } /******************************************************************** ********************************************************************/ void ISNSDisplay_IPAddr (IP_Address *ip_addr) { __LOG_INFO ("*************** IP ADDRESS RECORD *************\n"); ISNSDisplay_IPAddress (ip_addr); __LOG_INFO ("***********************************************\n"); } /******************************************************************** ********************************************************************/ void ISNSDisplay_Port_List(SOIP_Port_List *p_list) { int ii; __LOG_INFO ("Port List Entries : %d \n", (int)p_list->num_entries); __LOG_INFO ("Port List Bitmask : "); for (ii = 0; ii < SNS_MAP_SIZE; ii++) __LOG_INFO("%08lX", (long)p_list->bitmask[ii]); __LOG_INFO("\n"); for (ii = 0; ii < SNS_PORTS_PER_LIST; ii++) if ( p_list->bitmask[ii/32] & (1 << (ii % 32)) ) ISNSDisplay_Port_Name (&p_list->port_name[ii], p_name); } /******************************************************************** ********************************************************************/ void ISNSDisplay_Port_TypeList (SOIP_Port_List *p_list) { __LOG_INFO ("******************* PORT TYPE RECORD **********\n"); ISNSDisplay_Port_List(p_list); __LOG_INFO ("***********************************************\n"); } /******************************************************************** ********************************************************************/ void ISNSDisplay_FC4TypeList (SOIP_Port_List *p_list) { __LOG_INFO ("****************** FC4 LIST RECORD ************\n"); ISNSDisplay_Port_List(p_list); __LOG_INFO ("***********************************************\n"); } /******************************************************************** ********************************************************************/ void ISNSDisplay_FC4Type (void *fc4_types, uint32_t attr_len) { uint8_t i; uint32_t *nptr; if (attr_len == FC4_BITMAP_SIZE) { /* * Add the port to all FC4 type lists that * are enabled in the bit mask */ for (i = 0, nptr = (uint32_t *) ((FC4_Types *)fc4_types)->bitmap; i < 8; i++, nptr++) { if (nptr != NULL && *nptr != 0) { __LOG_INFO ("FC4 Type : 0x%-4x\n", *nptr); } } } else __LOG_INFO ("FC4 Type : 0x%x\n", *((uint8_t *)fc4_types)); } /******************************************************************** ********************************************************************/ void ISNSDisplay_Zone_Tag (SOIP_Zone *p_zone) { int ii; __LOG_INFO ("******************* ZONE TAG RECORD ***********\n"); __LOG_INFO ("Zone Tag : %08x \n", p_zone->zone_tag); for (ii = 0; ii < ZONE_SYM_NAME_SIZE; ii++) if (p_zone->sym_name[ii] == (char)SNS_UNREGISTERED) p_zone->sym_name[ii] = '\0'; __LOG_INFO ("Zone Symbolic Name : %s \n", p_zone->sym_name); ISNSDisplay_Port_List(&p_zone->plist); __LOG_INFO ("***********************************************\n"); } /******************************************************************** ********************************************************************/ void ISNSDisplay_Zone_Priority (uint32_t *zone_priority) { __LOG_INFO ("Zone Priority : 0x%-8x\n", *zone_priority); } #if 0 /******************************************************************** ********************************************************************/ void ISNSDisplay_RSCN_List (SOIP_RSCN_List *p_rscn) { uint32_t ii; SOIP_RSCN *rscn; __LOG_INFO ("******* STATE CHANGE NOTIFICATION RECORD ******\n"); __LOG_INFO ("Number of Entries : %ld \n", p_rscn->num_entries); for (ii = 0; ii < p_rscn->num_entries; ii++) { rscn = &p_rscn->rscn_entry[ii]; ISNSDisplay_Port_Name (&rscn->pn, p_name); __LOG_INFO ("Callback Routine : %08lX \n", (long) rscn->cfunc); } __LOG_INFO ("***********************************************\n"); } #endif /******************************************************************** ********************************************************************/ void ISNSDisplay_Zone (uint32_t *zone_tag) { __LOG_INFO ("Zone Tag : %d \n", *zone_tag); } /******************************************************************** ********************************************************************/ void ISNSDisplay_HardAddr (SOIP_Hard_Addr *hard_addr) { int ii; __LOG_INFO ("Hard Address : "); for (ii = 0; ii < HARD_ADDR_SIZE; ii++) __LOG_INFO("%02x", hard_addr->v[ii]); __LOG_INFO("\n"); } /******************************************************************** ********************************************************************/ void ISNSDisplay_NodeIPA (SOIP_Node_IPA *node_ipa) { int ii; __LOG_INFO ("Node IPA : "); for (ii = 0; ii < NODE_IPA_SIZE; ii++) __LOG_INFO("%02x", node_ipa->v[ii]); __LOG_INFO("\n"); } /******************************************************************** ********************************************************************/ void ISNSDisplay_Node_SymName (char *sym_name) { if (sym_name && sym_name[0] != (char)SNS_UNREGISTERED) __LOG_INFO ("Symbolic Node Name : %s \n", sym_name); else __LOG_INFO ("Symbolic Node Name : \n" ); } /******************************************************************** ********************************************************************/ void ISNSDisplay_Port_SymName (char *sym_name) { if (sym_name && sym_name[0] != (char)SNS_UNREGISTERED) __LOG_INFO ("Symbolic Port Name : %s \n", sym_name); else __LOG_INFO ("Symbolic Port Name : \n" ); } /******************************************************************** ********************************************************************/ void ISNSDisplay_Port_Type (SOIP_Port_Type *p_type) { __LOG_INFO ("Port Type : %d \n", *p_type); } /******************************************************************** ********************************************************************/ void ISNSDisplay_Port_Cos (SOIP_COS *p_cos) { __LOG_INFO ("PORT COS : %08X \n", *(unsigned int *)p_cos); } /******************************************************************** ********************************************************************/ void ISNSDisplay_Portal_Name(char *p_name) { char dot_no[INET_ADDR_LEN]; PORTAL_LIST_ENTRY *p_lentry; p_lentry = (PORTAL_LIST_ENTRY *)p_name; inet_ntoa_b(*(struct in_addr *)((char *)p_name+12), dot_no); if (p_name !=NULL) { __LOG_INFO("Portal IP: %s\n", dot_no); //__LOG_INFO("Portal Port: %#x\n", p_lentry->portal_ip_port.ip_port & 0xFFFF); __LOG_INFO("Portal Port: %i\n", p_lentry->portal_ip_port.ip_port); __LOG_INFO("Portal Type: %s\n", (p_lentry->portal_ip_port.ip_port & 0x10000)?"UDP":"TCP"); __LOG_INFO("Portal Idx : %u\n", p_lentry->portal_idx); } } /******************************************************************** ********************************************************************/ void ISNSDisplay_DD( SOIP_Dd *p_dd, int level ) { ISNS_LIST_NODE *pnode; if ( level == LO_DETAIL ) { __LOG_INFO("%u, %s\n", p_dd->id, p_dd->sym_name); } else { __LOG_INFO("*************** DD Entry ***************\n"); __LOG_INFO("DD ID : %u\n", p_dd->id); __LOG_INFO("DD SYM NAME : %s\n", p_dd->sym_name); __LOG_INFO("DD Enabled : %s \n", p_dd->activeFlag ? "Yes" : "No "); __LOG_INFO("DD DDS : "); pnode = NULL; while ( (pnode = GetNextNode(&p_dd->dds_list, pnode)) ) { __LOG_INFO("%u ", *(uint32_t *)GetNodeData(pnode)); } __LOG_INFO("\n"); pnode=NULL; while ( (pnode = GetNextNode(&p_dd->member_list, pnode)) ) { SOIP_Dd_Member *p_member; p_member = (SOIP_Dd_Member *)GetNodeData( pnode ); switch ( p_member->type ) { case ISNS_DD_ISCSI_MEMBER: __LOG_INFO( "DD ISCSI MEMBER: %s\n", p_member->node_id ); break; case ISNS_DD_IFCP_MEMBER: ISNSDisplay_Port_Name( (struct soip_port_name *)p_member->node_id, "DD IFCP MEMBER" ); break; default: break; } } __LOG_INFO("****************************************\n"); } } /******************************************************************** ********************************************************************/ void ISNSDisplay_DDS( SOIP_Dds *p_dds, int level ) { ISNS_LIST_NODE *pnode; if ( level == LO_DETAIL ) { __LOG_INFO("%u, %#x, %s\n", p_dds->id, p_dds->status, p_dds->sym_name); } else { __LOG_INFO("*************** DDS Entry ***************\n"); __LOG_INFO("DDS ID : %u\n", p_dds->id); __LOG_INFO("DDS SYM NAME : %s\n", p_dds->sym_name); __LOG_INFO("DDS STATUS : %#x (%s)\n", p_dds->status, (p_dds->status & 0x1)?"Enabled":"Disabled"); __LOG_INFO("DDS DD: "); pnode = NULL; while ( (pnode = GetNextNode(&p_dds->dd_list, pnode)) ) { __LOG_INFO("%u ", *(uint32_t *)GetNodeData(pnode)); } __LOG_INFO("\n"); __LOG_INFO("****************************************\n"); } } /******************************************************************** ********************************************************************/ static void SNSDisplay_Field ( char *p_field_name, char *p_field, int len ) { int indx; if (p_field != NULL) { __LOG_INFO ("%-19s : ", p_field_name); for (indx = 0; indx < len; indx++) __LOG_INFO ("%2.2x", *(unsigned char *)&p_field[ indx ]); __LOG_INFO ("\n"); } } /******************************************************************** ********************************************************************/ void ISNSDisplay_iFCPNode ( SOIP_Ifcp *p_node ) { int ii; __LOG_INFO ("************* iFCP NODE RECORD **************\n"); SNSDisplay_Field ("Port Name", (char *)&p_node->port_name, ISNS_PORT_NAME_SIZE); SNSDisplay_Field ("Node Name", (char *)&p_node->node_name, ISNS_NODE_NAME_SIZE); __LOG_INFO ("Port Type : %#x \n", p_node->type); SNSDisplay_Field ("Port ID", (char *)&p_node->id, ISNS_PORT_ID_SIZE); __LOG_INFO ("Port Symbolic Name : %s \n", p_node->sym_name); SNSDisplay_Field ("FC Port Name", (char *)&p_node->fabric_port_name, 8); ISNSDisplay_HardAddr (&p_node->hard_addr); ISNSDisplay_IPAddress (&p_node->ip_addr); __LOG_INFO ("FC COS : %08X \n", (unsigned int)p_node->cos); for (ii = 0; ii < 32; ii++) if (p_node->fc4_types.bitmap[ii]) __LOG_INFO ("FC-4 Types : 0x%2x [%d] \n", p_node->fc4_types.bitmap[ii], ii); __LOG_INFO ("**********************************************\n"); } /******************************************************************** ********************************************************************/ void ISNSDisplay_FCNode ( SOIP_Fc_Node *p_node ) { ISNS_LIST_NODE *pnode; __LOG_INFO ("************* FC NODE RECORD **************\n"); SNSDisplay_Field ("Node Name", (char *)&p_node->node_name, ISNS_NODE_NAME_SIZE); __LOG_INFO ("Symbolic Name : %s \n", p_node->sym_name); ISNSDisplay_IPAddress (&p_node->ip_addr); SNSDisplay_Field ("FC Device IPA", (char *)&p_node->node_ipa, 8); pnode=NULL; while ((pnode=GetNextNode(&p_node->port_list, pnode))) { SNSDisplay_Field ("Port Name", (char *)GetNodeData(pnode), ISNS_PORT_NAME_SIZE); } __LOG_INFO ("*********************************************\n"); } /******************************************************************** ********************************************************************/ void ISNSDisplay_ISCSINode ( SOIP_Iscsi *p_node, int level ) { if (level == LO_DETAIL) { __LOG_INFO(" %s, %s, %#08x, %s, %08x, %u, %u, %s\n", p_node->id.v, p_node->entity_id.id, p_node->type, p_node->alias, p_node->scn_bitmap, p_node->iscsi_index, p_node->entity_index, p_node->activeFlag?"Active":"Not Active"); } else { __LOG_INFO ("************* iSCSI NODE RECORD **************\n"); __LOG_INFO ("Index : %u\n", p_node->iscsi_index); __LOG_INFO ("iSCSI Name : %s \n", p_node->id.v); __LOG_INFO ("Node Type : %#08x \n", p_node->type); __LOG_INFO ("Alias : %s \n", p_node->alias); __LOG_INFO ("Entity ID : %s \n", p_node->entity_id.id); __LOG_INFO ("Entity Index : %u\n", p_node->entity_index); __LOG_INFO ("DD Enabled : %s \n", p_node->activeFlag ? "Yes" : "No "); __LOG_INFO ("*********************************************\n"); } } /******************************************************************** ********************************************************************/ void ISNSDisplay_Entity ( SOIP_Entity *p_entity, int level ) { ISNS_LIST_NODE *pnode; if ( level == LO_DETAIL ) { __LOG_INFO( "%s, %#08x, %u\n", p_entity->eid.id, p_entity->eid_type, p_entity->entity_index ); } else { __LOG_INFO ("******************** ENTITY RECORD **************\n"); __LOG_INFO ("INDEX : %#x\n", p_entity->entity_index); __LOG_INFO ("ID : %s\n", p_entity->eid.id); __LOG_INFO ("Type : %d\n", p_entity->eid_type); __LOG_INFO ("Prot Ver Max/Min: %d/%d\n", p_entity->prot_ver.ver_max, p_entity->prot_ver.ver_min); __LOG_INFO ("Reg Period : %d\n", p_entity->period); //ISNSDisplay_IPAddress ((struct IP_address *)p_entity->mgmt_ip_addr.v); __LOG_INFO ("TimeStamp : %s", ctime((const time_t *)&p_entity->timestamp.t_time)); pnode = NULL; while ( (pnode = GetNextNode(&p_entity->iportal_list, pnode)) ) { ISNSDisplay_Portal_Name ( (char *)GetNodeData(pnode) ); } switch ( p_entity->eid_type ) { case ( ENTITY_TYPE_IFCP ): pnode = NULL; while ( (pnode = GetNextNode( &p_entity->ifcp_node_list, pnode )) ) { ISNSDisplay_Port_Name ((struct soip_port_name *)GetNodeData( pnode ), "iFCP WWPN"); } break; case (ENTITY_TYPE_ISCSI): pnode=NULL; while ( (pnode = GetNextNode(&p_entity->iscsi_node_list, pnode)) ) { __LOG_INFO("iSCSI Node ID: %s\n", GetNodeData( pnode )); } break; default: __LOG_INFO("(Entity type unknown %d)", p_entity->eid_type); break; } __LOG_INFO ("***********************************************\n"); } } /******************************************************************** ********************************************************************/ void ISNSDisplay_Portal(SOIP_Portal *p_portal, int level) { ISNS_LIST_NODE *pnode; /* Assumes a IPv4 Address */ if (level == LO_DETAIL) { __LOG_INFO( " %s %#08x,%u\n", inet_ntoa(*(struct in_addr *)(p_portal->ip_addr.v+12)), p_portal->ip_port, p_portal->portal_index); } else { __LOG_INFO("******************** Portal Record **************\n"); __LOG_INFO("INDEX : %u\n", p_portal->portal_index); __LOG_INFO("IP : %s\n", inet_ntoa(*(struct in_addr *)(p_portal->ip_addr.v+12))); __LOG_INFO("PORT : %#x\n", p_portal->ip_port); __LOG_INFO("SYM NAME : %s\n", p_portal->sym_name); pnode = NULL; __LOG_INFO("ENTITY : %s\n", p_portal->entity_id.id); __LOG_INFO("ESI INTERVAL : %u\n", p_portal->esi_interval); __LOG_INFO("ESI/SCN UDP PORT: %u\n", p_portal->esi_port); __LOG_INFO ("*************************************************\n"); } } /******************************************************************** ********************************************************************/ void ipaddrchar(void * ipaddrhex, void * ipaddrstr) { uint32_t x1,x2,x3,x4,*xp; xp = (uint32_t *)ipaddrhex; x1 = ntohl(*xp++); x2 = ntohl(*xp++); x3 = ntohl(*xp++); x4 = ntohl(*xp); if (x1==0 && x2==0 && x3==0) { unsigned char *cp = (unsigned char *)xp; x1 = *cp++; x2 = *cp++; x3 = *cp++; x4 = *cp; } sprintf(ipaddrstr,"%d.%d.%d.%d",x1,x2,x3,x4); } /******************************************************************** ********************************************************************/ char * FuncIDText (uint16_t funcid) { switch (funcid) { /* Request */ case ISNS_REG_DEV_ATTR_REQ : return("Register Device Attribute Request"); case ISNS_DEV_ATTR_QRY_REQ : return("Device Attribute Query Request"); case ISNS_DEV_GET_NXT_REQ : return("Device Get Next Request"); case ISNS_DEREG_DEV_REQ : return("Deregister Device Request"); case ISNS_SCN_REG_REQ : return("SCN Register Request"); case ISNS_SCN_DEREG_REQ : return("SCN Deregister Request"); case ISNS_SCN_EVENT : return("SCN Event"); case ISNS_SCN : return("State Change Notification"); case ISNS_REG_DD_REQ : return("Discovery Domain Register"); case ISNS_DEREG_DD_REQ : return("Discovery Domain Deregister"); case ISNS_REG_DDS_REQ : return("Discovery Domain Set Register"); case ISNS_DEREG_DDS_REQ : return("Discovery Domain Set Deregister"); case ISNS_ESI : return("Entity Status Inquiry"); case ISNS_HEART_BEAT : return("Name Service Heartbeat"); case ISNS_REQ_SW_ID_REQ : return("Request Switch ID Request"); case ISNS_REL_SW_ID_REQ : return("Release Switch ID Request"); case ISNS_GET_SW_ID_REQ : return("Get Switch ID Request"); case ISNS_DDS_GET_NXT_MEMBER_REQ: return("Get DDS Next Member Request"); case ISNS_DD_GET_NXT_ISCSI_MEMBER_REQ: return("Get DDS Next Member Request"); case ISNS_ENTITY_GET_NXT_PORTAL_REQ: return("Get Entity Next Portal Request"); /* Response */ case ISNS_REG_DEV_ATTR_RES : return("Register Device Attribute Response"); case ISNS_DEV_ATTR_QRY_RES : return("Device Attribute Query Response"); case ISNS_DEV_GET_NXT_RES : return("Device Get Next Response"); case ISNS_DEREG_DEV_RES : return("Deregister Device Response"); case ISNS_SCN_REG_RES : return("SCN Register Response"); case ISNS_SCN_DEREG_RES : return("SCN Degregister Response"); case ISNS_SCN_EVENT_RES : return("SCN Event Response"); case ISNS_SCN_RES : return("SCN Response"); case ISNS_REG_DD_RES : return("Discovery Domain Register Response"); case ISNS_DEREG_DD_RES : return("Discovery Domain Deregister Response"); case ISNS_REG_DDS_RES : return("Discovery Domain Set Register Response"); case ISNS_DEREG_DDS_RES : return("Discovery Domain Set Deregister Response"); case ISNS_ESI_RSP : return("Entity Status Inquiry Response"); case ISNS_REQ_SW_ID_RES : return("Request Switch ID Response"); case ISNS_REL_SW_ID_RES : return("Release Switch ID Response"); case ISNS_GET_SW_ID_RES : return("Get Switch ID Response"); case ISNS_DDS_GET_NXT_MEMBER_RES: return("Get DDS Next Member Response"); case ISNS_DD_GET_NXT_ISCSI_MEMBER_RES: return("Get DDS Next Member Response"); case ISNS_ENTITY_GET_NXT_PORTAL_RES: return("Get Portal Next Entity Response"); /* Internal */ case ESI_TIMEOUT_EVENT : return("ESI Timeout Event"); case FSM_TIMEOUT_EVENT : return("FSM Timeout Event"); case REQ_TIMEOUT_EVENT : return("REQ Timeout Event"); default : return("Unknown Message Type"); } } /******************************************************************** ********************************************************************/ char * isnsTagText (uint32_t tagid) { switch (tagid) { case ISNS_DELIMITER : return("Delimiter"); case ISNS_ENTITY_ID : return("Entity Identifier"); case ISNS_ENTITY_TYPE : return("Entity Protocol"); case ISNS_MGMT_IP : return("Mgmt IP Address"); case ISNS_TIMESTAMP : return("Timestamp"); case ISNS_PROT_VER : return("Protocol Version Range"); case ISNS_ENTITY_PERIOD : return("Entity Period"); case ISNS_ENTITY_CERT : return("Entity Certificate"); case ISNS_PORTAL_IP : return("Portal IP-Address"); case ISNS_PORTAL_PORT : return("Portal TCP/UDP Port"); case ISNS_PORTAL_SYM_NAME : return("Portal Symbolic Name"); case ISNS_ESI_INTERVAL : return("ESI Interval"); case ISNS_ESI_PORT : return("ESI/SCN UDP Port"); case ISNS_PORTAL_CERT : return("Portal Certificate"); case ISNS_ISCSI_NODE_ID : return("iSCSI Name"); case ISNS_ISCSI_TYPE : return("iSCSI Node Type"); case ISNS_ISCSI_ALIAS : return("iSCSI Node Alias"); case ISNS_ISCSI_SCN_BITMAP : return("iSCSI SCN Bitmap"); case ISNS_ISCSI_CERT : return("iSCSI Node Certificate"); case ISNS_PORT_NAME : return("Port Name"); case ISNS_PORT_ID : return("Port_ID"); case ISNS_PORT_TYPE : return("Port_Type"); case ISNS_PORT_SYM_NAME : return("Port_Symbolic Name"); case ISNS_FABRIC_PORT_NAME : return("FC Fabric Port Name"); case ISNS_FC_HARD_ADDR : return("FC Hard Address"); case ISNS_FC_PORT_IP : return("FC Port IP-Address"); case ISNS_FC_COS : return("FC Class of Service"); case ISNS_FC4_TYPE : return("FC FC-4 Types"); case ISNS_FC4_DESC : return("FC FC-4 Descriptor"); case ISNS_FC4_FEATURE : return("FC FC-4 Features"); case ISNS_IFCP_SCN_BITMAP : return("iFCP Node SCN bitmap"); case ISNS_IFCP_NODE_CERT : return("iFCP Node Certificate"); case iSNS_FC4_TYPE_QUERY_KEY : return("FC-4 Type Code"); case ISNS_NODE_NAME : return("FC Device WWNN"); case ISNS_NODE_SYM_NAME : return("FC Device Sym Node Name"); case ISNS_FC_NODE_IP : return("FC Device IP-Address"); case ISNS_FC_NODE_IPA : return("FC Device IPA"); case ISNS_FC_NODE_CERT : return("FC Device Certificate"); case ISNS_DDS_ID : return("Discovery Domain Set ID"); case ISNS_DDS_SYM_NAME : return("Discovery Domain Set Symbolic Name"); case ISNS_DDS_STATUS : return("Discovery Domain Set Status"); case ISNS_DD_ID : return("Discovery Domain ID"); case ISNS_DD_FEATURE_BITMAP : return("Discovery Domain Feature Bitmap"); case ISNS_DD_SYM_NAME : return("Discovery Domain Symbolic Name"); case ISNS_DD_ISCSI_MEMBER : return("Discovery Domain iSCSI Member"); case ISNS_DD_IFCP_MEMBER : return("Discovery Domain iFCP Member"); case ISNS_COMPANY_OUI : return("Company OUI"); case ISNS_ENTITY_IDX : return("Entity Index"); case ISNS_ISCSI_IDX : return("iSCSI Index"); case ISNS_PORTAL_IDX : return("Portal Index"); case ISNS_DD_ISCSI_MEMBER_IDX: return("Discovery Domain iSCSI Member Index"); case ISNS_DD_ACTIVE : return("Discovery Domain Active"); case ISNS_NODE_ACTIVE : return("Node Active"); case ISNS_SCN_PORT : return("SCN Port"); case ISNS_PORTAL_GROUP : return("Portal Group Tag (depreciated)"); case ISNS_PORTAL_GROUP_TAG : return("Portal Group Tag"); case ISNS_PORTAL_GROUP_ISCSI_NAME : return("Portal Group ISCSI Name"); case ISNS_PORTAL_GROUP_IP : return("Portal Group IP Address"); case ISNS_PORTAL_GROUP_PORT : return("Portal Group TCP/UDP Port"); case ISNS_PORTAL_SECURITY_BITMAP: return("Portal Security Bitmap"); default : return("Unknown TAG code"); } } /******************************************************************** ********************************************************************/ char * errorText(int errorCode) { switch (errorCode) { case 0: return ("No error detected"); case 1: return ("Unknown error."); case 2: return ("Message format error."); case 3: return ("Invalid registration."); case 4: return ("Requested ESI period too short."); case 5: return ("Invalid query."); case 6: return ("Authentication unknown."); case 7: return ("Authentication absent."); case 8: return ("Authentication failed."); case 9: return ("No such entry."); case 10: return ("Version not supported."); case 11: return ("Internal bus error."); case 12: return ("Busy now."); case 13: return ("Option not understood"); case 14: return ("Invalid update."); case 15: return ("Message not supported"); case 16: return ("SCN event rejected."); case 17: return ("SCN registration rejected."); case 18: return ("Attribute not implemented."); case 19: return ("SWITCH_ID not available."); case 20: return ("SWITCH_ID not allocated."); default: return ("Unknown error code."); } } /*********************************************************************/ /* Parses a PDU */ /*********************************************************************/ void ParsePDU (char *buffer) { ISNS_Attr *p_attr; ISNS_Msg_Hdr *pdu; char *ptr; uint16_t pdufunc; uint16_t pdulen; uint16_t pduflags; uint32_t attrtag; uint32_t attrlen; int i=0; int *valword; pdu = (ISNS_Msg_Hdr *)buffer; __LOG_INFO("PDU Header: Version(%d) Func(%04X=%s) Len(%d) Flags(%04X) XID(%04X) Seq(%04X)\n", ntohs(pdu->version), pdufunc = ntohs(pdu->type), FuncIDText(ntohs(pdu->type)), pdulen = ntohs(pdu->msg_len), pduflags = ntohs(pdu->flags), ntohs(pdu->xid), ntohs(pdu->sequence)); ptr = buffer + sizeof (ISNS_Msg_Hdr); if (pdufunc >= ISNS_START_VALID_RES_FUNC_ID) { __LOG_INFO ("Error Code = %08X, \"%s\"\n", ntohl (*(uint32_t *) ptr), errorText(ntohl (*(uint32_t *) ptr))); ptr += 4; } if (pdufunc == ISNS_HEART_BEAT) { ISNS_Hb * hb = (ISNS_Hb *)ptr; char ipaddr[45]; ipaddrchar(hb->ip_addr.v, ipaddr); __LOG_INFO("IP address = %s\n",ipaddr); __LOG_INFO("UDP port = %d\n",ntohs(hb->udp_port)); __LOG_INFO("TCP port = %d\n",ntohs(hb->tcp_port)); __LOG_INFO("Interval = %d\n",ntohl(hb->interval)); __LOG_INFO("Counter = %d\n",ntohl(hb->counter)); } else while (ptr < buffer + sizeof (ISNS_Msg_Hdr) + pdulen) { p_attr = (struct ISNS_attr *)ptr; attrtag = ntohl (p_attr->tag); attrlen = ntohl (p_attr->len); __LOG_INFO("%08X %08X ",attrtag,attrlen); if (attrlen==0) __LOG_INFO("Tag: %s (empty)\n", isnsTagText(attrtag)); else switch (attrtag) { case ISNS_ENTITY_PERIOD : case ISNS_PORTAL_PORT : case ISNS_ESI_INTERVAL : case ISNS_ESI_PORT : case ISNS_DDS_ID : case ISNS_DD_ID : case ISNS_DD_FEATURE_BITMAP : __LOG_INFO ("Tag: %s = %d\n", isnsTagText(attrtag), ntohl(p_attr->val.index)); break; case ISNS_ENTITY_ID : case ISNS_PORTAL_SYM_NAME : case ISNS_DDS_SYM_NAME : case ISNS_DD_SYM_NAME : case ISNS_ISCSI_NODE_ID : case ISNS_ISCSI_ALIAS : case ISNS_PORT_NAME : case ISNS_PORT_SYM_NAME : case ISNS_FABRIC_PORT_NAME : case ISNS_NODE_SYM_NAME : case ISNS_DD_ISCSI_MEMBER : case ISNS_DD_IFCP_MEMBER : __LOG_INFO ("Tag: %s = \"%s\"\n", isnsTagText(attrtag), (char *)&p_attr->val); break; case ISNS_PORT_TYPE : __LOG_INFO ("Tag: %s = %08X (%s)\n", isnsTagText(attrtag), ntohl(p_attr->val.index), ntohl(p_attr->val.index)?"TCP":"UDP"); break; case ISNS_MGMT_IP : case ISNS_PORTAL_IP : case ISNS_FC_PORT_IP : case ISNS_FC_NODE_IP : { char ipaddr[45]; ipaddrchar(&p_attr->val,&ipaddr); __LOG_INFO ("Tag: %s = %s\n", isnsTagText(attrtag),ipaddr); } break; case ISNS_TIMESTAMP : { time_t timevalue; timevalue = ntohl(p_attr->val.timestamp.t_time); __LOG_INFO ("Tag: %s = %s", isnsTagText(attrtag), ctime(&timevalue)); break; } case ISNS_PROT_VER : __LOG_INFO ("Tag: %s = %04X-%04X\n", isnsTagText(attrtag), ntohs(p_attr->val.prot_ver.ver_min),ntohs(p_attr->val.prot_ver.ver_max)); break; case ISNS_ISCSI_TYPE : { char iscsi_type_str[256]={0}; uint32_t type = ntohl(p_attr->val.index); if (type & ISNS_ISCSI_TYPE_TARGET) strcat(iscsi_type_str, " Target"); if (type & ISNS_ISCSI_TYPE_INITIATOR) strcat(iscsi_type_str, " Initiator"); if (type & ISNS_ISCSI_TYPE_CONTROL) strcat(iscsi_type_str, " Control"); if (type & ISNS_ISCSI_TYPE_REMOTE) strcat(iscsi_type_str, " Remote"); __LOG_INFO ("Tag: %s = %08X (%s)\n", isnsTagText(attrtag), type, iscsi_type_str); } break; case ISNS_ENTITY_TYPE : { char * entity_type_str; switch (ntohl(p_attr->val.index)) { case ENTITY_TYPE_ISCSI: entity_type_str="iSCSI"; break; case ENTITY_TYPE_IFCP : entity_type_str="iFCP"; break; default: entity_type_str="unrecognized Entity type"; } __LOG_INFO ("Tag: %s = %08X (%s)\n", isnsTagText(attrtag), ntohl(p_attr->val.index), entity_type_str); } break; case ISNS_DDS_STATUS: __LOG_INFO ("Tag: %s = %08X (%s)\n", isnsTagText(attrtag), ntohl(p_attr->val.index), ntohl(p_attr->val.index)?"Enabled":"Disabled"); break; case ISNS_ENTITY_CERT : case ISNS_PORTAL_CERT : case ISNS_ISCSI_SCN_BITMAP : { uint32_t scn; char buffer[256]={0}; scn = ntohl(p_attr->val.index); if (scn & ISNS_SCN_DETAILED) strcat(buffer, " Detailed SCN"); if (scn & ISNS_SCN_MEMBER_ADDED) strcat(buffer, " Member Added"); if (scn & ISNS_SCN_MEMBER_REMOVED) strcat(buffer, " Member Removed"); if (scn & ISNS_SCN_OBJ_UPDATED) strcat(buffer, " Object Update"); if (scn & ISNS_SCN_OBJ_ADDED) strcat(buffer, " Object Added"); if (scn & ISNS_SCN_OBJ_REMOVED) strcat(buffer, " Object Removed"); __LOG_INFO ("Tag: %s = %08X (%s)\n", isnsTagText(attrtag), ntohl(p_attr->val.index), buffer); } break; case ISNS_ISCSI_CERT : case ISNS_PORT_ID : case ISNS_FC_HARD_ADDR : case ISNS_FC_COS : case ISNS_FC4_TYPE : case ISNS_FC4_DESC : case ISNS_FC4_FEATURE : case ISNS_IFCP_SCN_BITMAP : { uint32_t scn; char buffer[256]={0}; scn = ntohl(p_attr->val.index); if (scn & ISNS_SCN_DETAILED) strcat(buffer, " Detailed SCN"); if (scn & ISNS_SCN_MEMBER_ADDED) strcat(buffer, " Member Added"); if (scn & ISNS_SCN_MEMBER_REMOVED) strcat(buffer, " Member Removed"); if (scn & ISNS_SCN_OBJ_UPDATED) strcat(buffer, " Object Update"); if (scn & ISNS_SCN_OBJ_ADDED) strcat(buffer, " Object Added"); if (scn & ISNS_SCN_OBJ_REMOVED) strcat(buffer, " Object Removed"); __LOG_INFO ("Tag: %s = %08X (%s)\n", isnsTagText(attrtag), ntohl(p_attr->val.index), buffer); } break; case ISNS_IFCP_NODE_CERT : case iSNS_FC4_TYPE_QUERY_KEY : case ISNS_NODE_NAME : case ISNS_FC_NODE_CERT : case ISNS_COMPANY_OUI : default: __LOG_INFO ("Tag: %s = ", isnsTagText(attrtag)); for (valword=(int *)&p_attr->val; (unsigned int) i #include #include "iSNS.h" #include "iSNStypes.h" #include "iSNScomm.h" #include "iSNSmsg.h" #include "iSNSparse.h" #include "iSNSdebug.h" #include "errno.h" int sns_comm_debug = 0; int sns_comm_msg_filter = 0; char snsp_ip[16]=""; char snsp_bip[16]=SNS_BROADCAST_ADDR; int snsp_port; char sns_if_name[10] = {SNS_IF_NAME}; int ifAddrGet(char *ifname, char *ip) { if (strlen (snsp_ip) != 0) { strcpy(ip, snsp_ip); } else { return (ERROR); } return(SUCCESS); } int ifBroadcastGet(char *ifname, char *ip) { strcpy(ip, snsp_bip); return(SUCCESS); } /* NOTE: none of these are IP_ADDR 16 compliant */ int sns_comm_support = SNS_LAYER_2; int sns_comm_support_set = SNS_LAYER_2; int sns3 = 0; int sns_comm_main_port = SNS_UDP_PORT; int sns_comm_main_port_set = SNS_UDP_PORT; int sns_comm_mcast_port = SNS_UDP_PORT + 1; int sns_comm_mcast_grp = 0; int sns_comm_mcast_grp_set = 0; /* Variable to enable Hacks */ int enableHack=0; /* * Socket descriptor used by the SOIP service entity to communicate * with a remote SOIP service entity */ SOCKET sd; SOCKET mc_sd; SOCKET isns_sd; /* Socket address of the ISNS */ struct sockaddr_in isns_sock; /* * Socket address of the SOIP entity */ struct sockaddr_in local_sock; /* * Socket address of the server */ struct sockaddr_in server_sock; /* * Socket address of the service client/server multicast group */ struct sockaddr_in mc_sock; void pipe_handler(int n) { __LOG_INFO ("SIGPIPE received:%i",n); } /* * Function Name: SNSCommInit * * Synopsis: int SNSCommInit(entity); * * Arguments: entity - type of SOIP service entity for * which communication services need to be * initialized. * * Description: Creates a UDP socket, binds it to the SoIP * port and joins the IP multicast group based * on the type of SOIP entity. * * Return value: SUCCESS (0) * ERROR (-1) * */ int SNSCommInit (ISNS_Entity entity) { char ip_addr[INET_ADDR_LEN+1]; int bcast_on; #ifdef SNS_LINUX int not_needed = 1; #else char not_needed = 1; #endif /* * Check the entity type, Is it a client or server ? */ if ((entity != ISNS_CLIENT) && (entity != ISNS_SECONDARY_SERVER)) return (ERROR); /* * Set initialization parameters * */ sns_comm_support = sns_comm_support_set; sns_comm_main_port = sns_comm_main_port_set; sns_comm_mcast_port = sns_comm_main_port_set + 1; sns_comm_mcast_grp = sns_comm_mcast_grp_set; if ((sns_comm_support == SNS_LAYER_3) && (!IN_CLASSD(sns_comm_mcast_grp))) sns_comm_mcast_grp = inet_addr(SNS_SCGRP_IPMC_ADDR); /* * create UDP socket. */ if ((sd = socket (AF_INET, SOCK_DGRAM, 0)) < 0) { perror("\nSNSCommInit:socket"); return (-1); } #ifdef SNS_LINUX /* Allow reuse of addresses */ if (setsockopt (sd, SOL_SOCKET, SO_REUSEADDR, ¬_needed, sizeof(not_needed)) != 0) { perror ("Reuse address"); return (-1); } #endif if ((mc_sd = socket (AF_INET, SOCK_DGRAM, 0)) < 0) { perror("\nSNSCommInit:socket"); return (-1); } #ifdef SNS_LINUX /* Allow reuse of addresses */ if (setsockopt (mc_sd, SOL_SOCKET, SO_REUSEADDR, ¬_needed, sizeof(not_needed)) != 0) { perror ("Reuse address"); return (-1); } #endif bzero ((char *) &local_sock, sizeof (struct sockaddr_in)); bzero ((char *) &server_sock, sizeof (struct sockaddr_in)); bzero ((char *) &mc_sock, sizeof (struct sockaddr_in)); local_sock.sin_family = AF_INET; server_sock.sin_family = AF_INET; mc_sock.sin_family = AF_INET; local_sock.sin_port = htons ((short)sns_comm_main_port); server_sock.sin_port = htons ((short)sns_comm_main_port); mc_sock.sin_port = htons ((short)sns_comm_mcast_port); local_sock.sin_addr.s_addr = SNSGetIfAddr(); #ifdef SNS_LINUX /* Allow reuse of addresses */ if (setsockopt (sd, SOL_SOCKET, SO_REUSEADDR, ¬_needed, sizeof(not_needed)) < 0) { perror ("Reuse address"); return (-1); } #endif /* * Bind it to the well-known SoIP UDP port */ if (0 != bind (sd, (struct sockaddr *)&local_sock, sizeof (struct sockaddr))) { close(sd); perror ("\nSNSCommInit: bind"); return (-1); } mc_sock.sin_addr.s_addr = inet_addr(ip_addr); /* SNSGetIfBroadcastAddr(); */ /* htonl (INADDR_BROADCAST); */ /* Allow reuse of addresses */ #ifdef SNS_LINUX if (setsockopt (mc_sd, SOL_SOCKET, SO_REUSEADDR, ¬_needed, sizeof(not_needed)) < 0) { perror ("Reuse address"); return (-1); } #endif if (bind (mc_sd, (struct sockaddr *)&mc_sock, sizeof (struct sockaddr)) != 0 ) { close (sd); close (mc_sd); perror ("\nSNSCommInit: bind"); return (-1); } ifBroadcastGet(sns_if_name, ip_addr); mc_sock.sin_addr.s_addr = inet_addr(ip_addr); /* * Enable broadcast traffic on the iSNS socket. * This is a temporary workaround since Tornado 1.0 does not * support IP multicasting. */ bcast_on = 1; if (setsockopt (sd, SOL_SOCKET, SO_BROADCAST, (char *) &bcast_on, sizeof (int)) == -1 ) { close (sd); perror ("\nSNSCommInit: setsockopt SO_BROADCAST:"); return (-1); } signal (SIGPIPE, pipe_handler); return (SUCCESS); } /* * Function Name: SNSGetMsg * * Synopsis: int SNSGetMsg(p_md); * * Arguments: p_md - address of message descriptor block that will * be used for storing the received message and * sender address information. * * Description: Receive a message from a remote SOIP service entity. * * Return value: * */ int SNSGetMsg(ISNS_Msg_Descp *md) { int status; int rsd; fd_set sock_set; for (;;) { /* * Wait for a message to arrive on the socket. * Forward the received message to the service * agent task for processing. */ bzero ((char *) &md->cb.sock.addr, sizeof(struct sockaddr)); bzero ((char *) &md->msg, sizeof (ISNS_Msg)); md->cb.sock.len = sizeof (struct sockaddr_in); /* Set this as UDP */ md->cb.sock.socketType = ISNS_SOCKET_TYPE_UDP; FD_ZERO(&sock_set); FD_SET (sd, &sock_set); FD_SET (mc_sd, &sock_set); if (select (mc_sd+1, &sock_set, NULL, NULL, NULL) < 0) perror ("select"); if (FD_ISSET (mc_sd, &sock_set)) rsd = mc_sd; else if (FD_ISSET (sd, &sock_set)) rsd = sd; else return (ERROR); if (recvfrom (rsd, (char *) &md->msg, sizeof (ISNS_Msg), 0, (struct sockaddr *) &md->cb.sock.addr, &md->cb.sock.len) == -1 ) { __LOG_ERROR ("Error recform "); status = ERROR; } else { if (sns3) __LOG_INFO ("Receive from %x", (int)md->cb.sock.addr.sin_addr.s_addr); { /* iSNS msg */ md->msg.hdr.type = ntohs (md->msg.hdr.type); md->msg.hdr.xid = ntohs (md->msg.hdr.xid); md->msg.hdr.msg_len = ntohs (md->msg.hdr.msg_len); md->msg.hdr.flags = ntohs (md->msg.hdr.flags); md->msg.hdr.version = ntohs (md->msg.hdr.version); md->msg.hdr.sequence = ntohs (md->msg.hdr.sequence); } status = SUCCESS; break; } } return (status); } int ISNSSendMsg(ISNS_Msg_Descp *p_md) { ISNS_Attr * attr_indx[SNS_MAX_ATTRS]; ISNS_Attr * key_indx[SNS_MAX_ATTRS]; int rval; __DEBUG (sns_comm_debug &1,ISNSSendMsg); p_md->msg.hdr.flags |= ISNS_FLAG_SND_SERVER; ISNSParseMsg(&p_md->msg, attr_indx, key_indx, NULL); if (p_md->cb.sock.socketType==ISNS_SOCKET_TYPE_UDP) { /* UDP */ rval = SNSSendMsg_UDP(p_md); } else if (p_md->cb.sock.socketType==ISNS_SOCKET_TYPE_TCP) { /* TCP */ rval = SNSSendMsg_TCP(p_md); } else { /* UDP */ rval = SNSSendMsg_UDP(p_md); __LOG_WARNING ("WARNING: Wrong Socket Type."); return (rval); } return (rval); } int SNSSendMsg_TCP(ISNS_Msg_Descp *p_md) { int s_len; int len; int dest_version; char dot_not_addr[INET_ADDR_LEN]; __DEBUG (sns_comm_debug &1,ISNSSendMsg_TCP); SNSConvertPayloadHTON(&p_md->msg); len = sizeof (SNS_Msg_Hdr) + p_md->msg.hdr.msg_len; inet_ntoa_b (p_md->cb.sock.addr.sin_addr, dot_not_addr); dest_version = p_md->msg.hdr.version; p_md->msg.hdr.type = htons (p_md->msg.hdr.type); p_md->msg.hdr.xid = htons (p_md->msg.hdr.xid); p_md->msg.hdr.version = htons (SNS_VERSION); p_md->msg.hdr.sequence = htons (p_md->msg.hdr.sequence); p_md->msg.hdr.msg_len = htons (p_md->msg.hdr.msg_len); p_md->msg.hdr.flags |= ISNS_FLAG_LAST_PDU | ISNS_FLAG_FIRST_PDU; p_md->msg.hdr.flags = htons(p_md->msg.hdr.flags); s_len = send(p_md->cb.sock.sockfd, (char *)&p_md->msg, len, 0); if (s_len<=0) { __LOG_INFO ("send() error=%d %s",s_len, strerror(errno) ); return (ERROR); } __DEBUG (sns_comm_debug &1,ISNSSendMsg_TCP finished); return (SUCCESS); } /* * Function Name: SNSSendMsg * * Synopsis: SNSSendMsg(p_md); * * Arguments: p_md - pointer to message descriptor block. The iSNS * message associaed with this descriptor is * transmitted to the address contained in the * descriptor block. * * Description: Send a iSNS message to a remote SOIP service entity * * Return value: SUCCESS (0) OR ERROR (-1) * */ int SNSSendMsg_UDP(ISNS_Msg_Descp *p_md) { int status; int len, msg_len, payload_len, count; int dest_version; int display_debug; char dot_not_addr[INET_ADDR_LEN]; SNSConvertPayloadHTON(&p_md->msg); len = sizeof (SNS_Msg_Hdr) + p_md->msg.hdr.msg_len; inet_ntoa_b (p_md->cb.sock.addr.sin_addr, dot_not_addr); dest_version = p_md->msg.hdr.version; p_md->msg.hdr.type = htons (p_md->msg.hdr.type); p_md->msg.hdr.xid = htons (p_md->msg.hdr.xid); p_md->msg.hdr.version = htons (SNS_VERSION); p_md->msg.hdr.sequence = htons (p_md->msg.hdr.sequence); p_md->msg.hdr.msg_len = htons (p_md->msg.hdr.msg_len); display_debug = 0; if (sns_comm_debug == 1) display_debug = (p_md->msg.hdr.type != sns_comm_msg_filter); else if (sns_comm_debug == 2) display_debug = (p_md->msg.hdr.type == sns_comm_msg_filter); status = SUCCESS; if (len > SNS_MAX_ETH_PACKET_SIZE) { count = 0; p_md->msg.hdr.flags |= ISNS_FLAG_FIRST_PDU; while ((status != ERROR) && (len > (int)sizeof(SNS_Msg_Hdr))) { msg_len = MIN(len, SNS_MAX_ETH_PACKET_SIZE); if (msg_len == len) p_md->msg.hdr.flags |= ISNS_FLAG_LAST_PDU; p_md->msg.hdr.flags = htons(p_md->msg.hdr.flags); payload_len = msg_len - sizeof(SNS_Msg_Hdr); p_md->msg.hdr.msg_len = htons ((short)payload_len); status = sendto(sd, (void *)&p_md->msg, msg_len, 0, (struct sockaddr *)&p_md->cb.sock.addr, p_md->cb.sock.len); __DEBUG (display_debug, (iSNS Sending msg id %d, len %d, xid %d to %s), p_md->msg.hdr.type, p_md->msg.hdr.msg_len, p_md->msg.hdr.xid, dot_not_addr); count++; p_md->msg.hdr.sequence = htons ((short)count); len -= payload_len; memcpy(&p_md->msg.payload, (char *)&p_md->msg.payload + payload_len, len - sizeof(SNS_Msg_Hdr)); } } else { if (len > (int)SNS_OLD_MAX_PACKET_SIZE) p_md->msg.hdr.msg_len = htons (SNS_OLD_MAX_PACKET_SIZE); p_md->msg.hdr.flags |= (ISNS_FLAG_LAST_PDU | ISNS_FLAG_FIRST_PDU); p_md->msg.hdr.flags = htons(p_md->msg.hdr.flags); status = sendto(sd, (void *)&p_md->msg, len, 0, (struct sockaddr *)&p_md->cb.sock.addr, p_md->cb.sock.len); __DEBUG (display_debug, (iSNS Sending msg id %#x, len %d, xid %d to %s), ntohs(p_md->msg.hdr.type), ntohs(p_md->msg.hdr.msg_len), ntohs(p_md->msg.hdr.xid), dot_not_addr); if (status != ERROR) status = SUCCESS; } return (status); } /* * Function Name: SNSGetServerAddr * * Synopsis: SNSGetServerAddr(); * * Description: Get the socket address of the server. * * Return value: SUCCESS (0) OR ERROR (-1) * */ uint32_t SNSGetServerAddr(void) { return (server_sock.sin_addr.s_addr); } /* * Function Name: SNSCommUpdate * * Synopsis: SNSCommUpdate(server_addr); * * Description: update the socket address of the server. * * Return value: SUCCESS (0) OR ERROR (-1) * */ void ISNSCommUpdate (struct in_addr *server_addr) { if (server_sock.sin_addr.s_addr != server_addr->s_addr) server_sock.sin_addr.s_addr = server_addr->s_addr; } /* * Function Name: SNSGetLocalAddr * * Synopsis: SNSGetLocalAddr(); * * Description: Get the Local socket address. * * Return value: pointer to the local socket address structure. * */ struct in_addr * SNSGetLocalAddr(void) { return(&local_sock.sin_addr); } /* * Function Name: SNSGetMCgrpAddr * * Synopsis: SNSGetMCgrpAddr(); * * Description: Get the multicast group (*misnomer*--actually broadcast) * socket address. * * Return value: pointer to the multicast group socket address structure. * */ struct in_addr * SNSGetMCgrpAddr(void) { return(&mc_sock.sin_addr); } /* * Function Name: SNSSendMsg2Server * * Synopsis: SNSSendMsg2MCServer (p_msg); * * Arguments: p_msg - pointer to message that will be sent * to the iSNS server * * Description: Send an iSNS message to the SOIP service server * * Return value: SUCCESS (0) OR ERROR (-1) * */ int ISNSSendMsg2Server (ISNS_Msg *p_msg) { int status; int len; int display_debug; char dot_not_addr[INET_ADDR_LEN]; if (server_sock.sin_addr.s_addr == 0) return ERROR; inet_ntoa_b (server_sock.sin_addr, dot_not_addr); len = sizeof (SNS_Msg_Hdr) + p_msg->hdr.msg_len; SNSConvertPayloadHTON(p_msg); if (p_msg->hdr.type<999) { p_msg->hdr.type = htons (p_msg->hdr.type); p_msg->hdr.xid = htons (p_msg->hdr.xid); p_msg->hdr.msg_len = htons (p_msg->hdr.msg_len); p_msg->hdr.flags = htons (p_msg->hdr.flags); p_msg->hdr.version = htons (SNS_VERSION); p_msg->hdr.sequence = htons (p_msg->hdr.sequence); } else { __LOG_WARNING("Warning: type is already in network byte order."); } len = sizeof (SNS_Msg_Hdr) + ntohs(p_msg->hdr.msg_len); display_debug = 0; if (sns_comm_debug == 1) display_debug = (p_msg->hdr.type != sns_comm_msg_filter); else if (sns_comm_debug == 2) display_debug = (p_msg->hdr.type == sns_comm_msg_filter); if ( sendto(sd, (void *)p_msg, len, 0, (struct sockaddr *)&server_sock, sizeof(struct sockaddr_in)) == ERROR) { __DEBUG (sns_comm_debug, (Error in Sending message to %s), dot_not_addr); status = ERROR; } else { __DEBUG (display_debug, (Sending message to %s), dot_not_addr); status = SUCCESS; } return (status); } /* * Function Name: SNSSendMsg2MCgrp * * Synopsis: SNSSendMsg2MCgrp (p_msg); * * Arguments: p_msg - pointer to message that will be multicast * to the SOIP service server/client group * * Description: Send an iSNS message to the SOIP service server/client * multicast group. * * Return value: SUCCESS (0) OR ERROR (-1) * */ int SNSSendMsg2MCgrp (ISNS_Msg *p_msg) { int status; int len; int display_debug; struct sockaddr_in mc_dest_sock; char dot_not_addr[INET_ADDR_LEN]; len = sizeof (SNS_Msg_Hdr) + p_msg->hdr.msg_len; SNSConvertPayloadHTON(p_msg); p_msg->hdr.type = htons (p_msg->hdr.type); p_msg->hdr.xid = htons (p_msg->hdr.xid); p_msg->hdr.msg_len = htons (p_msg->hdr.msg_len); p_msg->hdr.flags = htons ((short)(p_msg->hdr.flags | ISNS_FLAG_SND_SERVER | ISNS_FLAG_LAST_PDU | ISNS_FLAG_FIRST_PDU)); p_msg->hdr.version = htons (SNS_VERSION); p_msg->hdr.sequence = htons (p_msg->hdr.sequence); status = SUCCESS; if (sns_comm_support == SNS_LAYER_2) { inet_ntoa_b (mc_sock.sin_addr, dot_not_addr); if ( sendto(sd, (void *)p_msg, len, 0, (struct sockaddr *)&mc_sock, sizeof(struct sockaddr_in)) == ERROR) status = ERROR; } else /* SNS_LAYER_3 */ { bzero ((char *) &mc_dest_sock, sizeof (struct sockaddr_in)); mc_dest_sock.sin_family = AF_INET; mc_dest_sock.sin_port = htons((short)sns_comm_mcast_port); mc_dest_sock.sin_addr.s_addr = htonl(sns_comm_mcast_grp); inet_ntoa_b (mc_dest_sock.sin_addr, dot_not_addr); if ( sendto(mc_sd, (void *)p_msg, len, 0, (struct sockaddr *)&mc_dest_sock, sizeof(struct sockaddr_in)) == ERROR) status = ERROR; } display_debug = 0; if (sns_comm_debug == 3) display_debug = (p_msg->hdr.type != sns_comm_msg_filter); __DEBUG (display_debug, (iSNS Sending bcast/mcast msg id %d, len %d, xid %d to %s), p_msg->hdr.type, p_msg->hdr.msg_len, p_msg->hdr.xid, dot_not_addr); return (status); } /* * Function Name: SNSGetIfAddr * * Synopsis: SNSGetIfAddr(); * * Description: Obtain the IP address associated with the NIC being * used by a SOIP service entity. * * Return value: 32 bit IPv4 address in network byte order. * */ int SNSGetIfAddr(void) { char ip_addr[16]; int ip; if (ifAddrGet(sns_if_name, ip_addr) == ERROR) { //return(INADDR_ANY); ip = SNSGetIPAddress(); return ip; } else return(inet_addr(ip_addr)); } /* * Function Name: SNSGetIfBroadcastAddr * * Synopsis: SNSGetIfBroadcastAddr(); * * Description: Obtain the Broadcat IP address associated with the NIC being * used by a SOIP service entity. * * Return value: 32 bit IPv4 address in network byte order. * */ int SNSGetIfBroadcastAddr(void) { char ip_addr[16]; if (ifBroadcastGet(sns_if_name, ip_addr) == ERROR) return(htonl(INADDR_ANY)); else return(inet_addr(ip_addr)); } /* * Function Name: SNSGetMgmtAddr * * Synopsis: SNSGetMgmtAddr(); * * Description: Obtain the IP address associated with the * switch management interface. * * Return value: 32 bit IPv4 address in network byte order. * */ int SNSGetMgmtAddr(void) { char ip_addr[INET_ADDR_LEN+1]; if (ifAddrGet(SNS_IFMGMT_NAME, ip_addr) == ERROR) return(INADDR_ANY); else return(inet_addr(ip_addr)); } int SNSGetIPAddress() { char hostname[256]; struct hostent *host; struct in_addr h_addr; gethostname(hostname,sizeof(hostname)); host = gethostbyname(hostname); h_addr.s_addr= *(uint32_t *)(host->h_addr_list[0]); return h_addr.s_addr; } isns-2.1-01/isnsserver/src/iSNShash.c0000644000175000017500000003131510665040341016376 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include "iSNStypes.h" #include "iSNSmsg.h" #include "iSNShash.h" #include "ndb.h" #include "iSNSdebug.h" static uint32_t hash(datum *pKey); static uint32_t entry_match_key (SNSHashEntry *pEntry, datum *pKey); static void* snsHashAlloc(uint32_t size); static void snsHashFree(void *p); static SNSHashEntry* createHashEntry(datum *pKey, datum *pContent); SNSHashEntry **HashKeyTable[HASH_TABLE_NUM_ENTRIES]; /* SNSHashEntry *HashTable[HASH_TABLE_NUM_ENTRIES]; */ MSG_Q_ID SNSHashEntryQ = NULL; uint8_t *HashBufferPool = NULL; int ndb_debug = 0; datum gNullDatum; ndb_error ndb_errno; NDB_FILE ndb_open (char *file, int block_size, int flags, int mode, void (*fatal_func)()) { int x; /* memset(HashTable, 0, sizeof(HashTable)); */ if (!SNSHashEntryQ) { SNSHashEntryQ = (void *)1; HashBufferPool = (uint8_t*)calloc(HASH_NUM_BUFFERS, HASH_BUFFER_SIZE); if (!HashBufferPool || !SNSHashEntryQ) return NULL; } gNullDatum.dsize = 0; gNullDatum.dptr = NULL; /* Initialize all hash tables */ for (x = 0; x < END_SNS_DEVI_ATTR; x++) { HashKeyTable[x] = calloc(HASH_TABLE_NUM_ENTRIES, sizeof(SNSHashEntry *)); } return (NDB_FILE)1234; } void ndb_close (NDB_FILE dbf) { SNSHashEntryQ = NULL; free(HashBufferPool); HashBufferPool = NULL; return; } int ndb_store ( NDB_FILE dbf, datum key, datum content, int flags) { SNSHashEntry *pEntry, *pPrev = NULL; uint32_t hash_val, i, hash_key_val; SNSHashEntry **table_ptr; hash_key_val = ((SOIP_DB_Entry *)(content.dptr))->data_type; if (ndb_debug & 0x02) { printf("ndb_store(): data_type = %d, hashes = %d", (int)hash_key_val, (int)hash_key_val); } table_ptr = HashKeyTable[ hash_key_val ]; hash_val = hash(&key); if (ndb_debug & 0x02) { printf("ndb_store(): entry stored at %d. Key size: %d\n", (int)hash_val, (int)key.dsize); for (i = 0; i < (unsigned)key.dsize; i ++) { if (i % 16 == 0) printf("\n"); printf("%02x ", (unsigned)key.dptr[i]); } printf("\n"); if (ndb_debug & 0x08) { for (i = 0; i < MIN((unsigned)content.dsize, 64); i ++) { if (i % 16 == 0) printf("\n"); printf("%02x ", (unsigned)content.dptr[i]); } } printf("\n"); } if (!table_ptr[hash_val]) { table_ptr[hash_val] = createHashEntry(&key, &content); return SUCCESS; } for (pEntry = table_ptr[hash_val]; pEntry; pEntry = pEntry->next) { if (entry_match_key(pEntry, &key)) { pEntry->data_len = MIN((unsigned)content.dsize, HASH_MAX_DATA_SIZE); /* Note: the entry's size might change, might need to re-alloc in the future */ memcpy(pEntry->data, content.dptr, pEntry->data_len); return SUCCESS; } pPrev = pEntry; } pPrev->next = createHashEntry(&key, &content); pPrev->next->prev = pPrev; return SUCCESS; } datum ndb_fetch (uint32_t key_type, datum key) { SNSHashEntry *pEntry; SNSHashEntry **table_ptr; uint32_t hash_val; uint32_t hash_key_val; datum ret; unsigned i; hash_key_val = key_type; if (ndb_debug & 0x02) { printf("ndb_fetch(): data_type = %d, hashes = %d", (int)key_type, (int)hash_key_val); } table_ptr = HashKeyTable[ hash_key_val ]; hash_val = hash(&key); if (ndb_debug & 0x04) { printf("ndb_fetch(): fetch hash %d. Key size: %d\n", (int)hash_val, (int)key.dsize); for (i = 0; i < (unsigned)key.dsize; i ++) { if (i % 16 == 0) printf("\n"); printf("%02x ", (unsigned)key.dptr[i]); } printf("\n"); } for (pEntry = table_ptr[hash_val]; pEntry; pEntry = pEntry->next) { if (entry_match_key(pEntry, &key)) { ret.dsize = pEntry->data_len; ret.dptr = malloc(ret.dsize); memcpy(ret.dptr, pEntry->data, ret.dsize); return ret; } } return gNullDatum; } datum ndb_fetch_sns (uint32_t key_type, datum key, char* msg) { SNSHashEntry *pEntry; SNSHashEntry **table_ptr; uint32_t hash_val; uint32_t hash_key_val; datum ret; unsigned i; hash_key_val = key_type; if (ndb_debug & 0x02) { printf("ndb_fetch(): data_type = %d, hashes = %d", (int)key_type, (int)hash_key_val); } table_ptr = HashKeyTable[ hash_key_val ]; hash_val = hash(&key); if (ndb_debug & 0x04) { printf("ndb_fetch(): fetch hash %d. Key size: %d\n", (int)hash_val, (int)key.dsize); for (i = 0; i < (unsigned)key.dsize; i ++) { if (i % 16 == 0) printf("\n"); printf("%02x ", (unsigned)key.dptr[i]); } printf("\n"); } for (pEntry = table_ptr[hash_val]; pEntry; pEntry = pEntry->next) { if (entry_match_key(pEntry, &key)) { ret.dsize = pEntry->data_len; ret.dptr = msg; memcpy(ret.dptr, pEntry->data, ret.dsize); return ret; } } return gNullDatum; } int ndb_delete (uint32_t key_type, datum key) { SNSHashEntry *pEntry; SNSHashEntry **table_ptr; uint32_t hash_val; uint32_t hash_key_val; hash_key_val = key_type; if (ndb_debug & 0x02) { printf("ndb_fetch(): data_type = %d, hashes = %d", (int)key_type, (int)hash_key_val); } table_ptr = HashKeyTable[ hash_key_val ]; hash_val = hash(&key); for (pEntry = table_ptr[hash_val]; pEntry; pEntry = pEntry->next) { if (entry_match_key(pEntry, &key)) { if (pEntry->prev) pEntry->prev->next = pEntry->next; else table_ptr[hash_val] = pEntry->next; if (pEntry->next) pEntry->next->prev = pEntry->prev; snsHashFree(pEntry); return SUCCESS; } } return ERROR; } datum ndb_firstkey (uint32_t key_type) { uint32_t i, hash_key_val; datum ret; SNSHashEntry **table_ptr; hash_key_val = key_type; table_ptr = HashKeyTable[ hash_key_val ]; for (i = 0; i < HASH_TABLE_NUM_ENTRIES; i ++) { if (table_ptr[i]) { ret.dsize = table_ptr[i]->key_len; ret.dptr = malloc(ret.dsize); memcpy(ret.dptr, table_ptr[i]->key, ret.dsize); return ret; } } return gNullDatum; } datum ndb_nextkey (uint32_t key_type, datum key) { SNSHashEntry *pEntry; SNSHashEntry **table_ptr; uint32_t hash_val, i, hash_key_val; datum ret; hash_key_val = key_type; table_ptr = HashKeyTable[ hash_key_val ]; hash_val = hash(&key); for (pEntry = table_ptr[hash_val]; pEntry; pEntry = pEntry->next) { if (entry_match_key(pEntry, &key)) { if (pEntry->next) { ret.dsize = pEntry->next->key_len; ret.dptr = malloc(ret.dsize); memcpy(ret.dptr, pEntry->next->key, ret.dsize); return ret; } for (i = hash_val + 1; i < HASH_TABLE_NUM_ENTRIES; i ++) { if (table_ptr[i]) { ret.dsize = table_ptr[i]->key_len; ret.dptr = malloc(ret.dsize); memcpy(ret.dptr, table_ptr[i]->key, ret.dsize); return ret; } } break; } } return gNullDatum; } static uint32_t hash(datum *pKey) { uint32_t ret_val = 0; uint32_t i; uint8_t *key = (uint8_t*)pKey->dptr; uint8_t *end_key = key + pKey->dsize; if (pKey->dsize > 1) { while (key != end_key) { i = (uint32_t)(*key); ret_val ^= i; /*ret_val <<= 1;*/ ret_val = (ret_val << 1) + (ret_val % 2); key ++; } } else { ret_val = ((uint32_t)(*key) << 8) + (uint32_t)(*key); } return (ret_val % HASH_TABLE_NUM_ENTRIES); } static uint32_t entry_match_key (SNSHashEntry *pEntry, datum *pKey) { return (pEntry->key_len == pKey->dsize && !memcmp(pEntry->key, pKey->dptr, pKey->dsize)); } static void* snsHashAlloc(uint32_t size) { void *ret; ret=malloc(size); return ret; } static void snsHashFree(void *p) { free(p); } static SNSHashEntry* createHashEntry(datum *pKey, datum *pContent) { SNSHashEntry *pEntry; uint32_t data_len; data_len = MIN(HASH_MAX_DATA_SIZE, (unsigned)pContent->dsize); pEntry = snsHashAlloc(sizeof(SNSHashEntry) + data_len - sizeof(pEntry->data)); memset(pEntry, 0, sizeof(SNSHashEntry) + data_len - sizeof(pEntry->data)); /*pEntry->data = (char*)pEntry + sizeof(SNSHashEntry);*/ pEntry->data_len = data_len; memcpy(pEntry->data, pContent->dptr, pEntry->data_len); pEntry->key_len = MIN(HASH_KEY_SIZE, pKey->dsize); memcpy(pEntry->key, pKey->dptr, pEntry->key_len); return pEntry; } #if 0 void snsShowHashEntry(uint32_t idx, uint32_t num_bytes) { uint32_t i; int count = 0; SNSHashEntry *pEntry = HashTable[idx]; if (!pEntry) { printf("Empty entry\n"); return; } while (pEntry) { count ++; printf("\n************************\n"); printf("Current entry at: 0x%x\n", (unsigned)pEntry); printf("next: 0x%x, prev: 0x%x\n", (unsigned)pEntry->next, (unsigned)pEntry->prev); printf("key_len: %d, data_len: %d\n", (unsigned)pEntry->key_len, (unsigned)pEntry->data_len); printf("key:"); for (i = 0; i < pEntry->key_len; i ++) { if (i % 16 == 0) printf("\n"); printf("%02x ", (unsigned)pEntry->key[i]); } num_bytes = num_bytes?num_bytes:pEntry->data_len; num_bytes = MIN(pEntry->data_len, num_bytes); printf("\ndata: %d bytes shown", (unsigned)num_bytes); for (i = 0; i < num_bytes; i ++) { if (i % 16 == 0) printf("\n"); printf("%02x ", (unsigned)pEntry->data[i]); } printf("\n************************\n"); pEntry = pEntry->next; } printf("Total: %d entries\n\n", count); } #endif void snsShowHashTable( void ) { int x; int i; int slot_count = 0; int total_count = 0; int count_per_entry; SNSHashEntry **table_ptr; SNSHashEntry *pEntry; for (x = 0; x < END_SNS_DEVI_ATTR; x++) { table_ptr = HashKeyTable[ x ]; for (i = 0; i < HASH_TABLE_NUM_ENTRIES; i ++) { count_per_entry = 0; for (pEntry = table_ptr[i]; pEntry; pEntry = pEntry->next) count_per_entry ++; if (count_per_entry) { if (slot_count % 8 == 0 ) printf("\n"); printf("%d", i); if (count_per_entry > 1) printf("(%d)", count_per_entry); printf(" "); total_count += count_per_entry; slot_count ++; } } } printf("\nTotal: %d entries in %d slots\n\n", total_count, slot_count); } isns-2.1-01/isnsserver/src/iSNSobjects.c0000644000175000017500000004443310665040341017111 0ustar zobelzobel/*********************************************************************** Copyright (c) 2007, Novell, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Novell, Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NOVELL, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This file contains source code for managing read and writing of iSNS objects * to the database * */ #include "iSNS.h" #include "iSNSdb.h" #include "iSNSobjects.h" #include "iSNStypes.h" #include "iSNSmsg.h" #include "iSNSdebug.h" /* Global */ extern int isns_db_debug; /********************************************************************* read_FCNodeObject *********************************************************************/ int read_FCNodeObject (char *p_id, SOIP_Fc_Node **p_node, SOIP_DB_Entry *p_entry) { ISNS_DBKey key; int rval; if ( (p_id == NULL ) || (strlen(p_id) <= 0) ) return (ERROR); key.tag = NODE_NAME_KEY; strcpy(key.val.node_key.v, p_id); rval = ISNSdbRead(&key,p_entry); *p_node = (SOIP_Fc_Node *)&p_entry->data; return rval; } /********************************************************************* read_FCPortObject *********************************************************************/ int read_FCPortObject (char *p_id, SOIP_Ifcp **p_node, SOIP_DB_Entry *p_entry) { ISNS_DBKey key; int rval; if ( (p_id == NULL ) || (strlen(p_id) <= 0) ) return (ERROR); key.tag = PORT_NAME_KEY; strcpy(key.val.port_key.v, p_id); rval = ISNSdbRead(&key,p_entry); *p_node = (SOIP_Ifcp *)&p_entry->data; return rval; } /********************************************************************* read_ISCSIObject *********************************************************************/ int read_ISCSIObject (char *p_id, SOIP_Iscsi **p_node, SOIP_DB_Entry *p_entry) { ISNS_DBKey key; int rval; if ( (p_id == NULL ) || (strlen(p_id) <= 0) ) return (ERROR); key.tag = ISCSI_ID_KEY; strcpy(key.val.iscsi_key.v, p_id); rval = ISNSdbRead(&key,p_entry); *p_node = (SOIP_Iscsi *)&p_entry->data; return rval; } /********************************************************************* read_EntityObject Fetches an entity from the database PARAMETERS: 1. p_entity_id - Entity ID. 2. p_entity - Address where to place results 2. p_entry - ENTRY Record RETURNS: 1. p_entity - will point to entry. Returns "no_error" if successful. *********************************************************************/ int read_EntityObject (char *p_entity_id, SOIP_Entity **p_entity, SOIP_DB_Entry *p_entry) { ISNS_DBKey key; int rval; if ( (p_entity_id == NULL ) || (strlen(p_entity_id) <= 0) ) return (ERROR); key.tag = ENTITY_ID_KEY; strcpy(key.val.entity_key.id,p_entity_id); rval = ISNSdbRead(&key,p_entry); *p_entity = (SOIP_Entity *)&p_entry->data; return rval; } /********************************************************************* read_PortalObject *********************************************************************/ int read_PortalObject (SOIP_Portal_Key *p_portal_key, SOIP_Portal **p_portal, SOIP_DB_Entry *p_entry) { ISNS_DBKey key; int rval; if ( p_portal_key == NULL ) return (ERROR); key.tag = PORTAL_ID_KEY; __ISNS_COPY (&key.val.portal_key, sizeof(SOIP_Portal_Key), p_portal_key, sizeof(SOIP_Portal_Key)); rval = ISNSdbRead(&key,p_entry); *p_portal = (SOIP_Portal *)&p_entry->data; return rval; } /********************************************************************* read_PortalGroupObject *********************************************************************/ int read_PortalGroupObject (SOIP_Portal_Group_Key *p_portal_key, SOIP_Portal_Group **p_portal, SOIP_DB_Entry *p_entry) { ISNS_DBKey key; int rval; if ( p_portal_key == NULL ) return (ERROR); key.tag = PORTAL_GROUP_ID_KEY; __ISNS_COPY (&key.val.portal_group_key, sizeof(SOIP_Portal_Group_Key), p_portal_key, sizeof(SOIP_Portal_Group_Key)); rval = ISNSdbRead(&key,p_entry); *p_portal = (SOIP_Portal_Group *)&p_entry->data; return rval; } /********************************************************************* read_DDObject Reads a DD object from the database *********************************************************************/ int read_DDObject (int id, SOIP_Dd **p_dd, SOIP_DB_Entry *p_entry) { ISNS_DBKey key; int rval; if (id == 0) return (ERROR); key.tag = DD_ID_KEY; key.val.dd_key.id = id; rval = ISNSdbRead(&key,p_entry); *p_dd = (SOIP_Dd *)&p_entry->data; return rval; } /********************************************************************* read_DDSObject Reads a DDS object from the database *********************************************************************/ int read_DDSObject (int id, SOIP_Dds **p_dds, SOIP_DB_Entry *p_entry) { ISNS_DBKey key; int rval; if (id == 0) return (ERROR); key.tag = DDS_ID_KEY; key.val.dds_key.id = id; rval = ISNSdbRead(&key,p_entry); *p_dds = (SOIP_Dds *)&p_entry->data; return rval; } /********************************************************************* read_EntityidxObject Reads a idx object from the database *********************************************************************/ int read_EntityidxObject (int id, void **p_idx, SOIP_DB_Entry *p_entry) { ISNS_DBKey key; int rval; if (id == 0) return (ERROR); key.tag = ENTITY_IDX_KEY; key.val.idx.index = id; key.val.idx.index_type = ENTITY_IDX_KEY; rval = ISNSdbRead(&key,p_entry); *p_idx = (char *)&p_entry->data.entity_idx.id; return rval; } /********************************************************************* read_ISCSIidxObject Reads a idx object from the database *********************************************************************/ int read_ISCSIidxObject (int id, void **p_idx, SOIP_DB_Entry *p_entry) { ISNS_DBKey key; int rval; if (id == 0) return (ERROR); key.tag = ISCSI_IDX_KEY; key.val.idx.index = id; key.val.idx.index_type = ISCSI_IDX_KEY; rval = ISNSdbRead(&key,p_entry); *p_idx = (char *)&p_entry->data.iscsi_idx; return rval; } /********************************************************************* read_PortalidxObject Reads a idx object from the database *********************************************************************/ int read_PortalidxObject (int id, void **p_idx, SOIP_DB_Entry *p_entry) { ISNS_DBKey key; int rval; if (id == 0) return (ERROR); key.tag = PORTAL_IDX_KEY; key.val.idx.index = id; key.val.idx.index_type = PORTAL_IDX_KEY; rval = ISNSdbRead(&key,p_entry); *p_idx = (char *)&p_entry->data.portal_idx; return rval; } /********************************************************************* write_FCNodeObject Writes a FCNode object from the database *********************************************************************/ int write_FCNodeObject (char *p_id, SOIP_DB_Entry p_entry) { ISNS_DBKey key; int rval; if ( (p_id == NULL ) || (strlen(p_id) <= 0) ) return (ERROR); key.tag = NODE_NAME_KEY; strcpy(key.val.node_key.v,p_id); rval = ISNSdbWrite(&key, p_entry); return rval; } /********************************************************************* write_FCPortObject Writes a FCPort object from the database *********************************************************************/ int write_FCPortObject (char *p_id, SOIP_DB_Entry p_entry) { ISNS_DBKey key; int rval; if ( (p_id == NULL ) || (strlen(p_id) <= 0) ) return (ERROR); key.tag = PORT_NAME_KEY; strcpy(key.val.port_key.v,p_id); rval = ISNSdbWrite(&key, p_entry); return rval; } /********************************************************************* write_ISCSIObject Writes a ISCSI object from the database *********************************************************************/ int write_ISCSIObject (char *p_id, SOIP_DB_Entry p_entry) { ISNS_DBKey key; int rval; if ( (p_id == NULL ) || (strlen(p_id) <= 0) ) return (ERROR); key.tag = ISCSI_ID_KEY; strcpy(key.val.iscsi_key.v,p_id); rval = ISNSdbWrite(&key, p_entry); return rval; } /********************************************************************* write_EntityObject Writes a Entity object from the database *********************************************************************/ int write_EntityObject (char *p_entity_id, SOIP_DB_Entry p_entry) { ISNS_DBKey key; int rval; if ( (p_entity_id == NULL ) || (strlen(p_entity_id) <= 0) ) return (ERROR); key.tag = ENTITY_ID_KEY; strcpy(key.val.entity_key.id,p_entity_id); rval = ISNSdbWrite(&key, p_entry); return rval; } /********************************************************************* write_PortalObject Writes a Portal object from the database *********************************************************************/ int write_PortalObject (SOIP_Portal_Key *p_id, SOIP_DB_Entry p_entry) { ISNS_DBKey key; int rval; if ( (p_id == NULL ) ) return (ERROR); key.tag = PORTAL_ID_KEY; __ISNS_COPY(&key.val.portal_key, sizeof(SOIP_Portal_Key), p_id, sizeof(SOIP_Portal_Key)); rval = ISNSdbWrite(&key, p_entry); return rval; } /********************************************************************* write_PortalGroupObject Writes a PortalGroup object from the database *********************************************************************/ int write_PortalGroupObject (SOIP_Portal_Group_Key *p_id, SOIP_DB_Entry p_entry) { ISNS_DBKey key; int rval; if ( (p_id == NULL ) ) return (ERROR); key.tag = PORTAL_GROUP_ID_KEY; __ISNS_COPY(&key.val.portal_group_key, sizeof(SOIP_Portal_Group_Key), p_id, sizeof(SOIP_Portal_Group_Key)); rval = ISNSdbWrite(&key, p_entry); return rval; } /********************************************************************* write_DDObject Writes a DD object from the database *********************************************************************/ int write_DDObject (int id, SOIP_DB_Entry p_entry) { ISNS_DBKey key; int rval; if (id == 0) return (ERROR); key.tag = DD_ID_KEY; key.val.dd_key.id = id; rval = ISNSdbWrite(&key, p_entry); return rval; } /********************************************************************* write_DDSObject Writes a DDS object from the database *********************************************************************/ int write_DDSObject (int id, SOIP_DB_Entry p_entry) { ISNS_DBKey key; int rval; if (id == 0) return (ERROR); key.tag = DDS_ID_KEY; key.val.dds_key.id = id; rval = ISNSdbWrite(&key, p_entry); return rval; } /********************************************************************* write_ISCSIidxObject Writes a index object from the database *********************************************************************/ int write_ISCSIidxObject (int id, SOIP_DB_Entry p_entry) { ISNS_DBKey idx_key; int rval; if (id == 0) return (ERROR); idx_key.tag = ISCSI_IDX_KEY; idx_key.val.idx.index_type = ISCSI_IDX_KEY; idx_key.val.idx.index = id; rval = ISNSdbWrite(&idx_key,p_entry); return rval; } /********************************************************************* write_EntityidxObject Writes a index object from the database *********************************************************************/ int write_EntityidxObject (int id, SOIP_DB_Entry p_entry) { ISNS_DBKey idx_key; int rval; if (id == 0) return (ERROR); idx_key.tag = ENTITY_IDX_KEY; idx_key.val.idx.index_type = ENTITY_IDX_KEY; idx_key.val.idx.index = id; rval = ISNSdbWrite(&idx_key,p_entry); return rval; } /********************************************************************* write_PortalidxObject Writes a index object from the database *********************************************************************/ int write_PortalidxObject (int id, SOIP_DB_Entry p_entry) { ISNS_DBKey idx_key; int rval; if (id == 0) return (ERROR); idx_key.tag = PORTAL_IDX_KEY; idx_key.val.idx.index_type = PORTAL_IDX_KEY; idx_key.val.idx.index = id; rval = ISNSdbWrite(&idx_key,p_entry); return rval; } /********************************************************************* delete_DDObject delete a DD object from the database *********************************************************************/ int delete_DDObject (int id) { ISNS_DBKey key; int rval; if (id == 0) return (ERROR); key.tag = DD_ID_KEY; key.val.dd_key.id = id; rval = ISNSdbDelete(&key); return rval; } /********************************************************************* delete_DDSObject delete a DDS object from the database *********************************************************************/ int delete_DDSObject (int id) { ISNS_DBKey key; int rval; if (id == 0) return (ERROR); key.tag = DDS_ID_KEY; key.val.dds_key.id = id; rval = ISNSdbDelete(&key); return rval; } /********************************************************************* delete_FCNodeObject delete a FCNode object from the database *********************************************************************/ int delete_FCNodeObject (char *p_id) { ISNS_DBKey key; int rval; if ( (p_id == NULL ) || (strlen(p_id) <= 0) ) return (ERROR); key.tag = NODE_NAME_KEY; strcpy(key.val.node_key.v,p_id); rval = ISNSdbDelete(&key); return rval; } /********************************************************************* delete_FCPortObject delete a FCPort object from the database *********************************************************************/ int delete_FCPortObject (char *p_id) { ISNS_DBKey key; int rval; if ( (p_id == NULL ) || (strlen(p_id) <= 0) ) return (ERROR); key.tag = PORT_NAME_KEY; strcpy(key.val.port_key.v,p_id); rval = ISNSdbDelete(&key); return rval; } /********************************************************************* delete_ISCSIObject delete a ISCSI object from the database *********************************************************************/ int delete_ISCSIObject (char *p_id) { ISNS_DBKey key; int rval; if ( (p_id == NULL ) || (strlen(p_id) <= 0) ) return (ERROR); key.tag = ISCSI_ID_KEY; strcpy(key.val.node_key.v,p_id); rval = ISNSdbDelete(&key); return rval; } /********************************************************************* delete_EntityObject delete a Enity object from the database *********************************************************************/ int delete_EntityObject (char *p_entity_id) { ISNS_DBKey key; int rval; if ( (p_entity_id == NULL ) || (strlen(p_entity_id) <= 0) ) return (ERROR); key.tag = ENTITY_ID_KEY; strcpy(key.val.entity_key.id,p_entity_id); rval = ISNSdbDelete(&key); return rval; } /********************************************************************* delete_PortalObject delete a Portal object from the database *********************************************************************/ int delete_PortalObject (SOIP_Portal_Key *p_id) { ISNS_DBKey key; int rval; if ( (p_id == NULL ) ) return (ERROR); key.tag = PORTAL_ID_KEY; __ISNS_COPY(&key.val.portal_key, sizeof(SOIP_Portal_Key), p_id, sizeof(SOIP_Portal_Key)); rval = ISNSdbDelete(&key); return rval; } /********************************************************************* delete_PortalGroupObject delete a PortalGroup object from the database *********************************************************************/ int delete_PortalGroupObject (SOIP_Portal_Group_Key *p_id) { ISNS_DBKey key; int rval; if ( (p_id == NULL ) ) return (ERROR); key.tag = PORTAL_GROUP_ID_KEY; __ISNS_COPY(&key.val.portal_group_key, sizeof(SOIP_Portal_Group_Key), p_id, sizeof(SOIP_Portal_Group_Key)); rval = ISNSdbDelete(&key); return rval; } /********************************************************************* delete_EntityidxObject delete a idx object from the database *********************************************************************/ int delete_EntityidxObject (int id) { ISNS_DBKey key; int rval; if (id == 0) return (ERROR); key.tag = ENTITY_IDX_KEY; key.val.idx.index = id; key.val.idx.index_type = ENTITY_IDX_KEY; rval = ISNSdbDelete(&key); return rval; } /********************************************************************* delete_ISCSIidxObject delete a idx object from the database *********************************************************************/ int delete_ISCSIidxObject (int id) { ISNS_DBKey key; int rval; if (id == 0) return (ERROR); key.tag = ISCSI_IDX_KEY; key.val.idx.index = id; key.val.idx.index_type = ISCSI_IDX_KEY; rval = ISNSdbDelete(&key); return rval; } /********************************************************************* delete_PortalidxObject delete a idx object from the database *********************************************************************/ int delete_PortalidxObject (int id) { ISNS_DBKey key; int rval; if (id == 0) return (ERROR); key.tag = PORTAL_IDX_KEY; key.val.idx.index = id; key.val.idx.index_type = PORTAL_IDX_KEY; rval = ISNSdbDelete(&key); return rval; } isns-2.1-01/isnsserver/src/iSNSesi.c0000644000175000017500000002137610665040341016241 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This file contains source code for managing the ESI - Entity State Inquiry. * */ #include "iSNS.h" #include "iSNSmsg.h" #include "iSNSList.h" #include "iSNSdb.h" #include "iSNSesi.h" #include "iSNSresponse.h" #include "iSNSreg.h" #include "iSNStypes.h" #include "iSNScomm.h" #include "iSNSbuffer.h" #include "iSNStbl.h" #include "iSNSparse.h" #include "iSNSdebug.h" #include "iSNSobjects.h" extern int isns_esi_debug; extern int sns_esi_interval; extern int esi_sent_limit; /* * static common variables for gdbm fetches * entry is for common registrations and queries * scn_entry is for state change notifications * opn_entry is for access control */ static SOIP_DB_Entry entry; /* top level fetches ONLY */ static SOIP_DB_Entry entry2; /* secondary fetches */ ISNS_Msg_Descp *p_rspMd; /********************************************************************* Sends out one or more ESI(s). *********************************************************************/ int ISNS_SendESI (void) { static int esi_xid = 1; int rval; SOIP_Portal *p_portal; SOIP_Portal_Key db_portal; ISNS_Msg_Descp *p_md; time_t mytime; ISNS_DBKey read_key = { 0 }; __DEBUG (isns_esi_debug &1, ISNS_SendESI); p_md = p_rspMd; memset( p_md, 0, sizeof( ISNS_Msg_Descp ) ); if (isns_role != ISNS_PRIMARY_SERVER) { return ( ISNS_NO_ERR ); } __DEBUG (isns_esi_debug &1, process each portal record); read_key.tag = PORTAL_ID_KEY; while ( SNSdbGetNextOfKey (&read_key) == SUCCESS ) { __DEBUG (isns_esi_debug &1, Next Portal Record found); __ISNS_COPY(&db_portal, sizeof(SOIP_Portal_Key), &read_key.val.portal_key, sizeof(SOIP_Portal_Key)); rval = read_PortalObject(&db_portal, &p_portal, &entry2); if (rval != SUCCESS) return rval; /* check to see if an interval is set > 0 */ if ( p_portal->esi_interval == 0 ) { __DEBUG (isns_esi_debug &1, esi_interval not set); continue; } /* check to see if timer interval expired */ time ( &mytime ); if (p_portal->esi_timer > 0 && (p_portal->esi_timer + p_portal->esi_interval) > mytime) { __DEBUG (isns_esi_debug &1, esi_timer plus interval not reached yet); __DEBUG (isns_esi_debug &1, esi_timer:%ld,p_portal->esi_timer); __DEBUG (isns_esi_debug &1, esi_interval:%i,p_portal->esi_interval); __DEBUG (isns_esi_debug &1, mytime:%ld,mytime); continue; } p_portal->esi_timer = mytime; p_portal->esiSent++; rval = write_PortalObject(&db_portal, entry2); __DEBUG (isns_esi_debug &1, esi_timer Timer Expired esiSend:%i,p_portal->esiSent); if ( p_portal->esiSent < esi_sent_limit ) { __DEBUG (isns_esi_debug & 2, (Sending ESI to Entity %s), p_portal->entity_id.id); /* Send a msg to the client & update the counter */ memset (&p_md->msg, 0, sizeof (ISNS_Msg)); p_md->msg.hdr.type = ISNS_ESI; ISNSAppendKey (&p_md->msg, ISNS_ENTITY_ID, PAD4 (strlen (p_portal->entity_id.id)), p_portal->entity_id.id, 0); ISNSAppendKey ( &p_md->msg, ISNS_PORTAL_IP, ISNS_IP_SIZE, p_portal->ip_addr.v, 0); ISNSAppendKey ( &p_md->msg, ISNS_PORTAL_PORT, ISNS_PORTAL_PORT_SIZE, NULL, p_portal->ip_port); memcpy ( &p_md->cb.sock.addr.sin_addr.s_addr, p_portal->ip_addr.v + 12, sizeof (p_md->cb.sock.addr.sin_addr.s_addr)); /* Determine how to send */ if ( p_portal->esi_port ) { p_md->msg.hdr.xid = esi_xid++; p_md->cb.sock.socketType = ISNS_SOCKET_TYPE_UDP; p_md->cb.sock.addr.sin_port = htons ((short)(p_portal->esi_port & 0xFFFF)); } else { p_md->msg.hdr.xid = esi_xid++; p_md->cb.sock.socketType = ISNS_SOCKET_TYPE_TCP; p_md->cb.sock.sockfd = p_portal->esi_sockfd; } __DEBUG (isns_esi_debug & 2, (Call ISNSSendMsg to Send ESI to Entity %s), p_portal->entity_id.id); rval = ISNSSendMsg ( p_md ); } else { __DEBUG (isns_esi_debug &1,esi timed out - remove portal record); __DEBUG (isns_esi_debug &1,portal ip_addr:%s,inet_ntoa(*(struct in_addr *)(p_portal->ip_addr.v+12)) ); __DEBUG (isns_esi_debug &1,port:%i,p_portal->ip_port); /* remove portal */ memset (&db_portal, 0, sizeof (db_portal)); memcpy (db_portal.ip_addr.v, p_portal->ip_addr.v, ISNS_IP_SIZE); db_portal.ip_port=p_portal->ip_port; SNSRemovePortalEntry (&db_portal, NULL, NULL); } } return ( ISNS_NO_ERR ); } /********************************************************************* Processes an ESI response. *********************************************************************/ int ISNS_ProcessESI ( ISNS_Msg_Descp *p_md ) { ISNS_Key *p_attr; SOIP_Entity *p_entity; SOIP_Portal *p_portal; time_t mytime; SOIP_Portal_Key db_portal; int i; int len; ISNS_Attr *attr_indx[SNS_MAX_ATTRS]; ISNS_Attr *key_indx[SNS_MAX_ATTRS]; int rval; SOIP_Entity_Id db_entity_id; __DEBUG (isns_esi_debug &1, ISNS_ProcessESI); ISNSParseMsg( &p_md->msg, attr_indx, key_indx, NULL ); i = ISNSFindTag (0, ISNS_ENTITY_ID, key_indx); if (i == -1) { __DEBUG (isns_esi_debug & 1, (Entity ID tag not found in msg)); return ( ERROR ); } p_attr = (ISNS_Key *)(key_indx[ i ]); memset(db_entity_id.id,0,sizeof(SOIP_Entity_Id)); strncpy(db_entity_id.id,p_attr->val.entity_id.id,sizeof(SOIP_Entity_Id)); rval = read_EntityObject(db_entity_id.id, &p_entity, &entry); if (rval != SUCCESS) return (ERROR); /* Update the time stamp */ len = sizeof (mytime); time ( &mytime ); p_entity->timestamp.t_pad = 0; p_entity->timestamp.t_time = mytime; __DEBUG (isns_esi_debug &1,(Time in seconds since UTC 1/1/70: %ld),mytime); __DEBUG (isns_esi_debug &1,(UNIX time and date: %s),ctime(&mytime) ); /* Store Entry */ write_EntityObject(db_entity_id.id, entry); memset(&db_portal,0,sizeof(SOIP_Portal_Key)); /* Fetch the portal IP */ i = ISNSFindTag (0, ISNS_PORTAL_IP, key_indx); if ( i == -1 ) { __DEBUG (isns_esi_debug & 1, (Portal IP tag not found in msg)); return ( ERROR ); } p_attr = (ISNS_Key *)(key_indx[i]); memcpy(db_portal.ip_addr.v, p_attr->val.ip_addr.v, ISNS_IP_SIZE); i = ISNSFindTag (0, ISNS_PORTAL_PORT, key_indx); if (i == -1) { __DEBUG (isns_esi_debug & 1, (Portal PORT tag not found in msg)); return ( ERROR ); } p_attr = (ISNS_Key *)(key_indx[i]); db_portal.ip_port=p_attr->val.ip_port; rval = read_PortalObject(&db_portal, &p_portal, &entry); if (rval != SUCCESS) return rval; p_portal->esiSent = 0; /* Store Portal */ rval = write_PortalObject(&db_portal, entry); return ( ISNS_NO_ERR ); } isns-2.1-01/isnsserver/src/iSNSfsm.c0000644000175000017500000004230010665040341016234 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include "iSNStypes.h" #include "iSNSfsm.h" #include "iSNS.h" #include "iSNSdb.h" #include "iSNScomm.h" #include "iSNSqueue.h" #include "iSNSbuffer.h" #include "iSNSipc.h" #include "iSNStbl.h" #include "iSNSdebug.h" /* Globals */ extern int sns_fsm_debug; /* state machine debugging */ extern int sns_bcast_debug; /* broadcast debugging (except hb, scn) */ extern int sns_hb_debug; extern int sns_comm_support; /* * multicast outgoing message common buffer */ static ISNS_Msg mc_msg; /* User Callback Routine when ever iSNS Readyness(sic) changes */ static void *notifyUser = 0; static int firstTime = 1; #if 0 void SNSFSMTimeoutHdlr(void); void SNSESIStartTimer(int timeout); #endif static void SNSFSMStartTimer(int timeout); static void SNSProcessClaim(ISNS_Msg_Descp *); static void SNSSendClaim(void); static void SNSSendDiscovery(void); static void SNSSendCommReq(void); static void SNSSendHeartbeat(void); void SNSResyncTimeoutHdlr(void); static void SNSInitiateTrans2Primary(void); static void SNSInvalidState(void); void SNSReady(); void ISNSNotReady(); /* * iSNS Server FSM */ struct SNS_fsm sns_server_fsm[SNS_NUM_FSM_STATES][SNS_NUM_FSM_EVENTS] = { /* SNS_INIT */ { {SNS_WFCOMM, NULL }, {SNS_INIT, NULL }, {SNS_INIT, NULL }, {SNS_INIT, NULL }, {SNS_INIT, NULL }, {SNS_WFDACK, SNSSendDiscovery }, {SNS_INIT, NULL }, {SNS_INIT, NULL }, {SNS_INIT, NULL }, {SNS_INIT, NULL }, {SNS_INIT, NULL }, {SNS_INIT, NULL } }, /* SNS_WFHB */ { {SNS_WFHB, NULL }, {SNS_WFHB, NULL }, {SNS_WFHB, NULL }, {SNS_ELECTION, SNSProcessClaim }, {SNS_WFHB, NULL }, {SNS_WFDACK, SNSSendDiscovery }, {SNS_WFCOMM, SNSSendCommReq }, {SNS_WFHB, NULL }, {SNS_WFHB, NULL }, {SNS_WFHB, NULL }, {SNS_WFHB, NULL }, {SNS_WFHB, NULL } }, /* SNS_WFCOMM */ { {SNS_WFCOMM, NULL }, {SNS_WFCOMM, NULL }, {SNS_WFHB, NULL }, {SNS_WFCOMM, NULL }, {SNS_WFCOMM, NULL }, {SNS_WFDACK, SNSSendDiscovery }, {SNS_WFCOMM, NULL }, {SNS_WFCOMM, NULL }, {SNS_WFCOMM, NULL }, {SNS_WFCOMM, NULL }, {SNS_WFCOMM, NULL }, {SNS_WFCOMM, NULL } }, /* SNS_WFDACK */ { {SNS_WFCOMM, NULL }, {SNS_WFDACK, NULL }, {SNS_WFDACK, NULL }, {SNS_ELECTION, SNSProcessClaim }, {SNS_WFDACK, NULL }, {SNS_ELECTION, SNSSendClaim }, {SNS_WFDACK, NULL }, {SNS_WFDACK, NULL }, {SNS_WFDACK, NULL }, {SNS_WFDACK, NULL }, {SNS_WFDACK, NULL }, {SNS_WFDACK, NULL } }, /* SNS_ELECTION */ { {SNS_WFCOMM, NULL }, {SNS_ELECTION, NULL }, {SNS_ELECTION, NULL }, {SNS_ELECTION, SNSProcessClaim }, {SNS_ELECTION, NULL }, {SNS_PRIMARY, SNSInitiateTrans2Primary }, {SNS_ELECTION, NULL }, {SNS_ELECTION, NULL }, {SNS_ELECTION, NULL }, {SNS_ELECTION, NULL }, {SNS_ELECTION, NULL }, {SNS_ELECTION, NULL } }, /* SNS_PRIMARY */ { {SNS_PRIMARY, NULL }, {SNS_PRIMARY, NULL }, {SNS_PRIMARY, NULL }, {SNS_PRIMARY, SNSSendHeartbeat }, {SNS_PRIMARY, SNSSendHeartbeat }, {SNS_PRIMARY, SNSSendHeartbeat }, {SNS_WFCOMM, NULL }, {SNS_PRIMARY, NULL }, {SNS_PRIMARY, NULL }, {SNS_PRIMARY, NULL }, {SNS_PRIMARY, NULL }, {SNS_PRIMARY, NULL } }, /* SNS_FSM_INVALID */{ {SNS_FSM_INVALID, SNSInvalidState }, {SNS_FSM_INVALID, SNSInvalidState }, {SNS_FSM_INVALID, SNSInvalidState }, {SNS_FSM_INVALID, SNSInvalidState }, {SNS_FSM_INVALID, SNSInvalidState }, {SNS_FSM_INVALID, SNSInvalidState }, {SNS_FSM_INVALID, SNSInvalidState }, {SNS_FSM_INVALID, SNSInvalidState }, {SNS_FSM_INVALID, SNSInvalidState }, {SNS_FSM_INVALID, SNSInvalidState }, {SNS_FSM_INVALID, SNSInvalidState }, {SNS_FSM_INVALID, SNSInvalidState } } }; /* string representation of the states */ char sns_state_string[SNS_NUM_FSM_STATES][16] = { {"SNS_INIT"}, {"SNS_WFHB"}, {"SNS_WFCOMM"}, {"SNS_WFDACK"}, {"SNS_ELECTION"}, {"SNS_PRIMARY"}, {"SNS_FSM_INVALID"} }; extern int sns_esi_interval; int sns_heartbeat_interval = SNS_HEARTBEAT_INTERVAL; int sns_heartbeat_timeout = SNS_HEARTBEAT_WAITTIME; int sns_heartbeat_counter = 0; int sns_discovery_counter = 0; /* * current state of the iSNS state machine */ int sns_fsm_tree_wait = TRUE; int sns_ready = FALSE; SNS_State sns_state; int sns_primary_version = 0; int sns_primary_priority = 0; int sns_local_version = SNS_VERSION; int sns_local_priority = 5; /* * persistant but scope-limited variables (static) */ static ISNS_Entity sns_init_role; /* * Timers for scheduling FSM events and resync events */ int sns_fsm_timeout = 0; #ifdef SNS_LINUX pthread_mutex_t sns_fsm_timer; pthread_mutex_t sns_resync_timer; pthread_mutex_t sns_esi_timer; /* Create AND initialize the conditions */ pthread_cond_t fsm_cond = PTHREAD_COND_INITIALIZER; pthread_cond_t resync_cond = PTHREAD_COND_INITIALIZER; pthread_cond_t esi_cond = PTHREAD_COND_INITIALIZER; int fsmtimeout_pid = 0; int esitimeout_pid = 0; int sns_resync_pid = 0; #else HANDLE sns_fsm_timer; HANDLE sns_resync_timer; HANDLE sns_esi_timer; HANDLE fsmtimeout_pid=0; HANDLE esitimeout_pid=0; HANDLE sns_resync_pid=0; DWORD fsmtimeout_id, sns_resync_timer_id; #endif /* * The Process ID of the Resync task. */ DWORD tresync_id; HANDLE tresync_pid=0; /* * List of ip addresses (sockets, really) during resync */ ISNS_ATTR_VALS_CB sync_ip_list = {0}; int SNSStartFSM(void) { sns_state = SNS_INIT; sns_init_role = isns_role; /* * Let them know we are still in setup. * Delay to let communication interface start up */ ISNSNotReady(); __DEBUG (sns_fsm_debug & 4, (iSNS starting...)); //sns_ready = TRUE; //isns_role = ISNS_PRIMARY_SERVER; /* * Initialize the queue for staging FSM messages * that require a response */ if (SNSQInit(SNS_FSM_QUEUE) == ERROR) return (ERROR); /* * Activate timeout handlers. */ #ifdef SNS_LINUX { pthread_t junk; if (0 != pthread_create (&junk, NULL, (void*)SNSFSMTimeoutThread, NULL)) perror ("Error creating thread for FSM Timeout"); if (0 != pthread_create (&junk, NULL, (void*)SNSESITimeoutThread, NULL)) perror ("Error creating thread for ESI Timeout"); if (0 != pthread_create (&junk, NULL, (void*)SNSResyncTimeoutThread, NULL)) perror ("Error creating thread for iSNS Resync"); } #else sns_esi_timer=CreateWaitableTimer(NULL, FALSE, NULL); sns_fsm_timer=CreateWaitableTimer(NULL, FALSE, NULL); sns_resync_timer=CreateWaitableTimer(NULL, FALSE, NULL); { DWORD junk; fsmtimeout_pid = CreateThread(0, 0,(void *) SNSFSMTimeoutThread, &junk, 0, &fsmtimeout_id); esitimeout_pid = CreateThread(0, 0,(void *) SNSESITimeoutThread, &junk, 0, &fsmtimeout_id); sns_resync_pid = CreateThread(0, 0,(void *) SNSResyncTimeoutThread, &junk, 0, &fsmtimeout_id); } #endif SNSFSMStartTimer(sns_heartbeat_interval * sysClkRateGet()); SNSESIStartTimer(sns_esi_interval * sysClkRateGet()); return(SUCCESS); } void SNSProcFSM(SNS_FSM_Event event, void *arg) { SNS_State sns_prev_state; char dot_not_local[INET_ADDR_LEN]; if (event > SNS_NUM_FSM_EVENTS) return; sns_prev_state = sns_state; if (sns_server_fsm[sns_state][event].action != NULL) { sns_server_fsm[sns_state][event].action(arg); sns_state = sns_server_fsm[sns_state][event].next_state; } if (sns_state == SNS_PRIMARY) isns_role = ISNS_PRIMARY_SERVER; else isns_role = sns_init_role; if (sns_prev_state != sns_state) { inet_ntoa_b(*(struct in_addr *)SNSGetLocalAddr(), dot_not_local); __DEBUG(sns_fsm_debug & 2, (%s - state change %s -> %s), dot_not_local, sns_state_string[sns_prev_state], sns_state_string[sns_state]); } } void SNSESIStartTimer (int timeout) { #ifndef SNS_LINUX STATUS status; wdCancel(sns_esi_timer); status = wdStart(sns_esi_timer, timeout, NULL, NULL); if (status == ERROR) __LOG_ERROR ("Error in starting HEARTBEAT TIMER\n"); #endif } /* * Function Name: SNSFSMStartTimer * * Synopsis: void SNSFSMStartTimer(int timeout); * * Description: Arm the heartbeat timer. * */ static void SNSFSMStartTimer (int timeout) { #ifndef SNS_LINUX STATUS status; wdCancel(sns_fsm_timer); status = wdStart(sns_fsm_timer, timeout, SNSFSMTimeoutHdlr, NULL); if (status == ERROR) __LOG_ERROR (" Error in starting HEARTBEAT TIMER"); #endif } void SNSFSMTimeoutHdlr(void) { char fsm_timeout_md[sizeof(SNS_Msg_Cb) + sizeof(SNS_Msg_Hdr)]; STATUS status = 0; sns_fsm_timeout = 1; bzero ((char *) fsm_timeout_md, sizeof (fsm_timeout_md)); /* * Send a FSM timeout message to the iSNS core task */ ((ISNS_Msg_Descp *)fsm_timeout_md)->msg.hdr.type = FSM_TIMEOUT_EVENT; ((ISNS_Msg_Descp *)fsm_timeout_md)->msg.hdr.msg_len = 0; status = SendIPCMessage (SNS_EP, (void *)fsm_timeout_md, sizeof(fsm_timeout_md), IPC_NO_WAIT); } void SNSESITimeoutHdlr(void) { char esi_timeout_md[sizeof(SNS_Msg_Cb) + sizeof(SNS_Msg_Hdr)]; STATUS status = 0; bzero ((char *) esi_timeout_md, sizeof (esi_timeout_md)); /* * Send a ESI timeout message to the iSNS core task */ ((ISNS_Msg_Descp *)esi_timeout_md)->msg.hdr.type = ESI_TIMEOUT_EVENT; ((ISNS_Msg_Descp *)esi_timeout_md)->msg.hdr.msg_len = 0; status = SendIPCMessage (SNS_EP, (void *)esi_timeout_md, sizeof(esi_timeout_md), IPC_NO_WAIT); } static void SNSProcessClaim(ISNS_Msg_Descp *p_md) { SNSFSMStartTimer(sns_heartbeat_timeout * sysClkRateGet()); } static void SNSSendClaim(void) { /* * start the heartbeat timer */ SNSFSMStartTimer(sns_heartbeat_interval * sysClkRateGet()); } static void SNSSendDiscovery(void) { ISNSNotReady(); /* * start the heartbeat timer */ SNSFSMStartTimer(sns_heartbeat_interval * sysClkRateGet()); sns_discovery_counter++; } static void SNSSendCommReq(void) { SNSFSMStartTimer(sns_heartbeat_timeout * sysClkRateGet()); } extern int sns_comm_main_port; static void SNSSendHeartbeat(void) { int ip; char dot_not_local[INET_ADDR_LEN]; char dot_not_bcast[INET_ADDR_LEN]; bzero ((char *)&mc_msg, sizeof(SNS_Msg_Hdr) + sizeof(SNS_Hb)); mc_msg.hdr.type = ISNS_HEART_BEAT; memset(mc_msg.payload.heartbeat.ip_addr.v, 0, sizeof(mc_msg.payload.heartbeat.ip_addr.v)); ip=*(uint32_t *)SNSGetLocalAddr(); *(uint32_t *)&mc_msg.payload.heartbeat.ip_addr.v[12]=ip; mc_msg.payload.heartbeat.udp_port = sns_comm_main_port; mc_msg.payload.heartbeat.tcp_port = sns_comm_main_port; mc_msg.payload.heartbeat.interval = sns_heartbeat_interval; mc_msg.payload.heartbeat.counter = sns_heartbeat_counter; mc_msg.hdr.msg_len = sizeof (SNS_Hb); inet_ntoa_b(*(struct in_addr *)SNSGetLocalAddr(), dot_not_local); inet_ntoa_b(*(struct in_addr *)SNSGetMCgrpAddr(), dot_not_bcast); __DEBUG(sns_hb_debug & 1, (%s - HEARTBEAT broadcast to %s. %d), dot_not_local, dot_not_bcast, sns_heartbeat_counter); sns_heartbeat_counter++; SNSSendMsg2MCgrp (&mc_msg); SNSFSMStartTimer(sns_heartbeat_interval * sysClkRateGet()); } static void SNSInitiateTrans2Primary(void) { char dot_not_local[INET_ADDR_LEN]; char trapstr[48]; sns_primary_version = sns_local_version; sns_primary_priority = sns_local_priority; sns_heartbeat_counter = 0; /* now primary, so set server_sock to own (local) address */ ISNSCommUpdate(SNSGetLocalAddr ()); /* get that heartbeat going out */ SNSFSMStartTimer(sns_heartbeat_interval * sysClkRateGet()); if (sns_ready == FALSE) SNSReady(); /* delete any outstanding resync task */ if (tresync_pid) taskDelete((pthread_t)tresync_pid); inet_ntoa_b(*(struct in_addr *)SNSGetLocalAddr(), dot_not_local); sprintf(trapstr, "%s elected primary\n", dot_not_local); } static void SNSInvalidState (void) { taskSuspend(); } void SNSSetNotifyUser(void *ptr) { notifyUser = ptr; } void SNSReady() { sns_ready = TRUE; __DEBUG (sns_fsm_debug & 1, (iSNS ready)); if (notifyUser == 0) return; if (firstTime == 1) { (*(void (*)())notifyUser)(SNS_FIRST_UP); firstTime = 0; } else { (*(void (*)())notifyUser)(SNS_UP); } } void ISNSNotReady() { if (sns_ready) { sns_ready = FALSE; __DEBUG (sns_fsm_debug & 1, (iSNS not ready)); if (notifyUser) (*(void (*)())notifyUser)(SNS_DOWN); } } isns-2.1-01/isnsserver/src/iSNSipc.c0000644000175000017500000001264510665040341016233 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This file contains IPC message service source code. * */ #include "iSNStypes.h" #include "iSNSmsg.h" #include "iSNSipc.h" #include "iSNSdebug.h" /* * IPC endpoints used by the switch software entities */ static IPC_EP ipc_ep[NUM_IPC_EP_NAMES+1]; MSG_Q_ID SNSDevMgtQueue; MSG_Q_ID SNSEpQueue; /* * Function Name: CreateIPCEndPoint * * Synopsis: int CreateIPCEndPoint (ep_name) * * Arguments: ep_name - End point name * * Description: create a message queue and bind it to * the named entity. * * Return value: 0 (0) or -1 (-1) * */ int CreateIPCEndPoint (IPC_EP_Name ep_name) { int num_buffers; struct sockaddr_in my_addr; if (!(VALID_EP_NAME (ep_name))) return (ERROR); num_buffers = ep_name==DEVICE_MGMT_EP?MAX_DEVICE_MGMT_EP_BUFFERS:MAX_SNS_EP_BUFFERS; my_addr.sin_family = AF_INET; my_addr.sin_port = htons ((short) (ep_name==DEVICE_MGMT_EP?6005:6006)); my_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); ipc_ep[ep_name].their_addr.sin_family = AF_INET; ipc_ep[ep_name].their_addr.sin_port = htons ((short) (ep_name==DEVICE_MGMT_EP?6005:6006)); ipc_ep[ep_name].their_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); ipc_ep[ep_name].s = socket(AF_INET, SOCK_DGRAM, 0); if (ipc_ep[ep_name].s < 0) { __LOG_ERROR ("Error: While calling socket."); return (ERROR); } if (bind ( ipc_ep[ep_name].s, (struct sockaddr *) &my_addr, sizeof (my_addr)) < 0) { __LOG_ERROR ("Fatal Error while Binding."); return (0); } return(SUCCESS); } /* * Function Name: SendIPCMessage * * Synopsis: int SendIPCMessage(ep_name, p_msg, size, pri) * * Arguments: ep_name - End point name * p_msg - pointer to outbound message * size - message size in bytes * pri - message priority * * Description: Send a message to a switch software entity. * * Return value: 0 (0) or -1 (-1) * */ int SendIPCMessage (IPC_EP_Name ep_name, void *p_msg, int msg_len, int options) { int cnt; if (!(VALID_EP_NAME (ep_name))) return (ERROR); if (ipc_ep[ep_name].s == 0) return (ERROR); cnt = sendto(ipc_ep[ep_name].s, p_msg, msg_len, 0, (struct sockaddr * )&ipc_ep[ep_name].their_addr, sizeof(ipc_ep[ep_name].their_addr)); if (cnt < 0) { __LOG_ERROR ("Error: sendto."); exit(1); } return (SUCCESS); } /* * Function Name: ReceiveIPCMessage * * Synopsis: int ReceiveIPCMessage(ep_name, p_msg, max_len, timeout) * * Arguments: ep_name - receive message from the named EP. * p_msg - place holder for received message * max_len - maximum size of expected message * timeout - timeout for message arrival * * Description: Receive a message from a switch software entity. * * Return value: SUCCESS (0) or ERROR (-1) * */ int ReceiveIPCMessage (IPC_EP_Name ep_name, void *p_msg, int max_len, int timeout) { int cnt; int len; if (!(VALID_EP_NAME (ep_name))) return (ERROR); if (ipc_ep[ep_name].s == 0) return (ERROR); len=sizeof(ipc_ep[ep_name].their_addr); cnt = recvfrom( ipc_ep[ep_name].s, p_msg, max_len, 0, (struct sockaddr * )&ipc_ep[ep_name].their_addr, (socklen_t *)&len); if (cnt < 0) { __LOG_ERROR ("Receive error."); exit(1); } return(SUCCESS); } /* * Function Name: DestroyIPCEndPoint * * Synopsis: int DestroyIPCEndPoint(ep_name) * * Arguments: ep_name - name of EP to remove. * * Description: Release resources associated with an IPC endpoint. * * Return value: 0 (0) or -1 (-1) * */ int DestroyIPCEndPoint (IPC_EP_Name ep_name) { return (SUCCESS); } isns-2.1-01/isnsserver/src/iSNSrcv.c0000644000175000017500000002530410665040341016246 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This file contains source code for receiving UDP messages * from a SOIP service entity. The messages received over * the socket are queued and later processed by the SOIP * service agent task. * */ #include "iSNS.h" #include "iSNSmsg.h" #include "iSNSfsm.h" #include "iSNScomm.h" #include "iSNSipc.h" #include "iSNSdebug.h" extern int isns_main_debug; int sns_recv_debug = 0; int sns_recv_msg_filter = 0; /* support fragmentated buffers */ int awaiting_fragment = 0; int frag_len = 0; ISNS_Msg_Descp frag_md; /* ReceiveMain statistics */ int sns_recv_num_dropped = 0; int sns_recv_num_pri_res = 0; int sns_recv_num_cli_fwd = 0; #define ARRAY_DEPTH 20 #define ARRAY_WIDTH 12 #ifdef SNS_LINUX unsigned int sns_recv_msg_array[ARRAY_DEPTH][2 + ARRAY_WIDTH]; #else int sns_recv_msg_array[ARRAY_DEPTH][2 + ARRAY_WIDTH]; #endif static ISNS_Msg_Descp md; static void SNS_SaveRecentMsg(ISNS_Msg_Descp *p_md); /* * Function Name: SNSReceiveMain * * Synopsis: int SNSReceiveMain(int sd); * * Parameters: sd = descriptor of receive socket * * Description: SNSMain is the entry-point of the SoIP * service task. * * Return value: If task is successfully initialized, * SNSMain() will not return. If an error * occurs during initialization SNSMain() * returns ERROR (-1). * * */ #ifdef SNS_LINUX int #else DWORD WINAPI #endif SNSReceiveMain (LPVOID lparam) { static int first_warn = TRUE; ISNS_Msg *p_msg = NULL; memset((char *)&frag_md, 0, sizeof(ISNS_Msg_Descp)); __DEBUG (isns_main_debug & 1, "Starting SNSReceiveMain thread."); /* * Wait for a message to arrive on the socket. * Forward the received message to the iSNS core * task for processing. */ for (;;) { extern int pauseFlag; if (pauseFlag) return (-1); if (( SNSGetMsg (&md)) != ERROR ) { p_msg = &md.msg; SNS_SaveRecentMsg(&md); /* Check the flags */ /* If First PDU set */ if (p_msg->hdr.flags & ISNS_FLAG_FIRST_PDU) { if (awaiting_fragment) { /* got another while waiting: drop previous message */ sns_recv_num_dropped++; __LOG_ERROR("dropped frame %d", sns_recv_num_dropped); awaiting_fragment = 0; frag_len = 0; } /* save header */ memcpy((char *)&frag_md, (char *)&md, sizeof(SNS_Msg_Cb) + sizeof(SNS_Msg_Hdr)); } else { /* xid and version must match prev */ if ((frag_md.msg.hdr.xid != p_msg->hdr.xid) || (frag_md.msg.hdr.version != p_msg->hdr.version)) { sns_recv_num_dropped++; __LOG_ERROR("dropped frame %d", sns_recv_num_dropped); awaiting_fragment = 0; frag_len = 0; memset((char *)&frag_md, 0, sizeof(SNS_Msg_Cb) + sizeof(SNS_Msg_Hdr)); continue; } } /* copy into buffer */ memcpy((char *)&frag_md.msg.payload + frag_len, (char *)&p_msg->payload, p_msg->hdr.msg_len); awaiting_fragment++; frag_len += p_msg->hdr.msg_len; if (!(p_msg->hdr.flags & ISNS_FLAG_FIRST_PDU)) continue; /* got all fragments, copy back into msg buffer */ memcpy((char *)&md, (char *)&frag_md, frag_len + sizeof(SNS_Msg_Cb) + sizeof(SNS_Msg_Hdr)); md.msg.hdr.msg_len = frag_len; /* clear all frag variables */ memset((char *)&frag_md, 0, frag_len + sizeof(SNS_Msg_Cb) + sizeof(SNS_Msg_Hdr)); awaiting_fragment = 0; frag_len = 0; if ((p_msg->hdr.version > SNS_VERSION) && (first_warn)) { /* * SNS_WARN(SNS_VERSION_WARN, * "version mismatch (current, new)\n", * SNS_VERSION, p_msg->hdr.version, 0); */ __LOG_WARNING("NOTE: Newer version (v %d) of iSNS detected in the", p_msg->hdr.version); __LOG_WARNING("network. Current version is v %d.", (int)SNS_VERSION); first_warn = FALSE; } md.cb.sender = ISNS_REMOTE; if (SendIPCMessage(SNS_EP, (void *)&md, sizeof(SNS_Msg_Cb) + sizeof(SNS_Msg_Hdr) + p_msg->hdr.msg_len, IPC_MSG_PRI_HI) == ERROR) { __LOG_ERROR ("%s %d: Error forwarding fsm message (xid %d)", __FILE__, __LINE__, p_msg->hdr.xid); } } else if (isns_role != ISNS_PRIMARY_SERVER) { if (SendIPCMessage(SNS_EP, (void *)&md, sizeof(SNS_Msg_Cb) + sizeof(SNS_Msg_Hdr) + p_msg->hdr.msg_len, 0) == ERROR) { __LOG_ERROR ("%s %d: Error forwarding res message (xid %d)", __FILE__, __LINE__, p_msg->hdr.xid); } else { sns_recv_num_cli_fwd++; sns_recv_num_dropped++; __LOG_ERROR("dropped frame %d", sns_recv_num_dropped); } } else if (isns_role == ISNS_PRIMARY_SERVER) { if (SendIPCMessage(SNS_EP, (void *)&md, sizeof(SNS_Msg_Cb) + sizeof(SNS_Msg_Hdr) + p_msg->hdr.msg_len, 0) == ERROR) { __LOG_ERROR ("%s %d: Error forwarding op message (xid %d)", __FILE__, __LINE__, p_msg->hdr.xid); } else { sns_recv_num_dropped++; __LOG_ERROR("dropped frame %d", sns_recv_num_dropped); } } else { __LOG_ERROR ("Socket Error"); taskDelay(1*sysClkRateGet()); } } return (-1); } static void SNS_SaveRecentMsg(ISNS_Msg_Descp *p_md) { static int index = 0; int display_debug; char dot_not_addr[INET_ADDR_LEN]; inet_ntoa_b(p_md->cb.sock.addr.sin_addr, dot_not_addr); display_debug = 0; if (sns_recv_debug == 1) display_debug = (p_md->msg.hdr.type != sns_recv_msg_filter); else if (sns_recv_debug == 2) display_debug = (p_md->msg.hdr.type == sns_recv_msg_filter); __DEBUG (display_debug, "recv msg %d, len %d, xid %d from %s", p_md->msg.hdr.type, p_md->msg.hdr.msg_len, p_md->msg.hdr.xid, dot_not_addr); if ((display_debug == 0) || (p_md->msg.hdr.type == sns_recv_msg_filter)) return; #ifdef SNS_LINUX sns_recv_msg_array[index][0] = (long double)time ((time_t*) 0); #else sns_recv_msg_array[index][0] = tickGet(); #endif sns_recv_msg_array[index][1] = (int)p_md->cb.sock.addr.sin_addr.s_addr; memcpy(&sns_recv_msg_array[index][2], &p_md->msg, ARRAY_WIDTH*sizeof(int)); index++; index = index % ARRAY_DEPTH; } void SNSReceiveMain_dump(int num_display) { int ii, jj; __LOG_INFO("SNSReceiveMain num dropped %d", sns_recv_num_dropped); __LOG_INFO("SNSReceiveMain num pri res %d", sns_recv_num_pri_res); __LOG_INFO("SNSReceiveMain num cli fwd %d", sns_recv_num_cli_fwd); __LOG_INFO("Msgs received"); if ((num_display < 0) || (num_display > ARRAY_DEPTH)) num_display = ARRAY_DEPTH; for (ii = 0; ii < num_display; ii++) { __LOG_INFO("time %08x, src %08x", sns_recv_msg_array[ii][0], sns_recv_msg_array[ii][1]); for (jj = 0; jj < ARRAY_WIDTH; jj++) { __LOG_INFO("%08x ", sns_recv_msg_array[ii][2 + jj]); if (jj == 7) __LOG_INFO("\n\t"); } } } int sns_recv_debug_help() { __LOG_INFO("sns_recv_debug represents the debugging level for the iSNS"); __LOG_INFO(" socket receive messages. Use in conjuction with sns_recv_msg_filter"); __LOG_INFO(" There is also SNSReceiveMain_dump x, which shows dropped"); __LOG_INFO(" msg stats and the last x (up to %d) msg headers received", ARRAY_DEPTH); __LOG_INFO(" when 1 : displays received msgs (except msg filter)"); __LOG_INFO(" when 2 : displays only msg filter msgs"); return (sns_recv_debug); } isns-2.1-01/isnsserver/src/iSNSreg.c0000644000175000017500000032212410665040341016231 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This file contains source code for registering objects with the * iSNS database. * */ #include "iSNS.h" #include "iSNStypes.h" #include "iSNSmsg.h" #include "iSNSList.h" #include "iSNSdb.h" #include "iSNSobjects.h" #include "iSNSreg.h" #include "iSNSscn.h" #include "iSNSquery.h" #include "iSNSresponse.h" #include "iSNScomm.h" #include "iSNSbuffer.h" #include "iSNStbl.h" #include "iSNSparse.h" #include "iSNSdebug.h" /* Global */ extern int isns_reg_debug; extern int sns_esi_interval; extern uint32_t *dlist_node; /*[MAX_DD_PER_LIST];*/ extern ISNS_LIST scn_callback_list; extern ISNS_Msg *p_scn_msg_buffer; extern ISNS_Msg *p_scn_all_msg_buffer; extern ISNS_Msg_Descp *p_scn_md; extern ISNS_Msg_Descp *p_rspMd; extern dbStats iSNS_stats; /* * static common variables for gdbm fetches * entry is for common registrations and queries * scn_entry is for state change notifications * opn_entry is for access control */ static SOIP_DB_Entry entry; /* top level fetches ONLY */ static SOIP_DB_Entry entry2; /* secondary fetches */ static SOIP_DB_Entry entry3; int Check_if_member_of_DD (char * id); static int Add_ISCSINode_Default_DD (SOIP_Iscsi *p_node); /********************************************************************* _SNSdbAddAttr Calls the more specific add routines. *********************************************************************/ int ISNSdbAddAttr (ISNS_Msg_Descp * p_md, ISNS_Msg *rspMsg) { ISNS_Attr *p_attr; int status; int i; int regEnitityFlag; int regFCNodeFlag; int regFCPortFlag; int regPortalFlag; int regISCSIFlag; int regPortalGroupFlag; int regFlag; ISNS_Attr *attr_indx[SNS_MAX_ATTRS]; ISNS_Attr *key_indx[SNS_MAX_ATTRS]; ISNS_Attr *src_attr; /* Search the operation Attributes */ regFlag = FALSE; regEnitityFlag = 0; regFCNodeFlag = 0; regFCPortFlag = 0; regPortalFlag = 0; regISCSIFlag = 0; regPortalGroupFlag = 0; ISNSParseMsg( &p_md->msg, attr_indx, key_indx, &src_attr ); /* Profile which registration needs to be done */ for (i = 0; i < MAX_PARSE_ATTRS && attr_indx[ i ]; i++) { p_attr = (ISNS_Attr *)(attr_indx[ i ]); switch ( p_attr->tag ) { case ISNS_ENTITY_ID: case ISNS_ENTITY_TYPE: case ISNS_MGMT_IP: case ISNS_PROT_VER: case ISNS_TIMESTAMP: case ISNS_ENTITY_CERT: case ISNS_ENTITY_PERIOD: regEnitityFlag = TRUE; break; case ISNS_PORTAL_IP: case ISNS_PORTAL_PORT: case ISNS_PORTAL_SYM_NAME: case ISNS_PORTAL_CERT: case ISNS_ESI_INTERVAL: case ISNS_ESI_PORT: regPortalFlag = TRUE; break; case ISNS_NODE_NAME: case ISNS_NODE_SYM_NAME: case ISNS_FC_NODE_IP: case ISNS_FC_NODE_IPA: case ISNS_FC_NODE_CERT: regFCNodeFlag = TRUE; break; case ISNS_PORT_NAME: case ISNS_PORT_ID: case ISNS_PORT_TYPE: case ISNS_PORT_SYM_NAME: case ISNS_FABRIC_PORT_NAME: case ISNS_FC_HARD_ADDR: case ISNS_FC_PORT_IP: case ISNS_FC_COS: case ISNS_FC4_TYPE: case ISNS_FC4_DESC: case ISNS_FC4_FEATURE: regFCPortFlag = TRUE; break; case ISNS_ISCSI_NODE_ID: case ISNS_ISCSI_ALIAS: case ISNS_ISCSI_TYPE: case ISNS_ISCSI_CERT: regISCSIFlag = TRUE; break; case ISNS_PORTAL_GROUP_ISCSI_NAME: case ISNS_PORTAL_GROUP_TAG: case ISNS_PORTAL_GROUP_PORT: case ISNS_PORTAL_GROUP_IP: regPortalGroupFlag = TRUE; break; default: break; } } regPortalGroupFlag = (regISCSIFlag && regPortalFlag) || regPortalGroupFlag; __DEBUG (isns_reg_debug &1,regISCSIFlag:%i,regISCSIFlag); __DEBUG (isns_reg_debug &1,regPortalFlag:%i,regPortalFlag); __DEBUG (isns_reg_debug &1,regEntityFlag%i,regEnitityFlag); __DEBUG (isns_reg_debug &1,regPortalGroupFlag%i,regPortalGroupFlag); status = ISNS_NO_ERR; /* Register Entity */ if (regEnitityFlag) { regFlag=TRUE; status = SNSdbAddAttrEntity (attr_indx, key_indx, p_md, rspMsg); } if (regFCPortFlag && status == ISNS_NO_ERR) { regFlag=TRUE; status = SNSdbAddAttrPort (attr_indx, key_indx, p_md, rspMsg); } /* Note the else */ else if (regFCNodeFlag && status == ISNS_NO_ERR) { regFlag=TRUE; status = ISNSdbAddAttrNode (attr_indx, key_indx, p_md, rspMsg); } if (regISCSIFlag && status == ISNS_NO_ERR) { regFlag=TRUE; status = ISNSdbAddAttrISCSINode (attr_indx, key_indx, p_md, rspMsg); } if (regPortalFlag && status == ISNS_NO_ERR) { regFlag=TRUE; status = ISNSdbAddAttrPortal (attr_indx, key_indx, p_md, rspMsg); } if (regPortalGroupFlag && status == ISNS_NO_ERR) { regFlag=TRUE; status = ISNSdbAddAttrPortalGroup (attr_indx, key_indx, p_md, rspMsg); } if (!regFlag) status=ISNS_INVALID_REG_ERR; return status; } /********************************************************************* _ISNSdbAddAttrPortal Adds one or more portals to the database. The keys are appended to the rsp message. *********************************************************************/ int ISNSdbAddAttrPortal (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Msg_Descp * p_md, ISNS_Msg * p_rspmsg) { ISNS_Key *key = NULL; ISNS_Attr *attr = NULL; SOIP_Portal *p_portal; SOIP_Entity *p_entity; SOIP_Portal_Key db_portal; int ii; int rval; int portalIpIndex; int portalPortIndex; int saveIndex; int stopFlag; int newPortalRegFlag; int eidKeyIndex; int updateESIflag; int foundFlag; int updateFlag; SOIP_Entity_Key db_entity_id = {{0}}; ISNS_LIST_NODE *pnode; ISNS_LIST_NODE *pnode2; PORTAL_LIST_ENTRY newPortalEntry; char *p_iscsi_name; SOIP_DB_Portal *p_idx; __DEBUG (isns_reg_debug & 1, (Registering Portal)); updateESIflag = FALSE; newPortalRegFlag = FALSE; portalPortIndex = -1; portalIpIndex = -1; for (ii = 0; ii < SNS_MAX_ATTRS && key_indx[ ii ] && (portalIpIndex == -1 || portalPortIndex == -1); ii++) { key = (ISNS_Key *)( key_indx[ ii ] ); switch ( key->tag ) { case ISNS_PORTAL_IP: /* Check to see if we already had an IP */ if (portalIpIndex != -1) { __DEBUG (isns_reg_debug & 1, (PORTAL_IP tag found twice)); return ( ISNS_INVALID_REG_ERR ); } portalIpIndex = ii; break; case ISNS_PORTAL_PORT: /* Check to see if we already had a PORT */ if (portalPortIndex != -1) { __DEBUG (isns_reg_debug & 1, (PORTAL_PORT tag found twice)); return ( ISNS_INVALID_REG_ERR ); } portalPortIndex = ii; break; default: break; } } if (portalIpIndex == -1 && portalPortIndex == -1) { /* No keys */ newPortalRegFlag = TRUE; } else if (portalIpIndex == -1 || portalPortIndex == -1) { /* One or the other key */ __DEBUG (isns_reg_debug & 1, (Portal Reg: Missing keys)); return ( ISNS_INVALID_REG_ERR ); } saveIndex = 0; /* Loop for every portal IP and portal PORT */ while ( saveIndex < SNS_MAX_ATTRS ) { if ( newPortalRegFlag ) { /* Search for the tag portal IP and portal PORT. */ /* These are going to be used as the key. */ portalIpIndex = -1; portalPortIndex = -1; for ( ii = saveIndex; ii < SNS_MAX_ATTRS && attr_indx[ii] && (portalIpIndex == -1 || portalPortIndex == -1); ii++ ) { attr = (ISNS_Attr *) attr_indx[ ii ]; switch ( attr->tag ) { case ISNS_PORTAL_IP: /* Check to see if we already had an IP */ if (portalIpIndex != -1) { __DEBUG (isns_reg_debug & 1, (PORTAL_IP tag found twice)); return ( ISNS_INVALID_REG_ERR ); } portalIpIndex = ii; break; case ISNS_PORTAL_PORT: /* Check to see if we already had a PORT */ if (portalPortIndex != -1) { __DEBUG (isns_reg_debug & 1, (PORTAL_PORT tag found twice)); return ( ISNS_INVALID_REG_ERR ); } portalPortIndex = ii; break; default: break; } } /* Check to see if we have both indices */ if ( portalIpIndex == -1 || portalPortIndex == -1 ) { __DEBUG (isns_reg_debug & 1, (PORTAL REG, MISSING KEYS)); return ( ISNS_INVALID_REG_ERR ); } __DEBUG (isns_reg_debug &1,(Portal ip_port:%i),attr->val.ip_port); attr = (ISNS_Attr *) attr_indx[ portalPortIndex ]; db_portal.ip_port = attr->val.ip_port; attr = (ISNS_Attr *) attr_indx[ portalIpIndex ]; __ISNS_COPY (db_portal.ip_addr.v, sizeof(db_portal.ip_addr.v), &attr->val, ISNS_PORTAL_IP_SIZE); saveIndex = ii; } else { __DEBUG (isns_reg_debug &1,(Portal ip_port:%i),key->val.ip_port); /* Use Keys to fetch the portal Object */ key = (ISNS_Key *) key_indx[ portalPortIndex ]; db_portal.ip_port = key->val.ip_port; __DEBUG (isns_reg_debug &1,(Portal ip_addr len:%i),key->len); key = (ISNS_Key *) key_indx[ portalIpIndex ]; __ISNS_COPY (db_portal.ip_addr.v, sizeof(db_portal.ip_addr.v), &key->val, key->len); saveIndex = 0; } __DEBUG (isns_reg_debug &1,(read portal:%s),db_portal.ip_addr.v); rval = read_PortalObject(&db_portal, &p_portal, &entry2); if ( (rval == SUCCESS) && (p_md->msg.hdr.flags & ISNS_FLAG_REPLACE_REG) ) { __DEBUG (isns_reg_debug & 1,Deregistering Portal); SNSRemovePortalEntry (&db_portal, NULL, NULL); rval = ERROR; } /* Create new entry */ if ( rval != SUCCESS ) { __DEBUG (isns_reg_debug &1,create new portal entry); if ( FALSE == newPortalRegFlag ) { __DEBUG (isns_reg_debug & 1, (Unable to retrieve portal entry)); return ( ISNS_INVALID_REG_ERR ); } /* create a new node element */ memset (&entry2, 0, sizeof (SOIP_DB_Entry)); attr = (ISNS_Attr *) attr_indx[portalIpIndex]; __ISNS_COPY (p_portal->ip_addr.v, sizeof(p_portal->ip_addr.v), attr->val.ip_addr.v, attr->len); attr = (ISNS_Attr *) attr_indx[portalPortIndex]; p_portal->ip_port = attr->val.ip_port; __DEBUG (isns_reg_debug & 1, (Obtain Portal ip_port:%i),p_portal->ip_port); p_portal->portal_index = ISNSGetNewPortalIdx(); p_portal->default_portal_tag = 1; //DEFAULT portal_tag memset (&entry3, 0, sizeof(SOIP_DB_Entry)); p_idx = &entry3.data.portal_idx; __ISNS_COPY (p_idx, sizeof(entry3.data.portal_idx), &db_portal,sizeof(SOIP_DB_Portal)); rval = write_PortalidxObject(p_portal->portal_index, entry3); /* Update Entity's portal Bitmap */ eidKeyIndex = ISNSFindTag (0, ISNS_ENTITY_ID, key_indx); if (eidKeyIndex == -1) { attr = ISNSFindKeyInResponseMsg (ISNS_ENTITY_ID, p_rspmsg); } else { attr = (ISNS_Attr *)(key_indx[eidKeyIndex]); } /* Fetch entity */ do { __DEBUG (isns_reg_debug &1,Fetch entity); strncpy(db_entity_id.id, (char *)&attr->val, sizeof(db_entity_id.id)); rval = read_EntityObject(db_entity_id.id, &p_entity, &entry); if ( rval != SUCCESS) { __DEBUG (isns_reg_debug & 1, Error Fetching Entity); return (ERROR); } foundFlag = FALSE; pnode = NULL; __DEBUG (isns_reg_debug &1,(Find iportal_list in entity)); while ((pnode=GetNextNode(&p_entity->iportal_list, pnode))) { void *ptr; ptr = GetNodeData(pnode); if (0 == memcmp(ptr, &db_portal, sizeof(db_portal))) { __DEBUG (isns_reg_debug &1, (set portal foundFlag)); foundFlag = TRUE; break; } } if (!foundFlag) { __ISNS_COPY (&newPortalEntry.portal_ip_port, sizeof(newPortalEntry.portal_ip_port), &db_portal, sizeof(db_portal)); newPortalEntry.portal_idx = p_portal->portal_index; __DEBUG (isns_reg_debug &1, (AddNode - iportal)); AddNode(&p_entity->iportal_list, (char *)&newPortalEntry, sizeof(newPortalEntry)); } strcpy(p_portal->entity_id.id,p_entity->eid.id); __DEBUG (isns_reg_debug &1, p_portal->entity_id.id is:%s,p_portal->entity_id.id); p_portal->entity_index = p_entity->entity_index; if (eidKeyIndex!=-1) eidKeyIndex = ISNSFindTag (eidKeyIndex+1, ISNS_ENTITY_ID, key_indx); if (eidKeyIndex!=-1) attr = (ISNS_Attr *)(key_indx[eidKeyIndex]); /* Store Entity Entry */ __DEBUG (isns_reg_debug &1,Store Entity); rval = write_EntityObject(db_entity_id.id, entry); } while ( eidKeyIndex!=-1 ); newPortalRegFlag = TRUE; } else { eidKeyIndex = 0; /* Any entities in the key */ while (-1 != (eidKeyIndex = ISNSFindTag (eidKeyIndex, ISNS_ENTITY_ID, key_indx))) { attr = (ISNS_Attr *)(key_indx[ eidKeyIndex ]); strncpy(db_entity_id.id, (char *)&attr->val, sizeof(db_entity_id.id)); if ( read_EntityObject (db_entity_id.id, &p_entity, &entry) ) { return (ISNS_INVALID_REG_ERR); } foundFlag = FALSE; pnode = NULL; while ( (pnode = GetNextNode(&p_entity->iportal_list, pnode)) ) { void *ptr; ptr = GetNodeData( pnode ); if (0 == memcmp(ptr, &db_portal, sizeof(db_portal))) { foundFlag = TRUE; break; } } if ( !foundFlag ) { /* Portal is not already in entity */ __ISNS_COPY (&newPortalEntry.portal_ip_port, sizeof(newPortalEntry.portal_ip_port), &db_portal, sizeof(db_portal)); newPortalEntry.portal_idx = p_portal->portal_index; AddNode(&p_entity->iportal_list, (char *)&newPortalEntry, sizeof(newPortalEntry)); strcpy(p_portal->entity_id.id,p_entity->eid.id); /* Store Entity Entry */ rval = write_EntityObject(db_entity_id.id,entry); } eidKeyIndex++; } } stopFlag = FALSE; updateFlag = FALSE; memset(p_scn_all_msg_buffer, 0, sizeof(ISNS_Msg)); for ( ii = saveIndex; (ii < SNS_MAX_ATTRS) && (attr_indx[ ii ]); ii++ ) { attr = (ISNS_Attr *) attr_indx[ ii ]; switch ( attr->tag ) { case ISNS_PORTAL_SYM_NAME: if (strncmp(p_portal->sym_name, (char *)&attr->val, MIN(PORTAL_SYM_NAME_SIZE, attr->len))) { memset (p_portal->sym_name, 0, attr->len); __ISNS_COPY (p_portal->sym_name, sizeof(p_portal->sym_name), &attr->val, attr->len); ISNSAppendKey( p_scn_all_msg_buffer, ISNS_PORTAL_SYM_NAME, PAD4(strlen(p_portal->sym_name)), p_portal->sym_name, 0 ); updateFlag = TRUE; } break; case ISNS_PORTAL_GROUP_TAG: p_portal->default_portal_tag = attr->val.portal_group; break; case ISNS_PORTAL_IP: case ISNS_PORTAL_PORT: saveIndex = ii; stopFlag = TRUE; break; case ISNS_ESI_INTERVAL: p_portal->esi_interval = *(uint32_t *) & attr->val; if (p_portal->esi_interval != 0 && p_portal->esi_interval < sns_esi_interval) { __DEBUG (isns_reg_debug & 1, (ESI Interval too small %u < %u), p_portal->esi_interval, sns_esi_interval); p_portal->esi_interval = sns_esi_interval; } updateESIflag = TRUE; break; case ISNS_ESI_PORT: p_portal->esi_port = *(uint32_t *) & attr->val & 0xFFFF; updateESIflag = TRUE; break; case ISNS_PORTAL_CERT: AddCert (&p_portal->ptr_cert, (int *)&p_portal->cert_size, &attr->val, attr->len); updateFlag = TRUE; break; case ISNS_ISCSI_TYPE: p_portal->node_type=p_portal->node_type | *(uint32_t *)&attr->val; updateFlag = TRUE; default: break; } if (stopFlag) break; } if ( updateESIflag ) { /* Update ESI */ if (p_portal->esi_port == 0 && p_portal->esi_interval != 0 && p_md->cb.sock.socketType != ISNS_SOCKET_TYPE_TCP) { __DEBUG (isns_reg_debug & 1, (ERROR:Attempting a TCP ESI without a TCP session)); return (ISNS_INVALID_REG_ERR); } if (p_portal->esi_port == 0 && p_portal->esi_interval != 0 && p_md->cb.sock.socketType == ISNS_SOCKET_TYPE_TCP) { p_portal->esi_sockfd=p_md->cb.sock.sockfd; } } __DEBUG(isns_reg_debug &1, Entity id:%s,p_portal->entity_id.id); /* Send Out Detailed SCN */ if (newPortalRegFlag || updateFlag) { if ( read_EntityObject ((char *)p_portal->entity_id.id, &p_entity, &entry) ) return ( ERROR ); pnode2 = NULL; while ( (pnode2 = GetNextNode( &p_entity->iscsi_node_list, pnode2)) ) { p_iscsi_name = (char *) GetNodeData( pnode2 ); send_iscsi_scn_to_members ( NULL, p_iscsi_name, p_scn_all_msg_buffer, ISNS_SCN_OBJ_ADDED ); } } if ( newPortalRegFlag ) iSNS_stats.num_portals++; /* Store the portal */ __DEBUG (isns_reg_debug &1,Store Portal:%s,db_portal.ip_addr.v); rval = write_PortalObject(&db_portal, entry2); /* insert the key(s) */ if (p_rspmsg != NULL) { ISNSAppendKey (p_rspmsg, ISNS_PORTAL_IP, ISNS_PORTAL_IP_SIZE, p_portal->ip_addr.v, 0); ISNSAppendKey (p_rspmsg, ISNS_PORTAL_PORT, ISNS_PORTAL_PORT_SIZE, 0, p_portal->ip_port); } /* Loop on the following conditions. */ attr = (ISNS_Attr *)(attr_indx[saveIndex]); if (!newPortalRegFlag) break; if (!attr_indx[saveIndex]) break; newPortalRegFlag = TRUE; updateESIflag = FALSE; if ((attr->tag == ISNS_PORTAL_IP) || (attr->tag == ISNS_PORTAL_PORT)) continue; else break; __DEBUG (isns_reg_debug &1,end of loop); } __DEBUG (isns_reg_debug &1,return); return (ISNS_NO_ERR); } /********************************************************************* _ISNSdbAddAttrPortalGroup Adds a portal group to the database. The keys are appended to the rsp message. *********************************************************************/ int ISNSdbAddAttrPortalGroup (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Msg_Descp * p_md, ISNS_Msg * p_rspmsg) { ISNS_Key *key = NULL; ISNS_Attr *attr = NULL; SOIP_Portal_Group *p_portal_group = NULL; SOIP_Portal_Group_Key db_portal_group; int ii; int rval; int portalIpIndex; int portalPortIndex; int iscsiIndex; int saveIndex; int stopFlag = FALSE; int portal_tag = 1; int newPortalGroupRegFlag; __DEBUG (isns_reg_debug & 1, (Registering Portal Group)); newPortalGroupRegFlag = FALSE; portalPortIndex = -1; portalIpIndex = -1; iscsiIndex = -1; memset(&db_portal_group,0,sizeof(SOIP_Portal_Group_Key)); for (ii = 0; ii < SNS_MAX_ATTRS && key_indx[ ii ] && (portalIpIndex == -1 || portalPortIndex == -1 || iscsiIndex == -1); ii++) { key = (ISNS_Key *)( key_indx[ ii ] ); switch ( key->tag ) { case ISNS_PORTAL_GROUP_IP: /* Check to see if we already had an IP */ if (portalIpIndex != -1) { __DEBUG (isns_reg_debug & 1, (PORTAL_IP tag found twice)); return ( ISNS_INVALID_REG_ERR ); } portalIpIndex = ii; break; case ISNS_PORTAL_GROUP_PORT: /* Check to see if we already had a PORT */ if (portalPortIndex != -1) { __DEBUG (isns_reg_debug & 1, (PORTAL_PORT tag found twice)); return ( ISNS_INVALID_REG_ERR ); } portalPortIndex = ii; break; case ISNS_ISCSI_NODE_ID: /* Check to see if we already have an iscsi name */ if (iscsiIndex != -1) { __DEBUG (isns_reg_debug & 1, (ISCSI Name tag found twice)); return ( ISNS_INVALID_REG_ERR ); } iscsiIndex = ii; break; default: break; } } if (portalIpIndex == -1 && portalPortIndex == -1) { /* No keys */ newPortalGroupRegFlag = TRUE; } else if (portalIpIndex == -1 || portalPortIndex == -1) { /* One or the other key */ __DEBUG (isns_reg_debug & 1, (Portal Reg: Missing keys in Key Attributes)); return ( ISNS_INVALID_REG_ERR ); } saveIndex = 0; /* Loop for every portal IP and portal PORT */ while ( saveIndex < SNS_MAX_ATTRS ) { if ( newPortalGroupRegFlag ) { /* Search for the tag portal IP and portal PORT. */ /* These are going to be used as the key. */ portalIpIndex = -1; portalPortIndex = -1; stopFlag=FALSE; for (ii=saveIndex; (iitag ) { case ISNS_PORTAL_IP: /* Check to see if we already had an IP */ if (portalIpIndex != -1) stopFlag=TRUE; else portalIpIndex = ii; break; case ISNS_PORTAL_PORT: /* Check to see if we already had a PORT */ if (portalPortIndex != -1) stopFlag=TRUE; else portalPortIndex = ii; break; case ISNS_ISCSI_NODE_ID: if (iscsiIndex != -1) stopFlag=TRUE; else iscsiIndex = ii; break; case ISNS_PORTAL_GROUP: case ISNS_PORTAL_GROUP_TAG: portal_tag = attr->val.portal_group; __DEBUG (isns_reg_debug &1,(Portal Group tag:%i),portal_tag); break; default: break; } } /* Check to see if we have all three indices */ if ( portalIpIndex == -1 || portalPortIndex == -1 || iscsiIndex == -1) { __DEBUG (isns_reg_debug & 1, (Portal Group Registration, MISSING KEYS)); return ( ISNS_INVALID_REG_ERR ); } attr = (ISNS_Attr *) attr_indx[ portalPortIndex ]; db_portal_group.ip_port = attr->val.ip_port; __DEBUG (isns_reg_debug &1,(Portal Group ip_port:%i),attr->val.ip_port); attr = (ISNS_Attr *) attr_indx[ portalIpIndex ]; __ISNS_COPY (db_portal_group.ip_addr.v, sizeof(db_portal_group.ip_addr.v), &attr->val, ISNS_PORTAL_IP_SIZE); __DEBUG (isns_reg_debug &1,(Portal Group ip_addr:%s),db_portal_group.ip_addr.v); attr = (ISNS_Attr *) attr_indx[ iscsiIndex ]; __ISNS_COPY (db_portal_group.id.v, sizeof(db_portal_group.id.v), &attr->val, attr->len); __DEBUG (isns_reg_debug &1,(Portal Group iscsi_name:%s),db_portal_group.id.v); saveIndex = ii; } else { /* Use Keys to fetch the portal Object */ key = (ISNS_Key *) key_indx[ portalPortIndex ]; db_portal_group.ip_port = key->val.ip_port; __DEBUG (isns_reg_debug &1,(Portal Group ip_port:%i),key->val.ip_port); key = (ISNS_Key *) key_indx[ portalIpIndex ]; __ISNS_COPY (db_portal_group.ip_addr.v, sizeof(db_portal_group.ip_addr.v), &key->val, key->len); __DEBUG (isns_reg_debug &1,(Portal ip_addr len:%i),key->len); attr = (ISNS_Attr *) key_indx[ iscsiIndex ]; __ISNS_COPY (db_portal_group.id.v, sizeof(db_portal_group.id.v), &attr->val, attr->len); __DEBUG (isns_reg_debug &1,(Portal Group iscsi_name:%s),db_portal_group.id.v); saveIndex = 0; /* Find portal_tag value */ stopFlag = FALSE; for ( ii = 0; (ii < SNS_MAX_ATTRS) && attr_indx[ii] && !stopFlag; ii++ ) { attr = (ISNS_Attr *) attr_indx[ ii ]; switch ( attr->tag ) { case ISNS_PORTAL_GROUP: case ISNS_PORTAL_GROUP_TAG: portal_tag = attr->val.portal_group; __DEBUG (isns_reg_debug &1,Portal Group tag:%i,p_portal_group->portal_tag); stopFlag = TRUE; break; default: break; } if (stopFlag) break; } } __DEBUG (isns_reg_debug &1,(read portal:%s),db_portal_group.id.v); rval = read_PortalGroupObject(&db_portal_group, &p_portal_group, &entry2); if ( (rval == SUCCESS) && (p_md->msg.hdr.flags & ISNS_FLAG_REPLACE_REG) ) { __DEBUG (isns_reg_debug & 1,Deregistering PortalGroup); rval = delete_PortalGroupObject(&db_portal_group); rval = ERROR; } /* Create new entry */ if ( rval != SUCCESS ) { __DEBUG (isns_reg_debug &1,create new portal group entry); memset (&entry2, 0, sizeof (SOIP_DB_Entry)); attr = (ISNS_Attr *) attr_indx[portalIpIndex]; __ISNS_COPY (p_portal_group->ip_addr.v, sizeof(p_portal_group->ip_addr.v), attr->val.ip_addr.v, attr->len); attr = (ISNS_Attr *) attr_indx[portalPortIndex]; p_portal_group->ip_port = attr->val.ip_port; attr = (ISNS_Attr *) attr_indx[iscsiIndex]; __ISNS_COPY (p_portal_group->id.v, sizeof(p_portal_group->id.v), attr->val.node_name.v, attr->len); newPortalGroupRegFlag = TRUE; } p_portal_group->portal_tag = portal_tag; __DEBUG (isns_reg_debug &1,Store Portal Group:%s,db_portal_group.id.v); rval = write_PortalGroupObject(&db_portal_group, entry2); if ( newPortalGroupRegFlag ) iSNS_stats.num_portal_groups++; if (p_rspmsg != NULL) { ISNSAppendKey (p_rspmsg, ISNS_PORTAL_GROUP_IP, ISNS_PORTAL_IP_SIZE, p_portal_group->ip_addr.v, 0); ISNSAppendKey (p_rspmsg, ISNS_PORTAL_GROUP_PORT, ISNS_PORTAL_PORT_SIZE, 0, p_portal_group->ip_port); ISNSAppendKey (p_rspmsg, ISNS_PORTAL_GROUP_TAG, ISNS_PORTAL_GROUP_TAG_SIZE, 0, p_portal_group->portal_tag); } /* Loop on the following conditions. */ attr = (ISNS_Attr *)(attr_indx[saveIndex]); if (!newPortalGroupRegFlag) break; if (!attr_indx[saveIndex]) break; newPortalGroupRegFlag = FALSE; if ((attr->tag == ISNS_PORTAL_IP) || (attr->tag == ISNS_PORTAL_PORT)) continue; else break; __DEBUG (isns_reg_debug &1,end of loop); } __DEBUG (isns_reg_debug &1, End of AddAttrPortalGroup); return (ISNS_NO_ERR); } /********************************************************************* _SNSdbAddAttrDDS Adds one or more DDS(s) to the database. *********************************************************************/ int ISNSdbAddAttrDDS ( ISNS_Msg_Descp * p_md, ISNS_Msg * p_rspmsg ) { int ii; int rval; int saveIndex; int stopFlag; int newRegFlag; int ddKeyIndex; int ddsSymIndex; int ddAttrIndex; int status_changed_flag; int updateFlag; int newMemberFlag; uint32_t newState; int dd_id; int new_dd_id; uint32_t count; uint32_t new_scn_bitmap; uint32_t updated_dd_array_size; ISNS_Key *key; ISNS_Attr *attr; ISNS_Key newKey; SOIP_Dds *p_dds; SOIP_Dd *p_dd; SOIP_DD_Key dds_key; ISNS_LIST_NODE *pnode; ISNS_Attr *src_attr; ISNS_Attr *attr_indx[SNS_MAX_ATTRS]; ISNS_Attr *key_indx[SNS_MAX_ATTRS]; int symIndex; char *p_sym; __DEBUG (isns_reg_debug & 1, (Registering DDS)); ISNSParseMsg( &p_md->msg, attr_indx, key_indx, &src_attr ); rval = Check_Authorization (src_attr); if (rval != SUCCESS) return (ISNS_AUTH_FAILED_ERR); /* Search the keys for DD_Set. */ ddKeyIndex = ISNSFindTag (0, ISNS_DDS_ID, key_indx); if (ddKeyIndex != -1) { key = (ISNS_Key *)(key_indx[ddKeyIndex]); if (key->len == 0) { /* Reset flag */ ddKeyIndex = -1; } } saveIndex = 0; while (saveIndex < SNS_MAX_ATTRS) { newRegFlag = FALSE; if (ddKeyIndex == -1) { /* DD_Set Tag not found in keys */ /* Search the op_attr */ ddAttrIndex = ISNSFindTag (saveIndex, ISNS_DDS_ID, attr_indx); if (ddAttrIndex != -1) { key = (ISNS_Key *)(attr_indx[ddAttrIndex]); saveIndex = ddAttrIndex + 1; if (key->len == 0) { /* Reset flag */ ddAttrIndex = -1; } } } if ( ddKeyIndex != -1 ) { /* DD_Set was found in the key */ /* Use it to fetch */ key = (ISNS_Key *)( key_indx[ ddKeyIndex ] ); } else if (ddAttrIndex != -1) { /* DD_Set was found in the op attr */ /* Use it to fetch */ key = (ISNS_Key *)( attr_indx[ ddAttrIndex ] ); } else { /* Generate a Unique DDS_ID */ newKey.len = 4; symIndex = ISNSFindTag( saveIndex, ISNS_DDS_SYM_NAME, attr_indx ); *(uint32_t *) & newKey.val = 0; if (symIndex != -1) { attr = (ISNS_Attr *)attr_indx[symIndex]; p_sym = (char *)&attr->val; *(uint32_t *) & newKey.val = ISNS_GetDDS_ID_from_sym( p_sym ); } if (!*(uint32_t *) & newKey.val) *(uint32_t *) & newKey.val = ISNS_GetNewDDS_ID (); key = &newKey; } dds_key.id = key->val.dds_id; if ( dds_key.id == 0 ) { __DEBUG( isns_reg_debug, (DDS ID of zero is reserved) ); return( ISNS_INVALID_REG_ERR ); } rval = read_DDSObject(dds_key.id, &p_dds, &entry); if ( (rval == SUCCESS) && (p_md->msg.hdr.flags & ISNS_FLAG_REPLACE_REG) ) { __DEBUG(isns_reg_debug & 1, "Deregistering DDS.\n"); SNSdbRemoveAttrDDS_Entry (dds_key.id, NULL, NULL); rval = ERROR; } if ( rval != SUCCESS ) { /* Create a new DDS element */ memset (&entry, 0, sizeof (SOIP_DB_Entry)); p_dds->id = *(uint32_t *) & key->val; if (-1 == (ddsSymIndex = ISNSFindTag(saveIndex, ISNS_DDS_SYM_NAME, attr_indx))) { return (ISNS_INVALID_REG_ERR); } else { attr = (ISNS_Attr *)attr_indx[ddsSymIndex]; if (!strlen((char *)&attr->val)) { return (ISNS_INVALID_REG_ERR); } } InitList(DDS_DD_LIST, p_dds); newRegFlag = TRUE; } new_scn_bitmap = 0; newMemberFlag = FALSE; updateFlag = FALSE; memset(p_scn_all_msg_buffer, 0, sizeof(ISNS_Msg)); p_scn_all_msg_buffer->hdr.type = ISNS_SCN; ISNSAppendKey(p_scn_all_msg_buffer, ISNS_DDS_ID, ISNS_DDS_ID_SIZE, NULL, p_dds->id); stopFlag = FALSE; status_changed_flag = FALSE; __DEBUG (isns_reg_debug &1,Process the message attributes); for (ii = saveIndex; (ii < SNS_MAX_ATTRS) && (attr_indx[ii]) && !stopFlag; ii++) { attr = (ISNS_Attr *) attr_indx[ii]; switch (attr->tag) { case ISNS_DDS_ID: stopFlag = TRUE; saveIndex = ii; break; case ISNS_DDS_SYM_NAME: if (FALSE == Check_Unique_DDS_Sym (p_dds, (char *)&attr->val)) { __DEBUG (isns_reg_debug & 1, (DDS sym name not unique:%s), (char *)&attr->val); rval = ISNS_INVALID_REG_ERR; if (newRegFlag) DeleteList(&p_dds->dd_list); return (rval); } strncpy (p_dds->sym_name, (char *)&attr->val, sizeof(p_dds->sym_name)); break; case ISNS_DDS_STATUS: if (p_dds->status != *(uint32_t *)&attr->val) { p_dds->status=*(uint32_t *)&attr->val; status_changed_flag = TRUE; updateFlag = TRUE; ISNSAppendKey( p_scn_all_msg_buffer, ISNS_DDS_STATUS, ISNS_DDS_STATUS_SIZE, NULL, p_dds->status ); } break; case ISNS_DD_ID: new_dd_id = *(uint32_t *) & attr->val; if (ISNS_NO_ERR != Add_dds_to_dd (p_dds, new_dd_id)) { rval = ISNS_UNKNOWN_ERR; if (newRegFlag) DeleteList(&p_dds->dd_list); return (rval); } ISNSAppendKey( p_scn_all_msg_buffer, ISNS_DD_ID, ISNS_DD_ID_SIZE, NULL, new_dd_id); newMemberFlag = TRUE; break; default: break; } } if (newRegFlag && !strlen(p_dds->sym_name)) { __DEBUG(isns_reg_debug & 1, (Symbolic name missing)); DeleteList(&p_dds->dd_list); return (ISNS_INVALID_REG_ERR); } /* Store Entry */ rval = write_DDSObject(dds_key.id, entry); if ( newRegFlag ) iSNS_stats.num_dds++; ISNSAppendKey ( p_rspmsg, ISNS_DDS_ID, ISNS_DDS_ID_SIZE, NULL, p_dds->id ); if ( status_changed_flag ) { /* Status changed */ updated_dd_array_size = 0; memset(dlist_node, 0, MAX_DD_PER_LIST*sizeof(uint32_t)); pnode = NULL; while ( (pnode = GetNextNode ( &p_dds->dd_list, pnode ) ) ) { dd_id = *(uint32_t *) GetNodeData (pnode); /* Change status for all DD */ rval = read_DDObject(dd_id, &p_dd, &entry); if (rval != SUCCESS) return rval; newState = IsDDActive ( dd_id, 0 ); if ( newState != p_dd->activeFlag) { p_dd->activeFlag = newState; dlist_node[ updated_dd_array_size ] = p_dd->id; updated_dd_array_size++; /* Store Entry */ write_DDObject(dd_id, entry); } } /* Change status for all DD's members */ for (count = 0; counttag == ISNS_DDS_ID) continue; else break; } return (ISNS_NO_ERR); } /********************************************************************* _SNSdbAddAttrDD Adds one or more DD to the database. *********************************************************************/ int ISNSdbAddAttrDD ( ISNS_Msg_Descp *p_md, ISNS_Msg * p_rspmsg ) { int ii; int rval; int ddKeyIndex; int ddAttrIndex; int ddSymIndex; int saveIndex; int stopFlag; int newRegFlag; int updateFlag; int newMemberFlag; int s; uint32_t new_scn_bitmap; ISNS_Key *key; ISNS_Attr *attr; ISNS_Key newKey; SOIP_Dd *p_dd; SOIP_DD_Key dd_key; ISNS_Attr *src_attr; ISNS_Attr *attr_indx[SNS_MAX_ATTRS]; ISNS_Attr *key_indx[SNS_MAX_ATTRS]; char *p_sym; int symIndex; uint32_t iscsi_idx; __DEBUG (isns_reg_debug & 1, (Registering DD)); ISNSParseMsg(&p_md->msg, attr_indx, key_indx, &src_attr); rval = Check_Authorization (src_attr); if (rval != SUCCESS) return (ISNS_AUTH_FAILED_ERR); /* Search the keys for DD_Set. */ ddKeyIndex = ISNSFindTag (0, ISNS_DD_ID, key_indx); if (ddKeyIndex != -1) { key = (ISNS_Key *)(key_indx[ddKeyIndex]); if (key->len == 0) { ddKeyIndex = -1; } } saveIndex = 0; while (saveIndex < SNS_MAX_ATTRS) { newRegFlag = FALSE; if (ddKeyIndex == -1) { /* DD_ID Tag not found in keys */ /* Search the op_attr */ ddAttrIndex = ISNSFindTag (saveIndex, ISNS_DD_ID, attr_indx); if (ddAttrIndex != -1) { key = (ISNS_Key *)(attr_indx[ddAttrIndex]); saveIndex = ddAttrIndex + 1; if (key->len == 0) { ddAttrIndex = -1; } } } if (ddKeyIndex != -1) { /* DD_ID was found in the key */ /* Use it to fetch */ key = (ISNS_Key *)(key_indx[ddKeyIndex]); } else if (ddAttrIndex != -1) { /* DD_ID was found in the op attr */ /* Use it to fetch */ key = (ISNS_Key *)(attr_indx[ddAttrIndex]); } else { /* Generate a Unique DD_ID, or retrieve the id of a dd with the same symbolic name. */ newKey.len = 4; /* First try to see if a DD_ID is associated with this symbolic name */ symIndex = ISNSFindTag(saveIndex, ISNS_DD_SYM_NAME, attr_indx); p_sym = NULL; if (symIndex != -1) { attr = (ISNS_Attr *)attr_indx[ symIndex ]; p_sym = (char *)&attr->val; *(uint32_t *) &newKey.val = ISNS_GetDD_ID_from_sym( p_sym ); } /* Get a new DD_ID */ if (!*(uint32_t *)&newKey.val) *(uint32_t *) & newKey.val = ISNS_GetNewDD_ID (); key = &newKey; } dd_key.id = *(uint32_t *) &key->val; rval = read_DDObject(dd_key.id, &p_dd, &entry); if ( (rval == SUCCESS) && (p_md->msg.hdr.flags & ISNS_FLAG_REPLACE_REG) ) { SNSdbRemoveDD_Entry ( dd_key.id, NULL, NULL ); rval = ERROR; } if ( rval != SUCCESS) { __DEBUG (isns_reg_debug &1,(Create a new DD element)); /* Create a new DD element */ memset ( &entry, 0, sizeof (SOIP_DB_Entry) ); p_dd->id = *(uint32_t *) & key->val; if (-1 == (ddSymIndex = ISNSFindTag(saveIndex, ISNS_DD_SYM_NAME, attr_indx))) { return (ISNS_INVALID_REG_ERR); } else { attr = (ISNS_Attr *)attr_indx[ddSymIndex]; if (!strlen((char *)&attr->val)) { return (ISNS_INVALID_REG_ERR); } } InitList(DD_DDS_LIST, p_dd ); InitList(DD_MEMBER_LIST, p_dd ); newRegFlag = TRUE; } __DEBUG (isns_reg_debug &1, p_dd dds_dds_list id:%i,p_dd->dds_list.list_id); __DEBUG (isns_reg_debug &1, p_dd member_list id:%i,p_dd->member_list.list_id); /* Prep the SCN message */ updateFlag = FALSE; newMemberFlag = FALSE; new_scn_bitmap = 0; memset( p_scn_all_msg_buffer, 0, sizeof(ISNS_Msg)); p_scn_all_msg_buffer->hdr.type = ISNS_SCN; ISNSAppendKey(p_scn_all_msg_buffer, ISNS_DD_ID, ISNS_DD_ID_SIZE, NULL, p_dd->id); stopFlag = FALSE; newMemberFlag = FALSE; iscsi_idx = 0; for (ii = saveIndex; (ii < SNS_MAX_ATTRS) && (attr_indx[ ii ]) && !stopFlag; ii++) { attr = (ISNS_Attr *) attr_indx[ii]; switch (attr->tag) { case ISNS_DD_ID: { saveIndex = ii; stopFlag = TRUE; break; } case ISNS_DD_FEATURE_BITMAP: { p_dd->feature = *(uint32_t *)&attr->val; break; } case ISNS_DD_SYM_NAME: { if (memcmp(p_dd->sym_name, (char *)&attr->val, attr->len )) { if ( FALSE == Check_Unique_DD_Sym ( p_dd, (char *)&attr->val ) ) { __DEBUG ( isns_reg_debug & 1,Error DD Symbolic name not unique); return ( ISNS_INVALID_REG_ERR ); } strncpy ( p_dd->sym_name, (char *)&attr->val, sizeof(p_dd->sym_name) ); ISNSAppendKey( p_scn_all_msg_buffer, ISNS_DD_SYM_NAME, attr->len, (char *)&attr->val, 0 ); updateFlag = TRUE; } break; } case ISNS_DD_ISCSI_MEMBER_IDX: { iscsi_idx = *(uint32_t *)&attr->val; break; } case ISNS_ISCSI_NODE_ID: case ISNS_DD_ISCSI_MEMBER: { s = Add_DD_to_ISCSI_Node ( p_dd, (char *)&attr->val ); Add_DD_Member ( p_dd, (char *) &attr->val, PAD4( strlen((char *)&attr->val) ), ISNS_DD_ISCSI_MEMBER, s == ISNS_NO_ERR?ISNS_DD_MEMBER_ENABLE:ISNS_DD_MEMBER_DISABLE, iscsi_idx); ISNSAppendKey( p_scn_all_msg_buffer, ISNS_DD_ISCSI_MEMBER, attr->len, (char *)&attr->val, 0); send_iscsi_scn_to_members (NULL, (char *)&attr->val, p_scn_all_msg_buffer, ISNS_SCN_OBJ_ADDED); newMemberFlag = TRUE; iscsi_idx = 0; break; } case ISNS_PORT_NAME: case ISNS_DD_IFCP_MEMBER: { s = Add_DD_to_IFCP_Node (p_dd->id, (char *)&attr->val); Add_DD_Member (p_dd, (char *) &attr->val, PORT_NAME_SIZE, ISNS_DD_IFCP_MEMBER, s == ISNS_NO_ERR?ISNS_DD_MEMBER_ENABLE:ISNS_DD_MEMBER_DISABLE, 0); updateFlag = TRUE; ISNSAppendKey( p_scn_all_msg_buffer, ISNS_DD_IFCP_MEMBER, attr->len, (char *)&attr->val, 0); send_iscsi_scn_to_members (NULL, (char *)&attr->val, p_scn_all_msg_buffer, ISNS_SCN_OBJ_ADDED); break; } default: __DEBUG(isns_reg_debug & 1, (Unrecognized tag for function: %u), attr->tag); break; } } if (newRegFlag && !strlen(p_dd->sym_name)) { __DEBUG(isns_reg_debug &1, (Symbolic name missing)); DeleteList( &p_dd->dds_list ); DeleteList( &p_dd->member_list ); return ( ISNS_INVALID_REG_ERR ); } /* Store Entry */ __DEBUG (isns_reg_debug &1, now write dd record dds_list id:%i,entry.data.dd.dds_list.list_id); rval = write_DDObject(dd_key.id, entry); if ( newRegFlag ) iSNS_stats.num_dd++; ISNSAppendKey (p_rspmsg, ISNS_DD_ID, ISNS_DD_ID_SIZE, NULL, p_dd->id); attr = (ISNS_Attr *)(attr_indx[saveIndex]); ddKeyIndex = -1; if (attr && attr->tag == ISNS_DD_ID) continue; else break; } return (ISNS_NO_ERR); } /********************************************************************* *********************************************************************/ int Add_DD_Member ( SOIP_Dd * p_dd, char * p_node_name, int p_len, uint32_t type, uint32_t status, uint32_t index ) { ISNS_LIST_NODE *pnode; SOIP_Dd_Member *p_member; SOIP_Dd_Member new_member; SOIP_Iscsi *p_node; int rval; SOIP_DB_Entry lentry; int index_number; __DEBUG (isns_reg_debug &1, Add_DD_Member:%s, p_node_name); rval = read_ISCSIObject(p_node_name, &p_node, &lentry); if ( rval != SUCCESS) { index_number = index; } else { index_number = p_node->iscsi_index; } pnode = NULL; while ((pnode = GetNextNode(&p_dd->member_list, pnode))) { p_member = (SOIP_Dd_Member *)GetNodeData(pnode); if ((p_member->type == type) && (0 == memcmp (p_member->node_id, p_node_name, strlen(p_node_name) ))) { return (ISNS_NO_ERR); } } memset(&new_member, 0, sizeof(new_member)); new_member.type = type; new_member.status = status; __ISNS_COPY (new_member.node_id, sizeof(new_member.node_id), p_node_name, strlen(p_node_name)); new_member.node_idx = index_number; __DEBUG (isns_reg_debug &1, Add_DD_Member member.type:%i,new_member.type); __DEBUG (isns_reg_debug &1, Add_DD_Member member.node_id:%s,new_member.node_id); __DEBUG (isns_reg_debug &1, Add_DD_Member member.node_idx:%i,new_member.node_idx); AddNode(&p_dd->member_list, (char *)&new_member, sizeof(new_member)); return (ISNS_NO_ERR); } /********************************************************************* _SNSdbAddAttrEntity Adds one or more entities *********************************************************************/ int SNSdbAddAttrEntity ( ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Msg_Descp * p_md, ISNS_Msg * p_rspmsg) { int ii; ISNS_Key *key = NULL; ISNS_Attr *attr; SOIP_Entity *p_entity; SOIP_Entity_Key db_entity_id; int entityKeyIndex; int entityAttrIndex; int newRegFlag; int rval; static int entityNumber = 0; time_t t; char tempEntityId[ ENTITY_ID_SIZE ] = {0}; int updateFlag; int node_type = 0; int nodeTypeIndex = -1; newRegFlag = FALSE; __DEBUG (isns_reg_debug & 1, (Registering Entity)); memset (&db_entity_id, 0, sizeof (db_entity_id)); /* Search the keys for entity ID. */ entityKeyIndex = -1; entityAttrIndex = -1; entityKeyIndex = ISNSFindTag ( 0, ISNS_ENTITY_ID, key_indx ); if ( entityKeyIndex != -1 ) { /* Entity wasn't in the keys */ /* Search the op attr */ key = (ISNS_Key *)(key_indx[ entityKeyIndex ]); if ( key->len == 0 ) entityKeyIndex = -1; strncpy ( db_entity_id.id, (char *)&key->val, sizeof(db_entity_id.id) ); } else { entityAttrIndex = ISNSFindTag (0, ISNS_ENTITY_ID, attr_indx); if ( entityAttrIndex != -1 ) { /* Use the Attr */ attr = (ISNS_Attr *)(attr_indx[ entityAttrIndex ]); if ( attr->len == 0 ) entityAttrIndex = -1; strncpy ( db_entity_id.id, (char *)&attr->val, sizeof(db_entity_id.id) ); } } if ( entityAttrIndex != -1 && entityKeyIndex != -1 ) { __DEBUG (isns_reg_debug & 1, (Same tag found in Key and Op Attr %u), key->tag); return (ISNS_MSG_FMT_ERR); } else if ( entityAttrIndex == -1 && entityKeyIndex == -1 ) { /* Entity ID was not provided so generate one. */ memset (tempEntityId, 0, sizeof (tempEntityId)); sprintf(tempEntityId, "isns.entity.%4.4d", entityNumber++); strncpy ((char *) db_entity_id.id, (char *) tempEntityId, sizeof(db_entity_id.id) ); } nodeTypeIndex = ISNSFindTag ( 0, ISNS_ISCSI_TYPE, attr_indx ); if (nodeTypeIndex != -1) { attr = (ISNS_Attr *) attr_indx[nodeTypeIndex]; node_type = *(uint32_t *)&attr->val; } rval = read_EntityObject(db_entity_id.id, &p_entity, &entry); /* If an entry was found and the update flag is not set deregister it */ /* Also if the entry was found and the node_type is different then */ /* don't de-register it */ if ( (rval == SUCCESS) && (p_md->msg.hdr.flags & ISNS_FLAG_REPLACE_REG) ) { if ( p_entity->node_type == node_type) { __DEBUG (isns_reg_debug &1, RemoveEntity); ISNSdbRemoveAttrEntityEntry (db_entity_id.id, NULL, NULL); rval = ERROR; } } if ( rval != SUCCESS ) { /* create a new entity element */ memset ( &entry, 0, sizeof (SOIP_DB_Entry) ); p_entity->entity_index = ISNSGetNewEntityIdx(); SOIP_Entity_Id *p_idx; memset (&entry3, 0, sizeof(SOIP_Entity_Id)); p_idx = &entry3.data.entity_idx; __ISNS_COPY (p_idx, sizeof(entry3.data.entity_idx), &db_entity_id.id, sizeof(SOIP_Entity_Id)); rval = write_EntityidxObject(p_entity->entity_index, entry3); strncpy (p_entity->eid.id, db_entity_id.id, sizeof(p_entity->eid.id) ); InitList(ENTITY_PORTAL_LIST, p_entity); InitList(ENTITY_ISCSI_LIST, p_entity); InitList(ENTITY_FCP_LIST, p_entity); if ( ISNSFindTag (0, ISNS_ENTITY_TYPE, attr_indx) == -1 ) { /* No ENTITY TYPE FLAG FOUND! */ if ( ISNSFindTag (0, ISNS_PORT_NAME, attr_indx) != -1 ) { p_entity->eid_type = ENTITY_TYPE_IFCP; } else if ( ISNSFindTag (0, ISNS_ISCSI_NODE_ID, attr_indx) != -1 ) { p_entity->eid_type = ENTITY_TYPE_ISCSI; } } newRegFlag = TRUE; } p_entity->timestamp.t_time = time (&t); __DEBUG (isns_reg_debug &1,nodecount:%i,p_entity->iscsi_node_list.node_count); updateFlag = FALSE; for (ii = 0; (ii < SNS_MAX_ATTRS) && (attr_indx[ ii ]); ii++) { attr = (ISNS_Attr *) attr_indx[ ii ]; switch ( attr->tag ) { case ISNS_ENTITY_TYPE: if (!( *(uint32_t *)&attr->val == ENTITY_TYPE_ISCSI || *(uint32_t *)&attr->val == ENTITY_TYPE_IFCP )) { __DEBUG ( isns_reg_debug & 1, (Invalid Entity Type) ); return ( ISNS_INVALID_REG_ERR ); } if ((uint32_t)p_entity->eid_type != *(uint32_t *) &attr->val) { p_entity->eid_type = *(uint32_t *) & attr->val; updateFlag = TRUE; } break; case ISNS_MGMT_IP: __ISNS_COPY (p_entity->mgmt_ip_addr.v, sizeof(p_entity->mgmt_ip_addr.v), &attr->val, ISNS_IP_SIZE); updateFlag = TRUE; break; case ISNS_PROT_VER: { if (attr->val.prot_ver.ver_max < attr->val.prot_ver.ver_min) { __DEBUG (isns_reg_debug & 1, (Version incorrect)); return (ISNS_INVALID_REG_ERR); } p_entity->prot_ver.ver_max = attr->val.prot_ver.ver_max; p_entity->prot_ver.ver_min = attr->val.prot_ver.ver_min; updateFlag = TRUE; break; } case ISNS_ENTITY_PERIOD: { if (p_entity->period != attr->val.period) { p_entity->period = attr->val.period; updateFlag = TRUE; } break; } case ISNS_ENTITY_CERT: AddCert ( &p_entity->ptr_cert, (int *)&p_entity->cert_size, &attr->val, attr->len ); updateFlag = TRUE; break; case ISNS_ISCSI_TYPE: p_entity->node_type = p_entity->node_type | *(uint32_t *)&attr->val; updateFlag = TRUE; break; default: break; } } /* Compose a response msg. */ ISNSAppendKey ( p_rspmsg, ISNS_ENTITY_ID, PAD4 (strlen (db_entity_id.id)), db_entity_id.id, 0 ); if ( newRegFlag ) iSNS_stats.num_entity++; rval = write_EntityObject(db_entity_id.id, entry); __DEBUG (isns_reg_debug & 1, (Save Entity:%i),rval); return ( rval ); } /********************************************************************* _ISNSdbAddAttrNode Adds one or more FC Nodes to the database. *********************************************************************/ int ISNSdbAddAttrNode (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Msg_Descp * p_md, ISNS_Msg * p_rspmsg) { int ii, rval; ISNS_Key *key; ISNS_Attr *attr; SOIP_Fc_Node *p_node; SOIP_DB_Node_Name db_node_name; int fcNodeIndex; int saveIndex; int stopFlag; int newRegFlag; int newKeyFlag; __DEBUG (isns_reg_debug & 1, (Registering FC Node)); /* Search for Node Name Key */ newKeyFlag = TRUE; newRegFlag = TRUE; fcNodeIndex = ISNSFindTag (0, ISNS_NODE_NAME, key_indx); /* Search Op Attributes for Enitity_id */ saveIndex = 0; /* Also see conditions at bottom */ while (saveIndex < SNS_MAX_ATTRS) { key = NULL; fcNodeIndex = -1; if (newRegFlag) { /* New registration */ for (ii = saveIndex; ii < SNS_MAX_ATTRS && attr_indx[ii] && fcNodeIndex == -1; ii++) { attr = (ISNS_Attr *) attr_indx[ii]; if (attr->tag == ISNS_NODE_NAME) { fcNodeIndex = ii; } } saveIndex = ii; key = (ISNS_Key *) attr_indx[fcNodeIndex]; } else { /* Update */ key = (ISNS_Key *) key_indx[fcNodeIndex]; } if (!key) { __DEBUG (isns_reg_debug & 1, (Fatal Error)); return (ERROR); } /* * Set the node name to be unique for db fetch */ memset (&db_node_name, 0, sizeof (db_node_name)); __ISNS_COPY (db_node_name.v, sizeof(db_node_name.v), key->val.node_name.v, ISNS_NODE_NAME_SIZE); db_node_name.v[8] = (char)SOIP_DB_Node_Id; rval = read_FCNodeObject(db_node_name.v, &p_node, &entry); if ( (rval == SUCCESS) && (p_md->msg.hdr.flags & ISNS_FLAG_REPLACE_REG) ) { __DEBUG (isns_reg_debug & 2, (Deregistering FC Node)); SNSRemoveFCNodeEntry (key->val.node_name.v, NULL); rval = ERROR; } if ( rval != SUCCESS ) { /* create a new node element */ memset (&entry, 0, sizeof (SOIP_DB_Entry)); memset (&entry.data.node.node_ipa, SNS_UNREGISTERED, NODE_IPA_SIZE); __ISNS_COPY (entry.data.node.node_name.v, sizeof(entry.data.node.node_name.v), db_node_name.v, ISNS_NODE_NAME_SIZE); InitList(FCP_PORTAL_LIST, p_node); newKeyFlag = TRUE; } /* Store the Node Name */ __ISNS_COPY (p_node->node_name.v, sizeof(p_node->node_name.v), entry.data.node.node_name.v, ISNS_NODE_NAME_SIZE); stopFlag = FALSE; for (ii = saveIndex; (ii < SNS_MAX_ATTRS) && (attr_indx[ii]) && !stopFlag; ii++) { attr = (ISNS_Attr *) attr_indx[ii]; switch (attr->tag) { case ISNS_NODE_SYM_NAME: strncpy (p_node->sym_name, attr->val.sym_node_name, NODE_SYM_NAME_SIZE); break; case ISNS_FC_NODE_IP: __ISNS_COPY (&p_node->ip_addr.v, sizeof(p_node->ip_addr.v), &attr->val.ip_addr.v, IP_ADDR_SIZE); break; case ISNS_FC_NODE_IPA: __ISNS_COPY (&p_node->node_ipa.v, sizeof(p_node->node_ipa.v), &attr->val.ipa.v, NODE_IPA_SIZE); break; case ISNS_NODE_NAME: stopFlag = TRUE; saveIndex = ii; break; case ISNS_FC_NODE_CERT: AddCert (&p_node->ptr_cert, (int *)&p_node->cert_size, &attr->val, attr->len); break; default: break; } } rval = write_FCNodeObject(db_node_name.v, entry); /* Compose a response */ if (newKeyFlag) { ISNSAppendKey (p_rspmsg, ISNS_NODE_NAME, ISNS_NODE_NAME_SIZE, p_node->node_name.v, 0); newKeyFlag = FALSE; } /* Decide on Looping */ attr = (ISNS_Attr *)attr_indx[saveIndex]; if (attr && attr->tag == ISNS_NODE_NAME) continue; else break; } /* End While */ return (rval); } /********************************************************************* _SNSdbAddAttrPort Adds the iFCP Node(s) to the database. *********************************************************************/ int SNSdbAddAttrPort (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Msg_Descp * p_md, ISNS_Msg * p_rspmsg) { SOIP_DB_Node_Name db_node_name; ISNS_Key *key; ISNS_Attr *attr; SOIP_Fc_Node *p_fc_node; SOIP_Ifcp *p_ifcp_node; SOIP_Entity *p_entity; SOIP_Entity_Key db_entity; char *entity_id; char buffer[MAX_ENTITY_ID_SIZE] = { 0 }; int entityKeyIndex, portKeyIndex; int newPortRegFlag; int saveIndex; int stopFlag; int entity_len; int free_slot; int updateNodeFlag = FALSE; int ii, rval; //char *p_wwpn; __DEBUG (isns_reg_debug & 1, (Registering iFCP WWPN)); /* Scan for Entity Keys */ entityKeyIndex = -1; portKeyIndex = -1; newPortRegFlag = TRUE; for (ii = 0; ii < MAX_PARSE_ATTRS && key_indx[ii]; ii++) { key = (ISNS_Key *)(key_indx[ii]); switch (key->tag) { case ISNS_PORT_NAME: portKeyIndex = ii; newPortRegFlag = FALSE; break; case ISNS_ENTITY_ID: entityKeyIndex = ii; break; default: break; } } saveIndex = 0; while (saveIndex < MAX_PARSE_ATTRS) { if (newPortRegFlag) { portKeyIndex = -1; portKeyIndex = ISNSFindTag (saveIndex, ISNS_PORT_NAME, attr_indx); saveIndex = portKeyIndex + 1; key = (ISNS_Key *) attr_indx[portKeyIndex]; } else { key = (ISNS_Key *) key_indx[portKeyIndex]; } if (portKeyIndex == -1) { __DEBUG(isns_reg_debug & 1, "***WARNING: PORT_NAME tag not found.\n"); return (ISNS_INVALID_REG_ERR); } rval = read_FCPortObject((char *)&key->val, &p_ifcp_node, &entry); if ( (rval == SUCCESS) && (p_md->msg.hdr.flags & ISNS_FLAG_REPLACE_REG) ) { __DEBUG (isns_reg_debug & 2, (Deregistering iFCP Node)); SNSRemoveIFCPNodeEntry ((char *)&key->val, NULL, NULL); rval = ERROR; } if ( rval != SUCCESS) { /* Fetch Entity */ if (entityKeyIndex != -1) { key = (ISNS_Key *)(key_indx[entityKeyIndex]); entity_id = (char *)&key->val; entity_len = key->len; } else { /* Check to see if we registered an entity id in this msg */ attr = ISNSFindKeyInResponseMsg (ISNS_ENTITY_ID, p_rspmsg); if (attr == NULL) { int rval; /* Create a new entity */ rval = SNSdbAddAttrEntity (attr_indx, key_indx, p_md, p_rspmsg); if (rval != SUCCESS) { __DEBUG (isns_reg_debug & 1, (Unsuccessful entity reg)); return (ERROR); } /* Check to see if we registered an entity id in this msg */ attr = ISNSFindKeyInResponseMsg (ISNS_ENTITY_ID, p_rspmsg); if (attr == NULL) { __DEBUG (isns_reg_debug & 1, (Unsuccessful entity reg)); return (ERROR); } } entity_id = (char *)&attr->val; entity_len = attr->len; } /* Fetch the entity */ memset(&db_entity, 0, sizeof(db_entity)); strncpy(db_entity.id, entity_id, sizeof(db_entity.id) ); if (SUCCESS != read_EntityObject (db_entity.id, &p_entity, &entry2)) return (ISNS_INVALID_REG_ERR); /* create a new port element */ memset (&entry, 0, sizeof (SOIP_DB_Entry)); __ISNS_COPY (p_ifcp_node->entity_id.id, sizeof(p_ifcp_node->entity_id.id), entity_id, entity_len); InitList(FCP_DD_LIST, &p_ifcp_node->dd_id_list); /* Search for free port */ if (!FindNode(&p_entity->ifcp_node_list, p_ifcp_node->port_name.v, PORT_NAME_SIZE)) { AddNode(&p_entity->ifcp_node_list, p_ifcp_node->port_name.v, PORT_NAME_SIZE); } rval = write_EntityObject(db_entity.id, entry2); } stopFlag = FALSE; for (ii = saveIndex; (ii < SNS_MAX_ATTRS) && (attr_indx[ii]) && !stopFlag; ii++) { attr = (ISNS_Attr *) attr_indx[ii]; switch (attr->tag) { case ISNS_PORT_NAME: stopFlag = TRUE; newPortRegFlag = TRUE; saveIndex = ii; break; case ISNS_PORT_SYM_NAME: __ISNS_COPY (p_ifcp_node->sym_name, sizeof(p_ifcp_node->sym_name), attr->val.sym_port_name, attr->len); break; case ISNS_FABRIC_PORT_NAME: __ISNS_COPY (&p_ifcp_node->fabric_port_name.v, sizeof(p_ifcp_node->fabric_port_name.v), &attr->val.fabric_port_name.v, PORT_NAME_SIZE); break; case ISNS_NODE_NAME: __ISNS_COPY (&p_ifcp_node->node_name.v, sizeof(p_ifcp_node->node_name.v), &attr->val.node_name.v, ISNS_NODE_NAME_SIZE); /* Update the FC NODE. */ updateNodeFlag = TRUE; break; case ISNS_FC_PORT_IP: __ISNS_COPY (p_ifcp_node->ip_addr.v, sizeof(p_ifcp_node->ip_addr.v), &attr->val, ISNS_IP_SIZE); break; case ISNS_FC_HARD_ADDR: __ISNS_COPY (&p_ifcp_node->hard_addr.v, sizeof(p_ifcp_node->hard_addr.v), &attr->val.hard_addr.v, HARD_ADDR_SIZE); break; case ISNS_PORT_ID: __ISNS_COPY (&p_ifcp_node->id, sizeof(p_ifcp_node->id), &attr->val, PORT_ID_SIZE); break; case ISNS_PORT_TYPE: p_ifcp_node->type = *(uint32_t *) & attr->val; break; case ISNS_IFCP_NODE_CERT: AddCert (&p_ifcp_node->ptr_cert, (int *)&p_ifcp_node->cert_size, &attr->val, attr->len); break; case ISNS_FC4_TYPE: __DEBUG (isns_reg_debug & 1, (Not Implemented)); break; case ISNS_FC_COS: __ISNS_COPY (&p_ifcp_node->cos, sizeof(p_ifcp_node->cos), &attr->val.cos, SNS_COS_SIZE); break; case ISNS_FC4_DESC: strncpy ( p_ifcp_node->fc_descr.v, (char *) &attr->val, sizeof(p_ifcp_node->fc_descr.v) ); break; case ISNS_FC4_FEATURE: __ISNS_COPY (&p_ifcp_node->fc_feature, sizeof(p_ifcp_node->fc_feature), &attr->val, FC_FEATURE_SIZE); break; case ISNS_IFCP_SCN_BITMAP: p_ifcp_node->scn_bitmap=*(uint32_t *)&attr->val; if (p_md->cb.sock.socketType == ISNS_SOCKET_TYPE_TCP) { p_ifcp_node->scn_sockfd = p_md->cb.sock.sockfd; } else { p_ifcp_node->scn_sockfd = 0; } break; default: break; } } memset (buffer, 0, sizeof (buffer)); __ISNS_COPY (buffer, sizeof(buffer), p_ifcp_node->port_name.v, PORT_NAME_SIZE); /* Activate DD Membership */ if (SUCCESS != Activate_DD_Membership (ISNS_DD_IFCP_MEMBER, p_ifcp_node)) return (ERROR); /* Store Port Name */ rval = write_FCPortObject(p_ifcp_node->port_name.v,entry); /* response */ ISNSAppendKey (p_rspmsg, ISNS_PORT_NAME, PORT_NAME_SIZE, p_ifcp_node->port_name.v, 0); /* Update the Node Entry */ memset (&db_node_name, 0, sizeof (db_node_name)); if (memcmp (db_node_name.v, p_ifcp_node->node_name.v, ISNS_NODE_NAME_SIZE)) { /* Node Name is not NULL */ __ISNS_COPY (db_node_name.v, sizeof(db_node_name.v), p_ifcp_node->node_name.v, ISNS_NODE_NAME_SIZE); db_node_name.v[8] = (char)SOIP_DB_Node_Id; rval = read_FCNodeObject(db_node_name.v, &p_fc_node, &entry2); if ( rval != SUCCESS) { /* We will create the node */ memset (&entry2, 0, sizeof (entry2)); memset (&entry2.data.node.node_ipa, SNS_UNREGISTERED, NODE_IPA_SIZE); __ISNS_COPY (entry2.data.node.node_name.v, sizeof(entry2.data.node.node_name.v), db_node_name.v, ISNS_NODE_NAME_SIZE); } /* insert port name into free slot in node's port list */ free_slot = -1; /* Is this port name already associated with the node? */ if (!FindNode(&p_fc_node->port_list, (char *)&p_ifcp_node->port_name.v, PORT_NAME_SIZE)) { AddNode(&p_fc_node->port_list, (char *)&p_ifcp_node->port_name.v, PORT_NAME_SIZE); } rval = write_FCNodeObject(db_node_name.v, entry2); } /* Determine to loop */ attr = (ISNS_Attr *)(attr_indx[saveIndex]); if (attr && attr->tag == ISNS_PORT_NAME) continue; else break; } return (rval); } /********************************************************************* Registers one or more iSCSI Node(s) by adding it to the database. *********************************************************************/ int ISNSdbAddAttrISCSINode ( ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Msg_Descp * p_md, ISNS_Msg * p_rspmsg ) { int ii; int rval; ISNS_Key *key; ISNS_Attr *attr; SOIP_Entity *p_entity; SOIP_Iscsi *p_node; SOIP_ISCSI_Node_Id db_node_name; SOIP_Entity_Key db_entity; int nodeIndex; int entityIndex; int saveIndex; int stopFlag; int newRegFlag; int updateFlag; uint32_t scn_bitmap= 0; uint32_t safe_len; int newIscsiNodeFlag; __DEBUG ( isns_reg_debug & 1, (Registering iSCSI Node) ); newRegFlag = FALSE; /* Search for ISCSI NODE ID Key */ nodeIndex = ISNSFindTag ( 0, ISNS_ISCSI_NODE_ID, attr_indx ); if (nodeIndex != -1) newRegFlag = TRUE; /* Also see conditions at bottom */ saveIndex = 0; while ( saveIndex < SNS_MAX_ATTRS ) { newIscsiNodeFlag = FALSE; key = NULL; if ( newRegFlag ) { /* New registration */ nodeIndex = -1; nodeIndex = ISNSFindTag (saveIndex, ISNS_ISCSI_NODE_ID, attr_indx); if ( nodeIndex == -1 ) { __DEBUG(isns_reg_debug & 1, (iSCSI Node tag not found)); return (ERROR); } saveIndex = nodeIndex + 1; key = (ISNS_Key *) (attr_indx[ nodeIndex ]); } else { /* Update */ key = (ISNS_Key *) (key_indx[ nodeIndex ]); } if ( !key ) { __DEBUG (isns_reg_debug & 1, (No ISNS_ISCSI_NODE_ID tag)); return ( ISNS_MSG_FMT_ERR ); } memset ( &db_node_name, 0, sizeof (db_node_name) ); strncpy ((char *) db_node_name.v, (char *) &key->val, key->len ); rval = read_ISCSIObject(db_node_name.v, &p_node, &entry); if ( (rval == SUCCESS) && (p_md->msg.hdr.flags & ISNS_FLAG_REPLACE_REG)) { __DEBUG ( isns_reg_debug & 2, (Deregistering iSCSI Node %s), db_node_name.v); SNSRemoveISCSINodeEntry ( db_node_name.v, NULL, NULL ); rval = ERROR; } if ( rval != SUCCESS) { /* Create new node */ if ( !newRegFlag ) { __DEBUG (isns_reg_debug & 1, (iSCSI Node not found %s), db_node_name.v); return ( ISNS_INVALID_REG_ERR ); } scn_bitmap |= ISNS_SCN_OBJ_ADDED; /* Search for an ENTITY Key */ entityIndex = -1; entityIndex = ISNSFindTag ( 0, ISNS_ENTITY_ID, key_indx ); memset ( &db_entity, 0, sizeof (db_entity) ); if ( entityIndex != -1 ) { key = (ISNS_Key *)( key_indx[ entityIndex ] ); strncpy(db_entity.id, (char *)&key->val, sizeof(db_entity.id) ); } else { /* if not found, search rsp mesg */ attr = ISNSFindKeyInResponseMsg ( ISNS_ENTITY_ID, p_rspmsg ); if ( attr == NULL ) { /* Create a new entity */ rval = SNSdbAddAttrEntity ( attr_indx, key_indx, p_md, p_rspmsg ); if ( rval != ISNS_NO_ERR ) { __DEBUG ( isns_reg_debug & 1, (Error Creating entity) ); return (rval); } /* Check again */ attr = ISNSFindKeyInResponseMsg ( ISNS_ENTITY_ID, p_rspmsg ); if ( attr == NULL ) { __DEBUG ( isns_reg_debug & 1, (Error Creating entity) ); return ( ISNS_UNKNOWN_ERR ); } } strncpy(db_entity.id, (char *)&attr->val, sizeof(db_entity.id) ); } /* Create a new node entry */ memset ( &entry, 0, sizeof (SOIP_DB_Entry) ); strncpy ( p_node->id.v, db_node_name.v, sizeof(p_node->id.v) ); p_node->iscsi_id_len = PAD4(strlen(p_node->id.v)); p_node->iscsi_index = ISNSGetNewISCSIIdx(); SOIP_ISCSI_Node_Id *p_idx; memset (&entry3, 0, sizeof(SOIP_ISCSI_Node_Id)); p_idx = &entry3.data.iscsi_idx; __ISNS_COPY (p_idx, sizeof(entry3.data.iscsi_idx), &p_node->id.v, sizeof(SOIP_ISCSI_Node_Id)); rval = write_ISCSIidxObject(p_node->iscsi_index, entry3); strncpy ( p_node->entity_id.id, db_entity.id, sizeof(p_node->entity_id.id) ); InitList(ISCSI_DD_LIST, p_node ); /* Setup for an entity fetch */ __DEBUG ( isns_reg_debug &1,call read_EntityObject:%s,db_entity.id); if ( SUCCESS != read_EntityObject (db_entity.id, &p_entity, &entry2) ) { return ( ISNS_INVALID_REG_ERR ); } if ( p_entity->eid_type != ENTITY_TYPE_ISCSI ) { __DEBUG( isns_reg_debug & 1, (Entity is not ISCSI type: %d), p_entity->eid_type ); return ( ISNS_UNKNOWN_ERR ); } __DEBUG (isns_reg_debug &1,iscsi_node_count:%i,p_entity->iscsi_node_list.node_count); /* Insert into iscsi_node_list */ if (!FindNode( &p_entity->iscsi_node_list, p_node->id.v, PAD4(strlen (p_node->id.v)) )) { AddNode( &p_entity->iscsi_node_list, p_node->id.v, PAD4(strlen (p_node->id.v)) ); } p_node->entity_index = p_entity->entity_index; newIscsiNodeFlag = TRUE; /* Check if member of a Domain */ Check_if_member_of_DD (p_node->id.v); } memset( p_scn_all_msg_buffer, 0, sizeof(ISNS_Msg)); p_scn_all_msg_buffer->hdr.type = ISNS_SCN; ISNSAppendKey( p_scn_all_msg_buffer, ISNS_ISCSI_NODE_ID, p_node->iscsi_id_len, p_node->id.v, 0 ); updateFlag = FALSE; stopFlag = FALSE; for (ii = saveIndex; (ii < SNS_MAX_ATTRS) && (attr_indx[ii]) && !stopFlag; ii++) { attr = (ISNS_Attr *) attr_indx[ii]; switch ( attr->tag ) { case ISNS_ISCSI_NODE_ID: { stopFlag = TRUE; saveIndex = ii; break; } case ISNS_ISCSI_TYPE: { if ( p_node->type != *(uint32_t *)&attr->val ) { p_node->type = *(uint32_t *)&attr->val; ISNSAppendKey( p_scn_all_msg_buffer, ISNS_ISCSI_TYPE, ISNS_ISCSI_TYPE_SIZE, NULL, p_node->type ); updateFlag = TRUE; } break; } case ISNS_ISCSI_ALIAS: { safe_len = MIN( strlen(p_node->alias), attr->len ); if ( !memcmp(p_node->alias, &attr->val, safe_len ) ) { strncpy( p_node->alias, (char *)&attr->val, sizeof(p_node->alias) ); p_node->alias_len = safe_len; ISNSAppendKey( p_scn_all_msg_buffer, ISNS_ISCSI_ALIAS, PAD4(strlen(p_node->alias)), p_node->alias, 0); updateFlag = TRUE; } break; } case ISNS_ISCSI_SCN_BITMAP: { if (p_node->scn_bitmap!=*(uint32_t *)&attr->val) { p_node->scn_bitmap = *(uint32_t *)&attr->val; ISNSAppendKey( p_scn_all_msg_buffer, ISNS_ISCSI_SCN_BITMAP, ISNS_SCN_BITMAP_SIZE, NULL, p_node->scn_bitmap ); updateFlag = TRUE; } if ( p_md->cb.sock.socketType == ISNS_SOCKET_TYPE_TCP ) { p_node->scn_sockfd = p_md->cb.sock.sockfd; } else { p_node->scn_sockfd = 0; } break; } case ISNS_ISCSI_CERT: { AddCert (&p_node->ptr_cert, (int *)&p_node->cert_size, &attr->val, attr->len); break; } default: break; } } /* Activate DD Membership */ Activate_DD_Membership ( ISNS_DD_ISCSI_MEMBER, p_node ); /* Store iSCSI Node Entry */ rval = write_ISCSIObject(p_node->id.v, entry); if ( newIscsiNodeFlag ) { iSNS_stats.num_iscsi++; ISNSAppendKey ( p_rspmsg, ISNS_ISCSI_NODE_ID, PAD4 (strlen (p_node->id.v)), p_node->id.v, 0 ); /* Store Entity */ rval = write_EntityObject(db_entity.id, entry2); } if ( newIscsiNodeFlag ) send_iscsi_scn_to_members ( p_node, NULL, p_scn_all_msg_buffer, ISNS_SCN_OBJ_ADDED ); else if ( updateFlag ) send_iscsi_scn_to_members ( p_node, NULL, p_scn_all_msg_buffer, ISNS_SCN_OBJ_UPDATED ); /* Decide on Looping */ attr = (ISNS_Attr *) ( attr_indx[ saveIndex ] ); if ( attr && attr->tag == ISNS_ISCSI_NODE_ID ) continue; else break; } return ( ISNS_NO_ERR ); } /********************************************************************* Registers a SCN. *********************************************************************/ int ISNS_RegisterSCN ( ISNS_Msg_Descp * p_md, ISNS_Msg * rspmsg) { int rval; int ii; int iscsiKeyIndex; int entityKeyIndex; int ifcpKeyIndex; int scn_bitmap_index; ISNS_Key *key; SOIP_Iscsi *p_node; SOIP_Ifcp *p_ifcp_node; SOIP_ISCSI_Node_Id db_node_name; SOIP_Entity *p_entity = NULL; ISNS_LIST_NODE *pnode = NULL; ISNS_Attr *src_attr; ISNS_Attr *attr_indx[SNS_MAX_ATTRS]; ISNS_Attr *key_indx[SNS_MAX_ATTRS]; SOIP_Portal_Key *db_portal; __DEBUG (isns_reg_debug &1,(RegisterSCN)); ISNSParseMsg( &p_md->msg, attr_indx, key_indx, &src_attr ); /* Validate the src attr for Permission */ /* Scan the keys */ iscsiKeyIndex = -1; ifcpKeyIndex = -1; entityKeyIndex = -1; for (ii = 0; ii < MAX_PARSE_ATTRS && key_indx[ ii ]; ii++) { key = (ISNS_Key *)(key_indx[ ii ]); switch ( key->tag ) { case ISNS_ISCSI_NODE_ID: iscsiKeyIndex = ii; break; case ISNS_PORT_NAME: ifcpKeyIndex = ii; break; default: break; } } if ( iscsiKeyIndex != -1 ) { key = (ISNS_Key *)(key_indx[ iscsiKeyIndex ]); /* Fetch the node */ memset (&db_node_name, 0, sizeof (db_node_name)); strncpy ((char *) db_node_name.v, (char *) &key->val, sizeof(db_node_name.v) ); rval = read_ISCSIObject(db_node_name.v, &p_node, &entry); if (rval != SUCCESS) return rval; scn_bitmap_index = ISNSFindTag (0, ISNS_ISCSI_SCN_BITMAP, attr_indx); if (scn_bitmap_index == -1) { __DEBUG (isns_reg_debug & 1, (No SCN Bitmap in request)); return (ISNS_SCN_REG_REJECTED_ERR); } key = (ISNS_Key *)(attr_indx[scn_bitmap_index]); p_node->scn_bitmap=*(uint32_t *)&key->val; if ( p_md->cb.sock.socketType == ISNS_SOCKET_TYPE_TCP ) { /* Use TCP for SCN */ p_node->scn_sockfd = p_md->cb.sock.sockfd; __DEBUG (isns_reg_debug &1,(SCN sockfd = %#x),p_md->cb.sock.sockfd); } else { /* Find a UDP port for SCN */ int foundSCNPortal; SOIP_Portal *p_portal; p_node->scn_sockfd = 0; /* Scan Portals */ /* Fetch entity */ read_EntityObject (p_node->entity_id.id, &p_entity, &entry2); /* Fetch portal */ foundSCNPortal = FALSE; pnode = NULL; while ( (pnode = GetNextNode(&p_entity->iportal_list, pnode)) != NULL) { db_portal = GetNodeData(pnode); rval = read_PortalObject(db_portal, &p_portal, &entry3); if (rval != SUCCESS) return rval; /* Get first ESI/SCN Portal */ if (p_portal->esi_port != 0) { foundSCNPortal = TRUE; break; } } /* Send out SCN */ if (!foundSCNPortal) { __DEBUG (isns_reg_debug & 1, (No portals to send out SCN)); return (ISNS_SCN_REG_REJECTED_ERR); } } /* Store the node */ write_ISCSIObject(db_node_name.v, entry); return (ISNS_NO_ERR); } else if (ifcpKeyIndex != -1) { key = (ISNS_Key *)(key_indx[ ifcpKeyIndex ]); rval = read_FCPortObject((char *)&key->val, &p_ifcp_node, &entry); if (rval != SUCCESS) return rval; scn_bitmap_index = ISNSFindTag (0, ISNS_IFCP_SCN_BITMAP, attr_indx); if (scn_bitmap_index == -1) { __DEBUG (isns_reg_debug & 1, (No SCN Bitmap in request)); return ( ISNS_SCN_REG_REJECTED_ERR ); } key = (ISNS_Key *)(attr_indx[scn_bitmap_index]); p_ifcp_node->scn_bitmap=*(uint32_t *)&key->val; if (p_md->cb.sock.socketType == ISNS_SOCKET_TYPE_TCP) { p_ifcp_node->scn_sockfd = p_md->cb.sock.sockfd; } else { p_ifcp_node->scn_sockfd = 0; } /* Store the node */ write_FCPortObject((char *)&key->val, entry); return ( ISNS_NO_ERR ); } else { __DEBUG (isns_reg_debug & 1, (No valid key in SCN request)); return ( ERROR ); } return ( ERROR ); } int Check_if_member_of_DD (char * id) { return SUCCESS; } /********************************************************************* _Add_DD_to_ISCSI_Node Adds the DD to the iSCSI Node's DD list. *********************************************************************/ int Add_DD_to_ISCSI_Node (SOIP_Dd *p_dd, char *p_node_name) { SOIP_DB_Entry lentry; SOIP_Iscsi *p_node; int id; int rval; __DEBUG (isns_reg_debug &1,(ISCSI_Node:%s),p_node_name); id = p_dd->id; rval = read_ISCSIObject(p_node_name, &p_node, &lentry); if (rval != SUCCESS) return rval; if (!FindNode(&p_node->dd_id_list, (char *)&id, sizeof(id))) { AddNode(&p_node->dd_id_list, (char *)&id, sizeof(id)); } if ( p_dd->activeFlag ) p_node->activeFlag = TRUE; rval = write_ISCSIObject(p_node_name, lentry); return ( ISNS_NO_ERR ); } /********************************************************************* _Add_DD_to_IFCP_Node Add the DD to the iFCP's DD list. *********************************************************************/ int Add_DD_to_IFCP_Node (int id, char *p_node_name) { SOIP_Ifcp *p_node; SOIP_DB_Entry lentry; int rval; rval = read_FCPortObject(p_node_name, &p_node, &lentry); if (rval != SUCCESS) return rval; if (!FindNode(&p_node->dd_id_list, (char *) &id, sizeof(id))) { AddNode(&p_node->dd_id_list, (char *)&id, sizeof(id)); } rval = write_FCPortObject(p_node_name, lentry); return (ISNS_NO_ERR); } /********************************************************************* _Add_dds_to_dd This will add a DDS to the DD's DDS list. Keep in mind that each DD maintains a list of DDS. *********************************************************************/ int Add_dds_to_dd (SOIP_Dds *p_dds, int dd_id) { SOIP_DB_Entry lentry; SOIP_Dd *p_dd; int rval; __DEBUG (isns_reg_debug &1, Add_dds_to_dd ); rval = read_DDObject(dd_id, &p_dd, &lentry); if (rval != SUCCESS) return rval; if (!FindNode(&p_dds->dd_list, (char *) &dd_id, sizeof(dd_id))) { AddNode(&p_dds->dd_list, (char *) &dd_id, sizeof(dd_id)); } if ( p_dds->status && !p_dd->activeFlag ) { p_dd->activeFlag = TRUE; } if (!FindNode(&p_dd->dds_list, (char *) &p_dds->id, sizeof(p_dds->id))) { AddNode(&p_dd->dds_list, (char *) &p_dds->id, sizeof(p_dds->id)); } write_DDObject(dd_id, lentry); return ( ISNS_NO_ERR ); } /********************************************************************* _Check_Unique_DDS_Sym Checks for a unique DDS symbolic name. *********************************************************************/ int Check_Unique_DDS_Sym (SOIP_Dds * p_dds, char *p_sym_name) { SOIP_DB_Entry lentry; SOIP_Dds *p_dds2; int rval; ISNS_DBKey key = { 0 }; key.tag = DDS_ID_KEY; while (SNSdbGetNextOfKey (&key) == SUCCESS) { if (key.val.dd_key.id == p_dds->id) continue; rval = read_DDSObject(p_dds->id, &p_dds2, &lentry); if (rval != SUCCESS) return (rval); if (0 == strcmp (p_dds2->sym_name, p_sym_name)) { return (FALSE); } } return (TRUE); } /********************************************************************* _ISNS_GetNewDD_ID Gets a new unique DD ID. *********************************************************************/ int ISNS_GetNewDD_ID ( void ) { static int current_ID = 0; SOIP_DB_Entry lentry; int rval; SOIP_Dd *p_dd; do { current_ID++; rval = read_DDObject(current_ID, &p_dd, &lentry); } while ( rval == SUCCESS); return (current_ID); } /********************************************************************* _Check_Unique_DD_Sym Checks for a unique DD name. RETURNS: Return TRUE if sym name is unique. *********************************************************************/ int Check_Unique_DD_Sym (SOIP_Dd * p_dd, char *p_sym_name) { SOIP_DB_Entry lentry; SOIP_Dd *p_dd2; int rval; ISNS_DBKey key = { 0 }; /* retrieve all DD */ key.tag = DD_ID_KEY; while (SNSdbGetNextOfKey (&key) == SUCCESS) { if (key.val.dd_key.id == p_dd->id) continue; rval = read_DDObject(key.val.dd_key.id, &p_dd2, &lentry); if (rval != SUCCESS) return rval; if (0 == strcmp (p_dd2->sym_name, p_sym_name)) { return (FALSE); } } return (TRUE); } /******************************************************************** ********************************************************************/ int ISNSAddSCNCallbackEntry ( char *nodename, int type, int bitmap, void (*cfunc)(ISNS_ATTR_VALS_CB *avcb_ptr) ) { SOIP_Scn_Callback_Entry new_entry; memset( &new_entry, 0, sizeof( new_entry ) ); if ( ISNS_PORT_NAME == type ) { __ISNS_COPY (new_entry.name.v, sizeof(new_entry.name.v), nodename, ISNS_PORT_NAME_SIZE ); } else if ( ISNS_ISCSI_NODE_ID == type ) { strncpy( new_entry.name.v, nodename, sizeof(new_entry.name.v) ); } else if ( ISNS_ENTITY_ID == type ) { strncpy( new_entry.name.v, nodename, sizeof(new_entry.name.v) ); } else { __DEBUG( isns_reg_debug & 1, (SCN node type wrong: %d), type ); return ( ERROR ); } new_entry.type = type; new_entry.scn_callback_func = cfunc; new_entry.bitmap = bitmap; if ( NULL == FindNode( &scn_callback_list, (char *)&new_entry, sizeof(new_entry)) ) { AddNode( &scn_callback_list, (char *)&new_entry, sizeof(new_entry) ); } return ( SUCCESS ); } /************************************************** **************************************************/ int ISNS_RegisterSCNCallback ( ISNS_Msg_Descp *p_md) { int rval; int bitmapIdx; int cbIdx; void *func; ISNS_Attr *attr; ISNS_Attr *attr_indx[SNS_MAX_ATTRS]; ISNS_Attr *key_indx[SNS_MAX_ATTRS]; ISNSParseMsg( &p_md->msg, attr_indx, key_indx, NULL ); if ( key_indx[0] == NULL ) { __DEBUG( isns_reg_debug & 1, (Missing key) ); return ( ERROR ); } if (-1 == (bitmapIdx = ISNSFindTag(0, ISNS_ISCSI_SCN_BITMAP, attr_indx))) { __DEBUG( isns_reg_debug & 1, (Missing key) ); return ( ERROR ); } if (-1 == (cbIdx = ISNSFindTag(0, ISNS_SCN_CALLBACK, attr_indx))) { __DEBUG( isns_reg_debug & 1, (Missing key) ); return ( ERROR ); } attr = (ISNS_Attr *)attr_indx[ cbIdx ]; func = attr->val.scn_callback; rval = ISNSAddSCNCallbackEntry((char *)&((ISNS_Key *)key_indx[ 0 ])->val, ((ISNS_Key *)key_indx[ 0 ])->tag, ((ISNS_Key *)key_indx[ bitmapIdx ])->tag, func); return (rval); } /********************************************************************* _AddCert Allocates space and copies the cert. *********************************************************************/ int AddCert (void **ptr, int *size, void *p_cert, int cert_size) { if (*ptr) { ISNSFreeBuffer (*ptr); *ptr = NULL; } *size = cert_size; *ptr = (void *)ISNSAllocBuffer (cert_size); memcpy (*ptr, p_cert, *size); return (SUCCESS); } /********************************************************************* Actives a DD membership. A DD member can be inactive when it is deleted. When the member is reregistered, this function is called to reactivate it. *********************************************************************/ int Activate_DD_Membership (uint32_t type, void *p_node) { SOIP_DB_Entry lentry; SOIP_Dd *p_dd; ISNS_DBKey key = { 0 }; ISNS_LIST_NODE *pnode; SOIP_Dd_Member *p_member; SOIP_Iscsi *p_iscsi = NULL; SOIP_Ifcp *p_ifcp = NULL; uint32_t index; char *p_node_name; ISNS_LIST *ddlist; int memberAddedFlag; int rval; __DEBUG (isns_reg_debug &1,Activate_DD_Membership); /* Get First DD Entry */ key.tag = DD_ID_KEY; key.len = 0; switch ( type ) { case ISNS_DD_ISCSI_MEMBER: p_iscsi = (SOIP_Iscsi *) p_node; p_node_name = p_iscsi->id.v; ddlist = &p_iscsi->dd_id_list; index = p_iscsi->iscsi_index; break; case ISNS_DD_IFCP_MEMBER: p_ifcp = (SOIP_Ifcp *) p_node; p_node_name = (char *)&p_ifcp->port_name; ddlist = &p_ifcp->dd_id_list; index = p_ifcp->ifcp_index; break; default: __LOG_ERROR ("Activate_DD_Membership(): Unknown type =%u.", type); return (ERROR); break; } /* Loop */ memberAddedFlag = FALSE; while ( SNSdbGetNextOfKey ( &key ) == SUCCESS ) { rval = read_DDObject(key.val.dd_key.id, &p_dd, &lentry); if (rval != SUCCESS) return rval; /* Find iSCSI Node */ pnode = NULL; while ( (pnode=GetNextNode(&p_dd->member_list, pnode)) ) { p_member=(SOIP_Dd_Member *)GetNodeData( pnode ); if (p_member->type != type) continue; if (type == ISNS_DD_ISCSI_MEMBER && 0 != strcmp ( p_member->node_id, p_node_name )) continue; if (type == ISNS_DD_IFCP_MEMBER && 0 != memcmp ( p_member->node_id, p_node_name, 8)) continue; /* Add to iSCSI Node's DD List */ if (!FindNode( ddlist, (char *)&p_dd->id, sizeof(p_dd->id) )) { AddNode( ddlist, (char *)&p_dd->id, sizeof(p_dd->id) ); } /* Active DD's Node Membership */ p_member->status = ISNS_DD_MEMBER_ENABLE; p_member->node_idx = index; switch ( type ) { case ISNS_DD_ISCSI_MEMBER: Add_DD_Member(p_dd,p_iscsi->id.v,PAD4(strlen(p_iscsi->id.v)),ISNS_DD_ISCSI_MEMBER,ISNS_DD_MEMBER_ENABLE,p_iscsi->iscsi_index); break; default: break; } if ( p_dd->activeFlag ) { switch ( type ) { case ISNS_DD_ISCSI_MEMBER: p_iscsi->activeFlag = TRUE; break; case ISNS_DD_IFCP_MEMBER: p_ifcp->activeFlag = TRUE; break; default: break; } } memberAddedFlag = TRUE; ISNSAppendKey( p_scn_all_msg_buffer, ISNS_DD_ID, ISNS_DD_ID_SIZE, NULL, p_dd->id); switch ( type ) { case ISNS_DD_ISCSI_MEMBER: ISNSAppendKey( p_scn_all_msg_buffer, ISNS_ISCSI_NODE_ID, PAD4(strlen(p_member->node_id)), (char *)p_member->node_id, 0); ISNSAppendKey( p_scn_all_msg_buffer, ISNS_ISCSI_SCN_BITMAP, ISNS_SCN_BITMAP_SIZE, NULL, ISNS_SCN_MEMBER_ADDED); break; case ISNS_DD_IFCP_MEMBER: ISNSAppendKey( p_scn_all_msg_buffer, ISNS_PORT_NAME, ISNS_PORT_NAME_SIZE, (char *)p_member->node_id, 0); ISNSAppendKey( p_scn_all_msg_buffer, ISNS_IFCP_SCN_BITMAP, ISNS_SCN_BITMAP_SIZE, NULL, ISNS_SCN_MEMBER_ADDED); break; default: break; } /* Store Entry */ write_DDObject(p_dd->id,lentry); break; } } if ( memberAddedFlag ) { send_iscsi_scn_to_members ( p_node, NULL, p_scn_all_msg_buffer, ISNS_SCN_OBJ_ADDED ); } else { Add_ISCSINode_Default_DD (p_node); switch ( type ) { case ISNS_DD_ISCSI_MEMBER: p_iscsi->activeFlag = TRUE; break; case ISNS_DD_IFCP_MEMBER: p_ifcp->activeFlag = TRUE; break; } } return ( SUCCESS ); } #if 0 /************************************************** This will reregister SCN when a connection drops **************************************************/ int ISNS_Re_Reg_SCN(void) { ISNS_LIST_NODE *lnode; SOIP_Scn_Callback_Entry *pdata; if (IsEmptyList(&scn_callback_list)) return (SUCCESS); memset(p_scn_md, 0, sizeof(ISNS_Msg_Descp)); p_scn_md->msg.hdr.type = ISNS_SCN_REG_REQ; p_scn_md->msg.hdr.xid = ISNSGetXID(); lnode = NULL; lnode = GetNextNode(&scn_callback_list, lnode); while (lnode) { p_scn_md->msg.hdr.msg_len = 0; pdata = (SOIP_Scn_Callback_Entry *)GetNodeData(lnode); __DEBUG( isns_reg_debug & 1, (Sending SCN re-reg msg node = %s), pdata->name.v); /* SRC */ ISNSAppendKey(&p_scn_md->msg, 0, 0, NULL, 0); /* Key */ ISNSAppendKey(&p_scn_md->msg, ISNS_ISCSI_NODE_ID, PAD4(strlen(pdata->name.v)), pdata->name.v, 0); ISNSAppendKey(&p_scn_md->msg, ISNS_DELIMITER, ISNS_DELIMITER_SIZE, NULL, 0); /* Attr */ ISNSAppendKey(&p_scn_md->msg, ISNS_ISCSI_SCN_BITMAP, ISNS_SCN_BITMAP_SIZE, NULL, pdata->bitmap); ISNSSendMsg2Server(&p_scn_md->msg); lnode = GetNextNode(&scn_callback_list, lnode); } return (SUCCESS); } #endif /********************************************************************* *********************************************************************/ int change_dd_member_active_flag( SOIP_Dd *p_dd ) { ISNS_LIST_NODE *lnode; ISNS_LIST_NODE *lnode2; SOIP_Dd_Member *p_member; SOIP_DB_Entry lentry; uint32_t activeFlag; SOIP_Iscsi *p_node; SOIP_ISCSI_Node_Id db_node_name; uint32_t old_activeFlag; int rval; /* For each dd member */ lnode = NULL; while ( (lnode = GetNextNode(&p_dd->member_list, lnode)) ) { p_member = (SOIP_Dd_Member *) GetNodeData(lnode); if (!p_member->type || p_member->status == ISNS_DD_MEMBER_DISABLE) continue; switch (p_member->type) { case ISNS_DD_ISCSI_MEMBER: /* Fetch the node */ memset (&db_node_name, 0, sizeof (db_node_name)); strncpy ((char *) db_node_name.v, p_member->node_id, sizeof(db_node_name.v) ); rval = read_ISCSIObject(db_node_name.v, &p_node, &lentry); if (rval != SUCCESS) return rval; old_activeFlag = p_node->activeFlag; if ( p_dd->activeFlag ) { p_node->activeFlag = TRUE; } else { lnode2 = NULL; activeFlag = FALSE; while ( (lnode2 = GetNextNode(&p_node->dd_id_list, lnode2)) ) { if (IsDDActive( *(uint32_t *)GetNodeData( lnode2 ), 0 )) { activeFlag = TRUE; break; } } p_node->activeFlag = activeFlag; } if (old_activeFlag != p_node->activeFlag) { write_ISCSIObject(db_node_name.v, lentry); } break; case ISNS_DD_IFCP_MEMBER: __LOG_ERROR("change_dd_member_active_flag(): IFCP not implemented."); break; default: __LOG_ERROR("change_dd_member_active_flag(): Unknown type = %u.", p_member->type); break; } } return (SUCCESS); } /********************************************************************* *********************************************************************/ int ISNS_GetDD_ID_from_sym ( char *p_sym ) { SOIP_DB_Entry lentry; SOIP_Dd *p_dd; ISNS_DBKey qkey = { 0 }; int rval; if ( p_sym ) { memset(&qkey, 0, sizeof(qkey)); qkey.tag = DD_ID_KEY; while (SNSdbGetNextOfKey (&qkey) == SUCCESS) { /* If a symbolic name is given, search for any entries that has that dd, return that DD */ rval = read_DDObject(qkey.val.dd_key.id, &p_dd, &lentry); if (rval != SUCCESS) return 0; if (0 == strcmp(p_dd->sym_name, p_sym)) return ( p_dd->id ); } } return (0); } /********************************************************************* _Copy_DD_List: This will copy the DD_List to static array. *********************************************************************/ int Copy_DD_List(ISNS_LIST *dd_list, ISNS_DD_LIST p_dlist) { ISNS_LIST_NODE *pnode; int index; index=0; pnode=NULL; while ((pnode=GetNextNode(dd_list, pnode))) { p_dlist[index]=*(uint32_t *)GetNodeData(pnode); index++; } return (SUCCESS); } /********************************************************************* _ISNS_GetDDS_ID_from_sym Gets a new unique DDS ID. *********************************************************************/ int ISNS_GetDDS_ID_from_sym (char *p_sym) { SOIP_DB_Entry lentry; SOIP_Dds *p_dds; ISNS_DBKey qkey = { 0 }; int rval; if ( p_sym ) { memset(&qkey, 0, sizeof(qkey)); qkey.tag = DDS_ID_KEY; while (SNSdbGetNextOfKey (&qkey) == SUCCESS) { rval = read_DDSObject(qkey.val.dds_key.id, &p_dds, &lentry); if ( rval != SUCCESS) return (0); if (0 == strcmp (p_dds->sym_name, p_sym)) return (p_dds->id); } } return ( 0 ); } /********************************************************************* _ISNS_GetNewDDS_ID Gets a new unique DDS ID. *********************************************************************/ int ISNS_GetNewDDS_ID (void) { static int currentDDS_ID = 0; SOIP_DB_Entry lentry; SOIP_Dds *p_dds; int rval; do { currentDDS_ID++; rval = read_DDSObject(currentDDS_ID, &p_dds, &lentry); } while ( rval == SUCCESS); return (currentDDS_ID); } /********************************************************************* Appends a DD to a DD list. Checks to make sure there aren't duplicate entries. *********************************************************************/ int Append_DD_to_List (ISNS_DD_LIST p_dlist, uint32_t id) { int ii; __DEBUG (isns_reg_debug &1,(Append_DD_to_List id=%i),id); for (ii = 0; ii < MAX_DD_PER_LIST; ii++) { if (p_dlist[ii] == 0) { p_dlist[ii] = id; return (ISNS_NO_ERR); } else if (p_dlist[ii] == id) { return (ISNS_NO_ERR); } } return (ERROR); } /********************************************************************* Appends a DD member to a list. *********************************************************************/ int append_to_member_list (SOIP_Dd_Member *p_ddmem, char *p_nodename, int type) { int ii; int freeSlot = -1; for (ii = 0; ii < MAX_MEMBER_PER_DD; ii++) { if (p_ddmem[ii].type==0) { freeSlot = ii; break; } if (memcmp (p_ddmem[ii].node_id, p_nodename, p_ddmem[ii].type == ISNS_DD_IFCP_MEMBER ? 8 : PAD4 (strlen (p_nodename))) == 0) { /* Duplicate */ return (ISNS_NO_ERR); } } if (freeSlot == -1) { __LOG_ERROR ("***ERROR: No free spots found in list."); return (ERROR); } else { /* Add Node to list */ memset (p_ddmem[freeSlot].node_id, 0, sizeof (p_ddmem[freeSlot].node_id)); p_ddmem[freeSlot].type = type; memcpy (p_ddmem[freeSlot].node_id, p_nodename, p_ddmem[freeSlot].type == ISNS_DD_IFCP_MEMBER ? 8 : PAD4 (strlen (p_nodename))); } return (ISNS_NO_ERR); } /********************************************************************* Appends the active nodes from a DD List. *********************************************************************/ int Append_Nodes_From_DD_List (ISNS_DD_LIST p_dlist, SOIP_Dd_Member p_ddmem[], uint32_t type) { int ii; SOIP_Dd *p_dd; SOIP_DB_Entry lentry; ISNS_LIST_NODE *pnode; int rval; __DEBUG (isns_reg_debug &1,(Append_Nodes_From_DD_List)); for (ii = 0; ii < MAX_DD_PER_LIST && p_dlist[ii]!=0; ii++) { __DEBUG (isns_reg_debug &1,(Append Node - dd:%i),p_dlist[ii]); rval = read_DDObject(p_dlist[ii], &p_dd, &lentry); if (rval != SUCCESS) return rval; pnode=NULL; while ((pnode=GetNextNode(&p_dd->member_list, pnode))) { SOIP_Dd_Member *p_member; p_member=(SOIP_Dd_Member *)GetNodeData(pnode); if (p_member->status == ISNS_DD_MEMBER_ENABLE && (type == 0 || p_member->type == type)) { __DEBUG (isns_reg_debug &1,(Append member to list)); append_to_member_list (p_ddmem, p_member->node_id, p_member->type); } } } return (ISNS_NO_ERR); } /********************************************************************* *********************************************************************/ int Create_Default_DD () { SOIP_DB_Entry lentry1; SOIP_DB_Entry lentry2; SOIP_Dd *p_dd = NULL; SOIP_Dds *p_dds = NULL; ISNS_DBKey dds_key = { 0 }; ISNS_DBKey dd_key = { 0 }; int rval; int found; __DEBUG (isns_reg_debug &1,Create Default Domains and Domain Sets); /* check if default DDS exists, if not create it */ dds_key.tag = DDS_ID_KEY; found = FALSE; while ( SNSdbGetNextOfKey ( &dds_key ) == SUCCESS ) { rval = read_DDSObject(dds_key.val.dds_key.id, &p_dds, &lentry1); if (rval != SUCCESS) return rval; if ( !strcmp("default DDS",p_dds->sym_name) ) { found = TRUE; } } if (!found) { __DEBUG (isns_reg_debug &1, Create Default DDS); dds_key.val.dds_key.id = ISNS_GetNewDDS_ID (); p_dds = (SOIP_Dds *)&lentry1.data; p_dds->id = dds_key.val.dds_key.id; strcpy(p_dds->sym_name,"default DDS"); InitList(DDS_DD_LIST, p_dds); p_dds->status = 1; rval = write_DDSObject(dds_key.val.dds_key.id, lentry1); __DEBUG (isns_reg_debug &1,Create Default DDS rval:%i,rval); } /* check if default DD exists, if not create it */ dd_key.tag = DD_ID_KEY; found = FALSE; while ( SNSdbGetNextOfKey ( &dd_key ) == SUCCESS ) { rval = read_DDObject(dd_key.val.dd_key.id, &p_dd, &lentry2); if (rval != SUCCESS) return rval; if ( !strcmp("default DD",p_dd->sym_name) ) { found = TRUE; } } if (!found) { __DEBUG (isns_reg_debug &1, Create Default DD); p_dd = (SOIP_Dd *)&lentry2.data; dd_key.val.dd_key.id = ISNS_GetNewDD_ID(); p_dd->id = dd_key.val.dd_key.id; strcpy(p_dd->sym_name,"default DD"); InitList(DD_MEMBER_LIST, p_dd); InitList(DD_DDS_LIST, p_dd); p_dd->activeFlag = p_dds->status; rval = write_DDObject(dd_key.val.dd_key.id, lentry2); __DEBUG (isns_reg_debug &1,Create Default DD rval:%i,rval); /* Add DD to DDS */ Add_dds_to_dd (p_dds,p_dd->id); rval = write_DDSObject(dds_key.val.dds_key.id, lentry1); } return SUCCESS; } static int Add_ISCSINode_Default_DD (SOIP_Iscsi *p_node) { SOIP_DB_Entry lentry2; SOIP_Dd *p_dd = NULL; ISNS_DBKey dd_key = { 0 }; int rval; int found; rval = 0; dd_key.tag = DD_ID_KEY; found = FALSE; while ( SNSdbGetNextOfKey ( &dd_key ) == SUCCESS ) { rval = read_DDObject(dd_key.val.dd_key.id, &p_dd, &lentry2); if (rval != SUCCESS) return rval; if ( !strcmp("default DD",p_dd->sym_name) ) { found = TRUE; break; } } if (found) { if (!FindNode(&p_node->dd_id_list, (char *)&p_dd->id, sizeof(p_dd->id))) { AddNode(&p_node->dd_id_list, (char *)&p_dd->id, sizeof(p_dd->id)); } if ( p_dd->activeFlag ) p_node->activeFlag = TRUE; Add_DD_Member(p_dd,p_node->id.v,PAD4(strlen(p_node->id.v)),ISNS_DD_ISCSI_MEMBER,ISNS_DD_MEMBER_ENABLE,p_node->iscsi_index); rval = write_DDObject(dd_key.val.dd_key.id, lentry2); } return SUCCESS; } /********************************************************************* *********************************************************************/ int Check_Authorization (ISNS_Attr *src_attr) { __DEBUG (isns_reg_debug &1,Check_Authorization:%s,src_attr->val.node_name.v); if ( 0 == strcmp (src_attr->val.node_name.v,isns_control_node) ) return SUCCESS; else return ISNS_AUTH_FAILED_ERR; } isns-2.1-01/isnsserver/src/iSNSscn.c0000644000175000017500000003733210665040341016243 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This file contains source code for managing the SCN - state change notification. * */ #include "iSNS.h" #include "iSNSdb.h" #include "iSNSobjects.h" #include "iSNStypes.h" #include "iSNSmsg.h" #include "iSNScomm.h" #include "iSNSbuffer.h" #include "iSNStbl.h" #include "iSNSList.h" #include "iSNSparse.h" #include "iSNSquery.h" #include "iSNSresponse.h" #include "iSNSreg.h" #include "iSNSdebug.h" /* Global */ extern int isns_scn_msg_filter; extern int isns_rsync_debug; extern ISNS_LIST scn_list; extern ISNS_LIST scn_callback_list; extern ISNS_Msg *p_scn_msg_buffer; extern ISNS_Msg *p_scn_all_msg_buffer; extern ISNS_Msg_Descp *p_scn_md; extern ISNS_Msg_Descp *p_rspMd; extern dbStats iSNS_stats; extern int sns_scn_debug; extern int sns_cb_debug; extern int sns_cb_msg_filter; extern int sns_scn_msg_filter; extern int sns_rsync_debug; extern int SNSGetMgmtAddr (void); extern int sns_esi_interval; extern uint32_t *dlist_src; /*[MAX_DD_PER_LIST];*/ extern uint32_t *dlist_node; /*[MAX_DD_PER_LIST];*/ extern SOIP_Dd_Member *ddmem; /* [100]; */ /* * static common variables for gdbm fetches * entry is for common registrations and queries * scn_entry is for state change notifications * opn_entry is for access control */ static SOIP_DB_Entry scn_entry; static SOIP_DB_Entry scn_entry2; static SOIP_DB_Entry scn_entry3; static ISNS_ATTR_VALS_CB * ISNSAttrGetList (ISNS_Msg_Descp *p_md); static void* SNSAttrGetAttrValLocation (ISNS_Attr *sns_attr); /********************************************************************* *********************************************************************/ static int send_iscsi_scn_md(char *p_node_name, ISNS_Msg_Descp *p_md) { int foundSCNPortal; SOIP_DB_Entry lentry; SOIP_DB_Entry lentry2; SOIP_Iscsi *p_node; SOIP_Entity *p_entity; SOIP_Portal *p_portal = NULL; ISNS_LIST_NODE *lnode; ISNS_ATTR_VALS_CB *attr_vals_cb; int rval; if ( p_node_name == NULL) return (ERROR); rval = read_ISCSIObject(p_node_name, &p_node, &lentry); if (rval != SUCCESS) return rval; if (!p_node->scn_bitmap) return (SUCCESS); /* Determine how to send */ if ( p_node->scn_callback ) { /* exec callback */ /* notify local devices of SCN */ attr_vals_cb = ISNSAttrGetList(p_md); if (attr_vals_cb != NULL) { p_node->scn_callback(attr_vals_cb); } ISNSFreeBuffer ((char *)attr_vals_cb->attr_val_sptr); ISNSFreeBuffer ((char *)attr_vals_cb); } else if ( p_node->scn_sockfd ) { /* TCP */ p_md->cb.sock.socketType = ISNS_SOCKET_TYPE_TCP; p_md->cb.sock.sockfd = p_node->scn_sockfd; if ( SUCCESS != ISNSSendMsg (p_md) ) { __DEBUG(sns_scn_debug & 1, (Warning: Failure sending SCN)); p_node->scn_bitmap = 0; write_ISCSIObject(p_node_name, lentry); } } else { /* UDP */ char buffer[256]={0}; /* Pick a portal, send out a SCN */ /* Fetch entity */ memset (buffer, 0, sizeof (buffer)); strncpy (buffer, p_node->entity_id.id, sizeof(buffer)); read_EntityObject (buffer, &p_entity, &lentry); /* Fetch portal */ foundSCNPortal = FALSE; lnode = NULL; while ((lnode=GetNextNode(&p_entity->iportal_list, lnode))) { rval = read_PortalObject(GetNodeData(lnode), &p_portal, &lentry2); if (rval != SUCCESS) return rval; /* Get first ESI/SCN Portal */ if (p_portal->esi_port != 0) { foundSCNPortal = TRUE; break; } } /* Send out SCN */ if (foundSCNPortal) { p_md->cb.sock.socketType = ISNS_SOCKET_TYPE_UDP; p_md->cb.sock.addr.sin_family = AF_INET; p_md->cb.sock.len = sizeof (p_md->cb.sock.addr); memcpy (&p_md->cb.sock.addr.sin_addr.s_addr, p_portal->ip_addr.v + 12, sizeof (p_md->cb.sock.addr.sin_addr.s_addr)); p_md->cb.sock.addr.sin_port = htons ((short)(p_portal->esi_port & 0xFFFF)); ISNSSendMsg (p_md); } else { __DEBUG (sns_scn_debug & 1, (No valid Portal to send SCN)); return (ERROR); } } return (SUCCESS); } /******************************************************************** Sends a SCN to all the DD members of the node that's passed in. ********************************************************************/ int send_iscsi_scn_to_members ( SOIP_Iscsi * p_node, char *p_src_name, ISNS_Msg *p_scn_msg, uint32_t scn_bitmap ) { ISNS_Msg *p_msg; time_t t; int rval; ISNS_LIST_NODE *ddnode; ISNS_LIST_NODE *pnode; SOIP_Iscsi *iscsi_node; int dd_id; SOIP_Dd *p_dd; __DEBUG (sns_scn_debug &1, send_iscsi_scn_to_members); p_msg=&p_scn_md->msg; memset(p_scn_md, 0, sizeof(ISNS_Msg_Descp)); if ( p_node == NULL ) { /* Fetch the node */ rval = read_ISCSIObject(p_src_name, &p_node, &scn_entry); if (rval != SUCCESS ) return rval; } ddnode = NULL; while ( (ddnode = GetNextNode(&p_node->dd_id_list, ddnode)) ) { dd_id = *(uint32_t *)GetNodeData (ddnode); rval = read_DDObject(dd_id, &p_dd, &scn_entry2); if (rval != SUCCESS) break; if ( !(p_dd->activeFlag) ) { __DEBUG (sns_scn_debug &1, Discovery Domain is not Active:%i,p_dd->id); continue; } /* For each member */ pnode = NULL; while ( (pnode = GetNextNode(&p_dd->member_list, pnode)) ) { SOIP_Dd_Member *p_member; p_member=(SOIP_Dd_Member *)GetNodeData(pnode); if (p_member->type != ISNS_DD_ISCSI_MEMBER) continue; if ( !strcmp(p_node->id.v,p_member->node_id) ) { continue; } /* Fetch Node */ rval = read_ISCSIObject(p_member->node_id, &iscsi_node, &scn_entry3); if (rval != SUCCESS) return ERROR; if (!(iscsi_node->scn_bitmap & scn_bitmap)) { continue; } memset(p_scn_md, 0, sizeof(ISNS_Msg_Descp)); p_msg->hdr.type = ISNS_SCN; /* Add Dest Attribute */ ISNSAppendKey (p_msg, ISNS_ISCSI_NODE_ID, PAD4 (strlen (p_member->node_id)), p_member->node_id, 0); /* Add Timestamp */ ISNSAppendKey (p_msg, ISNS_TIMESTAMP, ISNS_TIMESTAMP_SIZE, NULL, time (&t)); /* Copy the src attribute buffer into the msg */ memcpy((char *)&p_msg->payload+p_msg->hdr.msg_len, (char *)&p_scn_msg->payload, p_scn_msg->hdr.msg_len); p_msg->hdr.msg_len+=p_scn_msg->hdr.msg_len; /* Send SCN msg */ send_iscsi_scn_md(p_member->node_id, p_scn_md); } } return ( SUCCESS ); } /********************************************************************* Processes a SCN Event request. *********************************************************************/ int ISNS_Process_SCN_Event (ISNS_Msg *p_msg) { ISNS_Key *key; ISNS_Attr *p_attr; /* query attr, response attr */ ISNS_Attr *src_attr; ISNS_Attr *attr_indx[SNS_MAX_ATTRS]; ISNS_Attr *key_indx[SNS_MAX_ATTRS]; ISNSParseMsg( p_msg, attr_indx, key_indx, &src_attr); key = (ISNS_Key *)(key_indx[0]); if (key == NULL) { __DEBUG (sns_scn_debug & 1, (SCN Rejected:No Key)); return (ISNS_SCN_EVENT_REJECTED_ERR); } p_attr = (ISNS_Attr *)(attr_indx[0]); if (p_attr == NULL) { __DEBUG (sns_scn_debug & 1, (SCN Rejected:No Op Attr)); return (ISNS_SCN_EVENT_REJECTED_ERR); } switch ( key->tag ) { case ISNS_ISCSI_NODE_ID: if ( p_attr->tag != ISNS_ISCSI_SCN_BITMAP ) { __DEBUG (sns_scn_debug & 1, (SCN Rejected:Wrong Op Attr %u), p_attr->tag); return ( ISNS_SCN_EVENT_REJECTED_ERR ); } //if (SUCCESS != send_iscsi_scn_to_members (NULL, (char *)&key->val, *(uint32_t *) &p_attr->val),0) // return ( ISNS_SCN_EVENT_REJECTED_ERR ); break; case ISNS_PORT_NAME: if (p_attr->tag != ISNS_IFCP_SCN_BITMAP) { __DEBUG (sns_scn_debug & 1, (SCN Rejected:Wrong Op Attr %u), p_attr->tag); return ( ISNS_SCN_EVENT_REJECTED_ERR ); } //if (SUCCESS != send_iscsi_scn_to_members (NULL, (char *)&key->val, *(uint32_t *) &p_attr->val),0) // return ( ISNS_SCN_EVENT_REJECTED_ERR ); break; default: __DEBUG (sns_scn_debug & 1, (SCN Rejected:Invalid Key %u), key->tag); return ( ISNS_SCN_EVENT_REJECTED_ERR ); } return ( SUCCESS ); } /******************************************************************** ********************************************************************/ int ISNS_Process_SCN ( ISNS_Msg_Descp *p_md, ISNS_Msg *p_rsp_msg ) { ISNS_LIST_NODE *cnode; ISNS_Attr *p_attr; ISNS_ATTR_VALS_CB *attr_vals_cb; SOIP_Scn_Callback_Entry *p_scn; p_attr = (ISNS_Attr *)&p_md->msg.payload; /* Go through SCN */ /* If Dest Matches, exec scn callback */ cnode = NULL; while ((cnode = GetNextNode(&scn_callback_list, cnode))) { /* For each SCN Entry */ p_scn = (SOIP_Scn_Callback_Entry *)GetNodeData(cnode); /* Does SCN match, dest */ if (0 != strcmp((char *)&p_attr->val, p_scn->name.v)) continue; /* determine how to send scn */ if ( p_scn->scn_callback_func ) { /* exec callback */ /* notify local devices of SCN */ attr_vals_cb = ISNSAttrGetList(p_md); if ( attr_vals_cb != NULL ) { p_scn->scn_callback_func( attr_vals_cb ); } ISNSFreeBuffer ( (char *)attr_vals_cb->attr_val_sptr ); ISNSFreeBuffer ( (char *)attr_vals_cb ); } else { /* ignore the rest */ __LOG_WARNING ("Not implemented.\n"); } /* Fill in rsp */ ISNSAppendKey( p_rsp_msg, ISNS_ISCSI_NODE_ID, PAD4( strlen( p_scn->name.v ) ), p_scn->name.v, 0 ); break; } return (SUCCESS); } static ISNS_ATTR_VALS_CB * ISNSAttrGetList (ISNS_Msg_Descp *p_md) { ISNS_Key *p_key; char *loc_ptr1; uint16_t sns_attr_len; ISNS_ATTR_VALS *p_aval; ISNS_ATTR_VALS_CB *p_attr_vals_cb; void *val_location; int num_entries; int display_debug; uint16_t len; display_debug = 0; if ((sns_cb_debug == 3) && (p_md->msg.hdr.type != ISNS_SCN)) display_debug = (sns_cb_msg_filter == p_md->msg.hdr.type); /* * Initialize the vars and go to the start * of the message.. */ p_aval = NULL; p_attr_vals_cb = NULL; len = 0; if (p_md->msg.hdr.type == ISNS_SCN) { /* No error Code */ p_key = (ISNS_Key *)&p_md->msg.payload; sns_attr_len = p_md->msg.hdr.msg_len; } else { /* Error Code */ p_key = (ISNS_Key *)&p_md->msg.payload+ISNS_ERROR_CODE_SIZE; sns_attr_len = p_md->msg.hdr.msg_len-ISNS_ERROR_CODE_SIZE; } __DEBUG (display_debug, (Attributes length : 0x%x), sns_attr_len); /* * Go through the message's attributes and parse them into * the Attribute list. NOTE: All the pointers are allocated * here including the storage for the attribute values. */ num_entries = 0; loc_ptr1 = (char *)p_key; p_aval = (void *)ISNSAllocBuffer (sns_attr_len); while (((char *)loc_ptr1 - (char *)p_key) < sns_attr_len) { if (p_aval == NULL) { __LOG_WARNING("AttrGetList out of aval buffs (size:%i)", sns_attr_len); return (NULL); } /* Set the VALUE location for the attributes */ val_location = SNSAttrGetAttrValLocation((ISNS_Attr *)loc_ptr1); len = ((ISNS_Attr *)loc_ptr1)->len; if (val_location == NULL) { __LOG_WARNING("AttrGetList id not found (tag:%i, msg id:%i, xid:%i)", ((ISNS_Attr *)loc_ptr1)->tag, p_md->msg.hdr.type, p_md->msg.hdr.xid); ISNSFreeBuffer((char *)p_aval); p_aval = NULL; break; } p_aval[num_entries].attr_id = ((ISNS_Attr *)loc_ptr1)->tag; p_aval[num_entries].attr_len = len; p_aval[num_entries].attr_val = val_location; /* Word Align values */ if (len % 4) len += 4 - (len % 4); /* Debugging */ if ((sns_scn_debug == 3) && (p_md->msg.hdr.type == ISNS_SCN)) { if (p_aval[num_entries].attr_id == RSCN_EVENT) display_debug = (sns_scn_msg_filter == *(int *)p_aval[num_entries].attr_val); } __DEBUG (display_debug, (attr id %u, len %d), p_aval[num_entries].attr_id, p_aval[num_entries].attr_len); /* End Debugging */ loc_ptr1 = (char *) loc_ptr1 + ISNS_SIZEOF_TAG + len; num_entries++; } /* * Set the attribute value control block. */ if (p_aval != NULL) { p_attr_vals_cb = (ISNS_ATTR_VALS_CB *) ISNSAllocBuffer(sizeof (ISNS_ATTR_VALS_CB)); if (p_attr_vals_cb == NULL) { __LOG_WARNING("AttrGetList out of cb buffs (size:%i)", (int)sizeof (ISNS_ATTR_VALS_CB)); } else { p_attr_vals_cb->num_entries = num_entries; p_attr_vals_cb->total_size = sns_attr_len; p_attr_vals_cb->attr_val_sptr = p_aval; } } return (p_attr_vals_cb); } static void* SNSAttrGetAttrValLocation (ISNS_Attr *sns_attr) { if (sns_attr->tag < ISNS_END_VALID_TAG) { return ((void *)&sns_attr->val); } return (NULL); } isns-2.1-01/isnsserver/src/iSNStbl.c0000644000175000017500000001651710665040341016243 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include "iSNStypes.h" #include "iSNStbl.h" #include "iSNSdebug.h" static SCN_ENTRY *scnTbl[MAX_SCN_ENTRIES]; static ESI_ENTRY *esiTbl[MAX_ESI_ENTRIES]; static uint32_t nESI; static uint32_t nSCN; static uint32_t curIndex; int sns_tbl_debug=0xFF; void InitAllTables(void) { InitESITable(); InitSCNTable(); } void InitESITable(void) { memset(esiTbl, 0, sizeof(esiTbl)); } void InitSCNTable(void) { memset(scnTbl, 0, sizeof(scnTbl)); nSCN = 0; } int UpdateESIEntry(char *p_ip, int port, int sockfd, char *id, int interval) { int i; if (interval==0) { /* Remove Portal Entry */ i=FindESIEntry(p_ip, (uint32_t)port); if (i==-1) { return (SUCCESS); } free(esiTbl[i]); esiTbl[i]=NULL; nESI--; } else { /* Check for dup */ i=FindESIEntry(p_ip, (uint32_t)port); if (i==-1) { /* Find Empty Spot */ for (i=0; ientity_id, id); esiTbl[i]->port=port; esiTbl[i]->sockfd=sockfd; memcpy(esiTbl[i]->ip_ptr, p_ip, ISNS_IP_SIZE); break; } } } nESI++; } return (SUCCESS); } int FindESIEntry(char *p_ip, uint32_t port) { int i=-1; for (i=0; iip_ptr, ISNS_IP_SIZE) && esiTbl[i]->port==port) { return (i); } } return (-1); } void GetFirstESIEntry(ESI_ENTRY **p_esi) { if (nESI==0) { *p_esi=NULL; return; } for (curIndex=0; curIndextype==type && 0==strcmp(scnTbl[i]->name, p_name)) { return (i); } break; case ISNS_PORT_NAME: if (scnTbl[i] && scnTbl[i]->type==type && 0==memcmp(scnTbl[i]->name, p_name, ISNS_PORT_NAME_SIZE)) { return (i); } default: return (-1); } } return (-1); } int AddSCNEntry(int type, char *p_name) { int i; /* Check to see if it is already in Table */ if (FindSCNEntry(type, p_name)!=-1) { DEBUG_0(sns_tbl_debug & 1, (SCN already in table)); return (SUCCESS); } /* Find Empty slot */ for (i=0; itype=type; strcpy(scnTbl[i]->name, p_name); nSCN++; break; case ISNS_PORT_NAME: scnTbl[i]=malloc(sizeof(SCN_ENTRY)); memset(scnTbl[i], 0, sizeof(SCN_ENTRY)); scnTbl[i]->type=type; isns_copy (scnTbl[i]->name, sizeof(scnTbl[i]->name, p_name, ISNS_PORT_NAME_SIZE); nSCN++; break; default: DEBUG_1(sns_tbl_debug & 1, (Unknown type %d), type); return (ERROR); break; } break; } } return (SUCCESS); } int RemoveSCNEntry(int type, char *p_name) { int i; /* Check to see if it is already in the Table */ if (FindSCNEntry(type, p_name)==-1) { return (SUCCESS); } /* Find Empty slot */ for (i=0; itype==type) { if (type==ISNS_ENTITY_ID || type==ISNS_ISCSI_NODE_ID) { if (0==strcmp(scnTbl[i]->name, p_name)) { free(scnTbl[i]); scnTbl[i]=NULL; nSCN--; return(SUCCESS); } } else if (type==ISNS_PORT_NAME) { if (0==memcmp(scnTbl[i]->name, p_name, ISNS_PORT_NAME)) { free(scnTbl[i]); scnTbl[i]=NULL; nSCN--; return(SUCCESS); } } else { DEBUG_1(sns_tbl_debug & 1, (Unknown type %d), type); return (ERROR); } } } DEBUG_0(sns_tbl_debug & 1, (Unable to find entry)); return (ERROR); } void GetFirstSCNEntry(char **id, int type) { if (nSCN==0) { *id=NULL; return; } for (curIndex=0; curIndextype==type) { *id=scnTbl[curIndex]->name; break; } } } void GetNextSCNEntry(char **id, int type) { *id=NULL; curIndex++; for (; curIndextype==type) { *id=scnTbl[curIndex]->name; break; } } } isns-2.1-01/isnsserver/src/iSNSconfig.c0000644000175000017500000000415310665040341016720 0ustar zobelzobel/*********************************************************************** Copyright (c) 2006, Novell, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Novell, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include "iSNS.h" /* Global Configuration Variables */ int sns_esi_interval = SNS_ESI_INTERVAL; int esi_sent_limit = 4; /* debug settings */ int isns_db_debug = 0; int isns_esi_debug = 0; int isns_reg_debug = 0; int isns_dereg_debug = 0; int isns_query_debug = 0; int isns_parse_debug = 0; int sns_fsm_debug = 0; /* state machine debugging */ int sns_bcast_debug = 0; /* broadcast debugging (except hb, scn) */ isns-2.1-01/isnsserver/src/iSNStrcv.c0000644000175000017500000001741310665040341016434 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include #include #include #include "iSNS.h" #include "iSNSmsg.h" #include "iSNSfsm.h" #include "iSNScomm.h" #include "iSNSipc.h" #include "iSNSdebug.h" #define SOCKET_TIMEOUT_VALUE 120*1000 /******************************************/ #ifdef SNS_LINUX int #else DWORD WINAPI #endif TCP_RecvThread(LPVOID lparam); typedef struct _tcp_cb { SOCKET sock; } TCP_CB; #define MAX_BUFFER (2048) /******************************************/ extern int sns_ready; extern int sns_comm_main_port; int sns_tcp_debug=0; #ifdef SNS_LINUX int TCP_RecvMain(void) #else DWORD WINAPI TCP_RecvMain(LPVOID lp) #endif { SOCKET sock; SOCKET sockfd; int not_needed = 1; socklen_t addrlen; int rc; int threadcount = 0; pthread_attr_t attr; struct sockaddr_in my_addr, their_addr; __DEBUG(sns_tcp_debug & 1, (TCP_RecvMain: Starting)); my_addr.sin_family = AF_INET; my_addr.sin_port = htons ((short) sns_comm_main_port); my_addr.sin_addr.s_addr = INADDR_ANY; sock = socket(AF_INET, SOCK_STREAM, 0); #ifdef SNS_LINUX /* Allow reuse of addresses */ if (setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, ¬_needed, sizeof(not_needed)) < 0) { perror ("Reuse address"); return (-1); } #endif rc = bind (sock, (struct sockaddr *) &my_addr, sizeof (my_addr)); if (rc < 0) { close (sock); { __LOG_ERROR ("Fatal Error while Binding:%i - %s.",rc,strerror(errno)); return (0); } } addrlen = sizeof (their_addr); rc = listen(sock,100); if (rc < 0) { __LOG_ERROR ("Fatal Error while doing a Listen:%i - %s",rc,strerror(errno)); return (0); } while (1) { sockfd = accept (sock, (struct sockaddr *) &their_addr,&addrlen); if (sockfd < 0) { __LOG_ERROR ("Fatal Error while doing an Accept sockfd:%i - %s",sockfd,strerror(errno)); break; } else { #ifdef SNS_LINUX pthread_t ignore; #else DWORD ignore; #endif TCP_CB *cb_p; cb_p=malloc(sizeof(TCP_CB)); cb_p->sock=sockfd; __DEBUG(sns_tcp_debug & 1,"accepted a TCP connection request thread count:%i",threadcount); #ifdef SNS_LINUX pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED); rc = pthread_create (&ignore, &attr, (void*) TCP_RecvThread, (LPVOID)cb_p); if (rc != 0) { __LOG_ERROR("Error creating thread:%i - %s",rc,strerror(rc)); } threadcount++; #else CreateThread(0, 0, TCP_RecvThread, (LPVOID)cb_p, 0, &ignore); #endif } } __LOG_INFO("TCP_RecvMain: Finished."); return(ERROR); } /******************************************/ #ifdef SNS_LINUX int #else DWORD WINAPI #endif TCP_RecvThread(LPVOID lparam) { TCP_CB *cb_p=(TCP_CB *)lparam; SOCKET sockfd; char buffer[MAX_BUFFER]; int startIndex; int endIndex; int pending; int msg_size; int i; struct pollfd ufds; int rc; SNS_Msg_Hdr *p_msg; ISNS_Msg_Descp md; __DEBUG(sns_tcp_debug & 1, (TCP_RecvThread: Starting a thread on socket:%i),cb_p->sock); sockfd=cb_p->sock; free(cb_p); startIndex=0; endIndex=0; while (1) { ufds.fd = sockfd; ufds.events = POLLIN; ufds.revents = 0; rc = poll(&ufds, 1, SOCKET_TIMEOUT_VALUE); if (rc == 0) { /* close connection if no activity */ __DEBUG(sns_tcp_debug &1, (connection timed out and closed:%i),sockfd); close(sockfd); break; } else if (rc < 0) { __LOG_ERROR("Error on connection:%i - errno:%i %s",sockfd,errno,strerror(errno)); close(sockfd); break; } i = recv(sockfd, &buffer[endIndex], sizeof(buffer)-endIndex, 0); if (i == 0) { __DEBUG(sns_tcp_debug & 1, (recv no data - client closed connection)); close(sockfd); break; } else if (i < 0) { __LOG_ERROR("recv error we will close connection:%i - %s",i,strerror(errno)); close(sockfd); break; } endIndex+=i; pending=endIndex-startIndex; /* Parse Msg */ __DEBUG(sns_tcp_debug &1,"recvsize:%i pending:%i",i,pending); while ( pending >= sizeof(SNS_Msg_Hdr) ) { p_msg=(struct sns_msg_hdr *)&buffer[startIndex]; msg_size=sizeof(SNS_Msg_Hdr)+ntohs(p_msg->msg_len); if ( pending < msg_size) { __DEBUG(sns_tcp_debug &1,"pending:%i is less than msg_size:%i",pending,msg_size); break; } p_msg->type = ntohs (p_msg->type); p_msg->xid = ntohs (p_msg->xid); p_msg->msg_len = ntohs (p_msg->msg_len); p_msg->flags = ntohs (p_msg->flags); p_msg->version = ntohs (p_msg->version); p_msg->sequence = ntohs (p_msg->sequence); md.cb.sender = ISNS_REMOTE; /* Store the type and socket */ md.cb.sock.sockfd=sockfd; md.cb.sock.socketType=ISNS_SOCKET_TYPE_TCP; memcpy(&md.msg, p_msg, msg_size); __DEBUG(sns_tcp_debug &1, (ISNSPDU rcv size %d), msg_size); while (!sns_ready) { sleep(1); } __DEBUG(sns_tcp_debug &1,SendIPCMessage msg_len:%i,p_msg->msg_len); SendIPCMessage(SNS_EP, (void *)&md, sizeof(SNS_Msg_Cb) + sizeof(SNS_Msg_Hdr) + p_msg->msg_len, 0); pending-=msg_size; startIndex+=msg_size; } if (pending==0) { startIndex=0; endIndex=0; } else { __DEBUG(sns_tcp_debug &1,??? pending non-zero:%i,pending); /* copy buffer from StartIndex begining of buffer with size of pending */ memcpy(buffer, &buffer[startIndex], pending); /* set endIndex=pending set startIndex = 0 */ endIndex = pending; startIndex = 0; } } __DEBUG(sns_tcp_debug & 1, (TCP_RecvThread: Socket:%i Exiting thread),sockfd); /* thread terminates here */ pthread_exit(&rc); __LOG_ERROR("pthread_exit failed"); return (SUCCESS); } isns-2.1-01/isnsserver/Makefile0000644000175000017500000001074610665035152015434 0ustar zobelzobel# # The contents of this file are subject to the Nishan Systems, Inc. Public # License Version 1.0 (the "License"); you may not use this file except in # compliance with the License included with the distribution. You may # obtain a copy of the License at www.NishanSystems.com. # # Software distributed under the License is distributed on an "AS IS" # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See # the License for the specific language governing rights and limitations # under the License. # # The Original Software is Release 1.0 of the iSNS Example Client and # Server. Portions created by Nishan Systems are Copyright 2001 Nishan # Systems, Inc. All Rights Reserved. # # This Original Software is subject to a standard specification issued # by the IETF. The Specification is titled iSNS Internet Storage Name # Service. # # The Initial Contributor of the Original Software is Nishan Systems, Inc. # Revision Contributor(s) are listed below: # # Submitted Revision Contributor Name and Date # # SHELL = /bin/sh DESTDIR ?= INSTALL = install etcdir = /etc exec_prefix = initddir = $(etcdir)/init.d sbindir = $(exec_prefix)/usr/sbin PROGRAMS = isnssd CC = gcc -g SRCDIR = ./src/ INCDIR = ./include/ INCDIR += -I/usr/include/ OBJECTS = OBJECTS += iSNSMain.o OBJECTS += iSNScomm.o OBJECTS += iSNSparse.o #OBJECTS += iSNStbl.o OBJECTS += iSNSInit.o OBJECTS += iSNSUtil.o OBJECTS += iSNSdb.o OBJECTS += iSNSscn.o OBJECTS += iSNSesi.o OBJECTS += iSNSresponse.o OBJECTS += iSNSquery.o OBJECTS += iSNSreg.o OBJECTS += iSNSdereg.o OBJECTS += iSNSipc.o OBJECTS += iSNSqueue.o OBJECTS += iSNStrcv.o OBJECTS += iSNSLinux.o OBJECTS += iSNSbuffer.o OBJECTS += iSNSfsm.o OBJECTS += iSNSrcv.o OBJECTS += iSNSList.o OBJECTS += iSNSconfig.o OBJECTS += iSNSobjects.o OPTFLAGS ?= -g -O2 WARNFLAGS ?= -Wall CFLAGS += $(OPTFLAGS) $(WARNFLAGS) CFLAGS += -DSNS_LINUX CFLAGS += -DSNS_DEBUG LIBS = -lpthread -lgdbm PROGRAMS = isnsd all : $(PROGRAMS) isnsd: $(OBJECTS) $(CC) $^ -o $@ $(LIBS) iSNSMain.o : $(SRCDIR)iSNSMain.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ iSNScomm.o : $(SRCDIR)iSNScomm.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ iSNSparse.o : $(SRCDIR)iSNSparse.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ iSNStbl.o : $(SRCDIR)iSNStbl.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ iSNSInit.o : $(SRCDIR)iSNSInit.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ iSNSUtil.o : $(SRCDIR)iSNSUtil.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ iSNSdb.o : $(SRCDIR)iSNSdb.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ iSNSresponse.o : $(SRCDIR)iSNSresponse.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ iSNSscn.o : $(SRCDIR)iSNSscn.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ iSNSesi.o : $(SRCDIR)iSNSesi.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ iSNSquery.o : $(SRCDIR)iSNSquery.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ iSNSreg.o : $(SRCDIR)iSNSreg.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ iSNSdereg.o : $(SRCDIR)iSNSdereg.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ iSNSipc.o : $(SRCDIR)iSNSipc.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ iSNSqueue.o : $(SRCDIR)iSNSqueue.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ iSNStrcv.o : $(SRCDIR)iSNStrcv.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ iSNSLinux.o : $(SRCDIR)iSNSLinux.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ iSNSbuffer.o : $(SRCDIR)iSNSbuffer.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ iSNSfsm.o : $(SRCDIR)iSNSfsm.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ iSNSrcv.o : $(SRCDIR)iSNSrcv.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ iSNSList.o : $(SRCDIR)iSNSList.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ iSNSconfig.o : $(SRCDIR)iSNSconfig.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ iSNSobjects.o : $(SRCDIR)iSNSobjects.c $(CC) -I$(INCDIR) $(CFLAGS) -c $< -o $@ clean : rm $(OBJECTS) isnsd install: install_programs install_initd install_programs: $(PROGRAMS) $(INSTALL) -d $(DESTDIR)$(sbindir) $(INSTALL) -m 755 $^ $(DESTDIR)$(sbindir) install_initd: if [ -f /etc/SuSE-release ]; then \ $(MAKE) install_initd_suse ; \ elif [-f /etc/debian_version ]; then \ $(MAKE) install_initd_debian ; \ elif [-f /etc/redhat_version ]; then \ $(MAKE) install_initd_redhat ; \ fi install_initd_debian: $(INSTALL) -d $(DESTDIR)$(initddir) $(INSTALL) -m 755 etc/initd.debian $(DESTDIR)$(initddir)/isns install_initd_suse: $(INSTALL) -d $(DESTDIR)$(initddir) $(INSTALL) -m 755 etc/initd.suse $(DESTDIR)$(initddir)/isns install_initd_redhat: $(INSTALL) -d $(DESTDIR)$(initddir) $(INSTALL) -m 755 etc/initd.suse $(DESTDIR)$(initddir)/isns isns-2.1-01/isnsserver/LICENSE.TXT0000644000175000017500000000275110665035152015454 0ustar zobelzobelCopyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. isns-2.1-01/isnsserver/README.txt0000644000175000017500000001304710665035152015467 0ustar zobelzobelREADME.TXT ______________________ iSNS Release Version 2.0 ______________________ Introduction 1) Please read and accept the "LICENSE.TXT" before use 2) The client and server application can be built with For Linux: make SLSE 10 was used during test 3) Pre-built executable for both client and server are provided for 32-bit 3a) The server executable is isnsd 3b) The client executable is isnsc 4) The tested OS platforms are: SLES 10 32 and 64 bit ______________________ To Build The C source code can be built using Linux. The option for building the code is to use the Linux makefile, make make install ______________________ To Provide Feedback Please provide feedback to the development mail list for the isns server ______________________ To Uninstall 1) Delete the top-level directory that the iSNS code was installed in. _____________________ Server Options If the server executable is run without command line options, or the "-?" option is on the command line, the following supported options are listed: iSNSserver>isnss Usage: isnsd [options] NOTES: IP-Addresses must be in IP dotted notation. Options: [-a addr] IP-Address for SNSP traffic. [-b addr] Broadcast Address for SNSP traffic. [-p port] primary port for SNSP traffic. [-d] Full debug options on. [-f] Foreground and not as a daemon. [-?] Help. _____________________ Client Options If the client executable is run without command line options, or the "-?" option is on the command line, the following supported options are listed: iSNSclient>isnsc IETF iSNS Client, v1.1. Usage: isnsc [options] Options: [-h] Listen for L2 heartbeat from an iSNS. [-a ip] iSNS Address. [-t] TCP mode. [-p port] Port used for sending. Default is port 3205. [-?] Help. For the client to connect with the iSNS server, one of two options needs to be used, "-h" or "-a". The "-h" option allows for discovery using L2 broadcast heartbeats from the server. The "-a" option allows for static configuration of the iSNS server IP-Address. _____________________ About Discovery Domains and Discovery Domain Sets A Discovery Domain Set (DDS) is a collection of Discovery Domains. A DDS can be either Enabled or Disabled. A Discovery Domain (DD) is a collection of storage devices in the storage area network which will be allowed to query for information about each other. These queries will only be successful if the DD is a member of an Enabled DDS. A device does not necessarily know which DD it is a member of. Also, a device may belong to more than one DD. A DD can be a member of more then one DDS. The SOURCE field of every iSNS query and registration message identifies the storage device that sent the request. The iSNS Server uses this field to scope the operation to the set of DDs that the origin iSNS client is a member of. If the SOURCE field contains NULL, the iSNS message is assumed to have originated from an administrative iSNS client, so the message SHALL BE scoped to the entire contents of the iSNS, regardless of the configuration of Discovery Domains. If, after registering storage nodes, queries are done with the source of the message specified, then at least one DD should have been created and placed into an enabled DDS for the query to return results. Each device that is to be visible to each other needs to be placed into the same DD, and the DD needs to be placed in an enabled DDS. For more discussion on Discovery Domains please refer to the iSNS Specification. _____________________ About Registering Access Control Lists (ACLs) For an iSCSI Target ACLs map directly to an iSNS DD. If a target has a set of iSCSI Nodes that have access rights to it, then it can register a DD containing the iSCSI Node ID of the target and the set of iSCSI Node IDs of the initiators that have access to it. Additionally, the DD must be in an enabled DDS for it to be enforced by the iSNS. An example showing a simple ACL registration is shown below. _____________________ Getting Started The best way to start is to run the server and client in separate console windows on a Linux, NT or Windows 2000 based workstation. Then practice registering and querying several nodes without creating any Discovery Domains or Discovery Domain Sets. NOTE: it is important to leave the source field of any registration or query messages as NULL if no Discovery Domains and Discovery Domains Sets are created. Otherwise the queries will return with an error stating no matching nodes found. After doing registrations without DD/DDS's, create discovery domains and place nodes in the DD's to see how ACL's can registered and modified in the iSNS. _____________________ Example Test The interactive client generates iSNS registration and query messages that are sent to the server. The server responds with the appropriate messages to satisfy the registration and query messages. The PDU stream is printed to the console to facilitate testing and integration of the iSNS with storage products. The PDU's are documented in the iSNS Specification. The current version as of this specification is included in the iSNSserver directory of this release. 1) Open two console windows, possibly on separate workstations 2) Assuming a server with an interface having IP-Address 192.100.100.116 Broadcast Address 192.100.100.255 3) Launch the server >isnsd -f 4) Launch the client and use TCP for communication >isnsc -a 192.100.100.116 -t Or, to demonstrate the autodetection of the server in a layer 2 network, enter >isnsc -h -t isns-2.1-01/isnsserver/include/0000755000175000017500000000000010665035311015404 5ustar zobelzobelisns-2.1-01/isnsserver/include/iSNSLinux.h0000644000175000017500000000577410665040401017422 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef _linuxsns_h #define _linuxsns_h #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define HANDLE pthread_t* #define ULONG ulong #define FALSE 0 #define TRUE 1 #define LPVOID void * #define itoa(a,b,c) (((c)==10)?sprintf(b,"%d",a):sprintf(b,"%x",a)) typedef unsigned char BYTE; #define SNS_NT_FSM_TIMEOUT 10 #define SNS_NT_RS_TIMEOUT 10 #define WDOG_ID UINT_PTR #define OK SUCCESS #define FUNCPTR int //#define bzero(a,b) {memset(a, 0, b);} #define inet_ntoa_b(a,b) {strcpy(b,inet_ntoa(a));} typedef int STATUS; typedef HANDLE MSG_Q_ID; typedef int SOCKET; typedef unsigned int DWORD; void taskDelay (int time); int sysClkRateGet(void); int taskIdSelf(void); void taskSuspend(void); void taskDelete(pthread_t task); int SNSReqTimeoutThread(); int SNSFSMTimeoutThread(); int SNSESITimeoutThread(); int SNSResyncTimeoutThread(); void SNSTrap(void); int LinuxTaskSpawn(char* taskName, void* funcPtr); #define taskSpawn(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) LinuxTaskSpawn(a,e) #endif isns-2.1-01/isnsserver/include/iSNStypes.h0000644000175000017500000004635610665040401017470 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This file contains definitions of data structures * and macros used in storing attributes in the SoIP * service database. * */ #ifndef _SNStypes_h_ #define _SNStypes_h_ #ifdef SNS_LINUX #include "iSNSLinux.h" #else #include "iSNSnt.h" #endif #include "iSNSdefs.h" #include "iSNSList.h" #define SNS_IF_NAME "eth0" #define SNS_IFMGMT_NAME "eth1" #ifndef INET_ADDR_LEN #define INET_ADDR_LEN 18 #endif #include "iSNSfctypes.h" #define SNS_MSG_PAYLOAD_SIZE 8*1024 #define MAX_PORTS_PER_NODE 32 #define SNS_PORTS_PER_LIST 128 /* * Maximum number of attributes that can be sent in response * to an iSNS query. The maximum payload has small enough to * fit in an ethernet frame. */ #define SNS_MAX_ATTRS 64 /* * Definition of attribute sizes in bytes */ #define MAX_DD_PER_LIST (1024) #define MAX_MEMBER_PER_DD (1024) #define NODE_SYM_NAME_SIZE 256 #define PORT_NAME_SIZE 8 #define PORT_SYM_NAME_SIZE 256 #define PORT_ID_SIZE 3 #define PORT_ID_PAD 1 #define ZONE_SYM_NAME_SIZE 64 #define NX_PORT_TYPE_SIZE 10 #define NODE_IPA_SIZE 8 #define HARD_ADDR_SIZE 3 #define HARD_ADDR_PAD 1 #define DB_NODE_NAME_SIZE 9 #define SNS_COS_SIZE 4 #define PORT_TYPE_SIZE 1 #define PORT_TYPE_PAD 3 #define FC4_BITMAP_SIZE 32 #define FC4_TYPE_SIZE 1 #define FC4_TYPE_PAD 3 #define ZONE_BITMAP_SIZE 64 #define SAN_SYM_NAME_SIZE 64 #define ENTITY_ID_SIZE 128 #define ESI_SIZE 4 #define ESI_PORT_SIZE 4 #define ENTITY_TYPE_SIZE 4 #define IP_PORT_SIZE 4 #define SPACE_ID_SIZE 16 #define IP_ADDR_SIZE_V4 4 #define IP_ADDR_SIZE_V6 16 #define IP_ADDR_SIZE IP_ADDR_SIZE_V6 #define XID_BEGIN 0 #define XID_IN_PROGRESS 1 #define XID_END 2 #define SOIP_DB_Node_Id 0xFE #define ISNS_DD_MEMBER_ENABLE (1) #define ISNS_DD_MEMBER_DISABLE (0) #define ISNS_SOCKET_TYPE_UDP (0x12) #define ISNS_SOCKET_TYPE_TCP (0x34) #define ISNS_ISCSI_TYPE_SIZE (4) #define ESI_SIZE 4 #define ESI_PORT_SIZE 4 #define ENTITY_TYPE_SIZE 4 #define PORTAL_ID_SIZE 4 /* * Declaration of the attribute value structure. */ typedef struct { uint32_t attr_id; uint32_t attr_len; void *attr_val; } ISNS_ATTR_VALS; /* * Declaration of the attribute value control block. */ typedef struct { uint32_t flags; uint32_t num_entries; uint32_t total_size; ISNS_ATTR_VALS *attr_val_sptr; } ISNS_ATTR_VALS_CB; /* * External Node Name key: */ typedef struct soip_node_name { char v[NODE_SYM_NAME_SIZE]; } SOIP_Node_Name, SOIP_Node_Key; /* * Internal Node Name key: */ typedef struct soip_db_node_name { char v[NODE_SYM_NAME_SIZE]; char pad[3]; } SOIP_DB_Node_Name; /* * Port Name key: */ typedef struct soip_port_name { char v[PORT_NAME_SIZE]; } SOIP_Port_Name, SOIP_Port_Key; /* * IP Address Key: */ typedef struct IP_address { char v[IP_ADDR_SIZE]; } IP_Address; /* * Port ID Key: */ typedef struct SOIP_port_id { char v[PORT_ID_SIZE]; char bachelor_pad; } SOIP_Port_Id; /* * Port Type: */ typedef uint8_t SOIP_Port_Type; /* * Class of Service: */ typedef uint32_t SOIP_COS; typedef struct soip_node_ipa { char v[NODE_IPA_SIZE]; } SOIP_Node_IPA; typedef struct soip_hard_addr { char v[HARD_ADDR_SIZE]; char paddington_bear; } SOIP_Hard_Addr; typedef struct soip_device_type { uint16_t lun; uint8_t type; uint8_t launch_pad; } SOIP_Device_Type; /* * Socket based IPC endpoint used for communicating with a remote * SOIP service entity */ typedef struct socket_ep { struct sockaddr_in addr; uint32_t len; uint32_t socketType; int sockfd; } ISNS_Socket_Ep; /* * Definition of registration operational types. */ typedef int OP_TYPE; /* * Definition of Database Key. * */ typedef enum { NODE_NAME_KEY = 1, PORT_NAME_KEY, ENTITY_ID_KEY, PORTAL_ID_KEY, DDS_ID_KEY, DD_ID_KEY, ISCSI_ID_KEY, PORTAL_GROUP_ID_KEY, ENTITY_IDX_KEY, ISCSI_IDX_KEY, PORTAL_IDX_KEY, LIST_KEY } ISNS_Database_Key; /* * Definition of Device Attribute Tags. SoIP device attributes * are sent to the server in a UDP message and are encoded * in TLV format. * */ typedef enum { START_SNS_DEVI_ATTR = 20,/* 20 */ SYM_NODE_NAME = START_SNS_DEVI_ATTR, NODE_NAME, PORT_NAME, FABRIC_PORT_NAME, PORT_ID, SYM_PORT_NAME, /* 25 */ IP_ADDR, PORT_TYPE, FC4_TYPES, COS, PORT_PRIORITY, /* 30 */ ZONE_TAG, ZONE_SYM_NAME, ZONE_BITMAP, ZONE_DEST_PORT_NAME, ZONE_ORIG_PORT_NAME, /* 35 */ ZONE_PREV_BITMAP, NODE_IPA, HARD_ADDR, RSCN_TYPE, RSCN_CALLBACK, /* 40 */ RSCN_EVENT, REMOTE_FLAG, DEVICE_TYPE, ENTITY_ID, ESI, /* 45 */ ESI_PORT, ENTITY_TYPE, IP_PORT, PORTAL_ID, SPACE_ID, /* 50 */ AREA_ID, END_SNS_DEVI_ATTR } SNS_Devi_Attr; /* RSCN_Types (defined to fit in one byte) */ typedef struct soip_fc_feature { char v[FC_FEATURE_SIZE]; } SOIP_FC_Features; typedef struct soip_fc_descr { char v[FC_DESCRIPTOR_SIZE]; } SOIP_FC_Descr; typedef struct soip_dds { uint32_t id; uint32_t status; char sym_name[DDS_SYM_NAME_SIZE]; ISNS_LIST dd_list; } SOIP_Dds; typedef struct soip_dd_member { char node_id[DD_MAX_DD_MEMBER_SIZE]; uint32_t type; uint32_t status; uint32_t node_idx; } SOIP_Dd_Member, SOIP_DD_Member_Key; typedef uint32_t* ISNS_DD_LIST; typedef struct soip_dd { uint32_t id; char sym_name[DD_SYM_NAME_SIZE]; ISNS_LIST member_list; ISNS_LIST dds_list; uint32_t activeFlag; uint32_t feature; } SOIP_Dd; typedef struct _soip_iscsi_node_name { char v[MAX_ISCSI_NODE_ID_SIZE]; } SOIP_ISCSI_Node_Id; typedef struct _soip_time { uint32_t t_pad; time_t t_time; } SOIP_Time; typedef struct soip_entity_id { char id[ ENTITY_ID_SIZE ]; } SOIP_Entity_Id; /* * Definition of Node Name record stored in the SoIP * service database */ typedef struct soip_node { char sym_name[ NODE_SYM_NAME_SIZE ]; SOIP_Node_Name node_name; SOIP_Node_IPA node_ipa; IP_Address ip_addr; uint32_t port_map; /* * Store Port names their ip addresses */ uint32_t entity_index; SOIP_Port_Name port_name[ MAX_PORTS_PER_NODE ]; int sym_name_len; /* iSNS Stuff */ void *ptr_cert; uint32_t cert_size; ISNS_LIST port_list; } SOIP_Node, SOIP_Fc_Node; /* * Definition of Port Name record stored in the SoIP * service database. It contains all attributes associated * with a port/device. */ typedef struct SOIP_Ifcp { SOIP_Port_Name port_name; SOIP_Port_Name fabric_port_name; SOIP_Node_Name node_name; IP_Address ip_addr; SOIP_Hard_Addr hard_addr; SOIP_Port_Id id; SOIP_Port_Type type; char pad_thai[ PORT_TYPE_PAD ]; FC4_Types fc4_types; SOIP_COS cos; uint32_t priority; uint32_t ifcp_index; char zone_bitmap[ ZONE_BITMAP_SIZE ]; uint32_t san_id; char sym_name[ PORT_SYM_NAME_SIZE ]; uint32_t remote; SOIP_Device_Type dev_type; int sym_name_len; SOIP_Entity_Id entity_id; char space_id[ SPACE_ID_SIZE ]; /* iSNS Stuff */ ISNS_LIST dd_id_list; uint32_t scn_bitmap; int scn_sockfd; void *ptr_cert; uint32_t cert_size; SOIP_FC_Features fc_feature; SOIP_FC_Descr fc_descr; /* Internal */ uint32_t activeFlag; void (*scn_callback)(ISNS_ATTR_VALS_CB *attr_vals_sptr); } SOIP_Ifcp; /* * Definition of a port list which is used for maintaining * port names associated with a service domain, FC4 type * and port type. */ typedef struct soip_port_list { #define SNS_MAP_SIZE (SNS_PORTS_PER_LIST/32) uint32_t num_entries; uint32_t bitmask[ SNS_MAP_SIZE ]; SOIP_Port_Name port_name[ SNS_PORTS_PER_LIST ]; } SOIP_Port_List; typedef struct soip_scn_entry { uint32_t type; uint32_t scn_bitmap; int scn_sockfd; SOIP_ISCSI_Node_Id name; } SOIP_Scn_Entry; typedef struct soip_zone { uint32_t zone_tag; char sym_name[ ZONE_SYM_NAME_SIZE ]; SOIP_Port_List plist; int sym_name_len; } SOIP_Zone; typedef enum { ETYPE_ISCSI = 1, ETYPE_IFCP } SOIP_Entity_Type; typedef struct soip_prot_ver { uint16_t ver_max; uint16_t ver_min; } SOIP_Prot_Ver; typedef struct soip_entity { SOIP_Entity_Id eid; uint32_t eid_len; uint32_t esi; SOIP_Entity_Type eid_type; //1=iscsi, 2=ifcp uint32_t node_type; //1=target, 2=initiator, 3=both SOIP_Port_List port_list; uint32_t entity_index; SOIP_Time timestamp; IP_Address mgmt_ip_addr; ISNS_LIST iportal_list; ISNS_LIST ifcp_node_list; ISNS_LIST iscsi_node_list; uint32_t scn_bitmap; int scn_sockfd; SOIP_Prot_Ver prot_ver; void *ptr_cert; uint32_t cert_size; uint32_t period; } SOIP_Entity; typedef struct soip_entity_key { char id[ ENTITY_ID_SIZE ]; } SOIP_Entity_Key; typedef struct entity_list_entry { SOIP_Entity_Id eid; uint32_t entity_index; } ENTITY_LIST_ENTRY; typedef struct index_entry { uint32_t index; uint32_t index_type; } SOIP_IDX_Key; typedef struct soip_portal { uint32_t portal_id; IP_Address ip_addr; uint32_t ip_port; char sym_name[ PORTAL_SYM_NAME_SIZE ]; uint32_t node_type; //1=target, 2=initiator SOIP_Entity_Id entity_id; uint32_t entity_index; uint32_t portal_index; uint32_t esi_sockfd; uint32_t esi_port; uint32_t esi_interval; uint32_t esiSent; time_t esi_timer; void *ptr_cert; uint32_t cert_size; uint32_t default_portal_tag; } SOIP_Portal; typedef struct soip_portal_key { IP_Address ip_addr; uint32_t ip_port; } SOIP_Portal_Key; typedef struct soip_db_portal { IP_Address ip_addr; uint32_t ip_port; } SOIP_DB_Portal; typedef struct portal_list_entry { SOIP_DB_Portal portal_ip_port; uint32_t portal_idx; } PORTAL_LIST_ENTRY, SOIP_Portal_List_Key; typedef struct soip_portal_group { SOIP_ISCSI_Node_Id id; IP_Address ip_addr; uint32_t ip_port; uint32_t portal_tag; uint32_t portal_group_index; } SOIP_Portal_Group; typedef struct soip_portal_group_key { SOIP_ISCSI_Node_Id id; IP_Address ip_addr; uint32_t ip_port; } SOIP_Portal_Group_Key; /* * Entities that communicate with the SOIP service * agent */ #define HASH_MAX_BUFFER 256 typedef struct idx_hash_entry { uint32_t index; void *next; char buffer[HASH_MAX_BUFFER]; } IDX_HASH_ENTRY; #define DD_KEY_SIZE (4) #define DDS_KEY_SIZE (4) typedef struct soip_dd_key { uint32_t id; } SOIP_DD_Key; typedef struct soip_dds_key { uint32_t id; } SOIP_DDS_Key; typedef struct soip_iscsi { SOIP_ISCSI_Node_Id id; uint32_t iscsi_id_len; SOIP_Entity_Id entity_id; uint32_t entity_id_len; uint32_t type; char alias[MAX_ISCSI_ALIAS_SIZE]; uint32_t alias_len; ISNS_LIST dd_id_list; /* SCN */ uint32_t entity_index; uint32_t iscsi_index; uint32_t scn_bitmap; int scn_sockfd; /* Cert */ void *ptr_cert; uint32_t cert_size; uint32_t activeFlag; void (*scn_callback)(ISNS_ATTR_VALS_CB *attr_vals_sptr); } SOIP_Iscsi; typedef struct _soip_iscsi_key { char v[MAX_ISCSI_NODE_ID_SIZE]; } SOIP_ISCSI_Key; /* ids for identifying which list */ typedef enum { ISCSI_DD_LIST = 1, FCP_DD_LIST, FCP_PORTAL_LIST, ENTITY_PORTAL_LIST, ENTITY_FCP_LIST, ENTITY_ISCSI_LIST, DD_MEMBER_LIST, DD_DDS_LIST, DDS_DD_LIST, PORTAL_ENTITY_LIST, SCN_CALLBACK_LIST, SCN_LIST } DATA_LIST_ID; #define LIST_KEY_SIZE (8) typedef struct soip_list_key { int list_id; int list_index; union { /* The key to which the list belongs */ SOIP_Entity_Key entity_id; SOIP_DDS_Key dds; SOIP_DD_Key dd; SOIP_Node_Key node_name; SOIP_Portal_Key portal; } key; } SOIP_LIST_Key; typedef struct soip_list { int index; int next_index; int prev_index; union { SOIP_Entity_Key entity_id; SOIP_DDS_Key dds; SOIP_DD_Key dd; SOIP_Node_Key node_name; SOIP_Portal_Key portal; SOIP_DD_Member_Key ddmember; SOIP_Portal_List_Key portalmember; } key; } SOIP_DB_List; typedef struct soip_db_entry { /* * The "data_type" field identifies the type of data * stored in the iSNS database. This field is used * during database lookups to identify the type of * data associated with a database key. */ ISNS_Database_Key data_type; union { SOIP_Entity entity; SOIP_Portal portal; SOIP_Portal_Group portal_group; SOIP_Fc_Node ifcp_node; SOIP_Iscsi scsi_node; SOIP_Ifcp port; SOIP_Dds dds; SOIP_Dd dd; SOIP_Prot_Ver prot_ver; SOIP_Node node; SOIP_Entity_Id entity_idx; SOIP_ISCSI_Node_Id iscsi_idx; SOIP_DB_Portal portal_idx; SOIP_DB_List list; } data; } SOIP_DB_Entry; typedef struct ISNS_dbkey { int tag; uint32_t len; union { SOIP_ISCSI_Key iscsi_key; SOIP_Entity_Key entity_key; SOIP_Node_Key node_key; SOIP_Port_Key port_key; SOIP_DD_Key dd_key; SOIP_DD_Key dds_key; SOIP_Portal_Key portal_key; SOIP_Portal_Group_Key portal_group_key; SOIP_IDX_Key idx; SOIP_LIST_Key list; } val; } ISNS_DBKey; typedef struct ISNS_key { uint32_t tag; uint32_t len; union { uint32_t index; uint32_t node_type; uint32_t ip_port; uint32_t dds_id; uint32_t dd_id; SOIP_Dds dds; SOIP_Dd dd; SOIP_Entity_Id entity_id; SOIP_Node_Name node_name; SOIP_Port_Name port_name; IP_Address ip_addr; } val; } ISNS_Key; /* * Generic data structure for attribute */ typedef struct ISNS_attr { uint32_t tag; uint32_t len; union { uint32_t index; uint32_t period; uint32_t ip_port; uint32_t dds_id; uint32_t dd_id; uint32_t dds_status; SOIP_Prot_Ver prot_ver; uint32_t scn_bitmap; SOIP_Node_Name node_name; char sym_node_name[NODE_SYM_NAME_SIZE]; SOIP_Port_Name port_name; SOIP_Port_Name fabric_port_name; char sym_port_name[PORT_SYM_NAME_SIZE]; SOIP_Port_Id port_id; IP_Address ip_addr; SOIP_Port_Type port_type; FC4_Types fc4_types; SOIP_COS cos; uint32_t portal_group; uint32_t priority; SOIP_Node_IPA ipa; SOIP_Hard_Addr hard_addr; char sym_san_name[SAN_SYM_NAME_SIZE]; uint32_t remote; SOIP_Device_Type dev_type; SOIP_Time timestamp; void (*scn_callback)(ISNS_ATTR_VALS_CB *attr_vals_sptr); SOIP_Entity_Id entity_id; } val; } ISNS_Attr; /* * Configured role of the SOIP service software. SOIP service software * can be configured to run as a ISNS_CLIENT, ISNS_PRIMARY_SERVER or * ISNS_SECONDARY_SERVER. * */ typedef enum { ISNS_MGMT_AGENT = 1, ISNS_CLIENT, ISNS_PRIMARY_SERVER, ISNS_SECONDARY_SERVER, ISNS_REMOTE, ISNS_NUM_ENTITIES } ISNS_Entity; typedef struct soip_scn_callback_entry { uint32_t bitmap; uint32_t type; void (*scn_callback_func)(ISNS_ATTR_VALS_CB *avcb_ptr); SOIP_ISCSI_Node_Id name; } SOIP_Scn_Callback_Entry; extern ISNS_Entity isns_role; #endif isns-2.1-01/isnsserver/include/iSNSfctypes.h0000644000175000017500000000413410665040401017765 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This file contains definitions of fiber channel * protocol specific datatypes used by the SOIP * Name server. * */ #ifndef _SNSfctypes_h_ #define _SNSfctypes_h_ /* * FC-4 protocol types supported by a Port */ typedef struct fc4_types { uint8_t bitmap[32]; } FC4_Types; /* * Initial process associator */ typedef struct fc_ipa { uint8_t v[8]; } FC_IPA; #endif isns-2.1-01/isnsserver/include/iSNSbuffer.h0000644000175000017500000000410210665040401017554 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef _SNSbuffer_h_ #define _SNSbuffer_h_ #include "iSNSmsg.h" extern char * ISNSAllocBuffer (uint32_t); extern void ISNSFreeBuffer (char *); extern void SNSFreeAttrBuffer (char *); extern int SNSCreateBufferPools (void); extern void SNSInitBufferPool (void *buf_space, uint32_t max_buffers, uint32_t qtype); extern int SNSBufCount (uint32_t qtype); #endif isns-2.1-01/isnsserver/include/iSNSresponse.h0000644000175000017500000000424110665040401020145 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This file contains definitions related to iSNSreg * */ #ifndef _SNSresponse_h_ #define _SNSresponse_h_ int ISNSFindTag (int start_indx, int key, ISNS_Attr **attr_indx); ISNS_Attr * ISNSFindKeyInResponseMsg (int key, ISNS_Msg * msg); int ISNSAppendAttr (ISNS_Msg * msg, int tag, int size, char *p_value, int value); int ISNSAppendKey (ISNS_Msg * msg, int tag, int size, char *p_value, int value); int ISNSAppendTimeStamp (ISNS_Msg * msg); #endif isns-2.1-01/isnsserver/include/ndb.h0000644000175000017500000000545010665040401016320 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* Modeled after gdbm functions */ /* Protection for multiple includes. */ #ifndef _NDB_H_ #define _NDB_H_ typedef struct { char *dptr; int dsize; } datum; /* The file information header. This is good enough for most applications. */ typedef struct {int dummy[10];} *NDB_FILE; typedef int ndb_error; /* For compatibilities sake. */ /* Determine if the C(++) compiler requires complete function prototype */ #ifndef __P #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus) #define __P(x) x #else #define __P(x) () #endif #endif extern NDB_FILE ndb_open __P((char *, int, int, int, void (*)())); extern void ndb_close __P((NDB_FILE)); extern int ndb_store __P((NDB_FILE, datum, datum, int)); extern datum ndb_fetch __P((uint32_t key_type, datum)); extern int ndb_delete __P((uint32_t, datum)); extern datum ndb_firstkey __P((uint32_t key_type)); extern datum ndb_nextkey __P((uint32_t key_type, datum)); extern datum ndb_fetch_sns (); extern datum ndb_firstkey_isns (uint32_t key_type, char *key); extern datum ndb_nextkey_isns (uint32_t key_type, datum key, char *pkey); #endif isns-2.1-01/isnsserver/include/iSNSparse.h0000644000175000017500000000413710665040401017425 0ustar zobelzobel/********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef _parse_h #define _parse_h #define MAX_PARSE_ATTRS 30 typedef int SNS_Error_Codes; typedef int SNS_Attr_Options; extern int ISNSParseMsg (ISNS_Msg * msg, ISNS_Attr **attr_index, ISNS_Attr **key_index, ISNS_Attr **src_attr); extern int SNSParseTransOpcode (int op_code); int SNSConvertPayloadNTOH(ISNS_Msg_Descp* p_md); void SNSConvertPayloadHTON(ISNS_Msg* msg); #endif isns-2.1-01/isnsserver/include/iSNSdebug.h0000644000175000017500000001277210665040401017405 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This header file contains definitions for enabling * and disabling debug tracing of iSNS code. * */ #ifndef _SNSdebug_h_ #define _SNSdebug_h_ #include #define LO_DETAIL 1 #define HI_DETAIL 2 #define ERR_MODULE_SNS 0x40000000 /* Name Server */ #define SNS_IPC_ERR 0x0001 #define SNS_BPOOL_ERR 0x0002 #define SNS_DBOPEN_ERR 0x0003 #define SNS_COMM_ERR 0x0004 #define SNS_QINIT_ERR 0x0005 #define SNS_SPAWN_ERR 0x0006 #define SNS_FSM_ERR 0x0007 #define SNS_ROLE_ERR 0x0008 #define SNS_WDTIMER_ERR 0x0009 #define SNS_BUFFER_WARN 0x0100 /* p1 is buffer size */ #define SNS_SYNCATTR_WARN 0x0200 /* p1 is response status of sync request */ #define SNS_SYNCFAIL_WARN 0x0300 #define SNS_SYNCMSG_WARN 0x0400 /* p1 is unexpected msg_type */ #define SNS_GETATTR_WARN 0x0500 /* p1 is tag, p2 is msg id, p3 is xid */ #define SNS_MSGRETRY_WARN 0x0600 /* p1 is msg id, p2 is xid */ #define SNS_VERSION_WARN 0x0700 /* p1 is current version, p2 is other version */ #define SNS_DEBUG_WARN 0x1 #define SNS_DEBUG_ERROR 0x2 #define SNS_DEBUG_FATAL 0x4 #define SNS_DEBUG_INFO 0x8 extern char sns_errmsg[]; extern int daemon_state; /* * Function declaration. */ void ISNSDisplay_iFCPNode (SOIP_Ifcp *p_node); void ISNSDisplay_FCNode (SOIP_Fc_Node *p_node); void ISNSDisplay_ISCSINode (SOIP_Iscsi *p_node, int detail); void ISNSDisplay_Entity (SOIP_Entity *p_entity, int detail); void ISNSDisplay_DDS( SOIP_Dds *p_dds, int detail ); void ISNSDisplay_DD( SOIP_Dd *p_dd, int detail ); void ISNSDisplayMsg (ISNS_Msg *msg); void ISNSDisplay_Hdr_Info (ISNS_Msg *msg); void ISNSDisplay_DbData(ISNS_Key *p_key, SOIP_DB_Entry *p_entry, int detail); void ISNSDisplay_Port_Name (SOIP_Port_Name *p_port, char *p_name); void ISNSDisplay_Node_Name (SOIP_Node_Name *p_node); void ISNSDisplay_Port_Id (SOIP_Port_Id *p_id); void ISNSDisplay_IPAddress (IP_Address *ip_addr); void ISNSDisplay_Port (SOIP_Ifcp *p_port); void ISNSDisplay_Node (SOIP_Node *p_node); void ISNSDisplay_IPAddr (IP_Address *ip_addr); void ISNSDisplay_Port_List (SOIP_Port_List *p_list); void ISNSDisplay_Port_TypeList (SOIP_Port_List *p_list); void ISNSDisplay_FC4TypeList (SOIP_Port_List *p_list); void ISNSDisplay_FC4Type (void *fc4_types, uint32_t attr_len); void ISNSDisplay_Zone_Tag (SOIP_Zone *p_zone); void ISNSDisplay_Zone_Priority (uint32_t *zone_priority); void ISNSDisplay_Zone (uint32_t *zone_tag); void ISNSDisplay_HardAddr (SOIP_Hard_Addr *hard_addr); void ISNSDisplay_NodeIPA (SOIP_Node_IPA *node_ipa); void ISNSDisplay_Node_SymName (char *sym_name); void ISNSDisplay_Port_SymName (char *sym_name); void ISNSDisplay_Port_Type (SOIP_Port_Type *p_type); void ISNSDisplay_Port_Cos (SOIP_COS *p_cos); void ISNSDisplay_Portal(SOIP_Portal *p_portal, int level); void ipaddrchar(void * ipaddrhex, void * ipaddrstr); char *FuncIDText (uint16_t funcid); char *isnsTagText (uint32_t tagid); char *errorText(int errorCode); void ParsePDU (char *buffer); #ifdef SNS_DEBUG #define __DEBUG(level, format, ...) ((level) ? isns_log(LOG_DEBUG,"%s:%d\t" #format "\n", __FILE__,__LINE__, ##__VA_ARGS__ ) : 0) #else #define __DEBUG(level, format, ...) #endif #define __LOG_INFO(format, ...) isns_log(LOG_INFO,"%s:%d\t" format "\n", __FILE__,__LINE__,##__VA_ARGS__) #define __LOG_ERROR(format, ...) isns_log(LOG_ERR,"%s:%d\t" format "\n", __FILE__,__LINE__,##__VA_ARGS__) #define __LOG_WARNING(format, ...) isns_log(LOG_WARNING,"%s:%d\t" format "\n", __FILE__,__LINE__,##__VA_ARGS__) void isns_log(int level, char *format, ...); #define __ISNS_COPY(a,b,c,d) if (b #include "iSNSmsg.h" #ifndef SNS_LINUX #define bcmp(a,b,c) memcmp(a,b,c) #endif /* * Default initialization value for device attributes. * When a database table is created all attributes are * initialized to SNS_UNREGISTERED */ #define SNS_UNREGISTERED 0xFF /* * Function prototypes */ typedef struct _dbStats { int num_dd; int num_dds; int num_entity; int num_iscsi; int num_ifcp; int num_portals; int num_portal_groups; } dbStats; extern int ISNSdbOpen (void); extern void ISNSdbClose (void); int SNSdbGetNextOfKey (ISNS_DBKey * key); int ISNSdbRead (ISNS_DBKey *key, SOIP_DB_Entry *entry); int ISNSdbWrite (ISNS_DBKey *key, SOIP_DB_Entry entry); int ISNSdbDelete (ISNS_DBKey *key); uint32_t ISNSGetNewPortalIdx(void); int ISNS_GetNewDDS_ID (void); int ISNS_GetNewDD_ID (void); uint32_t ISNSGetNewEntityIdx(void); uint32_t ISNSGetNewISCSIIdx(void); uint32_t ISNSGetNewPortalIdx(void); void ISNSInitDBTables (void); #endif isns-2.1-01/isnsserver/include/iSNSnt.h0000644000175000017500000000607610665040401016740 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef _ntsns_h #define _ntsns_h #define _WIN32_WINNT 0x0400 #include #include #include extern WSADATA g_WsaData; #define S_IRUSR 0x0100 /* read permission, owner */ #define S_IWUSR 0x0080 /* write permission, owner */ #define S_IRGRP 0x0020 /* read permission, group */ #define SNS_NT_FSM_TIMEOUT 10 #define SNS_NT_RS_TIMEOUT 10 #define WDOG_ID UINT_PTR #define OK SUCCESS #define FUNCPTR int #define tickGet GetTickCount #define bzero(a,b) {memset(a, 0, b);} #define inet_ntoa_b(a,b) {strcpy(b,inet_ntoa(a));} void* NTtaskSpawn(char* taskName, void* funcPtr); #define taskSpawn(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) NTtaskSpawn(a,e) #define close(a) _close(a) typedef char uint8_t; typedef unsigned int uint32_t; typedef unsigned short int uint16_t; typedef int STATUS; typedef HANDLE MSG_Q_ID; void wdCancel(void *timer); void taskDelay (int time); int sysClkRateGet(void); int wdStart(void *sns_request_timer, int next_timeout, void *nptr1, void *nptr2); int taskIdSelf(void); void taskSuspend(void); void taskDelete(int task); DWORD WINAPI SNSReqTimeoutThread(LPVOID lparam); DWORD WINAPI SNSFSMTimeoutThread(LPVOID lparam); DWORD WINAPI SNSESITimeoutThread(LPVOID lparam); DWORD WINAPI SNSResyncTimeoutThread(LPVOID lparam); void SNSTrap(void); #endif isns-2.1-01/isnsserver/include/iSNSquery.h0000644000175000017500000001141110665040401017451 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This file contains definitions related to iSNSreg * */ #ifndef _SNSquery_h_ #define _SNSquery_h_ extern int SNSdbGetAttr (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Attr *src_attr, ISNS_Msg_Descp * md); extern ISNS_Msg_Descp * SNSdbGetPorts(ISNS_Attr **attr_indx, ISNS_Msg_Descp *); extern int SNSdbGetPortName(IP_Address *ip, SOIP_Port_Id *id, SOIP_Port_Name *pn); int ISNS_GetDD_ID_from_sym ( char *p_sym ); int ISNS_GetDDS_ID_from_sym ( char *p_sym ); int ISNSGetNextEntityPortal( ISNS_Msg_Descp *p_md, ISNS_Msg * p_rspmsg ); int ISNSGetNextDDIscsiMember( ISNS_Msg_Descp *p_md, ISNS_Msg * p_rspmsg ); int ISNSGetNextDDSMember( ISNS_Msg_Descp *p_md, ISNS_Msg * p_rspmsg ); int ISNSGetNextAttr( ISNS_Msg_Descp *p_md, ISNS_Msg * p_rspmsg ); int IsDDActive(int dd_id, int exclude_dds_id); int IsDDSActive(int dds_id); int Get_Active_DD_List (ISNS_LIST *dd_list, ISNS_DD_LIST p_dlist, int flag); int ISNSdbProcessISCSIOpAttr (ISNS_Msg * p_msg, ISNS_Attr ** attr_indx, SOIP_Iscsi * p_node); int ISNSdbProcessFCNodeOpAttr (ISNS_Msg * p_msg, ISNS_Attr ** attr_indx, SOIP_Fc_Node * p_node); int Get_Active_DD_List_From_ISCSI_Node (char *nodename, ISNS_DD_LIST p_dlist, int flag); int Append_Nodes_From_DD_List (ISNS_DD_LIST p_dlist, SOIP_Dd_Member p_ddmem[], uint32_t type); int Get_Active_DD_List_From_IFCP_Node (char *nodename, ISNS_DD_LIST p_dlist, int flag); int Get_Active_DD_List_From_ENTITY_Node (char *p_entity_name, SOIP_Entity * p_entity, ISNS_DD_LIST p_list, int flag); int SNSProcessPortalOpAttr (ISNS_Msg * p_msg, ISNS_Attr ** attr_indx, SOIP_Portal * p_portal); int ISNSdbProcessPortOpAttr (ISNS_Msg * p_msg, ISNS_Attr ** attr_indx, SOIP_Ifcp * p_port); int ISNSdbProcessEntityOpAttr (ISNS_Msg * p_msg, ISNS_Attr ** attr_indx, SOIP_Entity *p_entity); int ISNSdbProcessDDSOpAttr(ISNS_Msg *p_msg, ISNS_Attr **attr_indx, SOIP_Dds *p_dds); int ISNSdbProcessDDOpAttr(ISNS_Msg *p_msg, ISNS_Attr **attr_indx, SOIP_Dd *p_dd); int ISNSGetNextEntityPortal( ISNS_Msg_Descp *p_md, ISNS_Msg * p_rspmsg ); int ISNSGetNextDDIscsiMember( ISNS_Msg_Descp *p_md, ISNS_Msg * p_rspmsg ); int ISNSGetNextDDSMember( ISNS_Msg_Descp *p_md, ISNS_Msg * p_rspmsg ); int ISNSdbGetAttr ( ISNS_Msg_Descp * p_md, ISNS_Msg * p_rspmsg ); int Get_Active_DD_List_From_IFCP_Node (char *nodename, ISNS_DD_LIST p_dlist, int flag); int SNSGet_Active_DD_List_From_Src (ISNS_Attr * src_attr, ISNS_DD_LIST p_dlist_src, int flag); int Get_Active_DD_List_From_ENTITY_Node (char *p_entity_name, SOIP_Entity * p_entity, ISNS_DD_LIST p_list, int flag); int Check_Permission (ISNS_Attr *src_attr, int rectype, void *ptr); #endif isns-2.1-01/isnsserver/include/iSNSqueue.h0000644000175000017500000000550510665040401017437 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This file contains definitions of data structures * and macros used for implementing queueing of * SoIP service requests that require a response from * a peer SoIP service entity. * */ #ifndef _SNSqueue_h_ #define _SNSqueue_h_ #include "iSNSmsg.h" /* * iSNS message descriptor queue names */ typedef enum { SNS_FSM_QUEUE, SNS_TRANSACTION_QUEUE, ISNS_CALLBACK_QUEUE, SNS_ZONE_ACCESS_QUEUE, SNS_PENDING_MSG_QUEUE, SNS_NUM_QUEUES } SNS_Queue_Name; /* * Queue descriptor for staging iSNS requests that are * awaiting a response from another SOIP service entity * This queue maintains a list of pointers to all iSNS * requests for which a response is outstanding. */ struct SNS_Msg_Descp_Q { ISNS_Msg_Descp *head; ISNS_Msg_Descp *tail; }; /* * iSNS queue management routines */ extern int SNSQInit (SNS_Queue_Name); extern void ISNSEnqReq (SNS_Queue_Name, ISNS_Msg_Descp *); extern ISNS_Msg_Descp * ISNSDeqReq (SNS_Queue_Name, uint16_t, int); ISNS_Msg_Descp * ISNSQHead (SNS_Queue_Name name); ISNS_Msg_Descp * SNSGetReq (SNS_Queue_Name name, int xid, int tid); #endif isns-2.1-01/isnsserver/include/iSNScomm.h0000644000175000017500000000617210665040401017247 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This file contains definitions of macros and data * structures used for implementing UDP socket based * communication between SOIP service entities. * */ #ifndef _SNSCOMM_h_ #define _SNSCOMM_h_ int ifAddrGet(char *, char *); int ifBroadcastGet(char *, char *); char snsp_ip[16]; char snsp_subnet[16]; #include "iSNSmsg.h" /* * Macros used for configuring the client/server socket * communication */ #define SNS_SCGRP_IPMC_ADDR "255.255.255.255" #define SNS_BROADCAST_ADDR "255.255.255.255" #define SNS_UDP_PORT 3205 #define SNS_MC_UDP_PORT 3206 #define SNS_LAYER_2 1 #define SNS_LAYER_3 2 #ifndef IN_CLASSD #define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000) #endif extern char snsp_ip[16]; extern char snsp_bip[16]; extern int snsp_port; extern uint32_t SNSGetServerAddr(void); extern int SNSCommInit (ISNS_Entity); extern int SNSGetMsg (ISNS_Msg_Descp *); extern int ISNSSendMsg (ISNS_Msg_Descp *); int SNSSendMsg_UDP(ISNS_Msg_Descp* p_md); int SNSSendMsg_TCP(ISNS_Msg_Descp* p_md); extern void ISNSCommUpdate (struct in_addr *); extern struct in_addr * SNSGetLocalAddr (void); extern struct in_addr * SNSGetMCgrpAddr (void); extern int ISNSSendMsg2Server (ISNS_Msg *); extern int SNSSendMsg2MCgrp (ISNS_Msg *); extern int SNSGetIfAddr(void); extern int SNSGetIfBroadcastAddr(void); extern int SNSGetMgmtAddr(void); extern int SNSGetIPAddress(void); #endif isns-2.1-01/isnsserver/include/iSNSdefs.h0000644000175000017500000002315010665040401017230 0ustar zobelzobel#if 0 *********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #endif #ifndef _ISNSDEFS_H_ #define _ISNSDEFS_H_ #define ISNS_VER_SIZE (4) #define ISNS_DD_FEATURE_BITMAP_SIZE (4) #define ISNS_ISCSI_TYPE_SIZE (4) #define ISNS_COMPANY_OUI_SIZE (4) #define ISNS_VENDOR_ID_SIZE (256) #define ISNS_NODE_ACTIVE_SIZE (4) #define ISNS_DD_ACTIVE_SIZE (4) #define ISNS_ENTITY_IDX_SIZE (4) #define ISNS_ISCSI_IDX_SIZE (4) #define ISNS_PORTAL_IDX_SIZE (4) #define ISNS_DD_ISCSI_MEMBER_IDX_SIZE (4) #define ISNS_ENTITY_PERIOD_SIZE (4) #define ISNS_ERROR_CODE_SIZE (4) #define ISNS_DDS_STATUS_SIZE (4) #define ISNS_DD_ID_SIZE (4) #define ISNS_DDS_ID_SIZE (4) #define ISNS_IP_SIZE (16) #define ISNS_TIMESTAMP_SIZE (8) #define ISNS_ESI_INTERVAL_SIZE (4) #define ISNS_PORTAL_IP_SIZE (16) #define ISNS_PORTAL_PORT_SIZE (4) #define ISNS_PORTAL_GROUP_IP_SIZE (16) #define ISNS_PORTAL_GROUP_PORT_SIZE (4) #define ISNS_ESI_PORT_SIZE (4) #define PORTAL_NAME_SIZE (ISNS_PORTAL_PORT_SIZE+ISNS_PORTAL_IP_SIZE) #define ISNS_DELIMITER_SIZE (0) #define ISNS_SCN_BITMAP_SIZE (4) #define ISNS_ENTITY_TYPE_SIZE (4) #define ISNS_PORT_SIZE (4) #define ISNS_PORT_TYPE_SIZE (4) #define ISNS_FC_NODE_IPA_SIZE (8) #define ISNS_FC_NODE_IP_SIZE (16) #define ISNS_PORT_NAME_SIZE (8) #define ISNS_IFCP_NODE_NAME_SIZE (8) #define ISNS_FC_NODE_NAME_SIZE (8) #define ISNS_FABRIC_PORT_NAME_SIZE (8) #define ISNS_FC_HARD_ADDR_SIZE (4) #define ISNS_FC_PORT_IP_SIZE (16) #define ISNS_FC_COS_SIZE (4) #define ISNS_FC4_TYPE_SIZE (32) #define ISNS_FC4_FEATURE_SIZE (128) #define ISNS_PORT_ID_SIZE (4) #define ISNS_NODE_NAME_SIZE (8) #define ISNS_ISCSI_NODE_TYPE_SIZE (4) #define PORTAL_SYM_NAME_SIZE (256) #define MAX_ENTITY_ID_SIZE (256) #define MAX_ISCSI_NODE_ID_SIZE (256) #define MAX_ISCSI_ALIAS_SIZE (256) #define MAX_SAN_SYM_NAME_SIZE (256) #define FC_FEATURE_SIZE (128) #define FC_DESCRIPTOR_SIZE (256) #define ISNS_SCN_BITMAP_SIZE (4) #define ISNS_PORTAL_GROUP_TAG_SIZE (4) #define DD_SET_ID_SIZE (4) #define DD_SET_STATUS_SIZE (4) #define DD_ID_SIZE (4) #define DD_IFCP_MEMBER_SIZE (8) #define DDS_SYM_NAME_SIZE (256) #define DD_SYM_NAME_SIZE (256) #define DD_MAX_DD_MEMBER_SIZE (256) #define ISNS_DETAIL_SCN (0x80000000) #define ISNS_SCN_DETAILED (0x80000000) /* New scn types */ #define ISNS_SCN_ALL (0x1F) #define ISNS_SCN_MEMBER_ADDED (0x1) #define ISNS_SCN_MEMBER_REMOVED (0x2) #define ISNS_SCN_OBJ_ADDED (0x4) #define ISNS_SCN_OBJ_REMOVED (0x8) #define ISNS_SCN_OBJ_UPDATED (0x10) #define ISNS_PROT_VER_SIZE (4) /* ISCSI TYPES */ #define ISNS_ISCSI_TYPE_TARGET (0x1) #define ISNS_ISCSI_TYPE_INITIATOR (0x2) #define ISNS_ISCSI_TYPE_CONTROL (0x4) #define ISNS_ISCSI_TYPE_REMOTE (0x8) #define ISNS_DD_FEATURE_BOOT_LIST_BIT (0x1) /* ISNS FUNCTION IDs */ typedef enum { /* Request */ ISNS_START_VALID_REQ_FUNC_ID=1, ISNS_REG_DEV_ATTR_REQ=ISNS_START_VALID_REQ_FUNC_ID, /* 1 */ ISNS_DEV_ATTR_QRY_REQ, ISNS_DEV_GET_NXT_REQ, ISNS_DEREG_DEV_REQ, ISNS_SCN_REG_REQ, /* 5 */ ISNS_SCN_DEREG_REQ, ISNS_SCN_EVENT, ISNS_SCN, ISNS_REG_DD_REQ, ISNS_DEREG_DD_REQ, ISNS_REG_DDS_REQ, ISNS_DEREG_DDS_REQ, ISNS_ESI=0xD, ISNS_HEART_BEAT, ISNS_REQ_SW_ID_REQ=0x11, ISNS_REL_SW_ID_REQ, ISNS_GET_SW_ID_REQ, ISNS_DDS_GET_NXT_MEMBER_REQ, ISNS_DD_GET_NXT_ISCSI_MEMBER_REQ, ISNS_ENTITY_GET_NXT_PORTAL_REQ, ISNS_END_VALID_REQ_FUNC_ID, /* Response */ ISNS_START_VALID_RES_FUNC_ID=0x8001, ISNS_REG_DEV_ATTR_RES=ISNS_START_VALID_RES_FUNC_ID, /* 0x8001 */ ISNS_DEV_ATTR_QRY_RES, ISNS_DEV_GET_NXT_RES, ISNS_DEREG_DEV_RES, ISNS_SCN_REG_RES, ISNS_SCN_DEREG_RES, ISNS_SCN_EVENT_RES, ISNS_SCN_RES, ISNS_REG_DD_RES, ISNS_DEREG_DD_RES, ISNS_REG_DDS_RES, ISNS_DEREG_DDS_RES, ISNS_ESI_RSP=0x800D, ISNS_REQ_SW_ID_RES=0x8011, ISNS_REL_SW_ID_RES, ISNS_GET_SW_ID_RES, ISNS_DDS_GET_NXT_MEMBER_RES, ISNS_DD_GET_NXT_ISCSI_MEMBER_RES, ISNS_ENTITY_GET_NXT_PORTAL_RES, ISNS_END_VALID_RES_FUNC_ID, } ISNS_FUNC_ID; /* ISNS Tags */ typedef enum { ISNS_DELIMITER=0, ISNS_START_VALID_TAG=1, /* ENTITY tags */ ISNS_ENTITY_ID=ISNS_START_VALID_TAG, /* 1 */ ISNS_ENTITY_TYPE, ISNS_MGMT_IP, ISNS_TIMESTAMP, ISNS_PROT_VER, ISNS_ENTITY_PERIOD, /* REGISTRATION PERIOD */ ISNS_ENTITY_IDX, ISNS_ENTITY_NEXT_IDX, ISNS_ENTITY_ISAKMP=11, ISNS_ENTITY_CERT, /* PORT tags */ ISNS_PORTAL_IP=16, /* 16 */ ISNS_PORTAL_PORT, ISNS_PORTAL_SYM_NAME, ISNS_ESI_INTERVAL, ISNS_ESI_PORT, ISNS_PORTAL_GROUP, /* tag was removed from RFC spec */ ISNS_PORTAL_IDX=22, ISNS_SCN_PORT, ISNS_PORTAL_NEXT_IDX, ISNS_PORTAL_SECURITY_BITMAP=27, ISNS_PORTAL_CERT=31, /* ISCSI node tags */ ISNS_ISCSI_NODE_ID=32, /* 32 */ ISNS_ISCSI_TYPE, ISNS_ISCSI_ALIAS, ISNS_ISCSI_SCN_BITMAP, ISNS_ISCSI_IDX, ISNS_WWNN_TOKEN, ISNS_ISCSI_NEXT_IDX, ISNS_ISCSI_CERT=40, /* PORTAL_GROUP tags */ ISNS_PORTAL_GROUP_ISCSI_NAME=48, ISNS_PORTAL_GROUP_IP, ISNS_PORTAL_GROUP_PORT, ISNS_PORTAL_GROUP_TAG, ISNS_PORTAL_GROUP_IDX, ISNS_PORTAL_GROUP_NEXT_IDX, /* FC */ ISNS_PORT_NAME=64, /* 64 */ ISNS_PORT_ID, ISNS_PORT_TYPE, ISNS_PORT_SYM_NAME, ISNS_FABRIC_PORT_NAME, ISNS_FC_HARD_ADDR, ISNS_FC_PORT_IP, ISNS_FC_COS, ISNS_FC4_TYPE, ISNS_FC4_DESC, ISNS_FC4_FEATURE, ISNS_IFCP_SCN_BITMAP, ISNS_IFCP_NODE_CERT=80, iSNS_FC4_TYPE_QUERY_KEY=95, ISNS_NODE_NAME, ISNS_NODE_SYM_NAME, ISNS_FC_NODE_IP, ISNS_FC_NODE_IPA, ISNS_FC_NODE_CERT, /* Server specific tags */ ISNS_VENDOR_ID = 131, ISNS_VENDOR_REV, ISNS_PRIMARY_VER, ISNS_PRIMARY_IP, ISNS_PRIMARY_TCP_PORT, ISNS_PRIMARY_UDP_PORT, ISNS_PRIMARY_MGMT_IP, ISNS_COMPANY_OUI = 256, /* Nishan vendor specific tags */ ISNS_SCN_CALLBACK = 257, ISNS_DD_ACTIVE, ISNS_NODE_ACTIVE, ISNS_END_VALID_TAG, /* DDS tags */ ISNS_DDS_ID=2049, ISNS_DDS_SYM_NAME, ISNS_DDS_STATUS, /* DD tags */ ISNS_DD_ID=2065, ISNS_DD_SYM_NAME, ISNS_DD_ISCSI_MEMBER_IDX, ISNS_DD_ISCSI_MEMBER, ISNS_DD_IFCP_MEMBER, ISNS_DD_PORTAL_MEMBER_IDX, ISNS_DD_PORTAL_IP_ADDR, ISNS_DD_PORTAL_TCPUDP, ISNS_DD_FEATURE_BITMAP=2078, ISNS_DD_NEXT_ID } ISNS_TAG; /* ISNS Entity types */ typedef enum { NO_PROTOCOL=1, ENTITY_TYPE_ISCSI, ENTITY_TYPE_IFCP, } ISNS_ENITITY_TYPES; /* ISNS Flags */ #define ISNS_FLAG_FIRST_PDU (0x400) #define ISNS_FLAG_LAST_PDU (0x800) #define ISNS_FLAG_REPLACE_REG (0x1000) #define ISNS_FLAG_AUTH (0x2000) #define ISNS_FLAG_SND_SERVER (0x4000) #define ISNS_FLAG_SND_CLIENT (0x8000) /* ISNS Error Codes */ typedef enum { ISNS_NO_ERR=0, ISNS_UNKNOWN_ERR, ISNS_MSG_FMT_ERR, ISNS_INVALID_REG_ERR, ISNS_ESI_TOO_SHORT, ISNS_INVALID_QUERY_ERR, ISNS_AUTH_UNKNOWN_ERR, ISNS_AUTH_ABSENT_ERR, ISNS_AUTH_FAILED_ERR, ISNS_NO_SUCH_ENTRY_ERR, ISNS_VER_NOT_SUPPORTED_ERR, ISNS_INT_BUS_ERR, ISNS_BUSY_NOW_ERR, ISNS_OPTION_NOT_UNDERSTOOD_ERR, ISNS_INVALID_REG_UPD_ERR, ISNS_MSG_NOT_SUPPORTED_ERR, ISNS_SCN_EVENT_REJECTED_ERR, ISNS_SCN_REG_REJECTED_ERR, ISNS_SW_ID_NOT_AVAIL, ISNS_SW_ID_NOT_ALLOC, } ISNS_ERROR_CODES; #define ISNS_SIZEOF_TAG ( sizeof(uint32_t) + sizeof(uint32_t) ) #ifndef PAD4 #define PAD4(a) ( (a % 4) ? (4 - (a % 4) ) + a: (a+4) ) #endif #undef SUCCESS #define SUCCESS 0 #undef ERROR #define ERROR 1 #ifndef MIN #define MIN(a,b) ((a) <= (b) ? (a) : (b)) #endif #endif isns-2.1-01/isnsserver/include/iSNShash.h0000644000175000017500000000446410665040401017241 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef _SNS_HASH_H_ #define _SNS_HASH_H_ #define HASH_KEY_TABLE_NUM_ENTRIES 256 #define HASH_NUM_PORTS_SUPPORTED 256 #define HASH_TABLE_NUM_ENTRIES HASH_NUM_PORTS_SUPPORTED*4 #define HASH_NUM_BUFFERS HASH_NUM_PORTS_SUPPORTED*4 #define HASH_BUFFER_SIZE (sizeof(SNSHashEntry)+sizeof(SOIP_DB_Entry)) #define HASH_KEY_SIZE 256 #define HASH_MAX_DATA_SIZE sizeof(SOIP_DB_Entry) typedef struct _sns_hash_entry { struct _sns_hash_entry *next; struct _sns_hash_entry *prev; uint16_t key_len; uint16_t data_len; uint8_t key[HASH_KEY_SIZE]; uint8_t data[4]; } SNSHashEntry; #endif isns-2.1-01/isnsserver/include/iSNSobjects.h0000644000175000017500000000762310665040401017747 0ustar zobelzobel/*********************************************************************** Copyright (c) 2007, Novell, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Novell, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Novell, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This file contains definitions related to read and writing of database objects * */ #ifndef _SNSobjects_h_ #define _SNSobjects_h_ int read_FCNodeObject (char *p_id, SOIP_Fc_Node ** p_node, SOIP_DB_Entry *p_entry); int read_FCPortObject (char *p_id, SOIP_Ifcp ** p_port, SOIP_DB_Entry *p_entry); int read_ISCSIObject (char *p_id, SOIP_Iscsi ** p_node, SOIP_DB_Entry *p_entry); int read_EntityObject (char *p_entity_id, SOIP_Entity ** p_entity, SOIP_DB_Entry *p_entry); int read_PortalObject (SOIP_Portal_Key *p_portal_key, SOIP_Portal ** p_portal, SOIP_DB_Entry *p_entry); int read_PortalGroupObject (SOIP_Portal_Group_Key *p_portal_key, SOIP_Portal_Group ** p_portal, SOIP_DB_Entry *p_entry); int read_DDObject (int id, SOIP_Dd ** p_dd, SOIP_DB_Entry * p_entry); int read_DDSObject (int id, SOIP_Dds ** p_dds, SOIP_DB_Entry * p_entry); int read_EntityidxObject (int id, void **p_idx, SOIP_DB_Entry *p_entry); int read_ISCSIidxObject (int id, void **p_idx, SOIP_DB_Entry *p_entry); int read_PortalidxObject (int id, void **p_idx, SOIP_DB_Entry *p_entry); int write_FCNodeObject (char *p_id, SOIP_DB_Entry p_entry); int write_FCPortObject (char *p_id, SOIP_DB_Entry p_entry); int write_ISCSIObject (char *p_id, SOIP_DB_Entry p_entry); int write_EntityObject (char *p_entity_id, SOIP_DB_Entry p_entry); int write_PortalObject (SOIP_Portal_Key *p_portal_key, SOIP_DB_Entry p_entry); int write_PortalGroupObject (SOIP_Portal_Group_Key *p_portal_key, SOIP_DB_Entry p_entry); int write_DDObject (int id, SOIP_DB_Entry p_entry); int write_DDSObject (int id, SOIP_DB_Entry p_entry); int write_ISCSIidxObject( int id, SOIP_DB_Entry p_entry); int write_EntityidxObject( int id, SOIP_DB_Entry p_entry); int write_PortalidxObject( int id, SOIP_DB_Entry p_entry); int delete_FCNodeObject (char * p_id); int delete_FCPortObject (char * p_id); int delete_ISCSIObject (char * p_id); int delete_EntityObject (char * p_entity_id); int delete_PortalObject (SOIP_Portal_Key * p_portal_key); int delete_PortalGroupObject (SOIP_Portal_Group_Key * p_portal_key); int delete_DDObject (int id); int delete_DDSObject (int id); int delete_EntityidxObject (int id); int delete_ISCSIidxObject (int id); int delete_PortalidxObject (int id); #endif isns-2.1-01/isnsserver/include/iSNSesi.h0000644000175000017500000000361210665040401017070 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This file contains definitions related to iSNSreg * */ #ifndef _SNSesi_h_ #define _SNSesi_h_ int ISNS_SendESI(void); int ISNS_ProcessESI ( ISNS_Msg_Descp *p_md ); #endif isns-2.1-01/isnsserver/include/iSNSfsm.h0000644000175000017500000000515210665040401017076 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef _SNSfsm_h_ #define _SNSfsm_h_ #include #include "iSNSmsg.h" typedef enum { SNS_INIT, SNS_WFHB, SNS_WFCOMM, SNS_WFDACK, SNS_ELECTION, SNS_PRIMARY, SNS_FSM_INVALID, SNS_NUM_FSM_STATES } SNS_State; typedef enum { SNS_HEARTBEAT_RCVD, SNS_COMM_REQ_RCVD, SNS_COMM_ACK_RCVD, SNS_CLAIM_RCVD, SNS_DISCOVERY_RCVD, SNS_HEARTBEAT_TIMEOUT, SNS_TRANS_TO_WFCOMM, SNS_RESYNC_START, SNS_RESYNC_START_RES, SNS_RESYNC_END, SNS_RESYNC_END_RES, SNS_SYNC_TIMEOUT, SNS_NUM_FSM_EVENTS } SNS_FSM_Event; struct SNS_fsm { SNS_State next_state; void (*action)(); }; extern int SNSStartFSM(void); void SNSFSMTimeoutHdlr(void); void SNSESIStartTimer(int timeout); void SNSESITimeoutHdlr(void); extern void SNSProcFSM(SNS_FSM_Event, void *); extern void SNSSetNotifyUser(void *ptr); #endif isns-2.1-01/isnsserver/include/iSNSipc.h0000644000175000017500000000575410665040401017074 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This file contains definitions of data structures, macros * and function prototypes used to support a message queue * based IPC service * */ #ifndef _IPCmessage_h_ #define _IPCmessage_h_ #define MAX_SNS_EP_BUFFERS 256 #define MAX_DEVICE_MGMT_EP_BUFFERS 20 /* * End Point Names of switch software entities */ typedef enum { FIRST_EP_NAME = 0, DEVICE_MGMT_EP = FIRST_EP_NAME, SNS_EP, LAST_EP_NAME = SNS_EP, NUM_IPC_EP_NAMES = LAST_EP_NAME + 1 } IPC_EP_Name; /* * Message queue based IPC endpoint used for communicating with * a local switch software entity. */ typedef struct ipc_ep { SOCKET s; struct sockaddr_in their_addr; } IPC_EP; #if 0 #define VALID_EP_NAME(x) (((x < FIRST_EP_NAME) && (x > LAST_EP_NAME)) ? 0 : 1) #endif #define VALID_EP_NAME(x) (1) #define IPC_NO_WAIT 1 #define IPC_MSG_PRI_HI 2 /*----------------------------------------------------------- * Function prototypes *----------------------------------------------------------- */ extern int SendIPCMessage (IPC_EP_Name, void *, int, int); extern int ReceiveIPCMessage (IPC_EP_Name, void *, int, int); extern int CreateIPCEndPoint (IPC_EP_Name); extern int DestroyIPCEndPoint (IPC_EP_Name); extern void InitIPCEndPoints (void); #endif isns-2.1-01/isnsserver/include/iSNSmsg.h0000644000175000017500000001340410665040401017076 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef _SNSMsg_h_ #define _SNSMsg_h_ #include "iSNSipc.h" #include "iSNStypes.h" #define SNS_MAX_ETH_PACKET_SIZE 1440 #define SNS_OLD_MAX_PACKET_SIZE (SNS_MSG_PAYLOAD_SIZE + sizeof(SNS_Msg_Hdr)) #define SNS_MSG_PAYLOAD_SIZE 8*1024 typedef struct sns_msg_hdr { uint16_t version; uint16_t type; uint16_t msg_len; uint16_t flags; uint16_t xid; uint16_t sequence; } SNS_Msg_Hdr, ISNS_Msg_Hdr; /* * Definition of sns_msg_hdr flags */ #define SOIP_ENTITY_PRIMARY_SERVER 1 #define SOIP_ENTITY_SECONDARY_SERVER 2 #define SOIP_ENTITY_CLIENT 4 #define SOIP_OPERATION_FAILURE 8 /* * Definition of SoIP service message types. */ typedef enum { /* USED INTERNALLY FOR THE STATE MACHINE */ START_FSM_MSG_TYPE = 0xF150, DISCOVERY, CLAIM, REQ_TIMEOUT_EVENT, FSM_TIMEOUT_EVENT, TRANS_FROM_PRIMARY, VERIFY_COMM_REQ, VERIFY_COMM_RES, TRANS_TO_WFCOMM, ESI_TIMEOUT_EVENT, END_FSM_MSG_TYPE } SNS_Msg_Type; /* * Heartbeat message */ typedef struct sns_hb_payload { IP_Address ip_addr; uint16_t udp_port; uint16_t tcp_port; uint32_t interval; /* heartbeat interval */ uint32_t counter; /* incremental hb counter */ } SNS_Hb, ISNS_Hb; /* * Register Device Attribute message */ typedef struct sns_req_payload { ISNS_Key key; } SNS_Req; typedef struct SNS_reg_callback_req { union { void (*rfunc) (uint32_t xid, uint32_t status); void (*qfunc) (uint32_t xid, uint32_t status, ISNS_ATTR_VALS_CB *attr_vals_sptr); } func_val; } SNS_Reg_Callback_Req; /* * SOIP service agent message */ typedef struct ISNS_msg { SNS_Msg_Hdr hdr; union { uint32_t errorCode; uint32_t error_code; /* maximum size of a message */ uint8_t payload_data[SNS_MSG_PAYLOAD_SIZE]; /* heartbeat payload */ SNS_Hb heartbeat; /* sns attr request payload */ SNS_Req sns_req; /* callback payload */ SNS_Reg_Callback_Req rcb_req; } payload; } __attribute__((packed)) ISNS_Msg; /* * iSNS message descriptor block contains control information * pertaining to the message. */ typedef struct SNS_msg_cb { /* * Sender ID */ ISNS_Entity sender; /* * Address information associated with the sender */ ISNS_Socket_Ep sock; /* * Queue pointers used for enqueuing requests that * require a response from the peer SOIP service * entity */ struct ISNS_msg_descp *next; struct ISNS_msg_descp *prev; /* * Timeout value (in seconds) associated with an outstanding * request. */ long double resp_timeout; /* * Number of times this message is to be retransmitted * Every time there is response timeout for this message * the retransmit count is decremented and the message is * retransmitted. When the count reaches zero the message * is discarded */ int ttl; /* * This is used to indicate the messages are in the * registration queue prior to the server being online. */ int init_rmsg; /* * The task identifier. This is used to map an attribute * registration request with its callback function. */ int task_id; /* * Identifies the status of the transaction. */ int xid_status; /* Callback function */ union { void (*reg_func) (uint32_t xid, uint32_t status); void (*query_func) (uint32_t xid, uint32_t status, ISNS_ATTR_VALS_CB *avcb_ptr); } callback_func; } SNS_Msg_Cb, ISNS_Msg_Cb; /* * Message descriptor used for staging a received message along * with address information associated with the sender of the * message */ typedef struct ISNS_msg_descp { /* * Control block */ SNS_Msg_Cb cb; /* * iSNS message */ ISNS_Msg msg; } ISNS_Msg_Descp; #endif isns-2.1-01/isnsserver/include/iSNSreg.h0000644000175000017500000001533410665040401017071 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This file contains definitions related to iSNSreg * */ #ifndef _SNSreg_h_ #define _SNSreg_h_ #include #include "iSNSmsg.h" extern int SNSdbAddAttr (char **attr_indx, char **key_indx, ISNS_Msg_Descp * p_md); extern int SNSDeRegisterSCN (char **attr_indx, char **key_indx, ISNS_Attr * src_attr, ISNS_Msg * rspmsg); extern STATUS SNSRemoveAllPortsFromNode(SOIP_Node_Name nn); extern void ISNS_CheckEntities (void); int ISNS_RegisterSCNCallback(ISNS_Msg_Descp* p_md); int ISNSTouchEntity(ISNS_Attr* src_attr); int change_dd_member_active_flag( SOIP_Dd *p_dd ); int ISNS_DeRegisterSCN ( ISNS_Msg_Descp * p_md, ISNS_Msg * rspmsg); int ISNS_RegisterSCN (ISNS_Msg_Descp * p_md, ISNS_Msg * rspmsg); int ISNSdbRemoveAttr (ISNS_Msg_Descp * p_md, ISNS_Msg * rspmsg); int ISNSdbRemoveAttrDD ( ISNS_Msg_Descp * p_md, ISNS_Msg * p_rspmsg ); int ISNSdbRemoveAttrDDS ( ISNS_Msg_Descp * p_md, ISNS_Msg * p_rspmsg ); int ISNSAddSCNEntry(uint32_t type, char *nodename, uint32_t bitmap, int sockfd); int ISNSRemoveSCNEntry(uint32_t type, char *nodename); int Copy_DD_List(ISNS_LIST *dd_list, ISNS_DD_LIST p_dlist); int SNSRemovePortalEntry (SOIP_Portal_Key *portal_key, ISNS_Attr * src_attr, ISNS_Msg * p_rspmsg); int ISNSdbAddAttr (ISNS_Msg_Descp * p_md, ISNS_Msg *rspMsg); int ISNSdbAddAttrPortal (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Msg_Descp * p_md, ISNS_Msg * p_rspmsg); int ISNSdbAddAttrPortalGroup (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Msg_Descp * p_md, ISNS_Msg * p_rspmsg); int SNSdbAddAttrPort (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Msg_Descp * p_md, ISNS_Msg * p_rspmsg); int SNSdbRemoveAttrPort (ISNS_Attr **key_indx, ISNS_Attr *src_attr, ISNS_Msg_Descp * p_md, ISNS_Msg * rspmsg); int AddCert (void **ptr, int *size, void *p_cert, int cert_size); int RemoveCert (void **ptr); int SNSRemoveIFCPNodeEntry (char *ifcp_node_key, ISNS_Attr * src_attr, ISNS_Msg * p_rspmsg); int Activate_DD_Membership (uint32_t type, void *p_node); int SNSRemoveFCNodeEntry (char *p_key, ISNS_Msg * p_rspmsg); int Check_Overlap_DD (ISNS_DD_LIST p_dlist_src, ISNS_DD_LIST p_dlist_node); int SNSRemoveISCSINodeEntry (char *iscsi_node_key, ISNS_Attr * src_attr, ISNS_Msg * p_rspmsg); int ISNSdbAddAttrNode (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Msg_Descp * p_md, ISNS_Msg * p_rspmsg); int SNSdbAddAttrEntity (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Msg_Descp * p_md, ISNS_Msg * p_rspmsg); int Remove_DD_from_ISCSI_Node (SOIP_Dd *p_dd, char *p_node_name); int Add_dds_to_dd (SOIP_Dds *p_dds, int dd_id); int Remove_DD_from_IFCP_Node (int id, char *p_node_name); int Add_DD_to_ISCSI_Node (SOIP_Dd *p_dd, char *p_node_name); int Add_DD_Member (SOIP_Dd * p_dd, char *ptr, int p_len, uint32_t type, uint32_t status, uint32_t index); int Remove_DD_Member (SOIP_Dd *p_dd, char *ptr, uint32_t type); int Add_DD_to_IFCP_Node (int id, char *p_node_name); int Remove_dd_from_dds (SOIP_Dds * p_dds, int id); int ISNSdbAddAttrISCSINode (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Msg_Descp * p_md, ISNS_Msg * p_rspmsg); int SNSdbRemoveAttrEntity (ISNS_Attr **key_indx, ISNS_Attr *src_attr, ISNS_Msg_Descp * md, ISNS_Msg * rspmsg); int ISNSdbRemoveAttrEntityEntry (char *p_entity_id, ISNS_Attr * src_attr, ISNS_Msg * p_rspmsg); int ISNSdbAddAttrDDS ( ISNS_Msg_Descp * p_md, ISNS_Msg * p_rspmsg ); int ISNSdbAddAttrDD ( ISNS_Msg_Descp * p_md, ISNS_Msg * p_rspmsg ); int ISNSdbProcessDDOpAttr(ISNS_Msg *p_msg, ISNS_Attr **attr_indx, SOIP_Dd *p_dd); int ISNS_GetNewDDS_ID (void); int ISNS_GetNewDD_ID (void); int Check_Unique_DDS_Sym (SOIP_Dds * p_dds, char *p_sym_name); int Check_Unique_DD_Sym (SOIP_Dd * p_dd, char *p_sym_name); uint32_t ISNSGetNewEntityIdx(void); uint32_t ISNSGetNewISCSIIdx(void); uint32_t ISNSGetNewPortalIdx(void); int SNSdbRemoveAttrDDS_Entry(int id, ISNS_Attr *src_attr, ISNS_Msg *p_rspmsg); int SNSdbRemoveDD_Entry(int id, ISNS_Attr *src_attr, ISNS_Msg *p_rspmsg); int SNSdbRemoveDD_Member (int id, ISNS_Attr **attr_indx, ISNS_Attr * src_attr, ISNS_Msg * p_rspmsg); int Disable_DD_Member (SOIP_Dd * p_dd, char *ptr, uint32_t type); int SNSdbAddAttrPort (ISNS_Attr **attr_indx, ISNS_Attr **key_indx, ISNS_Msg_Descp * p_md, ISNS_Msg * rspmsg); int SNSdbRemoveAttrISCSI (ISNS_Attr **key_indx, ISNS_Attr *src_attr, ISNS_Msg_Descp * p_md, ISNS_Msg * rspmsg); int SNSdbRemoveAttrNode (ISNS_Attr **key_indx, ISNS_Attr *src_attr, ISNS_Msg_Descp * p_md, ISNS_Msg * rspmsg); int SNSdbRemoveAttrPortal (ISNS_Attr **key_indx, ISNS_Attr *src_attr, ISNS_Msg_Descp * p_md, ISNS_Msg * rspmsg); int Append_DD_to_List (ISNS_DD_LIST p_dlist, uint32_t id); int Create_Default_DD(); int Check_Authorization (ISNS_Attr *src_attr); #endif isns-2.1-01/isnsserver/include/iSNSscn.h0000644000175000017500000000410610665040401017072 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * This file contains definitions related to iSNSreg * */ #ifndef _SNSscn_h_ #define _SNSscn_h_ int send_iscsi_scn_to_members ( SOIP_Iscsi * p_src_node, char *p_src_name, ISNS_Msg *p_msg, uint32_t event_bitmap ); int ISNS_Process_SCN_Event (ISNS_Msg *p_msg); int ISNS_Process_SCN(ISNS_Msg_Descp *p_md, ISNS_Msg *p_rsp_msg); #endif isns-2.1-01/isnsserver/include/iSNStbl.h0000644000175000017500000000455210665040401017075 0ustar zobelzobel/*********************************************************************** Copyright (c) 2001, Nishan Systems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Nishan Systems, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NISHAN SYSTEMS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef _SNSTbl_h_ #define _SNSTbl_h_ #include "iSNSmsg.h" #define MAX_ENTRIES (64) #define MAX_ESI_ENTRIES (MAX_ENTRIES) #define MAX_SCN_ENTRIES (MAX_ENTRIES) typedef struct _scn_entry { int type; char name[256]; } SCN_ENTRY; typedef struct _esi_entry { char ip_ptr[16]; uint32_t port; uint32_t esi_port; char entity_id[256]; uint32_t sockfd; uint32_t interval; } ESI_ENTRY; void InitAllTables(void); /*************************/ void InitESITable(void); int GetESIIntervalMaxTime(void); /*************************/ void InitSCNTable(void); int FindESIEntry(char* p_ip, uint32_t port); #endif isns-2.1-01/isnsserver/ReleaseNotes.txt0000644000175000017500000000476410665035152017131 0ustar zobelzobelRelease 2.0.3 02/07/2007 ------------------------------- Changed output display of Discovery Domain Sets Release 2.0 01/04/2007 ------------------------------- Upgraded to latest RFC specification Added persistent database support Fixed much of the registration, degregistration, and query processing. Release 1.2.1 4/2/2002 ------------------------- Update to public release BUG FIX: corrected reported issues Release 1.2.0 10/3/2001 ------------------------- Update to public release FEATURE: this version supports both Linux v7.1/v6.2 and Windows NT4.0/2000 FEATURE: added entity, node and portal indexes to allow use with SNMP CHANGE: added replace bit functionality BUG FIX: corrected many issues in DD/DDS/Node and SCN processing Release 1.1.5 8/22/2001 ------------------------- Update to public release CHANGE: Modified Open Source License Release 1.1.4 8/6/2001 ------------------------- Update to public release CHANGE: Modified DD/DDS description in the README documentation of the release. (client) BUG FIX: Portal ports of type UDP were not registered correctly. (server) BUG FIX: Portals from different entities were not correctly returned in a query. Release 1.1.3 6/22/2001 ------------------------- Update to public release CHANGE: Added more text to the README documentation of the release. FEATURE: Added control type node support to the server. Release 1.1.2 6/19/2001 ------------------------- Update to public release (server) CHANGE : Added msg type "SAVE_DB_REQ" to enum to test out save/load feature. FEATURE: iSNS now will save and load DD/DDS information on startup use the [-l] option. BUG FIX: SCN was not sent out for all DDS updates. BUG FIX: Many other small SCN problems. (client) FEATURE: Added Save DD/DDS option to the menu. BUG FIX: Removed some unnecessary enum. Release 1.1.1 6/6/2001 ------------------------- Update to public release (server) FEATURE: Entity ID and iSCSI ID can be the same name. BUG FIX: Entity timestamp wasn't being updated during some updates. BUG FIX: DD/DDS ID of 0 is being rejected. BUG FIX: iSCSI Node Query with iSCSI Node key has been fixed. BUG FIX: Removed "-c" from server help. BUG FIX: Queries with certain src returned wrong nodes. (client) CHANGE : replaced all occurrances of "iSCSI Type" with "Node Type Bitmask." CHANGE : removed option to have source of type Entity ID CHANGE : Clarified the wording for iSCSI Node queries FEATURE: Added PORTAL/ENTITY attr to iSCSI queries. Release 1.1.0 5/29/2001 ------------------------- Public Distribution Release