xref: /titanic_44/usr/src/cmd/dcs/sparc/sun4u/dcs.h (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 2000 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef	_DCS_H
28 #define	_DCS_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <poll.h>
37 #include <signal.h>
38 
39 #include "remote_cfg.h"
40 #include "rdr_param_types.h"
41 
42 
43 #define	DCS_SERVICE		"sun-dr"
44 #define	SUN_DR_PORT		665
45 #define	DCS_BACKLOG		10
46 
47 #define	BLOCKFOREVER		(-1)
48 #define	DCS_SND_TIMEOUT		60000		/* 1 minute */
49 #define	DCS_RCV_TIMEOUT		300000		/* 5 minutes */
50 #define	DCS_RCV_CB_TIMEOUT	43200000	/* 12 hours */
51 
52 #define	DCS_ERR_OFFSET		12000
53 #define	MAX_MSG_LEN		512
54 
55 #define	DCS_MAX_SESSIONS	128
56 
57 /*
58  * Debugging
59  */
60 #define	DBG_NONE	0x00000000
61 #define	DBG_ALL		0xFFFFFFFF
62 #define	DBG_INFO	0x00000001
63 #define	DBG_MSG		0x00000002
64 #define	DBG_SES		0x00000004
65 #define	DBG_STATE	0x00000008
66 
67 #ifdef DCS_DEBUG
68 
69 /*
70  * supported options for debug version:
71  *
72  * -d  control the amount of debugging
73  * -S  control standalone mode
74  * -s  control maximum active sessions
75  */
76 #define	OPT_STR		"d:Ss:"
77 
78 #else /* DCS_DEBUG */
79 
80 /*
81  * supported options for non-debug version:
82  *
83  * -s  control maximum active sessions
84  */
85 #define	OPT_STR		"s:"
86 
87 #endif /* DCS_DEBUG */
88 
89 
90 /*
91  * Error codes that are used internally in the DCS. These error codes
92  * are mapped to the strings listed to the right of each error code
93  * as a comment.
94  */
95 typedef enum {
96 
97 	/*
98 	 * Network Errors:
99 	 */
100 	DCS_INIT_ERR = 0,   /* network initialization failed		   */
101 	DCS_NO_PORT,	    /* failed to acquire reserved port		   */
102 	DCS_CONNECT_ERR,    /* connection attempt failed		   */
103 	DCS_RECEIVE_ERR,    /* unable to receive message		   */
104 	DCS_OP_REPLY_ERR,   /* unable to send message for %s operation	   */
105 	DCS_NO_SERV,	    /* %s service not found, using reserved	   */
106 			    /* port 665					   */
107 	DCS_DISCONNECT,	    /* client disconnected			   */
108 
109 	/*
110 	 * Session Errors:
111 	 */
112 	DCS_SES_HAND_ERR,   /* failed to start a new session handler	   */
113 	DCS_ABORT_ERR,	    /* abort attempt of session, %d, unsuccessful  */
114 	DCS_VER_INVAL,	    /* unsupported message protocol version %d.%d  */
115 	DCS_SES_ABORTED,    /* session aborted				   */
116 
117 	/*
118 	 * DR Request Errors:
119 	 */
120 	DCS_UNKNOWN_OP,	    /* unknown operation requested		   */
121 	DCS_OP_FAILED,	    /* operation failed				   */
122 	DCS_SES_SEQ_INVAL,  /* invalid session establishment sequence	   */
123 	DCS_NO_SES_ESTBL,   /* %s operation issued before session	   */
124 			    /* established				   */
125 	DCS_MSG_INVAL,	    /* received an invalid message		   */
126 	DCS_CONF_CB_ERR,    /* confirm callback failed, aborting operation */
127 	DCS_MSG_CB_ERR,	    /* message callback failed, continuing	   */
128 	DCS_BAD_RETRY_VAL,  /* retry value invalid (%d)			   */
129 	DCS_BAD_TIME_VAL,   /* timeout value invalid (%d)		   */
130 	DCS_RETRY,	    /* retrying operation, attempt %d		   */
131 
132 	/*
133 	 * General Errors:
134 	 */
135 	DCS_NO_PRIV,	    /* permission denied			   */
136 	DCS_INT_ERR,	    /* internal error: %s: %s			   */
137 	DCS_UNKNOWN_ERR,    /* unrecognized error reported		   */
138 	DCS_BAD_OPT,	    /* illegal option (-%c), exiting		   */
139 	DCS_BAD_OPT_ARG,    /* illegal argument to -%c flag (%s), %s	   */
140 	DCS_CFGA_UNKNOWN,   /* configuration administration unknown error  */
141 	DCS_CFGA_ERR,	    /* %s: %s					   */
142 	DCS_RSRC_ERR,	    /* resource info init error (%d)		   */
143 	DCS_MSG_COUNT	    /* NULL					   */
144 
145 } dcs_err_code;
146 
147 
148 /*
149  * Public error codes. These error codes are returned to the
150  * client in the event of a fatal error. Since the DCS can
151  * report either a libcfgadm or internal error, there is a
152  * possiblity of conflicting error codes. To avoid this, the
153  * DCS error codes are offset by a constant value. However,
154  * 0 will always indicate that no errors have occurred.
155  */
156 typedef enum {
157 	DCS_OK = 0,
158 	DCS_ERROR = DCS_ERR_OFFSET,
159 	DCS_MSG_INVAL_ERR,
160 	DCS_VER_INVAL_ERR,
161 	DCS_NO_SES_ERR,
162 	DCS_SES_INVAL_ERR,
163 	DCS_SES_SEQ_INVAL_ERR,
164 	DCS_SES_ABORTED_ERR
165 } dcs_err_t;
166 
167 
168 /*
169  * DCS states. These states are the states that the DCS moves
170  * through as it processes a DR request. The order represents
171  * the transitions performed in a successful operation.
172  */
173 typedef enum {
174 	DCS_CONNECTED = 1,
175 	DCS_SES_REQ,
176 	DCS_SES_ESTBL,
177 	DCS_CONF_PENDING,
178 	DCS_CONF_DONE,
179 	DCS_SES_END
180 } dcs_ses_state_t;
181 
182 
183 /*
184  * Message Contents
185  */
186 typedef struct message {
187 	rdr_msg_hdr_t	*hdr;
188 	cfga_params_t	*params;
189 } message_t;
190 
191 
192 /*
193  * Session information
194  */
195 typedef struct session {
196 	unsigned long	id;
197 	unsigned short	major_version;
198 	unsigned short	minor_version;
199 	unsigned long	random_req;
200 	unsigned long	random_resp;
201 
202 	int		fd;
203 	dcs_ses_state_t	state;
204 	message_t	curr_msg;
205 } session_t;
206 
207 
208 /*
209  * Message Direction
210  */
211 typedef enum {
212 	DCS_SEND,
213 	DCS_RECEIVE
214 } dcs_msg_type_t;
215 
216 
217 /*
218  * Globals
219  */
220 extern ulong_t	dcs_debug;
221 extern int	standalone;
222 extern ulong_t	max_sessions;
223 
224 
225 /*
226  * From dcs.c:
227  */
228 int dcs_dispatch_message(rdr_msg_hdr_t *hdr, cfga_params_t *params);
229 void init_msg(rdr_msg_hdr_t *hdr);
230 
231 /*
232  * From dcs_ses.c:
233  */
234 int ses_start(int fd);
235 int ses_close(int err_code);
236 int ses_abort(long ses_id);
237 void ses_abort_enable(void);
238 void ses_abort_disable(void);
239 void abort_handler(void);
240 int ses_setlocale(char *locale);
241 void ses_init_signals(sigset_t *mask);
242 void ses_sleep(int sec);
243 int ses_poll(struct pollfd fds[], nfds_t nfds, int timeout);
244 session_t *curr_ses(void);
245 long curr_ses_id(void);
246 
247 /*
248  * From dcs_msg.c:
249  */
250 void dcs_log_msg(int priority, int code, ...);
251 char *dcs_cfga_str(char **err_str, int err_code);
252 void dcs_dbg(int level, char *fmt, ...);
253 void print_msg_hdr(dcs_msg_type_t type, rdr_msg_hdr_t *hdr);
254 const char *dcs_strerror(int err_code);
255 
256 
257 /*
258  * If the dcs_debug global variable is not set, no
259  * debugging messages will be logged.
260  */
261 #define	DCS_DBG		if (dcs_debug) dcs_dbg
262 #define	PRINT_MSG_DBG	if (dcs_debug) print_msg_hdr
263 
264 
265 #ifdef	__cplusplus
266 }
267 #endif
268 
269 #endif /* _DCS_H */
270