141 default :
return "Undefined Tag Name";
155 switch (error_number) {
179 default :
return "UNDEFINED ERROR CODE!";
204 ocs_log_test(iscsi->
os,
"iSNS ERROR: Failed to create the node\n");
258 char v4_start[16] =
"0:0:0:0:0:ffff";
263 ocs_log_test(iscsi->
os,
"iSNS ERROR: ip pointer is NULL");
267 ocs_memcpy(temp, ip, 14);
268 if(ocs_strcmp(temp, v4_start)) {
279 for( i = 0; i < 4; i++) {
282 for( i = 4; i < 16; i++) {
310 ipp = n->
ipp + ip_index;
334 ipp = n->
ipp + ip_index;
353 uint8_t passed_first_node = 0;
354 uint16_t ipps_count = 0;
355 uint16_t nodes_index = 0;
361 while (bytes_left > 0) {
362 ocs_memcpy(&tag, rsp_ptr, 4);
363 tag = ocs_be32toh(tag);
367 ocs_memcpy(&len, rsp_ptr, 4);
368 len = ocs_be32toh(len);
373 passed_first_node = 1;
376 ocs_isns_log(iscsi->
os,
"node #%d has %d ipps\n", nodes_index++, ipps_count);
378 ocs_log_err(iscsi->
os,
"iSNS ERROR: can't create a node!\n");
388 ocs_log_test(iscsi->
os,
"ERROR: UNDEFINED ATTR 0x%x between the NODES!!\n", tag);
394 if(bytes_left == 0) {
396 ocs_isns_log(iscsi->
os,
"node #%d has %d ipps\n", nodes_index++, ipps_count);
398 ocs_log_err(iscsi->
os,
"iSNS ERROR: can't create a node!\n");
428 uint16_t nodes_index = 0;
429 uint16_t ipp_index = 0;
434 while (bytes_left > 0) {
435 ocs_memcpy(&tag, rsp_ptr, 4);
436 tag = ocs_be32toh(tag);
440 ocs_memcpy(&len, rsp_ptr, 4);
441 len = ocs_be32toh(len);
448 ocs_memcpy(temp_node->
iname, rsp_ptr, len );
454 ocs_memcpy(temp_ipp->
ip, ip_addr, ocs_strlen(ip_addr));
458 v32 = ocs_htobe32( * (uint32_t *) rsp_ptr);
459 ocs_memcpy(&temp_ipp->
port, &v32,
sizeof(uint32_t));
463 ocs_log_test(iscsi->
os,
"ERROR: UNDEFINED ATTR 0x%x between the NODES!!\n", tag);
470 ocs_isns_log(iscsi->
os,
"\t\t\tISNS node fill attributes done\n");
556 ocs_memset( curr, 0, 8);
579 int padsize = len & 3;
583 padsize = 4 - padsize;
585 push = 2 *
sizeof(uint32_t) + len + padsize;
586 if (remaining < push) {
591 t = ocs_htobe32(tag);
592 ocs_memcpy(curr, &t,
sizeof(uint32_t));
593 curr +=
sizeof(uint32_t);
594 l = ocs_htobe32(len + padsize) ;
595 ocs_memcpy(curr, &l,
sizeof(uint32_t));
596 curr +=
sizeof(uint32_t);
601 *((uint16_t*)curr) = ocs_htobe16( * (uint16_t *) value);
604 *((uint32_t*)curr) = ocs_htobe32( * (uint32_t *) value);
607 *((uint64_t*)curr) = ocs_htobe64( * (uint64_t *) value);
610 ocs_log_test(iscsi->
os,
"Error: value attribute must be of size 2, 4, or 8 Bytes.\n");
615 t = ocs_htobe32(tag);
616 ocs_memcpy(curr, &t,
sizeof(uint32_t));
617 curr +=
sizeof(uint32_t);
618 l = ocs_htobe32(len + padsize);
619 ocs_memcpy(curr, &l,
sizeof(uint32_t));
620 curr +=
sizeof(uint32_t);
622 ocs_memcpy(curr, value, len);
627 ocs_memset(curr, 0, padsize);
655 for(i = 0; i < 10; i++)
659 for(i = 0; i < 4; i++)
675 ocs_isns_log(iscsi->
os,
"\t\t\tParsing flags (0x%x)of the response message\n", flags);
677 if (flags >> 2 & 1) {
682 if (flags >> 3 & 1) {
687 if (flags >> 4 & 1) {
692 if (flags >> 5 & 1) {
697 if (flags >> 6 & 1) {
702 if (flags >> 7 & 1) {
719 uint16_t version, func_id, payload_len, flags, transaction_id, sequence_id;
722 ocs_isns_log(iscsi->
os,
"\t\t\tISNS: PARSING THE HEADER OF THE RSP MSG\n");
724 ocs_memcpy(&version, rsp, 2);
727 ocs_memcpy(&func_id, rsp, 2);
730 ocs_memcpy(&payload_len, rsp, 2);
733 ocs_memcpy(&flags, rsp, 2);
736 ocs_memcpy(&transaction_id, rsp, 2);
739 ocs_memcpy(&sequence_id, rsp, 2);
742 ocs_isns_log(iscsi->
os,
"version is (%x) \n", ocs_be16toh(version));
743 ocs_isns_log(iscsi->
os,
"func_id is (%d) \n", ocs_be16toh(func_id));
744 ocs_isns_log(iscsi->
os,
"payload_len is (%d) \n", ocs_be16toh(payload_len));
745 ocs_isns_log(iscsi->
os,
"flags is (0x%x) \n", ocs_be16toh(flags));
746 ocs_isns_log(iscsi->
os,
"transaction_id is (%d) \n", ocs_be16toh(transaction_id));
747 ocs_isns_log(iscsi->
os,
"sequence_id is (%d) \n", ocs_be16toh(sequence_id));
765 uint32_t error_code = 0;
766 int16_t bytes_left = rsp_len;
769 uint8_t delimiter_parsed = 0;
776 uint16_t nodes_count = 0;
778 void *nodes_ptr = NULL;
789 ocs_isns_log(iscsi->
os,
"\t\t\tPARSING THE PDU OF THE RSP MSG\n");
791 ocs_memcpy(&error_code, rsp_ptr, 4);
792 error_code = ocs_be32toh(error_code);
796 if (error_code == 0) {
797 ocs_isns_log(iscsi->
os,
"error code = %d (SUCCESS!) \n", error_code);
799 ocs_log_test(iscsi->
os,
"FAILURE: ISNS Query Response Message has error code = %s (%d)\n",
ocs_get_error_name(error_code), error_code);
805 ocs_isns_log(iscsi->
os,
"\t\t\tPRINTING PDU ATTRIBUTES IN THE QRY RSP MSG\n");
807 while (bytes_left > 0) {
810 ocs_memcpy(&tag, rsp_ptr, 4);
811 tag = ocs_be32toh(tag);
815 ocs_memcpy(&len, rsp_ptr, 4);
816 len = ocs_be32toh(len);
823 delimiter_parsed = 1;
829 }
else if (delimiter_parsed ) {
831 ocs_isns_log(iscsi->
os,
"********* Operating Attribute #%d *********\n", counter);
834 ocs_isns_log(iscsi->
os,
"********* Message Key Attribute #%d *********\n", counter);
845 ocs_isns_log(iscsi->
os,
"value = NO VALUE! [Binary Attr but has length = 0]\n");
848 v16 = ocs_htobe16( * (uint16_t *) rsp_ptr);
852 v32 = ocs_htobe32( * (uint32_t *) rsp_ptr);
856 v64 = ocs_htobe64( * (uint64_t *) rsp_ptr);
860 ocs_log_test(iscsi->
os,
"Error: value attribute must be of size 2, 4, or 8 Bytes.\n");
865 ip_addr, ARRAY_SIZE(ip_addr) );
868 void_v = ocs_malloc(iscsi->
os, len, OCS_M_ZERO | OCS_M_NOWAIT);
870 ocs_log_err(iscsi->
os,
"iSNS ERROR: Failed to allocate memory len %d\n", len);
873 ocs_memcpy(void_v, rsp_ptr, len);
875 ocs_free(iscsi->
os, void_v, len);
887 if(nodes_count != 0) {
889 *ret_nodes_count = nodes_count;
891 ret = ocs_malloc(iscsi->
os, nodes_count *
sizeof(
ocs_isns_node_t), OCS_M_ZERO | OCS_M_NOWAIT);
893 ocs_log_err(iscsi->
os,
"iSNS ERROR: Failed to allocate memory, nodes_count %d\n",
898 ocs_log_err(iscsi->
os,
"Error: can't create nodes\n");
927 ocs_t *ocs = iscsi->
os;
928 void *msg_ptr = NULL;
929 void *current_ptr = NULL;
933 uint32_t payload_len = 0;
937 uint32_t node_type = 0x00000001;
938 void *ret_ptr = NULL;
940 msg_ptr = ocs_malloc(ocs,
PDU_MEM_SIZE, OCS_M_ZERO | OCS_M_NOWAIT);
942 ocs_log_err(iscsi->
os,
"iSNS ERROR: Failed to allocate memory\n");
948 if(iscsi_name == NULL){
949 ocs_log_test(iscsi->
os,
"iSNS ERROR: Failed to get iSCSI name\n");
954 if(ip_addr_struct == NULL){
955 ocs_log_test(iscsi->
os,
"iSNS ERROR: Failed to get ip address\n");
960 ip_addr, ARRAY_SIZE(ip_addr) );
964 ocs_isns_log(iscsi->
os,
"***its length=%d Bytes\n", (
int) ocs_strlen(iscsi_name));
967 ocs_isns_log(iscsi->
os,
"\t\t\tForming the PDU (adding tlv attrs)\n");
973 if (bytes_added <= 0) {
974 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
978 current_ptr += bytes_added;
979 ocs_isns_log(iscsi->
os,
"1- iSCSI name added, current_ptr moved %d bytes\n",
985 if (bytes_added <= 0) {
986 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
990 current_ptr += bytes_added;
991 ocs_isns_log(iscsi->
os,
"2- iSCSI node type added, current_ptr moved %d bytes\n",
996 if (bytes_added <= 0) {
997 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1001 current_ptr += bytes_added;
1002 ocs_isns_log(iscsi->
os,
"3- delimiter added, current_ptr moved %d bytes\n",
1009 if (bytes_added <= 0) {
1010 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1014 current_ptr += bytes_added;
1015 ocs_isns_log(iscsi->
os,
"6- (EMPTY) portal ip address (%s) added, current_ptr moved %d bytes\n",
1016 ip_addr, bytes_added);
1021 if (bytes_added <= 0) {
1022 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1026 current_ptr += bytes_added;
1027 ocs_isns_log(iscsi->
os,
"7- (EMPTY) portal TCP port added, current_ptr moved %d bytes\n",
1033 if (bytes_added <= 0) {
1034 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1038 current_ptr += bytes_added;
1039 ocs_isns_log(iscsi->
os,
"8- (EMPTY) iSCSI name added, current_ptr moved %d bytes\n",
1043 payload_len = current_ptr - msg_ptr -
sizeof(
isns_hdr_t);
1046 ocs_isns_log(iscsi->
os,
"payload_len= %u, nmsg_len= %u\n", payload_len, msg_len);
1050 if (bytes_added != 12) {
1051 ocs_log_test(iscsi->
os,
"EROR: ISNS error in building the header of the message\n");
1064 ocs_isns_log(ocs,
"iSNS Send Sent, received %d bytes\n",
1068 if(ret_ptr == NULL){
1069 ocs_log_test(iscsi->
os,
"EROR: ISNS error in parsing the query response\n");
1081 ocs_isns_log(iscsi->
os,
"==============================================================================\n");
1104 uint32_t error_code = 0;
1105 int16_t bytes_left = rsp_len;
1107 uint8_t counter = 0;
1108 uint8_t delimiter_parsed = 0;
1112 void *void_v = NULL;
1124 ocs_isns_log(iscsi->
os,
"\t\t\tPARSING THE PDU OF THE RSP of the %s MSG\n", original_func_name);
1126 ocs_memcpy(&error_code, rsp_ptr, 4);
1127 error_code = ocs_be32toh(error_code);
1131 if (error_code == 0) {
1132 ocs_isns_log(iscsi->
os,
"error code = %d (SUCCESS!) \n", error_code);
1134 ocs_log_test(iscsi->
os,
"FAILURE: Response Message of the %s function has error code = %s (%d)\n", original_func_name,
ocs_get_error_name(error_code), error_code);
1143 while (bytes_left > 0) {
1146 ocs_memcpy(&tag, rsp_ptr, 4);
1147 tag = ocs_be32toh(tag);
1151 ocs_memcpy(&len, rsp_ptr, 4);
1152 len = ocs_be32toh(len);
1158 delimiter_parsed = 1;
1160 }
else if (delimiter_parsed ) {
1162 ocs_isns_log(iscsi->
os,
"********* Operating Attribute #%d *********\n", counter);
1165 ocs_isns_log(iscsi->
os,
"********* Message Key Attribute #%d *********\n", counter);
1176 ocs_isns_log(iscsi->
os,
"value = NO VALUE! [Binary Attr but has length = 0]\n");
1179 v16 = ocs_htobe16( * (uint16_t *) rsp_ptr);
1183 v32 = ocs_htobe32( * (uint32_t *) rsp_ptr);
1187 v64 = ocs_htobe64( * (uint64_t *) rsp_ptr);
1191 ocs_log_test(iscsi->
os,
"Error: value attribute must be of size 2, 4, or 8 Bytes.\n");
1196 ip_addr, ARRAY_SIZE(ip_addr) );
1199 void_v = ocs_malloc(iscsi->
os, len, OCS_M_ZERO | OCS_M_NOWAIT);
1201 ocs_log_err(iscsi->
os,
"iSNS ERROR: Failed to allocate memory len %d\n", len);
1204 ocs_memcpy(void_v, rsp_ptr, len);
1206 ocs_free(iscsi->
os, void_v, len);
1210 ocs_memcpy(eid, rsp_ptr, len);
1238 ocs_t *ocs = iscsi->
os;
1239 void *msg_ptr = NULL;
1240 void *current_ptr = NULL;
1243 int bytes_added = 0;
1244 uint32_t payload_len = 0;
1248 uint32_t node_type = 0x00000001;
1249 void *ret_ptr = NULL;
1250 uint32_t nodes_index = 0;
1251 uint16_t *ret_nodes_count = NULL;
1253 msg_ptr = ocs_malloc(ocs,
PDU_MEM_SIZE, OCS_M_ZERO | OCS_M_NOWAIT);
1254 if(msg_ptr == NULL){
1255 ocs_log_test(iscsi->
os,
"iSNS ERROR: Failed to allocate memory\n");
1265 if(ip_addr_struct == NULL) {
1266 ocs_log_test(iscsi->
os,
"iSNS ERROR: Failed to get ip address\n");
1271 ip_addr, ARRAY_SIZE(ip_addr) );
1273 ocs_isns_log(iscsi->
os,
"***iscsi name #%u is (%s) \n", nodes_index, iscsi_name);
1274 ocs_isns_log(iscsi->
os,
"***its length=%d Bytes\n", (
int) ocs_strlen(iscsi_name));
1277 ocs_isns_log(iscsi->
os,
"\t\t\tForming the PDU (adding tlv attrs)\n");
1283 if (bytes_added <= 0) {
1284 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1288 current_ptr += bytes_added;
1289 ocs_isns_log(iscsi->
os,
"1- iSCSI name added, current_ptr moved %d bytes\n",
1295 if (bytes_added <= 0) {
1296 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1300 current_ptr += bytes_added;
1301 ocs_isns_log(iscsi->
os,
"2- iSCSI node type added, current_ptr moved %d bytes\n",
1306 if (bytes_added <= 0) {
1307 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1311 current_ptr += bytes_added;
1312 ocs_isns_log(iscsi->
os,
"3- delimiter added, current_ptr moved %d bytes\n",
1318 if (bytes_added <= 0) {
1319 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1323 current_ptr += bytes_added;
1324 ocs_isns_log(iscsi->
os,
"-- (EMPTY) Alias added, current_ptr moved %d bytes\n",
1328 payload_len = current_ptr - msg_ptr -
sizeof(
isns_hdr_t);
1331 ocs_isns_log(iscsi->
os,
"payload_len= %u, nmsg_len= %u\n", payload_len, msg_len);
1335 if (bytes_added != 12) {
1336 ocs_log_test(iscsi->
os,
"ERROR: ISNS error in building the header of the message\n");
1349 ocs_isns_log(ocs,
"iSNS Send Sent, received %d bytes\n", msg_len);
1352 if(ret_ptr == NULL){
1353 ocs_log_test(iscsi->
os,
"EROR: ISNS: error in parsing the query response\n");
1359 ocs_isns_log(ocs,
"iSNS Send failed with rc %d\n", rc);
1361 if(ret_ptr == NULL) {
1362 ocs_log_test(ocs,
"FAILED at index %u !\n", nodes_index);
1371 ocs_isns_log(iscsi->
os,
"==============================================================================\n");
1386 ocs_t *ocs = (ocs_t *) arg;
1387 uint32_t cycle_period = ocs->iscsi.isns_reg_period;
1388 void *qry_rsp_ptr = NULL;
1390 ocs_isns_log(ocs,
"cycle_period = %u msec.\n", cycle_period);
1392 if(qry_rsp_ptr == NULL) {
1393 ocs_log_debug(ocs,
"iSNS ERROR: ISNS ATTR QRY FAILED! but wont return\n");
1396 cycle_period = 20 * 1000;
1397 ocs_setup_timer(ocs, &ocs->iscsi.isns_timer,
1400 cycle_period,
false);
1422 ocs_t *ocs = iscsi->
os;
1423 void *msg_ptr = NULL;
1424 void *current_ptr = NULL;
1428 int bytes_added = 0;
1429 uint32_t payload_len = 0;
1433 uint32_t node_type = 0x00000001;
1438 uint8_t ipv6_addr[16];
1441 uint32_t reg_period = 0;
1442 uint32_t cycle_period;
1445 ocs_isns_log(iscsi->
os,
"\t\t\tiSNS register function begin with index = %u\n", index);
1447 msg_ptr = ocs_malloc(ocs,
PDU_MEM_SIZE, OCS_M_ZERO | OCS_M_NOWAIT);
1448 if(msg_ptr == NULL){
1449 ocs_log_err(iscsi->
os,
"iSNS ERROR: Failed to allocate memory\n");
1461 ocs_isns_log(iscsi->
os,
"\t\t\tForming the PDU (adding tlv attrs)\n");
1466 if (bytes_added <= 0) {
1467 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1471 current_ptr += bytes_added;
1472 ocs_isns_log(iscsi->
os,
"1- iSCSI name added, current_ptr moved %d bytes\n",
1478 if (bytes_added <= 0) {
1479 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1483 current_ptr += bytes_added;
1484 ocs_isns_log(iscsi->
os,
"2- MSG Key attr (EID but empty in our case), current_ptr moved %d bytes\n",
1489 if (bytes_added <= 0) {
1490 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1494 current_ptr += bytes_added;
1495 ocs_isns_log(iscsi->
os,
"3- delimiter added, current_ptr moved %d bytes\n",
1502 if (bytes_added <= 0) {
1503 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1507 current_ptr += bytes_added;
1508 ocs_isns_log(iscsi->
os,
"4- (Empty) EID, current_ptr moved %d bytes\n",
1515 if (bytes_added <= 0) {
1516 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1520 current_ptr += bytes_added;
1521 ocs_isns_log(iscsi->
os,
"5- protocol name added, current_ptr moved %d bytes\n",
1527 while (ip_addr_struct) {
1529 ip_addr, ARRAY_SIZE(ip_addr) );
1531 ocs_isns_log(iscsi->
os,
"****ip_addr is (%s). its length=%d Bytes \n", ip_addr, (
int) ocs_strlen(ip_addr));
1534 if (bytes_added <= 0) {
1535 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1539 current_ptr += bytes_added;
1540 ocs_isns_log(iscsi->
os,
"6- portal ip address (%s) added, current_ptr moved %d bytes\n",
1541 ip_addr, bytes_added);
1547 if (bytes_added <= 0) {
1548 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1552 current_ptr += bytes_added;
1553 ocs_isns_log(iscsi->
os,
"7- portal TCP port added, current_ptr moved %d bytes\n",
1561 if (bytes_added <= 0) {
1562 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1566 current_ptr += bytes_added;
1567 ocs_isns_log(iscsi->
os,
"7- ESI interval added, current_ptr moved %d bytes\n",
1573 if (bytes_added <= 0) {
1574 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1578 current_ptr += bytes_added;
1579 ocs_isns_log(iscsi->
os,
"7- ESI port added, current_ptr moved %d bytes\n",
1594 if (bytes_added <= 0) {
1595 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1599 current_ptr += bytes_added;
1600 ocs_isns_log(iscsi->
os,
"8- iSCSI name added, current_ptr moved %d bytes\n",
1606 if (bytes_added <= 0) {
1607 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1611 current_ptr += bytes_added;
1612 ocs_isns_log(iscsi->
os,
"9- iSCSI node type added, current_ptr moved %d bytes\n",
1619 if (bytes_added <= 0) {
1620 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1624 current_ptr += bytes_added;
1625 ocs_isns_log(iscsi->
os,
"10- iSCSI name alias added, current_ptr moved %d bytes\n",
1638 node_type = 0x00000002;
1645 ocs_isns_log(iscsi->
os,
"***its length=%d Bytes\n", (
int) ocs_strlen(iscsi_name));
1647 ocs_isns_log(iscsi->
os,
"***its length=%d Bytes\n", (
int) ocs_strlen(alias));
1648 ocs_isns_log(iscsi->
os,
"***Portal TCP Port is (%d) \n", tcp_port);
1649 ocs_isns_log(iscsi->
os,
"***its length=%d Bytes\n", (
int)
sizeof(uint32_t));
1652 ocs_isns_log(iscsi->
os,
"\t\t\tForming the PDU (adding tlv attrs)\n");
1658 while (ip_addr_struct) {
1660 ip_addr, ARRAY_SIZE(ip_addr) );
1662 ocs_isns_log(iscsi->
os,
"****ip_addr is (%s). its length=%d Bytes \n", ip_addr, (
int) ocs_strlen(ip_addr));
1665 if (bytes_added <= 0) {
1666 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1670 current_ptr += bytes_added;
1671 ocs_isns_log(iscsi->
os,
"6- portal ip address (%s) added, current_ptr moved %d bytes\n",
1672 ip_addr, bytes_added);
1678 if (bytes_added <= 0) {
1679 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1683 current_ptr += bytes_added;
1684 ocs_isns_log(iscsi->
os,
"7- portal TCP port added, current_ptr moved %d bytes\n",
1696 if (bytes_added <= 0) {
1697 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1701 current_ptr += bytes_added;
1702 ocs_isns_log(iscsi->
os,
"8- iSCSI name added, current_ptr moved %d bytes\n",
1708 if (bytes_added <= 0) {
1709 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1713 current_ptr += bytes_added;
1714 ocs_isns_log(iscsi->
os,
"9- iSCSI node type added, current_ptr moved %d bytes\n",
1721 if (bytes_added <= 0) {
1722 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1726 current_ptr += bytes_added;
1727 ocs_isns_log(iscsi->
os,
"10- iSCSI name alias added, current_ptr moved %d bytes\n",
1732 payload_len = current_ptr - msg_ptr -
sizeof(
isns_hdr_t);
1735 ocs_isns_log(iscsi->
os,
"payload_len= %u, msg_len= %u\n", payload_len, msg_len);
1739 if (bytes_added != 12) {
1740 ocs_log_test(iscsi->
os,
"ERROR: ISNS error in building the header of the message\n");
1753 ocs_isns_log(ocs,
"iSNS Send Sent, received %d bytes\n", msg_len);
1755 if(
ocs_parse_msg_rsp(&ocs->iscsi, __func__, msg_ptr, msg_len, ®_period, eid) != 0) {
1761 ocs_log_test(ocs,
"iSNS Send failed with rc %d\n", rc);
1766 cycle_period = (reg_period * 3 / 4) * 1000;
1774 ocs_isns_log(ocs,
"ESI NOT ENABLED--> will call ocs_isns_keep_alive with cycle_period = %u msec\n", cycle_period);
1778 cycle_period,
false);
1786 ocs_isns_log(iscsi->
os,
"==============================================================================\n");
1808 void *msg_ptr = NULL;
1809 void *current_ptr = NULL;
1811 int bytes_added = 0;
1812 uint32_t payload_len = 0;
1816 uint32_t reg_period = 0;
1820 ocs_log_err(iscsi->
os,
"iSNS ERROR: ocs is null. Deregistration failed!\n");
1824 iscsi = &ocs->iscsi;
1830 if (isns_ip == NULL) {
1831 ocs_log_err(iscsi->
os,
"iSNS ERROR: isns_ip is null. Deregistration failed!\n");
1835 msg_ptr = ocs_malloc(ocs,
PDU_MEM_SIZE, OCS_M_ZERO | OCS_M_NOWAIT);
1836 if (msg_ptr == NULL) {
1837 ocs_log_err(iscsi->
os,
"iSNS ERROR: Failed to allocate memory for msg_ptr\n");
1844 ocs_isns_log(iscsi->
os,
"\t\t\tForming the PDU (adding tlv attrs)\n");
1849 if (bytes_added <= 0) {
1850 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1854 current_ptr += bytes_added;
1855 ocs_isns_log(ocs,
"iscsi_name = (%s) size = %d\n", iscsi_name, (
int) ocs_strlen(iscsi_name));
1856 ocs_isns_log(iscsi->
os,
" - iSCSI name added, current_ptr moved %d bytes\n",
1861 if (bytes_added <= 0) {
1862 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1866 current_ptr += bytes_added;
1867 ocs_isns_log(iscsi->
os,
" - delimiter added, current_ptr moved %d bytes\n",
1874 if (bytes_added <= 0) {
1875 ocs_log_test(iscsi->
os,
"Error: Insufficient Space for the PDU Attributes\n");
1879 current_ptr += bytes_added;
1880 ocs_isns_log(ocs,
"eid = (%s) size = %d\n", eid, (
int) ocs_strlen(eid));
1885 payload_len = current_ptr - msg_ptr -
sizeof(
isns_hdr_t);
1888 ocs_isns_log(iscsi->
os,
"payload_len= %u, msg_len= %u\n", payload_len, msg_len);
1892 if (bytes_added != 12) {
1893 ocs_log_test(iscsi->
os,
"ERROR: ISNS error in building the header of the message\n");
1907 ocs_isns_log(ocs,
"iSNS Send Sent, received %d bytes\n", msg_len);
1909 if(
ocs_parse_msg_rsp(&ocs->iscsi, __func__, msg_ptr, msg_len, ®_period, eid) != 0) {
1915 ocs_log_test(ocs,
"iSNS Send failed with rc %d\n", rc);
1922 ocs_isns_log(iscsi->
os,
"==============================================================================\n");
void ocs_str_to_ip_struct(ocs_iscsi_t *iscsi, char *ip, ocs_ip_address_t *ip_struct)
Converts a string ip into an ip struct.
#define ISNS_ERROR_DOMAIN_ID_UNAVAILABLE
ocs_ip_address_t * ocs_iscsi_tgt_get_ip_address(ocs_t *ocs, char *tgt_name, uint32_t index)
Returns the IP address of the target name based on the index.
#define ISNS_ERROR_NO_SUCH_ENTRY
#define ISNS_TAG_ENTITY_PROTOCOL
static void * ocs_parse_qry_rsp(ocs_iscsi_t *iscsi, void *rsp_ptr, uint16_t rsp_len, uint16_t *ret_nodes_count)
Parses the response of the DevAttrQry message.
#define ISNS_ERROR_OPTION_NOT_UNDERSTOOD
static int ocs_add_delimiter(void *curr, int remaining)
Create a delimiter attribute.
int8_t ocs_isns_register(ocs_iscsi_t *iscsi, uint8_t reg_tgts, uint8_t reg_ini, ocs_ip_address_t *isns_ip, char *eid)
Sends the DevAttrReg message to the iSNS server.
#define ISNS_FUNC_DEV_ATTR_REG
#define ISNS_ERROR_INVALID_UPDATE
static int ocs_build_hdr_dev_dereg(void *curr, uint16_t len)
Builds the header of the DevAttrDereg message.
char * ocs_get_iscsi_name(ocs_iscsi_t *iscsi, void *p, uint16_t index)
Gets the iscsi name of a given node.
#define ISNS_FUNC_DEV_ATTR_DEREG
#define ISNS_ERROR_INVALID_REG
static int8_t ocs_create_nodes(ocs_iscsi_t *iscsi, void *rsp_ptr, int16_t bytes_left, void *ret)
Creates an isns node.
static void ocs_isns_keep_alive(void *arg)
Sends a query to an ISNS target to keep it alive.
#define ISNS_FLAG_REPLACE
#define ISNS_TAG_ESI_PORT
#define ISNS_TAG_ENTITY_IDENTIFIER
#define ISNS_FUNC_DEV_ATTR_QRY
char * ocs_iscsi_ini_get_name(ocs_t *ocs)
Return this initiator's name.
static void ocs_parse_flags(ocs_iscsi_t *iscsi, uint16_t flags)
Parses the flags of the response of an isns message.
#define ISNS_TAG_REG_PERIOD
#define ISNS_ERROR_FUNC_ID
#define ISNS_TAG_ESI_INTERVAL
char * ocs_iscsi_tgt_get_names(ocs_t *ocs, uint32_t index)
Returns the target name based on the index.
#define ocs_isns_log(os, fmt,...)
static void * ocs_isns_qry_attr(ocs_iscsi_t *iscsi, ocs_ip_address_t *isns_ip)
Sends the DevAttrReg message to the iSNS server.
static int ocs_build_hdr_dev_attr_qry(void *curr, uint16_t len)
Builds the header of the DevAttrQry message.
#define ISNS_ERROR_UNALLCATED_DOMAIN_ID
#define ISNS_TAG_PORTAL_INDEX
#define ISNS_TAG_ISCSI_NODE_TYPE
static int8_t ocs_create_node(ocs_iscsi_t *iscsi, void *ptr, uint16_t num)
Creates an empty isns node.
#define ISNS_ERROR_INTERNAL_ERROR
#define ISNS_TAG_ISCSI_ALIAS
#define ISNS_TRANSACTION_ID_2
#define ISNS_TAG_PORTAL_IP_ADDRESS
static void ocs_fill_nodes_values(ocs_iscsi_t *iscsi, void *rsp_ptr, int16_t bytes_left, void *ret)
Fills the attributes of the isns node.
#define ISNS_ERROR_SOURCE_UNATHORIZED
#define ISNS_ERROR_SCN_REG_REJ
#define ISNS_ERROR_MSG_FORMAT
#define ISNS_ERROR_NOT_IMPL
static int ocs_binary_attr(int tag)
Determines whether a given isns attribute is a numeric (binary) one.
#define ISNS_TRANSACTION_ID_1
#define ISNS_TAG_PORTAL_TCP_PORT
#define ISNS_TAG_ISCSI_NAME
#define ISNS_ERROR_SCN_EVENT_REJ
#define ISNS_TAG_DELIMITER
void * ocs_isns_qry_tgts(ocs_iscsi_t *iscsi, ocs_ip_address_t *isns_ip, uint16_t *ret_nodes_count)
Sends the DevAttrReg message to the iSNS server.
static int ocs_build_hdr_dev_attr_reg(void *curr, uint16_t len)
Builds the header of the DevAttrReg message.
#define ISNS_ERROR_INVALID_DEREG
uint16_t ocs_get_iscsi_ipp_count(ocs_iscsi_t *iscsi, void *p, uint16_t index)
Gets the count of the ip_port structs in a given node.
int32_t ocs_isns_initialize(ocs_iscsi_t *iscsi)
Initialize the iSNS module.
void format_ip_address(ocs_ip_type_e ip_type, uint8_t *address, char *buffer, int size)
Format an IP address into a string.
char * ocs_get_ip(ocs_iscsi_t *iscsi, void *p, uint16_t index, uint16_t ip_index)
Gets the ip address of a given isns node.
char * ocs_iscsi_ini_get_alias(ocs_t *ocs)
Returns the initiator alias.
#define ISNS_ERROR_INVALID_QUERY
#define ISNS_ERROR_SOURCE_ABSENT
uint16_t ocs_get_port(ocs_iscsi_t *iscsi, void *p, uint16_t index, uint16_t ip_index)
Gets the port of a given isns node.
ocs_ip_type_e
enum identifying the types of IP addresses.
#define ISNS_ERROR_SOURCE_UNKNOWN
static void ocs_parse_rsp_hdr(ocs_iscsi_t *iscsi, void *rsp)
Parses the header of the response of an isns message.
#define ISNS_ERROR_REG_FEATURE_UNSUPPORTED
#define ISNS_ERROR_UNKNOWN
#define ISNS_ERROR_VERSION_NOT_SUPPORTED
#define ISNS_ESI_INTERVAL
int32_t ocs_iscsi_isns_send(ocs_t *ocs, ocs_ip_address_t *isns_server, uint32_t tcp_port, void *buffer, uint32_t *pkt_len, uint32_t buff_len)
Sends an iSNS packet to a server to test the interface.
#define ISNS_ERROR_RESERVED
int32_t ocs_isns_teardown(ocs_iscsi_t *iscsi)
Shutdown the iSNS module.
#define ISNS_STARTING_SEQ_ID
static int8_t ocs_parse_msg_rsp(ocs_iscsi_t *iscsi, const char *original_func_name, void *rsp_ptr, uint16_t rsp_len, uint32_t *reg_period, char *eid)
Parses the response of an isns message.
static char * ocs_get_tag_name(uint32_t tag)
Gets the name of the given isns tag.
#define OCS_ISCSI_TCP_PORT
int32_t ocs_iscsi_inet_pton6(const char *src, ocs_ip_address_t *ip)
Converts an IPv6 address from a string to the IP structure.
static char * ocs_get_error_name(uint32_t error_number)
Gets the name of the given isns error.
structure wrapping an IP address together with it's type.
static int ocs_add_tlv(ocs_iscsi_t *iscsi, void *curr, uint32_t tag, uint32_t len, void *value, int remaining)
Create a tag-length-value attribute.
char * ocs_iscsi_tgt_get_alias(ocs_t *ocs, uint32_t index)
Returns the target alias based on the index.
int8_t ocs_isns_deregister(ocs_t *ocs, ocs_ip_address_t *isns_ip, char *eid)
Sends the DevDereg message to the iSNS server.
#define ISNS_ERROR_ESI_UNAVAILABLE
static void ocs_get_ipv6_string(ocs_iscsi_t *iscsi, ocs_ip_address_t *addr, uint8_t *ret_addr)
Forms an v6-format ip string.
static void ocs_print_nl(ocs_iscsi_t *iscsi, uint32_t ctr)
Prints a number of empty lines.