xref: /illumos-gate/usr/src/cmd/vntsd/vntsd.h (revision 28b1e50e)
11ae08745Sheppo /*
21ae08745Sheppo  * CDDL HEADER START
31ae08745Sheppo  *
41ae08745Sheppo  * The contents of this file are subject to the terms of the
51ae08745Sheppo  * Common Development and Distribution License (the "License").
61ae08745Sheppo  * You may not use this file except in compliance with the License.
71ae08745Sheppo  *
81ae08745Sheppo  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91ae08745Sheppo  * or http://www.opensolaris.org/os/licensing.
101ae08745Sheppo  * See the License for the specific language governing permissions
111ae08745Sheppo  * and limitations under the License.
121ae08745Sheppo  *
131ae08745Sheppo  * When distributing Covered Code, include this CDDL HEADER in each
141ae08745Sheppo  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151ae08745Sheppo  * If applicable, add the following below this CDDL HEADER, with the
161ae08745Sheppo  * fields enclosed by brackets "[]" replaced with your own identifying
171ae08745Sheppo  * information: Portions Copyright [yyyy] [name of copyright owner]
181ae08745Sheppo  *
191ae08745Sheppo  * CDDL HEADER END
201ae08745Sheppo  */
211ae08745Sheppo /*
22*28b1e50eSSriharsha Basavapatna  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
231ae08745Sheppo  * Use is subject to license terms.
241ae08745Sheppo  */
251ae08745Sheppo 
261ae08745Sheppo /*
271ae08745Sheppo  * vntsd uses configuration information provided by vcc to export access
281ae08745Sheppo  * to Ldom console access over regular TCP sockets. When it starts, it opens
291ae08745Sheppo  * the vcc driver control port and obtains the list of ports that have been
301ae08745Sheppo  * created by the vcc driver as well as TCP port number and group associated
311ae08745Sheppo  * with each port.
321ae08745Sheppo  * vntsd consists of multiple components as the follows:
331ae08745Sheppo  *
341ae08745Sheppo  * vntsd.c
351ae08745Sheppo  * This module initializes vnts daemon, process user options such as instance
361ae08745Sheppo  * number, ip address and etc., and provides main thread to poll any console
371ae08745Sheppo  * port change.
381ae08745Sheppo  *
391ae08745Sheppo  * vntsdvcc.c
401ae08745Sheppo  * This module provides vcc driver interface. It opens vcc driver control
411ae08745Sheppo  * ports, read initial configuration, and provides interface to read, write and
421ae08745Sheppo  * ioctl virtual console ports. This module creates a listen thread for each
431ae08745Sheppo  * console group. It further dynamically adds and removes virtual consoles
441ae08745Sheppo  * and groups following instructions of the vcc driver. This module
451ae08745Sheppo  * is executed in the same thread as vntsd.c which is blocked on vcc control
461ae08745Sheppo  * poll interface.
471ae08745Sheppo  *
481ae08745Sheppo  * listen.c
491ae08745Sheppo  * This is a group listen thread. Each group's tcp-port has a listen thread
501ae08745Sheppo  * associated with it. The thread is created when a console is associated with
511ae08745Sheppo  * a new group and is removed when all consoles in the group are removed.
521ae08745Sheppo  *
531ae08745Sheppo  * console.c
541ae08745Sheppo  * This is a console selection thread. The thread is created when a client
551ae08745Sheppo  * connects to a group TCP port and exited when client disconnects. If there is
561ae08745Sheppo  * only one console in the group, the client is connected to that console. If
571ae08745Sheppo  * there are multiple consoles in the group, the client is asked to select a
581ae08745Sheppo  * console. After determining which console to connect to, this thread
591ae08745Sheppo  * a write thread if the cient is a writer and it self read in client input.
601ae08745Sheppo  *
611ae08745Sheppo  * read.c
621ae08745Sheppo  * it reads input from a TCP client, processes
631ae08745Sheppo  * special daemon and telent commands and write to vcc driver if the client
641ae08745Sheppo  * is a writer. The client is a writer if the client is the first one connects
651ae08745Sheppo  * to the console. Read thread print out an error message if a reader attempt
661ae08745Sheppo  * to input to vcc. Read thread exits if console is deleted, client
671ae08745Sheppo  * disconnects, or there is a fatal error.
681ae08745Sheppo  *
691ae08745Sheppo  * Write.c
701ae08745Sheppo  * Write thread is creaed when first client connects to a console. It reads
711ae08745Sheppo  * from vcc and writes to all clients that connect to the same console.
721ae08745Sheppo  * Write thread exits when all clients disconnect from the console.
731ae08745Sheppo  *
741ae08745Sheppo  * cmd.c
751ae08745Sheppo  * This is a supporting module for handling special daemon and telnet commands.
761ae08745Sheppo  *
771ae08745Sheppo  * common.c
781ae08745Sheppo  * supporting modules shared by threads modules.
791ae08745Sheppo  *
801ae08745Sheppo  * queue.c
811ae08745Sheppo  * This is a moudle supporting queue operations. Vntsd organizes its data
821ae08745Sheppo  * in multiple queues <see data structure below>.
831ae08745Sheppo  *
841ae08745Sheppo  * vntsd.xml
851ae08745Sheppo  * This is a manifest to support SMF interfaces.
861ae08745Sheppo  *
871ae08745Sheppo  * Data structures
881ae08745Sheppo  * each group has a vntsd_group_t structure, which contains a queue of
891ae08745Sheppo  * all console in that group.
901ae08745Sheppo  * each console has a vntsd_cons_t structure, which contains a queue of
911ae08745Sheppo  * all clients that connected to the console.
921ae08745Sheppo  *
931ae08745Sheppo  *     +----------+   +----------+   +----------+
941ae08745Sheppo  *     |  group	  |-->|  group   |-->|   group  |-->....
951ae08745Sheppo  *     +----------+   +----------+   +----------+
961ae08745Sheppo  *          |
971ae08745Sheppo  *          |<-----------------------------------------+
981ae08745Sheppo  *          |<------------------------+                |
991ae08745Sheppo  *          |<--------+               |                |
1001ae08745Sheppo  *          |         |               |                |
1011ae08745Sheppo  *          |      +----------+     +----------+     +----------+
1021ae08745Sheppo  *          +----->| console  |---->| console  |---->| lconsole |---> ....
1031ae08745Sheppo  *                 +----------+     +----------+     +----------+
1041ae08745Sheppo  *                     |  |
1051ae08745Sheppo  *		       |  |     +----------+      +----------+
1061ae08745Sheppo  *		       |  +---->|  client  |----->|   client |----->......
1071ae08745Sheppo  *		       |	+----------+      +----------+
1081ae08745Sheppo  *		       |	     |                 |
1091ae08745Sheppo  *		       |<------------+                 |
1101ae08745Sheppo  *		       |<------------------------------+
1111ae08745Sheppo  *
1121ae08745Sheppo  * Locks
1131ae08745Sheppo  *  Each vntsd has one lock to protect the group queue
1141ae08745Sheppo  *  Each group has one lock to protect the console queue,  the queue for
1151ae08745Sheppo  *  clients without a console connection and status.
1161ae08745Sheppo  *  Each console has one lock to protect client queue and status.
1171ae08745Sheppo  *  Each client has one lock to protect the state of the client. The client
1181ae08745Sheppo  *  states are:
1191ae08745Sheppo  *
1201ae08745Sheppo  *  VCC_CLIENT_READER
1211ae08745Sheppo  *	A client is connected to a console as either a writer or a reader.
1221ae08745Sheppo  *	if this client is the first one connects the console, the client is
1231ae08745Sheppo  *	a writer, otherwise the client is a reader. A writer' write thread
1241ae08745Sheppo  *	reads from vcc and send output to all readers connected to the
1251ae08745Sheppo  *	same console. a reader's write thread is blocked until a reader becomes
1261ae08745Sheppo  *	a writer.
1271ae08745Sheppo  *
1281ae08745Sheppo  *	When a client selected a console, the client becomes a reader if
1291ae08745Sheppo  *	there is another client connected to the console before the client.
1301ae08745Sheppo  *	A client will be a writer if
1311ae08745Sheppo  *	1. client is the first one connected to the console or
1321ae08745Sheppo  *	2. client has entered a ~w daemon command or
1331ae08745Sheppo  *	3. all clients connected to the console before the client have
1341ae08745Sheppo  *	   disconnected from the console.
1351ae08745Sheppo  *
1361ae08745Sheppo  *  VCC_CLIENT_MOVE_CONS_FORWARD
1371ae08745Sheppo  *  VCC_CLIENT_MOVE_CONS_BACKWOARD
1381ae08745Sheppo  *	A client is disconnecting from one console and move to the next or
1391ae08745Sheppo  *	previous console in the group queue.
1401ae08745Sheppo  *	A client is in one of these state if
1411ae08745Sheppo  *	1. the client has entered the daemon command and
1421ae08745Sheppo  *	2. the vntsd is in process of switching the client from one
1431ae08745Sheppo  *	   console to another.
1441ae08745Sheppo  *
1451ae08745Sheppo  *  VCC_CLIENT_DISABLE_DAEMON_CMD
1461ae08745Sheppo  *	vntsd is in processing of a client's daemon command or the client is
1471ae08745Sheppo  *	in selecting console.
1481ae08745Sheppo  *	A client is in this state if
1491ae08745Sheppo  *	1. the client has not selected a console or
1501ae08745Sheppo  *	2. the vntsd is processing a client's daemon command.
1511ae08745Sheppo  *
1521ae08745Sheppo  *  VCC_CLIENT_ACQUIRE_WRITER
1531ae08745Sheppo  *	A reader forces to become a writer via vntsd special command.
1541ae08745Sheppo  *	A client is in this state if
1551ae08745Sheppo  *	1. the client is a reader and
1561ae08745Sheppo  *	2. client has entered a daemon command to become a writer.
1571ae08745Sheppo  *
1581ae08745Sheppo  *  VCC_CLIENT_CONS_DELETED
1591ae08745Sheppo  *	The console that the client is connected to is being deleted and
1601ae08745Sheppo  *	waiting for the client to disconnect.
1611ae08745Sheppo  *	A client is in this state if
1621ae08745Sheppo  *	1. the console a client is connected to is being removed and
1631ae08745Sheppo  *	2. the vntsd is in process of disconnecting the client from the console.
1641ae08745Sheppo  *
1651ae08745Sheppo  */
1661ae08745Sheppo 
1671ae08745Sheppo #ifndef _VNTSD_H
1681ae08745Sheppo #define	_VNTSD_H
1691ae08745Sheppo 
1701ae08745Sheppo #ifdef __cplusplus
1711ae08745Sheppo extern "C" {
1721ae08745Sheppo #endif
1731ae08745Sheppo 
1741ae08745Sheppo #include	<sys/shm.h>
1751ae08745Sheppo #include	<strings.h>
1761ae08745Sheppo #include	<assert.h>
1771ae08745Sheppo #include	<sys/wait.h>
1781ae08745Sheppo #include	<sys/stat.h>
1791ae08745Sheppo #include	<fcntl.h>
1801ae08745Sheppo #include	<stropts.h>
1811ae08745Sheppo #include	<errno.h>
1821ae08745Sheppo #include	<sys/param.h>
1831ae08745Sheppo #include	"../../uts/sun4v/sys/vcc.h"
1841ae08745Sheppo 
1851ae08745Sheppo #define	DEBUG
1861ae08745Sheppo 
1871ae08745Sheppo /* vntsd limits */
1881ae08745Sheppo #define	    VNTSD_MAX_BUF_SIZE		128
1891ae08745Sheppo #define	    VNTSD_LINE_LEN		100
1901ae08745Sheppo #define	    VNTSD_MAX_SOCKETS		5
1911ae08745Sheppo #define	    VNTSD_EOL_LEN		2
1921ae08745Sheppo 
1931ae08745Sheppo /* secons before re-send signal for cv_wait */
1941ae08745Sheppo #define	    VNTSD_CV_WAIT_DELTIME	10
1951ae08745Sheppo 
1961ae08745Sheppo #define	    VCC_PATH_PREFIX     \
1971ae08745Sheppo 		"/devices/virtual-devices@100/channel-devices@200/"
1981ae08745Sheppo #define	    VCC_DEVICE_PATH			"/devices%s"
1991ae08745Sheppo #define	    VCC_DEVICE_CTL_PATH VCC_PATH_PREFIX "%s:ctl"
2001ae08745Sheppo 
2011ae08745Sheppo /* common messages */
2021ae08745Sheppo #define	    VNTSD_NO_WRITE_ACCESS_MSG	"You do not have write access"
2031ae08745Sheppo 
2041ae08745Sheppo /* vntsd options */
2051ae08745Sheppo #define	    VNTSD_OPT_DAEMON_OFF	0x1
206*28b1e50eSSriharsha Basavapatna #define	    VNTSD_OPT_AUTH_CHECK	0x2	/* Enable auth checking */
2071ae08745Sheppo 
2084d39be2bSsg /*
2094d39be2bSsg  * group states
2104d39be2bSsg  * When a console is removed or vntsd is exiting, main thread
2114d39be2bSsg  * notifies listen, read and write thread to exit.
2124d39be2bSsg  * After those threads exit, main thread clears up group structurre.
2134d39be2bSsg  *
2144d39be2bSsg  * VNTSD_GROUP_SIG_WAIT
2154d39be2bSsg  * The main thread is waiting for listen thread to exit.
2164d39be2bSsg  * VNTSD_GROUP_CLEAN_CONS
2174d39be2bSsg  * There are console(s) in the group that are being removed.
2184d39be2bSsg  * This is a transition state where the corresponding vcc port has been
2194d39be2bSsg  * removed, but vntsd has not done its clean up yet.
2204d39be2bSsg  * VNTSD_GROUP_IN_CLEANUP
2214d39be2bSsg  * vntsd main thread has started cleaning up the group.
2224d39be2bSsg  */
2231ae08745Sheppo 
2244d39be2bSsg #define	    VNTSD_GROUP_SIG_WAIT	0x1
2254d39be2bSsg #define	    VNTSD_GROUP_CLEAN_CONS	0x2
2264d39be2bSsg #define	    VNTSD_GROUP_IN_CLEANUP	0x4
2271ae08745Sheppo 
2281ae08745Sheppo 
2291ae08745Sheppo 
2301ae08745Sheppo 
2311ae08745Sheppo 
2324d39be2bSsg /*
2334d39be2bSsg  * console states
2344d39be2bSsg  * There are two states when a console is removed
2354d39be2bSsg  * VNTSD_CONS_DELETED
2364d39be2bSsg  * the console is being deleted
2374d39be2bSsg  * VNTSD_CONS_SIG_WAIT
2384d39be2bSsg  * console is waiting for all clients to exit.
2394d39be2bSsg  */
2401ae08745Sheppo 
2411ae08745Sheppo #define	    VNTSD_CONS_DELETED		0x1	/* deleted */
2424d39be2bSsg #define	    VNTSD_CONS_SIG_WAIT		0x2	/* waiting for signal */
2431ae08745Sheppo 
2441ae08745Sheppo 
2451ae08745Sheppo #define	    VNTSD_CLIENT_IO_ERR		    0x1	    /* reader */
2461ae08745Sheppo #define	    VNTSD_CLIENT_DISABLE_DAEMON_CMD 0x2	    /* disable daemon cmd */
2471ae08745Sheppo #define	    VNTSD_CLIENT_TIMEOUT	    0x4	    /* timeout */
2481ae08745Sheppo #define	    VNTSD_CLIENT_CONS_DELETED	    0x8	    /* console deleted */
2491ae08745Sheppo 
2501ae08745Sheppo /* generic que structure */
2511ae08745Sheppo typedef	struct vntsd_que {
2521ae08745Sheppo 	void			*handle;	/* element in queue */
2531ae08745Sheppo 	struct vntsd_que	*nextp;		/* next queue element */
2541ae08745Sheppo 	struct vntsd_que	*prevp;		/* previous queue element */
2551ae08745Sheppo } vntsd_que_t;
2561ae08745Sheppo 
2571ae08745Sheppo struct vntsd_cons;
2581ae08745Sheppo struct vntsd_group;
2591ae08745Sheppo struct vntsd;
2601ae08745Sheppo 
2611ae08745Sheppo /* client structure  */
2621ae08745Sheppo typedef struct vntsd_client {
2631ae08745Sheppo 	mutex_t	    lock;	    /* protect the client */
2641ae08745Sheppo 	uint_t	    status;	    /* client's state */
2651ae08745Sheppo 
2661ae08745Sheppo 	int	    sockfd;	    /* connection socket */
2671ae08745Sheppo 	thread_t    cons_tid;	    /* console thread */
2681ae08745Sheppo 
2691ae08745Sheppo 	struct vntsd_cons    *cons; /* back link to console configuration */
2701ae08745Sheppo 
271d10e4ef2Snarayan 	char	    prev_char;	    /* previous char read by this client */
272d10e4ef2Snarayan 
2731ae08745Sheppo } vntsd_client_t;
2741ae08745Sheppo 
2751ae08745Sheppo /* console structure */
2761ae08745Sheppo typedef struct vntsd_cons {
2771ae08745Sheppo 	mutex_t		lock;			    /* protect console port */
2781ae08745Sheppo 	cond_t		cvp;			    /* sync between threads */
2791ae08745Sheppo 
2801ae08745Sheppo 	vntsd_que_t	*clientpq;		    /* client que */
2811ae08745Sheppo 	uint_t		status;			    /* client's state */
2821ae08745Sheppo 	int		vcc_fd;			    /* vcc console port */
2831ae08745Sheppo 	thread_t	wr_tid;			    /* write thread */
2841ae08745Sheppo 
2851ae08745Sheppo 	uint_t		cons_no;		    /* console port number  */
2861ae08745Sheppo 	char		domain_name[MAXPATHLEN];    /* domain name */
2871ae08745Sheppo 	char		dev_name[MAXPATHLEN];
2881ae08745Sheppo 
2891ae08745Sheppo 	struct vntsd_group   *group;		    /* back link to group */
2901ae08745Sheppo } vntsd_cons_t;
2911ae08745Sheppo 
2921ae08745Sheppo /* group structure  */
2931ae08745Sheppo typedef struct vntsd_group {
2941ae08745Sheppo 	mutex_t	    lock;		    /* protect group */
2951ae08745Sheppo 	cond_t	    cvp;		    /* sync remove group */
2961ae08745Sheppo 
2971ae08745Sheppo 	uint_t	    status;		    /* group status */
2981ae08745Sheppo 	char	    group_name[MAXPATHLEN];
2991ae08745Sheppo 	uint64_t    tcp_port;		    /* telnet port */
3001ae08745Sheppo 
3011ae08745Sheppo 	thread_t    listen_tid;		    /* listen thread */
3021ae08745Sheppo 	int	    sockfd;		    /* listen socket */
3031ae08745Sheppo 
3041ae08745Sheppo 	vntsd_que_t *conspq;		    /* console queue */
3051ae08745Sheppo 	uint_t	    num_cons;		    /* num console */
3061ae08745Sheppo 
3071ae08745Sheppo 	/* clients have no console connection */
3081ae08745Sheppo 	vntsd_que_t *no_cons_clientpq;
3091ae08745Sheppo 	struct vntsd   *vntsd;
3101ae08745Sheppo 
3111ae08745Sheppo } vntsd_group_t;
3121ae08745Sheppo 
3131ae08745Sheppo /* daemon structure */
3141ae08745Sheppo typedef struct vntsd {
3151ae08745Sheppo 
3161ae08745Sheppo 	mutex_t		lock;			/* protect vntsd */
3171ae08745Sheppo 	mutex_t		tmo_lock;		/* protect tmo queue */
3181ae08745Sheppo 
3191ae08745Sheppo 	int		instance;		/* vcc instance */
3201ae08745Sheppo 	struct in_addr  ip_addr;		/* ip address to listen */
3211ae08745Sheppo 	uint64_t	options;		/* daemon options */
3221ae08745Sheppo 	int		timeout;		/* connection timeout */
3231ae08745Sheppo 
3241ae08745Sheppo 	char		*devinst;		/* device name */
3251ae08745Sheppo 	int		ctrl_fd;		/* vcc ctrl port */
3261ae08745Sheppo 
3271ae08745Sheppo 	vntsd_que_t	*grouppq;		/* group queue */
3281ae08745Sheppo 	uint_t		num_grps;		/* num groups */
3291ae08745Sheppo 
3301ae08745Sheppo 	vntsd_que_t	*tmoq;			/* timeout queue */
3311ae08745Sheppo 	thread_t	tid;			/* main thread id */
3321ae08745Sheppo 
3331ae08745Sheppo } vntsd_t;
3341ae08745Sheppo 
3351ae08745Sheppo /* handle for creating thread */
3361ae08745Sheppo typedef	struct vntsd_thr_arg {
3371ae08745Sheppo 	void	*handle;
3381ae08745Sheppo 	void	*arg;
3391ae08745Sheppo } vntsd_thr_arg_t;
3401ae08745Sheppo 
3411ae08745Sheppo /* timeout structure */
3421ae08745Sheppo typedef struct vntsd_timeout {
3431ae08745Sheppo 	thread_t	tid;		    /* thread tid */
3441ae08745Sheppo 	uint_t		minutes;	    /* idle minutes */
3451ae08745Sheppo 	vntsd_client_t	*clientp;	    /* client */
3461ae08745Sheppo } vntsd_timeout_t;
3471ae08745Sheppo 
3481ae08745Sheppo /* vntsd status and error  definitions */
3491ae08745Sheppo typedef enum {
3501ae08745Sheppo 
3511ae08745Sheppo 	/* status */
3521ae08745Sheppo 	VNTSD_SUCCESS = 0,		/* success */
3531ae08745Sheppo 	VNTSD_STATUS_CONTINUE,		/* continue to execute */
3541ae08745Sheppo 	VNTSD_STATUS_EXIT_SIG,		/* exit siginal */
3551ae08745Sheppo 	VNTSD_STATUS_SIG,		/* known signal */
3561ae08745Sheppo 	VNTSD_STATUS_NO_HOST_NAME,	/* no host name set */
3571ae08745Sheppo 	VNTSD_STATUS_CLIENT_QUIT,	/* client disconnected from group */
3581ae08745Sheppo 	VNTSD_STATUS_RESELECT_CONS,	/* client re-selecting console */
3591ae08745Sheppo 	VNTSD_STATUS_VCC_IO_ERR,	/* a vcc io error occurs */
3601ae08745Sheppo 	VNTSD_STATUS_MOV_CONS_FORWARD,	/* down arrow  */
3611ae08745Sheppo 	VNTSD_STATUS_MOV_CONS_BACKWARD,	/* up  arrow  */
3621ae08745Sheppo 	VNTSD_STATUS_ACQUIRE_WRITER,	/* force become the writer */
3631ae08745Sheppo 	VNTSD_STATUS_INTR,		/* thread receive a signal */
3641ae08745Sheppo 	VNTSD_STATUS_DISCONN_CONS,	/* disconnect a client from cons */
3651ae08745Sheppo 	VNTSD_STATUS_NO_CONS,		/* disconnect a client from cons */
366*28b1e50eSSriharsha Basavapatna 	VNTSD_STATUS_AUTH_ENABLED,	/* auth enabled; can't process '-p' */
3671ae08745Sheppo 
3681ae08745Sheppo 	/* resource errors */
3691ae08745Sheppo 	VNTSD_ERR_NO_MEM,		/* memory allocation error */
3701ae08745Sheppo 	VNTSD_ERR_NO_DRV,		/* cannot open vcc port */
3711ae08745Sheppo 
3721ae08745Sheppo 	/* vcc errors */
3731ae08745Sheppo 	VNTSD_ERR_VCC_CTRL_DATA,	/* vcc ctrl data error */
3741ae08745Sheppo 	VNTSD_ERR_VCC_POLL,		/* error poll vcc driver */
3751ae08745Sheppo 	VNTSD_ERR_VCC_IOCTL,		/* vcc ioctl call error */
3761ae08745Sheppo 	VNTSD_ERR_VCC_GRP_NAME,		/* group name differs from database */
3771ae08745Sheppo 	VNTSD_ERR_ADD_CONS_FAILED,	/* addition of a console failed */
3781ae08745Sheppo 
3791ae08745Sheppo 	/* create thread errors */
3801ae08745Sheppo 	VNTSD_ERR_CREATE_LISTEN_THR,	/* listen thread creation failed */
3811ae08745Sheppo 	VNTSD_ERR_CREATE_CONS_THR,	/* create console thread err  */
3821ae08745Sheppo 	VNTSD_ERR_CREATE_WR_THR,	/* listen thread creation failed */
3831ae08745Sheppo 
3841ae08745Sheppo 	/* listen thread errors */
3851ae08745Sheppo 	VNTSD_ERR_LISTEN_SOCKET,	/* can not create tcp socket */
3861ae08745Sheppo 	VNTSD_ERR_LISTEN_OPTS,		/* can not set socket opt */
3871ae08745Sheppo 	VNTSD_ERR_LISTEN_BIND,		/* can not bind socket */
3881ae08745Sheppo 	VNTSD_STATUS_ACCEPT_ERR,	/* accept error  */
3891ae08745Sheppo 
3901ae08745Sheppo 	/* tcp client read and write errors */
3911ae08745Sheppo 	VNTSD_ERR_WRITE_CLIENT,		/* writing tcp client err */
3921ae08745Sheppo 
3931ae08745Sheppo 	/* tcp client timeout */
3941ae08745Sheppo 	VNTSD_ERR_CLIENT_TIMEOUT,	/* client has no activity for timeout */
3951ae08745Sheppo 
3961ae08745Sheppo 	/* signal errors */
3971ae08745Sheppo 	VNTSD_ERR_SIG,			/* unknown signal */
3981ae08745Sheppo 
3991ae08745Sheppo 	/* user input error */
4001ae08745Sheppo 	VNTSD_ERR_INVALID_INPUT,	/* client typed in */
4011ae08745Sheppo 
4021ae08745Sheppo 	/* internal errors */
4031ae08745Sheppo 	VNTSD_ERR_EL_NOT_FOUND,		/* element not found */
4041ae08745Sheppo 	VNTSD_ERR_UNKNOWN_CMD		/* unknown error/cmd */
4051ae08745Sheppo 
4061ae08745Sheppo } vntsd_status_t;
4071ae08745Sheppo 
4081ae08745Sheppo /* function prototype defines */
4091ae08745Sheppo typedef	int	    (*compare_func_t)(void *el, void *data);
4101ae08745Sheppo typedef	int	    (*el_func_t)(void *el);
4111ae08745Sheppo typedef	void	    (*clean_func_t)(void *el);
4121ae08745Sheppo typedef	void	    (*sig_handler_t)(int sig);
4131ae08745Sheppo typedef	void	    *(*thr_func_t)(void *);
4141ae08745Sheppo 
4151ae08745Sheppo 
4161ae08745Sheppo 
4171ae08745Sheppo /* function prototype */
4181ae08745Sheppo void		vntsd_log(vntsd_status_t err, char *msg);
4191ae08745Sheppo struct in_addr	vntsd_ip_addr(void);
4201ae08745Sheppo 
4211ae08745Sheppo void		vntsd_get_config(vntsd_t *vntsdp);
4221ae08745Sheppo void		vntsd_daemon_wakeup(vntsd_t *vntsdp);
4231ae08745Sheppo int		vntsd_open_vcc(char *domain_name, uint_t cons_no);
4241ae08745Sheppo void		vntsd_delete_cons(vntsd_t *vntsdp);
4251ae08745Sheppo void		vntsd_clean_group(vntsd_group_t *groupp);
4261ae08745Sheppo 
4271ae08745Sheppo 
4281ae08745Sheppo void		*vntsd_listen_thread(vntsd_group_t *groupp);
4291ae08745Sheppo void		*vntsd_console_thread(vntsd_thr_arg_t *argp);
4301ae08745Sheppo int		vntsd_read(vntsd_client_t *clientp);
4311ae08745Sheppo void		*vntsd_write_thread(vntsd_cons_t *consp);
4321ae08745Sheppo 
4331ae08745Sheppo boolean_t	vntsd_cons_by_consno(vntsd_cons_t *consp, int *cons_id);
4341ae08745Sheppo 
4351ae08745Sheppo int		vntsd_que_append(vntsd_que_t **que_hd, void *handle);
4361ae08745Sheppo int		vntsd_que_rm(vntsd_que_t **que_hd, void *handle);
4371ae08745Sheppo void		*vntsd_que_find(vntsd_que_t *que_hd, compare_func_t
4381ae08745Sheppo 			compare_func, void *data);
4391ae08745Sheppo void		*vntsd_que_walk(vntsd_que_t *que_hd, el_func_t el_func);
4401ae08745Sheppo 
4411ae08745Sheppo int		vntsd_que_insert_after(vntsd_que_t *que, void *handle,
4421ae08745Sheppo 			void *next);
4431ae08745Sheppo void		*vntsd_que_pos(vntsd_que_t *que_hd, void *handle, int pos);
4441ae08745Sheppo void		vntsd_free_que(vntsd_que_t **q, clean_func_t clean_func);
4451ae08745Sheppo 
4461ae08745Sheppo int		vntsd_read_char(vntsd_client_t *clientp, char *c);
4471ae08745Sheppo int		vntsd_read_line(vntsd_client_t *clientp, char *buf, int *size);
4481ae08745Sheppo int		vntsd_read_data(vntsd_client_t *clientp, char *c);
4491ae08745Sheppo int		vntsd_get_yes_no(vntsd_client_t *clientp, char *msg,
4501ae08745Sheppo 			int *yes_no);
4511ae08745Sheppo int		vntsd_ctrl_cmd(vntsd_client_t *clientp, char c);
4521ae08745Sheppo int		vntsd_process_daemon_cmd(vntsd_client_t *clientp, char c);
4531ae08745Sheppo int		vntsd_telnet_cmd(vntsd_client_t *clientp, char c);
4541ae08745Sheppo 
4551ae08745Sheppo int		vntsd_set_telnet_options(int fd);
4561ae08745Sheppo int		vntsd_write_client(vntsd_client_t *client, char *buffer,
4571ae08745Sheppo 	size_t sz);
4581ae08745Sheppo int		vntsd_write_fd(int fd, void *buffer, size_t sz);
4591ae08745Sheppo int		vntsd_write_line(vntsd_client_t *clientp, char *line);
4601ae08745Sheppo int		vntsd_write_lines(vntsd_client_t *clientp, char *lines);
4611ae08745Sheppo extern char	vntsd_eol[];
4621ae08745Sheppo 
4631ae08745Sheppo void		vntsd_clean_group(vntsd_group_t *portp);
4641ae08745Sheppo void		vntsd_free_client(vntsd_client_t *clientp);
4651ae08745Sheppo int		vntsd_attach_timer(vntsd_timeout_t *tmop);
4661ae08745Sheppo int		vntsd_detach_timer(vntsd_timeout_t *tmop);
4671ae08745Sheppo void		vntsd_reset_timer(thread_t tid);
4681ae08745Sheppo void		vntsd_init_esctable_msgs(void);
4691ae08745Sheppo int		vntsd_vcc_ioctl(int ioctl_code, uint_t portno, void *buf);
4701ae08745Sheppo int		vntsd_vcc_err(vntsd_cons_t *consp);
4711ae08745Sheppo int		vntsd_cons_chk_intr(vntsd_client_t *clientp);
4721ae08745Sheppo boolean_t	vntsd_vcc_cons_alive(vntsd_cons_t *consp);
4731ae08745Sheppo boolean_t	vntsd_notify_client_cons_del(vntsd_client_t *clientp);
4741ae08745Sheppo int		vntsd_chk_group_total_cons(vntsd_group_t *groupp);
4754d39be2bSsg boolean_t	vntsd_mark_deleted_cons(vntsd_cons_t *consp);
476*28b1e50eSSriharsha Basavapatna boolean_t	auth_check_fd(int sock_fd, char *group_name);
4771ae08745Sheppo 
4781ae08745Sheppo #ifdef	DEBUG
4791ae08745Sheppo 
4801ae08745Sheppo extern int vntsddbg;
4811ae08745Sheppo 
4821ae08745Sheppo #define	D1 	if (vntsddbg & 0x01) (void) fprintf
4831ae08745Sheppo #define	D2	if (vntsddbg & 0x02) (void) fprintf
4841ae08745Sheppo #define	D3 	if (vntsddbg & 0x04) (void) fprintf
4851ae08745Sheppo #define	DERR 	if (vntsddbg & 0x08) (void) fprintf
4861ae08745Sheppo 
4871ae08745Sheppo #else  /* not DEBUG */
4881ae08745Sheppo 
4891ae08745Sheppo #define	D1
4901ae08745Sheppo #define	D2
4911ae08745Sheppo #define	D3
4921ae08745Sheppo #define	DERR
4931ae08745Sheppo 
4941ae08745Sheppo #endif /* not DEBUG */
4951ae08745Sheppo 
4961ae08745Sheppo #ifdef __cplusplus
4971ae08745Sheppo }
4981ae08745Sheppo #endif
4991ae08745Sheppo 
5001ae08745Sheppo #endif /* _VNTSD_H */
501