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