xref: /illumos-gate/usr/src/cmd/dcs/sparc/sun4u/dcs.h (revision bbf215553c7233fbab8a0afdf1fac74c44781867)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_DCS_H
27 #define	_DCS_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #include <poll.h>
34 #include <signal.h>
35 
36 #include "remote_cfg.h"
37 #include "rdr_param_types.h"
38 
39 
40 #define	DCS_SERVICE		"sun-dr"
41 #define	SUN_DR_PORT		665
42 #define	DCS_BACKLOG		10
43 
44 #define	BLOCKFOREVER		(-1)
45 #define	DCS_SND_TIMEOUT		60000		/* 1 minute */
46 #define	DCS_RCV_TIMEOUT		300000		/* 5 minutes */
47 #define	DCS_RCV_CB_TIMEOUT	43200000	/* 12 hours */
48 
49 #define	DCS_ERR_OFFSET		12000
50 #define	MAX_MSG_LEN		512
51 
52 #define	DCS_MAX_SESSIONS	128
53 
54 /*
55  * Header files for per-socket IPsec
56  */
57 #include <netinet/in.h>
58 #include <net/pfkeyv2.h>
59 
60 
61 /*
62  * The IPsec socket option struct, from ipsec(4P):
63  *
64  *     typedef struct ipsec_req {
65  *         uint_t      ipsr_ah_req;            AH request
66  *         uint_t      ipsr_esp_req;           ESP request
67  *         uint_t      ipsr_self_encap_req;    Self-Encap request
68  *         uint8_t     ipsr_auth_alg;          Auth algs for AH
69  *         uint8_t     ipsr_esp_alg;           Encr algs for ESP
70  *         uint8_t     ipsr_esp_auth_alg;      Auth algs for ESP
71  *     } ipsec_req_t;
72  *
73  * The -a option sets the ipsr_auth_alg field. Allowable arguments
74  * are "none", "md5", or "sha1". The -e option sets the ipsr_esp_alg
75  * field. Allowable arguments are "none", "des", or "3des". "none"
76  * is the default for both options. The -u option sets the ipsr_esp_auth_alg
77  * field. Allowable arguments are the same as -a.
78  *
79  * The arguments ("md5", "des", etc.) are named so that they match
80  * kmd(8)'s accepted arguments which are listed on the SC in
81  * /etc/opt/SUNWSMS/SMS/config/kmd_policy.cf.
82  */
83 #define	AH_REQ		(IPSEC_PREF_REQUIRED | IPSEC_PREF_UNIQUE)
84 #define	ESP_REQ		(IPSEC_PREF_REQUIRED | IPSEC_PREF_UNIQUE)
85 #define	SELF_ENCAP_REQ	0x0
86 
87 /*
88  * A type to hold the command line argument string used to select a
89  * particular authentication header (AH) or encapsulating security
90  * payload (ESP) algorithm and the ID used for that algorithm when
91  * filling the ipsec_req_t structure which is passed to
92  * setsockopt(3SOCKET).
93  */
94 typedef struct dcs_alg {
95 	char		*arg_name;
96 	uint8_t		alg_id;
97 } dcs_alg_t;
98 
99 
100 /*
101  * Debugging
102  */
103 #define	DBG_NONE	0x00000000
104 #define	DBG_ALL		0xFFFFFFFF
105 #define	DBG_INFO	0x00000001
106 #define	DBG_MSG		0x00000002
107 #define	DBG_SES		0x00000004
108 #define	DBG_STATE	0x00000008
109 
110 #ifdef DCS_DEBUG
111 
112 /*
113  * supported options for debug version:
114  *
115  * -d  control the amount of debugging
116  * -S  control standalone mode
117  * -s  control maximum active sessions
118  * -a  control the IPsec AH algorithm ("none", "md5", or "sha1")
119  * -e  control the IPsec ESP encr algorithm ("none", "des", or "3des")
120  * -u  control the IPsec ESP auth algorithm ("none", "md5", or "sha1")
121  * -l  control the use of libdscp for endpoint authentication.
122  */
123 #define	OPT_STR		"d:Ss:a:e:u:l"
124 
125 #else /* DCS_DEBUG */
126 
127 /*
128  * supported options for non-debug version:
129  *
130  * -s  control maximum active sessions
131  * -a  control the IPsec AH algorithm ("none", "md5", or "sha1")
132  * -e  control the IPsec ESP encr algorithm ("none", "des", or "3des")
133  * -u  control the IPsec ESP auth algorithm ("none", "md5", or "sha1")
134  * -l  control the use of libdscp for endpoint authentication.
135  */
136 #define	OPT_STR		"s:a:e:u:l"
137 
138 #endif /* DCS_DEBUG */
139 
140 
141 /*
142  * Error codes that are used internally in the DCS. These error codes
143  * are mapped to the strings listed to the right of each error code
144  * as a comment.
145  */
146 typedef enum {
147 
148 	/*
149 	 * Network Errors:
150 	 */
151 	DCS_INIT_ERR = 0,   /* network initialization failed		   */
152 	DCS_NO_PORT,	    /* failed to acquire reserved port		   */
153 	DCS_CONNECT_ERR,    /* connection attempt failed		   */
154 	DCS_RECEIVE_ERR,    /* unable to receive message		   */
155 	DCS_OP_REPLY_ERR,   /* unable to send message for %s operation	   */
156 	DCS_NO_SERV,	    /* %s service not found, using reserved	   */
157 			    /* port 665					   */
158 	DCS_DISCONNECT,	    /* client disconnected			   */
159 
160 	/*
161 	 * Session Errors:
162 	 */
163 	DCS_SES_HAND_ERR,   /* failed to start a new session handler	   */
164 	DCS_ABORT_ERR,	    /* abort attempt of session, %d, unsuccessful  */
165 	DCS_VER_INVAL,	    /* unsupported message protocol version %d.%d  */
166 	DCS_SES_ABORTED,    /* session aborted				   */
167 
168 	/*
169 	 * DR Request Errors:
170 	 */
171 	DCS_UNKNOWN_OP,	    /* unknown operation requested		   */
172 	DCS_OP_FAILED,	    /* operation failed				   */
173 	DCS_SES_SEQ_INVAL,  /* invalid session establishment sequence	   */
174 	DCS_NO_SES_ESTBL,   /* %s operation issued before session	   */
175 			    /* established				   */
176 	DCS_MSG_INVAL,	    /* received an invalid message		   */
177 	DCS_CONF_CB_ERR,    /* confirm callback failed, aborting operation */
178 	DCS_MSG_CB_ERR,	    /* message callback failed, continuing	   */
179 	DCS_BAD_RETRY_VAL,  /* retry value invalid (%d)			   */
180 	DCS_BAD_TIME_VAL,   /* timeout value invalid (%d)		   */
181 	DCS_RETRY,	    /* retrying operation, attempt %d		   */
182 
183 	/*
184 	 * General Errors:
185 	 */
186 	DCS_NO_PRIV,	    /* permission denied			   */
187 	DCS_INT_ERR,	    /* internal error: %s: %s			   */
188 	DCS_UNKNOWN_ERR,    /* unrecognized error reported		   */
189 	DCS_BAD_OPT,	    /* illegal option (-%c), exiting		   */
190 	DCS_BAD_OPT_ARG,    /* illegal argument to -%c flag (%s), %s	   */
191 	DCS_CFGA_UNKNOWN,   /* configuration administration unknown error  */
192 	DCS_CFGA_ERR,	    /* %s: %s					   */
193 	DCS_RSRC_ERR,	    /* resource info init error (%d)		   */
194 	DCS_NO_ERR,	    /* no error					   */
195 	DCS_MSG_COUNT	    /* NULL					   */
196 
197 } dcs_err_code;
198 
199 
200 /*
201  * Public error codes. These error codes are returned to the
202  * client in the event of a fatal error. Since the DCS can
203  * report either a libcfgadm or internal error, there is a
204  * possiblity of conflicting error codes. To avoid this, the
205  * DCS error codes are offset by a constant value. However,
206  * 0 will always indicate that no errors have occurred.
207  */
208 typedef enum {
209 	DCS_OK = 0,
210 	DCS_ERROR = DCS_ERR_OFFSET,
211 	DCS_MSG_INVAL_ERR,
212 	DCS_VER_INVAL_ERR,
213 	DCS_NO_SES_ERR,
214 	DCS_SES_INVAL_ERR,
215 	DCS_SES_SEQ_INVAL_ERR,
216 	DCS_SES_ABORTED_ERR
217 } dcs_err_t;
218 
219 
220 /*
221  * DCS states. These states are the states that the DCS moves
222  * through as it processes a DR request. The order represents
223  * the transitions performed in a successful operation.
224  */
225 typedef enum {
226 	DCS_CONNECTED = 1,
227 	DCS_SES_REQ,
228 	DCS_SES_ESTBL,
229 	DCS_CONF_PENDING,
230 	DCS_CONF_DONE,
231 	DCS_SES_END
232 } dcs_ses_state_t;
233 
234 
235 /*
236  * Message Contents
237  */
238 typedef struct message {
239 	rdr_msg_hdr_t	*hdr;
240 	cfga_params_t	*params;
241 } message_t;
242 
243 
244 /*
245  * Session information
246  */
247 typedef struct session {
248 	unsigned long	id;
249 	unsigned short	major_version;
250 	unsigned short	minor_version;
251 	unsigned long	random_req;
252 	unsigned long	random_resp;
253 
254 	int		fd;
255 	dcs_ses_state_t	state;
256 	message_t	curr_msg;
257 } session_t;
258 
259 
260 /*
261  * Message Direction
262  */
263 typedef enum {
264 	DCS_SEND,
265 	DCS_RECEIVE
266 } dcs_msg_type_t;
267 
268 
269 /*
270  * Globals
271  */
272 extern ulong_t	dcs_debug;
273 extern int	standalone;
274 extern ulong_t	max_sessions;
275 extern int	use_libdscp;
276 
277 
278 /*
279  * From dcs.c:
280  */
281 int dcs_dispatch_message(rdr_msg_hdr_t *hdr, cfga_params_t *params);
282 void init_msg(rdr_msg_hdr_t *hdr);
283 
284 /*
285  * From dcs_ses.c:
286  */
287 int ses_start(int fd);
288 int ses_close(int err_code);
289 int ses_abort(long ses_id);
290 void ses_abort_enable(void);
291 void ses_abort_disable(void);
292 void abort_handler(void);
293 int ses_setlocale(char *locale);
294 void ses_init_signals(sigset_t *mask);
295 void ses_sleep(int sec);
296 int ses_poll(struct pollfd fds[], nfds_t nfds, int timeout);
297 session_t *curr_ses(void);
298 long curr_ses_id(void);
299 
300 /*
301  * From dcs_msg.c:
302  */
303 void dcs_log_msg(int priority, int code, ...);
304 char *dcs_cfga_str(char **err_str, int err_code);
305 void dcs_dbg(int level, char *fmt, ...);
306 void print_msg_hdr(dcs_msg_type_t type, rdr_msg_hdr_t *hdr);
307 const char *dcs_strerror(int err_code);
308 
309 
310 /*
311  * If the dcs_debug global variable is not set, no
312  * debugging messages will be logged.
313  */
314 #define	DCS_DBG		if (dcs_debug) dcs_dbg
315 #define	PRINT_MSG_DBG	if (dcs_debug) print_msg_hdr
316 
317 
318 #ifdef	__cplusplus
319 }
320 #endif
321 
322 #endif /* _DCS_H */
323