xref: /illumos-gate/usr/src/cmd/isns/isnsd/dump.c (revision fcf3ce44)
1*fcf3ce44SJohn Forte /*
2*fcf3ce44SJohn Forte  * CDDL HEADER START
3*fcf3ce44SJohn Forte  *
4*fcf3ce44SJohn Forte  * The contents of this file are subject to the terms of the
5*fcf3ce44SJohn Forte  * Common Development and Distribution License (the "License").
6*fcf3ce44SJohn Forte  * You may not use this file except in compliance with the License.
7*fcf3ce44SJohn Forte  *
8*fcf3ce44SJohn Forte  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*fcf3ce44SJohn Forte  * or http://www.opensolaris.org/os/licensing.
10*fcf3ce44SJohn Forte  * See the License for the specific language governing permissions
11*fcf3ce44SJohn Forte  * and limitations under the License.
12*fcf3ce44SJohn Forte  *
13*fcf3ce44SJohn Forte  * When distributing Covered Code, include this CDDL HEADER in each
14*fcf3ce44SJohn Forte  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*fcf3ce44SJohn Forte  * If applicable, add the following below this CDDL HEADER, with the
16*fcf3ce44SJohn Forte  * fields enclosed by brackets "[]" replaced with your own identifying
17*fcf3ce44SJohn Forte  * information: Portions Copyright [yyyy] [name of copyright owner]
18*fcf3ce44SJohn Forte  *
19*fcf3ce44SJohn Forte  * CDDL HEADER END
20*fcf3ce44SJohn Forte  */
21*fcf3ce44SJohn Forte 
22*fcf3ce44SJohn Forte /*
23*fcf3ce44SJohn Forte  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24*fcf3ce44SJohn Forte  * Use is subject to license terms.
25*fcf3ce44SJohn Forte  */
26*fcf3ce44SJohn Forte 
27*fcf3ce44SJohn Forte /* This file is getting large unexpectly, a lex & yacc */
28*fcf3ce44SJohn Forte /* implementation is expected. */
29*fcf3ce44SJohn Forte 
30*fcf3ce44SJohn Forte 
31*fcf3ce44SJohn Forte #include <stdio.h>
32*fcf3ce44SJohn Forte #include <stdlib.h>
33*fcf3ce44SJohn Forte #include <string.h>
34*fcf3ce44SJohn Forte #include <sys/types.h>
35*fcf3ce44SJohn Forte #include <sys/stat.h>
36*fcf3ce44SJohn Forte #include <sys/socket.h>
37*fcf3ce44SJohn Forte #include <netinet/in.h>
38*fcf3ce44SJohn Forte #include <arpa/inet.h>
39*fcf3ce44SJohn Forte #include <fcntl.h>
40*fcf3ce44SJohn Forte #include <unistd.h>
41*fcf3ce44SJohn Forte #include <pthread.h>
42*fcf3ce44SJohn Forte 
43*fcf3ce44SJohn Forte #include "isns_server.h"
44*fcf3ce44SJohn Forte #include "isns_htab.h"
45*fcf3ce44SJohn Forte #include "isns_msgq.h"
46*fcf3ce44SJohn Forte #include "isns_obj.h"
47*fcf3ce44SJohn Forte #include "isns_func.h"
48*fcf3ce44SJohn Forte #include "isns_dd.h"
49*fcf3ce44SJohn Forte #include "isns_cache.h"
50*fcf3ce44SJohn Forte #include "isns_pdu.h"
51*fcf3ce44SJohn Forte 
52*fcf3ce44SJohn Forte #ifdef DEBUG
53*fcf3ce44SJohn Forte /*
54*fcf3ce44SJohn Forte  * external variables
55*fcf3ce44SJohn Forte  */
56*fcf3ce44SJohn Forte extern const int NUM_OF_CHILD[MAX_OBJ_TYPE];
57*fcf3ce44SJohn Forte extern const int TYPE_OF_CHILD[MAX_OBJ_TYPE][MAX_CHILD_TYPE];
58*fcf3ce44SJohn Forte extern const int UID_ATTR_INDEX[MAX_OBJ_TYPE_FOR_SIZE];
59*fcf3ce44SJohn Forte extern const int NUM_OF_REF[MAX_OBJ_TYPE_FOR_SIZE];
60*fcf3ce44SJohn Forte 
61*fcf3ce44SJohn Forte extern lookup_ctrl_t *setup_ddid_lcp(lookup_ctrl_t *, uint32_t);
62*fcf3ce44SJohn Forte extern lookup_ctrl_t *setup_ddsid_lcp(lookup_ctrl_t *, uint32_t);
63*fcf3ce44SJohn Forte 
64*fcf3ce44SJohn Forte /*
65*fcf3ce44SJohn Forte  * global variables
66*fcf3ce44SJohn Forte  */
67*fcf3ce44SJohn Forte int verbose_mc = 0;
68*fcf3ce44SJohn Forte int verbose_tc = 0;
69*fcf3ce44SJohn Forte int verbose_lock = 0;
70*fcf3ce44SJohn Forte int verbose_net = 0;
71*fcf3ce44SJohn Forte int verbose_parser = 0;
72*fcf3ce44SJohn Forte 
73*fcf3ce44SJohn Forte /*
74*fcf3ce44SJohn Forte  * local variables
75*fcf3ce44SJohn Forte  */
76*fcf3ce44SJohn Forte static void print_entity(char *, isns_obj_t *);
77*fcf3ce44SJohn Forte static void print_iscsi(char *, isns_obj_t *);
78*fcf3ce44SJohn Forte static void print_portal(char *, isns_obj_t *);
79*fcf3ce44SJohn Forte static void print_pg(char *, isns_obj_t *);
80*fcf3ce44SJohn Forte static void print_dd(char *, isns_obj_t *);
81*fcf3ce44SJohn Forte static void print_dds(char *, isns_obj_t *);
82*fcf3ce44SJohn Forte static void (*const print_func[MAX_OBJ_TYPE])(char *, isns_obj_t *) = {
83*fcf3ce44SJohn Forte 	NULL,
84*fcf3ce44SJohn Forte 	&print_entity,
85*fcf3ce44SJohn Forte 	&print_iscsi,
86*fcf3ce44SJohn Forte 	&print_portal,
87*fcf3ce44SJohn Forte 	&print_pg,
88*fcf3ce44SJohn Forte 	&print_dd,
89*fcf3ce44SJohn Forte 	&print_dds
90*fcf3ce44SJohn Forte };
91*fcf3ce44SJohn Forte static int run_cmd(char *);
92*fcf3ce44SJohn Forte 
93*fcf3ce44SJohn Forte typedef struct {
94*fcf3ce44SJohn Forte 	uint16_t func_id;
95*fcf3ce44SJohn Forte 	char *fname;
96*fcf3ce44SJohn Forte } isnsp_fnames_t;
97*fcf3ce44SJohn Forte isnsp_fnames_t fnames[] = {
98*fcf3ce44SJohn Forte { ISNS_DEV_ATTR_REG, "DevAttrReg" },
99*fcf3ce44SJohn Forte { ISNS_DEV_ATTR_QRY, "DevAttrQry" },
100*fcf3ce44SJohn Forte { ISNS_DEV_GET_NEXT, "DevGetNext" },
101*fcf3ce44SJohn Forte { ISNS_DEV_DEREG, "DevDereg" },
102*fcf3ce44SJohn Forte { ISNS_SCN_REG, "SCNReg" },
103*fcf3ce44SJohn Forte { ISNS_SCN_DEREG, "SCNDereg" },
104*fcf3ce44SJohn Forte { ISNS_DD_REG, "DDReg" },
105*fcf3ce44SJohn Forte { ISNS_DD_DEREG, "DDDereg" },
106*fcf3ce44SJohn Forte { ISNS_DDS_REG, "DDSReg" },
107*fcf3ce44SJohn Forte { ISNS_DDS_DEREG, "DDSDereg" },
108*fcf3ce44SJohn Forte { ISNS_SCN, "SCN" },
109*fcf3ce44SJohn Forte { ISNS_ESI, "ESI" },
110*fcf3ce44SJohn Forte { ISNS_HEARTBEAT, "Heartbeat" },
111*fcf3ce44SJohn Forte { ISNS_DEV_ATTR_REG_RSP, "DevAttrRegRsp" },
112*fcf3ce44SJohn Forte { ISNS_DEV_ATTR_QRY_RSP, "DevAttrQryRsp" },
113*fcf3ce44SJohn Forte { ISNS_DEV_GET_NEXT_RSP, "DevGetNextRsp" },
114*fcf3ce44SJohn Forte { ISNS_DEV_DEREG_RSP, "DevDeregRsp" },
115*fcf3ce44SJohn Forte { ISNS_SCN_REG_RSP, "SCNRegRsp" },
116*fcf3ce44SJohn Forte { ISNS_SCN_DEREG_RSP, "SCNDeregRsp" },
117*fcf3ce44SJohn Forte { ISNS_SCN_RSP, "SCNRsp" },
118*fcf3ce44SJohn Forte { ISNS_ESI_RSP, "ESIRsp" },
119*fcf3ce44SJohn Forte { 0xFFFF, "Unknown" } };
120*fcf3ce44SJohn Forte 
121*fcf3ce44SJohn Forte static char *
get_func_name(uint16_t id)122*fcf3ce44SJohn Forte get_func_name(
123*fcf3ce44SJohn Forte 	uint16_t id
124*fcf3ce44SJohn Forte )
125*fcf3ce44SJohn Forte {
126*fcf3ce44SJohn Forte 	int i = 0;
127*fcf3ce44SJohn Forte 	isnsp_fnames_t *fp = &fnames[i ++];
128*fcf3ce44SJohn Forte 	while (fp->func_id != 0xFFFF) {
129*fcf3ce44SJohn Forte 		if (fp->func_id == id) {
130*fcf3ce44SJohn Forte 			return (fp->fname);
131*fcf3ce44SJohn Forte 		}
132*fcf3ce44SJohn Forte 		fp = &fnames[i ++];
133*fcf3ce44SJohn Forte 	}
134*fcf3ce44SJohn Forte 
135*fcf3ce44SJohn Forte 	return ("UNKNOWN");
136*fcf3ce44SJohn Forte }
137*fcf3ce44SJohn Forte 
138*fcf3ce44SJohn Forte static char *
get_tlv_tag_name(uint32_t tag)139*fcf3ce44SJohn Forte get_tlv_tag_name(
140*fcf3ce44SJohn Forte 	uint32_t tag
141*fcf3ce44SJohn Forte )
142*fcf3ce44SJohn Forte {
143*fcf3ce44SJohn Forte 	switch (tag) {
144*fcf3ce44SJohn Forte 		case ISNS_DELIMITER_ATTR_ID:
145*fcf3ce44SJohn Forte 			return ("Delimiter");
146*fcf3ce44SJohn Forte 		case ISNS_EID_ATTR_ID:
147*fcf3ce44SJohn Forte 			return ("Entity Identifier");
148*fcf3ce44SJohn Forte 		case ISNS_ENTITY_PROTOCOL_ATTR_ID:
149*fcf3ce44SJohn Forte 			return ("Entity Protocol");
150*fcf3ce44SJohn Forte 		case ISNS_ENTITY_REG_PERIOD_ATTR_ID:
151*fcf3ce44SJohn Forte 			return ("Registration Period");
152*fcf3ce44SJohn Forte 		case ISNS_TIMESTAMP_ATTR_ID:
153*fcf3ce44SJohn Forte 			return ("Timestamp");
154*fcf3ce44SJohn Forte 		case ISNS_PORTAL_IP_ADDR_ATTR_ID:
155*fcf3ce44SJohn Forte 			return ("Portal IP Address");
156*fcf3ce44SJohn Forte 		case ISNS_PORTAL_PORT_ATTR_ID:
157*fcf3ce44SJohn Forte 			return ("Portal TCP/UDP Port");
158*fcf3ce44SJohn Forte 		case ISNS_PORTAL_NAME_ATTR_ID:
159*fcf3ce44SJohn Forte 			return ("Portal Symbolic Name");
160*fcf3ce44SJohn Forte 		case ISNS_ESI_INTERVAL_ATTR_ID:
161*fcf3ce44SJohn Forte 			return ("ESI Interval");
162*fcf3ce44SJohn Forte 		case ISNS_ESI_PORT_ATTR_ID:
163*fcf3ce44SJohn Forte 			return ("ESI Port");
164*fcf3ce44SJohn Forte 		case ISNS_SCN_PORT_ATTR_ID:
165*fcf3ce44SJohn Forte 			return ("SCN Port");
166*fcf3ce44SJohn Forte 		case ISNS_PORTAL_SEC_BMP_ATTR_ID:
167*fcf3ce44SJohn Forte 			return ("Portal Security Bitmap");
168*fcf3ce44SJohn Forte 		case ISNS_ISCSI_NAME_ATTR_ID:
169*fcf3ce44SJohn Forte 			return ("iSCSI Name");
170*fcf3ce44SJohn Forte 		case ISNS_ISCSI_NODE_TYPE_ATTR_ID:
171*fcf3ce44SJohn Forte 			return ("iSCSI Node Type");
172*fcf3ce44SJohn Forte 		case ISNS_ISCSI_ALIAS_ATTR_ID:
173*fcf3ce44SJohn Forte 			return ("iSCSI Alias");
174*fcf3ce44SJohn Forte 		case ISNS_ISCSI_AUTH_METHOD_ATTR_ID:
175*fcf3ce44SJohn Forte 			return ("iSCSI Auth Method");
176*fcf3ce44SJohn Forte 		case ISNS_ISCSI_SCN_BITMAP_ATTR_ID:
177*fcf3ce44SJohn Forte 			return ("iSCSI SCN Bitmap");
178*fcf3ce44SJohn Forte 		case ISNS_PG_ISCSI_NAME_ATTR_ID:
179*fcf3ce44SJohn Forte 			return ("PG iSCSI Name");
180*fcf3ce44SJohn Forte 		case ISNS_PG_PORTAL_IP_ADDR_ATTR_ID:
181*fcf3ce44SJohn Forte 			return ("PG Portal IP Addr");
182*fcf3ce44SJohn Forte 		case ISNS_PG_PORTAL_PORT_ATTR_ID:
183*fcf3ce44SJohn Forte 			return ("PG Portal TCP/UDP Port");
184*fcf3ce44SJohn Forte 		case ISNS_PG_TAG_ATTR_ID:
185*fcf3ce44SJohn Forte 			return ("PG Tag (PGT)");
186*fcf3ce44SJohn Forte 		case ISNS_PG_INDEX_ATTR_ID:
187*fcf3ce44SJohn Forte 			return ("PG Index");
188*fcf3ce44SJohn Forte 		case ISNS_DD_NAME_ATTR_ID:
189*fcf3ce44SJohn Forte 			return ("DD Name");
190*fcf3ce44SJohn Forte 		case ISNS_DD_ID_ATTR_ID:
191*fcf3ce44SJohn Forte 			return ("DD Index");
192*fcf3ce44SJohn Forte 		case ISNS_DD_ISCSI_INDEX_ATTR_ID:
193*fcf3ce44SJohn Forte 			return ("DD ISCSI Node Index");
194*fcf3ce44SJohn Forte 		case ISNS_DD_ISCSI_NAME_ATTR_ID:
195*fcf3ce44SJohn Forte 			return ("DD ISCSI Node Name");
196*fcf3ce44SJohn Forte 		case ISNS_DD_SET_NAME_ATTR_ID:
197*fcf3ce44SJohn Forte 			return ("DDS Name");
198*fcf3ce44SJohn Forte 		case ISNS_DD_SET_ID_ATTR_ID:
199*fcf3ce44SJohn Forte 			return ("DDS Index");
200*fcf3ce44SJohn Forte 		case ISNS_DD_SET_STATUS_ATTR_ID:
201*fcf3ce44SJohn Forte 			return ("DDS Status");
202*fcf3ce44SJohn Forte 		default:
203*fcf3ce44SJohn Forte 			return ("Unknown");
204*fcf3ce44SJohn Forte 	}
205*fcf3ce44SJohn Forte }
206*fcf3ce44SJohn Forte 
207*fcf3ce44SJohn Forte static void
dump_pdu(isns_pdu_t * pdu,int flag)208*fcf3ce44SJohn Forte dump_pdu(
209*fcf3ce44SJohn Forte 	isns_pdu_t *pdu,
210*fcf3ce44SJohn Forte 	int flag
211*fcf3ce44SJohn Forte )
212*fcf3ce44SJohn Forte {
213*fcf3ce44SJohn Forte 	short ver, id, len, flags, xid, seq;
214*fcf3ce44SJohn Forte 
215*fcf3ce44SJohn Forte 	uint8_t *payload = pdu->payload;
216*fcf3ce44SJohn Forte 	isns_resp_t *resp;
217*fcf3ce44SJohn Forte 
218*fcf3ce44SJohn Forte 	/* convert the data */
219*fcf3ce44SJohn Forte 	if (flag) {
220*fcf3ce44SJohn Forte 		ver = ntohs(pdu->version);
221*fcf3ce44SJohn Forte 		id = ntohs(pdu->func_id);
222*fcf3ce44SJohn Forte 		len = ntohs(pdu->payload_len);
223*fcf3ce44SJohn Forte 		flags = ntohs(pdu->flags) & 0xFFFF;
224*fcf3ce44SJohn Forte 		xid = ntohs(pdu->xid);
225*fcf3ce44SJohn Forte 		seq = ntohs(pdu->seq);
226*fcf3ce44SJohn Forte 	} else {
227*fcf3ce44SJohn Forte 		ver = pdu->version;
228*fcf3ce44SJohn Forte 		id = pdu->func_id;
229*fcf3ce44SJohn Forte 		len = pdu->payload_len;
230*fcf3ce44SJohn Forte 		flags = pdu->flags & 0xFFFF;
231*fcf3ce44SJohn Forte 		xid = pdu->xid;
232*fcf3ce44SJohn Forte 		seq = pdu->seq;
233*fcf3ce44SJohn Forte 	}
234*fcf3ce44SJohn Forte 
235*fcf3ce44SJohn Forte 	/* print the pdu header */
236*fcf3ce44SJohn Forte 	printf("iSNSP Version: %d\n", ver);
237*fcf3ce44SJohn Forte 	printf("Function ID: %s\n", get_func_name(id));
238*fcf3ce44SJohn Forte 	printf("PDU Length: %d\n", len);
239*fcf3ce44SJohn Forte 	printf("Flags: %x\n", flags);
240*fcf3ce44SJohn Forte 	printf("    %d... .... .... .... : ISNS_FLAG_CLIENT\n",
241*fcf3ce44SJohn Forte 	    ((flags & ISNS_FLAG_CLIENT) == 0) ? 0 : 1);
242*fcf3ce44SJohn Forte 	printf("    .%d.. .... .... .... : ISNS_FLAG_SERVER\n",
243*fcf3ce44SJohn Forte 	    ((flags & ISNS_FLAG_SERVER) == 0) ? 0 : 1);
244*fcf3ce44SJohn Forte 	printf("    ..%d. .... .... .... : ISNS_FLAG_AUTH_BLK_PRESENTED\n",
245*fcf3ce44SJohn Forte 	    ((flags & ISNS_FLAG_AUTH_BLK_PRESENTED) == 0) ? 0 : 1);
246*fcf3ce44SJohn Forte 	printf("    ...%d .... .... .... : ISNS_FLAG_REPLACE_REG\n",
247*fcf3ce44SJohn Forte 	    ((flags & ISNS_FLAG_REPLACE_REG) == 0) ? 0 : 1);
248*fcf3ce44SJohn Forte 	printf("    .... %d... .... .... : ISNS_FLAG_LAST_PDU\n",
249*fcf3ce44SJohn Forte 	    ((flags & ISNS_FLAG_LAST_PDU) == 0) ? 0 : 1);
250*fcf3ce44SJohn Forte 	printf("    .... .%d.. .... .... : ISNS_FLAG_FIRST_PDU\n",
251*fcf3ce44SJohn Forte 	    ((flags & ISNS_FLAG_FIRST_PDU) == 0) ? 0 : 1);
252*fcf3ce44SJohn Forte 	printf("Transaction ID: %d\n", xid);
253*fcf3ce44SJohn Forte 	printf("Sequence ID: %d\n", seq);
254*fcf3ce44SJohn Forte 
255*fcf3ce44SJohn Forte 	printf("Payload: ...\n");
256*fcf3ce44SJohn Forte 	if (id & ISNS_RSP_MASK) {
257*fcf3ce44SJohn Forte 		resp = (isns_resp_t *)payload;
258*fcf3ce44SJohn Forte 		printf("    ErrorCode: %d\n", ntohl(resp->status));
259*fcf3ce44SJohn Forte 		len -= 4;
260*fcf3ce44SJohn Forte 		payload += 4;
261*fcf3ce44SJohn Forte 	}
262*fcf3ce44SJohn Forte 
263*fcf3ce44SJohn Forte 	/* print the payload */
264*fcf3ce44SJohn Forte 	while (len > 0) {
265*fcf3ce44SJohn Forte 		isns_tlv_t *tlvp;
266*fcf3ce44SJohn Forte 		int t, l;
267*fcf3ce44SJohn Forte 		uint8_t *v;
268*fcf3ce44SJohn Forte 		char *s;
269*fcf3ce44SJohn Forte 		int i;
270*fcf3ce44SJohn Forte 		in6_addr_t *ip;
271*fcf3ce44SJohn Forte 		char pbuff[256] = { 0 };
272*fcf3ce44SJohn Forte 
273*fcf3ce44SJohn Forte 		tlvp = (isns_tlv_t *)payload;
274*fcf3ce44SJohn Forte 
275*fcf3ce44SJohn Forte 		/* convert the data */
276*fcf3ce44SJohn Forte 		t = ntohl(tlvp->attr_id);
277*fcf3ce44SJohn Forte 		l = ntohl(tlvp->attr_len);
278*fcf3ce44SJohn Forte 		v = &(tlvp->attr_value[0]);
279*fcf3ce44SJohn Forte 
280*fcf3ce44SJohn Forte 		/* print payload */
281*fcf3ce44SJohn Forte 		if (l > 0) {
282*fcf3ce44SJohn Forte 			printf("%s: ", get_tlv_tag_name(t));
283*fcf3ce44SJohn Forte 			switch (t) {
284*fcf3ce44SJohn Forte 				case ISNS_EID_ATTR_ID:
285*fcf3ce44SJohn Forte 				case ISNS_ISCSI_NAME_ATTR_ID:
286*fcf3ce44SJohn Forte 				case ISNS_ISCSI_ALIAS_ATTR_ID:
287*fcf3ce44SJohn Forte 				case ISNS_ISCSI_AUTH_METHOD_ATTR_ID:
288*fcf3ce44SJohn Forte 				case ISNS_PG_ISCSI_NAME_ATTR_ID:
289*fcf3ce44SJohn Forte 				case ISNS_DD_NAME_ATTR_ID:
290*fcf3ce44SJohn Forte 				case ISNS_DD_SET_NAME_ATTR_ID:
291*fcf3ce44SJohn Forte 					s = (char *)v;
292*fcf3ce44SJohn Forte 					printf("%s\n", s);
293*fcf3ce44SJohn Forte 					break;
294*fcf3ce44SJohn Forte 				case ISNS_ENTITY_PROTOCOL_ATTR_ID:
295*fcf3ce44SJohn Forte 					i = ntohl(*(uint32_t *)v);
296*fcf3ce44SJohn Forte 					printf("%s (%d)\n",
297*fcf3ce44SJohn Forte 					    ((i == 1) ? "No Protocol" :
298*fcf3ce44SJohn Forte 					    ((i == 2) ? "iSCSI" :
299*fcf3ce44SJohn Forte 					    ((i == 3) ? "iFCP" :
300*fcf3ce44SJohn Forte 					    "Others"))),
301*fcf3ce44SJohn Forte 					    i);
302*fcf3ce44SJohn Forte 					break;
303*fcf3ce44SJohn Forte 				case ISNS_PORTAL_IP_ADDR_ATTR_ID:
304*fcf3ce44SJohn Forte 				case ISNS_PG_PORTAL_IP_ADDR_ATTR_ID:
305*fcf3ce44SJohn Forte 					ip = (in6_addr_t *)v;
306*fcf3ce44SJohn Forte 					inet_ntop(AF_INET6, (void *)ip,
307*fcf3ce44SJohn Forte 					    pbuff, sizeof (pbuff));
308*fcf3ce44SJohn Forte 					printf("%s\n", pbuff);
309*fcf3ce44SJohn Forte 					break;
310*fcf3ce44SJohn Forte 				case ISNS_PORTAL_PORT_ATTR_ID:
311*fcf3ce44SJohn Forte 				case ISNS_ESI_PORT_ATTR_ID:
312*fcf3ce44SJohn Forte 				case ISNS_SCN_PORT_ATTR_ID:
313*fcf3ce44SJohn Forte 					i = ntohl(*(uint32_t *)v);
314*fcf3ce44SJohn Forte 					printf("%d\n", (i & 0x0000FFFF));
315*fcf3ce44SJohn Forte 					printf("    .... .... %d... .... : "
316*fcf3ce44SJohn Forte 					    "0=TCP\n",
317*fcf3ce44SJohn Forte 					    ((i & 0x10000) == 0) ? 0 : 1);
318*fcf3ce44SJohn Forte 					break;
319*fcf3ce44SJohn Forte 				case ISNS_ISCSI_NODE_TYPE_ATTR_ID:
320*fcf3ce44SJohn Forte 					i = ntohl(*(uint32_t *)v);
321*fcf3ce44SJohn Forte 					printf("0x%x\t", i);
322*fcf3ce44SJohn Forte 					if (i & ISNS_CONTROL_NODE_TYPE) {
323*fcf3ce44SJohn Forte 						printf("Control ");
324*fcf3ce44SJohn Forte 					}
325*fcf3ce44SJohn Forte 					if (i & ISNS_INITIATOR_NODE_TYPE) {
326*fcf3ce44SJohn Forte 						printf("Initiator ");
327*fcf3ce44SJohn Forte 					}
328*fcf3ce44SJohn Forte 					if (i & ISNS_TARGET_NODE_TYPE) {
329*fcf3ce44SJohn Forte 						printf("Target ");
330*fcf3ce44SJohn Forte 					}
331*fcf3ce44SJohn Forte 					printf("\n");
332*fcf3ce44SJohn Forte 					break;
333*fcf3ce44SJohn Forte 				case ISNS_PG_TAG_ATTR_ID:
334*fcf3ce44SJohn Forte 				default:
335*fcf3ce44SJohn Forte 					i = ntohl(*(uint32_t *)v);
336*fcf3ce44SJohn Forte 					printf("%d\n", i);
337*fcf3ce44SJohn Forte 					break;
338*fcf3ce44SJohn Forte 			}
339*fcf3ce44SJohn Forte 			printf("    Attribute Tag: %s (%d)\n",
340*fcf3ce44SJohn Forte 			    get_tlv_tag_name(t), t);
341*fcf3ce44SJohn Forte 			printf("    Attribute Length: %d\n", l);
342*fcf3ce44SJohn Forte 		} else {
343*fcf3ce44SJohn Forte 			printf("%s: (%d)\n", get_tlv_tag_name(t), t);
344*fcf3ce44SJohn Forte 		}
345*fcf3ce44SJohn Forte 
346*fcf3ce44SJohn Forte 		len -= (sizeof (uint32_t) * 2 + l);
347*fcf3ce44SJohn Forte 		payload += (sizeof (uint32_t) * 2 + l);
348*fcf3ce44SJohn Forte 	}
349*fcf3ce44SJohn Forte }
350*fcf3ce44SJohn Forte 
351*fcf3ce44SJohn Forte void
dump_pdu1(isns_pdu_t * pdu)352*fcf3ce44SJohn Forte dump_pdu1(
353*fcf3ce44SJohn Forte 	isns_pdu_t *pdu
354*fcf3ce44SJohn Forte )
355*fcf3ce44SJohn Forte {
356*fcf3ce44SJohn Forte 	if (verbose_net) {
357*fcf3ce44SJohn Forte 		printf("### PDU RECEIVED ###\n");
358*fcf3ce44SJohn Forte 		dump_pdu(pdu, 0);
359*fcf3ce44SJohn Forte 	}
360*fcf3ce44SJohn Forte }
361*fcf3ce44SJohn Forte 
362*fcf3ce44SJohn Forte void
dump_pdu2(isns_pdu_t * pdu)363*fcf3ce44SJohn Forte dump_pdu2(
364*fcf3ce44SJohn Forte 	isns_pdu_t *pdu
365*fcf3ce44SJohn Forte )
366*fcf3ce44SJohn Forte {
367*fcf3ce44SJohn Forte 	if (verbose_net) {
368*fcf3ce44SJohn Forte 		printf("### PDU SENT ###\n");
369*fcf3ce44SJohn Forte 		dump_pdu(pdu, 1);
370*fcf3ce44SJohn Forte 	}
371*fcf3ce44SJohn Forte }
372*fcf3ce44SJohn Forte 
373*fcf3ce44SJohn Forte void
dump_db()374*fcf3ce44SJohn Forte dump_db(
375*fcf3ce44SJohn Forte )
376*fcf3ce44SJohn Forte {
377*fcf3ce44SJohn Forte #if 0
378*fcf3ce44SJohn Forte 	isns_list_t *list, *lista, *listb;
379*fcf3ce44SJohn Forte 	isns_dds_t *dds;
380*fcf3ce44SJohn Forte 	isns_dd_t *dd;
381*fcf3ce44SJohn Forte 	isns_iscsi2_t *iscsi2;
382*fcf3ce44SJohn Forte 
383*fcf3ce44SJohn Forte 	printf("### DUMP DATABASE ###\n");
384*fcf3ce44SJohn Forte 	/* dump dds(s) */
385*fcf3ce44SJohn Forte 	list = dds_list;
386*fcf3ce44SJohn Forte 	while (list != NULL) {
387*fcf3ce44SJohn Forte 		dds = list->obj.dds;
388*fcf3ce44SJohn Forte 		printf("[DDS:%d]%s(%s)\n", dds->id, dds->name,
389*fcf3ce44SJohn Forte 		    dds->status ? "enabled" : "disabled");
390*fcf3ce44SJohn Forte 		lista = dds->dd_list;
391*fcf3ce44SJohn Forte 		/* dd(s) that belong to this dds */
392*fcf3ce44SJohn Forte 		while (lista != NULL) {
393*fcf3ce44SJohn Forte 			dd = lista->obj.dd;
394*fcf3ce44SJohn Forte 			printf("\t[DD:%d]%s\n", dd->id, dd->name);
395*fcf3ce44SJohn Forte 			lista = lista->next;
396*fcf3ce44SJohn Forte 		}
397*fcf3ce44SJohn Forte 		list = list->next;
398*fcf3ce44SJohn Forte 	}
399*fcf3ce44SJohn Forte 	/* dump dd(s) */
400*fcf3ce44SJohn Forte 	list = dd_list;
401*fcf3ce44SJohn Forte 	while (list != NULL) {
402*fcf3ce44SJohn Forte 		dd = list->obj.dd;
403*fcf3ce44SJohn Forte 		printf("[DD:%d]%s\n", dd->id, dd->name);
404*fcf3ce44SJohn Forte 		/* dds(s) this dd belongs to */
405*fcf3ce44SJohn Forte 		lista = dd->dds_list;
406*fcf3ce44SJohn Forte 		while (lista != NULL) {
407*fcf3ce44SJohn Forte 			dds = lista->obj.dds;
408*fcf3ce44SJohn Forte 			printf("\t[DDS:%d]%s\n", dds->id, dds->name);
409*fcf3ce44SJohn Forte 			lista = lista->next;
410*fcf3ce44SJohn Forte 		}
411*fcf3ce44SJohn Forte 		/* node(s) that this dd have */
412*fcf3ce44SJohn Forte 		listb = dd->iscsi_list;
413*fcf3ce44SJohn Forte 		while (listb != NULL) {
414*fcf3ce44SJohn Forte 			iscsi2 = listb->obj.iscsi2;
415*fcf3ce44SJohn Forte 			printf("\t[ISCSI:%d]%s\n", iscsi2->id, iscsi2->name);
416*fcf3ce44SJohn Forte 			listb = listb->next;
417*fcf3ce44SJohn Forte 		}
418*fcf3ce44SJohn Forte 		list = list->next;
419*fcf3ce44SJohn Forte 	}
420*fcf3ce44SJohn Forte 	/* dump node(s) */
421*fcf3ce44SJohn Forte 	list = iscsi_list;
422*fcf3ce44SJohn Forte 	while (list != NULL) {
423*fcf3ce44SJohn Forte 		iscsi2 = list->obj.iscsi2;
424*fcf3ce44SJohn Forte 		printf("[ISCSI:%d]%s\n", iscsi2->id, iscsi2->name);
425*fcf3ce44SJohn Forte 		lista = iscsi2->dd_list;
426*fcf3ce44SJohn Forte 		/* dd(s) that this node belongs to */
427*fcf3ce44SJohn Forte 		while (lista != NULL) {
428*fcf3ce44SJohn Forte 			dd = lista->obj.dd;
429*fcf3ce44SJohn Forte 			printf("\t[DD:%d]%s\n", dd->id, dd->name);
430*fcf3ce44SJohn Forte 			lista = lista->next;
431*fcf3ce44SJohn Forte 		}
432*fcf3ce44SJohn Forte 		list = list->next;
433*fcf3ce44SJohn Forte 	}
434*fcf3ce44SJohn Forte #endif
435*fcf3ce44SJohn Forte }
436*fcf3ce44SJohn Forte 
437*fcf3ce44SJohn Forte static void
test_cli_help()438*fcf3ce44SJohn Forte test_cli_help(
439*fcf3ce44SJohn Forte )
440*fcf3ce44SJohn Forte {
441*fcf3ce44SJohn Forte 	printf("list          - list all of storage node.\n");
442*fcf3ce44SJohn Forte 	printf("list dd  [id] - list all of dd or one with member.\n");
443*fcf3ce44SJohn Forte 	printf("list dds [id] - list all of dd-set or one with member.\n");
444*fcf3ce44SJohn Forte 
445*fcf3ce44SJohn Forte 	printf("\n");
446*fcf3ce44SJohn Forte 	printf("new dd  <name>  - create a dd with name.\n");
447*fcf3ce44SJohn Forte 	printf("new dds <name>  - create a dd-set with name.\n");
448*fcf3ce44SJohn Forte 	printf("new ddn  <id> <name>  - create a dd with id and name.\n");
449*fcf3ce44SJohn Forte 	printf("new ddsn <id> <name>  - create a dd-set with id and name.\n");
450*fcf3ce44SJohn Forte 	printf("del dd   <id>   - delete a dd.\n");
451*fcf3ce44SJohn Forte 	printf("del dds  <id>   - delete a dd-set.\n");
452*fcf3ce44SJohn Forte 
453*fcf3ce44SJohn Forte 	printf("\n");
454*fcf3ce44SJohn Forte 	printf("add dd   <dd_id>  <node_name> - add a node to dd.\n");
455*fcf3ce44SJohn Forte 	printf("add ddn  <dd_id>  <node_id>   - add a node to dd.\n");
456*fcf3ce44SJohn Forte 	printf("add ddsn <dds_id> <dd_id>     - add a dd to dd-set.\n");
457*fcf3ce44SJohn Forte 	printf("remove dd   <dd_id> <node_name> - remove a node from dd.\n");
458*fcf3ce44SJohn Forte 	printf("remove ddn  <dd_id> <node_id>   - remove a node from dd.\n");
459*fcf3ce44SJohn Forte 	printf("remove ddsn <dds_id> <dd_id>    - remove a dd from dd-set.\n");
460*fcf3ce44SJohn Forte 
461*fcf3ce44SJohn Forte 	printf("\n");
462*fcf3ce44SJohn Forte 	printf("enable  <dds_id> - enable a dd-set.\n");
463*fcf3ce44SJohn Forte 	printf("disable <dds_id> - disable a dd-set.\n");
464*fcf3ce44SJohn Forte 
465*fcf3ce44SJohn Forte 	printf("\n");
466*fcf3ce44SJohn Forte 	printf("file <f> - loading command from a file.\n");
467*fcf3ce44SJohn Forte 	printf("pause    - suspend batch until enter key is pressed.\n");
468*fcf3ce44SJohn Forte 
469*fcf3ce44SJohn Forte 	printf("help   - print this help.\n");
470*fcf3ce44SJohn Forte 	printf("quit   - stop iSNS server and quit.\n");
471*fcf3ce44SJohn Forte }
472*fcf3ce44SJohn Forte 
473*fcf3ce44SJohn Forte static enum {
474*fcf3ce44SJohn Forte 	CMD_LIST, CMD_LISTNE, CMD_LISTP, CMD_LISTPG,
475*fcf3ce44SJohn Forte 	CMD_LISTDD, CMD_LISTDDS, CMD_LISTDDN, CMD_LISTDDSN,
476*fcf3ce44SJohn Forte 	CMD_NEWDD, CMD_NEWDDS, CMD_NEWDDN, CMD_NEWDDSN,
477*fcf3ce44SJohn Forte 	CMD_DELDD, CMD_DELDDS,
478*fcf3ce44SJohn Forte 	CMD_ENABLE, CMD_DISABLE,
479*fcf3ce44SJohn Forte 	CMD_ADDDD, CMD_ADDDDN, CMD_ADDDDSN,
480*fcf3ce44SJohn Forte 	CMD_REMDD, CMD_REMDDN, CMD_REMDDSN,
481*fcf3ce44SJohn Forte 	CMD_VIEW,
482*fcf3ce44SJohn Forte 	CMD_FILE, CMD_PAUSE,
483*fcf3ce44SJohn Forte 	CMD_HELP,
484*fcf3ce44SJohn Forte 	CMD_VERBOSE_MEMORY, CMD_VERBOSE_NET,
485*fcf3ce44SJohn Forte 	CMD_VERBOSE_PARSER, CMD_VERBOSE_TIME,
486*fcf3ce44SJohn Forte 	CMD_VERBOSE_LOCK,
487*fcf3ce44SJohn Forte 	CMD_QUIT,
488*fcf3ce44SJohn Forte 	CMD_NONE, CMD_INVALID
489*fcf3ce44SJohn Forte };
490*fcf3ce44SJohn Forte 
491*fcf3ce44SJohn Forte static int
getcmd(int * argc,int * argv,char * cmd)492*fcf3ce44SJohn Forte getcmd(
493*fcf3ce44SJohn Forte 	int *argc, int *argv, char *cmd
494*fcf3ce44SJohn Forte )
495*fcf3ce44SJohn Forte {
496*fcf3ce44SJohn Forte 	int j = 0;
497*fcf3ce44SJohn Forte 	char tmp[256] = { 0 };
498*fcf3ce44SJohn Forte 	*argc = 0;
499*fcf3ce44SJohn Forte 	while (*cmd == ' ') cmd ++;
500*fcf3ce44SJohn Forte 
501*fcf3ce44SJohn Forte 	if (*cmd == 0) {
502*fcf3ce44SJohn Forte 		return (CMD_NONE);
503*fcf3ce44SJohn Forte 	} else if (*cmd == '?') {
504*fcf3ce44SJohn Forte 		return (CMD_HELP);
505*fcf3ce44SJohn Forte 	}
506*fcf3ce44SJohn Forte 
507*fcf3ce44SJohn Forte 	/* list, list dd, list dds, list dd 0 */
508*fcf3ce44SJohn Forte 	if (strncmp(cmd, "list ", 5) == 0) {
509*fcf3ce44SJohn Forte 		cmd += 5;
510*fcf3ce44SJohn Forte 		while (*cmd == ' ') cmd ++;
511*fcf3ce44SJohn Forte 		if (*cmd == 0) {
512*fcf3ce44SJohn Forte 			return (CMD_LIST);
513*fcf3ce44SJohn Forte 		} else if (*cmd == 'p') {
514*fcf3ce44SJohn Forte 			cmd ++;
515*fcf3ce44SJohn Forte 			while (*cmd == ' ') cmd ++;
516*fcf3ce44SJohn Forte 			if (*cmd == 0) {
517*fcf3ce44SJohn Forte 				return (CMD_LISTP);
518*fcf3ce44SJohn Forte 			}
519*fcf3ce44SJohn Forte 		} else if (*cmd == 'g') {
520*fcf3ce44SJohn Forte 			cmd ++;
521*fcf3ce44SJohn Forte 			while (*cmd == ' ') cmd ++;
522*fcf3ce44SJohn Forte 			if (*cmd == 0) {
523*fcf3ce44SJohn Forte 				return (CMD_LISTPG);
524*fcf3ce44SJohn Forte 			}
525*fcf3ce44SJohn Forte 		} else if (*cmd == 'e') {
526*fcf3ce44SJohn Forte 			cmd ++;
527*fcf3ce44SJohn Forte 			while (*cmd == ' ') cmd ++;
528*fcf3ce44SJohn Forte 			if (*cmd == 0) {
529*fcf3ce44SJohn Forte 				return (CMD_LISTNE);
530*fcf3ce44SJohn Forte 			}
531*fcf3ce44SJohn Forte 		} else if (strncmp(cmd, "dds ", 4) == 0) {
532*fcf3ce44SJohn Forte 			cmd += 4;
533*fcf3ce44SJohn Forte 			while (*cmd == ' ') cmd ++;
534*fcf3ce44SJohn Forte 			if (*cmd == 0) {
535*fcf3ce44SJohn Forte 				return (CMD_LISTDDS);
536*fcf3ce44SJohn Forte 			}
537*fcf3ce44SJohn Forte 			j = 0;
538*fcf3ce44SJohn Forte 			while (*cmd >= '0' && *cmd <= '9') {
539*fcf3ce44SJohn Forte 				tmp[j++] = *cmd ++;
540*fcf3ce44SJohn Forte 			}
541*fcf3ce44SJohn Forte 			tmp[j] = 0;
542*fcf3ce44SJohn Forte 			while (*cmd == ' ') cmd ++;
543*fcf3ce44SJohn Forte 			if (*cmd == 0 && j > 0) {
544*fcf3ce44SJohn Forte 				argv[(*argc)++] = atoi(tmp);
545*fcf3ce44SJohn Forte 				return (CMD_LISTDDSN);
546*fcf3ce44SJohn Forte 			}
547*fcf3ce44SJohn Forte 		} else if (strncmp(cmd, "dd ", 3) == 0) {
548*fcf3ce44SJohn Forte 			cmd += 3;
549*fcf3ce44SJohn Forte 			while (*cmd == ' ') cmd ++;
550*fcf3ce44SJohn Forte 			if (*cmd == 0) {
551*fcf3ce44SJohn Forte 				return (CMD_LISTDD);
552*fcf3ce44SJohn Forte 			}
553*fcf3ce44SJohn Forte 			j = 0;
554*fcf3ce44SJohn Forte 			while (*cmd >= '0' && *cmd <= '9') {
555*fcf3ce44SJohn Forte 				tmp[j++] = *cmd ++;
556*fcf3ce44SJohn Forte 			}
557*fcf3ce44SJohn Forte 			tmp[j] = 0;
558*fcf3ce44SJohn Forte 			while (*cmd == ' ') cmd ++;
559*fcf3ce44SJohn Forte 			if (*cmd == 0 && j > 0) {
560*fcf3ce44SJohn Forte 				argv[(*argc)++] = atoi(tmp);
561*fcf3ce44SJohn Forte 				return (CMD_LISTDDN);
562*fcf3ce44SJohn Forte 			}
563*fcf3ce44SJohn Forte 		}
564*fcf3ce44SJohn Forte 		return (CMD_INVALID);
565*fcf3ce44SJohn Forte 	}
566*fcf3ce44SJohn Forte 
567*fcf3ce44SJohn Forte 	/* view 0 */
568*fcf3ce44SJohn Forte 	if (strncmp(cmd, "view ", 5) == 0) {
569*fcf3ce44SJohn Forte 		cmd += 5;
570*fcf3ce44SJohn Forte 		while (*cmd == ' ') cmd ++;
571*fcf3ce44SJohn Forte 		j = 0;
572*fcf3ce44SJohn Forte 		while (*cmd >= '0' && *cmd <= '9') {
573*fcf3ce44SJohn Forte 			tmp[j++] = *cmd ++;
574*fcf3ce44SJohn Forte 		}
575*fcf3ce44SJohn Forte 		tmp[j] = 0;
576*fcf3ce44SJohn Forte 		while (*cmd == ' ') cmd ++;
577*fcf3ce44SJohn Forte 		if (*cmd == 0 && j > 0) {
578*fcf3ce44SJohn Forte 			argv[(*argc)++] = atoi(tmp);
579*fcf3ce44SJohn Forte 			return (CMD_VIEW);
580*fcf3ce44SJohn Forte 		}
581*fcf3ce44SJohn Forte 		return (CMD_INVALID);
582*fcf3ce44SJohn Forte 	}
583*fcf3ce44SJohn Forte 
584*fcf3ce44SJohn Forte 	/* add dd name */
585*fcf3ce44SJohn Forte 	/* add ddn/ddsn id id */
586*fcf3ce44SJohn Forte 	if (strncmp(cmd, "add ", 4) == 0) {
587*fcf3ce44SJohn Forte 		int addcmd = CMD_INVALID;
588*fcf3ce44SJohn Forte 		cmd += 4;
589*fcf3ce44SJohn Forte 		while (*cmd == ' ') cmd ++;
590*fcf3ce44SJohn Forte 		if (strncmp(cmd, "dd ", 3) == 0) {
591*fcf3ce44SJohn Forte 			cmd += 3;
592*fcf3ce44SJohn Forte 			addcmd = CMD_ADDDD;
593*fcf3ce44SJohn Forte 		} else if (strncmp(cmd, "ddn ", 4) == 0) {
594*fcf3ce44SJohn Forte 			cmd += 4;
595*fcf3ce44SJohn Forte 			addcmd = CMD_ADDDDN;
596*fcf3ce44SJohn Forte 		} else if (strncmp(cmd, "ddsn ", 5) == 0) {
597*fcf3ce44SJohn Forte 			cmd += 5;
598*fcf3ce44SJohn Forte 			addcmd = CMD_ADDDDSN;
599*fcf3ce44SJohn Forte 		} else {
600*fcf3ce44SJohn Forte 			return (CMD_INVALID);
601*fcf3ce44SJohn Forte 		}
602*fcf3ce44SJohn Forte 		while (*cmd == ' ') cmd ++;
603*fcf3ce44SJohn Forte 		j = 0;
604*fcf3ce44SJohn Forte 		while (*cmd >= '0' && *cmd <= '9') {
605*fcf3ce44SJohn Forte 			tmp[j++] = *cmd ++;
606*fcf3ce44SJohn Forte 		}
607*fcf3ce44SJohn Forte 		tmp[j] = 0;
608*fcf3ce44SJohn Forte 		if (j > 0) {
609*fcf3ce44SJohn Forte 			argv[(*argc)++] = atoi(tmp);
610*fcf3ce44SJohn Forte 		} else {
611*fcf3ce44SJohn Forte 			return (CMD_INVALID);
612*fcf3ce44SJohn Forte 		}
613*fcf3ce44SJohn Forte 		while (*cmd == ' ') cmd ++;
614*fcf3ce44SJohn Forte 		if (*cmd != 0) {
615*fcf3ce44SJohn Forte 			switch (addcmd) {
616*fcf3ce44SJohn Forte 			case CMD_ADDDDN:
617*fcf3ce44SJohn Forte 			case CMD_ADDDDSN:
618*fcf3ce44SJohn Forte 				j = 0;
619*fcf3ce44SJohn Forte 				while (*cmd >= '0' && *cmd <= '9') {
620*fcf3ce44SJohn Forte 					tmp[j++] = *cmd ++;
621*fcf3ce44SJohn Forte 				}
622*fcf3ce44SJohn Forte 				tmp[j] = 0;
623*fcf3ce44SJohn Forte 				while (*cmd == ' ') cmd ++;
624*fcf3ce44SJohn Forte 				if (*cmd == 0 && j > 0) {
625*fcf3ce44SJohn Forte 					argv[(*argc)++] = atoi(tmp);
626*fcf3ce44SJohn Forte 				} else {
627*fcf3ce44SJohn Forte 					return (CMD_INVALID);
628*fcf3ce44SJohn Forte 				}
629*fcf3ce44SJohn Forte 				break;
630*fcf3ce44SJohn Forte 			case CMD_ADDDD:
631*fcf3ce44SJohn Forte 				j = strlen(cmd);
632*fcf3ce44SJohn Forte 				while (j > 0) {
633*fcf3ce44SJohn Forte 					/* get rid of trail blank space */
634*fcf3ce44SJohn Forte 					if (cmd[j - 1] == ' ') {
635*fcf3ce44SJohn Forte 						cmd[--j] = 0;
636*fcf3ce44SJohn Forte 					} else {
637*fcf3ce44SJohn Forte 						break;
638*fcf3ce44SJohn Forte 					}
639*fcf3ce44SJohn Forte 				}
640*fcf3ce44SJohn Forte 				if (j > 0) {
641*fcf3ce44SJohn Forte 					cmd[j] = 0;
642*fcf3ce44SJohn Forte 					argv[(*argc)++] = (int)cmd;
643*fcf3ce44SJohn Forte 				} else {
644*fcf3ce44SJohn Forte 					return (CMD_INVALID);
645*fcf3ce44SJohn Forte 				}
646*fcf3ce44SJohn Forte 				break;
647*fcf3ce44SJohn Forte 			}
648*fcf3ce44SJohn Forte 			return (addcmd);
649*fcf3ce44SJohn Forte 		}
650*fcf3ce44SJohn Forte 		return (CMD_INVALID);
651*fcf3ce44SJohn Forte 	}
652*fcf3ce44SJohn Forte 
653*fcf3ce44SJohn Forte 	/* remove dd name */
654*fcf3ce44SJohn Forte 	/* remove ddn/ddsn id id */
655*fcf3ce44SJohn Forte 	if (strncmp(cmd, "remove ", 7) == 0) {
656*fcf3ce44SJohn Forte 		int rmcmd = CMD_INVALID;
657*fcf3ce44SJohn Forte 		cmd += 7;
658*fcf3ce44SJohn Forte 		while (*cmd == ' ') cmd ++;
659*fcf3ce44SJohn Forte 		if (strncmp(cmd, "dd ", 3) == 0) {
660*fcf3ce44SJohn Forte 			cmd += 3;
661*fcf3ce44SJohn Forte 			while (*cmd == ' ') cmd ++;
662*fcf3ce44SJohn Forte 			rmcmd = CMD_REMDD;
663*fcf3ce44SJohn Forte 		} else if (strncmp(cmd, "ddn ", 4) == 0) {
664*fcf3ce44SJohn Forte 			cmd += 4;
665*fcf3ce44SJohn Forte 			while (*cmd == ' ') cmd ++;
666*fcf3ce44SJohn Forte 			rmcmd = CMD_REMDDN;
667*fcf3ce44SJohn Forte 		} else if (strncmp(cmd, "ddsn ", 5) == 0) {
668*fcf3ce44SJohn Forte 			cmd += 5;
669*fcf3ce44SJohn Forte 			while (*cmd == ' ') cmd ++;
670*fcf3ce44SJohn Forte 			rmcmd = CMD_REMDDSN;
671*fcf3ce44SJohn Forte 		} else {
672*fcf3ce44SJohn Forte 			return (CMD_INVALID);
673*fcf3ce44SJohn Forte 		}
674*fcf3ce44SJohn Forte 		j = 0;
675*fcf3ce44SJohn Forte 		while (*cmd >= '0' && *cmd <= '9') {
676*fcf3ce44SJohn Forte 			tmp[j++] = *cmd ++;
677*fcf3ce44SJohn Forte 		}
678*fcf3ce44SJohn Forte 		tmp[j] = 0;
679*fcf3ce44SJohn Forte 		if (j > 0) {
680*fcf3ce44SJohn Forte 			argv[(*argc)++] = atoi(tmp);
681*fcf3ce44SJohn Forte 		} else {
682*fcf3ce44SJohn Forte 			return (CMD_INVALID);
683*fcf3ce44SJohn Forte 		}
684*fcf3ce44SJohn Forte 		while (*cmd == ' ') cmd ++;
685*fcf3ce44SJohn Forte 		if (*cmd != 0) {
686*fcf3ce44SJohn Forte 			switch (rmcmd) {
687*fcf3ce44SJohn Forte 			case CMD_REMDDN:
688*fcf3ce44SJohn Forte 			case CMD_REMDDSN:
689*fcf3ce44SJohn Forte 				j = 0;
690*fcf3ce44SJohn Forte 				while (*cmd >= '0' && *cmd <= '9') {
691*fcf3ce44SJohn Forte 					tmp[j++] = *cmd ++;
692*fcf3ce44SJohn Forte 				}
693*fcf3ce44SJohn Forte 				tmp[j] = 0;
694*fcf3ce44SJohn Forte 				while (*cmd == ' ') cmd ++;
695*fcf3ce44SJohn Forte 				if (*cmd == 0 && j > 0) {
696*fcf3ce44SJohn Forte 					argv[(*argc)++] = atoi(tmp);
697*fcf3ce44SJohn Forte 				} else {
698*fcf3ce44SJohn Forte 					return (CMD_INVALID);
699*fcf3ce44SJohn Forte 				}
700*fcf3ce44SJohn Forte 				break;
701*fcf3ce44SJohn Forte 			case CMD_REMDD:
702*fcf3ce44SJohn Forte 				j = strlen(cmd);
703*fcf3ce44SJohn Forte 				while (j > 0) {
704*fcf3ce44SJohn Forte 					/* get rid of trail blank space */
705*fcf3ce44SJohn Forte 					if (cmd[j - 1] == ' ') {
706*fcf3ce44SJohn Forte 						cmd[--j] = 0;
707*fcf3ce44SJohn Forte 					} else {
708*fcf3ce44SJohn Forte 						break;
709*fcf3ce44SJohn Forte 					}
710*fcf3ce44SJohn Forte 				}
711*fcf3ce44SJohn Forte 				if (j > 0) {
712*fcf3ce44SJohn Forte 					cmd[j] = 0;
713*fcf3ce44SJohn Forte 					argv[(*argc)++] = (int)cmd;
714*fcf3ce44SJohn Forte 				} else {
715*fcf3ce44SJohn Forte 					return (CMD_INVALID);
716*fcf3ce44SJohn Forte 				}
717*fcf3ce44SJohn Forte 				break;
718*fcf3ce44SJohn Forte 			}
719*fcf3ce44SJohn Forte 			return (rmcmd);
720*fcf3ce44SJohn Forte 		}
721*fcf3ce44SJohn Forte 		return (CMD_INVALID);
722*fcf3ce44SJohn Forte 	}
723*fcf3ce44SJohn Forte 
724*fcf3ce44SJohn Forte 	/* new dd, new dds */
725*fcf3ce44SJohn Forte 	if (strncmp(cmd, "new ", 4) == 0) {
726*fcf3ce44SJohn Forte 		int newcmd = CMD_INVALID;
727*fcf3ce44SJohn Forte 		cmd += 4;
728*fcf3ce44SJohn Forte 		while (*cmd == ' ') cmd ++;
729*fcf3ce44SJohn Forte 		if (strncmp(cmd, "dd ", 3) == 0) {
730*fcf3ce44SJohn Forte 			cmd += 3;
731*fcf3ce44SJohn Forte 			newcmd = CMD_NEWDD;
732*fcf3ce44SJohn Forte 		} else if (strncmp(cmd, "dds ", 4) == 0) {
733*fcf3ce44SJohn Forte 			cmd += 4;
734*fcf3ce44SJohn Forte 			newcmd = CMD_NEWDDS;
735*fcf3ce44SJohn Forte 		} else if (strncmp(cmd, "ddn ", 4) == 0) {
736*fcf3ce44SJohn Forte 			cmd += 4;
737*fcf3ce44SJohn Forte 			newcmd = CMD_NEWDDN;
738*fcf3ce44SJohn Forte 		} else if (strncmp(cmd, "ddsn ", 5) == 0) {
739*fcf3ce44SJohn Forte 			cmd += 5;
740*fcf3ce44SJohn Forte 			newcmd = CMD_NEWDDSN;
741*fcf3ce44SJohn Forte 		}
742*fcf3ce44SJohn Forte 		if (newcmd != CMD_INVALID) {
743*fcf3ce44SJohn Forte 			while (*cmd == ' ') cmd ++;
744*fcf3ce44SJohn Forte 			if (*cmd == 0) {
745*fcf3ce44SJohn Forte 				return (newcmd);
746*fcf3ce44SJohn Forte 			}
747*fcf3ce44SJohn Forte 			switch (newcmd) {
748*fcf3ce44SJohn Forte 			case CMD_NEWDDN:
749*fcf3ce44SJohn Forte 			case CMD_NEWDDSN:
750*fcf3ce44SJohn Forte 				j = 0;
751*fcf3ce44SJohn Forte 				while (*cmd >= '0' && *cmd <= '9') {
752*fcf3ce44SJohn Forte 					tmp[j++] = *cmd ++;
753*fcf3ce44SJohn Forte 				}
754*fcf3ce44SJohn Forte 				tmp[j] = 0;
755*fcf3ce44SJohn Forte 				if (*cmd == ' ' && j > 0) {
756*fcf3ce44SJohn Forte 					argv[(*argc)++] = atoi(tmp);
757*fcf3ce44SJohn Forte 				} else {
758*fcf3ce44SJohn Forte 					return (CMD_INVALID);
759*fcf3ce44SJohn Forte 				}
760*fcf3ce44SJohn Forte 			case CMD_NEWDD:
761*fcf3ce44SJohn Forte 			case CMD_NEWDDS:
762*fcf3ce44SJohn Forte 				while (*cmd == ' ') cmd ++;
763*fcf3ce44SJohn Forte 				if (*cmd != 0) {
764*fcf3ce44SJohn Forte 					j = strlen(cmd);
765*fcf3ce44SJohn Forte 				} else {
766*fcf3ce44SJohn Forte 					j = 0;
767*fcf3ce44SJohn Forte 				}
768*fcf3ce44SJohn Forte 				while (j > 0) {
769*fcf3ce44SJohn Forte 					/* get rid of trail blank space */
770*fcf3ce44SJohn Forte 					if (cmd[j - 1] == ' ') {
771*fcf3ce44SJohn Forte 						cmd[--j] = 0;
772*fcf3ce44SJohn Forte 					} else {
773*fcf3ce44SJohn Forte 						break;
774*fcf3ce44SJohn Forte 					}
775*fcf3ce44SJohn Forte 				}
776*fcf3ce44SJohn Forte 				if (j > 0) {
777*fcf3ce44SJohn Forte 					cmd[j] = 0;
778*fcf3ce44SJohn Forte 					argv[(*argc)++] = (int)cmd;
779*fcf3ce44SJohn Forte 				}
780*fcf3ce44SJohn Forte 			}
781*fcf3ce44SJohn Forte 			return (newcmd);
782*fcf3ce44SJohn Forte 		}
783*fcf3ce44SJohn Forte 		return (CMD_INVALID);
784*fcf3ce44SJohn Forte 	}
785*fcf3ce44SJohn Forte 
786*fcf3ce44SJohn Forte 	/* del dd, del dds, disable 0 */
787*fcf3ce44SJohn Forte 	if (strncmp(cmd, "del ", 4) == 0) {
788*fcf3ce44SJohn Forte 		int delcmd = CMD_INVALID;
789*fcf3ce44SJohn Forte 		cmd += 4;
790*fcf3ce44SJohn Forte 		while (*cmd == ' ') cmd ++;
791*fcf3ce44SJohn Forte 		if (strncmp(cmd, "dds ", 4) == 0) {
792*fcf3ce44SJohn Forte 			cmd += 4;
793*fcf3ce44SJohn Forte 			delcmd = CMD_DELDDS;
794*fcf3ce44SJohn Forte 		} else if (strncmp(cmd, "dd ", 3) == 0) {
795*fcf3ce44SJohn Forte 			cmd += 3;
796*fcf3ce44SJohn Forte 			delcmd = CMD_DELDD;
797*fcf3ce44SJohn Forte 		}
798*fcf3ce44SJohn Forte 		if (delcmd != CMD_INVALID) {
799*fcf3ce44SJohn Forte 			while (*cmd == ' ') cmd ++;
800*fcf3ce44SJohn Forte 			j = 0;
801*fcf3ce44SJohn Forte 			while (*cmd >= '0' && *cmd <= '9') {
802*fcf3ce44SJohn Forte 				tmp[j++] = *cmd ++;
803*fcf3ce44SJohn Forte 			}
804*fcf3ce44SJohn Forte 			tmp[j] = 0;
805*fcf3ce44SJohn Forte 			while (*cmd == ' ') cmd ++;
806*fcf3ce44SJohn Forte 			if (*cmd == 0 && j > 0) {
807*fcf3ce44SJohn Forte 				argv[(*argc)++] = atoi(tmp);
808*fcf3ce44SJohn Forte 				return (delcmd);
809*fcf3ce44SJohn Forte 			}
810*fcf3ce44SJohn Forte 		}
811*fcf3ce44SJohn Forte 		return (CMD_INVALID);
812*fcf3ce44SJohn Forte 	}
813*fcf3ce44SJohn Forte 
814*fcf3ce44SJohn Forte 	/* enable 0 */
815*fcf3ce44SJohn Forte 	if (strncmp(cmd, "enable ", 7) == 0) {
816*fcf3ce44SJohn Forte 		cmd += 7;
817*fcf3ce44SJohn Forte 		while (*cmd == ' ') cmd ++;
818*fcf3ce44SJohn Forte 		j = 0;
819*fcf3ce44SJohn Forte 		while (*cmd >= '0' && *cmd <= '9') {
820*fcf3ce44SJohn Forte 			tmp[j++] = *cmd ++;
821*fcf3ce44SJohn Forte 		}
822*fcf3ce44SJohn Forte 		tmp[j] = 0;
823*fcf3ce44SJohn Forte 		while (*cmd == ' ') cmd ++;
824*fcf3ce44SJohn Forte 		if (*cmd == 0 && j > 0) {
825*fcf3ce44SJohn Forte 			argv[(*argc)++] = atoi(tmp);
826*fcf3ce44SJohn Forte 			return (CMD_ENABLE);
827*fcf3ce44SJohn Forte 		}
828*fcf3ce44SJohn Forte 		return (CMD_INVALID);
829*fcf3ce44SJohn Forte 	}
830*fcf3ce44SJohn Forte 
831*fcf3ce44SJohn Forte 	/* disable 0 */
832*fcf3ce44SJohn Forte 	if (strncmp(cmd, "disable ", 8) == 0) {
833*fcf3ce44SJohn Forte 		cmd += 8;
834*fcf3ce44SJohn Forte 		while (*cmd == ' ') cmd ++;
835*fcf3ce44SJohn Forte 		j = 0;
836*fcf3ce44SJohn Forte 		while (*cmd >= '0' && *cmd <= '9') {
837*fcf3ce44SJohn Forte 			tmp[j++] = *cmd ++;
838*fcf3ce44SJohn Forte 		}
839*fcf3ce44SJohn Forte 		tmp[j] = 0;
840*fcf3ce44SJohn Forte 		while (*cmd == ' ') cmd ++;
841*fcf3ce44SJohn Forte 		if (*cmd == 0 && j > 0) {
842*fcf3ce44SJohn Forte 			argv[(*argc)++] = atoi(tmp);
843*fcf3ce44SJohn Forte 			return (CMD_DISABLE);
844*fcf3ce44SJohn Forte 		}
845*fcf3ce44SJohn Forte 		return (CMD_INVALID);
846*fcf3ce44SJohn Forte 	}
847*fcf3ce44SJohn Forte 
848*fcf3ce44SJohn Forte 	/* file */
849*fcf3ce44SJohn Forte 	if (strncmp(cmd, "file ", 5) == 0) {
850*fcf3ce44SJohn Forte 		cmd += 5;
851*fcf3ce44SJohn Forte 		while (*cmd == ' ') cmd ++;
852*fcf3ce44SJohn Forte 		if (*cmd != 0) {
853*fcf3ce44SJohn Forte 			j = strlen(cmd);
854*fcf3ce44SJohn Forte 		} else {
855*fcf3ce44SJohn Forte 			j = 0;
856*fcf3ce44SJohn Forte 		}
857*fcf3ce44SJohn Forte 		while (j > 0) {
858*fcf3ce44SJohn Forte 			/* get rid of trail blank space */
859*fcf3ce44SJohn Forte 			if (cmd[j - 1] == ' ') {
860*fcf3ce44SJohn Forte 				cmd[--j] = 0;
861*fcf3ce44SJohn Forte 			} else {
862*fcf3ce44SJohn Forte 				break;
863*fcf3ce44SJohn Forte 			}
864*fcf3ce44SJohn Forte 		}
865*fcf3ce44SJohn Forte 		if (j > 0) {
866*fcf3ce44SJohn Forte 			cmd[j] = 0;
867*fcf3ce44SJohn Forte 			argv[(*argc)++] = (int)cmd;
868*fcf3ce44SJohn Forte 			return (CMD_FILE);
869*fcf3ce44SJohn Forte 		}
870*fcf3ce44SJohn Forte 		return (CMD_INVALID);
871*fcf3ce44SJohn Forte 	}
872*fcf3ce44SJohn Forte 
873*fcf3ce44SJohn Forte 	/* pause */
874*fcf3ce44SJohn Forte 	if (strncmp(cmd, "pause ", 6) == 0) {
875*fcf3ce44SJohn Forte 		cmd += 6;
876*fcf3ce44SJohn Forte 		while (*cmd == ' ') cmd ++;
877*fcf3ce44SJohn Forte 		if (*cmd == 0) {
878*fcf3ce44SJohn Forte 			return (CMD_PAUSE);
879*fcf3ce44SJohn Forte 		}
880*fcf3ce44SJohn Forte 		return (CMD_INVALID);
881*fcf3ce44SJohn Forte 	}
882*fcf3ce44SJohn Forte 
883*fcf3ce44SJohn Forte 	/* help */
884*fcf3ce44SJohn Forte 	if (strncmp(cmd, "help ", 5) == 0) {
885*fcf3ce44SJohn Forte 		cmd += 5;
886*fcf3ce44SJohn Forte 		while (*cmd == ' ') cmd ++;
887*fcf3ce44SJohn Forte 		if (*cmd == 0) {
888*fcf3ce44SJohn Forte 			return (CMD_HELP);
889*fcf3ce44SJohn Forte 		}
890*fcf3ce44SJohn Forte 		return (CMD_INVALID);
891*fcf3ce44SJohn Forte 	}
892*fcf3ce44SJohn Forte 
893*fcf3ce44SJohn Forte 	/* verbose */
894*fcf3ce44SJohn Forte 	if (strncmp(cmd, "verbose ", 8) == 0) {
895*fcf3ce44SJohn Forte 		cmd += 8;
896*fcf3ce44SJohn Forte 		while (*cmd == ' ') cmd ++;
897*fcf3ce44SJohn Forte 		if (*cmd == 0) {
898*fcf3ce44SJohn Forte 			return (CMD_VERBOSE_PARSER);
899*fcf3ce44SJohn Forte 		} else if (*cmd == 'm') {
900*fcf3ce44SJohn Forte 			cmd ++;
901*fcf3ce44SJohn Forte 			while (*cmd == ' ') cmd ++;
902*fcf3ce44SJohn Forte 			if (*cmd == 0) {
903*fcf3ce44SJohn Forte 				return (CMD_VERBOSE_MEMORY);
904*fcf3ce44SJohn Forte 			}
905*fcf3ce44SJohn Forte 		} else if (*cmd == 'n') {
906*fcf3ce44SJohn Forte 			cmd ++;
907*fcf3ce44SJohn Forte 			while (*cmd == ' ') cmd ++;
908*fcf3ce44SJohn Forte 			if (*cmd == 0) {
909*fcf3ce44SJohn Forte 				return (CMD_VERBOSE_NET);
910*fcf3ce44SJohn Forte 			}
911*fcf3ce44SJohn Forte 		} else if (*cmd == 'p') {
912*fcf3ce44SJohn Forte 			cmd ++;
913*fcf3ce44SJohn Forte 			while (*cmd == ' ') cmd ++;
914*fcf3ce44SJohn Forte 			if (*cmd == 0) {
915*fcf3ce44SJohn Forte 				return (CMD_VERBOSE_PARSER);
916*fcf3ce44SJohn Forte 			}
917*fcf3ce44SJohn Forte 		} else if (*cmd == 't') {
918*fcf3ce44SJohn Forte 			cmd ++;
919*fcf3ce44SJohn Forte 			while (*cmd == ' ') cmd ++;
920*fcf3ce44SJohn Forte 			if (*cmd == 0) {
921*fcf3ce44SJohn Forte 				return (CMD_VERBOSE_TIME);
922*fcf3ce44SJohn Forte 			}
923*fcf3ce44SJohn Forte 		} else if (*cmd == 'l') {
924*fcf3ce44SJohn Forte 			cmd ++;
925*fcf3ce44SJohn Forte 			while (*cmd == ' ') cmd ++;
926*fcf3ce44SJohn Forte 			if (*cmd == 0) {
927*fcf3ce44SJohn Forte 				return (CMD_VERBOSE_LOCK);
928*fcf3ce44SJohn Forte 			}
929*fcf3ce44SJohn Forte 		}
930*fcf3ce44SJohn Forte 		return (CMD_INVALID);
931*fcf3ce44SJohn Forte 	}
932*fcf3ce44SJohn Forte 
933*fcf3ce44SJohn Forte 	/* quit */
934*fcf3ce44SJohn Forte 	if (strncmp(cmd, "quit ", 5) == 0) {
935*fcf3ce44SJohn Forte 		cmd += 5;
936*fcf3ce44SJohn Forte 		while (*cmd == ' ') cmd ++;
937*fcf3ce44SJohn Forte 		if (*cmd == 0) {
938*fcf3ce44SJohn Forte 			return (CMD_QUIT);
939*fcf3ce44SJohn Forte 		}
940*fcf3ce44SJohn Forte 		return (CMD_INVALID);
941*fcf3ce44SJohn Forte 	}
942*fcf3ce44SJohn Forte 
943*fcf3ce44SJohn Forte 	return (CMD_INVALID);
944*fcf3ce44SJohn Forte }
945*fcf3ce44SJohn Forte 
946*fcf3ce44SJohn Forte static void
print_entity(char * ident,isns_obj_t * obj)947*fcf3ce44SJohn Forte print_entity(
948*fcf3ce44SJohn Forte 	char *ident,
949*fcf3ce44SJohn Forte 	isns_obj_t *obj
950*fcf3ce44SJohn Forte )
951*fcf3ce44SJohn Forte {
952*fcf3ce44SJohn Forte 	uint32_t uid;
953*fcf3ce44SJohn Forte 	uchar_t *eid;
954*fcf3ce44SJohn Forte 	uint32_t *cuid;
955*fcf3ce44SJohn Forte 	int i, num;
956*fcf3ce44SJohn Forte 
957*fcf3ce44SJohn Forte 	eid = obj->attrs[
958*fcf3ce44SJohn Forte 	    ATTR_INDEX_ENTITY(ISNS_EID_ATTR_ID)].value.ptr;
959*fcf3ce44SJohn Forte 	uid = get_obj_uid(obj);
960*fcf3ce44SJohn Forte 
961*fcf3ce44SJohn Forte 	if (ident != NULL) {
962*fcf3ce44SJohn Forte 		printf("%s%d\t%s\n", ident, uid, (const char *)eid);
963*fcf3ce44SJohn Forte 	} else {
964*fcf3ce44SJohn Forte 		printf("%d\t%s\n", uid, (const char *)eid);
965*fcf3ce44SJohn Forte 	}
966*fcf3ce44SJohn Forte 
967*fcf3ce44SJohn Forte 	i = 0;
968*fcf3ce44SJohn Forte 	while (i < NUM_OF_CHILD[obj->type]) {
969*fcf3ce44SJohn Forte 		cuid = get_child_n(obj, i);
970*fcf3ce44SJohn Forte 		if (ident != NULL) {
971*fcf3ce44SJohn Forte 			printf("%s\t%s%d:", "child", i);
972*fcf3ce44SJohn Forte 		} else {
973*fcf3ce44SJohn Forte 			printf("\t%s%d:", "child", i);
974*fcf3ce44SJohn Forte 		}
975*fcf3ce44SJohn Forte 		if (cuid != NULL) {
976*fcf3ce44SJohn Forte 			num = *cuid ++;
977*fcf3ce44SJohn Forte 		} else {
978*fcf3ce44SJohn Forte 			num = 0;
979*fcf3ce44SJohn Forte 		}
980*fcf3ce44SJohn Forte 		while (num > 0) {
981*fcf3ce44SJohn Forte 			printf("\t%d", *cuid ++);
982*fcf3ce44SJohn Forte 			num --;
983*fcf3ce44SJohn Forte 		}
984*fcf3ce44SJohn Forte 		printf("\n");
985*fcf3ce44SJohn Forte 		i ++;
986*fcf3ce44SJohn Forte 	}
987*fcf3ce44SJohn Forte }
988*fcf3ce44SJohn Forte 
989*fcf3ce44SJohn Forte static void
print_iscsi(char * ident,isns_obj_t * obj)990*fcf3ce44SJohn Forte print_iscsi(
991*fcf3ce44SJohn Forte 	char *ident,
992*fcf3ce44SJohn Forte 	isns_obj_t *obj
993*fcf3ce44SJohn Forte )
994*fcf3ce44SJohn Forte {
995*fcf3ce44SJohn Forte 	uchar_t *name = obj->attrs[ATTR_INDEX_ISCSI(ISNS_ISCSI_NAME_ATTR_ID)]
996*fcf3ce44SJohn Forte 	    .value.ptr;
997*fcf3ce44SJohn Forte 	uchar_t *alias = obj->attrs[ATTR_INDEX_ISCSI(ISNS_ISCSI_ALIAS_ATTR_ID)]
998*fcf3ce44SJohn Forte 	    .value.ptr;
999*fcf3ce44SJohn Forte 	uint32_t type = obj->attrs[
1000*fcf3ce44SJohn Forte 	    ATTR_INDEX_ISCSI(ISNS_ISCSI_NODE_TYPE_ATTR_ID)].value.ui;
1001*fcf3ce44SJohn Forte 	uint32_t uid = get_obj_uid(obj);
1002*fcf3ce44SJohn Forte 	uint32_t puid = get_parent_uid(obj);
1003*fcf3ce44SJohn Forte 
1004*fcf3ce44SJohn Forte 	if (!alias) {
1005*fcf3ce44SJohn Forte 		alias = (uchar_t *)"-";
1006*fcf3ce44SJohn Forte 	}
1007*fcf3ce44SJohn Forte 
1008*fcf3ce44SJohn Forte 	if (ident != NULL) {
1009*fcf3ce44SJohn Forte 		printf("%s%d[%d]\t%s\n", ident,
1010*fcf3ce44SJohn Forte 		    uid, puid, (const char *)name);
1011*fcf3ce44SJohn Forte 		printf("%s\t%s", ident, alias);
1012*fcf3ce44SJohn Forte 	} else {
1013*fcf3ce44SJohn Forte 		printf("%d[%d]\t%s\n",
1014*fcf3ce44SJohn Forte 		    uid, puid, (const char *)name);
1015*fcf3ce44SJohn Forte 		printf("\t%s", alias);
1016*fcf3ce44SJohn Forte 	}
1017*fcf3ce44SJohn Forte 	if (IS_TYPE_TARGET(type)) {
1018*fcf3ce44SJohn Forte 		printf("\tTarget");
1019*fcf3ce44SJohn Forte 	}
1020*fcf3ce44SJohn Forte 	if (IS_TYPE_INITIATOR(type)) {
1021*fcf3ce44SJohn Forte 		printf("\tInitiator");
1022*fcf3ce44SJohn Forte 	}
1023*fcf3ce44SJohn Forte 	if (IS_TYPE_CONTROL(type)) {
1024*fcf3ce44SJohn Forte 		printf("\tControl");
1025*fcf3ce44SJohn Forte 	}
1026*fcf3ce44SJohn Forte 	if (IS_TYPE_UNKNOWN(type)) {
1027*fcf3ce44SJohn Forte 		printf("\t-");
1028*fcf3ce44SJohn Forte 	}
1029*fcf3ce44SJohn Forte 	printf("\n");
1030*fcf3ce44SJohn Forte }
1031*fcf3ce44SJohn Forte 
1032*fcf3ce44SJohn Forte static void
print_portal(char * ident,isns_obj_t * obj)1033*fcf3ce44SJohn Forte print_portal(
1034*fcf3ce44SJohn Forte 	char *ident,
1035*fcf3ce44SJohn Forte 	isns_obj_t *obj
1036*fcf3ce44SJohn Forte )
1037*fcf3ce44SJohn Forte {
1038*fcf3ce44SJohn Forte 	char pbuff[256] = { 0 };
1039*fcf3ce44SJohn Forte 	in6_addr_t *ip = obj->attrs[
1040*fcf3ce44SJohn Forte 	    ATTR_INDEX_PORTAL(ISNS_PORTAL_IP_ADDR_ATTR_ID)].value.ip;
1041*fcf3ce44SJohn Forte 	uint32_t port = obj->attrs[
1042*fcf3ce44SJohn Forte 	    ATTR_INDEX_PORTAL(ISNS_PORTAL_PORT_ATTR_ID)].value.ui;
1043*fcf3ce44SJohn Forte 	uint32_t uid = get_obj_uid(obj);
1044*fcf3ce44SJohn Forte 	uint32_t puid = get_parent_uid(obj);
1045*fcf3ce44SJohn Forte 
1046*fcf3ce44SJohn Forte 	inet_ntop(AF_INET6, (void *)ip, pbuff, sizeof (pbuff));
1047*fcf3ce44SJohn Forte 	if (ident != NULL) {
1048*fcf3ce44SJohn Forte 		printf("%s%d[%d]\t%s:%d", ident,
1049*fcf3ce44SJohn Forte 		    uid, puid, pbuff, PORT_NUMBER(port));
1050*fcf3ce44SJohn Forte 	} else {
1051*fcf3ce44SJohn Forte 		printf("%d[%d]\t%s:%d",
1052*fcf3ce44SJohn Forte 		    uid, puid, pbuff, PORT_NUMBER(port));
1053*fcf3ce44SJohn Forte 	}
1054*fcf3ce44SJohn Forte 	printf(" %s\n", IS_PORT_UDP(port) ? "UDP" : "TCP");
1055*fcf3ce44SJohn Forte }
1056*fcf3ce44SJohn Forte 
1057*fcf3ce44SJohn Forte static void
print_pg(char * ident,isns_obj_t * obj)1058*fcf3ce44SJohn Forte print_pg(
1059*fcf3ce44SJohn Forte 	char *ident,
1060*fcf3ce44SJohn Forte 	isns_obj_t *obj
1061*fcf3ce44SJohn Forte )
1062*fcf3ce44SJohn Forte {
1063*fcf3ce44SJohn Forte 	uint32_t ref;
1064*fcf3ce44SJohn Forte 	int i;
1065*fcf3ce44SJohn Forte 
1066*fcf3ce44SJohn Forte 	char pbuff[256] = { 0 };
1067*fcf3ce44SJohn Forte 	uchar_t *name = obj->attrs[ATTR_INDEX_PG(ISNS_PG_ISCSI_NAME_ATTR_ID)]
1068*fcf3ce44SJohn Forte 	    .value.ptr;
1069*fcf3ce44SJohn Forte 	in6_addr_t *ip = obj->attrs[
1070*fcf3ce44SJohn Forte 	    ATTR_INDEX_PG(ISNS_PG_PORTAL_IP_ADDR_ATTR_ID)].value.ip;
1071*fcf3ce44SJohn Forte 	uint32_t port = obj->attrs[
1072*fcf3ce44SJohn Forte 	    ATTR_INDEX_PG(ISNS_PG_PORTAL_PORT_ATTR_ID)].value.ui;
1073*fcf3ce44SJohn Forte 	uint32_t tag = obj->attrs[
1074*fcf3ce44SJohn Forte 	    ATTR_INDEX_PG(ISNS_PG_TAG_ATTR_ID)].value.ui;
1075*fcf3ce44SJohn Forte 	uint32_t uid = get_obj_uid(obj);
1076*fcf3ce44SJohn Forte 	uint32_t puid = get_parent_uid(obj);
1077*fcf3ce44SJohn Forte 
1078*fcf3ce44SJohn Forte 	inet_ntop(AF_INET6, (void *)ip, pbuff, sizeof (pbuff));
1079*fcf3ce44SJohn Forte 	if (ident != NULL) {
1080*fcf3ce44SJohn Forte 		printf("%s%d[%d]\t[%d] %s\n", ident,
1081*fcf3ce44SJohn Forte 		    uid, puid, tag, (const char *)name);
1082*fcf3ce44SJohn Forte 		printf("%s\t%s:%d", ident, pbuff, PORT_NUMBER(port));
1083*fcf3ce44SJohn Forte 	} else {
1084*fcf3ce44SJohn Forte 		printf("%d[%d]\t[%d] %s\n",
1085*fcf3ce44SJohn Forte 		    uid, puid, tag, (const char *)name);
1086*fcf3ce44SJohn Forte 		printf("\t%s:%d", pbuff, PORT_NUMBER(port));
1087*fcf3ce44SJohn Forte 	}
1088*fcf3ce44SJohn Forte 	printf(" %s\n", IS_PORT_UDP(port) ? "UDP" : "TCP");
1089*fcf3ce44SJohn Forte 
1090*fcf3ce44SJohn Forte 	if (NUM_OF_REF[obj->type] > 0) {
1091*fcf3ce44SJohn Forte 		if (ident != NULL) {
1092*fcf3ce44SJohn Forte 			printf("%s\t%s:", "ref");
1093*fcf3ce44SJohn Forte 		} else {
1094*fcf3ce44SJohn Forte 			printf("\t%s:", "ref");
1095*fcf3ce44SJohn Forte 		}
1096*fcf3ce44SJohn Forte 	}
1097*fcf3ce44SJohn Forte 	i = 0;
1098*fcf3ce44SJohn Forte 	while (i < NUM_OF_REF[obj->type]) {
1099*fcf3ce44SJohn Forte 		ref = get_ref_n(obj, i);
1100*fcf3ce44SJohn Forte 		printf("\t%d", ref);
1101*fcf3ce44SJohn Forte 		i ++;
1102*fcf3ce44SJohn Forte 	}
1103*fcf3ce44SJohn Forte 	if (i > 0) {
1104*fcf3ce44SJohn Forte 		printf("\n");
1105*fcf3ce44SJohn Forte 	}
1106*fcf3ce44SJohn Forte }
1107*fcf3ce44SJohn Forte 
1108*fcf3ce44SJohn Forte static void
print_dd(char * ident,isns_obj_t * obj)1109*fcf3ce44SJohn Forte print_dd(
1110*fcf3ce44SJohn Forte 	char *ident,
1111*fcf3ce44SJohn Forte 	isns_obj_t *obj
1112*fcf3ce44SJohn Forte )
1113*fcf3ce44SJohn Forte {
1114*fcf3ce44SJohn Forte 	uchar_t *name = obj->attrs[ATTR_INDEX_DD(ISNS_DD_NAME_ATTR_ID)]
1115*fcf3ce44SJohn Forte 	    .value.ptr;
1116*fcf3ce44SJohn Forte 	uint32_t uid = obj->attrs[UID_ATTR_INDEX[OBJ_DD]].value.ui;
1117*fcf3ce44SJohn Forte 
1118*fcf3ce44SJohn Forte 	if (ident != NULL) {
1119*fcf3ce44SJohn Forte 		printf("%s%d\t%s\n", ident, uid, (const char *)name);
1120*fcf3ce44SJohn Forte 	} else {
1121*fcf3ce44SJohn Forte 		printf("%d\t%s\n", uid, (const char *)name);
1122*fcf3ce44SJohn Forte 	}
1123*fcf3ce44SJohn Forte }
1124*fcf3ce44SJohn Forte 
1125*fcf3ce44SJohn Forte static void
print_dds(char * ident,isns_obj_t * obj)1126*fcf3ce44SJohn Forte print_dds(
1127*fcf3ce44SJohn Forte 	char *ident,
1128*fcf3ce44SJohn Forte 	isns_obj_t *obj
1129*fcf3ce44SJohn Forte )
1130*fcf3ce44SJohn Forte {
1131*fcf3ce44SJohn Forte 	uchar_t *name = obj->attrs[ATTR_INDEX_DDS(
1132*fcf3ce44SJohn Forte 	    ISNS_DD_SET_NAME_ATTR_ID)].value.ptr;
1133*fcf3ce44SJohn Forte 	uint32_t uid = obj->attrs[UID_ATTR_INDEX[OBJ_DDS]].value.ui;
1134*fcf3ce44SJohn Forte 	uint32_t enabled = obj->attrs[ATTR_INDEX_DDS(
1135*fcf3ce44SJohn Forte 	    ISNS_DD_SET_STATUS_ATTR_ID)].value.ui;
1136*fcf3ce44SJohn Forte 
1137*fcf3ce44SJohn Forte 	if (ident != NULL) {
1138*fcf3ce44SJohn Forte 		printf("%s%d\t%s\t\t(%s)\n", ident, uid,
1139*fcf3ce44SJohn Forte 		    (const char *)name, enabled ? "enabled" : "disabled");
1140*fcf3ce44SJohn Forte 	} else {
1141*fcf3ce44SJohn Forte 		printf("%d\t%s\t\t(%s)\n", uid,
1142*fcf3ce44SJohn Forte 		    (const char *)name, enabled ? "enabled" : "disabled");
1143*fcf3ce44SJohn Forte 	}
1144*fcf3ce44SJohn Forte }
1145*fcf3ce44SJohn Forte 
1146*fcf3ce44SJohn Forte void
print_object(char * ident,isns_obj_t * obj)1147*fcf3ce44SJohn Forte print_object(
1148*fcf3ce44SJohn Forte 	char *ident,
1149*fcf3ce44SJohn Forte 	isns_obj_t *obj
1150*fcf3ce44SJohn Forte )
1151*fcf3ce44SJohn Forte {
1152*fcf3ce44SJohn Forte 	print_func[obj->type](ident, obj);
1153*fcf3ce44SJohn Forte }
1154*fcf3ce44SJohn Forte 
1155*fcf3ce44SJohn Forte /*ARGSUSED*/
1156*fcf3ce44SJohn Forte static int
cb_print_obj_n(void * p1,void * p2)1157*fcf3ce44SJohn Forte cb_print_obj_n(
1158*fcf3ce44SJohn Forte 	void *p1,
1159*fcf3ce44SJohn Forte 	void *p2
1160*fcf3ce44SJohn Forte )
1161*fcf3ce44SJohn Forte {
1162*fcf3ce44SJohn Forte 	isns_obj_t *obj = (isns_obj_t *)p1;
1163*fcf3ce44SJohn Forte 	print_func[obj->type](NULL, obj);
1164*fcf3ce44SJohn Forte 
1165*fcf3ce44SJohn Forte 	return (0);
1166*fcf3ce44SJohn Forte }
1167*fcf3ce44SJohn Forte 
1168*fcf3ce44SJohn Forte static void
list_pg()1169*fcf3ce44SJohn Forte list_pg(
1170*fcf3ce44SJohn Forte )
1171*fcf3ce44SJohn Forte {
1172*fcf3ce44SJohn Forte 	cache_dump_htab(OBJ_PG);
1173*fcf3ce44SJohn Forte }
1174*fcf3ce44SJohn Forte 
1175*fcf3ce44SJohn Forte static void
list_portal()1176*fcf3ce44SJohn Forte list_portal(
1177*fcf3ce44SJohn Forte )
1178*fcf3ce44SJohn Forte {
1179*fcf3ce44SJohn Forte 	cache_dump_htab(OBJ_PORTAL);
1180*fcf3ce44SJohn Forte }
1181*fcf3ce44SJohn Forte 
1182*fcf3ce44SJohn Forte static void
list_node()1183*fcf3ce44SJohn Forte list_node(
1184*fcf3ce44SJohn Forte )
1185*fcf3ce44SJohn Forte {
1186*fcf3ce44SJohn Forte 	cache_dump_htab(OBJ_ISCSI);
1187*fcf3ce44SJohn Forte }
1188*fcf3ce44SJohn Forte 
1189*fcf3ce44SJohn Forte static void
list_entity()1190*fcf3ce44SJohn Forte list_entity(
1191*fcf3ce44SJohn Forte )
1192*fcf3ce44SJohn Forte {
1193*fcf3ce44SJohn Forte 	cache_dump_htab(OBJ_ENTITY);
1194*fcf3ce44SJohn Forte }
1195*fcf3ce44SJohn Forte 
1196*fcf3ce44SJohn Forte static void
list_dd()1197*fcf3ce44SJohn Forte list_dd(
1198*fcf3ce44SJohn Forte )
1199*fcf3ce44SJohn Forte {
1200*fcf3ce44SJohn Forte 	cache_dump_htab(OBJ_DD);
1201*fcf3ce44SJohn Forte }
1202*fcf3ce44SJohn Forte 
1203*fcf3ce44SJohn Forte static void
list_ddn(uint32_t uid)1204*fcf3ce44SJohn Forte list_ddn(
1205*fcf3ce44SJohn Forte 	uint32_t uid
1206*fcf3ce44SJohn Forte )
1207*fcf3ce44SJohn Forte {
1208*fcf3ce44SJohn Forte 	lookup_ctrl_t lc;
1209*fcf3ce44SJohn Forte 
1210*fcf3ce44SJohn Forte 	bmp_t *p;
1211*fcf3ce44SJohn Forte 	uint32_t n;
1212*fcf3ce44SJohn Forte 
1213*fcf3ce44SJohn Forte 	if (uid != 0) {
1214*fcf3ce44SJohn Forte 		setup_ddid_lcp(&lc, uid);
1215*fcf3ce44SJohn Forte 		cache_lookup(&lc, &uid, cb_print_obj_n);
1216*fcf3ce44SJohn Forte 	}
1217*fcf3ce44SJohn Forte 
1218*fcf3ce44SJohn Forte 	if (uid != 0) {
1219*fcf3ce44SJohn Forte 		printf("--------------------------------\n");
1220*fcf3ce44SJohn Forte 		get_dd_matrix(uid, &p, &n);
1221*fcf3ce44SJohn Forte 		SET_UID_LCP(&lc, OBJ_ISCSI, 0);
1222*fcf3ce44SJohn Forte 		FOR_EACH_MEMBER(p, n, uid, {
1223*fcf3ce44SJohn Forte 			lc.data[0].ui = uid;
1224*fcf3ce44SJohn Forte 			cache_lookup(&lc, NULL, cb_print_obj_n);
1225*fcf3ce44SJohn Forte 		});
1226*fcf3ce44SJohn Forte 		free(p);
1227*fcf3ce44SJohn Forte 	} else {
1228*fcf3ce44SJohn Forte 		printf("no such dd.\n");
1229*fcf3ce44SJohn Forte 	}
1230*fcf3ce44SJohn Forte }
1231*fcf3ce44SJohn Forte 
1232*fcf3ce44SJohn Forte static void
list_ddsn(uint32_t uid)1233*fcf3ce44SJohn Forte list_ddsn(
1234*fcf3ce44SJohn Forte 	uint32_t uid
1235*fcf3ce44SJohn Forte )
1236*fcf3ce44SJohn Forte {
1237*fcf3ce44SJohn Forte 	lookup_ctrl_t lc;
1238*fcf3ce44SJohn Forte 
1239*fcf3ce44SJohn Forte 	bmp_t *p;
1240*fcf3ce44SJohn Forte 	uint32_t n;
1241*fcf3ce44SJohn Forte 
1242*fcf3ce44SJohn Forte 	if (uid != 0) {
1243*fcf3ce44SJohn Forte 		setup_ddsid_lcp(&lc, uid);
1244*fcf3ce44SJohn Forte 		cache_lookup(&lc, &uid, cb_print_obj_n);
1245*fcf3ce44SJohn Forte 	}
1246*fcf3ce44SJohn Forte 
1247*fcf3ce44SJohn Forte 	if (uid != 0) {
1248*fcf3ce44SJohn Forte 		printf("--------------------------------\n");
1249*fcf3ce44SJohn Forte 		get_dds_matrix(uid, &p, &n);
1250*fcf3ce44SJohn Forte 		SET_UID_LCP(&lc, OBJ_DD, 0);
1251*fcf3ce44SJohn Forte 		FOR_EACH_MEMBER(p, n, uid, {
1252*fcf3ce44SJohn Forte 			lc.data[0].ui = uid;
1253*fcf3ce44SJohn Forte 			cache_lookup(&lc, NULL, cb_print_obj_n);
1254*fcf3ce44SJohn Forte 		});
1255*fcf3ce44SJohn Forte 		free(p);
1256*fcf3ce44SJohn Forte 	} else {
1257*fcf3ce44SJohn Forte 		printf("no such dd-set.\n");
1258*fcf3ce44SJohn Forte 	}
1259*fcf3ce44SJohn Forte }
1260*fcf3ce44SJohn Forte 
1261*fcf3ce44SJohn Forte static void
list_dds()1262*fcf3ce44SJohn Forte list_dds(
1263*fcf3ce44SJohn Forte )
1264*fcf3ce44SJohn Forte {
1265*fcf3ce44SJohn Forte 	cache_dump_htab(OBJ_DDS);
1266*fcf3ce44SJohn Forte }
1267*fcf3ce44SJohn Forte 
1268*fcf3ce44SJohn Forte static void
new_dd_dds(int cmd_id,int argc,int * argv)1269*fcf3ce44SJohn Forte new_dd_dds(
1270*fcf3ce44SJohn Forte 	int cmd_id,
1271*fcf3ce44SJohn Forte 	int argc,
1272*fcf3ce44SJohn Forte 	int *argv
1273*fcf3ce44SJohn Forte )
1274*fcf3ce44SJohn Forte {
1275*fcf3ce44SJohn Forte 	uint32_t buff[256];
1276*fcf3ce44SJohn Forte 	isns_pdu_t *pdu = (isns_pdu_t *)buff;
1277*fcf3ce44SJohn Forte 	uint8_t *payload = &pdu->payload[0];
1278*fcf3ce44SJohn Forte 	uint16_t payload_len = 0;
1279*fcf3ce44SJohn Forte 	isns_tlv_t *tlv;
1280*fcf3ce44SJohn Forte 
1281*fcf3ce44SJohn Forte 	int len = 0;
1282*fcf3ce44SJohn Forte 	uint32_t uid = 0;
1283*fcf3ce44SJohn Forte 	char *name;
1284*fcf3ce44SJohn Forte 
1285*fcf3ce44SJohn Forte 	conn_arg_t conn;
1286*fcf3ce44SJohn Forte 
1287*fcf3ce44SJohn Forte 	pdu->version = ISNSP_VERSION;
1288*fcf3ce44SJohn Forte 
1289*fcf3ce44SJohn Forte 	/* source attribute */
1290*fcf3ce44SJohn Forte 	tlv = (isns_tlv_t *)payload;
1291*fcf3ce44SJohn Forte 	tlv->attr_id = htonl(ISNS_ISCSI_NAME_ATTR_ID);
1292*fcf3ce44SJohn Forte 	tlv->attr_len = htonl(32);
1293*fcf3ce44SJohn Forte 	strcpy((char *)tlv->attr_value, "i am a control node.");
1294*fcf3ce44SJohn Forte 	payload += 8 + 32;
1295*fcf3ce44SJohn Forte 	payload_len += 8 + 32;
1296*fcf3ce44SJohn Forte 
1297*fcf3ce44SJohn Forte 	/* key attributes */
1298*fcf3ce44SJohn Forte 
1299*fcf3ce44SJohn Forte 	/* delimiter */
1300*fcf3ce44SJohn Forte 	tlv = (isns_tlv_t *)payload;
1301*fcf3ce44SJohn Forte 	tlv->attr_id = htonl(ISNS_DELIMITER_ATTR_ID);
1302*fcf3ce44SJohn Forte 	tlv->attr_len = htonl(0);
1303*fcf3ce44SJohn Forte 	payload += 8 + 0;
1304*fcf3ce44SJohn Forte 	payload_len += 8 + 0;
1305*fcf3ce44SJohn Forte 
1306*fcf3ce44SJohn Forte 	/* operating attributes */
1307*fcf3ce44SJohn Forte 	switch (cmd_id) {
1308*fcf3ce44SJohn Forte 	case CMD_NEWDD:
1309*fcf3ce44SJohn Forte 		pdu->func_id = ISNS_DD_REG;
1310*fcf3ce44SJohn Forte 		if (argc == 1) {
1311*fcf3ce44SJohn Forte 			name = (char *)argv[0];
1312*fcf3ce44SJohn Forte 			len = strlen(name) + 1;
1313*fcf3ce44SJohn Forte 			len += 4 - (len % 4);
1314*fcf3ce44SJohn Forte 		}
1315*fcf3ce44SJohn Forte 		tlv = (isns_tlv_t *)payload;
1316*fcf3ce44SJohn Forte 		tlv->attr_id = htonl(ISNS_DD_NAME_ATTR_ID);
1317*fcf3ce44SJohn Forte 		tlv->attr_len = htonl(len);
1318*fcf3ce44SJohn Forte 		if (len > 0) {
1319*fcf3ce44SJohn Forte 			strcpy((char *)tlv->attr_value, name);
1320*fcf3ce44SJohn Forte 		}
1321*fcf3ce44SJohn Forte 		payload_len += 8 + len;
1322*fcf3ce44SJohn Forte 		break;
1323*fcf3ce44SJohn Forte 	case CMD_NEWDDS:
1324*fcf3ce44SJohn Forte 		pdu->func_id = ISNS_DDS_REG;
1325*fcf3ce44SJohn Forte 		if (argc == 1) {
1326*fcf3ce44SJohn Forte 			name = (char *)argv[0];
1327*fcf3ce44SJohn Forte 			len = strlen(name) + 1;
1328*fcf3ce44SJohn Forte 			len += 4 - (len % 4);
1329*fcf3ce44SJohn Forte 		}
1330*fcf3ce44SJohn Forte 		tlv = (isns_tlv_t *)payload;
1331*fcf3ce44SJohn Forte 		tlv->attr_id = htonl(ISNS_DD_SET_NAME_ATTR_ID);
1332*fcf3ce44SJohn Forte 		tlv->attr_len = htonl(len);
1333*fcf3ce44SJohn Forte 		if (len > 0) {
1334*fcf3ce44SJohn Forte 			strcpy((char *)tlv->attr_value, name);
1335*fcf3ce44SJohn Forte 		}
1336*fcf3ce44SJohn Forte 		payload_len += 8 + len;
1337*fcf3ce44SJohn Forte 		break;
1338*fcf3ce44SJohn Forte 	case CMD_NEWDDN:
1339*fcf3ce44SJohn Forte 		pdu->func_id = ISNS_DD_REG;
1340*fcf3ce44SJohn Forte 		switch (argc) {
1341*fcf3ce44SJohn Forte 		case 2:
1342*fcf3ce44SJohn Forte 			name = (char *)argv[1];
1343*fcf3ce44SJohn Forte 			len = strlen(name) + 1;
1344*fcf3ce44SJohn Forte 			len += 4 - (len % 4);
1345*fcf3ce44SJohn Forte 		case 1:
1346*fcf3ce44SJohn Forte 			uid = argv[0];
1347*fcf3ce44SJohn Forte 		}
1348*fcf3ce44SJohn Forte 		tlv = (isns_tlv_t *)payload;
1349*fcf3ce44SJohn Forte 		tlv->attr_id = htonl(ISNS_DD_NAME_ATTR_ID);
1350*fcf3ce44SJohn Forte 		tlv->attr_len = htonl(len);
1351*fcf3ce44SJohn Forte 		if (len > 0) {
1352*fcf3ce44SJohn Forte 			strcpy((char *)tlv->attr_value, name);
1353*fcf3ce44SJohn Forte 		}
1354*fcf3ce44SJohn Forte 		payload += 8 + len;
1355*fcf3ce44SJohn Forte 		payload_len += 8 + len;
1356*fcf3ce44SJohn Forte 		if (uid > 0) {
1357*fcf3ce44SJohn Forte 			tlv = (isns_tlv_t *)payload;
1358*fcf3ce44SJohn Forte 			tlv->attr_id = htonl(ISNS_DD_ID_ATTR_ID);
1359*fcf3ce44SJohn Forte 			tlv->attr_len = htonl(4);
1360*fcf3ce44SJohn Forte 			*(uint32_t *)tlv->attr_value = htonl(uid);
1361*fcf3ce44SJohn Forte 			payload_len += 8 + 4;
1362*fcf3ce44SJohn Forte 		}
1363*fcf3ce44SJohn Forte 		break;
1364*fcf3ce44SJohn Forte 	case CMD_NEWDDSN:
1365*fcf3ce44SJohn Forte 		pdu->func_id = ISNS_DDS_REG;
1366*fcf3ce44SJohn Forte 		switch (argc) {
1367*fcf3ce44SJohn Forte 		case 2:
1368*fcf3ce44SJohn Forte 			name = (char *)argv[1];
1369*fcf3ce44SJohn Forte 			len = strlen(name) + 1;
1370*fcf3ce44SJohn Forte 			len += 4 - (len % 4);
1371*fcf3ce44SJohn Forte 		case 1:
1372*fcf3ce44SJohn Forte 			uid = argv[0];
1373*fcf3ce44SJohn Forte 		}
1374*fcf3ce44SJohn Forte 		tlv = (isns_tlv_t *)payload;
1375*fcf3ce44SJohn Forte 		tlv->attr_id = htonl(ISNS_DD_SET_NAME_ATTR_ID);
1376*fcf3ce44SJohn Forte 		tlv->attr_len = htonl(len);
1377*fcf3ce44SJohn Forte 		if (len > 0) {
1378*fcf3ce44SJohn Forte 			strcpy((char *)tlv->attr_value, name);
1379*fcf3ce44SJohn Forte 		}
1380*fcf3ce44SJohn Forte 		payload_len += 8 + len;
1381*fcf3ce44SJohn Forte 		payload += 8 + len;
1382*fcf3ce44SJohn Forte 		if (uid > 0) {
1383*fcf3ce44SJohn Forte 			tlv = (isns_tlv_t *)payload;
1384*fcf3ce44SJohn Forte 			tlv->attr_id = htonl(ISNS_DD_SET_ID_ATTR_ID);
1385*fcf3ce44SJohn Forte 			tlv->attr_len = htonl(4);
1386*fcf3ce44SJohn Forte 			*(uint32_t *)tlv->attr_value = htonl(uid);
1387*fcf3ce44SJohn Forte 			payload_len += 8 + 4;
1388*fcf3ce44SJohn Forte 		}
1389*fcf3ce44SJohn Forte 		break;
1390*fcf3ce44SJohn Forte 	default:
1391*fcf3ce44SJohn Forte 		break;
1392*fcf3ce44SJohn Forte 	}
1393*fcf3ce44SJohn Forte 
1394*fcf3ce44SJohn Forte 	pdu->payload_len = payload_len;
1395*fcf3ce44SJohn Forte 
1396*fcf3ce44SJohn Forte 	dump_pdu1(pdu);
1397*fcf3ce44SJohn Forte 
1398*fcf3ce44SJohn Forte 	conn.in_packet.pdu = pdu;
1399*fcf3ce44SJohn Forte 	conn.out_packet.pdu = NULL;
1400*fcf3ce44SJohn Forte 	conn.out_packet.sz = 0;
1401*fcf3ce44SJohn Forte 
1402*fcf3ce44SJohn Forte 	if (packet_split_verify(&conn) == 0) {
1403*fcf3ce44SJohn Forte 		cache_lock(conn.lock);
1404*fcf3ce44SJohn Forte 		conn.handler(&conn);
1405*fcf3ce44SJohn Forte 		conn.ec = cache_unlock(conn.lock, conn.ec);
1406*fcf3ce44SJohn Forte 	}
1407*fcf3ce44SJohn Forte 
1408*fcf3ce44SJohn Forte 	if (conn.out_packet.pdu != NULL) {
1409*fcf3ce44SJohn Forte 		pdu_update_code(conn.out_packet.pdu,
1410*fcf3ce44SJohn Forte 		    &conn.out_packet.pl, conn.ec);
1411*fcf3ce44SJohn Forte 		dump_pdu2(conn.out_packet.pdu);
1412*fcf3ce44SJohn Forte 		free(conn.out_packet.pdu);
1413*fcf3ce44SJohn Forte 	} else if (conn.ec != 0) {
1414*fcf3ce44SJohn Forte 		printf("operation failed[%d].\n", conn.ec);
1415*fcf3ce44SJohn Forte 	}
1416*fcf3ce44SJohn Forte }
1417*fcf3ce44SJohn Forte 
1418*fcf3ce44SJohn Forte static void
del_dd_dds(int cmd_id,int uid)1419*fcf3ce44SJohn Forte del_dd_dds(
1420*fcf3ce44SJohn Forte 	int cmd_id,
1421*fcf3ce44SJohn Forte 	int uid
1422*fcf3ce44SJohn Forte )
1423*fcf3ce44SJohn Forte {
1424*fcf3ce44SJohn Forte 	uint32_t buff[256];
1425*fcf3ce44SJohn Forte 	isns_pdu_t *pdu = (isns_pdu_t *)buff;
1426*fcf3ce44SJohn Forte 	uint8_t *payload = &pdu->payload[0];
1427*fcf3ce44SJohn Forte 	uint16_t payload_len = 0;
1428*fcf3ce44SJohn Forte 	isns_tlv_t *tlv;
1429*fcf3ce44SJohn Forte 
1430*fcf3ce44SJohn Forte 	uint32_t tag;
1431*fcf3ce44SJohn Forte 
1432*fcf3ce44SJohn Forte 	conn_arg_t conn;
1433*fcf3ce44SJohn Forte 
1434*fcf3ce44SJohn Forte 	if (uid == 0) {
1435*fcf3ce44SJohn Forte 		return;
1436*fcf3ce44SJohn Forte 	}
1437*fcf3ce44SJohn Forte 
1438*fcf3ce44SJohn Forte 	pdu->version = ISNSP_VERSION;
1439*fcf3ce44SJohn Forte 
1440*fcf3ce44SJohn Forte 	if (cmd_id == CMD_DELDD) {
1441*fcf3ce44SJohn Forte 		tag = ISNS_DD_ID_ATTR_ID;
1442*fcf3ce44SJohn Forte 		pdu->func_id = ISNS_DD_DEREG;
1443*fcf3ce44SJohn Forte 	} else {
1444*fcf3ce44SJohn Forte 		tag = ISNS_DD_SET_ID_ATTR_ID;
1445*fcf3ce44SJohn Forte 		pdu->func_id = ISNS_DDS_DEREG;
1446*fcf3ce44SJohn Forte 	}
1447*fcf3ce44SJohn Forte 
1448*fcf3ce44SJohn Forte 	/* source attribute */
1449*fcf3ce44SJohn Forte 	tlv = (isns_tlv_t *)payload;
1450*fcf3ce44SJohn Forte 	tlv->attr_id = htonl(ISNS_ISCSI_NAME_ATTR_ID);
1451*fcf3ce44SJohn Forte 	tlv->attr_len = htonl(32);
1452*fcf3ce44SJohn Forte 	strcpy((char *)tlv->attr_value, "i am a control node.");
1453*fcf3ce44SJohn Forte 	payload_len += 8 + 32;
1454*fcf3ce44SJohn Forte 	payload += 8 + 32;
1455*fcf3ce44SJohn Forte 
1456*fcf3ce44SJohn Forte 	/* key attributes */
1457*fcf3ce44SJohn Forte 	tlv = (isns_tlv_t *)payload;
1458*fcf3ce44SJohn Forte 	tlv->attr_id = htonl(tag);
1459*fcf3ce44SJohn Forte 	tlv->attr_len = htonl(4);
1460*fcf3ce44SJohn Forte 	*(uint32_t *)tlv->attr_value = htonl(uid);
1461*fcf3ce44SJohn Forte 	payload_len += 8 + 4;
1462*fcf3ce44SJohn Forte 	payload += 8 + 4;
1463*fcf3ce44SJohn Forte 
1464*fcf3ce44SJohn Forte 	/* delimiter */
1465*fcf3ce44SJohn Forte 	tlv = (isns_tlv_t *)payload;
1466*fcf3ce44SJohn Forte 	tlv->attr_id = htonl(ISNS_DELIMITER_ATTR_ID);
1467*fcf3ce44SJohn Forte 	tlv->attr_len = htonl(0);
1468*fcf3ce44SJohn Forte 	payload_len += 8 + 0;
1469*fcf3ce44SJohn Forte 	payload += 8 + 0;
1470*fcf3ce44SJohn Forte 
1471*fcf3ce44SJohn Forte 	/* operating attributes */
1472*fcf3ce44SJohn Forte 
1473*fcf3ce44SJohn Forte 	pdu->payload_len = payload_len;
1474*fcf3ce44SJohn Forte 
1475*fcf3ce44SJohn Forte 	dump_pdu1(pdu);
1476*fcf3ce44SJohn Forte 
1477*fcf3ce44SJohn Forte 	conn.in_packet.pdu = pdu;
1478*fcf3ce44SJohn Forte 	conn.out_packet.pdu = NULL;
1479*fcf3ce44SJohn Forte 	conn.out_packet.sz = 0;
1480*fcf3ce44SJohn Forte 
1481*fcf3ce44SJohn Forte 	if (packet_split_verify(&conn) == 0) {
1482*fcf3ce44SJohn Forte 		cache_lock(conn.lock);
1483*fcf3ce44SJohn Forte 		conn.handler(&conn);
1484*fcf3ce44SJohn Forte 		conn.ec = cache_unlock(conn.lock, conn.ec);
1485*fcf3ce44SJohn Forte 	}
1486*fcf3ce44SJohn Forte 
1487*fcf3ce44SJohn Forte 	if (conn.out_packet.pdu != NULL) {
1488*fcf3ce44SJohn Forte 		pdu_update_code(conn.out_packet.pdu,
1489*fcf3ce44SJohn Forte 		    &conn.out_packet.pl, conn.ec);
1490*fcf3ce44SJohn Forte 		dump_pdu2(conn.out_packet.pdu);
1491*fcf3ce44SJohn Forte 		free(conn.out_packet.pdu);
1492*fcf3ce44SJohn Forte 	} else if (conn.ec != 0) {
1493*fcf3ce44SJohn Forte 		printf("operation failed[%d].\n", conn.ec);
1494*fcf3ce44SJohn Forte 	}
1495*fcf3ce44SJohn Forte }
1496*fcf3ce44SJohn Forte 
1497*fcf3ce44SJohn Forte static void
update_dds(int cmd_id,int uid)1498*fcf3ce44SJohn Forte update_dds(
1499*fcf3ce44SJohn Forte 	int cmd_id,
1500*fcf3ce44SJohn Forte 	int uid
1501*fcf3ce44SJohn Forte )
1502*fcf3ce44SJohn Forte {
1503*fcf3ce44SJohn Forte 	uint32_t buff[256];
1504*fcf3ce44SJohn Forte 	isns_pdu_t *pdu = (isns_pdu_t *)buff;
1505*fcf3ce44SJohn Forte 	uint8_t *payload = &pdu->payload[0];
1506*fcf3ce44SJohn Forte 	uint16_t payload_len = 0;
1507*fcf3ce44SJohn Forte 	isns_tlv_t *tlv;
1508*fcf3ce44SJohn Forte 
1509*fcf3ce44SJohn Forte 	conn_arg_t conn;
1510*fcf3ce44SJohn Forte 
1511*fcf3ce44SJohn Forte 	if (uid == 0) {
1512*fcf3ce44SJohn Forte 		return;
1513*fcf3ce44SJohn Forte 	}
1514*fcf3ce44SJohn Forte 
1515*fcf3ce44SJohn Forte 	pdu->version = ISNSP_VERSION;
1516*fcf3ce44SJohn Forte 
1517*fcf3ce44SJohn Forte 	pdu->func_id = ISNS_DDS_REG;
1518*fcf3ce44SJohn Forte 
1519*fcf3ce44SJohn Forte 	/* source attribute */
1520*fcf3ce44SJohn Forte 	tlv = (isns_tlv_t *)payload;
1521*fcf3ce44SJohn Forte 	tlv->attr_id = htonl(ISNS_ISCSI_NAME_ATTR_ID);
1522*fcf3ce44SJohn Forte 	tlv->attr_len = htonl(32);
1523*fcf3ce44SJohn Forte 	strcpy((char *)tlv->attr_value, "i am a control node.");
1524*fcf3ce44SJohn Forte 	payload_len += 8 + 32;
1525*fcf3ce44SJohn Forte 	payload += 8 + 32;
1526*fcf3ce44SJohn Forte 
1527*fcf3ce44SJohn Forte 	/* key attributes */
1528*fcf3ce44SJohn Forte 	tlv = (isns_tlv_t *)payload;
1529*fcf3ce44SJohn Forte 	tlv->attr_id = htonl(ISNS_DD_SET_ID_ATTR_ID);
1530*fcf3ce44SJohn Forte 	tlv->attr_len = htonl(4);
1531*fcf3ce44SJohn Forte 	*(uint32_t *)tlv->attr_value = htonl(uid);
1532*fcf3ce44SJohn Forte 	payload_len += 8 + 4;
1533*fcf3ce44SJohn Forte 	payload += 8 + 4;
1534*fcf3ce44SJohn Forte 
1535*fcf3ce44SJohn Forte 	/* delimiter */
1536*fcf3ce44SJohn Forte 	tlv = (isns_tlv_t *)payload;
1537*fcf3ce44SJohn Forte 	tlv->attr_id = htonl(ISNS_DELIMITER_ATTR_ID);
1538*fcf3ce44SJohn Forte 	tlv->attr_len = htonl(0);
1539*fcf3ce44SJohn Forte 	payload_len += 8 + 0;
1540*fcf3ce44SJohn Forte 	payload += 8 + 0;
1541*fcf3ce44SJohn Forte 
1542*fcf3ce44SJohn Forte 	/* operating attributes */
1543*fcf3ce44SJohn Forte 	tlv = (isns_tlv_t *)payload;
1544*fcf3ce44SJohn Forte 	tlv->attr_id = htonl(ISNS_DD_SET_STATUS_ATTR_ID);
1545*fcf3ce44SJohn Forte 	tlv->attr_len = htonl(4);
1546*fcf3ce44SJohn Forte 	if (cmd_id == CMD_ENABLE) {
1547*fcf3ce44SJohn Forte 		*(uint32_t *)tlv->attr_value = htonl(1);
1548*fcf3ce44SJohn Forte 	} else {
1549*fcf3ce44SJohn Forte 		*(uint32_t *)tlv->attr_value = htonl(0);
1550*fcf3ce44SJohn Forte 	}
1551*fcf3ce44SJohn Forte 	payload_len += 8 + 4;
1552*fcf3ce44SJohn Forte 
1553*fcf3ce44SJohn Forte 	pdu->payload_len = payload_len;
1554*fcf3ce44SJohn Forte 
1555*fcf3ce44SJohn Forte 	dump_pdu1(pdu);
1556*fcf3ce44SJohn Forte 
1557*fcf3ce44SJohn Forte 	conn.in_packet.pdu = pdu;
1558*fcf3ce44SJohn Forte 	conn.out_packet.pdu = NULL;
1559*fcf3ce44SJohn Forte 	conn.out_packet.sz = 0;
1560*fcf3ce44SJohn Forte 
1561*fcf3ce44SJohn Forte 	if (packet_split_verify(&conn) == 0) {
1562*fcf3ce44SJohn Forte 		cache_lock(conn.lock);
1563*fcf3ce44SJohn Forte 		conn.handler(&conn);
1564*fcf3ce44SJohn Forte 		conn.ec = cache_unlock(conn.lock, conn.ec);
1565*fcf3ce44SJohn Forte 	}
1566*fcf3ce44SJohn Forte 
1567*fcf3ce44SJohn Forte 	if (conn.out_packet.pdu != NULL) {
1568*fcf3ce44SJohn Forte 		pdu_update_code(conn.out_packet.pdu,
1569*fcf3ce44SJohn Forte 		    &conn.out_packet.pl, conn.ec);
1570*fcf3ce44SJohn Forte 		dump_pdu2(conn.out_packet.pdu);
1571*fcf3ce44SJohn Forte 		free(conn.out_packet.pdu);
1572*fcf3ce44SJohn Forte 	} else if (conn.ec != 0) {
1573*fcf3ce44SJohn Forte 		printf("operation failed[%d].\n", conn.ec);
1574*fcf3ce44SJohn Forte 	}
1575*fcf3ce44SJohn Forte }
1576*fcf3ce44SJohn Forte 
1577*fcf3ce44SJohn Forte static void
update_member(int cmd_id,int * argv)1578*fcf3ce44SJohn Forte update_member(
1579*fcf3ce44SJohn Forte 	int cmd_id,
1580*fcf3ce44SJohn Forte 	int *argv
1581*fcf3ce44SJohn Forte )
1582*fcf3ce44SJohn Forte {
1583*fcf3ce44SJohn Forte 	uint32_t buff[256];
1584*fcf3ce44SJohn Forte 	isns_pdu_t *pdu = (isns_pdu_t *)buff;
1585*fcf3ce44SJohn Forte 	uint8_t *payload = &pdu->payload[0];
1586*fcf3ce44SJohn Forte 	uint16_t payload_len = 0;
1587*fcf3ce44SJohn Forte 	isns_tlv_t *tlv;
1588*fcf3ce44SJohn Forte 	uint32_t key_tag, op_tag, op_len;
1589*fcf3ce44SJohn Forte 
1590*fcf3ce44SJohn Forte 	uint32_t uid = argv[0];
1591*fcf3ce44SJohn Forte 	uint32_t m_id;
1592*fcf3ce44SJohn Forte 	char *m_name;
1593*fcf3ce44SJohn Forte 
1594*fcf3ce44SJohn Forte 	conn_arg_t conn;
1595*fcf3ce44SJohn Forte 
1596*fcf3ce44SJohn Forte 	if (uid == 0) {
1597*fcf3ce44SJohn Forte 		printf("operation failed.\n");
1598*fcf3ce44SJohn Forte 		return;
1599*fcf3ce44SJohn Forte 	}
1600*fcf3ce44SJohn Forte 
1601*fcf3ce44SJohn Forte 	pdu->version = ISNSP_VERSION;
1602*fcf3ce44SJohn Forte 
1603*fcf3ce44SJohn Forte 	switch (cmd_id) {
1604*fcf3ce44SJohn Forte 	case CMD_ADDDD:
1605*fcf3ce44SJohn Forte 	case CMD_ADDDDN:
1606*fcf3ce44SJohn Forte 		pdu->func_id = ISNS_DD_REG;
1607*fcf3ce44SJohn Forte 		break;
1608*fcf3ce44SJohn Forte 	case CMD_REMDD:
1609*fcf3ce44SJohn Forte 	case CMD_REMDDN:
1610*fcf3ce44SJohn Forte 		pdu->func_id = ISNS_DD_DEREG;
1611*fcf3ce44SJohn Forte 		break;
1612*fcf3ce44SJohn Forte 	case CMD_ADDDDSN:
1613*fcf3ce44SJohn Forte 		pdu->func_id = ISNS_DDS_REG;
1614*fcf3ce44SJohn Forte 		break;
1615*fcf3ce44SJohn Forte 	case CMD_REMDDSN:
1616*fcf3ce44SJohn Forte 		pdu->func_id = ISNS_DDS_DEREG;
1617*fcf3ce44SJohn Forte 		break;
1618*fcf3ce44SJohn Forte 	}
1619*fcf3ce44SJohn Forte 	switch (cmd_id) {
1620*fcf3ce44SJohn Forte 	case CMD_ADDDD:
1621*fcf3ce44SJohn Forte 	case CMD_REMDD:
1622*fcf3ce44SJohn Forte 		key_tag = ISNS_DD_ID_ATTR_ID;
1623*fcf3ce44SJohn Forte 		op_tag = ISNS_DD_ISCSI_NAME_ATTR_ID;
1624*fcf3ce44SJohn Forte 		m_name = (char *)argv[1];
1625*fcf3ce44SJohn Forte 		op_len = strlen(m_name);
1626*fcf3ce44SJohn Forte 		op_len += 4 - (op_len % 4);
1627*fcf3ce44SJohn Forte 		break;
1628*fcf3ce44SJohn Forte 	case CMD_ADDDDN:
1629*fcf3ce44SJohn Forte 	case CMD_REMDDN:
1630*fcf3ce44SJohn Forte 		key_tag = ISNS_DD_ID_ATTR_ID;
1631*fcf3ce44SJohn Forte 		op_tag = ISNS_DD_ISCSI_INDEX_ATTR_ID;
1632*fcf3ce44SJohn Forte 		m_id = argv[1];
1633*fcf3ce44SJohn Forte 		op_len = 4;
1634*fcf3ce44SJohn Forte 		break;
1635*fcf3ce44SJohn Forte 	case CMD_ADDDDSN:
1636*fcf3ce44SJohn Forte 	case CMD_REMDDSN:
1637*fcf3ce44SJohn Forte 		key_tag = ISNS_DD_SET_ID_ATTR_ID;
1638*fcf3ce44SJohn Forte 		op_tag = ISNS_DD_ID_ATTR_ID;
1639*fcf3ce44SJohn Forte 		m_id = argv[1];
1640*fcf3ce44SJohn Forte 		op_len = 4;
1641*fcf3ce44SJohn Forte 		break;
1642*fcf3ce44SJohn Forte 	}
1643*fcf3ce44SJohn Forte 
1644*fcf3ce44SJohn Forte 	/* source attribute */
1645*fcf3ce44SJohn Forte 	tlv = (isns_tlv_t *)payload;
1646*fcf3ce44SJohn Forte 	tlv->attr_id = htonl(ISNS_ISCSI_NAME_ATTR_ID);
1647*fcf3ce44SJohn Forte 	tlv->attr_len = htonl(32);
1648*fcf3ce44SJohn Forte 	strcpy((char *)tlv->attr_value, "i am a control node.");
1649*fcf3ce44SJohn Forte 	payload_len += 8 + 32;
1650*fcf3ce44SJohn Forte 	payload += 8 + 32;
1651*fcf3ce44SJohn Forte 
1652*fcf3ce44SJohn Forte 	/* key attributes */
1653*fcf3ce44SJohn Forte 	tlv = (isns_tlv_t *)payload;
1654*fcf3ce44SJohn Forte 	tlv->attr_id = htonl(key_tag);
1655*fcf3ce44SJohn Forte 	tlv->attr_len = htonl(4);
1656*fcf3ce44SJohn Forte 	*(uint32_t *)tlv->attr_value = htonl(uid);
1657*fcf3ce44SJohn Forte 	payload_len += 8 + 4;
1658*fcf3ce44SJohn Forte 	payload += 8 + 4;
1659*fcf3ce44SJohn Forte 
1660*fcf3ce44SJohn Forte 	/* delimiter */
1661*fcf3ce44SJohn Forte 	tlv = (isns_tlv_t *)payload;
1662*fcf3ce44SJohn Forte 	tlv->attr_id = htonl(ISNS_DELIMITER_ATTR_ID);
1663*fcf3ce44SJohn Forte 	tlv->attr_len = htonl(0);
1664*fcf3ce44SJohn Forte 	payload_len += 8 + 0;
1665*fcf3ce44SJohn Forte 	payload += 8 + 0;
1666*fcf3ce44SJohn Forte 
1667*fcf3ce44SJohn Forte 	/* operating attributes */
1668*fcf3ce44SJohn Forte 	tlv = (isns_tlv_t *)payload;
1669*fcf3ce44SJohn Forte 	tlv->attr_id = htonl(op_tag);
1670*fcf3ce44SJohn Forte 	tlv->attr_len = htonl(op_len);
1671*fcf3ce44SJohn Forte 	switch (cmd_id) {
1672*fcf3ce44SJohn Forte 	case CMD_ADDDD:
1673*fcf3ce44SJohn Forte 	case CMD_REMDD:
1674*fcf3ce44SJohn Forte 		strcpy((char *)tlv->attr_value, m_name);
1675*fcf3ce44SJohn Forte 		break;
1676*fcf3ce44SJohn Forte 	case CMD_ADDDDN:
1677*fcf3ce44SJohn Forte 	case CMD_ADDDDSN:
1678*fcf3ce44SJohn Forte 	case CMD_REMDDN:
1679*fcf3ce44SJohn Forte 	case CMD_REMDDSN:
1680*fcf3ce44SJohn Forte 		*(uint32_t *)tlv->attr_value = htonl(m_id);
1681*fcf3ce44SJohn Forte 		break;
1682*fcf3ce44SJohn Forte 	}
1683*fcf3ce44SJohn Forte 	payload_len += 8 + op_len;
1684*fcf3ce44SJohn Forte 
1685*fcf3ce44SJohn Forte 	pdu->payload_len = payload_len;
1686*fcf3ce44SJohn Forte 
1687*fcf3ce44SJohn Forte 	dump_pdu1(pdu);
1688*fcf3ce44SJohn Forte 
1689*fcf3ce44SJohn Forte 	conn.in_packet.pdu = pdu;
1690*fcf3ce44SJohn Forte 	conn.out_packet.pdu = NULL;
1691*fcf3ce44SJohn Forte 	conn.out_packet.sz = 0;
1692*fcf3ce44SJohn Forte 
1693*fcf3ce44SJohn Forte 	if (packet_split_verify(&conn) == 0) {
1694*fcf3ce44SJohn Forte 		cache_lock(conn.lock);
1695*fcf3ce44SJohn Forte 		conn.handler(&conn);
1696*fcf3ce44SJohn Forte 		conn.ec = cache_unlock(conn.lock, conn.ec);
1697*fcf3ce44SJohn Forte 	}
1698*fcf3ce44SJohn Forte 
1699*fcf3ce44SJohn Forte 	if (conn.out_packet.pdu != NULL) {
1700*fcf3ce44SJohn Forte 		pdu_update_code(conn.out_packet.pdu,
1701*fcf3ce44SJohn Forte 		    &conn.out_packet.pl, conn.ec);
1702*fcf3ce44SJohn Forte 		dump_pdu2(conn.out_packet.pdu);
1703*fcf3ce44SJohn Forte 		free(conn.out_packet.pdu);
1704*fcf3ce44SJohn Forte 	} else if (conn.ec != 0) {
1705*fcf3ce44SJohn Forte 		printf("operation failed[%d].\n", conn.ec);
1706*fcf3ce44SJohn Forte 	}
1707*fcf3ce44SJohn Forte }
1708*fcf3ce44SJohn Forte 
1709*fcf3ce44SJohn Forte static void
cmd_file(char * file)1710*fcf3ce44SJohn Forte cmd_file(
1711*fcf3ce44SJohn Forte 	char *file
1712*fcf3ce44SJohn Forte )
1713*fcf3ce44SJohn Forte {
1714*fcf3ce44SJohn Forte 	char i = 0, ch, cmd[256];
1715*fcf3ce44SJohn Forte 	FILE *f = fopen(file, "r");
1716*fcf3ce44SJohn Forte 	if (f != NULL) {
1717*fcf3ce44SJohn Forte 		while ((ch = fgetc(f)) != 0 && ch != EOF) {
1718*fcf3ce44SJohn Forte 			if (ch == '\t') {
1719*fcf3ce44SJohn Forte 				cmd[i++] = ' ';
1720*fcf3ce44SJohn Forte 			} else if (ch != '\n') {
1721*fcf3ce44SJohn Forte 				cmd[i++] = ch;
1722*fcf3ce44SJohn Forte 			} else {
1723*fcf3ce44SJohn Forte 				cmd[i ++] = ' ';
1724*fcf3ce44SJohn Forte 				cmd[i] = 0;
1725*fcf3ce44SJohn Forte 				i = 0;
1726*fcf3ce44SJohn Forte 				printf("%s\n", cmd);
1727*fcf3ce44SJohn Forte 				if (run_cmd(cmd) != 0) {
1728*fcf3ce44SJohn Forte 					break;
1729*fcf3ce44SJohn Forte 				}
1730*fcf3ce44SJohn Forte 			}
1731*fcf3ce44SJohn Forte 		}
1732*fcf3ce44SJohn Forte 		fclose(f);
1733*fcf3ce44SJohn Forte 	} else {
1734*fcf3ce44SJohn Forte 		printf("Cannot open file %s.\n", file);
1735*fcf3ce44SJohn Forte 	}
1736*fcf3ce44SJohn Forte }
1737*fcf3ce44SJohn Forte 
1738*fcf3ce44SJohn Forte static int
run_cmd(char * cmd)1739*fcf3ce44SJohn Forte run_cmd(
1740*fcf3ce44SJohn Forte 	char *cmd
1741*fcf3ce44SJohn Forte )
1742*fcf3ce44SJohn Forte {
1743*fcf3ce44SJohn Forte 	int argc, argv[32];
1744*fcf3ce44SJohn Forte 	int cmd_id;
1745*fcf3ce44SJohn Forte 	cmd_id = getcmd(&argc, argv, cmd);
1746*fcf3ce44SJohn Forte 	switch (cmd_id) {
1747*fcf3ce44SJohn Forte 		case CMD_LIST:
1748*fcf3ce44SJohn Forte 			list_node();
1749*fcf3ce44SJohn Forte 			break;
1750*fcf3ce44SJohn Forte 		case CMD_LISTNE:
1751*fcf3ce44SJohn Forte 			list_entity();
1752*fcf3ce44SJohn Forte 			break;
1753*fcf3ce44SJohn Forte 		case CMD_LISTP:
1754*fcf3ce44SJohn Forte 			list_portal();
1755*fcf3ce44SJohn Forte 			break;
1756*fcf3ce44SJohn Forte 		case CMD_LISTPG:
1757*fcf3ce44SJohn Forte 			list_pg();
1758*fcf3ce44SJohn Forte 			break;
1759*fcf3ce44SJohn Forte 		case CMD_LISTDD:
1760*fcf3ce44SJohn Forte 			list_dd();
1761*fcf3ce44SJohn Forte 			break;
1762*fcf3ce44SJohn Forte 		case CMD_LISTDDS:
1763*fcf3ce44SJohn Forte 			list_dds();
1764*fcf3ce44SJohn Forte 			break;
1765*fcf3ce44SJohn Forte 		case CMD_LISTDDN:
1766*fcf3ce44SJohn Forte 			list_ddn(argv[0]);
1767*fcf3ce44SJohn Forte 			break;
1768*fcf3ce44SJohn Forte 		case CMD_LISTDDSN:
1769*fcf3ce44SJohn Forte 			list_ddsn(argv[0]);
1770*fcf3ce44SJohn Forte 			break;
1771*fcf3ce44SJohn Forte 		case CMD_NEWDD:
1772*fcf3ce44SJohn Forte 		case CMD_NEWDDS:
1773*fcf3ce44SJohn Forte 		case CMD_NEWDDN:
1774*fcf3ce44SJohn Forte 		case CMD_NEWDDSN:
1775*fcf3ce44SJohn Forte 			new_dd_dds(cmd_id, argc, argv);
1776*fcf3ce44SJohn Forte 			break;
1777*fcf3ce44SJohn Forte 		case CMD_DELDD:
1778*fcf3ce44SJohn Forte 		case CMD_DELDDS:
1779*fcf3ce44SJohn Forte 			del_dd_dds(cmd_id, argv[0]);
1780*fcf3ce44SJohn Forte 			break;
1781*fcf3ce44SJohn Forte 		case CMD_ENABLE:
1782*fcf3ce44SJohn Forte 		case CMD_DISABLE:
1783*fcf3ce44SJohn Forte 			update_dds(cmd_id, argv[0]);
1784*fcf3ce44SJohn Forte 			break;
1785*fcf3ce44SJohn Forte 		case CMD_ADDDD:
1786*fcf3ce44SJohn Forte 		case CMD_ADDDDN:
1787*fcf3ce44SJohn Forte 		case CMD_ADDDDSN:
1788*fcf3ce44SJohn Forte 		case CMD_REMDD:
1789*fcf3ce44SJohn Forte 		case CMD_REMDDN:
1790*fcf3ce44SJohn Forte 		case CMD_REMDDSN:
1791*fcf3ce44SJohn Forte 			update_member(cmd_id, argv);
1792*fcf3ce44SJohn Forte 			break;
1793*fcf3ce44SJohn Forte 		case CMD_PAUSE:
1794*fcf3ce44SJohn Forte 			printf("Press enter to continue...");
1795*fcf3ce44SJohn Forte 			getchar();
1796*fcf3ce44SJohn Forte 			break;
1797*fcf3ce44SJohn Forte 		case CMD_FILE:
1798*fcf3ce44SJohn Forte 			cmd_file((char *)argv[0]);
1799*fcf3ce44SJohn Forte 			break;
1800*fcf3ce44SJohn Forte 		case CMD_HELP:
1801*fcf3ce44SJohn Forte 			test_cli_help();
1802*fcf3ce44SJohn Forte 			break;
1803*fcf3ce44SJohn Forte 		case CMD_VERBOSE_MEMORY:
1804*fcf3ce44SJohn Forte 			verbose_mc = !verbose_mc;
1805*fcf3ce44SJohn Forte 			break;
1806*fcf3ce44SJohn Forte 		case CMD_VERBOSE_NET:
1807*fcf3ce44SJohn Forte 			verbose_net = !verbose_net;
1808*fcf3ce44SJohn Forte 			break;
1809*fcf3ce44SJohn Forte 		case CMD_VERBOSE_TIME:
1810*fcf3ce44SJohn Forte 			verbose_tc = !verbose_tc;
1811*fcf3ce44SJohn Forte 			break;
1812*fcf3ce44SJohn Forte 		case CMD_VERBOSE_LOCK:
1813*fcf3ce44SJohn Forte 			verbose_lock = !verbose_lock;
1814*fcf3ce44SJohn Forte 			break;
1815*fcf3ce44SJohn Forte 		case CMD_VERBOSE_PARSER:
1816*fcf3ce44SJohn Forte 			verbose_parser = !verbose_parser;
1817*fcf3ce44SJohn Forte 			break;
1818*fcf3ce44SJohn Forte 		case CMD_QUIT:
1819*fcf3ce44SJohn Forte 			/* clean up cli */
1820*fcf3ce44SJohn Forte 			/* notify sys control */
1821*fcf3ce44SJohn Forte 			shutdown_server();
1822*fcf3ce44SJohn Forte 			return (1);
1823*fcf3ce44SJohn Forte 		case CMD_NONE:
1824*fcf3ce44SJohn Forte 			break;
1825*fcf3ce44SJohn Forte 		default:
1826*fcf3ce44SJohn Forte 			printf("invalid command\n");
1827*fcf3ce44SJohn Forte 			break;
1828*fcf3ce44SJohn Forte 	}
1829*fcf3ce44SJohn Forte 	if (cmd_id != CMD_NONE) {
1830*fcf3ce44SJohn Forte 		printf("\n>");
1831*fcf3ce44SJohn Forte 	} else {
1832*fcf3ce44SJohn Forte 		printf(">");
1833*fcf3ce44SJohn Forte 	}
1834*fcf3ce44SJohn Forte 	return (0);
1835*fcf3ce44SJohn Forte }
1836*fcf3ce44SJohn Forte 
1837*fcf3ce44SJohn Forte /*ARGSUSED*/
cli_test(void * arg)1838*fcf3ce44SJohn Forte void *cli_test(void *arg) {
1839*fcf3ce44SJohn Forte 	char i = 0, ch, cmd[256];
1840*fcf3ce44SJohn Forte 
1841*fcf3ce44SJohn Forte 	printf("iSNS Server test CLI.\n");
1842*fcf3ce44SJohn Forte 	printf("Copyright 2007 Sun Microsystems, Inc.\n");
1843*fcf3ce44SJohn Forte 
1844*fcf3ce44SJohn Forte 	printf("\n>");
1845*fcf3ce44SJohn Forte 	while ((ch = getchar()) != 0 && ch != EOF) {
1846*fcf3ce44SJohn Forte 		if (ch == '\t') {
1847*fcf3ce44SJohn Forte 			cmd[i++] = ' ';
1848*fcf3ce44SJohn Forte 		} else if (ch != '\n') {
1849*fcf3ce44SJohn Forte 			cmd[i++] = ch;
1850*fcf3ce44SJohn Forte 		} else {
1851*fcf3ce44SJohn Forte 			cmd[i ++] = ' ';
1852*fcf3ce44SJohn Forte 			cmd[i] = 0;
1853*fcf3ce44SJohn Forte 			i = 0;
1854*fcf3ce44SJohn Forte 			if (run_cmd(cmd) != 0) {
1855*fcf3ce44SJohn Forte 				break;
1856*fcf3ce44SJohn Forte 			}
1857*fcf3ce44SJohn Forte 		}
1858*fcf3ce44SJohn Forte 	}
1859*fcf3ce44SJohn Forte 
1860*fcf3ce44SJohn Forte 	return (NULL);
1861*fcf3ce44SJohn Forte }
1862*fcf3ce44SJohn Forte #endif
1863