10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*1772Sjl139090 * Common Development and Distribution License (the "License"). 6*1772Sjl139090 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*1772Sjl139090 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 231120Smb158278 * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _DCS_H 270Sstevel@tonic-gate #define _DCS_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 300Sstevel@tonic-gate 310Sstevel@tonic-gate #ifdef __cplusplus 320Sstevel@tonic-gate extern "C" { 330Sstevel@tonic-gate #endif 340Sstevel@tonic-gate 350Sstevel@tonic-gate #include <poll.h> 360Sstevel@tonic-gate #include <signal.h> 370Sstevel@tonic-gate 380Sstevel@tonic-gate #include "remote_cfg.h" 390Sstevel@tonic-gate #include "rdr_param_types.h" 400Sstevel@tonic-gate 410Sstevel@tonic-gate 420Sstevel@tonic-gate #define DCS_SERVICE "sun-dr" 430Sstevel@tonic-gate #define SUN_DR_PORT 665 440Sstevel@tonic-gate #define DCS_BACKLOG 10 450Sstevel@tonic-gate 460Sstevel@tonic-gate #define BLOCKFOREVER (-1) 470Sstevel@tonic-gate #define DCS_SND_TIMEOUT 60000 /* 1 minute */ 480Sstevel@tonic-gate #define DCS_RCV_TIMEOUT 300000 /* 5 minutes */ 490Sstevel@tonic-gate #define DCS_RCV_CB_TIMEOUT 43200000 /* 12 hours */ 500Sstevel@tonic-gate 510Sstevel@tonic-gate #define DCS_ERR_OFFSET 12000 520Sstevel@tonic-gate #define MAX_MSG_LEN 512 530Sstevel@tonic-gate 540Sstevel@tonic-gate #define DCS_MAX_SESSIONS 128 550Sstevel@tonic-gate 560Sstevel@tonic-gate /* 571120Smb158278 * Header files for per-socket IPsec 581120Smb158278 */ 591120Smb158278 #include <netinet/in.h> 601120Smb158278 #include <net/pfkeyv2.h> 611120Smb158278 621120Smb158278 631120Smb158278 /* 641120Smb158278 * The IPsec socket option struct, from ipsec(7P): 651120Smb158278 * 661120Smb158278 * typedef struct ipsec_req { 671120Smb158278 * uint_t ipsr_ah_req; AH request 681120Smb158278 * uint_t ipsr_esp_req; ESP request 691120Smb158278 * uint_t ipsr_self_encap_req; Self-Encap request 701120Smb158278 * uint8_t ipsr_auth_alg; Auth algs for AH 711120Smb158278 * uint8_t ipsr_esp_alg; Encr algs for ESP 721120Smb158278 * uint8_t ipsr_esp_auth_alg; Auth algs for ESP 731120Smb158278 * } ipsec_req_t; 741120Smb158278 * 751120Smb158278 * The -a option sets the ipsr_auth_alg field. Allowable arguments 761120Smb158278 * are "none", "md5", or "sha1". The -e option sets the ipsr_esp_alg 771120Smb158278 * field. Allowable arguments are "none", "des", or "3des". "none" 781120Smb158278 * is the default for both options. The -u option sets the ipsr_esp_auth_alg 791120Smb158278 * field. Allowable arguments are the same as -a. 801120Smb158278 * 811120Smb158278 * The arguments ("md5", "des", etc.) are named so that they match 821120Smb158278 * kmd(1m)'s accepted arguments which are listed on the SC in 831120Smb158278 * /etc/opt/SUNWSMS/SMS/config/kmd_policy.cf. 841120Smb158278 */ 851120Smb158278 #define AH_REQ (IPSEC_PREF_REQUIRED | IPSEC_PREF_UNIQUE) 861120Smb158278 #define ESP_REQ (IPSEC_PREF_REQUIRED | IPSEC_PREF_UNIQUE) 871120Smb158278 #define SELF_ENCAP_REQ 0x0 881120Smb158278 891120Smb158278 /* 901120Smb158278 * A type to hold the command line argument string used to select a 911120Smb158278 * particular authentication header (AH) or encapsulating security 921120Smb158278 * payload (ESP) algorithm and the ID used for that algorithm when 931120Smb158278 * filling the ipsec_req_t structure which is passed to 941120Smb158278 * setsockopt(3SOCKET). 951120Smb158278 */ 961120Smb158278 typedef struct dcs_alg { 971120Smb158278 char *arg_name; 981120Smb158278 uint8_t alg_id; 991120Smb158278 } dcs_alg_t; 1001120Smb158278 1011120Smb158278 1021120Smb158278 /* 1030Sstevel@tonic-gate * Debugging 1040Sstevel@tonic-gate */ 1050Sstevel@tonic-gate #define DBG_NONE 0x00000000 1060Sstevel@tonic-gate #define DBG_ALL 0xFFFFFFFF 1070Sstevel@tonic-gate #define DBG_INFO 0x00000001 1080Sstevel@tonic-gate #define DBG_MSG 0x00000002 1090Sstevel@tonic-gate #define DBG_SES 0x00000004 1100Sstevel@tonic-gate #define DBG_STATE 0x00000008 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate #ifdef DCS_DEBUG 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate /* 1150Sstevel@tonic-gate * supported options for debug version: 1160Sstevel@tonic-gate * 1170Sstevel@tonic-gate * -d control the amount of debugging 1180Sstevel@tonic-gate * -S control standalone mode 1190Sstevel@tonic-gate * -s control maximum active sessions 1201120Smb158278 * -a control the IPsec AH algorithm ("none", "md5", or "sha1") 1211120Smb158278 * -e control the IPsec ESP encr algorithm ("none", "des", or "3des") 1221120Smb158278 * -u control the IPsec ESP auth algorithm ("none", "md5", or "sha1") 123*1772Sjl139090 * -l control the use of libdscp for endpoint authentication. 1240Sstevel@tonic-gate */ 125*1772Sjl139090 #define OPT_STR "d:Ss:a:e:u:l" 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate #else /* DCS_DEBUG */ 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate /* 1300Sstevel@tonic-gate * supported options for non-debug version: 1310Sstevel@tonic-gate * 1320Sstevel@tonic-gate * -s control maximum active sessions 1331120Smb158278 * -a control the IPsec AH algorithm ("none", "md5", or "sha1") 1341120Smb158278 * -e control the IPsec ESP encr algorithm ("none", "des", or "3des") 1351120Smb158278 * -u control the IPsec ESP auth algorithm ("none", "md5", or "sha1") 136*1772Sjl139090 * -l control the use of libdscp for endpoint authentication. 1370Sstevel@tonic-gate */ 138*1772Sjl139090 #define OPT_STR "s:a:e:u:l" 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate #endif /* DCS_DEBUG */ 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate /* 1440Sstevel@tonic-gate * Error codes that are used internally in the DCS. These error codes 1450Sstevel@tonic-gate * are mapped to the strings listed to the right of each error code 1460Sstevel@tonic-gate * as a comment. 1470Sstevel@tonic-gate */ 1480Sstevel@tonic-gate typedef enum { 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate /* 1510Sstevel@tonic-gate * Network Errors: 1520Sstevel@tonic-gate */ 1530Sstevel@tonic-gate DCS_INIT_ERR = 0, /* network initialization failed */ 1540Sstevel@tonic-gate DCS_NO_PORT, /* failed to acquire reserved port */ 1550Sstevel@tonic-gate DCS_CONNECT_ERR, /* connection attempt failed */ 1560Sstevel@tonic-gate DCS_RECEIVE_ERR, /* unable to receive message */ 1570Sstevel@tonic-gate DCS_OP_REPLY_ERR, /* unable to send message for %s operation */ 1580Sstevel@tonic-gate DCS_NO_SERV, /* %s service not found, using reserved */ 1590Sstevel@tonic-gate /* port 665 */ 1600Sstevel@tonic-gate DCS_DISCONNECT, /* client disconnected */ 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate /* 1630Sstevel@tonic-gate * Session Errors: 1640Sstevel@tonic-gate */ 1650Sstevel@tonic-gate DCS_SES_HAND_ERR, /* failed to start a new session handler */ 1660Sstevel@tonic-gate DCS_ABORT_ERR, /* abort attempt of session, %d, unsuccessful */ 1670Sstevel@tonic-gate DCS_VER_INVAL, /* unsupported message protocol version %d.%d */ 1680Sstevel@tonic-gate DCS_SES_ABORTED, /* session aborted */ 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate /* 1710Sstevel@tonic-gate * DR Request Errors: 1720Sstevel@tonic-gate */ 1730Sstevel@tonic-gate DCS_UNKNOWN_OP, /* unknown operation requested */ 1740Sstevel@tonic-gate DCS_OP_FAILED, /* operation failed */ 1750Sstevel@tonic-gate DCS_SES_SEQ_INVAL, /* invalid session establishment sequence */ 1760Sstevel@tonic-gate DCS_NO_SES_ESTBL, /* %s operation issued before session */ 1770Sstevel@tonic-gate /* established */ 1780Sstevel@tonic-gate DCS_MSG_INVAL, /* received an invalid message */ 1790Sstevel@tonic-gate DCS_CONF_CB_ERR, /* confirm callback failed, aborting operation */ 1800Sstevel@tonic-gate DCS_MSG_CB_ERR, /* message callback failed, continuing */ 1810Sstevel@tonic-gate DCS_BAD_RETRY_VAL, /* retry value invalid (%d) */ 1820Sstevel@tonic-gate DCS_BAD_TIME_VAL, /* timeout value invalid (%d) */ 1830Sstevel@tonic-gate DCS_RETRY, /* retrying operation, attempt %d */ 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate /* 1860Sstevel@tonic-gate * General Errors: 1870Sstevel@tonic-gate */ 1880Sstevel@tonic-gate DCS_NO_PRIV, /* permission denied */ 1890Sstevel@tonic-gate DCS_INT_ERR, /* internal error: %s: %s */ 1900Sstevel@tonic-gate DCS_UNKNOWN_ERR, /* unrecognized error reported */ 1910Sstevel@tonic-gate DCS_BAD_OPT, /* illegal option (-%c), exiting */ 1920Sstevel@tonic-gate DCS_BAD_OPT_ARG, /* illegal argument to -%c flag (%s), %s */ 1930Sstevel@tonic-gate DCS_CFGA_UNKNOWN, /* configuration administration unknown error */ 1940Sstevel@tonic-gate DCS_CFGA_ERR, /* %s: %s */ 1950Sstevel@tonic-gate DCS_RSRC_ERR, /* resource info init error (%d) */ 1961120Smb158278 DCS_NO_ERR, /* no error */ 1970Sstevel@tonic-gate DCS_MSG_COUNT /* NULL */ 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate } dcs_err_code; 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate /* 2030Sstevel@tonic-gate * Public error codes. These error codes are returned to the 2040Sstevel@tonic-gate * client in the event of a fatal error. Since the DCS can 2050Sstevel@tonic-gate * report either a libcfgadm or internal error, there is a 2060Sstevel@tonic-gate * possiblity of conflicting error codes. To avoid this, the 2070Sstevel@tonic-gate * DCS error codes are offset by a constant value. However, 2080Sstevel@tonic-gate * 0 will always indicate that no errors have occurred. 2090Sstevel@tonic-gate */ 2100Sstevel@tonic-gate typedef enum { 2110Sstevel@tonic-gate DCS_OK = 0, 2120Sstevel@tonic-gate DCS_ERROR = DCS_ERR_OFFSET, 2130Sstevel@tonic-gate DCS_MSG_INVAL_ERR, 2140Sstevel@tonic-gate DCS_VER_INVAL_ERR, 2150Sstevel@tonic-gate DCS_NO_SES_ERR, 2160Sstevel@tonic-gate DCS_SES_INVAL_ERR, 2170Sstevel@tonic-gate DCS_SES_SEQ_INVAL_ERR, 2180Sstevel@tonic-gate DCS_SES_ABORTED_ERR 2190Sstevel@tonic-gate } dcs_err_t; 2200Sstevel@tonic-gate 2210Sstevel@tonic-gate 2220Sstevel@tonic-gate /* 2230Sstevel@tonic-gate * DCS states. These states are the states that the DCS moves 2240Sstevel@tonic-gate * through as it processes a DR request. The order represents 2250Sstevel@tonic-gate * the transitions performed in a successful operation. 2260Sstevel@tonic-gate */ 2270Sstevel@tonic-gate typedef enum { 2280Sstevel@tonic-gate DCS_CONNECTED = 1, 2290Sstevel@tonic-gate DCS_SES_REQ, 2300Sstevel@tonic-gate DCS_SES_ESTBL, 2310Sstevel@tonic-gate DCS_CONF_PENDING, 2320Sstevel@tonic-gate DCS_CONF_DONE, 2330Sstevel@tonic-gate DCS_SES_END 2340Sstevel@tonic-gate } dcs_ses_state_t; 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate /* 2380Sstevel@tonic-gate * Message Contents 2390Sstevel@tonic-gate */ 2400Sstevel@tonic-gate typedef struct message { 2410Sstevel@tonic-gate rdr_msg_hdr_t *hdr; 2420Sstevel@tonic-gate cfga_params_t *params; 2430Sstevel@tonic-gate } message_t; 2440Sstevel@tonic-gate 2450Sstevel@tonic-gate 2460Sstevel@tonic-gate /* 2470Sstevel@tonic-gate * Session information 2480Sstevel@tonic-gate */ 2490Sstevel@tonic-gate typedef struct session { 2500Sstevel@tonic-gate unsigned long id; 2510Sstevel@tonic-gate unsigned short major_version; 2520Sstevel@tonic-gate unsigned short minor_version; 2530Sstevel@tonic-gate unsigned long random_req; 2540Sstevel@tonic-gate unsigned long random_resp; 2550Sstevel@tonic-gate 2560Sstevel@tonic-gate int fd; 2570Sstevel@tonic-gate dcs_ses_state_t state; 2580Sstevel@tonic-gate message_t curr_msg; 2590Sstevel@tonic-gate } session_t; 2600Sstevel@tonic-gate 2610Sstevel@tonic-gate 2620Sstevel@tonic-gate /* 2630Sstevel@tonic-gate * Message Direction 2640Sstevel@tonic-gate */ 2650Sstevel@tonic-gate typedef enum { 2660Sstevel@tonic-gate DCS_SEND, 2670Sstevel@tonic-gate DCS_RECEIVE 2680Sstevel@tonic-gate } dcs_msg_type_t; 2690Sstevel@tonic-gate 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate /* 2720Sstevel@tonic-gate * Globals 2730Sstevel@tonic-gate */ 2740Sstevel@tonic-gate extern ulong_t dcs_debug; 2750Sstevel@tonic-gate extern int standalone; 2760Sstevel@tonic-gate extern ulong_t max_sessions; 277*1772Sjl139090 extern int use_libdscp; 2780Sstevel@tonic-gate 2790Sstevel@tonic-gate 2800Sstevel@tonic-gate /* 2810Sstevel@tonic-gate * From dcs.c: 2820Sstevel@tonic-gate */ 2830Sstevel@tonic-gate int dcs_dispatch_message(rdr_msg_hdr_t *hdr, cfga_params_t *params); 2840Sstevel@tonic-gate void init_msg(rdr_msg_hdr_t *hdr); 2850Sstevel@tonic-gate 2860Sstevel@tonic-gate /* 2870Sstevel@tonic-gate * From dcs_ses.c: 2880Sstevel@tonic-gate */ 2890Sstevel@tonic-gate int ses_start(int fd); 2900Sstevel@tonic-gate int ses_close(int err_code); 2910Sstevel@tonic-gate int ses_abort(long ses_id); 2920Sstevel@tonic-gate void ses_abort_enable(void); 2930Sstevel@tonic-gate void ses_abort_disable(void); 2940Sstevel@tonic-gate void abort_handler(void); 2950Sstevel@tonic-gate int ses_setlocale(char *locale); 2960Sstevel@tonic-gate void ses_init_signals(sigset_t *mask); 2970Sstevel@tonic-gate void ses_sleep(int sec); 2980Sstevel@tonic-gate int ses_poll(struct pollfd fds[], nfds_t nfds, int timeout); 2990Sstevel@tonic-gate session_t *curr_ses(void); 3000Sstevel@tonic-gate long curr_ses_id(void); 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate /* 3030Sstevel@tonic-gate * From dcs_msg.c: 3040Sstevel@tonic-gate */ 3050Sstevel@tonic-gate void dcs_log_msg(int priority, int code, ...); 3060Sstevel@tonic-gate char *dcs_cfga_str(char **err_str, int err_code); 3070Sstevel@tonic-gate void dcs_dbg(int level, char *fmt, ...); 3080Sstevel@tonic-gate void print_msg_hdr(dcs_msg_type_t type, rdr_msg_hdr_t *hdr); 3090Sstevel@tonic-gate const char *dcs_strerror(int err_code); 3100Sstevel@tonic-gate 3110Sstevel@tonic-gate 3120Sstevel@tonic-gate /* 3130Sstevel@tonic-gate * If the dcs_debug global variable is not set, no 3140Sstevel@tonic-gate * debugging messages will be logged. 3150Sstevel@tonic-gate */ 3160Sstevel@tonic-gate #define DCS_DBG if (dcs_debug) dcs_dbg 3170Sstevel@tonic-gate #define PRINT_MSG_DBG if (dcs_debug) print_msg_hdr 3180Sstevel@tonic-gate 3190Sstevel@tonic-gate 3200Sstevel@tonic-gate #ifdef __cplusplus 3210Sstevel@tonic-gate } 3220Sstevel@tonic-gate #endif 3230Sstevel@tonic-gate 3240Sstevel@tonic-gate #endif /* _DCS_H */ 325