4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* This file is getting large unexpectly, a lex & yacc */
28 /* implementation is expected. */
34 #include <sys/types.h>
36 #include <sys/socket.h>
37 #include <netinet/in.h>
38 #include <arpa/inet.h>
43 #include "isns_server.h"
44 #include "isns_htab.h"
45 #include "isns_msgq.h"
47 #include "isns_func.h"
49 #include "isns_cache.h"
56 extern const int NUM_OF_CHILD
[MAX_OBJ_TYPE
];
57 extern const int TYPE_OF_CHILD
[MAX_OBJ_TYPE
][MAX_CHILD_TYPE
];
58 extern const int UID_ATTR_INDEX
[MAX_OBJ_TYPE_FOR_SIZE
];
59 extern const int NUM_OF_REF
[MAX_OBJ_TYPE_FOR_SIZE
];
61 extern lookup_ctrl_t
*setup_ddid_lcp(lookup_ctrl_t
*, uint32_t);
62 extern lookup_ctrl_t
*setup_ddsid_lcp(lookup_ctrl_t
*, uint32_t);
71 int verbose_parser
= 0;
76 static void print_entity(char *, isns_obj_t
*);
77 static void print_iscsi(char *, isns_obj_t
*);
78 static void print_portal(char *, isns_obj_t
*);
79 static void print_pg(char *, isns_obj_t
*);
80 static void print_dd(char *, isns_obj_t
*);
81 static void print_dds(char *, isns_obj_t
*);
82 static void (*const print_func
[MAX_OBJ_TYPE
])(char *, isns_obj_t
*) = {
91 static int run_cmd(char *);
97 isnsp_fnames_t fnames
[] = {
98 { ISNS_DEV_ATTR_REG
, "DevAttrReg" },
99 { ISNS_DEV_ATTR_QRY
, "DevAttrQry" },
100 { ISNS_DEV_GET_NEXT
, "DevGetNext" },
101 { ISNS_DEV_DEREG
, "DevDereg" },
102 { ISNS_SCN_REG
, "SCNReg" },
103 { ISNS_SCN_DEREG
, "SCNDereg" },
104 { ISNS_DD_REG
, "DDReg" },
105 { ISNS_DD_DEREG
, "DDDereg" },
106 { ISNS_DDS_REG
, "DDSReg" },
107 { ISNS_DDS_DEREG
, "DDSDereg" },
110 { ISNS_HEARTBEAT
, "Heartbeat" },
111 { ISNS_DEV_ATTR_REG_RSP
, "DevAttrRegRsp" },
112 { ISNS_DEV_ATTR_QRY_RSP
, "DevAttrQryRsp" },
113 { ISNS_DEV_GET_NEXT_RSP
, "DevGetNextRsp" },
114 { ISNS_DEV_DEREG_RSP
, "DevDeregRsp" },
115 { ISNS_SCN_REG_RSP
, "SCNRegRsp" },
116 { ISNS_SCN_DEREG_RSP
, "SCNDeregRsp" },
117 { ISNS_SCN_RSP
, "SCNRsp" },
118 { ISNS_ESI_RSP
, "ESIRsp" },
119 { 0xFFFF, "Unknown" } };
127 isnsp_fnames_t
*fp
= &fnames
[i
++];
128 while (fp
->func_id
!= 0xFFFF) {
129 if (fp
->func_id
== id
) {
144 case ISNS_DELIMITER_ATTR_ID
:
145 return ("Delimiter");
146 case ISNS_EID_ATTR_ID
:
147 return ("Entity Identifier");
148 case ISNS_ENTITY_PROTOCOL_ATTR_ID
:
149 return ("Entity Protocol");
150 case ISNS_ENTITY_REG_PERIOD_ATTR_ID
:
151 return ("Registration Period");
152 case ISNS_TIMESTAMP_ATTR_ID
:
153 return ("Timestamp");
154 case ISNS_PORTAL_IP_ADDR_ATTR_ID
:
155 return ("Portal IP Address");
156 case ISNS_PORTAL_PORT_ATTR_ID
:
157 return ("Portal TCP/UDP Port");
158 case ISNS_PORTAL_NAME_ATTR_ID
:
159 return ("Portal Symbolic Name");
160 case ISNS_ESI_INTERVAL_ATTR_ID
:
161 return ("ESI Interval");
162 case ISNS_ESI_PORT_ATTR_ID
:
164 case ISNS_SCN_PORT_ATTR_ID
:
166 case ISNS_PORTAL_SEC_BMP_ATTR_ID
:
167 return ("Portal Security Bitmap");
168 case ISNS_ISCSI_NAME_ATTR_ID
:
169 return ("iSCSI Name");
170 case ISNS_ISCSI_NODE_TYPE_ATTR_ID
:
171 return ("iSCSI Node Type");
172 case ISNS_ISCSI_ALIAS_ATTR_ID
:
173 return ("iSCSI Alias");
174 case ISNS_ISCSI_AUTH_METHOD_ATTR_ID
:
175 return ("iSCSI Auth Method");
176 case ISNS_ISCSI_SCN_BITMAP_ATTR_ID
:
177 return ("iSCSI SCN Bitmap");
178 case ISNS_PG_ISCSI_NAME_ATTR_ID
:
179 return ("PG iSCSI Name");
180 case ISNS_PG_PORTAL_IP_ADDR_ATTR_ID
:
181 return ("PG Portal IP Addr");
182 case ISNS_PG_PORTAL_PORT_ATTR_ID
:
183 return ("PG Portal TCP/UDP Port");
184 case ISNS_PG_TAG_ATTR_ID
:
185 return ("PG Tag (PGT)");
186 case ISNS_PG_INDEX_ATTR_ID
:
188 case ISNS_DD_NAME_ATTR_ID
:
190 case ISNS_DD_ID_ATTR_ID
:
192 case ISNS_DD_ISCSI_INDEX_ATTR_ID
:
193 return ("DD ISCSI Node Index");
194 case ISNS_DD_ISCSI_NAME_ATTR_ID
:
195 return ("DD ISCSI Node Name");
196 case ISNS_DD_SET_NAME_ATTR_ID
:
198 case ISNS_DD_SET_ID_ATTR_ID
:
199 return ("DDS Index");
200 case ISNS_DD_SET_STATUS_ATTR_ID
:
201 return ("DDS Status");
213 short ver
, id
, len
, flags
, xid
, seq
;
215 uint8_t *payload
= pdu
->payload
;
218 /* convert the data */
220 ver
= ntohs(pdu
->version
);
221 id
= ntohs(pdu
->func_id
);
222 len
= ntohs(pdu
->payload_len
);
223 flags
= ntohs(pdu
->flags
) & 0xFFFF;
224 xid
= ntohs(pdu
->xid
);
225 seq
= ntohs(pdu
->seq
);
229 len
= pdu
->payload_len
;
230 flags
= pdu
->flags
& 0xFFFF;
235 /* print the pdu header */
236 printf("iSNSP Version: %d\n", ver
);
237 printf("Function ID: %s\n", get_func_name(id
));
238 printf("PDU Length: %d\n", len
);
239 printf("Flags: %x\n", flags
);
240 printf(" %d... .... .... .... : ISNS_FLAG_CLIENT\n",
241 ((flags
& ISNS_FLAG_CLIENT
) == 0) ? 0 : 1);
242 printf(" .%d.. .... .... .... : ISNS_FLAG_SERVER\n",
243 ((flags
& ISNS_FLAG_SERVER
) == 0) ? 0 : 1);
244 printf(" ..%d. .... .... .... : ISNS_FLAG_AUTH_BLK_PRESENTED\n",
245 ((flags
& ISNS_FLAG_AUTH_BLK_PRESENTED
) == 0) ? 0 : 1);
246 printf(" ...%d .... .... .... : ISNS_FLAG_REPLACE_REG\n",
247 ((flags
& ISNS_FLAG_REPLACE_REG
) == 0) ? 0 : 1);
248 printf(" .... %d... .... .... : ISNS_FLAG_LAST_PDU\n",
249 ((flags
& ISNS_FLAG_LAST_PDU
) == 0) ? 0 : 1);
250 printf(" .... .%d.. .... .... : ISNS_FLAG_FIRST_PDU\n",
251 ((flags
& ISNS_FLAG_FIRST_PDU
) == 0) ? 0 : 1);
252 printf("Transaction ID: %d\n", xid
);
253 printf("Sequence ID: %d\n", seq
);
255 printf("Payload: ...\n");
256 if (id
& ISNS_RSP_MASK
) {
257 resp
= (isns_resp_t
*)payload
;
258 printf(" ErrorCode: %d\n", ntohl(resp
->status
));
263 /* print the payload */
271 char pbuff
[256] = { 0 };
273 tlvp
= (isns_tlv_t
*)payload
;
275 /* convert the data */
276 t
= ntohl(tlvp
->attr_id
);
277 l
= ntohl(tlvp
->attr_len
);
278 v
= &(tlvp
->attr_value
[0]);
282 printf("%s: ", get_tlv_tag_name(t
));
284 case ISNS_EID_ATTR_ID
:
285 case ISNS_ISCSI_NAME_ATTR_ID
:
286 case ISNS_ISCSI_ALIAS_ATTR_ID
:
287 case ISNS_ISCSI_AUTH_METHOD_ATTR_ID
:
288 case ISNS_PG_ISCSI_NAME_ATTR_ID
:
289 case ISNS_DD_NAME_ATTR_ID
:
290 case ISNS_DD_SET_NAME_ATTR_ID
:
294 case ISNS_ENTITY_PROTOCOL_ATTR_ID
:
295 i
= ntohl(*(uint32_t *)v
);
297 ((i
== 1) ? "No Protocol" :
298 ((i
== 2) ? "iSCSI" :
303 case ISNS_PORTAL_IP_ADDR_ATTR_ID
:
304 case ISNS_PG_PORTAL_IP_ADDR_ATTR_ID
:
305 ip
= (in6_addr_t
*)v
;
306 inet_ntop(AF_INET6
, (void *)ip
,
307 pbuff
, sizeof (pbuff
));
308 printf("%s\n", pbuff
);
310 case ISNS_PORTAL_PORT_ATTR_ID
:
311 case ISNS_ESI_PORT_ATTR_ID
:
312 case ISNS_SCN_PORT_ATTR_ID
:
313 i
= ntohl(*(uint32_t *)v
);
314 printf("%d\n", (i
& 0x0000FFFF));
315 printf(" .... .... %d... .... : "
317 ((i
& 0x10000) == 0) ? 0 : 1);
319 case ISNS_ISCSI_NODE_TYPE_ATTR_ID
:
320 i
= ntohl(*(uint32_t *)v
);
322 if (i
& ISNS_CONTROL_NODE_TYPE
) {
325 if (i
& ISNS_INITIATOR_NODE_TYPE
) {
326 printf("Initiator ");
328 if (i
& ISNS_TARGET_NODE_TYPE
) {
333 case ISNS_PG_TAG_ATTR_ID
:
335 i
= ntohl(*(uint32_t *)v
);
339 printf(" Attribute Tag: %s (%d)\n",
340 get_tlv_tag_name(t
), t
);
341 printf(" Attribute Length: %d\n", l
);
343 printf("%s: (%d)\n", get_tlv_tag_name(t
), t
);
346 len
-= (sizeof (uint32_t) * 2 + l
);
347 payload
+= (sizeof (uint32_t) * 2 + l
);
357 printf("### PDU RECEIVED ###\n");
368 printf("### PDU SENT ###\n");
378 isns_list_t
*list
, *lista
, *listb
;
381 isns_iscsi2_t
*iscsi2
;
383 printf("### DUMP DATABASE ###\n");
386 while (list
!= NULL
) {
388 printf("[DDS:%d]%s(%s)\n", dds
->id
, dds
->name
,
389 dds
->status
? "enabled" : "disabled");
390 lista
= dds
->dd_list
;
391 /* dd(s) that belong to this dds */
392 while (lista
!= NULL
) {
394 printf("\t[DD:%d]%s\n", dd
->id
, dd
->name
);
401 while (list
!= NULL
) {
403 printf("[DD:%d]%s\n", dd
->id
, dd
->name
);
404 /* dds(s) this dd belongs to */
405 lista
= dd
->dds_list
;
406 while (lista
!= NULL
) {
407 dds
= lista
->obj
.dds
;
408 printf("\t[DDS:%d]%s\n", dds
->id
, dds
->name
);
411 /* node(s) that this dd have */
412 listb
= dd
->iscsi_list
;
413 while (listb
!= NULL
) {
414 iscsi2
= listb
->obj
.iscsi2
;
415 printf("\t[ISCSI:%d]%s\n", iscsi2
->id
, iscsi2
->name
);
422 while (list
!= NULL
) {
423 iscsi2
= list
->obj
.iscsi2
;
424 printf("[ISCSI:%d]%s\n", iscsi2
->id
, iscsi2
->name
);
425 lista
= iscsi2
->dd_list
;
426 /* dd(s) that this node belongs to */
427 while (lista
!= NULL
) {
429 printf("\t[DD:%d]%s\n", dd
->id
, dd
->name
);
441 printf("list - list all of storage node.\n");
442 printf("list dd [id] - list all of dd or one with member.\n");
443 printf("list dds [id] - list all of dd-set or one with member.\n");
446 printf("new dd <name> - create a dd with name.\n");
447 printf("new dds <name> - create a dd-set with name.\n");
448 printf("new ddn <id> <name> - create a dd with id and name.\n");
449 printf("new ddsn <id> <name> - create a dd-set with id and name.\n");
450 printf("del dd <id> - delete a dd.\n");
451 printf("del dds <id> - delete a dd-set.\n");
454 printf("add dd <dd_id> <node_name> - add a node to dd.\n");
455 printf("add ddn <dd_id> <node_id> - add a node to dd.\n");
456 printf("add ddsn <dds_id> <dd_id> - add a dd to dd-set.\n");
457 printf("remove dd <dd_id> <node_name> - remove a node from dd.\n");
458 printf("remove ddn <dd_id> <node_id> - remove a node from dd.\n");
459 printf("remove ddsn <dds_id> <dd_id> - remove a dd from dd-set.\n");
462 printf("enable <dds_id> - enable a dd-set.\n");
463 printf("disable <dds_id> - disable a dd-set.\n");
466 printf("file <f> - loading command from a file.\n");
467 printf("pause - suspend batch until enter key is pressed.\n");
469 printf("help - print this help.\n");
470 printf("quit - stop iSNS server and quit.\n");
474 CMD_LIST
, CMD_LISTNE
, CMD_LISTP
, CMD_LISTPG
,
475 CMD_LISTDD
, CMD_LISTDDS
, CMD_LISTDDN
, CMD_LISTDDSN
,
476 CMD_NEWDD
, CMD_NEWDDS
, CMD_NEWDDN
, CMD_NEWDDSN
,
477 CMD_DELDD
, CMD_DELDDS
,
478 CMD_ENABLE
, CMD_DISABLE
,
479 CMD_ADDDD
, CMD_ADDDDN
, CMD_ADDDDSN
,
480 CMD_REMDD
, CMD_REMDDN
, CMD_REMDDSN
,
484 CMD_VERBOSE_MEMORY
, CMD_VERBOSE_NET
,
485 CMD_VERBOSE_PARSER
, CMD_VERBOSE_TIME
,
488 CMD_NONE
, CMD_INVALID
493 int *argc
, int *argv
, char *cmd
497 char tmp
[256] = { 0 };
499 while (*cmd
== ' ') cmd
++;
503 } else if (*cmd
== '?') {
507 /* list, list dd, list dds, list dd 0 */
508 if (strncmp(cmd
, "list ", 5) == 0) {
510 while (*cmd
== ' ') cmd
++;
513 } else if (*cmd
== 'p') {
515 while (*cmd
== ' ') cmd
++;
519 } else if (*cmd
== 'g') {
521 while (*cmd
== ' ') cmd
++;
525 } else if (*cmd
== 'e') {
527 while (*cmd
== ' ') cmd
++;
531 } else if (strncmp(cmd
, "dds ", 4) == 0) {
533 while (*cmd
== ' ') cmd
++;
535 return (CMD_LISTDDS
);
538 while (*cmd
>= '0' && *cmd
<= '9') {
542 while (*cmd
== ' ') cmd
++;
543 if (*cmd
== 0 && j
> 0) {
544 argv
[(*argc
)++] = atoi(tmp
);
545 return (CMD_LISTDDSN
);
547 } else if (strncmp(cmd
, "dd ", 3) == 0) {
549 while (*cmd
== ' ') cmd
++;
554 while (*cmd
>= '0' && *cmd
<= '9') {
558 while (*cmd
== ' ') cmd
++;
559 if (*cmd
== 0 && j
> 0) {
560 argv
[(*argc
)++] = atoi(tmp
);
561 return (CMD_LISTDDN
);
564 return (CMD_INVALID
);
568 if (strncmp(cmd
, "view ", 5) == 0) {
570 while (*cmd
== ' ') cmd
++;
572 while (*cmd
>= '0' && *cmd
<= '9') {
576 while (*cmd
== ' ') cmd
++;
577 if (*cmd
== 0 && j
> 0) {
578 argv
[(*argc
)++] = atoi(tmp
);
581 return (CMD_INVALID
);
585 /* add ddn/ddsn id id */
586 if (strncmp(cmd
, "add ", 4) == 0) {
587 int addcmd
= CMD_INVALID
;
589 while (*cmd
== ' ') cmd
++;
590 if (strncmp(cmd
, "dd ", 3) == 0) {
593 } else if (strncmp(cmd
, "ddn ", 4) == 0) {
596 } else if (strncmp(cmd
, "ddsn ", 5) == 0) {
598 addcmd
= CMD_ADDDDSN
;
600 return (CMD_INVALID
);
602 while (*cmd
== ' ') cmd
++;
604 while (*cmd
>= '0' && *cmd
<= '9') {
609 argv
[(*argc
)++] = atoi(tmp
);
611 return (CMD_INVALID
);
613 while (*cmd
== ' ') cmd
++;
619 while (*cmd
>= '0' && *cmd
<= '9') {
623 while (*cmd
== ' ') cmd
++;
624 if (*cmd
== 0 && j
> 0) {
625 argv
[(*argc
)++] = atoi(tmp
);
627 return (CMD_INVALID
);
633 /* get rid of trail blank space */
634 if (cmd
[j
- 1] == ' ') {
642 argv
[(*argc
)++] = (int)cmd
;
644 return (CMD_INVALID
);
650 return (CMD_INVALID
);
654 /* remove ddn/ddsn id id */
655 if (strncmp(cmd
, "remove ", 7) == 0) {
656 int rmcmd
= CMD_INVALID
;
658 while (*cmd
== ' ') cmd
++;
659 if (strncmp(cmd
, "dd ", 3) == 0) {
661 while (*cmd
== ' ') cmd
++;
663 } else if (strncmp(cmd
, "ddn ", 4) == 0) {
665 while (*cmd
== ' ') cmd
++;
667 } else if (strncmp(cmd
, "ddsn ", 5) == 0) {
669 while (*cmd
== ' ') cmd
++;
672 return (CMD_INVALID
);
675 while (*cmd
>= '0' && *cmd
<= '9') {
680 argv
[(*argc
)++] = atoi(tmp
);
682 return (CMD_INVALID
);
684 while (*cmd
== ' ') cmd
++;
690 while (*cmd
>= '0' && *cmd
<= '9') {
694 while (*cmd
== ' ') cmd
++;
695 if (*cmd
== 0 && j
> 0) {
696 argv
[(*argc
)++] = atoi(tmp
);
698 return (CMD_INVALID
);
704 /* get rid of trail blank space */
705 if (cmd
[j
- 1] == ' ') {
713 argv
[(*argc
)++] = (int)cmd
;
715 return (CMD_INVALID
);
721 return (CMD_INVALID
);
724 /* new dd, new dds */
725 if (strncmp(cmd
, "new ", 4) == 0) {
726 int newcmd
= CMD_INVALID
;
728 while (*cmd
== ' ') cmd
++;
729 if (strncmp(cmd
, "dd ", 3) == 0) {
732 } else if (strncmp(cmd
, "dds ", 4) == 0) {
735 } else if (strncmp(cmd
, "ddn ", 4) == 0) {
738 } else if (strncmp(cmd
, "ddsn ", 5) == 0) {
740 newcmd
= CMD_NEWDDSN
;
742 if (newcmd
!= CMD_INVALID
) {
743 while (*cmd
== ' ') cmd
++;
751 while (*cmd
>= '0' && *cmd
<= '9') {
755 if (*cmd
== ' ' && j
> 0) {
756 argv
[(*argc
)++] = atoi(tmp
);
758 return (CMD_INVALID
);
762 while (*cmd
== ' ') cmd
++;
769 /* get rid of trail blank space */
770 if (cmd
[j
- 1] == ' ') {
778 argv
[(*argc
)++] = (int)cmd
;
783 return (CMD_INVALID
);
786 /* del dd, del dds, disable 0 */
787 if (strncmp(cmd
, "del ", 4) == 0) {
788 int delcmd
= CMD_INVALID
;
790 while (*cmd
== ' ') cmd
++;
791 if (strncmp(cmd
, "dds ", 4) == 0) {
794 } else if (strncmp(cmd
, "dd ", 3) == 0) {
798 if (delcmd
!= CMD_INVALID
) {
799 while (*cmd
== ' ') cmd
++;
801 while (*cmd
>= '0' && *cmd
<= '9') {
805 while (*cmd
== ' ') cmd
++;
806 if (*cmd
== 0 && j
> 0) {
807 argv
[(*argc
)++] = atoi(tmp
);
811 return (CMD_INVALID
);
815 if (strncmp(cmd
, "enable ", 7) == 0) {
817 while (*cmd
== ' ') cmd
++;
819 while (*cmd
>= '0' && *cmd
<= '9') {
823 while (*cmd
== ' ') cmd
++;
824 if (*cmd
== 0 && j
> 0) {
825 argv
[(*argc
)++] = atoi(tmp
);
828 return (CMD_INVALID
);
832 if (strncmp(cmd
, "disable ", 8) == 0) {
834 while (*cmd
== ' ') cmd
++;
836 while (*cmd
>= '0' && *cmd
<= '9') {
840 while (*cmd
== ' ') cmd
++;
841 if (*cmd
== 0 && j
> 0) {
842 argv
[(*argc
)++] = atoi(tmp
);
843 return (CMD_DISABLE
);
845 return (CMD_INVALID
);
849 if (strncmp(cmd
, "file ", 5) == 0) {
851 while (*cmd
== ' ') cmd
++;
858 /* get rid of trail blank space */
859 if (cmd
[j
- 1] == ' ') {
867 argv
[(*argc
)++] = (int)cmd
;
870 return (CMD_INVALID
);
874 if (strncmp(cmd
, "pause ", 6) == 0) {
876 while (*cmd
== ' ') cmd
++;
880 return (CMD_INVALID
);
884 if (strncmp(cmd
, "help ", 5) == 0) {
886 while (*cmd
== ' ') cmd
++;
890 return (CMD_INVALID
);
894 if (strncmp(cmd
, "verbose ", 8) == 0) {
896 while (*cmd
== ' ') cmd
++;
898 return (CMD_VERBOSE_PARSER
);
899 } else if (*cmd
== 'm') {
901 while (*cmd
== ' ') cmd
++;
903 return (CMD_VERBOSE_MEMORY
);
905 } else if (*cmd
== 'n') {
907 while (*cmd
== ' ') cmd
++;
909 return (CMD_VERBOSE_NET
);
911 } else if (*cmd
== 'p') {
913 while (*cmd
== ' ') cmd
++;
915 return (CMD_VERBOSE_PARSER
);
917 } else if (*cmd
== 't') {
919 while (*cmd
== ' ') cmd
++;
921 return (CMD_VERBOSE_TIME
);
923 } else if (*cmd
== 'l') {
925 while (*cmd
== ' ') cmd
++;
927 return (CMD_VERBOSE_LOCK
);
930 return (CMD_INVALID
);
934 if (strncmp(cmd
, "quit ", 5) == 0) {
936 while (*cmd
== ' ') cmd
++;
940 return (CMD_INVALID
);
943 return (CMD_INVALID
);
958 ATTR_INDEX_ENTITY(ISNS_EID_ATTR_ID
)].value
.ptr
;
959 uid
= get_obj_uid(obj
);
962 printf("%s%d\t%s\n", ident
, uid
, (const char *)eid
);
964 printf("%d\t%s\n", uid
, (const char *)eid
);
968 while (i
< NUM_OF_CHILD
[obj
->type
]) {
969 cuid
= get_child_n(obj
, i
);
971 printf("%s\t%s%d:", "child", i
);
973 printf("\t%s%d:", "child", i
);
981 printf("\t%d", *cuid
++);
995 uchar_t
*name
= obj
->attrs
[ATTR_INDEX_ISCSI(ISNS_ISCSI_NAME_ATTR_ID
)]
997 uchar_t
*alias
= obj
->attrs
[ATTR_INDEX_ISCSI(ISNS_ISCSI_ALIAS_ATTR_ID
)]
999 uint32_t type
= obj
->attrs
[
1000 ATTR_INDEX_ISCSI(ISNS_ISCSI_NODE_TYPE_ATTR_ID
)].value
.ui
;
1001 uint32_t uid
= get_obj_uid(obj
);
1002 uint32_t puid
= get_parent_uid(obj
);
1005 alias
= (uchar_t
*)"-";
1008 if (ident
!= NULL
) {
1009 printf("%s%d[%d]\t%s\n", ident
,
1010 uid
, puid
, (const char *)name
);
1011 printf("%s\t%s", ident
, alias
);
1013 printf("%d[%d]\t%s\n",
1014 uid
, puid
, (const char *)name
);
1015 printf("\t%s", alias
);
1017 if (IS_TYPE_TARGET(type
)) {
1020 if (IS_TYPE_INITIATOR(type
)) {
1021 printf("\tInitiator");
1023 if (IS_TYPE_CONTROL(type
)) {
1024 printf("\tControl");
1026 if (IS_TYPE_UNKNOWN(type
)) {
1038 char pbuff
[256] = { 0 };
1039 in6_addr_t
*ip
= obj
->attrs
[
1040 ATTR_INDEX_PORTAL(ISNS_PORTAL_IP_ADDR_ATTR_ID
)].value
.ip
;
1041 uint32_t port
= obj
->attrs
[
1042 ATTR_INDEX_PORTAL(ISNS_PORTAL_PORT_ATTR_ID
)].value
.ui
;
1043 uint32_t uid
= get_obj_uid(obj
);
1044 uint32_t puid
= get_parent_uid(obj
);
1046 inet_ntop(AF_INET6
, (void *)ip
, pbuff
, sizeof (pbuff
));
1047 if (ident
!= NULL
) {
1048 printf("%s%d[%d]\t%s:%d", ident
,
1049 uid
, puid
, pbuff
, PORT_NUMBER(port
));
1051 printf("%d[%d]\t%s:%d",
1052 uid
, puid
, pbuff
, PORT_NUMBER(port
));
1054 printf(" %s\n", IS_PORT_UDP(port
) ? "UDP" : "TCP");
1066 char pbuff
[256] = { 0 };
1067 uchar_t
*name
= obj
->attrs
[ATTR_INDEX_PG(ISNS_PG_ISCSI_NAME_ATTR_ID
)]
1069 in6_addr_t
*ip
= obj
->attrs
[
1070 ATTR_INDEX_PG(ISNS_PG_PORTAL_IP_ADDR_ATTR_ID
)].value
.ip
;
1071 uint32_t port
= obj
->attrs
[
1072 ATTR_INDEX_PG(ISNS_PG_PORTAL_PORT_ATTR_ID
)].value
.ui
;
1073 uint32_t tag
= obj
->attrs
[
1074 ATTR_INDEX_PG(ISNS_PG_TAG_ATTR_ID
)].value
.ui
;
1075 uint32_t uid
= get_obj_uid(obj
);
1076 uint32_t puid
= get_parent_uid(obj
);
1078 inet_ntop(AF_INET6
, (void *)ip
, pbuff
, sizeof (pbuff
));
1079 if (ident
!= NULL
) {
1080 printf("%s%d[%d]\t[%d] %s\n", ident
,
1081 uid
, puid
, tag
, (const char *)name
);
1082 printf("%s\t%s:%d", ident
, pbuff
, PORT_NUMBER(port
));
1084 printf("%d[%d]\t[%d] %s\n",
1085 uid
, puid
, tag
, (const char *)name
);
1086 printf("\t%s:%d", pbuff
, PORT_NUMBER(port
));
1088 printf(" %s\n", IS_PORT_UDP(port
) ? "UDP" : "TCP");
1090 if (NUM_OF_REF
[obj
->type
] > 0) {
1091 if (ident
!= NULL
) {
1092 printf("%s\t%s:", "ref");
1094 printf("\t%s:", "ref");
1098 while (i
< NUM_OF_REF
[obj
->type
]) {
1099 ref
= get_ref_n(obj
, i
);
1100 printf("\t%d", ref
);
1114 uchar_t
*name
= obj
->attrs
[ATTR_INDEX_DD(ISNS_DD_NAME_ATTR_ID
)]
1116 uint32_t uid
= obj
->attrs
[UID_ATTR_INDEX
[OBJ_DD
]].value
.ui
;
1118 if (ident
!= NULL
) {
1119 printf("%s%d\t%s\n", ident
, uid
, (const char *)name
);
1121 printf("%d\t%s\n", uid
, (const char *)name
);
1131 uchar_t
*name
= obj
->attrs
[ATTR_INDEX_DDS(
1132 ISNS_DD_SET_NAME_ATTR_ID
)].value
.ptr
;
1133 uint32_t uid
= obj
->attrs
[UID_ATTR_INDEX
[OBJ_DDS
]].value
.ui
;
1134 uint32_t enabled
= obj
->attrs
[ATTR_INDEX_DDS(
1135 ISNS_DD_SET_STATUS_ATTR_ID
)].value
.ui
;
1137 if (ident
!= NULL
) {
1138 printf("%s%d\t%s\t\t(%s)\n", ident
, uid
,
1139 (const char *)name
, enabled
? "enabled" : "disabled");
1141 printf("%d\t%s\t\t(%s)\n", uid
,
1142 (const char *)name
, enabled
? "enabled" : "disabled");
1152 print_func
[obj
->type
](ident
, obj
);
1162 isns_obj_t
*obj
= (isns_obj_t
*)p1
;
1163 print_func
[obj
->type
](NULL
, obj
);
1172 cache_dump_htab(OBJ_PG
);
1179 cache_dump_htab(OBJ_PORTAL
);
1186 cache_dump_htab(OBJ_ISCSI
);
1193 cache_dump_htab(OBJ_ENTITY
);
1200 cache_dump_htab(OBJ_DD
);
1214 setup_ddid_lcp(&lc
, uid
);
1215 cache_lookup(&lc
, &uid
, cb_print_obj_n
);
1219 printf("--------------------------------\n");
1220 get_dd_matrix(uid
, &p
, &n
);
1221 SET_UID_LCP(&lc
, OBJ_ISCSI
, 0);
1222 FOR_EACH_MEMBER(p
, n
, uid
, {
1223 lc
.data
[0].ui
= uid
;
1224 cache_lookup(&lc
, NULL
, cb_print_obj_n
);
1228 printf("no such dd.\n");
1243 setup_ddsid_lcp(&lc
, uid
);
1244 cache_lookup(&lc
, &uid
, cb_print_obj_n
);
1248 printf("--------------------------------\n");
1249 get_dds_matrix(uid
, &p
, &n
);
1250 SET_UID_LCP(&lc
, OBJ_DD
, 0);
1251 FOR_EACH_MEMBER(p
, n
, uid
, {
1252 lc
.data
[0].ui
= uid
;
1253 cache_lookup(&lc
, NULL
, cb_print_obj_n
);
1257 printf("no such dd-set.\n");
1265 cache_dump_htab(OBJ_DDS
);
1276 isns_pdu_t
*pdu
= (isns_pdu_t
*)buff
;
1277 uint8_t *payload
= &pdu
->payload
[0];
1278 uint16_t payload_len
= 0;
1287 pdu
->version
= ISNSP_VERSION
;
1289 /* source attribute */
1290 tlv
= (isns_tlv_t
*)payload
;
1291 tlv
->attr_id
= htonl(ISNS_ISCSI_NAME_ATTR_ID
);
1292 tlv
->attr_len
= htonl(32);
1293 strcpy((char *)tlv
->attr_value
, "i am a control node.");
1295 payload_len
+= 8 + 32;
1297 /* key attributes */
1300 tlv
= (isns_tlv_t
*)payload
;
1301 tlv
->attr_id
= htonl(ISNS_DELIMITER_ATTR_ID
);
1302 tlv
->attr_len
= htonl(0);
1304 payload_len
+= 8 + 0;
1306 /* operating attributes */
1309 pdu
->func_id
= ISNS_DD_REG
;
1311 name
= (char *)argv
[0];
1312 len
= strlen(name
) + 1;
1313 len
+= 4 - (len
% 4);
1315 tlv
= (isns_tlv_t
*)payload
;
1316 tlv
->attr_id
= htonl(ISNS_DD_NAME_ATTR_ID
);
1317 tlv
->attr_len
= htonl(len
);
1319 strcpy((char *)tlv
->attr_value
, name
);
1321 payload_len
+= 8 + len
;
1324 pdu
->func_id
= ISNS_DDS_REG
;
1326 name
= (char *)argv
[0];
1327 len
= strlen(name
) + 1;
1328 len
+= 4 - (len
% 4);
1330 tlv
= (isns_tlv_t
*)payload
;
1331 tlv
->attr_id
= htonl(ISNS_DD_SET_NAME_ATTR_ID
);
1332 tlv
->attr_len
= htonl(len
);
1334 strcpy((char *)tlv
->attr_value
, name
);
1336 payload_len
+= 8 + len
;
1339 pdu
->func_id
= ISNS_DD_REG
;
1342 name
= (char *)argv
[1];
1343 len
= strlen(name
) + 1;
1344 len
+= 4 - (len
% 4);
1348 tlv
= (isns_tlv_t
*)payload
;
1349 tlv
->attr_id
= htonl(ISNS_DD_NAME_ATTR_ID
);
1350 tlv
->attr_len
= htonl(len
);
1352 strcpy((char *)tlv
->attr_value
, name
);
1355 payload_len
+= 8 + len
;
1357 tlv
= (isns_tlv_t
*)payload
;
1358 tlv
->attr_id
= htonl(ISNS_DD_ID_ATTR_ID
);
1359 tlv
->attr_len
= htonl(4);
1360 *(uint32_t *)tlv
->attr_value
= htonl(uid
);
1361 payload_len
+= 8 + 4;
1365 pdu
->func_id
= ISNS_DDS_REG
;
1368 name
= (char *)argv
[1];
1369 len
= strlen(name
) + 1;
1370 len
+= 4 - (len
% 4);
1374 tlv
= (isns_tlv_t
*)payload
;
1375 tlv
->attr_id
= htonl(ISNS_DD_SET_NAME_ATTR_ID
);
1376 tlv
->attr_len
= htonl(len
);
1378 strcpy((char *)tlv
->attr_value
, name
);
1380 payload_len
+= 8 + len
;
1383 tlv
= (isns_tlv_t
*)payload
;
1384 tlv
->attr_id
= htonl(ISNS_DD_SET_ID_ATTR_ID
);
1385 tlv
->attr_len
= htonl(4);
1386 *(uint32_t *)tlv
->attr_value
= htonl(uid
);
1387 payload_len
+= 8 + 4;
1394 pdu
->payload_len
= payload_len
;
1398 conn
.in_packet
.pdu
= pdu
;
1399 conn
.out_packet
.pdu
= NULL
;
1400 conn
.out_packet
.sz
= 0;
1402 if (packet_split_verify(&conn
) == 0) {
1403 cache_lock(conn
.lock
);
1404 conn
.handler(&conn
);
1405 conn
.ec
= cache_unlock(conn
.lock
, conn
.ec
);
1408 if (conn
.out_packet
.pdu
!= NULL
) {
1409 pdu_update_code(conn
.out_packet
.pdu
,
1410 &conn
.out_packet
.pl
, conn
.ec
);
1411 dump_pdu2(conn
.out_packet
.pdu
);
1412 free(conn
.out_packet
.pdu
);
1413 } else if (conn
.ec
!= 0) {
1414 printf("operation failed[%d].\n", conn
.ec
);
1425 isns_pdu_t
*pdu
= (isns_pdu_t
*)buff
;
1426 uint8_t *payload
= &pdu
->payload
[0];
1427 uint16_t payload_len
= 0;
1438 pdu
->version
= ISNSP_VERSION
;
1440 if (cmd_id
== CMD_DELDD
) {
1441 tag
= ISNS_DD_ID_ATTR_ID
;
1442 pdu
->func_id
= ISNS_DD_DEREG
;
1444 tag
= ISNS_DD_SET_ID_ATTR_ID
;
1445 pdu
->func_id
= ISNS_DDS_DEREG
;
1448 /* source attribute */
1449 tlv
= (isns_tlv_t
*)payload
;
1450 tlv
->attr_id
= htonl(ISNS_ISCSI_NAME_ATTR_ID
);
1451 tlv
->attr_len
= htonl(32);
1452 strcpy((char *)tlv
->attr_value
, "i am a control node.");
1453 payload_len
+= 8 + 32;
1456 /* key attributes */
1457 tlv
= (isns_tlv_t
*)payload
;
1458 tlv
->attr_id
= htonl(tag
);
1459 tlv
->attr_len
= htonl(4);
1460 *(uint32_t *)tlv
->attr_value
= htonl(uid
);
1461 payload_len
+= 8 + 4;
1465 tlv
= (isns_tlv_t
*)payload
;
1466 tlv
->attr_id
= htonl(ISNS_DELIMITER_ATTR_ID
);
1467 tlv
->attr_len
= htonl(0);
1468 payload_len
+= 8 + 0;
1471 /* operating attributes */
1473 pdu
->payload_len
= payload_len
;
1477 conn
.in_packet
.pdu
= pdu
;
1478 conn
.out_packet
.pdu
= NULL
;
1479 conn
.out_packet
.sz
= 0;
1481 if (packet_split_verify(&conn
) == 0) {
1482 cache_lock(conn
.lock
);
1483 conn
.handler(&conn
);
1484 conn
.ec
= cache_unlock(conn
.lock
, conn
.ec
);
1487 if (conn
.out_packet
.pdu
!= NULL
) {
1488 pdu_update_code(conn
.out_packet
.pdu
,
1489 &conn
.out_packet
.pl
, conn
.ec
);
1490 dump_pdu2(conn
.out_packet
.pdu
);
1491 free(conn
.out_packet
.pdu
);
1492 } else if (conn
.ec
!= 0) {
1493 printf("operation failed[%d].\n", conn
.ec
);
1504 isns_pdu_t
*pdu
= (isns_pdu_t
*)buff
;
1505 uint8_t *payload
= &pdu
->payload
[0];
1506 uint16_t payload_len
= 0;
1515 pdu
->version
= ISNSP_VERSION
;
1517 pdu
->func_id
= ISNS_DDS_REG
;
1519 /* source attribute */
1520 tlv
= (isns_tlv_t
*)payload
;
1521 tlv
->attr_id
= htonl(ISNS_ISCSI_NAME_ATTR_ID
);
1522 tlv
->attr_len
= htonl(32);
1523 strcpy((char *)tlv
->attr_value
, "i am a control node.");
1524 payload_len
+= 8 + 32;
1527 /* key attributes */
1528 tlv
= (isns_tlv_t
*)payload
;
1529 tlv
->attr_id
= htonl(ISNS_DD_SET_ID_ATTR_ID
);
1530 tlv
->attr_len
= htonl(4);
1531 *(uint32_t *)tlv
->attr_value
= htonl(uid
);
1532 payload_len
+= 8 + 4;
1536 tlv
= (isns_tlv_t
*)payload
;
1537 tlv
->attr_id
= htonl(ISNS_DELIMITER_ATTR_ID
);
1538 tlv
->attr_len
= htonl(0);
1539 payload_len
+= 8 + 0;
1542 /* operating attributes */
1543 tlv
= (isns_tlv_t
*)payload
;
1544 tlv
->attr_id
= htonl(ISNS_DD_SET_STATUS_ATTR_ID
);
1545 tlv
->attr_len
= htonl(4);
1546 if (cmd_id
== CMD_ENABLE
) {
1547 *(uint32_t *)tlv
->attr_value
= htonl(1);
1549 *(uint32_t *)tlv
->attr_value
= htonl(0);
1551 payload_len
+= 8 + 4;
1553 pdu
->payload_len
= payload_len
;
1557 conn
.in_packet
.pdu
= pdu
;
1558 conn
.out_packet
.pdu
= NULL
;
1559 conn
.out_packet
.sz
= 0;
1561 if (packet_split_verify(&conn
) == 0) {
1562 cache_lock(conn
.lock
);
1563 conn
.handler(&conn
);
1564 conn
.ec
= cache_unlock(conn
.lock
, conn
.ec
);
1567 if (conn
.out_packet
.pdu
!= NULL
) {
1568 pdu_update_code(conn
.out_packet
.pdu
,
1569 &conn
.out_packet
.pl
, conn
.ec
);
1570 dump_pdu2(conn
.out_packet
.pdu
);
1571 free(conn
.out_packet
.pdu
);
1572 } else if (conn
.ec
!= 0) {
1573 printf("operation failed[%d].\n", conn
.ec
);
1584 isns_pdu_t
*pdu
= (isns_pdu_t
*)buff
;
1585 uint8_t *payload
= &pdu
->payload
[0];
1586 uint16_t payload_len
= 0;
1588 uint32_t key_tag
, op_tag
, op_len
;
1590 uint32_t uid
= argv
[0];
1597 printf("operation failed.\n");
1601 pdu
->version
= ISNSP_VERSION
;
1606 pdu
->func_id
= ISNS_DD_REG
;
1610 pdu
->func_id
= ISNS_DD_DEREG
;
1613 pdu
->func_id
= ISNS_DDS_REG
;
1616 pdu
->func_id
= ISNS_DDS_DEREG
;
1622 key_tag
= ISNS_DD_ID_ATTR_ID
;
1623 op_tag
= ISNS_DD_ISCSI_NAME_ATTR_ID
;
1624 m_name
= (char *)argv
[1];
1625 op_len
= strlen(m_name
);
1626 op_len
+= 4 - (op_len
% 4);
1630 key_tag
= ISNS_DD_ID_ATTR_ID
;
1631 op_tag
= ISNS_DD_ISCSI_INDEX_ATTR_ID
;
1637 key_tag
= ISNS_DD_SET_ID_ATTR_ID
;
1638 op_tag
= ISNS_DD_ID_ATTR_ID
;
1644 /* source attribute */
1645 tlv
= (isns_tlv_t
*)payload
;
1646 tlv
->attr_id
= htonl(ISNS_ISCSI_NAME_ATTR_ID
);
1647 tlv
->attr_len
= htonl(32);
1648 strcpy((char *)tlv
->attr_value
, "i am a control node.");
1649 payload_len
+= 8 + 32;
1652 /* key attributes */
1653 tlv
= (isns_tlv_t
*)payload
;
1654 tlv
->attr_id
= htonl(key_tag
);
1655 tlv
->attr_len
= htonl(4);
1656 *(uint32_t *)tlv
->attr_value
= htonl(uid
);
1657 payload_len
+= 8 + 4;
1661 tlv
= (isns_tlv_t
*)payload
;
1662 tlv
->attr_id
= htonl(ISNS_DELIMITER_ATTR_ID
);
1663 tlv
->attr_len
= htonl(0);
1664 payload_len
+= 8 + 0;
1667 /* operating attributes */
1668 tlv
= (isns_tlv_t
*)payload
;
1669 tlv
->attr_id
= htonl(op_tag
);
1670 tlv
->attr_len
= htonl(op_len
);
1674 strcpy((char *)tlv
->attr_value
, m_name
);
1680 *(uint32_t *)tlv
->attr_value
= htonl(m_id
);
1683 payload_len
+= 8 + op_len
;
1685 pdu
->payload_len
= payload_len
;
1689 conn
.in_packet
.pdu
= pdu
;
1690 conn
.out_packet
.pdu
= NULL
;
1691 conn
.out_packet
.sz
= 0;
1693 if (packet_split_verify(&conn
) == 0) {
1694 cache_lock(conn
.lock
);
1695 conn
.handler(&conn
);
1696 conn
.ec
= cache_unlock(conn
.lock
, conn
.ec
);
1699 if (conn
.out_packet
.pdu
!= NULL
) {
1700 pdu_update_code(conn
.out_packet
.pdu
,
1701 &conn
.out_packet
.pl
, conn
.ec
);
1702 dump_pdu2(conn
.out_packet
.pdu
);
1703 free(conn
.out_packet
.pdu
);
1704 } else if (conn
.ec
!= 0) {
1705 printf("operation failed[%d].\n", conn
.ec
);
1714 char i
= 0, ch
, cmd
[256];
1715 FILE *f
= fopen(file
, "r");
1717 while ((ch
= fgetc(f
)) != 0 && ch
!= EOF
) {
1720 } else if (ch
!= '\n') {
1726 printf("%s\n", cmd
);
1727 if (run_cmd(cmd
) != 0) {
1734 printf("Cannot open file %s.\n", file
);
1745 cmd_id
= getcmd(&argc
, argv
, cmd
);
1775 new_dd_dds(cmd_id
, argc
, argv
);
1779 del_dd_dds(cmd_id
, argv
[0]);
1783 update_dds(cmd_id
, argv
[0]);
1791 update_member(cmd_id
, argv
);
1794 printf("Press enter to continue...");
1798 cmd_file((char *)argv
[0]);
1803 case CMD_VERBOSE_MEMORY
:
1804 verbose_mc
= !verbose_mc
;
1806 case CMD_VERBOSE_NET
:
1807 verbose_net
= !verbose_net
;
1809 case CMD_VERBOSE_TIME
:
1810 verbose_tc
= !verbose_tc
;
1812 case CMD_VERBOSE_LOCK
:
1813 verbose_lock
= !verbose_lock
;
1815 case CMD_VERBOSE_PARSER
:
1816 verbose_parser
= !verbose_parser
;
1820 /* notify sys control */
1826 printf("invalid command\n");
1829 if (cmd_id
!= CMD_NONE
) {
1838 void *cli_test(void *arg
) {
1839 char i
= 0, ch
, cmd
[256];
1841 printf("iSNS Server test CLI.\n");
1842 printf("Copyright 2007 Sun Microsystems, Inc.\n");
1845 while ((ch
= getchar()) != 0 && ch
!= EOF
) {
1848 } else if (ch
!= '\n') {
1854 if (run_cmd(cmd
) != 0) {