xref: /titanic_53/usr/src/cmd/vntsd/vntsd.h (revision 1ae0874509b6811fdde1dfd46f0d93fd09867a3f)
1*1ae08745Sheppo /*
2*1ae08745Sheppo  * CDDL HEADER START
3*1ae08745Sheppo  *
4*1ae08745Sheppo  * The contents of this file are subject to the terms of the
5*1ae08745Sheppo  * Common Development and Distribution License (the "License").
6*1ae08745Sheppo  * You may not use this file except in compliance with the License.
7*1ae08745Sheppo  *
8*1ae08745Sheppo  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*1ae08745Sheppo  * or http://www.opensolaris.org/os/licensing.
10*1ae08745Sheppo  * See the License for the specific language governing permissions
11*1ae08745Sheppo  * and limitations under the License.
12*1ae08745Sheppo  *
13*1ae08745Sheppo  * When distributing Covered Code, include this CDDL HEADER in each
14*1ae08745Sheppo  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*1ae08745Sheppo  * If applicable, add the following below this CDDL HEADER, with the
16*1ae08745Sheppo  * fields enclosed by brackets "[]" replaced with your own identifying
17*1ae08745Sheppo  * information: Portions Copyright [yyyy] [name of copyright owner]
18*1ae08745Sheppo  *
19*1ae08745Sheppo  * CDDL HEADER END
20*1ae08745Sheppo  */
21*1ae08745Sheppo /*
22*1ae08745Sheppo  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23*1ae08745Sheppo  * Use is subject to license terms.
24*1ae08745Sheppo  */
25*1ae08745Sheppo 
26*1ae08745Sheppo /*
27*1ae08745Sheppo  * vntsd uses configuration information provided by vcc to export access
28*1ae08745Sheppo  * to Ldom console access over regular TCP sockets. When it starts, it opens
29*1ae08745Sheppo  * the vcc driver control port and obtains the list of ports that have been
30*1ae08745Sheppo  * created by the vcc driver as well as TCP port number and group associated
31*1ae08745Sheppo  * with each port.
32*1ae08745Sheppo  * vntsd consists of multiple components as the follows:
33*1ae08745Sheppo  *
34*1ae08745Sheppo  * vntsd.c
35*1ae08745Sheppo  * This module initializes vnts daemon, process user options such as instance
36*1ae08745Sheppo  * number, ip address and etc., and provides main thread to poll any console
37*1ae08745Sheppo  * port change.
38*1ae08745Sheppo  *
39*1ae08745Sheppo  * vntsdvcc.c
40*1ae08745Sheppo  * This module provides vcc driver interface. It opens vcc driver control
41*1ae08745Sheppo  * ports, read initial configuration, and provides interface to read, write and
42*1ae08745Sheppo  * ioctl virtual console ports. This module creates a listen thread for each
43*1ae08745Sheppo  * console group. It further dynamically adds and removes virtual consoles
44*1ae08745Sheppo  * and groups following instructions of the vcc driver. This module
45*1ae08745Sheppo  * is executed in the same thread as vntsd.c which is blocked on vcc control
46*1ae08745Sheppo  * poll interface.
47*1ae08745Sheppo  *
48*1ae08745Sheppo  * listen.c
49*1ae08745Sheppo  * This is a group listen thread. Each group's tcp-port has a listen thread
50*1ae08745Sheppo  * associated with it. The thread is created when a console is associated with
51*1ae08745Sheppo  * a new group and is removed when all consoles in the group are removed.
52*1ae08745Sheppo  *
53*1ae08745Sheppo  * console.c
54*1ae08745Sheppo  * This is a console selection thread. The thread is created when a client
55*1ae08745Sheppo  * connects to a group TCP port and exited when client disconnects. If there is
56*1ae08745Sheppo  * only one console in the group, the client is connected to that console. If
57*1ae08745Sheppo  * there are multiple consoles in the group, the client is asked to select a
58*1ae08745Sheppo  * console. After determining which console to connect to, this thread
59*1ae08745Sheppo  * a write thread if the cient is a writer and it self read in client input.
60*1ae08745Sheppo  *
61*1ae08745Sheppo  * read.c
62*1ae08745Sheppo  * it reads input from a TCP client, processes
63*1ae08745Sheppo  * special daemon and telent commands and write to vcc driver if the client
64*1ae08745Sheppo  * is a writer. The client is a writer if the client is the first one connects
65*1ae08745Sheppo  * to the console. Read thread print out an error message if a reader attempt
66*1ae08745Sheppo  * to input to vcc. Read thread exits if console is deleted, client
67*1ae08745Sheppo  * disconnects, or there is a fatal error.
68*1ae08745Sheppo  *
69*1ae08745Sheppo  * Write.c
70*1ae08745Sheppo  * Write thread is creaed when first client connects to a console. It reads
71*1ae08745Sheppo  * from vcc and writes to all clients that connect to the same console.
72*1ae08745Sheppo  * Write thread exits when all clients disconnect from the console.
73*1ae08745Sheppo  *
74*1ae08745Sheppo  * cmd.c
75*1ae08745Sheppo  * This is a supporting module for handling special daemon and telnet commands.
76*1ae08745Sheppo  *
77*1ae08745Sheppo  * common.c
78*1ae08745Sheppo  * supporting modules shared by threads modules.
79*1ae08745Sheppo  *
80*1ae08745Sheppo  * queue.c
81*1ae08745Sheppo  * This is a moudle supporting queue operations. Vntsd organizes its data
82*1ae08745Sheppo  * in multiple queues <see data structure below>.
83*1ae08745Sheppo  *
84*1ae08745Sheppo  * vntsd.xml
85*1ae08745Sheppo  * This is a manifest to support SMF interfaces.
86*1ae08745Sheppo  *
87*1ae08745Sheppo  * Data structures
88*1ae08745Sheppo  * each group has a vntsd_group_t structure, which contains a queue of
89*1ae08745Sheppo  * all console in that group.
90*1ae08745Sheppo  * each console has a vntsd_cons_t structure, which contains a queue of
91*1ae08745Sheppo  * all clients that connected to the console.
92*1ae08745Sheppo  *
93*1ae08745Sheppo  *     +----------+   +----------+   +----------+
94*1ae08745Sheppo  *     |  group	  |-->|  group   |-->|   group  |-->....
95*1ae08745Sheppo  *     +----------+   +----------+   +----------+
96*1ae08745Sheppo  *          |
97*1ae08745Sheppo  *          |<-----------------------------------------+
98*1ae08745Sheppo  *          |<------------------------+                |
99*1ae08745Sheppo  *          |<--------+               |                |
100*1ae08745Sheppo  *          |         |               |                |
101*1ae08745Sheppo  *          |      +----------+     +----------+     +----------+
102*1ae08745Sheppo  *          +----->| console  |---->| console  |---->| lconsole |---> ....
103*1ae08745Sheppo  *                 +----------+     +----------+     +----------+
104*1ae08745Sheppo  *                     |  |
105*1ae08745Sheppo  *		       |  |     +----------+      +----------+
106*1ae08745Sheppo  *		       |  +---->|  client  |----->|   client |----->......
107*1ae08745Sheppo  *		       |	+----------+      +----------+
108*1ae08745Sheppo  *		       |	     |                 |
109*1ae08745Sheppo  *		       |<------------+                 |
110*1ae08745Sheppo  *		       |<------------------------------+
111*1ae08745Sheppo  *
112*1ae08745Sheppo  * Locks
113*1ae08745Sheppo  *  Each vntsd has one lock to protect the group queue
114*1ae08745Sheppo  *  Each group has one lock to protect the console queue,  the queue for
115*1ae08745Sheppo  *  clients without a console connection and status.
116*1ae08745Sheppo  *  Each console has one lock to protect client queue and status.
117*1ae08745Sheppo  *  Each client has one lock to protect the state of the client. The client
118*1ae08745Sheppo  *  states are:
119*1ae08745Sheppo  *
120*1ae08745Sheppo  *  VCC_CLIENT_READER
121*1ae08745Sheppo  *	A client is connected to a console as either a writer or a reader.
122*1ae08745Sheppo  *	if this client is the first one connects the console, the client is
123*1ae08745Sheppo  *	a writer, otherwise the client is a reader. A writer' write thread
124*1ae08745Sheppo  *	reads from vcc and send output to all readers connected to the
125*1ae08745Sheppo  *	same console. a reader's write thread is blocked until a reader becomes
126*1ae08745Sheppo  *	a writer.
127*1ae08745Sheppo  *
128*1ae08745Sheppo  *	When a client selected a console, the client becomes a reader if
129*1ae08745Sheppo  *	there is another client connected to the console before the client.
130*1ae08745Sheppo  *	A client will be a writer if
131*1ae08745Sheppo  *	1. client is the first one connected to the console or
132*1ae08745Sheppo  *	2. client has entered a ~w daemon command or
133*1ae08745Sheppo  *	3. all clients connected to the console before the client have
134*1ae08745Sheppo  *	   disconnected from the console.
135*1ae08745Sheppo  *
136*1ae08745Sheppo  *  VCC_CLIENT_MOVE_CONS_FORWARD
137*1ae08745Sheppo  *  VCC_CLIENT_MOVE_CONS_BACKWOARD
138*1ae08745Sheppo  *	A client is disconnecting from one console and move to the next or
139*1ae08745Sheppo  *	previous console in the group queue.
140*1ae08745Sheppo  *	A client is in one of these state if
141*1ae08745Sheppo  *	1. the client has entered the daemon command and
142*1ae08745Sheppo  *	2. the vntsd is in process of switching the client from one
143*1ae08745Sheppo  *	   console to another.
144*1ae08745Sheppo  *
145*1ae08745Sheppo  *  VCC_CLIENT_DISABLE_DAEMON_CMD
146*1ae08745Sheppo  *	vntsd is in processing of a client's daemon command or the client is
147*1ae08745Sheppo  *	in selecting console.
148*1ae08745Sheppo  *	A client is in this state if
149*1ae08745Sheppo  *	1. the client has not selected a console or
150*1ae08745Sheppo  *	2. the vntsd is processing a client's daemon command.
151*1ae08745Sheppo  *
152*1ae08745Sheppo  *  VCC_CLIENT_ACQUIRE_WRITER
153*1ae08745Sheppo  *	A reader forces to become a writer via vntsd special command.
154*1ae08745Sheppo  *	A client is in this state if
155*1ae08745Sheppo  *	1. the client is a reader and
156*1ae08745Sheppo  *	2. client has entered a daemon command to become a writer.
157*1ae08745Sheppo  *
158*1ae08745Sheppo  *  VCC_CLIENT_CONS_DELETED
159*1ae08745Sheppo  *	The console that the client is connected to is being deleted and
160*1ae08745Sheppo  *	waiting for the client to disconnect.
161*1ae08745Sheppo  *	A client is in this state if
162*1ae08745Sheppo  *	1. the console a client is connected to is being removed and
163*1ae08745Sheppo  *	2. the vntsd is in process of disconnecting the client from the console.
164*1ae08745Sheppo  *
165*1ae08745Sheppo  */
166*1ae08745Sheppo 
167*1ae08745Sheppo #ifndef _VNTSD_H
168*1ae08745Sheppo #define	_VNTSD_H
169*1ae08745Sheppo 
170*1ae08745Sheppo #pragma ident	"%Z%%M%	%I%	%E% SMI"
171*1ae08745Sheppo 
172*1ae08745Sheppo #ifdef __cplusplus
173*1ae08745Sheppo extern "C" {
174*1ae08745Sheppo #endif
175*1ae08745Sheppo 
176*1ae08745Sheppo #include	<sys/shm.h>
177*1ae08745Sheppo #include	<strings.h>
178*1ae08745Sheppo #include	<assert.h>
179*1ae08745Sheppo #include	<sys/wait.h>
180*1ae08745Sheppo #include	<sys/stat.h>
181*1ae08745Sheppo #include	<fcntl.h>
182*1ae08745Sheppo #include	<stropts.h>
183*1ae08745Sheppo #include	<errno.h>
184*1ae08745Sheppo #include	<sys/param.h>
185*1ae08745Sheppo #include	"../../uts/sun4v/sys/vcc.h"
186*1ae08745Sheppo 
187*1ae08745Sheppo #define	DEBUG
188*1ae08745Sheppo 
189*1ae08745Sheppo /* vntsd limits */
190*1ae08745Sheppo #define	    VNTSD_MAX_BUF_SIZE		128
191*1ae08745Sheppo #define	    VNTSD_LINE_LEN		100
192*1ae08745Sheppo #define	    VNTSD_MAX_SOCKETS		5
193*1ae08745Sheppo #define	    VNTSD_EOL_LEN		2
194*1ae08745Sheppo 
195*1ae08745Sheppo /* secons before re-send signal for cv_wait */
196*1ae08745Sheppo #define	    VNTSD_CV_WAIT_DELTIME	10
197*1ae08745Sheppo 
198*1ae08745Sheppo #define	    VCC_PATH_PREFIX     \
199*1ae08745Sheppo 		"/devices/virtual-devices@100/channel-devices@200/"
200*1ae08745Sheppo #define	    VCC_DEVICE_PATH			"/devices%s"
201*1ae08745Sheppo #define	    VCC_DEVICE_CTL_PATH VCC_PATH_PREFIX "%s:ctl"
202*1ae08745Sheppo 
203*1ae08745Sheppo /* common messages */
204*1ae08745Sheppo #define	    VNTSD_NO_WRITE_ACCESS_MSG	"You do not have write access"
205*1ae08745Sheppo 
206*1ae08745Sheppo /* vntsd options */
207*1ae08745Sheppo #define	    VNTSD_OPT_DAEMON_OFF	0x1
208*1ae08745Sheppo 
209*1ae08745Sheppo /* group states */
210*1ae08745Sheppo 
211*1ae08745Sheppo #define	    VNTSD_GROUP_SIG_WAIT	0x1	/*  waiting for signal */
212*1ae08745Sheppo #define	    VNTSD_GROUP_CLEAN_CONS	0x2	/*  cons needs to be clean */
213*1ae08745Sheppo #define	    VNTSD_GROUP_CLEANUP		0x4	/*  waiting for signal */
214*1ae08745Sheppo 
215*1ae08745Sheppo 
216*1ae08745Sheppo 
217*1ae08745Sheppo 
218*1ae08745Sheppo 
219*1ae08745Sheppo /* console status */
220*1ae08745Sheppo 
221*1ae08745Sheppo #define	    VNTSD_CONS_DELETED		0x1	/* deleted */
222*1ae08745Sheppo #define	    VNTSD_CONS_SIG_WAIT		0x2	/* waiting fro signal */
223*1ae08745Sheppo 
224*1ae08745Sheppo 
225*1ae08745Sheppo #define	    VNTSD_CLIENT_IO_ERR		    0x1	    /* reader */
226*1ae08745Sheppo #define	    VNTSD_CLIENT_DISABLE_DAEMON_CMD 0x2	    /* disable daemon cmd */
227*1ae08745Sheppo #define	    VNTSD_CLIENT_TIMEOUT	    0x4	    /* timeout */
228*1ae08745Sheppo #define	    VNTSD_CLIENT_CONS_DELETED	    0x8	    /* console deleted */
229*1ae08745Sheppo 
230*1ae08745Sheppo /* generic que structure */
231*1ae08745Sheppo typedef	struct vntsd_que {
232*1ae08745Sheppo 	void			*handle;	/* element in queue */
233*1ae08745Sheppo 	struct vntsd_que	*nextp;		/* next queue element */
234*1ae08745Sheppo 	struct vntsd_que	*prevp;		/* previous queue element */
235*1ae08745Sheppo } vntsd_que_t;
236*1ae08745Sheppo 
237*1ae08745Sheppo struct vntsd_cons;
238*1ae08745Sheppo struct vntsd_group;
239*1ae08745Sheppo struct vntsd;
240*1ae08745Sheppo 
241*1ae08745Sheppo /* client structure  */
242*1ae08745Sheppo typedef struct vntsd_client {
243*1ae08745Sheppo 	mutex_t	    lock;	    /* protect the client */
244*1ae08745Sheppo 	uint_t	    status;	    /* client's state */
245*1ae08745Sheppo 
246*1ae08745Sheppo 	int	    sockfd;	    /* connection socket */
247*1ae08745Sheppo 	thread_t    cons_tid;	    /* console thread */
248*1ae08745Sheppo 
249*1ae08745Sheppo 	struct vntsd_cons    *cons; /* back link to console configuration */
250*1ae08745Sheppo 
251*1ae08745Sheppo } vntsd_client_t;
252*1ae08745Sheppo 
253*1ae08745Sheppo /* console structure */
254*1ae08745Sheppo typedef struct vntsd_cons {
255*1ae08745Sheppo 	mutex_t		lock;			    /* protect console port */
256*1ae08745Sheppo 	cond_t		cvp;			    /* sync between threads */
257*1ae08745Sheppo 
258*1ae08745Sheppo 	vntsd_que_t	*clientpq;		    /* client que */
259*1ae08745Sheppo 	uint_t		status;			    /* client's state */
260*1ae08745Sheppo 	int		vcc_fd;			    /* vcc console port */
261*1ae08745Sheppo 	thread_t	wr_tid;			    /* write thread */
262*1ae08745Sheppo 
263*1ae08745Sheppo 	uint_t		cons_no;		    /* console port number  */
264*1ae08745Sheppo 	char		domain_name[MAXPATHLEN];    /* domain name */
265*1ae08745Sheppo 	char		dev_name[MAXPATHLEN];
266*1ae08745Sheppo 
267*1ae08745Sheppo 	struct vntsd_group   *group;		    /* back link to group */
268*1ae08745Sheppo } vntsd_cons_t;
269*1ae08745Sheppo 
270*1ae08745Sheppo /* group structure  */
271*1ae08745Sheppo typedef struct vntsd_group {
272*1ae08745Sheppo 	mutex_t	    lock;		    /* protect group */
273*1ae08745Sheppo 	cond_t	    cvp;		    /* sync remove group */
274*1ae08745Sheppo 
275*1ae08745Sheppo 	uint_t	    status;		    /* group status */
276*1ae08745Sheppo 	char	    group_name[MAXPATHLEN];
277*1ae08745Sheppo 	uint64_t    tcp_port;		    /* telnet port */
278*1ae08745Sheppo 
279*1ae08745Sheppo 	thread_t    listen_tid;		    /* listen thread */
280*1ae08745Sheppo 	int	    sockfd;		    /* listen socket */
281*1ae08745Sheppo 
282*1ae08745Sheppo 	vntsd_que_t *conspq;		    /* console queue */
283*1ae08745Sheppo 	uint_t	    num_cons;		    /* num console */
284*1ae08745Sheppo 
285*1ae08745Sheppo 	/* clients have no console connection */
286*1ae08745Sheppo 	vntsd_que_t *no_cons_clientpq;
287*1ae08745Sheppo 	struct vntsd   *vntsd;
288*1ae08745Sheppo 
289*1ae08745Sheppo } vntsd_group_t;
290*1ae08745Sheppo 
291*1ae08745Sheppo /* daemon structure */
292*1ae08745Sheppo typedef struct vntsd {
293*1ae08745Sheppo 
294*1ae08745Sheppo 	mutex_t		lock;			/* protect vntsd */
295*1ae08745Sheppo 	mutex_t		tmo_lock;		/* protect tmo queue */
296*1ae08745Sheppo 
297*1ae08745Sheppo 	int		instance;		/* vcc instance */
298*1ae08745Sheppo 	struct in_addr  ip_addr;		/* ip address to listen */
299*1ae08745Sheppo 	uint64_t	options;		/* daemon options */
300*1ae08745Sheppo 	int		timeout;		/* connection timeout */
301*1ae08745Sheppo 
302*1ae08745Sheppo 	char		*devinst;		/* device name */
303*1ae08745Sheppo 	int		ctrl_fd;		/* vcc ctrl port */
304*1ae08745Sheppo 
305*1ae08745Sheppo 	vntsd_que_t	*grouppq;		/* group queue */
306*1ae08745Sheppo 	uint_t		num_grps;		/* num groups */
307*1ae08745Sheppo 
308*1ae08745Sheppo 	vntsd_que_t	*tmoq;			/* timeout queue */
309*1ae08745Sheppo 	thread_t	tid;			/* main thread id */
310*1ae08745Sheppo 
311*1ae08745Sheppo } vntsd_t;
312*1ae08745Sheppo 
313*1ae08745Sheppo /* handle for creating thread */
314*1ae08745Sheppo typedef	struct vntsd_thr_arg {
315*1ae08745Sheppo 	void	*handle;
316*1ae08745Sheppo 	void	*arg;
317*1ae08745Sheppo } vntsd_thr_arg_t;
318*1ae08745Sheppo 
319*1ae08745Sheppo /* timeout structure */
320*1ae08745Sheppo typedef struct vntsd_timeout {
321*1ae08745Sheppo 	thread_t	tid;		    /* thread tid */
322*1ae08745Sheppo 	uint_t		minutes;	    /* idle minutes */
323*1ae08745Sheppo 	vntsd_client_t	*clientp;	    /* client */
324*1ae08745Sheppo } vntsd_timeout_t;
325*1ae08745Sheppo 
326*1ae08745Sheppo /* vntsd status and error  definitions */
327*1ae08745Sheppo typedef enum {
328*1ae08745Sheppo 
329*1ae08745Sheppo 	/* status */
330*1ae08745Sheppo 	VNTSD_SUCCESS = 0,		/* success */
331*1ae08745Sheppo 	VNTSD_STATUS_CONTINUE,		/* continue to execute */
332*1ae08745Sheppo 	VNTSD_STATUS_EXIT_SIG,		/* exit siginal */
333*1ae08745Sheppo 	VNTSD_STATUS_SIG,		/* known signal */
334*1ae08745Sheppo 	VNTSD_STATUS_NO_HOST_NAME,	/* no host name set */
335*1ae08745Sheppo 	VNTSD_STATUS_CLIENT_QUIT,	/* client disconnected from group */
336*1ae08745Sheppo 	VNTSD_STATUS_RESELECT_CONS,	/* client re-selecting console */
337*1ae08745Sheppo 	VNTSD_STATUS_VCC_IO_ERR,	/* a vcc io error occurs */
338*1ae08745Sheppo 	VNTSD_STATUS_MOV_CONS_FORWARD,	/* down arrow  */
339*1ae08745Sheppo 	VNTSD_STATUS_MOV_CONS_BACKWARD,	/* up  arrow  */
340*1ae08745Sheppo 	VNTSD_STATUS_ACQUIRE_WRITER,	/* force become the writer */
341*1ae08745Sheppo 	VNTSD_STATUS_INTR,		/* thread receive a signal */
342*1ae08745Sheppo 	VNTSD_STATUS_DISCONN_CONS,	/* disconnect a client from cons */
343*1ae08745Sheppo 	VNTSD_STATUS_NO_CONS,		/* disconnect a client from cons */
344*1ae08745Sheppo 
345*1ae08745Sheppo 	/* resource errors */
346*1ae08745Sheppo 	VNTSD_ERR_NO_MEM,		/* memory allocation error */
347*1ae08745Sheppo 	VNTSD_ERR_NO_DRV,		/* cannot open vcc port */
348*1ae08745Sheppo 
349*1ae08745Sheppo 	/* vcc errors */
350*1ae08745Sheppo 	VNTSD_ERR_VCC_CTRL_DATA,	/* vcc ctrl data error */
351*1ae08745Sheppo 	VNTSD_ERR_VCC_POLL,		/* error poll vcc driver */
352*1ae08745Sheppo 	VNTSD_ERR_VCC_IOCTL,		/* vcc ioctl call error */
353*1ae08745Sheppo 	VNTSD_ERR_VCC_GRP_NAME,		/* group name differs from database */
354*1ae08745Sheppo 	VNTSD_ERR_ADD_CONS_FAILED,	/* addition of a console failed */
355*1ae08745Sheppo 
356*1ae08745Sheppo 	/* create thread errors */
357*1ae08745Sheppo 	VNTSD_ERR_CREATE_LISTEN_THR,	/* listen thread creation failed */
358*1ae08745Sheppo 	VNTSD_ERR_CREATE_CONS_THR,	/* create console thread err  */
359*1ae08745Sheppo 	VNTSD_ERR_CREATE_WR_THR,	/* listen thread creation failed */
360*1ae08745Sheppo 
361*1ae08745Sheppo 	/* listen thread errors */
362*1ae08745Sheppo 	VNTSD_ERR_LISTEN_SOCKET,	/* can not create tcp socket */
363*1ae08745Sheppo 	VNTSD_ERR_LISTEN_OPTS,		/* can not set socket opt */
364*1ae08745Sheppo 	VNTSD_ERR_LISTEN_BIND,		/* can not bind socket */
365*1ae08745Sheppo 	VNTSD_STATUS_ACCEPT_ERR,	/* accept error  */
366*1ae08745Sheppo 
367*1ae08745Sheppo 	/* tcp client read and write errors */
368*1ae08745Sheppo 	VNTSD_ERR_WRITE_CLIENT,		/* writing tcp client err */
369*1ae08745Sheppo 
370*1ae08745Sheppo 	/* tcp client timeout */
371*1ae08745Sheppo 	VNTSD_ERR_CLIENT_TIMEOUT,	/* client has no activity for timeout */
372*1ae08745Sheppo 
373*1ae08745Sheppo 	/* signal errors */
374*1ae08745Sheppo 	VNTSD_ERR_SIG,			/* unknown signal */
375*1ae08745Sheppo 
376*1ae08745Sheppo 	/* user input error */
377*1ae08745Sheppo 	VNTSD_ERR_INVALID_INPUT,	/* client typed in */
378*1ae08745Sheppo 
379*1ae08745Sheppo 	/* internal errors */
380*1ae08745Sheppo 	VNTSD_ERR_EL_NOT_FOUND,		/* element not found */
381*1ae08745Sheppo 	VNTSD_ERR_UNKNOWN_CMD		/* unknown error/cmd */
382*1ae08745Sheppo 
383*1ae08745Sheppo } vntsd_status_t;
384*1ae08745Sheppo 
385*1ae08745Sheppo /* function prototype defines */
386*1ae08745Sheppo typedef	int	    (*compare_func_t)(void *el, void *data);
387*1ae08745Sheppo typedef	int	    (*el_func_t)(void *el);
388*1ae08745Sheppo typedef	void	    (*clean_func_t)(void *el);
389*1ae08745Sheppo typedef	void	    (*sig_handler_t)(int sig);
390*1ae08745Sheppo typedef	void	    *(*thr_func_t)(void *);
391*1ae08745Sheppo 
392*1ae08745Sheppo 
393*1ae08745Sheppo 
394*1ae08745Sheppo /* function prototype */
395*1ae08745Sheppo void		vntsd_log(vntsd_status_t err, char *msg);
396*1ae08745Sheppo struct in_addr	vntsd_ip_addr(void);
397*1ae08745Sheppo 
398*1ae08745Sheppo void		vntsd_get_config(vntsd_t *vntsdp);
399*1ae08745Sheppo void		vntsd_daemon_wakeup(vntsd_t *vntsdp);
400*1ae08745Sheppo int		vntsd_open_vcc(char *domain_name, uint_t cons_no);
401*1ae08745Sheppo void		vntsd_delete_cons(vntsd_t *vntsdp);
402*1ae08745Sheppo void		vntsd_clean_group(vntsd_group_t *groupp);
403*1ae08745Sheppo 
404*1ae08745Sheppo 
405*1ae08745Sheppo void		*vntsd_listen_thread(vntsd_group_t *groupp);
406*1ae08745Sheppo void		*vntsd_console_thread(vntsd_thr_arg_t *argp);
407*1ae08745Sheppo int		vntsd_read(vntsd_client_t *clientp);
408*1ae08745Sheppo void		*vntsd_write_thread(vntsd_cons_t *consp);
409*1ae08745Sheppo 
410*1ae08745Sheppo boolean_t	vntsd_cons_by_consno(vntsd_cons_t *consp, int *cons_id);
411*1ae08745Sheppo 
412*1ae08745Sheppo int		vntsd_que_append(vntsd_que_t **que_hd, void *handle);
413*1ae08745Sheppo int		vntsd_que_rm(vntsd_que_t **que_hd, void *handle);
414*1ae08745Sheppo void		*vntsd_que_find(vntsd_que_t *que_hd, compare_func_t
415*1ae08745Sheppo 			compare_func, void *data);
416*1ae08745Sheppo void		*vntsd_que_walk(vntsd_que_t *que_hd, el_func_t el_func);
417*1ae08745Sheppo 
418*1ae08745Sheppo int		vntsd_que_insert_after(vntsd_que_t *que, void *handle,
419*1ae08745Sheppo 			void *next);
420*1ae08745Sheppo void		*vntsd_que_pos(vntsd_que_t *que_hd, void *handle, int pos);
421*1ae08745Sheppo void		vntsd_free_que(vntsd_que_t **q, clean_func_t clean_func);
422*1ae08745Sheppo 
423*1ae08745Sheppo int		vntsd_read_char(vntsd_client_t *clientp, char *c);
424*1ae08745Sheppo int		vntsd_read_line(vntsd_client_t *clientp, char *buf, int *size);
425*1ae08745Sheppo int		vntsd_read_data(vntsd_client_t *clientp, char *c);
426*1ae08745Sheppo int		vntsd_get_yes_no(vntsd_client_t *clientp, char *msg,
427*1ae08745Sheppo 			int *yes_no);
428*1ae08745Sheppo int		vntsd_ctrl_cmd(vntsd_client_t *clientp, char c);
429*1ae08745Sheppo int		vntsd_process_daemon_cmd(vntsd_client_t *clientp, char c);
430*1ae08745Sheppo int		vntsd_telnet_cmd(vntsd_client_t *clientp, char c);
431*1ae08745Sheppo 
432*1ae08745Sheppo int		vntsd_set_telnet_options(int fd);
433*1ae08745Sheppo int		vntsd_write_client(vntsd_client_t *client, char *buffer,
434*1ae08745Sheppo 	size_t sz);
435*1ae08745Sheppo int		vntsd_write_fd(int fd, void *buffer, size_t sz);
436*1ae08745Sheppo int		vntsd_write_line(vntsd_client_t *clientp, char *line);
437*1ae08745Sheppo int		vntsd_write_lines(vntsd_client_t *clientp, char *lines);
438*1ae08745Sheppo extern char	vntsd_eol[];
439*1ae08745Sheppo 
440*1ae08745Sheppo void		vntsd_clean_group(vntsd_group_t *portp);
441*1ae08745Sheppo void		vntsd_free_client(vntsd_client_t *clientp);
442*1ae08745Sheppo int		vntsd_attach_timer(vntsd_timeout_t *tmop);
443*1ae08745Sheppo int		vntsd_detach_timer(vntsd_timeout_t *tmop);
444*1ae08745Sheppo void		vntsd_reset_timer(thread_t tid);
445*1ae08745Sheppo void		vntsd_init_esctable_msgs(void);
446*1ae08745Sheppo int		vntsd_vcc_ioctl(int ioctl_code, uint_t portno, void *buf);
447*1ae08745Sheppo int		vntsd_vcc_err(vntsd_cons_t *consp);
448*1ae08745Sheppo int		vntsd_cons_chk_intr(vntsd_client_t *clientp);
449*1ae08745Sheppo boolean_t	vntsd_vcc_cons_alive(vntsd_cons_t *consp);
450*1ae08745Sheppo boolean_t	vntsd_notify_client_cons_del(vntsd_client_t *clientp);
451*1ae08745Sheppo int		vntsd_chk_group_total_cons(vntsd_group_t *groupp);
452*1ae08745Sheppo 
453*1ae08745Sheppo 
454*1ae08745Sheppo #ifdef	DEBUG
455*1ae08745Sheppo 
456*1ae08745Sheppo extern int vntsddbg;
457*1ae08745Sheppo 
458*1ae08745Sheppo #define	D1 	if (vntsddbg & 0x01) (void) fprintf
459*1ae08745Sheppo #define	D2	if (vntsddbg & 0x02) (void) fprintf
460*1ae08745Sheppo #define	D3 	if (vntsddbg & 0x04) (void) fprintf
461*1ae08745Sheppo #define	DERR 	if (vntsddbg & 0x08) (void) fprintf
462*1ae08745Sheppo 
463*1ae08745Sheppo #else  /* not DEBUG */
464*1ae08745Sheppo 
465*1ae08745Sheppo #define	D1
466*1ae08745Sheppo #define	D2
467*1ae08745Sheppo #define	D3
468*1ae08745Sheppo #define	DERR
469*1ae08745Sheppo 
470*1ae08745Sheppo #endif /* not DEBUG */
471*1ae08745Sheppo 
472*1ae08745Sheppo #ifdef __cplusplus
473*1ae08745Sheppo }
474*1ae08745Sheppo #endif
475*1ae08745Sheppo 
476*1ae08745Sheppo #endif /* _VNTSD_H */
477