17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
525cf1a30Sjl  * Common Development and Distribution License (the "License").
625cf1a30Sjl  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
2225cf1a30Sjl  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  * WARNING: The contents of this file are shared by all projects
287c478bd9Sstevel@tonic-gate  * that  wish to  perform  remote  Dynamic Reconfiguration  (DR)
297c478bd9Sstevel@tonic-gate  * operations. Copies of this file can be found in the following
307c478bd9Sstevel@tonic-gate  * locations:
317c478bd9Sstevel@tonic-gate  *
327c478bd9Sstevel@tonic-gate  *	Project	    Location
337c478bd9Sstevel@tonic-gate  *	-------	    --------
347c478bd9Sstevel@tonic-gate  *	Solaris	    usr/src/cmd/dcs/sparc/sun4u/%M%
357c478bd9Sstevel@tonic-gate  *	SMS	    src/sms/lib/librdr/%M%
367c478bd9Sstevel@tonic-gate  *
377c478bd9Sstevel@tonic-gate  * In order for proper communication to occur,  the files in the
387c478bd9Sstevel@tonic-gate  * above locations must match exactly. Any changes that are made
397c478bd9Sstevel@tonic-gate  * to this file should  be made to all of the files in the list.
407c478bd9Sstevel@tonic-gate  */
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate  * This file is a module that contains an interface for performing
447c478bd9Sstevel@tonic-gate  * remote Dynamic Reconfiguration (DR) operations. It hides all
457c478bd9Sstevel@tonic-gate  * network operations such as establishing a connection, sending
467c478bd9Sstevel@tonic-gate  * and receiving messages, and closing a connection. It also handles
477c478bd9Sstevel@tonic-gate  * the packing and unpacking of messages for network transport.
487c478bd9Sstevel@tonic-gate  */
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #include <stdio.h>
517c478bd9Sstevel@tonic-gate #include <stdlib.h>
527c478bd9Sstevel@tonic-gate #include <unistd.h>
537c478bd9Sstevel@tonic-gate #include <string.h>
547c478bd9Sstevel@tonic-gate #include <fcntl.h>
557c478bd9Sstevel@tonic-gate #include <errno.h>
5625cf1a30Sjl #include <dlfcn.h>
577c478bd9Sstevel@tonic-gate #include <netdb.h>
5825cf1a30Sjl #include <libdscp.h>
597c478bd9Sstevel@tonic-gate #include <sys/socket.h>
6025cf1a30Sjl #include <sys/systeminfo.h>
617c478bd9Sstevel@tonic-gate #include <netinet/tcp.h>
627c478bd9Sstevel@tonic-gate 
6325cf1a30Sjl #include "dcs.h"
647c478bd9Sstevel@tonic-gate #include "remote_cfg.h"
657c478bd9Sstevel@tonic-gate #include "rdr_param_types.h"
667c478bd9Sstevel@tonic-gate #include "rdr_messages.h"
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate /*
707c478bd9Sstevel@tonic-gate  * Structure holding information about
717c478bd9Sstevel@tonic-gate  * all possible variable length fields
727c478bd9Sstevel@tonic-gate  * that can be present in an RDR message.
737c478bd9Sstevel@tonic-gate  */
747c478bd9Sstevel@tonic-gate typedef struct {
757c478bd9Sstevel@tonic-gate 	int	ap_id_int_size;
767c478bd9Sstevel@tonic-gate 	int	ap_id_char_size;
777c478bd9Sstevel@tonic-gate 	int	*ap_id_sizes;
787c478bd9Sstevel@tonic-gate 	char	*ap_id_chars;
797c478bd9Sstevel@tonic-gate 	int	errstring_strlen;
807c478bd9Sstevel@tonic-gate 	int	errstring_pad_sz;
817c478bd9Sstevel@tonic-gate 	int	options_strlen;
827c478bd9Sstevel@tonic-gate 	int	options_pad_sz;
837c478bd9Sstevel@tonic-gate 	int	listopts_strlen;
847c478bd9Sstevel@tonic-gate 	int	listopts_pad_sz;
857c478bd9Sstevel@tonic-gate 	int	function_strlen;
867c478bd9Sstevel@tonic-gate 	int	function_pad_sz;
877c478bd9Sstevel@tonic-gate } rdr_variable_message_info_t;
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate /*
907c478bd9Sstevel@tonic-gate  * A table of maximum sizes for each message type. Message size is
917c478bd9Sstevel@tonic-gate  * validated when the message header is first received. This prevents
927c478bd9Sstevel@tonic-gate  * a situation where a corrupted or bad header can cause too much
937c478bd9Sstevel@tonic-gate  * memory to be allocated.
947c478bd9Sstevel@tonic-gate  *
957c478bd9Sstevel@tonic-gate  * The message size limits were chosen to be a very generous upper bound
967c478bd9Sstevel@tonic-gate  * on the amount of data each message can send. They are not intended to
977c478bd9Sstevel@tonic-gate  * be a precise measurement of the data size.
987c478bd9Sstevel@tonic-gate  */
997c478bd9Sstevel@tonic-gate #define	NOMSG		0
1007c478bd9Sstevel@tonic-gate #define	SHORTMSG	(150 * 1024)		/* 150 KB */
1017c478bd9Sstevel@tonic-gate #define	LONGMSG		(3 * 1024 * 1024)	/* 3 MB */
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate struct {
1047c478bd9Sstevel@tonic-gate 	ulong_t	req_max;
1057c478bd9Sstevel@tonic-gate 	ulong_t	reply_max;
1067c478bd9Sstevel@tonic-gate } msg_sizes[] = {
1077c478bd9Sstevel@tonic-gate 	/*
1087c478bd9Sstevel@tonic-gate 	 * request	reply
1097c478bd9Sstevel@tonic-gate 	 * -------	-----
1107c478bd9Sstevel@tonic-gate 	 */
1117c478bd9Sstevel@tonic-gate 	{  NOMSG,	NOMSG	  },	/*  Invalid Opcode		*/
1127c478bd9Sstevel@tonic-gate 	{  SHORTMSG,	SHORTMSG  },	/*  RDR_SES_REQ			*/
1137c478bd9Sstevel@tonic-gate 	{  NOMSG,	NOMSG	  },	/*  RDR_SES_ESTBL		*/
1147c478bd9Sstevel@tonic-gate 	{  NOMSG,	NOMSG	  },	/*  RDR_SES_END			*/
1157c478bd9Sstevel@tonic-gate 	{  SHORTMSG,	SHORTMSG  },	/*  RDR_CONF_CHANGE_STATE	*/
1167c478bd9Sstevel@tonic-gate 	{  SHORTMSG,	SHORTMSG  },	/*  RDR_CONF_PRIVATE_FUNC	*/
1177c478bd9Sstevel@tonic-gate 	{  SHORTMSG,	SHORTMSG  },	/*  RDR_CONF_TEST		*/
1187c478bd9Sstevel@tonic-gate 	{  SHORTMSG,	LONGMSG	  },	/*  RDR_CONF_LIST_EXT		*/
1197c478bd9Sstevel@tonic-gate 	{  SHORTMSG,	NOMSG	  },	/*  RDR_CONF_HELP		*/
1207c478bd9Sstevel@tonic-gate 	{  SHORTMSG,	NOMSG	  },	/*  RDR_CONF_AP_ID_CMP		*/
1217c478bd9Sstevel@tonic-gate 	{  SHORTMSG,	NOMSG	  },	/*  RDR_CONF_ABORT_CMD		*/
122*fd3215f7SToomas Soome 	{  SHORTMSG,	SHORTMSG  },	/*  RDR_CONF_CONFIRM_CALLBACK	*/
1237c478bd9Sstevel@tonic-gate 	{  SHORTMSG,	NOMSG	  },	/*  RDR_CONF_MSG_CALLBACK	*/
1247c478bd9Sstevel@tonic-gate 	{  SHORTMSG,	LONGMSG	  }	/*  RDR_RSRC_INFO		*/
1257c478bd9Sstevel@tonic-gate };
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate #define	RDR_BAD_FD		(-1)
1297c478bd9Sstevel@tonic-gate 
130*fd3215f7SToomas Soome #define	RDR_MSG_HDR_SIZE	sizeof (rdr_msg_hdr_t)
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate static const int RDR_ALIGN_64_BIT = 8;   /* 8 bytes */
1337c478bd9Sstevel@tonic-gate 
13425cf1a30Sjl /*
13525cf1a30Sjl  * Interfaces for dynamic use of libdscp.
13625cf1a30Sjl  */
13725cf1a30Sjl 
13825cf1a30Sjl #define	LIBDSCP_PATH	"/usr/platform/%s/lib/libdscp.so.1"
13925cf1a30Sjl 
14025cf1a30Sjl #define	LIBDSCP_BIND	"dscpBind"
14125cf1a30Sjl #define	LIBDSCP_SECURE	"dscpSecure"
14225cf1a30Sjl #define	LIBDSCP_AUTH	"dscpAuth"
14325cf1a30Sjl 
14425cf1a30Sjl typedef enum {
14525cf1a30Sjl 	LIBDSCP_UNKNOWN = 0,
14625cf1a30Sjl 	LIBDSCP_AVAILABLE,
14725cf1a30Sjl 	LIBDSCP_UNAVAILABLE
14825cf1a30Sjl } dscp_status_t;
14925cf1a30Sjl 
15025cf1a30Sjl typedef struct {
15125cf1a30Sjl 	dscp_status_t	status;
15225cf1a30Sjl 	int		(*bind)(int, int, int);
15325cf1a30Sjl 	int		(*secure)(int, int);
15425cf1a30Sjl 	int		(*auth)(int, struct sockaddr *, int);
15525cf1a30Sjl } libdscp_t;
15625cf1a30Sjl 
15725cf1a30Sjl static libdscp_t libdscp;
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate /*
1607c478bd9Sstevel@tonic-gate  * Static Function Declarations
1617c478bd9Sstevel@tonic-gate  */
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate /*
1647c478bd9Sstevel@tonic-gate  * Socket Related Routines
1657c478bd9Sstevel@tonic-gate  */
1667c478bd9Sstevel@tonic-gate static int rdr_setopt(int fd, int name, int level);
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate static int rdr_bind(int fd, struct sockaddr *addr);
1697c478bd9Sstevel@tonic-gate 
17025cf1a30Sjl static int rdr_secure(int fd, struct sockaddr *addr);
17125cf1a30Sjl 
17225cf1a30Sjl static int rdr_auth(struct sockaddr *addr, int len);
17325cf1a30Sjl 
1747c478bd9Sstevel@tonic-gate static int rdr_snd(int fd, rdr_msg_hdr_t *hdr, char *data, int data_sz,
1757c478bd9Sstevel@tonic-gate 			int timeout);
1767c478bd9Sstevel@tonic-gate static int rdr_snd_raw(int fd, char *msg, int data_sz, int timeout);
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate static int rdr_rcv(int fd, rdr_msg_hdr_t *hdr, char **data, int timeout);
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate static int rdr_rcv_raw(int fd, char *msg, int data_size, int timeout);
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate /*
1837c478bd9Sstevel@tonic-gate  * Data Validation Routines
1847c478bd9Sstevel@tonic-gate  */
1857c478bd9Sstevel@tonic-gate static int validate_header(rdr_msg_hdr_t *hdr);
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate /*
1897c478bd9Sstevel@tonic-gate  * Session Request Routines
1907c478bd9Sstevel@tonic-gate  */
1917c478bd9Sstevel@tonic-gate static int pack_ses_req_request(ses_req_params_t *params, char **buf,
1927c478bd9Sstevel@tonic-gate 			int *buf_size);
1937c478bd9Sstevel@tonic-gate static int unpack_ses_req_request(ses_req_params_t *params, const char *buf);
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate static int pack_ses_req_reply(ses_req_params_t *params, char **buf,
1967c478bd9Sstevel@tonic-gate 			int *buf_size);
1977c478bd9Sstevel@tonic-gate static int unpack_ses_req_reply(ses_req_params_t *params, const char *buf);
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate /*
2017c478bd9Sstevel@tonic-gate  * Change State Routines
2027c478bd9Sstevel@tonic-gate  */
2037c478bd9Sstevel@tonic-gate static int pack_change_state_request(change_state_params_t *params,
2047c478bd9Sstevel@tonic-gate 			char **buf, int *buf_size);
2057c478bd9Sstevel@tonic-gate static int unpack_change_state_request(change_state_params_t *params,
2067c478bd9Sstevel@tonic-gate 			const char *buf);
2077c478bd9Sstevel@tonic-gate static int pack_change_state_reply(change_state_params_t *params,
2087c478bd9Sstevel@tonic-gate 			char **buf, int *buf_size);
2097c478bd9Sstevel@tonic-gate static int unpack_change_state_reply(change_state_params_t *params,
2107c478bd9Sstevel@tonic-gate 			const char *buf);
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate /*
2137c478bd9Sstevel@tonic-gate  * Private Func Routines
2147c478bd9Sstevel@tonic-gate  */
2157c478bd9Sstevel@tonic-gate static int pack_private_func_request(private_func_params_t *params,
2167c478bd9Sstevel@tonic-gate 			char **buf, int *buf_size);
2177c478bd9Sstevel@tonic-gate static int unpack_private_func_request(private_func_params_t *params,
2187c478bd9Sstevel@tonic-gate 			const char *buf);
2197c478bd9Sstevel@tonic-gate static int pack_private_func_reply(private_func_params_t *params,
2207c478bd9Sstevel@tonic-gate 			char **buf, int *buf_size);
2217c478bd9Sstevel@tonic-gate static int unpack_private_func_reply(private_func_params_t *params,
2227c478bd9Sstevel@tonic-gate 			const char *buf);
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate /*
2257c478bd9Sstevel@tonic-gate  * Test Routines
2267c478bd9Sstevel@tonic-gate  */
2277c478bd9Sstevel@tonic-gate static int pack_test_request(test_params_t *params, char **buf, int *buf_size);
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate static int unpack_test_request(test_params_t *params, const char *buf);
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate static int pack_test_reply(test_params_t *params, char **buf, int *buf_size);
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate static int unpack_test_reply(test_params_t *params, const char *buf);
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate /*
2377c478bd9Sstevel@tonic-gate  * List Ext Routines
2387c478bd9Sstevel@tonic-gate  */
2397c478bd9Sstevel@tonic-gate static int pack_list_ext_request(list_ext_params_t *params, char **buf,
2407c478bd9Sstevel@tonic-gate 			int *buf_size);
2417c478bd9Sstevel@tonic-gate static int unpack_list_ext_request(list_ext_params_t *params, const char *buf);
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate static int pack_list_ext_reply(list_ext_params_t *params, char **buf,
2447c478bd9Sstevel@tonic-gate 			int *buf_size);
2457c478bd9Sstevel@tonic-gate static int unpack_list_ext_reply(list_ext_params_t *params, const char *buf);
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate /*
2497c478bd9Sstevel@tonic-gate  * Help Routines
2507c478bd9Sstevel@tonic-gate  */
2517c478bd9Sstevel@tonic-gate static int pack_help_request(help_params_t *params, char **buf, int *buf_size);
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate static int unpack_help_request(help_params_t *params, const char *buf);
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate 
2567c478bd9Sstevel@tonic-gate /*
2577c478bd9Sstevel@tonic-gate  * Ap Id Cmp Routines
2587c478bd9Sstevel@tonic-gate  */
2597c478bd9Sstevel@tonic-gate static int pack_ap_id_cmp_request(ap_id_cmp_params_t *params, char **buf,
2607c478bd9Sstevel@tonic-gate 			int *buf_size);
2617c478bd9Sstevel@tonic-gate static int unpack_ap_id_cmp_request(ap_id_cmp_params_t *params,
2627c478bd9Sstevel@tonic-gate 			const char *buf);
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate /*
2657c478bd9Sstevel@tonic-gate  * Abort Routines
2667c478bd9Sstevel@tonic-gate  */
2677c478bd9Sstevel@tonic-gate static int pack_abort_cmd_request(abort_cmd_params_t *params, char **buf,
2687c478bd9Sstevel@tonic-gate 			int *buf_size);
2697c478bd9Sstevel@tonic-gate static int unpack_abort_cmd_request(abort_cmd_params_t *params,
2707c478bd9Sstevel@tonic-gate 			const char *buf);
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate /*
2737c478bd9Sstevel@tonic-gate  * Confirm Callback Routines
2747c478bd9Sstevel@tonic-gate  */
2757c478bd9Sstevel@tonic-gate static int pack_confirm_request(confirm_callback_params_t *params, char **buf,
2767c478bd9Sstevel@tonic-gate 			int *buf_size);
2777c478bd9Sstevel@tonic-gate static int unpack_confirm_request(confirm_callback_params_t *params,
2787c478bd9Sstevel@tonic-gate 			const char *buf);
2797c478bd9Sstevel@tonic-gate static int pack_confirm_reply(confirm_callback_params_t *params,
2807c478bd9Sstevel@tonic-gate 			char **buf, int *buf_size);
2817c478bd9Sstevel@tonic-gate static int unpack_confirm_reply(confirm_callback_params_t *params,
2827c478bd9Sstevel@tonic-gate 			const char *buf);
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate /*
2857c478bd9Sstevel@tonic-gate  * Message Callback Routines
2867c478bd9Sstevel@tonic-gate  */
2877c478bd9Sstevel@tonic-gate static int pack_message_request(msg_callback_params_t *params, char **buf,
2887c478bd9Sstevel@tonic-gate 			int *buf_size);
2897c478bd9Sstevel@tonic-gate static int unpack_message_request(msg_callback_params_t *params,
2907c478bd9Sstevel@tonic-gate 			const char *buf);
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate /*
2937c478bd9Sstevel@tonic-gate  * Resource Info Routines
2947c478bd9Sstevel@tonic-gate  */
2957c478bd9Sstevel@tonic-gate static int pack_rsrc_info_request(rsrc_info_params_t *params, char **buf,
2967c478bd9Sstevel@tonic-gate 			int *buf_size);
2977c478bd9Sstevel@tonic-gate static int unpack_rsrc_info_request(rsrc_info_params_t *params,
2987c478bd9Sstevel@tonic-gate 			const char *buf);
2997c478bd9Sstevel@tonic-gate static int pack_rsrc_info_reply(rsrc_info_params_t *params, char **buf,
30025cf1a30Sjl 			int *buf_size, int encoding);
3017c478bd9Sstevel@tonic-gate static int unpack_rsrc_info_reply(rsrc_info_params_t *params, const char *buf);
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate /*
3047c478bd9Sstevel@tonic-gate  * General Pack/Unpack Routines
3057c478bd9Sstevel@tonic-gate  */
3067c478bd9Sstevel@tonic-gate static int pack_ap_ids(int num_ap_ids, char *const *ap_ids,
3077c478bd9Sstevel@tonic-gate 			rdr_variable_message_info_t *var_msg_info);
3087c478bd9Sstevel@tonic-gate static int unpack_ap_ids(int num_ap_ids, char **ap_ids, const char *buf,
3097c478bd9Sstevel@tonic-gate 			rdr_variable_message_info_t *var_msg_info);
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate /*
3127c478bd9Sstevel@tonic-gate  * Find Variable Info Sizes
3137c478bd9Sstevel@tonic-gate  */
3147c478bd9Sstevel@tonic-gate static int find_options_sizes(char *options,
3157c478bd9Sstevel@tonic-gate 			rdr_variable_message_info_t *var_msg_info);
3167c478bd9Sstevel@tonic-gate static int find_listopts_sizes(char *listopts,
3177c478bd9Sstevel@tonic-gate 			rdr_variable_message_info_t *var_msg_info);
3187c478bd9Sstevel@tonic-gate static int find_function_sizes(char *function,
3197c478bd9Sstevel@tonic-gate 			rdr_variable_message_info_t *var_msg_info);
3207c478bd9Sstevel@tonic-gate static int find_errstring_sizes(char **errstring,
3217c478bd9Sstevel@tonic-gate 			rdr_variable_message_info_t *var_msg_info);
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate /*
3247c478bd9Sstevel@tonic-gate  * Extract Info From Buffers
3257c478bd9Sstevel@tonic-gate  */
3267c478bd9Sstevel@tonic-gate static int get_ap_ids_from_buf(char ***ap_id_ptr, int num_ap_ids,
3277c478bd9Sstevel@tonic-gate 			rdr_variable_message_info_t *var_msg_info,
3287c478bd9Sstevel@tonic-gate 			const char *buf);
3297c478bd9Sstevel@tonic-gate static int get_string_from_buf(char **stringptr, int strsize, const char *buf);
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate /*
3337c478bd9Sstevel@tonic-gate  * Cleanup Routines
3347c478bd9Sstevel@tonic-gate  */
3357c478bd9Sstevel@tonic-gate static int cleanup_ap_ids(int num_ap_ids, char **ap_ids);
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate static int cleanup_errstring(char **errstring);
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate static void cleanup_variable_ap_id_info(
3407c478bd9Sstevel@tonic-gate 			rdr_variable_message_info_t *var_msg_info);
3417c478bd9Sstevel@tonic-gate 
34225cf1a30Sjl /*
34325cf1a30Sjl  * Functions for loading libdscp.
34425cf1a30Sjl  */
34525cf1a30Sjl static int load_libdscp(libdscp_t *libdscp);
34625cf1a30Sjl 
3477c478bd9Sstevel@tonic-gate /*
3487c478bd9Sstevel@tonic-gate  * Public Functions
3497c478bd9Sstevel@tonic-gate  */
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate /*
3537c478bd9Sstevel@tonic-gate  * rdr_open:
3547c478bd9Sstevel@tonic-gate  *
3557c478bd9Sstevel@tonic-gate  * Establish a transport endpoint to prepare for a new
3567c478bd9Sstevel@tonic-gate  * connection. Returns a file descriptor representing the
3577c478bd9Sstevel@tonic-gate  * new transport if successful or RDR_BAD_FD upon failure.
3587c478bd9Sstevel@tonic-gate  */
3597c478bd9Sstevel@tonic-gate int
rdr_open(int family)3607c478bd9Sstevel@tonic-gate rdr_open(int family)
3617c478bd9Sstevel@tonic-gate {
3627c478bd9Sstevel@tonic-gate 	int	newfd;
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate 
365*fd3215f7SToomas Soome 	if ((newfd = socket(family, SOCK_STREAM, 0)) == -1) {
3667c478bd9Sstevel@tonic-gate 		return (RDR_BAD_FD);
3677c478bd9Sstevel@tonic-gate 	}
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate 	return (newfd);
3707c478bd9Sstevel@tonic-gate }
3717c478bd9Sstevel@tonic-gate 
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate /*
3747c478bd9Sstevel@tonic-gate  * rdr_init:
3757c478bd9Sstevel@tonic-gate  *
3767c478bd9Sstevel@tonic-gate  * Initialize a transport endpoint. This involves binding to
3777c478bd9Sstevel@tonic-gate  * a particular port and setting any user specified socket
3787c478bd9Sstevel@tonic-gate  * options.
3797c478bd9Sstevel@tonic-gate  */
3807c478bd9Sstevel@tonic-gate int
rdr_init(int fd,struct sockaddr * addr,int * opts,int num_opts,int blog)3817c478bd9Sstevel@tonic-gate rdr_init(int fd, struct sockaddr *addr, int *opts, int num_opts, int blog)
3827c478bd9Sstevel@tonic-gate {
3837c478bd9Sstevel@tonic-gate 	int	i;
3847c478bd9Sstevel@tonic-gate 
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate 	/* sanity checks */
3877c478bd9Sstevel@tonic-gate 	if ((fd < 0) || (addr == NULL)) {
3887c478bd9Sstevel@tonic-gate 		return (RDR_ERROR);
3897c478bd9Sstevel@tonic-gate 	}
3907c478bd9Sstevel@tonic-gate 
3917c478bd9Sstevel@tonic-gate 	if ((opts == NULL) || (num_opts < 0)) {
3927c478bd9Sstevel@tonic-gate 		num_opts = 0;
3937c478bd9Sstevel@tonic-gate 	}
3947c478bd9Sstevel@tonic-gate 
39525cf1a30Sjl 	/* turn on security features */
39625cf1a30Sjl 	if (rdr_secure(fd, addr) != RDR_OK) {
39725cf1a30Sjl 		return (RDR_NET_ERR);
39825cf1a30Sjl 	}
39925cf1a30Sjl 
4007c478bd9Sstevel@tonic-gate 	/* bind the address, if is not already bound */
4017c478bd9Sstevel@tonic-gate 	if (rdr_bind(fd, addr) != RDR_OK) {
4027c478bd9Sstevel@tonic-gate 		return (RDR_NET_ERR);
4037c478bd9Sstevel@tonic-gate 	}
4047c478bd9Sstevel@tonic-gate 
4057c478bd9Sstevel@tonic-gate 	/*
4067c478bd9Sstevel@tonic-gate 	 * Set TCP_NODELAY for this endpoint. This disables Nagle's
4077c478bd9Sstevel@tonic-gate 	 * algorithm that can cause a delay in sending small sized
4087c478bd9Sstevel@tonic-gate 	 * messages. Since most of the RDR messages are small, this
4097c478bd9Sstevel@tonic-gate 	 * is a restriction that negatively impacts performance.
4107c478bd9Sstevel@tonic-gate 	 */
4117c478bd9Sstevel@tonic-gate 	if (rdr_setopt(fd, TCP_NODELAY, IPPROTO_TCP) != RDR_OK) {
4127c478bd9Sstevel@tonic-gate 		return (RDR_NET_ERR);
4137c478bd9Sstevel@tonic-gate 	}
4147c478bd9Sstevel@tonic-gate 
4157c478bd9Sstevel@tonic-gate 	/* set the user specified socket options */
4167c478bd9Sstevel@tonic-gate 	for (i = 0; i < num_opts; i++) {
4177c478bd9Sstevel@tonic-gate 		if (rdr_setopt(fd, opts[i], SOL_SOCKET) != RDR_OK) {
4187c478bd9Sstevel@tonic-gate 			return (RDR_NET_ERR);
4197c478bd9Sstevel@tonic-gate 		}
4207c478bd9Sstevel@tonic-gate 	}
4217c478bd9Sstevel@tonic-gate 
4227c478bd9Sstevel@tonic-gate 	/*
4237c478bd9Sstevel@tonic-gate 	 * If blog is not zero, it is a server that is being
4247c478bd9Sstevel@tonic-gate 	 * initialized. In order for it to be able to accept
4257c478bd9Sstevel@tonic-gate 	 * connections, we have to set the size of the incoming
4267c478bd9Sstevel@tonic-gate 	 * connection queue.
4277c478bd9Sstevel@tonic-gate 	 */
4287c478bd9Sstevel@tonic-gate 	if (blog != 0) {
4297c478bd9Sstevel@tonic-gate 		if (listen(fd, blog) == -1) {
4307c478bd9Sstevel@tonic-gate 			return (RDR_NET_ERR);
4317c478bd9Sstevel@tonic-gate 		}
4327c478bd9Sstevel@tonic-gate 	}
4337c478bd9Sstevel@tonic-gate 
4347c478bd9Sstevel@tonic-gate 	return (RDR_OK);
4357c478bd9Sstevel@tonic-gate }
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate 
4387c478bd9Sstevel@tonic-gate /*
4397c478bd9Sstevel@tonic-gate  * rdr_connect_clnt:
4407c478bd9Sstevel@tonic-gate  *
4417c478bd9Sstevel@tonic-gate  * Perform the necessary steps for a client to connect to
4427c478bd9Sstevel@tonic-gate  * a server process. The required information is the file
4437c478bd9Sstevel@tonic-gate  * descriptor for the transport endpoint, and the remote
4447c478bd9Sstevel@tonic-gate  * address.
4457c478bd9Sstevel@tonic-gate  */
4467c478bd9Sstevel@tonic-gate int
rdr_connect_clnt(int fd,struct sockaddr * addr)4477c478bd9Sstevel@tonic-gate rdr_connect_clnt(int fd, struct sockaddr *addr)
4487c478bd9Sstevel@tonic-gate {
4497c478bd9Sstevel@tonic-gate 	unsigned int	addr_len;
4507c478bd9Sstevel@tonic-gate 
4517c478bd9Sstevel@tonic-gate 
4527c478bd9Sstevel@tonic-gate 	/* sanity check */
4537c478bd9Sstevel@tonic-gate 	if (addr == NULL) {
4547c478bd9Sstevel@tonic-gate 		return (RDR_ERROR);
4557c478bd9Sstevel@tonic-gate 	}
4567c478bd9Sstevel@tonic-gate 
4577c478bd9Sstevel@tonic-gate 	/* initialize the address length */
4587c478bd9Sstevel@tonic-gate 	switch (addr->sa_family) {
4597c478bd9Sstevel@tonic-gate 
4607c478bd9Sstevel@tonic-gate 	case AF_INET:
4617c478bd9Sstevel@tonic-gate 		addr_len = sizeof (struct sockaddr_in);
4627c478bd9Sstevel@tonic-gate 		break;
4637c478bd9Sstevel@tonic-gate 
4647c478bd9Sstevel@tonic-gate 	case AF_INET6:
4657c478bd9Sstevel@tonic-gate 		addr_len = sizeof (struct sockaddr_in6);
4667c478bd9Sstevel@tonic-gate 		break;
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate 	default:
4697c478bd9Sstevel@tonic-gate 		return (RDR_ERROR);
4707c478bd9Sstevel@tonic-gate 	}
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate 	/* attempt the connection */
4737c478bd9Sstevel@tonic-gate 	if (connect(fd, addr, addr_len) == -1) {
4747c478bd9Sstevel@tonic-gate 		return (RDR_NET_ERR);
4757c478bd9Sstevel@tonic-gate 	}
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate 	return (RDR_OK);
4787c478bd9Sstevel@tonic-gate }
4797c478bd9Sstevel@tonic-gate 
4807c478bd9Sstevel@tonic-gate 
4817c478bd9Sstevel@tonic-gate /*
4827c478bd9Sstevel@tonic-gate  * rdr_connect_srv:
4837c478bd9Sstevel@tonic-gate  *
4847c478bd9Sstevel@tonic-gate  * Perform the necessary steps for a server to connect to a
4857c478bd9Sstevel@tonic-gate  * pending client request. The new connection is allocated a
4867c478bd9Sstevel@tonic-gate  * new file descriptor, separate from the one used to accept
4877c478bd9Sstevel@tonic-gate  * the connection.
4887c478bd9Sstevel@tonic-gate  */
4897c478bd9Sstevel@tonic-gate int
rdr_connect_srv(int fd)4907c478bd9Sstevel@tonic-gate rdr_connect_srv(int fd)
4917c478bd9Sstevel@tonic-gate {
4927c478bd9Sstevel@tonic-gate 	int			newfd;
4937c478bd9Sstevel@tonic-gate 	unsigned int		faddr_len;
4947c478bd9Sstevel@tonic-gate 	struct sockaddr_storage	faddr;
4957c478bd9Sstevel@tonic-gate 
4967c478bd9Sstevel@tonic-gate 
49725cf1a30Sjl 	/* accept the connection */
4987c478bd9Sstevel@tonic-gate 	faddr_len = sizeof (faddr);
4997c478bd9Sstevel@tonic-gate 	if ((newfd = accept(fd, (struct sockaddr *)&faddr, &faddr_len)) == -1) {
5007c478bd9Sstevel@tonic-gate 		return (RDR_BAD_FD);
5017c478bd9Sstevel@tonic-gate 	}
5027c478bd9Sstevel@tonic-gate 
50325cf1a30Sjl 	/* if the peer doesn't authenticate properly, reject */
50425cf1a30Sjl 	if (rdr_auth((struct sockaddr *)&faddr, faddr_len) != RDR_OK) {
50525cf1a30Sjl 		(void) close(newfd);
50625cf1a30Sjl 		return (RDR_BAD_FD);
50725cf1a30Sjl 	}
50825cf1a30Sjl 
5097c478bd9Sstevel@tonic-gate 	return (newfd);
5107c478bd9Sstevel@tonic-gate }
5117c478bd9Sstevel@tonic-gate 
5127c478bd9Sstevel@tonic-gate 
5137c478bd9Sstevel@tonic-gate /*
5147c478bd9Sstevel@tonic-gate  * rdr_reject:
5157c478bd9Sstevel@tonic-gate  *
5167c478bd9Sstevel@tonic-gate  * Reject an incoming connection attempt. This requires
5177c478bd9Sstevel@tonic-gate  * that the connection be accepted first.
5187c478bd9Sstevel@tonic-gate  */
5197c478bd9Sstevel@tonic-gate int
rdr_reject(int fd)5207c478bd9Sstevel@tonic-gate rdr_reject(int fd)
5217c478bd9Sstevel@tonic-gate {
5227c478bd9Sstevel@tonic-gate 	unsigned int		faddr_len;
5237c478bd9Sstevel@tonic-gate 	struct sockaddr_storage	faddr;
5247c478bd9Sstevel@tonic-gate 
5257c478bd9Sstevel@tonic-gate 
5267c478bd9Sstevel@tonic-gate 	/* first accept the connection */
5277c478bd9Sstevel@tonic-gate 	faddr_len = sizeof (faddr);
5287c478bd9Sstevel@tonic-gate 	if (accept(fd, (struct sockaddr *)&faddr, &faddr_len) == -1) {
5297c478bd9Sstevel@tonic-gate 		return (RDR_NET_ERR);
5307c478bd9Sstevel@tonic-gate 	}
5317c478bd9Sstevel@tonic-gate 
5327c478bd9Sstevel@tonic-gate 	/* then close it */
53325cf1a30Sjl 	(void) close(fd);
5347c478bd9Sstevel@tonic-gate 
5357c478bd9Sstevel@tonic-gate 	return (RDR_OK);
5367c478bd9Sstevel@tonic-gate }
5377c478bd9Sstevel@tonic-gate 
5387c478bd9Sstevel@tonic-gate 
5397c478bd9Sstevel@tonic-gate /*
5407c478bd9Sstevel@tonic-gate  * rdr_close:
5417c478bd9Sstevel@tonic-gate  *
5427c478bd9Sstevel@tonic-gate  * Close down an given connection.
5437c478bd9Sstevel@tonic-gate  */
5447c478bd9Sstevel@tonic-gate int
rdr_close(int fd)5457c478bd9Sstevel@tonic-gate rdr_close(int fd)
5467c478bd9Sstevel@tonic-gate {
54725cf1a30Sjl 	(void) close(fd);
5487c478bd9Sstevel@tonic-gate 
5497c478bd9Sstevel@tonic-gate 	return (RDR_OK);
5507c478bd9Sstevel@tonic-gate }
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate 
5537c478bd9Sstevel@tonic-gate /*
5547c478bd9Sstevel@tonic-gate  * rdr_snd_msg:
5557c478bd9Sstevel@tonic-gate  *
5567c478bd9Sstevel@tonic-gate  * Public interface for sending an RDR message. The data
5577c478bd9Sstevel@tonic-gate  * passed in through hdr and param are packed for network
5587c478bd9Sstevel@tonic-gate  * transport and sent.
5597c478bd9Sstevel@tonic-gate  */
5607c478bd9Sstevel@tonic-gate int
rdr_snd_msg(int fd,rdr_msg_hdr_t * hdr,cfga_params_t * param,int timeout)5617c478bd9Sstevel@tonic-gate rdr_snd_msg(int fd, rdr_msg_hdr_t *hdr, cfga_params_t *param, int timeout)
5627c478bd9Sstevel@tonic-gate {
5637c478bd9Sstevel@tonic-gate 	int	err;
5647c478bd9Sstevel@tonic-gate 	char	*pack_buf = NULL;
5657c478bd9Sstevel@tonic-gate 	int	pack_buf_sz = 0;
5667c478bd9Sstevel@tonic-gate 
5677c478bd9Sstevel@tonic-gate 
5687c478bd9Sstevel@tonic-gate 	/* sanity checks */
5697c478bd9Sstevel@tonic-gate 	if ((hdr == NULL) || (param == NULL)) {
5707c478bd9Sstevel@tonic-gate 		return (RDR_ERROR);
5717c478bd9Sstevel@tonic-gate 	}
5727c478bd9Sstevel@tonic-gate 
5737c478bd9Sstevel@tonic-gate 	/*
5747c478bd9Sstevel@tonic-gate 	 * Pack the message for transport
5757c478bd9Sstevel@tonic-gate 	 */
5767c478bd9Sstevel@tonic-gate 	switch (hdr->message_opcode) {
5777c478bd9Sstevel@tonic-gate 
5787c478bd9Sstevel@tonic-gate 		case RDR_SES_REQ: {
5797c478bd9Sstevel@tonic-gate 
5807c478bd9Sstevel@tonic-gate 			ses_req_params_t *rparam;
5817c478bd9Sstevel@tonic-gate 			rparam = (ses_req_params_t *)param;
5827c478bd9Sstevel@tonic-gate 
5837c478bd9Sstevel@tonic-gate 			if (hdr->data_type == RDR_REQUEST) {
5847c478bd9Sstevel@tonic-gate 				err = pack_ses_req_request(rparam,
5857c478bd9Sstevel@tonic-gate 				    &pack_buf, &pack_buf_sz);
5867c478bd9Sstevel@tonic-gate 			} else {
5877c478bd9Sstevel@tonic-gate 				err = pack_ses_req_reply(rparam,
5887c478bd9Sstevel@tonic-gate 				    &pack_buf, &pack_buf_sz);
5897c478bd9Sstevel@tonic-gate 			}
5907c478bd9Sstevel@tonic-gate 
5917c478bd9Sstevel@tonic-gate 			break;
5927c478bd9Sstevel@tonic-gate 		}
5937c478bd9Sstevel@tonic-gate 
5947c478bd9Sstevel@tonic-gate 		case RDR_SES_ESTBL:
5957c478bd9Sstevel@tonic-gate 		case RDR_SES_END:
5967c478bd9Sstevel@tonic-gate 
5977c478bd9Sstevel@tonic-gate 			/*
5987c478bd9Sstevel@tonic-gate 			 * This is not an error condition because
5997c478bd9Sstevel@tonic-gate 			 * there is no extra information to pack.
6007c478bd9Sstevel@tonic-gate 			 */
6017c478bd9Sstevel@tonic-gate 			err = RDR_OK;
6027c478bd9Sstevel@tonic-gate 			break;
6037c478bd9Sstevel@tonic-gate 
6047c478bd9Sstevel@tonic-gate 		case RDR_CONF_CHANGE_STATE: {
6057c478bd9Sstevel@tonic-gate 
6067c478bd9Sstevel@tonic-gate 			change_state_params_t *cparam;
6077c478bd9Sstevel@tonic-gate 			cparam = (change_state_params_t *)param;
6087c478bd9Sstevel@tonic-gate 
6097c478bd9Sstevel@tonic-gate 			if (hdr->data_type == RDR_REQUEST) {
6107c478bd9Sstevel@tonic-gate 				err = pack_change_state_request(cparam,
6117c478bd9Sstevel@tonic-gate 				    &pack_buf, &pack_buf_sz);
6127c478bd9Sstevel@tonic-gate 			} else {
6137c478bd9Sstevel@tonic-gate 				err = pack_change_state_reply(cparam,
6147c478bd9Sstevel@tonic-gate 				    &pack_buf, &pack_buf_sz);
6157c478bd9Sstevel@tonic-gate 			}
6167c478bd9Sstevel@tonic-gate 			break;
6177c478bd9Sstevel@tonic-gate 		}
6187c478bd9Sstevel@tonic-gate 
6197c478bd9Sstevel@tonic-gate 		case RDR_CONF_PRIVATE_FUNC: {
6207c478bd9Sstevel@tonic-gate 
6217c478bd9Sstevel@tonic-gate 			private_func_params_t *pparam;
6227c478bd9Sstevel@tonic-gate 			pparam = (private_func_params_t *)param;
6237c478bd9Sstevel@tonic-gate 
6247c478bd9Sstevel@tonic-gate 			if (hdr->data_type == RDR_REQUEST) {
6257c478bd9Sstevel@tonic-gate 				err = pack_private_func_request(pparam,
6267c478bd9Sstevel@tonic-gate 				    &pack_buf, &pack_buf_sz);
6277c478bd9Sstevel@tonic-gate 			} else {
6287c478bd9Sstevel@tonic-gate 				err = pack_private_func_reply(pparam,
6297c478bd9Sstevel@tonic-gate 				    &pack_buf, &pack_buf_sz);
6307c478bd9Sstevel@tonic-gate 			}
6317c478bd9Sstevel@tonic-gate 			break;
6327c478bd9Sstevel@tonic-gate 		}
6337c478bd9Sstevel@tonic-gate 
6347c478bd9Sstevel@tonic-gate 		case RDR_CONF_TEST: {
6357c478bd9Sstevel@tonic-gate 
6367c478bd9Sstevel@tonic-gate 			test_params_t *tparam;
6377c478bd9Sstevel@tonic-gate 			tparam = (test_params_t *)param;
6387c478bd9Sstevel@tonic-gate 
6397c478bd9Sstevel@tonic-gate 			if (hdr->data_type == RDR_REQUEST) {
6407c478bd9Sstevel@tonic-gate 				err = pack_test_request(tparam,
6417c478bd9Sstevel@tonic-gate 				    &pack_buf, &pack_buf_sz);
6427c478bd9Sstevel@tonic-gate 			} else {
6437c478bd9Sstevel@tonic-gate 				err = pack_test_reply(tparam,
6447c478bd9Sstevel@tonic-gate 				    &pack_buf, &pack_buf_sz);
6457c478bd9Sstevel@tonic-gate 			}
6467c478bd9Sstevel@tonic-gate 			break;
6477c478bd9Sstevel@tonic-gate 		}
6487c478bd9Sstevel@tonic-gate 
6497c478bd9Sstevel@tonic-gate 		case RDR_CONF_LIST_EXT: {
6507c478bd9Sstevel@tonic-gate 
6517c478bd9Sstevel@tonic-gate 			list_ext_params_t *lparam;
6527c478bd9Sstevel@tonic-gate 			lparam = (list_ext_params_t *)param;
6537c478bd9Sstevel@tonic-gate 
6547c478bd9Sstevel@tonic-gate 			if (hdr->data_type == RDR_REQUEST) {
6557c478bd9Sstevel@tonic-gate 				err = pack_list_ext_request(lparam, &pack_buf,
6567c478bd9Sstevel@tonic-gate 				    &pack_buf_sz);
6577c478bd9Sstevel@tonic-gate 			} else {
6587c478bd9Sstevel@tonic-gate 				err = pack_list_ext_reply(lparam, &pack_buf,
6597c478bd9Sstevel@tonic-gate 				    &pack_buf_sz);
6607c478bd9Sstevel@tonic-gate 			}
6617c478bd9Sstevel@tonic-gate 			break;
6627c478bd9Sstevel@tonic-gate 		}
6637c478bd9Sstevel@tonic-gate 
6647c478bd9Sstevel@tonic-gate 		case RDR_CONF_HELP: {
6657c478bd9Sstevel@tonic-gate 
6667c478bd9Sstevel@tonic-gate 			help_params_t *hparam;
6677c478bd9Sstevel@tonic-gate 			hparam = (help_params_t *)param;
6687c478bd9Sstevel@tonic-gate 
6697c478bd9Sstevel@tonic-gate 			if (hdr->data_type == RDR_REQUEST) {
6707c478bd9Sstevel@tonic-gate 				err = pack_help_request(hparam,
6717c478bd9Sstevel@tonic-gate 				    &pack_buf, &pack_buf_sz);
6727c478bd9Sstevel@tonic-gate 			} else {
6737c478bd9Sstevel@tonic-gate 
6747c478bd9Sstevel@tonic-gate 				/*
6757c478bd9Sstevel@tonic-gate 				 * This is not an error because help
6767c478bd9Sstevel@tonic-gate 				 * reply does not have any extra information
6777c478bd9Sstevel@tonic-gate 				 * to pack.
6787c478bd9Sstevel@tonic-gate 				 */
6797c478bd9Sstevel@tonic-gate 				err = RDR_OK;
6807c478bd9Sstevel@tonic-gate 			}
6817c478bd9Sstevel@tonic-gate 			break;
6827c478bd9Sstevel@tonic-gate 		}
6837c478bd9Sstevel@tonic-gate 
6847c478bd9Sstevel@tonic-gate 		case RDR_CONF_AP_ID_CMP: {
6857c478bd9Sstevel@tonic-gate 
6867c478bd9Sstevel@tonic-gate 			ap_id_cmp_params_t *aparam;
6877c478bd9Sstevel@tonic-gate 			aparam = (ap_id_cmp_params_t *)param;
6887c478bd9Sstevel@tonic-gate 
6897c478bd9Sstevel@tonic-gate 			if (hdr->data_type == RDR_REQUEST) {
6907c478bd9Sstevel@tonic-gate 				err = pack_ap_id_cmp_request(aparam,
6917c478bd9Sstevel@tonic-gate 				    &pack_buf, &pack_buf_sz);
6927c478bd9Sstevel@tonic-gate 			} else {
6937c478bd9Sstevel@tonic-gate 
6947c478bd9Sstevel@tonic-gate 				/*
6957c478bd9Sstevel@tonic-gate 				 * This is not an error because ap_id_cmp
6967c478bd9Sstevel@tonic-gate 				 * reply does not have any extra information
6977c478bd9Sstevel@tonic-gate 				 * to pack.
6987c478bd9Sstevel@tonic-gate 				 */
6997c478bd9Sstevel@tonic-gate 				err = RDR_OK;
7007c478bd9Sstevel@tonic-gate 			}
7017c478bd9Sstevel@tonic-gate 			break;
7027c478bd9Sstevel@tonic-gate 		}
7037c478bd9Sstevel@tonic-gate 
7047c478bd9Sstevel@tonic-gate 		case RDR_CONF_ABORT_CMD: {
7057c478bd9Sstevel@tonic-gate 
7067c478bd9Sstevel@tonic-gate 			abort_cmd_params_t *aparam;
7077c478bd9Sstevel@tonic-gate 			aparam = (abort_cmd_params_t *)param;
7087c478bd9Sstevel@tonic-gate 
7097c478bd9Sstevel@tonic-gate 			if (hdr->data_type == RDR_REQUEST) {
7107c478bd9Sstevel@tonic-gate 				err = pack_abort_cmd_request(aparam,
7117c478bd9Sstevel@tonic-gate 				    &pack_buf, &pack_buf_sz);
7127c478bd9Sstevel@tonic-gate 			} else {
7137c478bd9Sstevel@tonic-gate 				/*
7147c478bd9Sstevel@tonic-gate 				 * This is not an error because session
7157c478bd9Sstevel@tonic-gate 				 * abort reply does not have any extra
7167c478bd9Sstevel@tonic-gate 				 * information to pack.
7177c478bd9Sstevel@tonic-gate 				 */
7187c478bd9Sstevel@tonic-gate 				err = RDR_OK;
7197c478bd9Sstevel@tonic-gate 			}
7207c478bd9Sstevel@tonic-gate 			break;
7217c478bd9Sstevel@tonic-gate 		}
7227c478bd9Sstevel@tonic-gate 
7237c478bd9Sstevel@tonic-gate 		case RDR_CONF_CONFIRM_CALLBACK: {
7247c478bd9Sstevel@tonic-gate 
7257c478bd9Sstevel@tonic-gate 			confirm_callback_params_t *cparam;
7267c478bd9Sstevel@tonic-gate 			cparam = (confirm_callback_params_t *)param;
7277c478bd9Sstevel@tonic-gate 
7287c478bd9Sstevel@tonic-gate 			if (hdr->data_type == RDR_REQUEST) {
7297c478bd9Sstevel@tonic-gate 				err = pack_confirm_request(cparam,
7307c478bd9Sstevel@tonic-gate 				    &pack_buf, &pack_buf_sz);
7317c478bd9Sstevel@tonic-gate 			} else {
7327c478bd9Sstevel@tonic-gate 				err = pack_confirm_reply(cparam, &pack_buf,
7337c478bd9Sstevel@tonic-gate 				    &pack_buf_sz);
7347c478bd9Sstevel@tonic-gate 			}
7357c478bd9Sstevel@tonic-gate 			break;
7367c478bd9Sstevel@tonic-gate 		}
7377c478bd9Sstevel@tonic-gate 
7387c478bd9Sstevel@tonic-gate 		case RDR_CONF_MSG_CALLBACK: {
7397c478bd9Sstevel@tonic-gate 
7407c478bd9Sstevel@tonic-gate 			msg_callback_params_t *mparam;
7417c478bd9Sstevel@tonic-gate 			mparam = (msg_callback_params_t *)param;
7427c478bd9Sstevel@tonic-gate 
7437c478bd9Sstevel@tonic-gate 			if (hdr->data_type == RDR_REQUEST) {
7447c478bd9Sstevel@tonic-gate 				err = pack_message_request(mparam,
7457c478bd9Sstevel@tonic-gate 				    &pack_buf, &pack_buf_sz);
7467c478bd9Sstevel@tonic-gate 			} else {
7477c478bd9Sstevel@tonic-gate 				/*
7487c478bd9Sstevel@tonic-gate 				 * It is an error to send a reply
7497c478bd9Sstevel@tonic-gate 				 * to a message callback.
7507c478bd9Sstevel@tonic-gate 				 */
7517c478bd9Sstevel@tonic-gate 				err = RDR_MSG_INVAL;
7527c478bd9Sstevel@tonic-gate 			}
7537c478bd9Sstevel@tonic-gate 			break;
7547c478bd9Sstevel@tonic-gate 		}
7557c478bd9Sstevel@tonic-gate 
7567c478bd9Sstevel@tonic-gate 		case RDR_RSRC_INFO: {
7577c478bd9Sstevel@tonic-gate 
7587c478bd9Sstevel@tonic-gate 			rsrc_info_params_t *rparam;
7597c478bd9Sstevel@tonic-gate 			rparam = (rsrc_info_params_t *)param;
7607c478bd9Sstevel@tonic-gate 
7617c478bd9Sstevel@tonic-gate 			if (hdr->data_type == RDR_REQUEST) {
7627c478bd9Sstevel@tonic-gate 				err = pack_rsrc_info_request(rparam, &pack_buf,
7637c478bd9Sstevel@tonic-gate 				    &pack_buf_sz);
7647c478bd9Sstevel@tonic-gate 			} else {
76525cf1a30Sjl 				if ((hdr->major_version == 1) &&
76625cf1a30Sjl 				    (hdr->minor_version == 0)) {
76725cf1a30Sjl 					err = pack_rsrc_info_reply(rparam,
76825cf1a30Sjl 					    &pack_buf, &pack_buf_sz,
76925cf1a30Sjl 					    NV_ENCODE_NATIVE);
77025cf1a30Sjl 				} else {
77125cf1a30Sjl 					err = pack_rsrc_info_reply(rparam,
77225cf1a30Sjl 					    &pack_buf, &pack_buf_sz,
77325cf1a30Sjl 					    NV_ENCODE_XDR);
77425cf1a30Sjl 				}
7757c478bd9Sstevel@tonic-gate 			}
7767c478bd9Sstevel@tonic-gate 			break;
7777c478bd9Sstevel@tonic-gate 		}
7787c478bd9Sstevel@tonic-gate 
7797c478bd9Sstevel@tonic-gate 		default:
7807c478bd9Sstevel@tonic-gate 			err = RDR_MSG_INVAL;
7817c478bd9Sstevel@tonic-gate 			break;
7827c478bd9Sstevel@tonic-gate 	}
7837c478bd9Sstevel@tonic-gate 
7847c478bd9Sstevel@tonic-gate 	/* check if packed correctly */
7857c478bd9Sstevel@tonic-gate 	if (err != RDR_OK) {
7867c478bd9Sstevel@tonic-gate 		return (err);
7877c478bd9Sstevel@tonic-gate 	}
7887c478bd9Sstevel@tonic-gate 
7897c478bd9Sstevel@tonic-gate 	/* send the message */
7907c478bd9Sstevel@tonic-gate 	err = rdr_snd(fd, hdr, pack_buf, pack_buf_sz, timeout);
7917c478bd9Sstevel@tonic-gate 
7927c478bd9Sstevel@tonic-gate 	free((void *)pack_buf);
7937c478bd9Sstevel@tonic-gate 
7947c478bd9Sstevel@tonic-gate 	return (err);
7957c478bd9Sstevel@tonic-gate }
7967c478bd9Sstevel@tonic-gate 
7977c478bd9Sstevel@tonic-gate 
7987c478bd9Sstevel@tonic-gate /*
7997c478bd9Sstevel@tonic-gate  * rdr_rcv_msg:
8007c478bd9Sstevel@tonic-gate  *
8017c478bd9Sstevel@tonic-gate  * Public interface for receiving an RDR message. Data is
8027c478bd9Sstevel@tonic-gate  * unpacked into the hdr and param paramters.
8037c478bd9Sstevel@tonic-gate  */
8047c478bd9Sstevel@tonic-gate int
rdr_rcv_msg(int fd,rdr_msg_hdr_t * hdr,cfga_params_t * param,int timeout)8057c478bd9Sstevel@tonic-gate rdr_rcv_msg(int fd, rdr_msg_hdr_t *hdr, cfga_params_t *param, int timeout)
8067c478bd9Sstevel@tonic-gate {
8077c478bd9Sstevel@tonic-gate 	int	err;
8087c478bd9Sstevel@tonic-gate 	char	*unpack_buf = NULL;
8097c478bd9Sstevel@tonic-gate 
8107c478bd9Sstevel@tonic-gate 
8117c478bd9Sstevel@tonic-gate 	/* sanity checks */
8127c478bd9Sstevel@tonic-gate 	if ((hdr == NULL) || (param == NULL)) {
8137c478bd9Sstevel@tonic-gate 		return (RDR_ERROR);
8147c478bd9Sstevel@tonic-gate 	}
8157c478bd9Sstevel@tonic-gate 
8167c478bd9Sstevel@tonic-gate 	(void) memset(param, 0, sizeof (cfga_params_t));
8177c478bd9Sstevel@tonic-gate 
8187c478bd9Sstevel@tonic-gate 	/* receive the message */
8197c478bd9Sstevel@tonic-gate 	if ((err = rdr_rcv(fd, hdr, &unpack_buf, timeout)) != RDR_OK) {
8207c478bd9Sstevel@tonic-gate 		return (err);
8217c478bd9Sstevel@tonic-gate 	}
8227c478bd9Sstevel@tonic-gate 
8237c478bd9Sstevel@tonic-gate 	/*
8247c478bd9Sstevel@tonic-gate 	 * Unpack the message
8257c478bd9Sstevel@tonic-gate 	 */
8267c478bd9Sstevel@tonic-gate 	switch (hdr->message_opcode) {
8277c478bd9Sstevel@tonic-gate 
8287c478bd9Sstevel@tonic-gate 		case RDR_SES_REQ: {
8297c478bd9Sstevel@tonic-gate 
8307c478bd9Sstevel@tonic-gate 			ses_req_params_t *rparam;
8317c478bd9Sstevel@tonic-gate 			rparam = (ses_req_params_t *)param;
8327c478bd9Sstevel@tonic-gate 
8337c478bd9Sstevel@tonic-gate 			if (hdr->data_type == RDR_REQUEST) {
8347c478bd9Sstevel@tonic-gate 				err = unpack_ses_req_request(rparam,
8357c478bd9Sstevel@tonic-gate 				    unpack_buf);
8367c478bd9Sstevel@tonic-gate 			} else {
8377c478bd9Sstevel@tonic-gate 				err = unpack_ses_req_reply(rparam, unpack_buf);
8387c478bd9Sstevel@tonic-gate 			}
8397c478bd9Sstevel@tonic-gate 			break;
8407c478bd9Sstevel@tonic-gate 		}
8417c478bd9Sstevel@tonic-gate 
8427c478bd9Sstevel@tonic-gate 		case RDR_SES_ESTBL:
8437c478bd9Sstevel@tonic-gate 		case RDR_SES_END:
8447c478bd9Sstevel@tonic-gate 
8457c478bd9Sstevel@tonic-gate 			/* no information to unpack */
8467c478bd9Sstevel@tonic-gate 			(void) memset(param, 0, sizeof (cfga_params_t));
8477c478bd9Sstevel@tonic-gate 			err = RDR_OK;
8487c478bd9Sstevel@tonic-gate 			break;
8497c478bd9Sstevel@tonic-gate 
8507c478bd9Sstevel@tonic-gate 		case RDR_CONF_CHANGE_STATE: {
8517c478bd9Sstevel@tonic-gate 
8527c478bd9Sstevel@tonic-gate 			change_state_params_t *cparam;
8537c478bd9Sstevel@tonic-gate 			cparam = (change_state_params_t *)param;
8547c478bd9Sstevel@tonic-gate 
8557c478bd9Sstevel@tonic-gate 			if (hdr->data_type == RDR_REQUEST) {
8567c478bd9Sstevel@tonic-gate 				err = unpack_change_state_request(cparam,
8577c478bd9Sstevel@tonic-gate 				    unpack_buf);
8587c478bd9Sstevel@tonic-gate 			} else {
8597c478bd9Sstevel@tonic-gate 				err = unpack_change_state_reply(cparam,
8607c478bd9Sstevel@tonic-gate 				    unpack_buf);
8617c478bd9Sstevel@tonic-gate 			}
8627c478bd9Sstevel@tonic-gate 			break;
8637c478bd9Sstevel@tonic-gate 		}
8647c478bd9Sstevel@tonic-gate 
8657c478bd9Sstevel@tonic-gate 		case RDR_CONF_PRIVATE_FUNC: {
8667c478bd9Sstevel@tonic-gate 
8677c478bd9Sstevel@tonic-gate 			private_func_params_t *pparam;
8687c478bd9Sstevel@tonic-gate 			pparam = (private_func_params_t *)param;
8697c478bd9Sstevel@tonic-gate 
8707c478bd9Sstevel@tonic-gate 			if (hdr->data_type == RDR_REQUEST) {
8717c478bd9Sstevel@tonic-gate 				err = unpack_private_func_request(pparam,
8727c478bd9Sstevel@tonic-gate 				    unpack_buf);
8737c478bd9Sstevel@tonic-gate 			} else {
8747c478bd9Sstevel@tonic-gate 				err = unpack_private_func_reply(pparam,
8757c478bd9Sstevel@tonic-gate 				    unpack_buf);
8767c478bd9Sstevel@tonic-gate 			}
8777c478bd9Sstevel@tonic-gate 			break;
8787c478bd9Sstevel@tonic-gate 		}
8797c478bd9Sstevel@tonic-gate 
8807c478bd9Sstevel@tonic-gate 		case RDR_CONF_TEST: {
8817c478bd9Sstevel@tonic-gate 
8827c478bd9Sstevel@tonic-gate 			test_params_t *tparam;
8837c478bd9Sstevel@tonic-gate 			tparam = (test_params_t *)param;
8847c478bd9Sstevel@tonic-gate 
8857c478bd9Sstevel@tonic-gate 			if (hdr->data_type == RDR_REQUEST) {
8867c478bd9Sstevel@tonic-gate 				err = unpack_test_request(tparam, unpack_buf);
8877c478bd9Sstevel@tonic-gate 			} else {
8887c478bd9Sstevel@tonic-gate 				err = unpack_test_reply(tparam, unpack_buf);
8897c478bd9Sstevel@tonic-gate 			}
8907c478bd9Sstevel@tonic-gate 			break;
8917c478bd9Sstevel@tonic-gate 		}
8927c478bd9Sstevel@tonic-gate 
8937c478bd9Sstevel@tonic-gate 		case RDR_CONF_LIST_EXT: {
8947c478bd9Sstevel@tonic-gate 
8957c478bd9Sstevel@tonic-gate 			list_ext_params_t *lparam;
8967c478bd9Sstevel@tonic-gate 			lparam = (list_ext_params_t *)param;
8977c478bd9Sstevel@tonic-gate 
8987c478bd9Sstevel@tonic-gate 			if (hdr->data_type == RDR_REQUEST) {
8997c478bd9Sstevel@tonic-gate 				err = unpack_list_ext_request(lparam,
9007c478bd9Sstevel@tonic-gate 				    unpack_buf);
9017c478bd9Sstevel@tonic-gate 			} else {
9027c478bd9Sstevel@tonic-gate 				err = unpack_list_ext_reply(lparam, unpack_buf);
9037c478bd9Sstevel@tonic-gate 			}
9047c478bd9Sstevel@tonic-gate 			break;
9057c478bd9Sstevel@tonic-gate 		}
9067c478bd9Sstevel@tonic-gate 
9077c478bd9Sstevel@tonic-gate 		case RDR_CONF_HELP: {
9087c478bd9Sstevel@tonic-gate 
9097c478bd9Sstevel@tonic-gate 			help_params_t *hparam;
9107c478bd9Sstevel@tonic-gate 			hparam = (help_params_t *)param;
9117c478bd9Sstevel@tonic-gate 
9127c478bd9Sstevel@tonic-gate 			if (hdr->data_type == RDR_REQUEST) {
9137c478bd9Sstevel@tonic-gate 				err = unpack_help_request(hparam,
9147c478bd9Sstevel@tonic-gate 				    unpack_buf);
9157c478bd9Sstevel@tonic-gate 			} else {
9167c478bd9Sstevel@tonic-gate 				/*
9177c478bd9Sstevel@tonic-gate 				 * This is not an error because help
9187c478bd9Sstevel@tonic-gate 				 * reply does not have any extra information
9197c478bd9Sstevel@tonic-gate 				 * to unpack.
9207c478bd9Sstevel@tonic-gate 				 */
9217c478bd9Sstevel@tonic-gate 				err = RDR_OK;
9227c478bd9Sstevel@tonic-gate 			}
9237c478bd9Sstevel@tonic-gate 			break;
9247c478bd9Sstevel@tonic-gate 		}
9257c478bd9Sstevel@tonic-gate 
9267c478bd9Sstevel@tonic-gate 		case RDR_CONF_AP_ID_CMP: {
9277c478bd9Sstevel@tonic-gate 
9287c478bd9Sstevel@tonic-gate 			ap_id_cmp_params_t *aparam;
9297c478bd9Sstevel@tonic-gate 			aparam = (ap_id_cmp_params_t *)param;
9307c478bd9Sstevel@tonic-gate 
9317c478bd9Sstevel@tonic-gate 			if (hdr->data_type == RDR_REQUEST) {
9327c478bd9Sstevel@tonic-gate 				err = unpack_ap_id_cmp_request(aparam,
9337c478bd9Sstevel@tonic-gate 				    unpack_buf);
9347c478bd9Sstevel@tonic-gate 			} else {
9357c478bd9Sstevel@tonic-gate 				/*
9367c478bd9Sstevel@tonic-gate 				 * This is not an error because ap_id_cmp
9377c478bd9Sstevel@tonic-gate 				 * reply does not have any extra information
9387c478bd9Sstevel@tonic-gate 				 * to pack.
9397c478bd9Sstevel@tonic-gate 				 */
9407c478bd9Sstevel@tonic-gate 				err = RDR_OK;
9417c478bd9Sstevel@tonic-gate 			}
9427c478bd9Sstevel@tonic-gate 			break;
9437c478bd9Sstevel@tonic-gate 		}
9447c478bd9Sstevel@tonic-gate 
9457c478bd9Sstevel@tonic-gate 		case RDR_CONF_ABORT_CMD: {
9467c478bd9Sstevel@tonic-gate 
9477c478bd9Sstevel@tonic-gate 			abort_cmd_params_t *aparam;
9487c478bd9Sstevel@tonic-gate 			aparam = (abort_cmd_params_t *)param;
9497c478bd9Sstevel@tonic-gate 
9507c478bd9Sstevel@tonic-gate 			if (hdr->data_type == RDR_REQUEST) {
9517c478bd9Sstevel@tonic-gate 				err = unpack_abort_cmd_request(aparam,
9527c478bd9Sstevel@tonic-gate 				    unpack_buf);
9537c478bd9Sstevel@tonic-gate 			} else {
9547c478bd9Sstevel@tonic-gate 				/* no information to unpack */
9557c478bd9Sstevel@tonic-gate 				(void) memset(param, 0, sizeof (cfga_params_t));
9567c478bd9Sstevel@tonic-gate 				err = RDR_OK;
9577c478bd9Sstevel@tonic-gate 			}
9587c478bd9Sstevel@tonic-gate 
9597c478bd9Sstevel@tonic-gate 			break;
9607c478bd9Sstevel@tonic-gate 		}
9617c478bd9Sstevel@tonic-gate 
9627c478bd9Sstevel@tonic-gate 		case RDR_CONF_CONFIRM_CALLBACK: {
9637c478bd9Sstevel@tonic-gate 
9647c478bd9Sstevel@tonic-gate 			confirm_callback_params_t *cparam;
9657c478bd9Sstevel@tonic-gate 			cparam = (confirm_callback_params_t *)param;
9667c478bd9Sstevel@tonic-gate 
9677c478bd9Sstevel@tonic-gate 			if (hdr->data_type == RDR_REQUEST) {
9687c478bd9Sstevel@tonic-gate 				err = unpack_confirm_request(cparam,
9697c478bd9Sstevel@tonic-gate 				    unpack_buf);
9707c478bd9Sstevel@tonic-gate 			} else {
9717c478bd9Sstevel@tonic-gate 				err = unpack_confirm_reply(cparam, unpack_buf);
9727c478bd9Sstevel@tonic-gate 			}
9737c478bd9Sstevel@tonic-gate 			break;
9747c478bd9Sstevel@tonic-gate 		}
9757c478bd9Sstevel@tonic-gate 
9767c478bd9Sstevel@tonic-gate 		case RDR_CONF_MSG_CALLBACK: {
9777c478bd9Sstevel@tonic-gate 
9787c478bd9Sstevel@tonic-gate 			msg_callback_params_t *mparam;
9797c478bd9Sstevel@tonic-gate 			mparam = (msg_callback_params_t *)param;
9807c478bd9Sstevel@tonic-gate 
9817c478bd9Sstevel@tonic-gate 			if (hdr->data_type == RDR_REQUEST) {
9827c478bd9Sstevel@tonic-gate 				err = unpack_message_request(mparam,
9837c478bd9Sstevel@tonic-gate 				    unpack_buf);
9847c478bd9Sstevel@tonic-gate 			} else {
9857c478bd9Sstevel@tonic-gate 				/*
9867c478bd9Sstevel@tonic-gate 				 * It is an error to send a reply
9877c478bd9Sstevel@tonic-gate 				 * to a message callback.
9887c478bd9Sstevel@tonic-gate 				 */
9897c478bd9Sstevel@tonic-gate 				(void) memset(param, 0, sizeof (cfga_params_t));
9907c478bd9Sstevel@tonic-gate 				err = RDR_MSG_INVAL;
9917c478bd9Sstevel@tonic-gate 			}
9927c478bd9Sstevel@tonic-gate 			break;
9937c478bd9Sstevel@tonic-gate 		}
9947c478bd9Sstevel@tonic-gate 
9957c478bd9Sstevel@tonic-gate 		case RDR_RSRC_INFO: {
9967c478bd9Sstevel@tonic-gate 
9977c478bd9Sstevel@tonic-gate 			rsrc_info_params_t *rparam;
9987c478bd9Sstevel@tonic-gate 			rparam = (rsrc_info_params_t *)param;
9997c478bd9Sstevel@tonic-gate 
10007c478bd9Sstevel@tonic-gate 			if (hdr->data_type == RDR_REQUEST) {
10017c478bd9Sstevel@tonic-gate 				err = unpack_rsrc_info_request(rparam,
10027c478bd9Sstevel@tonic-gate 				    unpack_buf);
10037c478bd9Sstevel@tonic-gate 			} else {
10047c478bd9Sstevel@tonic-gate 				err = unpack_rsrc_info_reply(rparam,
10057c478bd9Sstevel@tonic-gate 				    unpack_buf);
10067c478bd9Sstevel@tonic-gate 			}
10077c478bd9Sstevel@tonic-gate 			break;
10087c478bd9Sstevel@tonic-gate 		}
10097c478bd9Sstevel@tonic-gate 
10107c478bd9Sstevel@tonic-gate 		default:
10117c478bd9Sstevel@tonic-gate 			err = RDR_MSG_INVAL;
10127c478bd9Sstevel@tonic-gate 			break;
10137c478bd9Sstevel@tonic-gate 	}
10147c478bd9Sstevel@tonic-gate 
10157c478bd9Sstevel@tonic-gate 	free(unpack_buf);
10167c478bd9Sstevel@tonic-gate 
10177c478bd9Sstevel@tonic-gate 	/* check if unpacked correctly */
10187c478bd9Sstevel@tonic-gate 	if (err != RDR_OK) {
10197c478bd9Sstevel@tonic-gate 		return (err);
10207c478bd9Sstevel@tonic-gate 	}
10217c478bd9Sstevel@tonic-gate 
10227c478bd9Sstevel@tonic-gate 	return (RDR_OK);
10237c478bd9Sstevel@tonic-gate }
10247c478bd9Sstevel@tonic-gate 
10257c478bd9Sstevel@tonic-gate 
10267c478bd9Sstevel@tonic-gate /*
10277c478bd9Sstevel@tonic-gate  * rdr_cleanup_params:
10287c478bd9Sstevel@tonic-gate  *
10297c478bd9Sstevel@tonic-gate  * Deallocate any memory that was allocated in unpacking a
10307c478bd9Sstevel@tonic-gate  * message.
10317c478bd9Sstevel@tonic-gate  */
10327c478bd9Sstevel@tonic-gate int
rdr_cleanup_params(rdr_msg_opcode_t message_opcode,cfga_params_t * param)10337c478bd9Sstevel@tonic-gate rdr_cleanup_params(rdr_msg_opcode_t message_opcode, cfga_params_t *param)
10347c478bd9Sstevel@tonic-gate {
10357c478bd9Sstevel@tonic-gate 	/* sanity check */
10367c478bd9Sstevel@tonic-gate 	if ((param == NULL)) {
10377c478bd9Sstevel@tonic-gate 		return (RDR_ERROR);
10387c478bd9Sstevel@tonic-gate 	}
10397c478bd9Sstevel@tonic-gate 
10407c478bd9Sstevel@tonic-gate 	/*
10417c478bd9Sstevel@tonic-gate 	 * Deallocate memory depending on
10427c478bd9Sstevel@tonic-gate 	 * the operation.
10437c478bd9Sstevel@tonic-gate 	 */
10447c478bd9Sstevel@tonic-gate 	switch (message_opcode) {
10457c478bd9Sstevel@tonic-gate 
10467c478bd9Sstevel@tonic-gate 	case RDR_SES_REQ: {
10477c478bd9Sstevel@tonic-gate 
10487c478bd9Sstevel@tonic-gate 		ses_req_params_t *sparam;
10497c478bd9Sstevel@tonic-gate 		sparam = (ses_req_params_t *)param;
10507c478bd9Sstevel@tonic-gate 
10517c478bd9Sstevel@tonic-gate 		if (sparam->locale_str != NULL) {
10527c478bd9Sstevel@tonic-gate 			free((void *)sparam->locale_str);
10537c478bd9Sstevel@tonic-gate 			sparam->locale_str = NULL;
10547c478bd9Sstevel@tonic-gate 		}
10557c478bd9Sstevel@tonic-gate 		break;
10567c478bd9Sstevel@tonic-gate 	}
10577c478bd9Sstevel@tonic-gate 
10587c478bd9Sstevel@tonic-gate 	case RDR_SES_ESTBL:
10597c478bd9Sstevel@tonic-gate 	case RDR_SES_END:
10607c478bd9Sstevel@tonic-gate 
10617c478bd9Sstevel@tonic-gate 		/* nothing to deallocate */
10627c478bd9Sstevel@tonic-gate 		break;
10637c478bd9Sstevel@tonic-gate 
10647c478bd9Sstevel@tonic-gate 	case RDR_CONF_CHANGE_STATE: {
10657c478bd9Sstevel@tonic-gate 
10667c478bd9Sstevel@tonic-gate 		change_state_params_t *cparam;
10677c478bd9Sstevel@tonic-gate 		cparam = (change_state_params_t *)param;
10687c478bd9Sstevel@tonic-gate 
10697c478bd9Sstevel@tonic-gate 		cleanup_ap_ids(cparam->num_ap_ids, (char **)cparam->ap_ids);
10707c478bd9Sstevel@tonic-gate 		cparam->ap_ids = NULL;
10717c478bd9Sstevel@tonic-gate 		if (cparam->options != NULL) {
10727c478bd9Sstevel@tonic-gate 			free((void *)cparam->options);
10737c478bd9Sstevel@tonic-gate 			cparam->options = NULL;
10747c478bd9Sstevel@tonic-gate 		}
10757c478bd9Sstevel@tonic-gate 		if (cparam->confp != NULL) {
10767c478bd9Sstevel@tonic-gate 			free((void *)cparam->confp);
10777c478bd9Sstevel@tonic-gate 			cparam->confp = NULL;
10787c478bd9Sstevel@tonic-gate 		}
10797c478bd9Sstevel@tonic-gate 		if (cparam->msgp != NULL) {
10807c478bd9Sstevel@tonic-gate 			free((void *)cparam->msgp);
10817c478bd9Sstevel@tonic-gate 			cparam->msgp = NULL;
10827c478bd9Sstevel@tonic-gate 		}
10837c478bd9Sstevel@tonic-gate 		cleanup_errstring(cparam->errstring);
10847c478bd9Sstevel@tonic-gate 		break;
10857c478bd9Sstevel@tonic-gate 	}
10867c478bd9Sstevel@tonic-gate 
10877c478bd9Sstevel@tonic-gate 	case RDR_CONF_PRIVATE_FUNC: {
10887c478bd9Sstevel@tonic-gate 
10897c478bd9Sstevel@tonic-gate 		private_func_params_t *pparam;
10907c478bd9Sstevel@tonic-gate 		pparam = (private_func_params_t *)param;
10917c478bd9Sstevel@tonic-gate 
10927c478bd9Sstevel@tonic-gate 		cleanup_ap_ids(pparam->num_ap_ids, (char **)pparam->ap_ids);
10937c478bd9Sstevel@tonic-gate 		pparam->ap_ids = NULL;
10947c478bd9Sstevel@tonic-gate 		if (pparam->options != NULL) {
10957c478bd9Sstevel@tonic-gate 			free((void *)pparam->options);
10967c478bd9Sstevel@tonic-gate 			pparam->options = NULL;
10977c478bd9Sstevel@tonic-gate 		}
10987c478bd9Sstevel@tonic-gate 		if (pparam->confp != NULL) {
10997c478bd9Sstevel@tonic-gate 			free((void *)pparam->confp);
11007c478bd9Sstevel@tonic-gate 			pparam->confp = NULL;
11017c478bd9Sstevel@tonic-gate 		}
11027c478bd9Sstevel@tonic-gate 		if (pparam->msgp != NULL) {
11037c478bd9Sstevel@tonic-gate 			free((void *)pparam->msgp);
11047c478bd9Sstevel@tonic-gate 			pparam->msgp = NULL;
11057c478bd9Sstevel@tonic-gate 		}
11067c478bd9Sstevel@tonic-gate 		cleanup_errstring(pparam->errstring);
11077c478bd9Sstevel@tonic-gate 		break;
11087c478bd9Sstevel@tonic-gate 	}
11097c478bd9Sstevel@tonic-gate 
11107c478bd9Sstevel@tonic-gate 	case RDR_CONF_TEST: {
11117c478bd9Sstevel@tonic-gate 
11127c478bd9Sstevel@tonic-gate 		test_params_t *tparam;
11137c478bd9Sstevel@tonic-gate 		tparam = (test_params_t *)param;
11147c478bd9Sstevel@tonic-gate 
11157c478bd9Sstevel@tonic-gate 		cleanup_ap_ids(tparam->num_ap_ids, (char **)tparam->ap_ids);
11167c478bd9Sstevel@tonic-gate 		tparam->ap_ids = NULL;
11177c478bd9Sstevel@tonic-gate 		if (tparam->options != NULL) {
11187c478bd9Sstevel@tonic-gate 			free((void *)tparam->options);
11197c478bd9Sstevel@tonic-gate 			tparam->options = NULL;
11207c478bd9Sstevel@tonic-gate 		}
11217c478bd9Sstevel@tonic-gate 		if (tparam->msgp != NULL) {
11227c478bd9Sstevel@tonic-gate 			free((void *)tparam->msgp);
11237c478bd9Sstevel@tonic-gate 			tparam->msgp = NULL;
11247c478bd9Sstevel@tonic-gate 		}
11257c478bd9Sstevel@tonic-gate 		cleanup_errstring(tparam->errstring);
11267c478bd9Sstevel@tonic-gate 		break;
11277c478bd9Sstevel@tonic-gate 	}
11287c478bd9Sstevel@tonic-gate 
11297c478bd9Sstevel@tonic-gate 	case RDR_CONF_LIST_EXT: {
11307c478bd9Sstevel@tonic-gate 
11317c478bd9Sstevel@tonic-gate 		list_ext_params_t *lparam;
11327c478bd9Sstevel@tonic-gate 		lparam = (list_ext_params_t *)param;
11337c478bd9Sstevel@tonic-gate 
11347c478bd9Sstevel@tonic-gate 		cleanup_ap_ids(lparam->num_ap_ids, (char **)lparam->ap_ids);
11357c478bd9Sstevel@tonic-gate 		lparam->ap_ids = NULL;
11367c478bd9Sstevel@tonic-gate 
11377c478bd9Sstevel@tonic-gate 		if (lparam->nlist != NULL) {
11387c478bd9Sstevel@tonic-gate 			free((void *)lparam->nlist);
11397c478bd9Sstevel@tonic-gate 			lparam->nlist = NULL;
11407c478bd9Sstevel@tonic-gate 		}
11417c478bd9Sstevel@tonic-gate 		if (lparam->ap_id_list != NULL) {
11427c478bd9Sstevel@tonic-gate 			if (*lparam->ap_id_list != NULL) {
11437c478bd9Sstevel@tonic-gate 				free((void *)*lparam->ap_id_list);
11447c478bd9Sstevel@tonic-gate 			}
11457c478bd9Sstevel@tonic-gate 			free((void *)lparam->ap_id_list);
11467c478bd9Sstevel@tonic-gate 			lparam->ap_id_list = NULL;
11477c478bd9Sstevel@tonic-gate 		}
11487c478bd9Sstevel@tonic-gate 		if (lparam->ap_id_list != NULL) {
11497c478bd9Sstevel@tonic-gate 			free((void *)lparam->ap_id_list);
11507c478bd9Sstevel@tonic-gate 			lparam->ap_id_list = NULL;
11517c478bd9Sstevel@tonic-gate 		}
11527c478bd9Sstevel@tonic-gate 
11537c478bd9Sstevel@tonic-gate 		if (lparam->options != NULL) {
11547c478bd9Sstevel@tonic-gate 			free((void *)lparam->options);
11557c478bd9Sstevel@tonic-gate 			lparam->options = NULL;
11567c478bd9Sstevel@tonic-gate 		}
11577c478bd9Sstevel@tonic-gate 		if (lparam->listopts != NULL) {
11587c478bd9Sstevel@tonic-gate 			free((void *)lparam->listopts);
11597c478bd9Sstevel@tonic-gate 			lparam->listopts = NULL;
11607c478bd9Sstevel@tonic-gate 		}
11617c478bd9Sstevel@tonic-gate 		cleanup_errstring(lparam->errstring);
11627c478bd9Sstevel@tonic-gate 		break;
11637c478bd9Sstevel@tonic-gate 	}
11647c478bd9Sstevel@tonic-gate 
11657c478bd9Sstevel@tonic-gate 	case RDR_CONF_HELP: {
11667c478bd9Sstevel@tonic-gate 
11677c478bd9Sstevel@tonic-gate 		help_params_t *hparam;
11687c478bd9Sstevel@tonic-gate 		hparam = (help_params_t *)param;
11697c478bd9Sstevel@tonic-gate 
11707c478bd9Sstevel@tonic-gate 		cleanup_ap_ids(hparam->num_ap_ids, (char **)hparam->ap_ids);
11717c478bd9Sstevel@tonic-gate 		hparam->ap_ids = NULL;
11727c478bd9Sstevel@tonic-gate 		if (hparam->msgp != NULL) {
11737c478bd9Sstevel@tonic-gate 			free((void *)hparam->msgp);
11747c478bd9Sstevel@tonic-gate 			hparam->msgp = NULL;
11757c478bd9Sstevel@tonic-gate 		}
11767c478bd9Sstevel@tonic-gate 		if (hparam->options != NULL) {
11777c478bd9Sstevel@tonic-gate 			free((void *)hparam->options);
11787c478bd9Sstevel@tonic-gate 			hparam->options = NULL;
11797c478bd9Sstevel@tonic-gate 		}
11807c478bd9Sstevel@tonic-gate 		break;
11817c478bd9Sstevel@tonic-gate 	}
11827c478bd9Sstevel@tonic-gate 
11837c478bd9Sstevel@tonic-gate 	case RDR_CONF_AP_ID_CMP: {
11847c478bd9Sstevel@tonic-gate 
11857c478bd9Sstevel@tonic-gate 		ap_id_cmp_params_t *aparam;
11867c478bd9Sstevel@tonic-gate 		aparam = (ap_id_cmp_params_t *)param;
11877c478bd9Sstevel@tonic-gate 
11887c478bd9Sstevel@tonic-gate 		if (aparam->ap_log_id1 != NULL) {
11897c478bd9Sstevel@tonic-gate 			free((void *)aparam->ap_log_id1);
11907c478bd9Sstevel@tonic-gate 			aparam->ap_log_id1 = NULL;
11917c478bd9Sstevel@tonic-gate 		}
11927c478bd9Sstevel@tonic-gate 		if (aparam->ap_log_id2 != NULL) {
11937c478bd9Sstevel@tonic-gate 			free((void *)aparam->ap_log_id2);
11947c478bd9Sstevel@tonic-gate 			aparam->ap_log_id2 = NULL;
11957c478bd9Sstevel@tonic-gate 		}
11967c478bd9Sstevel@tonic-gate 		break;
11977c478bd9Sstevel@tonic-gate 	}
11987c478bd9Sstevel@tonic-gate 
11997c478bd9Sstevel@tonic-gate 	case RDR_CONF_ABORT_CMD:
12007c478bd9Sstevel@tonic-gate 
12017c478bd9Sstevel@tonic-gate 		/* nothing to deallocate */
12027c478bd9Sstevel@tonic-gate 		break;
12037c478bd9Sstevel@tonic-gate 
12047c478bd9Sstevel@tonic-gate 	case RDR_CONF_CONFIRM_CALLBACK: {
12057c478bd9Sstevel@tonic-gate 
12067c478bd9Sstevel@tonic-gate 		confirm_callback_params_t *cparam;
12077c478bd9Sstevel@tonic-gate 		cparam = (confirm_callback_params_t *)param;
12087c478bd9Sstevel@tonic-gate 
12097c478bd9Sstevel@tonic-gate 		if (cparam->confp != NULL) {
12107c478bd9Sstevel@tonic-gate 			free((void *)cparam->confp);
12117c478bd9Sstevel@tonic-gate 			cparam->confp = NULL;
1212