/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* This file is getting large unexpectly, a lex & yacc */
/* implementation is expected. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <pthread.h>
#include "isns_server.h"
#include "isns_htab.h"
#include "isns_msgq.h"
#include "isns_obj.h"
#include "isns_func.h"
#include "isns_dd.h"
#include "isns_cache.h"
#include "isns_pdu.h"
#ifdef DEBUG
/*
* external variables
*/
extern const int NUM_OF_CHILD[MAX_OBJ_TYPE];
extern const int UID_ATTR_INDEX[MAX_OBJ_TYPE_FOR_SIZE];
extern const int NUM_OF_REF[MAX_OBJ_TYPE_FOR_SIZE];
/*
* global variables
*/
int verbose_mc = 0;
int verbose_tc = 0;
int verbose_lock = 0;
int verbose_net = 0;
int verbose_parser = 0;
/*
* local variables
*/
static void print_entity(char *, isns_obj_t *);
static void print_iscsi(char *, isns_obj_t *);
static void print_portal(char *, isns_obj_t *);
static void print_pg(char *, isns_obj_t *);
static void print_dd(char *, isns_obj_t *);
static void print_dds(char *, isns_obj_t *);
NULL,
&print_pg,
&print_dd,
};
static int run_cmd(char *);
typedef struct {
char *fname;
{ ISNS_DEV_ATTR_REG, "DevAttrReg" },
{ ISNS_DEV_ATTR_QRY, "DevAttrQry" },
{ ISNS_DEV_GET_NEXT, "DevGetNext" },
{ ISNS_DEV_DEREG, "DevDereg" },
{ ISNS_SCN_REG, "SCNReg" },
{ ISNS_SCN_DEREG, "SCNDereg" },
{ ISNS_DD_REG, "DDReg" },
{ ISNS_DD_DEREG, "DDDereg" },
{ ISNS_DDS_REG, "DDSReg" },
{ ISNS_DDS_DEREG, "DDSDereg" },
{ ISNS_SCN, "SCN" },
{ ISNS_ESI, "ESI" },
{ ISNS_HEARTBEAT, "Heartbeat" },
{ ISNS_DEV_ATTR_REG_RSP, "DevAttrRegRsp" },
{ ISNS_DEV_ATTR_QRY_RSP, "DevAttrQryRsp" },
{ ISNS_DEV_GET_NEXT_RSP, "DevGetNextRsp" },
{ ISNS_DEV_DEREG_RSP, "DevDeregRsp" },
{ ISNS_SCN_REG_RSP, "SCNRegRsp" },
{ ISNS_SCN_DEREG_RSP, "SCNDeregRsp" },
{ ISNS_SCN_RSP, "SCNRsp" },
{ ISNS_ESI_RSP, "ESIRsp" },
{ 0xFFFF, "Unknown" } };
static char *
)
{
int i = 0;
}
}
return ("UNKNOWN");
}
static char *
)
{
switch (tag) {
case ISNS_DELIMITER_ATTR_ID:
return ("Delimiter");
case ISNS_EID_ATTR_ID:
return ("Entity Identifier");
return ("Entity Protocol");
return ("Registration Period");
case ISNS_TIMESTAMP_ATTR_ID:
return ("Timestamp");
return ("Portal IP Address");
case ISNS_PORTAL_PORT_ATTR_ID:
case ISNS_PORTAL_NAME_ATTR_ID:
return ("Portal Symbolic Name");
return ("ESI Interval");
case ISNS_ESI_PORT_ATTR_ID:
return ("ESI Port");
case ISNS_SCN_PORT_ATTR_ID:
return ("SCN Port");
return ("Portal Security Bitmap");
case ISNS_ISCSI_NAME_ATTR_ID:
return ("iSCSI Name");
return ("iSCSI Node Type");
case ISNS_ISCSI_ALIAS_ATTR_ID:
return ("iSCSI Alias");
return ("iSCSI Auth Method");
return ("iSCSI SCN Bitmap");
return ("PG iSCSI Name");
return ("PG Portal IP Addr");
case ISNS_PG_TAG_ATTR_ID:
return ("PG Tag (PGT)");
case ISNS_PG_INDEX_ATTR_ID:
return ("PG Index");
case ISNS_DD_NAME_ATTR_ID:
return ("DD Name");
case ISNS_DD_ID_ATTR_ID:
return ("DD Index");
return ("DD ISCSI Node Index");
return ("DD ISCSI Node Name");
case ISNS_DD_SET_NAME_ATTR_ID:
return ("DDS Name");
case ISNS_DD_SET_ID_ATTR_ID:
return ("DDS Index");
return ("DDS Status");
default:
return ("Unknown");
}
}
static void
int flag
)
{
/* convert the data */
if (flag) {
} else {
}
/* print the pdu header */
printf(" %d... .... .... .... : ISNS_FLAG_CLIENT\n",
printf(" .%d.. .... .... .... : ISNS_FLAG_SERVER\n",
printf(" ..%d. .... .... .... : ISNS_FLAG_AUTH_BLK_PRESENTED\n",
printf(" ...%d .... .... .... : ISNS_FLAG_REPLACE_REG\n",
printf(" .... %d... .... .... : ISNS_FLAG_LAST_PDU\n",
printf(" .... .%d.. .... .... : ISNS_FLAG_FIRST_PDU\n",
printf("Payload: ...\n");
if (id & ISNS_RSP_MASK) {
len -= 4;
payload += 4;
}
/* print the payload */
while (len > 0) {
int t, l;
uint8_t *v;
char *s;
int i;
/* convert the data */
v = &(tlvp->attr_value[0]);
/* print payload */
if (l > 0) {
switch (t) {
case ISNS_EID_ATTR_ID:
case ISNS_ISCSI_NAME_ATTR_ID:
case ISNS_ISCSI_ALIAS_ATTR_ID:
case ISNS_DD_NAME_ATTR_ID:
case ISNS_DD_SET_NAME_ATTR_ID:
s = (char *)v;
printf("%s\n", s);
break;
printf("%s (%d)\n",
((i == 1) ? "No Protocol" :
((i == 2) ? "iSCSI" :
((i == 3) ? "iFCP" :
"Others"))),
i);
break;
ip = (in6_addr_t *)v;
break;
case ISNS_PORTAL_PORT_ATTR_ID:
case ISNS_ESI_PORT_ATTR_ID:
case ISNS_SCN_PORT_ATTR_ID:
printf(" .... .... %d... .... : "
"0=TCP\n",
((i & 0x10000) == 0) ? 0 : 1);
break;
printf("0x%x\t", i);
if (i & ISNS_CONTROL_NODE_TYPE) {
printf("Control ");
}
if (i & ISNS_INITIATOR_NODE_TYPE) {
printf("Initiator ");
}
if (i & ISNS_TARGET_NODE_TYPE) {
printf("Target ");
}
printf("\n");
break;
case ISNS_PG_TAG_ATTR_ID:
default:
printf("%d\n", i);
break;
}
printf(" Attribute Tag: %s (%d)\n",
get_tlv_tag_name(t), t);
printf(" Attribute Length: %d\n", l);
} else {
}
}
}
void
)
{
if (verbose_net) {
printf("### PDU RECEIVED ###\n");
}
}
void
)
{
if (verbose_net) {
printf("### PDU SENT ###\n");
}
}
void
)
{
#if 0
printf("### DUMP DATABASE ###\n");
/* dump dds(s) */
/* dd(s) that belong to this dds */
}
}
/* dump dd(s) */
/* dds(s) this dd belongs to */
}
/* node(s) that this dd have */
}
}
/* dump node(s) */
list = iscsi_list;
/* dd(s) that this node belongs to */
}
}
#endif
}
static void
)
{
printf("list - list all of storage node.\n");
printf("list dd [id] - list all of dd or one with member.\n");
printf("list dds [id] - list all of dd-set or one with member.\n");
printf("\n");
printf("new dd <name> - create a dd with name.\n");
printf("new dds <name> - create a dd-set with name.\n");
printf("new ddn <id> <name> - create a dd with id and name.\n");
printf("new ddsn <id> <name> - create a dd-set with id and name.\n");
printf("del dd <id> - delete a dd.\n");
printf("del dds <id> - delete a dd-set.\n");
printf("\n");
printf("add dd <dd_id> <node_name> - add a node to dd.\n");
printf("add ddn <dd_id> <node_id> - add a node to dd.\n");
printf("add ddsn <dds_id> <dd_id> - add a dd to dd-set.\n");
printf("remove dd <dd_id> <node_name> - remove a node from dd.\n");
printf("remove ddn <dd_id> <node_id> - remove a node from dd.\n");
printf("remove ddsn <dds_id> <dd_id> - remove a dd from dd-set.\n");
printf("\n");
printf("enable <dds_id> - enable a dd-set.\n");
printf("disable <dds_id> - disable a dd-set.\n");
printf("\n");
printf("file <f> - loading command from a file.\n");
printf("pause - suspend batch until enter key is pressed.\n");
printf("help - print this help.\n");
printf("quit - stop iSNS server and quit.\n");
}
static enum {
};
static int
)
{
int j = 0;
*argc = 0;
if (*cmd == 0) {
return (CMD_NONE);
} else if (*cmd == '?') {
return (CMD_HELP);
}
/* list, list dd, list dds, list dd 0 */
cmd += 5;
if (*cmd == 0) {
return (CMD_LIST);
} else if (*cmd == 'p') {
cmd ++;
if (*cmd == 0) {
return (CMD_LISTP);
}
} else if (*cmd == 'g') {
cmd ++;
if (*cmd == 0) {
return (CMD_LISTPG);
}
} else if (*cmd == 'e') {
cmd ++;
if (*cmd == 0) {
return (CMD_LISTNE);
}
cmd += 4;
if (*cmd == 0) {
return (CMD_LISTDDS);
}
j = 0;
}
tmp[j] = 0;
if (*cmd == 0 && j > 0) {
return (CMD_LISTDDSN);
}
cmd += 3;
if (*cmd == 0) {
return (CMD_LISTDD);
}
j = 0;
}
tmp[j] = 0;
if (*cmd == 0 && j > 0) {
return (CMD_LISTDDN);
}
}
return (CMD_INVALID);
}
/* view 0 */
cmd += 5;
j = 0;
}
tmp[j] = 0;
if (*cmd == 0 && j > 0) {
return (CMD_VIEW);
}
return (CMD_INVALID);
}
/* add dd name */
cmd += 4;
cmd += 3;
cmd += 4;
addcmd = CMD_ADDDDN;
cmd += 5;
} else {
return (CMD_INVALID);
}
j = 0;
}
tmp[j] = 0;
if (j > 0) {
} else {
return (CMD_INVALID);
}
if (*cmd != 0) {
switch (addcmd) {
case CMD_ADDDDN:
case CMD_ADDDDSN:
j = 0;
}
tmp[j] = 0;
if (*cmd == 0 && j > 0) {
} else {
return (CMD_INVALID);
}
break;
case CMD_ADDDD:
while (j > 0) {
/* get rid of trail blank space */
cmd[--j] = 0;
} else {
break;
}
}
if (j > 0) {
cmd[j] = 0;
} else {
return (CMD_INVALID);
}
break;
}
return (addcmd);
}
return (CMD_INVALID);
}
/* remove dd name */
cmd += 7;
cmd += 3;
cmd += 4;
rmcmd = CMD_REMDDN;
cmd += 5;
rmcmd = CMD_REMDDSN;
} else {
return (CMD_INVALID);
}
j = 0;
}
tmp[j] = 0;
if (j > 0) {
} else {
return (CMD_INVALID);
}
if (*cmd != 0) {
switch (rmcmd) {
case CMD_REMDDN:
case CMD_REMDDSN:
j = 0;
}
tmp[j] = 0;
if (*cmd == 0 && j > 0) {
} else {
return (CMD_INVALID);
}
break;
case CMD_REMDD:
while (j > 0) {
/* get rid of trail blank space */
cmd[--j] = 0;
} else {
break;
}
}
if (j > 0) {
cmd[j] = 0;
} else {
return (CMD_INVALID);
}
break;
}
return (rmcmd);
}
return (CMD_INVALID);
}
/* new dd, new dds */
cmd += 4;
cmd += 3;
cmd += 4;
newcmd = CMD_NEWDDS;
cmd += 4;
newcmd = CMD_NEWDDN;
cmd += 5;
}
if (newcmd != CMD_INVALID) {
if (*cmd == 0) {
return (newcmd);
}
switch (newcmd) {
case CMD_NEWDDN:
case CMD_NEWDDSN:
j = 0;
}
tmp[j] = 0;
if (*cmd == ' ' && j > 0) {
} else {
return (CMD_INVALID);
}
case CMD_NEWDD:
case CMD_NEWDDS:
if (*cmd != 0) {
} else {
j = 0;
}
while (j > 0) {
/* get rid of trail blank space */
cmd[--j] = 0;
} else {
break;
}
}
if (j > 0) {
cmd[j] = 0;
}
}
return (newcmd);
}
return (CMD_INVALID);
}
/* del dd, del dds, disable 0 */
cmd += 4;
cmd += 4;
delcmd = CMD_DELDDS;
cmd += 3;
}
if (delcmd != CMD_INVALID) {
j = 0;
}
tmp[j] = 0;
if (*cmd == 0 && j > 0) {
return (delcmd);
}
}
return (CMD_INVALID);
}
/* enable 0 */
cmd += 7;
j = 0;
}
tmp[j] = 0;
if (*cmd == 0 && j > 0) {
return (CMD_ENABLE);
}
return (CMD_INVALID);
}
/* disable 0 */
cmd += 8;
j = 0;
}
tmp[j] = 0;
if (*cmd == 0 && j > 0) {
return (CMD_DISABLE);
}
return (CMD_INVALID);
}
/* file */
cmd += 5;
if (*cmd != 0) {
} else {
j = 0;
}
while (j > 0) {
/* get rid of trail blank space */
cmd[--j] = 0;
} else {
break;
}
}
if (j > 0) {
cmd[j] = 0;
return (CMD_FILE);
}
return (CMD_INVALID);
}
/* pause */
cmd += 6;
if (*cmd == 0) {
return (CMD_PAUSE);
}
return (CMD_INVALID);
}
/* help */
cmd += 5;
if (*cmd == 0) {
return (CMD_HELP);
}
return (CMD_INVALID);
}
/* verbose */
cmd += 8;
if (*cmd == 0) {
return (CMD_VERBOSE_PARSER);
} else if (*cmd == 'm') {
cmd ++;
if (*cmd == 0) {
return (CMD_VERBOSE_MEMORY);
}
} else if (*cmd == 'n') {
cmd ++;
if (*cmd == 0) {
return (CMD_VERBOSE_NET);
}
} else if (*cmd == 'p') {
cmd ++;
if (*cmd == 0) {
return (CMD_VERBOSE_PARSER);
}
} else if (*cmd == 't') {
cmd ++;
if (*cmd == 0) {
return (CMD_VERBOSE_TIME);
}
} else if (*cmd == 'l') {
cmd ++;
if (*cmd == 0) {
return (CMD_VERBOSE_LOCK);
}
}
return (CMD_INVALID);
}
/* quit */
cmd += 5;
if (*cmd == 0) {
return (CMD_QUIT);
}
return (CMD_INVALID);
}
return (CMD_INVALID);
}
static void
char *ident,
)
{
int i, num;
if (ident != NULL) {
} else {
}
i = 0;
if (ident != NULL) {
} else {
}
} else {
num = 0;
}
while (num > 0) {
num --;
}
printf("\n");
i ++;
}
}
static void
char *ident,
)
{
if (!alias) {
}
if (ident != NULL) {
printf("%s%d[%d]\t%s\n", ident,
} else {
printf("%d[%d]\t%s\n",
}
if (IS_TYPE_TARGET(type)) {
printf("\tTarget");
}
if (IS_TYPE_INITIATOR(type)) {
printf("\tInitiator");
}
if (IS_TYPE_CONTROL(type)) {
printf("\tControl");
}
if (IS_TYPE_UNKNOWN(type)) {
printf("\t-");
}
printf("\n");
}
static void
char *ident,
)
{
if (ident != NULL) {
printf("%s%d[%d]\t%s:%d", ident,
} else {
printf("%d[%d]\t%s:%d",
}
}
static void
char *ident,
)
{
int i;
if (ident != NULL) {
printf("%s%d[%d]\t[%d] %s\n", ident,
} else {
printf("%d[%d]\t[%d] %s\n",
}
if (ident != NULL) {
} else {
}
}
i = 0;
i ++;
}
if (i > 0) {
printf("\n");
}
}
static void
char *ident,
)
{
if (ident != NULL) {
} else {
}
}
static void
char *ident,
)
{
if (ident != NULL) {
} else {
}
}
void
char *ident,
)
{
}
/*ARGSUSED*/
static int
void *p1,
void *p2
)
{
return (0);
}
static void
)
{
}
static void
)
{
}
static void
)
{
}
static void
)
{
}
static void
)
{
}
static void
)
{
bmp_t *p;
uint32_t n;
if (uid != 0) {
}
if (uid != 0) {
printf("--------------------------------\n");
get_dd_matrix(uid, &p, &n);
FOR_EACH_MEMBER(p, n, uid, {
});
free(p);
} else {
printf("no such dd.\n");
}
}
static void
)
{
bmp_t *p;
uint32_t n;
if (uid != 0) {
}
if (uid != 0) {
printf("--------------------------------\n");
get_dds_matrix(uid, &p, &n);
FOR_EACH_MEMBER(p, n, uid, {
});
free(p);
} else {
printf("no such dd-set.\n");
}
}
static void
)
{
}
static void
int cmd_id,
int argc,
int *argv
)
{
int len = 0;
char *name;
/* source attribute */
/* key attributes */
/* delimiter */
payload += 8 + 0;
payload_len += 8 + 0;
/* operating attributes */
switch (cmd_id) {
case CMD_NEWDD:
if (argc == 1) {
}
if (len > 0) {
}
break;
case CMD_NEWDDS:
if (argc == 1) {
}
if (len > 0) {
}
break;
case CMD_NEWDDN:
switch (argc) {
case 2:
case 1:
}
if (len > 0) {
}
if (uid > 0) {
}
break;
case CMD_NEWDDSN:
switch (argc) {
case 2:
case 1:
}
if (len > 0) {
}
if (uid > 0) {
}
break;
default:
break;
}
if (packet_split_verify(&conn) == 0) {
}
}
}
static void
int cmd_id,
int uid
)
{
if (uid == 0) {
return;
}
} else {
}
/* source attribute */
/* key attributes */
/* delimiter */
payload_len += 8 + 0;
payload += 8 + 0;
/* operating attributes */
if (packet_split_verify(&conn) == 0) {
}
}
}
static void
int cmd_id,
int uid
)
{
if (uid == 0) {
return;
}
/* source attribute */
/* key attributes */
/* delimiter */
payload_len += 8 + 0;
payload += 8 + 0;
/* operating attributes */
if (cmd_id == CMD_ENABLE) {
} else {
}
if (packet_split_verify(&conn) == 0) {
}
}
}
static void
int cmd_id,
int *argv
)
{
char *m_name;
if (uid == 0) {
printf("operation failed.\n");
return;
}
switch (cmd_id) {
case CMD_ADDDD:
case CMD_ADDDDN:
break;
case CMD_REMDD:
case CMD_REMDDN:
break;
case CMD_ADDDDSN:
break;
case CMD_REMDDSN:
break;
}
switch (cmd_id) {
case CMD_ADDDD:
case CMD_REMDD:
break;
case CMD_ADDDDN:
case CMD_REMDDN:
op_len = 4;
break;
case CMD_ADDDDSN:
case CMD_REMDDSN:
op_len = 4;
break;
}
/* source attribute */
/* key attributes */
/* delimiter */
payload_len += 8 + 0;
payload += 8 + 0;
/* operating attributes */
switch (cmd_id) {
case CMD_ADDDD:
case CMD_REMDD:
break;
case CMD_ADDDDN:
case CMD_ADDDDSN:
case CMD_REMDDN:
case CMD_REMDDSN:
break;
}
if (packet_split_verify(&conn) == 0) {
}
}
}
static void
char *file
)
{
if (f != NULL) {
if (ch == '\t') {
cmd[i++] = ' ';
} else if (ch != '\n') {
} else {
cmd[i ++] = ' ';
cmd[i] = 0;
i = 0;
break;
}
}
}
fclose(f);
} else {
}
}
static int
char *cmd
)
{
int cmd_id;
switch (cmd_id) {
case CMD_LIST:
list_node();
break;
case CMD_LISTNE:
list_entity();
break;
case CMD_LISTP:
list_portal();
break;
case CMD_LISTPG:
list_pg();
break;
case CMD_LISTDD:
list_dd();
break;
case CMD_LISTDDS:
list_dds();
break;
case CMD_LISTDDN:
break;
case CMD_LISTDDSN:
break;
case CMD_NEWDD:
case CMD_NEWDDS:
case CMD_NEWDDN:
case CMD_NEWDDSN:
break;
case CMD_DELDD:
case CMD_DELDDS:
break;
case CMD_ENABLE:
case CMD_DISABLE:
break;
case CMD_ADDDD:
case CMD_ADDDDN:
case CMD_ADDDDSN:
case CMD_REMDD:
case CMD_REMDDN:
case CMD_REMDDSN:
break;
case CMD_PAUSE:
printf("Press enter to continue...");
getchar();
break;
case CMD_FILE:
break;
case CMD_HELP:
break;
case CMD_VERBOSE_MEMORY:
verbose_mc = !verbose_mc;
break;
case CMD_VERBOSE_NET:
break;
case CMD_VERBOSE_TIME:
verbose_tc = !verbose_tc;
break;
case CMD_VERBOSE_LOCK:
break;
case CMD_VERBOSE_PARSER:
break;
case CMD_QUIT:
/* clean up cli */
/* notify sys control */
return (1);
case CMD_NONE:
break;
default:
printf("invalid command\n");
break;
}
printf("\n>");
} else {
printf(">");
}
return (0);
}
/*ARGSUSED*/
printf("iSNS Server test CLI.\n");
printf("Copyright 2007 Sun Microsystems, Inc.\n");
printf("\n>");
if (ch == '\t') {
cmd[i++] = ' ';
} else if (ch != '\n') {
} else {
cmd[i ++] = ' ';
cmd[i] = 0;
i = 0;
break;
}
}
}
return (NULL);
}
#endif