Home | History | Annotate | Download | only in rpc
      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 2005 Sun Microsystems, Inc.  All rights reserved.
     24  * Use is subject to license terms.
     25  */
     26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
     27 /* All Rights Reserved */
     28 /*
     29  * Portions of this source code were derived from Berkeley
     30  * 4.3 BSD under license from the Regents of the University of
     31  * California.
     32  */
     33 
     34 /*
     35  * clnt.h - Client side remote procedure call interface.
     36  */
     37 
     38 #ifndef	_RPC_CLNT_H
     39 #define	_RPC_CLNT_H
     40 
     41 #pragma ident	"@(#)clnt.h	1.81	05/10/21 SMI"
     42 
     43 #include <sys/types.h>
     44 #include <rpc/rpc_com.h>
     45 #include <rpc/clnt_stat.h>
     46 #include <rpc/auth.h>
     47 
     48 /*
     49  * rpc calls return an enum clnt_stat.  This should be looked at more,
     50  * since each implementation is required to live with this (implementation
     51  * independent) list of errors.
     52  */
     53 #include <sys/netconfig.h>
     54 #ifdef _KERNEL
     55 #include <sys/t_kuser.h>
     56 #endif	/* _KERNEL */
     57 
     58 #ifdef __cplusplus
     59 extern "C" {
     60 #endif
     61 
     62 /*
     63  * Following defines the multicast group address used by IPV6 enabled
     64  * client to do the broadcast. IPv6 doesn't have any broadcast support
     65  * as IPv4 provides, thus it used this reserved address which is joined
     66  * by all rpc clients.
     67  */
     68 
     69 #define	RPCB_MULTICAST_ADDR "FF02::202"
     70 
     71 /*
     72  * the following errors are in general unrecoverable.  The caller
     73  * should give up rather than retry.
     74  */
     75 #define	IS_UNRECOVERABLE_RPC(s)	(((s) == RPC_AUTHERROR) || \
     76 	((s) == RPC_CANTENCODEARGS) || \
     77 	((s) == RPC_CANTDECODERES) || \
     78 	((s) == RPC_VERSMISMATCH) || \
     79 	((s) == RPC_PROCUNAVAIL) || \
     80 	((s) == RPC_PROGUNAVAIL) || \
     81 	((s) == RPC_PROGVERSMISMATCH) || \
     82 	((s) == RPC_CANTDECODEARGS))
     83 
     84 /* Maximum rpc backoff time */
     85 #define	RPC_MAX_BACKOFF	30
     86 
     87 /*
     88  * Error info.
     89  */
     90 struct rpc_err {
     91 	enum clnt_stat re_status;
     92 	union {
     93 		struct {
     94 			int RE_errno;	/* related system error */
     95 			int RE_t_errno;	/* related tli error number */
     96 		} RE_err;
     97 		enum auth_stat RE_why;	/* why the auth error occurred */
     98 		struct {
     99 			rpcvers_t low;	/* lowest verion supported */
    100 			rpcvers_t high;	/* highest verion supported */
    101 		} RE_vers;
    102 		struct {		/* maybe meaningful if RPC_FAILED */
    103 			int32_t s1;
    104 			int32_t s2;
    105 		} RE_lb;		/* life boot & debugging only */
    106 	} ru;
    107 #define	re_errno	ru.RE_err.RE_errno
    108 #define	re_terrno	ru.RE_err.RE_t_errno
    109 #define	re_why		ru.RE_why
    110 #define	re_vers		ru.RE_vers
    111 #define	re_lb		ru.RE_lb
    112 };
    113 
    114 
    115 /*
    116  * Timers used for the pseudo-transport protocol when using datagrams
    117  */
    118 struct rpc_timers {
    119 	clock_t		rt_srtt;	/* smoothed round-trip time */
    120 	clock_t		rt_deviate;	/* estimated deviation */
    121 	clock_t		rt_rtxcur;	/* current (backed-off) rto */
    122 };
    123 
    124 /*
    125  * PSARC 2003/523 Contract Private Interface
    126  * CLIENT
    127  * Changes must be reviewed by Solaris File Sharing
    128  * Changes must be communicated to contract-2003-523 (at) sun.com
    129  *
    130  * Client rpc handle.
    131  * Created by individual implementations
    132  * Client is responsible for initializing auth, see e.g. auth_none.c.
    133  */
    134 
    135 typedef struct __client {
    136 	AUTH	*cl_auth;			/* authenticator */
    137 	struct clnt_ops {
    138 #ifdef __STDC__
    139 		/* call remote procedure */
    140 		enum clnt_stat	(*cl_call)(struct __client *, rpcproc_t,
    141 				    xdrproc_t, caddr_t, xdrproc_t,
    142 				    caddr_t, struct timeval);
    143 		/* abort a call */
    144 		void		(*cl_abort)(/* various */);
    145 		/* get specific error code */
    146 		void		(*cl_geterr)(struct __client *,
    147 				    struct rpc_err *);
    148 		/* frees results */
    149 		bool_t		(*cl_freeres)(struct __client *, xdrproc_t,
    150 				    caddr_t);
    151 		/* destroy this structure */
    152 		void		(*cl_destroy)(struct __client *);
    153 		/* the ioctl() of rpc */
    154 		bool_t		(*cl_control)(struct __client *, int, char *);
    155 		/* set rpc level timers */
    156 		int		(*cl_settimers)(struct __client *,
    157 				    struct rpc_timers *, struct rpc_timers *,
    158 				    int, void (*)(), caddr_t, uint32_t);
    159 #ifndef _KERNEL
    160 		/* send a one-way asynchronous call to remote procedure */
    161 		enum clnt_stat	(*cl_send)(struct __client *, rpcproc_t,
    162 				    xdrproc_t, caddr_t);
    163 #endif /* !_KERNEL */
    164 #else
    165 		enum clnt_stat	(*cl_call)();	/* call remote procedure */
    166 		void		(*cl_abort)();	/* abort a call */
    167 		void		(*cl_geterr)();	/* get specific error code */
    168 		bool_t		(*cl_freeres)(); /* frees results */
    169 		void		(*cl_destroy)(); /* destroy this structure */
    170 		bool_t		(*cl_control)(); /* the ioctl() of rpc */
    171 		int		(*cl_settimers)(); /* set rpc level timers */
    172 #ifndef _KERNEL
    173 		enum clnt_stat  (*cl_send)();   /* send one-way request */
    174 #endif /* !_KERNEL */
    175 #endif
    176 	} *cl_ops;
    177 	caddr_t			cl_private;	/* private stuff */
    178 #ifndef _KERNEL
    179 	char			*cl_netid;	/* network token */
    180 	char			*cl_tp;		/* device name */
    181 #else
    182 	bool_t			cl_nosignal;  /* to handle NOINTR */
    183 #endif
    184 } CLIENT;
    185 
    186 /*
    187  * Feedback values used for possible congestion and rate control
    188  */
    189 #define	FEEDBACK_REXMIT1	1	/* first retransmit */
    190 #define	FEEDBACK_OK		2	/* no retransmits */
    191 
    192 /*
    193  * The following defines the control routines
    194  * for rpcbind.
    195  */
    196 
    197 #define	CLCR_GET_RPCB_TIMEOUT	1
    198 #define	CLCR_SET_RPCB_TIMEOUT	2
    199 #define	CLCR_SET_LOWVERS	3
    200 #define	CLCR_GET_LOWVERS	4
    201 #define	CLCR_SET_RPCB_RMTTIME	5
    202 #define	CLCR_GET_RPCB_RMTTIME  	6
    203 #define	CLCR_SET_CRED_CACHE_SZ 	7
    204 #define	CLCR_GET_CRED_CACHE_SZ 	8
    205 
    206 #define	RPCSMALLMSGSIZE	400	/* a more reasonable packet size */
    207 
    208 #define	KNC_STRSIZE	128	/* maximum length of knetconfig strings */
    209 /*
    210  * PSARC 2003/523 Contract Private Interface
    211  * knetconfig
    212  * Changes must be reviewed by Solaris File Sharing
    213  * Changes must be communicated to contract-2003-523 (at) sun.com
    214  *
    215  * Note that the knetconfig strings can either be dynamically allocated, or
    216  * they can be string literals.  The code that sets up the knetconfig is
    217  * responsible for keeping track of this and freeing the strings if
    218  * necessary when the knetconfig is destroyed.
    219  */
    220 struct knetconfig {
    221 	unsigned int	knc_semantics;	/* token name */
    222 	caddr_t		knc_protofmly;	/* protocol family */
    223 	caddr_t		knc_proto;	/* protocol */
    224 	dev_t		knc_rdev;	/* device id */
    225 	unsigned int	knc_unused[8];
    226 };
    227 
    228 #ifdef _SYSCALL32
    229 struct knetconfig32 {
    230 	uint32_t	knc_semantics;	/* token name */
    231 	caddr32_t	knc_protofmly;	/* protocol family */
    232 	caddr32_t	knc_proto;	/* protocol */
    233 	dev32_t		knc_rdev;	/* device id */
    234 	uint32_t	knc_unused[8];
    235 };
    236 #endif /* _SYSCALL32 */
    237 
    238 #ifdef _KERNEL
    239 
    240 /*
    241  * Bucket defined for the call table.  Padded out to 64 bytes so that
    242  * false sharing won't be induced.
    243  */
    244 typedef	union call_table {
    245 	struct {
    246 		struct calllist_s	*uct_call_next;
    247 		struct calllist_s	*uct_call_prev;
    248 		uint_t			uct_len;
    249 		kmutex_t		uct_lock;
    250 	} ct_s;
    251 	char				uct_pad[64];
    252 } call_table_t;
    253 
    254 /*
    255  * Define some macros for easy access into the call table structure
    256  */
    257 #define	ct_call_next ct_s.uct_call_next
    258 #define	ct_call_prev ct_s.uct_call_prev
    259 #define	ct_len ct_s.uct_len
    260 #define	ct_lock ct_s.uct_lock
    261 
    262 /*
    263  * List of outstanding calls awaiting replies, for COTS, CLTS
    264  */
    265 typedef struct calllist_s {
    266 	struct calllist_s *call_next;	/* hash chain, MUST BE FIRST */
    267 	struct calllist_s *call_prev;
    268 	bool_t		call_notified;
    269 	uint_t		call_xid;	/* the xid on the call */
    270 	uint_t		call_hash;	/* hash value */
    271 	call_table_t	*call_bucket;	/* back pointer to bucket */
    272 	mblk_t		*call_reply;	/* the reply to the call */
    273 	kcondvar_t	call_cv;	/* cv to notify when reply is done */
    274 	kmutex_t	call_lock;	/* lock for cv */
    275 	struct rpc_err	call_err;	/* status on reply */
    276 #define	call_status call_err.re_status	/* error on reply (rep is invalid) */
    277 #define	call_reason call_err.re_errno	/* reason code on T_DISCON_IND */
    278 	queue_t		*call_wq;	/* the write queue the call is using */
    279 } calllist_t;
    280 
    281 /*
    282  * Define macros for call table hashing
    283  */
    284 /*
    285  * A simple hash function.  Due to the way XID's get allocated, this may be
    286  * sufficient.  This hash function provides round robin bucket selection so
    287  * that the next time a particular bucket gets picked is when there have
    288  * been N-1 calls.  N is the number of buckets.
    289  */
    290 #define	call_hash(xid, hashsize) \
    291 		(xid % hashsize);
    292 
    293 #define	call_table_enter(e)				\
    294 {							\
    295 	call_table_t *ctp = e->call_bucket;		\
    296 	mutex_enter(&ctp->ct_lock);			\
    297 	ctp->ct_len++;					\
    298 	e->call_next = (calllist_t *)ctp->ct_call_next;	\
    299 	e->call_prev = (calllist_t *)ctp;		\
    300 	((call_table_t *)ctp->ct_call_next)->ct_call_prev = e;		\
    301 	ctp->ct_call_next = e;				\
    302 	mutex_exit(&e->call_bucket->ct_lock);		\
    303 }
    304 
    305 #define	call_table_remove(e)				\
    306 {							\
    307 	call_table_t *ctp = e->call_bucket;		\
    308 	mutex_enter(&ctp->ct_lock);			\
    309 	ctp->ct_len--;					\
    310 	((call_table_t *)e->call_prev)->ct_call_next = e->call_next;	\
    311 	((call_table_t *)e->call_next)->ct_call_prev = e->call_prev;	\
    312 	mutex_exit(&ctp->ct_lock);			\
    313 }
    314 
    315 #define	call_table_find(ctp, xid, ele)			\
    316 {							\
    317 	calllist_t *cp;					\
    318 	ele = NULL;					\
    319 	mutex_enter(&(ctp)->ct_lock);			\
    320 	for (cp = (ctp)->ct_call_next;			\
    321 		cp != (calllist_t *)ctp;		\
    322 		cp = cp->call_next) {			\
    323 		if (cp->call_xid == xid)		\
    324 			ele = cp;			\
    325 	}						\
    326 }
    327 
    328 #define	DEFAULT_MIN_HASH_SIZE	32
    329 #define	DEFAULT_HASH_SIZE	1024
    330 
    331 #define	RESERVED_PORTSPACE (IPPORT_RESERVED - (IPPORT_RESERVED/2))
    332 #define	NONRESERVED_PORTSPACE (0xFFFF - IPPORT_RESERVED)
    333 
    334 /*
    335  *	Alloc_xid presents an interface which kernel RPC clients
    336  *	should use to allocate their XIDs.  Its implementation
    337  *	may change over time (for example, to allow sharing of
    338  *	XIDs between the kernel and user-level applications, so
    339  *	all XID allocation should be done by calling alloc_xid().
    340  */
    341 extern uint32_t alloc_xid(void);
    342 
    343 extern struct zone *rpc_zone(void);
    344 extern zoneid_t rpc_zoneid(void);
    345 
    346 extern int clnt_tli_kcreate(struct knetconfig *config, struct netbuf *svcaddr,
    347 	rpcprog_t, rpcvers_t, uint_t max_msgsize, int retrys,
    348 	struct cred *cred, CLIENT **ncl);
    349 
    350 extern int clnt_tli_kinit(CLIENT *h, struct knetconfig *config,
    351 	struct netbuf *addr, uint_t max_msgsize, int retries,
    352 	struct cred *cred);
    353 
    354 extern int rpc_uaddr2port(int af, char *addr);
    355 
    356 /*
    357  * kRPC internal function. Not for general use. Subject to rapid change.
    358  */
    359 extern int bindresvport(TIUSER *tiptr, struct netbuf *addr,
    360 	struct netbuf *bound_addr, bool_t istcp);
    361 
    362 /*
    363  * kRPC internal function. Not for general use. Subject to rapid change.
    364  */
    365 extern int clnt_clts_kcreate(struct knetconfig *config, struct netbuf *addr,
    366 	rpcprog_t, rpcvers_t, int retries, struct cred *cred, CLIENT **cl);
    367 
    368 /*
    369  * kRPC internal function. Not for general use. Subject to rapid change.
    370  */
    371 extern int clnt_cots_kcreate(dev_t dev, struct netbuf *addr, int family,
    372 	rpcprog_t, rpcvers_t, uint_t max_msgsize, struct cred *cred,
    373 	CLIENT **ncl);
    374 /*
    375  * kRPC internal function. Not for general use. Subject to rapid change.
    376  */
    377 extern int clnt_rdma_kcreate(char *proto, void *handle, struct netbuf *raddr,
    378 	int family, rpcprog_t pgm, rpcvers_t vers, struct cred *cred,
    379 	CLIENT **cl);
    380 /*
    381  * kRPC internal function. Not for general use. Subject to rapid change.
    382  */
    383 extern int rdma_reachable(int addr_type, struct netbuf *addr,
    384 	struct knetconfig **knconf);
    385 
    386 /*
    387  * kRPC internal function. Not for general use. Subject to rapid change.
    388  */
    389 extern void clnt_clts_kinit(CLIENT *h, struct netbuf *addr, int retries,
    390 	struct cred *cred);
    391 
    392 /*
    393  * kRPC internal function. Not for general use. Subject to rapid change.
    394  */
    395 extern void clnt_cots_kinit(CLIENT *h, dev_t dev, int family,
    396 	struct netbuf *addr, int max_msgsize, struct cred *cred);
    397 
    398 /*
    399  * kRPC internal function. Not for general use. Subject to rapid change.
    400  */
    401 extern void clnt_rdma_kinit(CLIENT *h, char *proto, void *handle,
    402 	struct netbuf *addr, struct cred *cred);
    403 
    404 /*
    405  * kRPC internal function. Not for general use. Subject to rapid change.
    406  */
    407 extern bool_t clnt_dispatch_notify(mblk_t *, zoneid_t);
    408 
    409 /*
    410  * kRPC internal function. Not for general use. Subject to rapid change.
    411  */
    412 extern bool_t clnt_dispatch_notifyconn(queue_t *, mblk_t *);
    413 
    414 /*
    415  * kRPC internal function. Not for general use. Subject to rapid change.
    416  */
    417 extern void clnt_dispatch_notifyall(queue_t *, int32_t, int32_t);
    418 
    419 /*
    420  * kRPC internal function. Not for general use. Subject to rapid change.
    421  */
    422 extern enum clnt_stat clnt_clts_kcallit_addr(CLIENT *, rpcproc_t, xdrproc_t,
    423 	caddr_t, xdrproc_t, caddr_t, struct timeval, struct netbuf *);
    424 
    425 /*
    426  * kRPC internal function. Not for general use. Subject to rapid change.
    427  */
    428 extern call_table_t *call_table_init(int);
    429 
    430 /*
    431  * kRPC internal function. Not for general use. Subject to rapid change.
    432  */
    433 extern void clnt_init(void);
    434 
    435 /*
    436  * kRPC internal function. Not for general use. Subject to rapid change.
    437  */
    438 extern void clnt_fini(void);
    439 
    440 /*
    441  * kRPC internal function. Not for general use. Subject to rapid change.
    442  */
    443 extern void clnt_clts_init(void);
    444 
    445 /*
    446  * kRPC internal function. Not for general use. Subject to rapid change.
    447  */
    448 extern void clnt_clts_fini(void);
    449 
    450 /*
    451  * kRPC internal function. Not for general use. Subject to rapid change.
    452  */
    453 extern void clnt_cots_init(void);
    454 
    455 /*
    456  * kRPC internal function. Not for general use. Subject to rapid change.
    457  */
    458 extern void clnt_cots_fini(void);
    459 
    460 /*
    461  * kRPC internal function. Not for general use. Subject to rapid change.
    462  */
    463 extern void clnt_clts_dispatch_notify(mblk_t *, int, zoneid_t);
    464 
    465 extern void rpc_poptimod(struct vnode *);
    466 extern int kstr_push(struct vnode *, char *);
    467 extern void t_kadvise(TIUSER *, uchar_t *, int);
    468 
    469 extern boolean_t connmgr_cpr_reset(void *, int);
    470 
    471 extern void put_inet_port(struct netbuf *, ushort_t);
    472 extern void put_inet6_port(struct netbuf *, ushort_t);
    473 extern void put_loopback_port(struct netbuf *, char *);
    474 extern enum clnt_stat rpcbind_getaddr(struct knetconfig *, rpcprog_t,
    475     rpcvers_t, struct netbuf *);
    476 
    477 /*
    478  * Kstat stuff
    479  */
    480 #include <sys/zone.h>
    481 
    482 extern zone_key_t rpcstat_zone_key;
    483 
    484 struct rpc_clts_client;		/* unix:0:rpc_clts_client */
    485 struct rpc_clts_server;		/* unix:0:rpc_clts_server */
    486 struct rpc_cots_client;		/* unix:0:rpc_cots_client */
    487 struct rpc_cots_server;		/* unix:0:rpc_cots_server */
    488 
    489 struct rpcstat {
    490 	struct rpc_clts_client *rpc_clts_client;
    491 	struct rpc_clts_server *rpc_clts_server;
    492 	struct rpc_cots_client *rpc_cots_client;
    493 	struct rpc_cots_server *rpc_cots_server;
    494 };
    495 
    496 extern kstat_named_t *rpcstat_zone_init_common(zoneid_t, const char *,
    497     const char *, const kstat_named_t *, size_t);
    498 extern void rpcstat_zone_fini_common(zoneid_t, const char *, const char *);
    499 
    500 extern void clnt_clts_stats_init(zoneid_t, struct rpc_clts_client **);
    501 extern void clnt_clts_stats_fini(zoneid_t, struct rpc_clts_client **);
    502 
    503 extern void svc_clts_stats_init(zoneid_t, struct rpc_clts_server **);
    504 extern void svc_clts_stats_fini(zoneid_t, struct rpc_clts_server **);
    505 
    506 extern void clnt_cots_stats_init(zoneid_t, struct rpc_cots_client **);
    507 extern void clnt_cots_stats_fini(zoneid_t, struct rpc_cots_client **);
    508 
    509 extern void svc_cots_stats_init(zoneid_t, struct rpc_cots_server **);
    510 extern void svc_cots_stats_fini(zoneid_t, struct rpc_cots_server **);
    511 
    512 #endif /* _KERNEL */
    513 
    514 /*
    515  * client side rpc interface ops
    516  */
    517 
    518 /*
    519  * enum clnt_stat
    520  * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
    521  * 	CLIENT *rh;
    522  *	rpcproc_t proc;
    523  *	xdrproc_t xargs;
    524  *	caddr_t argsp;
    525  *	xdrproc_t xres;
    526  *	caddr_t resp;
    527  *	struct timeval timeout;
    528  *
    529  * PSARC 2003/523 Contract Private Interface
    530  * CLNT_CALL
    531  * Changes must be reviewed by Solaris File Sharing
    532  * Changes must be communicated to contract-2003-523 (at) sun.com
    533  */
    534 #define	CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs)	\
    535 	((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
    536 #define	clnt_call(rh, proc, xargs, argsp, xres, resp, secs)	\
    537 	((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
    538 
    539 #ifndef _KERNEL
    540 /*
    541  * enum clnt_stat
    542  * CLNT_SEND(rh, proc, xargs, argsp)
    543  * 	CLIENT *rh;
    544  *	rpcproc_t proc;
    545  *	xdrproc_t xargs;
    546  *	caddr_t argsp;
    547  *
    548  * PSARC 2000/428  Contract Private Interface
    549  */
    550 #define	CLNT_SEND(rh, proc, xargs, argsp)	\
    551 	((*(rh)->cl_ops->cl_send)(rh, proc, xargs, argsp))
    552 #define	clnt_send(rh, proc, xargs, argsp)	\
    553 	((*(rh)->cl_ops->cl_send)(rh, proc, xargs, argsp))
    554 #endif /* !_KERNEL */
    555 
    556 /*
    557  * void
    558  * CLNT_ABORT(rh);
    559  * 	CLIENT *rh;
    560  */
    561 #define	CLNT_ABORT(rh)	((*(rh)->cl_ops->cl_abort)(rh))
    562 #define	clnt_abort(rh)	((*(rh)->cl_ops->cl_abort)(rh))
    563 
    564 /*
    565  * struct rpc_err
    566  * CLNT_GETERR(rh);
    567  * 	CLIENT *rh;
    568  */
    569 #define	CLNT_GETERR(rh, errp)	((*(rh)->cl_ops->cl_geterr)(rh, errp))
    570 #define	clnt_geterr(rh, errp)	((*(rh)->cl_ops->cl_geterr)(rh, errp))
    571 
    572 /*
    573  * bool_t
    574  * CLNT_FREERES(rh, xres, resp);
    575  * 	CLIENT *rh;
    576  *	xdrproc_t xres;
    577  *	caddr_t resp;
    578  */
    579 #define	CLNT_FREERES(rh, xres, resp) \
    580 		((*(rh)->cl_ops->cl_freeres)(rh, xres, resp))
    581 #define	clnt_freeres(rh, xres, resp) \
    582 		((*(rh)->cl_ops->cl_freeres)(rh, xres, resp))
    583 
    584 /*
    585  * bool_t
    586  * CLNT_CONTROL(cl, request, info)
    587  *	CLIENT *cl;
    588  *	uint_t request;
    589  *	char *info;
    590  *
    591  * PSARC 2003/523 Contract Private Interface
    592  * CLNT_CONTROL
    593  * Changes must be reviewed by Solaris File Sharing
    594  * Changes must be communicated to contract-2003-523 (at) sun.com
    595  */
    596 #define	CLNT_CONTROL(cl, rq, in) ((*(cl)->cl_ops->cl_control)(cl, rq, in))
    597 #define	clnt_control(cl, rq, in) ((*(cl)->cl_ops->cl_control)(cl, rq, in))
    598 
    599 
    600 /*
    601  * control operations that apply to all transports
    602  */
    603 #define	CLSET_TIMEOUT		1	/* set timeout (timeval) */
    604 #define	CLGET_TIMEOUT		2	/* get timeout (timeval) */
    605 #define	CLGET_SERVER_ADDR	3	/* get server's address (sockaddr) */
    606 #define	CLGET_FD		6	/* get connections file descriptor */
    607 #define	CLGET_SVC_ADDR		7	/* get server's address (netbuf) */
    608 #define	CLSET_FD_CLOSE		8	/* close fd while clnt_destroy */
    609 #define	CLSET_FD_NCLOSE		9	/* Do not close fd while clnt_destroy */
    610 #define	CLGET_XID 		10	/* Get xid */
    611 #define	CLSET_XID		11	/* Set xid */
    612 #define	CLGET_VERS		12	/* Get version number */
    613 #define	CLSET_VERS		13	/* Set version number */
    614 #define	CLGET_PROG		14	/* Get program number */
    615 #define	CLSET_PROG		15	/* Set program number */
    616 #define	CLSET_SVC_ADDR		16	/* get server's address (netbuf) */
    617 #define	CLSET_PUSH_TIMOD	17	/* push timod if not already present */
    618 #define	CLSET_POP_TIMOD		18	/* pop timod */
    619 #ifndef _KERNEL
    620 /* 00-08-17 - NON STANDARD CONTROL PARAMETER */
    621 #define	CLSET_IO_MODE		19	/* clnt_send behavior */
    622 #define	CLGET_IO_MODE		20	/* clnt_send behavior */
    623 #define	CLSET_FLUSH_MODE	21	/* flush behavior */
    624 #define	CLGET_FLUSH_MODE	22	/* flush behavior */
    625 #define	CLFLUSH			23	/* flush now (user wants it) */
    626 #define	CLSET_CONNMAXREC_SIZE	24	/* set pending request buffer size */
    627 #define	CLGET_CONNMAXREC_SIZE	25	/* set pending request buffer size */
    628 #define	CLGET_CURRENT_REC_SIZE	26	/* get pending request buffer size */
    629 
    630 typedef enum {
    631 	RPC_CL_BESTEFFORT_FLUSH = 100,	/* flush as much as possible */
    632 					/* without blocking */
    633 	RPC_CL_BLOCKING_FLUSH,		/* flush the buffer completely */
    634 					/* (possibly blocking) */
    635 	RPC_CL_DEFAULT_FLUSH		/* flush according to the currently */
    636 					/* defined policy. */
    637 } rpcflushmode_t;
    638 
    639 
    640 typedef enum {
    641 	RPC_CL_BLOCKING = 10,	/* PASSED CLNT_CONTROL SET_IO_MODE */
    642 	RPC_CL_NONBLOCKING
    643 } rpciomode_t;
    644 #endif /* !_KERNEL */
    645 /*
    646  * Connectionless only control operations
    647  */
    648 #define	CLSET_RETRY_TIMEOUT 4   /* set retry timeout (timeval) */
    649 #define	CLGET_RETRY_TIMEOUT 5   /* get retry timeout (timeval) */
    650 
    651 #ifdef	_KERNEL
    652 /*
    653  * Connection oriented only control operation.
    654  */
    655 #define	CLSET_PROGRESS		10000	/* Report RPC_INPROGRESS if a request */
    656 					/* has been sent but no reply */
    657 					/* received yet. */
    658 #define	CLSET_BCAST		10001	/* Set RPC Broadcast hint */
    659 #define	CLGET_BCAST		10002	/* Get RPC Broadcast hint */
    660 #define	CLSET_NODELAYONERR	10003	/* Set enable/disable of delay on */
    661 					/* connection setup error	  */
    662 #define	CLGET_NODELAYONERR	10004	/* Get enable/disable of delay on */
    663 					/* connection setup error	  */
    664 #define	CLSET_BINDRESVPORT	10005	/* Set preference for reserve port */
    665 #define	CLGET_BINDRESVPORT	10006	/* Get preference for reserve port */
    666 #endif
    667 
    668 /*
    669  * void
    670  * CLNT_SETTIMERS(rh);
    671  *	CLIENT *rh;
    672  *	struct rpc_timers *t;
    673  *	struct rpc_timers *all;
    674  *	unsigned int min;
    675  *	void    (*fdbck)();
    676  *	caddr_t arg;
    677  *	uint_t  xid;
    678  */
    679 #define	CLNT_SETTIMERS(rh, t, all, min, fdbck, arg, xid) \
    680 		((*(rh)->cl_ops->cl_settimers)(rh, t, all, min, \
    681 		fdbck, arg, xid))
    682 #define	clnt_settimers(rh, t, all, min, fdbck, arg, xid) \
    683 		((*(rh)->cl_ops->cl_settimers)(rh, t, all, min, \
    684 		fdbck, arg, xid))
    685 
    686 
    687 /*
    688  * void
    689  * CLNT_DESTROY(rh);
    690  * 	CLIENT *rh;
    691  *
    692  * PSARC 2003/523 Contract Private Interface
    693  * CLNT_DESTROY
    694  * Changes must be reviewed by Solaris File Sharing
    695  * Changes must be communicated to contract-2003-523 (at) sun.com
    696  */
    697 #define	CLNT_DESTROY(rh)	((*(rh)->cl_ops->cl_destroy)(rh))
    698 #define	clnt_destroy(rh)	((*(rh)->cl_ops->cl_destroy)(rh))
    699 
    700 
    701 /*
    702  * RPCTEST is a test program which is accessable on every rpc
    703  * transport/port.  It is used for testing, performance evaluation,
    704  * and network administration.
    705  */
    706 
    707 #define	RPCTEST_PROGRAM		((rpcprog_t)1)
    708 #define	RPCTEST_VERSION		((rpcvers_t)1)
    709 #define	RPCTEST_NULL_PROC	((rpcproc_t)2)
    710 #define	RPCTEST_NULL_BATCH_PROC	((rpcproc_t)3)
    711 
    712 /*
    713  * By convention, procedure 0 takes null arguments and returns them
    714  */
    715 
    716 #define	NULLPROC ((rpcproc_t)0)
    717 
    718 /*
    719  * Below are the client handle creation routines for the various
    720  * implementations of client side rpc.  They can return NULL if a
    721  * creation failure occurs.
    722  */
    723 
    724 #ifndef _KERNEL
    725 
    726 /*
    727  * Generic client creation routine. Supported protocols are which belong
    728  * to the nettype name space
    729  */
    730 #ifdef __STDC__
    731 extern  CLIENT * clnt_create(const char *, const rpcprog_t, const rpcvers_t,
    732 	const char *);
    733 /*
    734  *
    735  * 	const char *hostname;			-- hostname
    736  *	const rpcprog_t prog;			-- program number
    737  *	const rpcvers_t vers;			-- version number
    738  *	const char *nettype;			-- network type
    739  */
    740 #else
    741 extern CLIENT * clnt_create();
    742 #endif
    743 
    744 /*
    745  * Generic client creation routine. Just like clnt_create(), except
    746  * it takes an additional timeout parameter.
    747  */
    748 #ifdef __STDC__
    749 extern  CLIENT * clnt_create_timed(const char *, const rpcprog_t,
    750 	const rpcvers_t, const char *, const struct timeval *);
    751 /*
    752  *
    753  * 	const char *hostname;			-- hostname
    754  *	const rpcprog_t prog;			-- program number
    755  *	const rpcvers_t vers;			-- version number
    756  *	const char *nettype;			-- network type
    757  *	const struct timeval *tp;		-- timeout
    758  */
    759 #else
    760 extern CLIENT * clnt_create_timed();
    761 #endif
    762 
    763 /*
    764  * Generic client creation routine. Supported protocols are which belong
    765  * to the nettype name space.
    766  */
    767 #ifdef __STDC__
    768 extern CLIENT * clnt_create_vers(const char *, const rpcprog_t, rpcvers_t *,
    769 	const rpcvers_t, const rpcvers_t, const char *);
    770 /*
    771  *	const char *host;		-- hostname
    772  *	const rpcprog_t prog;		-- program number
    773  *	rpcvers_t *vers_out;	-- servers highest available version number
    774  *	const rpcvers_t vers_low;	-- low version number
    775  *	const rpcvers_t vers_high;	-- high version number
    776  *	const char *nettype;		-- network type
    777  */
    778 #else
    779 extern CLIENT * clnt_create_vers();
    780 #endif
    781 
    782 /*
    783  * Generic client creation routine. Supported protocols are which belong
    784  * to the nettype name space.
    785  */
    786 #ifdef __STDC__
    787 extern CLIENT * clnt_create_vers_timed(const char *, const rpcprog_t,
    788 	rpcvers_t *, const rpcvers_t, const rpcvers_t, const char *,
    789 	const struct timeval *);
    790 /*
    791  *	const char *host;		-- hostname
    792  *	const rpcprog_t prog;		-- program number
    793  *	rpcvers_t *vers_out;	-- servers highest available version number
    794  *	const rpcvers_t vers_low;	-- low version number
    795  *	const prcvers_t vers_high;	-- high version number
    796  *	const char *nettype;		-- network type
    797  *	const struct timeval *tp	-- timeout
    798  */
    799 #else
    800 extern CLIENT * clnt_create_vers_timed();
    801 #endif
    802 
    803 
    804 /*
    805  * Generic client creation routine. It takes a netconfig structure
    806  * instead of nettype
    807  */
    808 #ifdef __STDC__
    809 extern CLIENT * clnt_tp_create(const char *, const rpcprog_t, const rpcvers_t,
    810 	const struct netconfig *);
    811 /*
    812  *	const char *hostname;			-- hostname
    813  *	const rpcprog_t prog;			-- program number
    814  *	const rpcvers_t vers;			-- version number
    815  *	const struct netconfig *netconf; 	-- network config structure
    816  */
    817 #else
    818 extern CLIENT * clnt_tp_create();
    819 #endif
    820 
    821 /*
    822  * Generic client creation routine. Just like clnt_tp_create(), except
    823  * it takes an additional timeout parameter.
    824  */
    825 #ifdef __STDC__
    826 extern CLIENT * clnt_tp_create_timed(const char *, const rpcprog_t,
    827 	const rpcvers_t, const struct netconfig *, const struct timeval *);
    828 /*
    829  *	const char *hostname;			-- hostname
    830  *	const rpcprog_t prog;			-- program number
    831  *	const rpcvers_t vers;			-- version number
    832  *	const struct netconfig *netconf; 	-- network config structure
    833  *	const struct timeval *tp;		-- timeout
    834  */
    835 #else
    836 extern CLIENT * clnt_tp_create_timed();
    837 #endif
    838 
    839 /*
    840  * Generic TLI create routine
    841  */
    842 
    843 #ifdef __STDC__
    844 extern CLIENT * clnt_tli_create(const int, const struct netconfig *,
    845 	struct netbuf *, const rpcprog_t, const rpcvers_t, const uint_t,
    846 	const uint_t);
    847 /*
    848  *	const int fd;		-- fd
    849  *	const struct netconfig *nconf;	-- netconfig structure
    850  *	struct netbuf *svcaddr;		-- servers address
    851  *	const rpcprog_t prog;		-- program number
    852  *	const rpcvers_t vers;		-- version number
    853  *	const uint_t sendsz;		-- send size
    854  *	const uint_t recvsz;		-- recv size
    855  */
    856 
    857 #else
    858 extern CLIENT * clnt_tli_create();
    859 #endif
    860 
    861 /*
    862  * Low level clnt create routine for connectionful transports, e.g. tcp.
    863  */
    864 #ifdef __STDC__
    865 extern  CLIENT * clnt_vc_create(const int, struct netbuf *,
    866 	const rpcprog_t, const rpcvers_t, const uint_t, const uint_t);
    867 /*
    868  *	const int fd;				-- open file descriptor
    869  *	const struct netbuf *svcaddr;		-- servers address
    870  *	const rpcprog_t prog;			-- program number
    871  *	const rpcvers_t vers;			-- version number
    872  *	const uint_t sendsz;			-- buffer recv size
    873  *	const uint_t recvsz;			-- buffer send size
    874  */
    875 #else
    876 extern CLIENT * clnt_vc_create();
    877 #endif
    878 
    879 /*
    880  * Low level clnt create routine for connectionless transports, e.g. udp.
    881  */
    882 #ifdef __STDC__
    883 extern  CLIENT * clnt_dg_create(const int, struct netbuf *,
    884 	const rpcprog_t, const rpcvers_t, const uint_t, const uint_t);
    885 /*
    886  *	const int fd;				-- open file descriptor
    887  *	const struct netbuf *svcaddr;		-- servers address
    888  *	const rpcprog_t program;		-- program number
    889  *	const rpcvers_t version;		-- version number
    890  *	const uint_t sendsz;			-- buffer recv size
    891  *	const uint_t recvsz;			-- buffer send size
    892  */
    893 #else
    894 extern CLIENT * clnt_dg_create();
    895 #endif
    896 
    897 /*
    898  * Memory based rpc (for speed check and testing)
    899  * CLIENT *
    900  * clnt_raw_create(prog, vers)
    901  *	const rpcprog_t prog;			-- program number
    902  *	const rpcvers_t vers;			-- version number
    903  */
    904 #ifdef __STDC__
    905 extern CLIENT *clnt_raw_create(const rpcprog_t, const rpcvers_t);
    906 #else
    907 extern CLIENT *clnt_raw_create();
    908 #endif
    909 
    910 /*
    911  * Client creation routine over doors transport.
    912  */
    913 #ifdef __STDC__
    914 extern  CLIENT * clnt_door_create(const rpcprog_t, const rpcvers_t,
    915 	const uint_t);
    916 /*
    917  *	const rpcprog_t prog;			-- program number
    918  *	const rpcvers_t vers;			-- version number
    919  *	const uint_t sendsz;			-- max send size
    920  */
    921 #else
    922 extern CLIENT * clnt_door_create();
    923 #endif
    924 
    925 /*
    926  * internal function. Not for general use. Subject to rapid change.
    927  */
    928 #ifdef __STDC__
    929 extern CLIENT *clnt_create_service_timed(const char *,
    930 					const char *,
    931 					const rpcprog_t,
    932 					const rpcvers_t,
    933 					const ushort_t,
    934 					const char *,
    935 					const struct timeval *);
    936 #else
    937 extern CLIENT *clnt_create_service_timed();
    938 #endif
    939 
    940 /*
    941  * Print why creation failed
    942  */
    943 #ifdef __STDC__
    944 void clnt_pcreateerror(const char *);	/* stderr */
    945 char *clnt_spcreateerror(const char *);	/* string */
    946 #else
    947 void clnt_pcreateerror();
    948 char *clnt_spcreateerror();
    949 #endif
    950 
    951 /*
    952  * Like clnt_perror(), but is more verbose in its output
    953  */
    954 #ifdef __STDC__
    955 void clnt_perrno(const enum clnt_stat);	/* stderr */
    956 #else
    957 void clnt_perrno();
    958 #endif
    959 
    960 /*
    961  * Print an error message, given the client error code
    962  */
    963 #ifdef __STDC__
    964 void clnt_perror(const CLIENT *, const char *);
    965 #else
    966 void clnt_perror();
    967 #endif
    968 
    969 /*
    970  * If a creation fails, the following allows the user to figure out why.
    971  */
    972 struct rpc_createerr {
    973 	enum clnt_stat cf_stat;
    974 	struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
    975 };
    976 
    977 #ifdef	_REENTRANT
    978 extern struct rpc_createerr	*__rpc_createerr();
    979 #define	rpc_createerr	(*(__rpc_createerr()))
    980 #else
    981 extern struct rpc_createerr rpc_createerr;
    982 #endif	/* _REENTRANT */
    983 
    984 /*
    985  * The simplified interface:
    986  * enum clnt_stat
    987  * rpc_call(host, prognum, versnum, procnum, inproc, in, outproc, out, nettype)
    988  *	const char *host;
    989  *	const rpcprog_t prognum;
    990  *	const rpcvers_t versnum;
    991  *	const rpcproc_t procnum;
    992  *	const xdrproc_t inproc, outproc;
    993  *	const char *in;
    994  *	char *out;
    995  *	const char *nettype;
    996  */
    997 #ifdef __STDC__
    998 extern enum clnt_stat rpc_call(const char *, const rpcprog_t, const rpcvers_t,
    999 	const rpcproc_t, const xdrproc_t, const char *, const xdrproc_t,
   1000 	char *, const char *);
   1001 #else
   1002 extern enum clnt_stat rpc_call();
   1003 #endif
   1004 
   1005 #ifdef	_REENTRANT
   1006 extern struct rpc_err	*__rpc_callerr();
   1007 #define	rpc_callerr	(*(__rpc_callerr()))
   1008 #else
   1009 extern struct rpc_err rpc_callerr;
   1010 #endif	/* _REENTRANT */
   1011 
   1012 /*
   1013  * RPC broadcast interface
   1014  * The call is broadcasted to all locally connected nets.
   1015  *
   1016  * extern enum clnt_stat
   1017  * rpc_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp,
   1018  *			eachresult, nettype)
   1019  *	const rpcprog_t		prog;		-- program number
   1020  *	const rpcvers_t		vers;		-- version number
   1021  *	const rpcproc_t		proc;		-- procedure number
   1022  *	const xdrproc_t	xargs;		-- xdr routine for args
   1023  *	caddr_t		argsp;		-- pointer to args
   1024  *	const xdrproc_t	xresults;	-- xdr routine for results
   1025  *	caddr_t		resultsp;	-- pointer to results
   1026  *	const resultproc_t	eachresult;	-- call with each result
   1027  *	const char		*nettype;	-- Transport type
   1028  *
   1029  * For each valid response received, the procedure eachresult is called.
   1030  * Its form is:
   1031  *		done = eachresult(resp, raddr, nconf)
   1032  *			bool_t done;
   1033  *			caddr_t resp;
   1034  *			struct netbuf *raddr;
   1035  *			struct netconfig *nconf;
   1036  * where resp points to the results of the call and raddr is the
   1037  * address if the responder to the broadcast.  nconf is the transport
   1038  * on which the response was received.
   1039  *
   1040  * extern enum clnt_stat
   1041  * rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp,
   1042  *			eachresult, inittime, waittime, nettype)
   1043  *	const rpcprog_t		prog;		-- program number
   1044  *	const rpcvers_t		vers;		-- version number
   1045  *	const rpcproc_t		proc;		-- procedure number
   1046  *	const xdrproc_t	xargs;		-- xdr routine for args
   1047  *	caddr_t		argsp;		-- pointer to args
   1048  *	const xdrproc_t	xresults;	-- xdr routine for results
   1049  *	caddr_t		resultsp;	-- pointer to results
   1050  *	const resultproc_t	eachresult;	-- call with each result
   1051  *	const int 		inittime;	-- how long to wait initially
   1052  *	const int 		waittime;	-- maximum time to wait
   1053  *	const char		*nettype;	-- Transport type
   1054  */
   1055 
   1056 typedef bool_t(*resultproc_t)(
   1057 #ifdef	__STDC__
   1058 	caddr_t,
   1059 	... /* for backward compatibility */
   1060 #endif				/* __STDC__ */
   1061 );
   1062 #ifdef __STDC__
   1063 extern enum clnt_stat rpc_broadcast(const rpcprog_t, const rpcvers_t,
   1064 	const rpcproc_t, const xdrproc_t, caddr_t, const xdrproc_t,
   1065 	caddr_t, const resultproc_t, const char *);
   1066 extern enum clnt_stat rpc_broadcast_exp(const rpcprog_t, const rpcvers_t,
   1067 	const rpcproc_t, const xdrproc_t, caddr_t, const xdrproc_t, caddr_t,
   1068 	const resultproc_t, const int, const int, const char *);
   1069 #else
   1070 extern enum clnt_stat rpc_broadcast();
   1071 extern enum clnt_stat rpc_broadcast_exp();
   1072 #endif
   1073 #endif /* !_KERNEL */
   1074 
   1075 /*
   1076  * Copy error message to buffer.
   1077  */
   1078 #ifdef __STDC__
   1079 const char *clnt_sperrno(const enum clnt_stat);
   1080 #else
   1081 char *clnt_sperrno();	/* string */
   1082 #endif
   1083 
   1084 /*
   1085  * Print an error message, given the client error code
   1086  */
   1087 #ifdef __STDC__
   1088 char *clnt_sperror(const CLIENT *, const char *);
   1089 #else
   1090 char *clnt_sperror();
   1091 #endif
   1092 
   1093 /*
   1094  * Client side rpc control routine for rpcbind.
   1095  */
   1096 #ifdef __STDC__
   1097 bool_t __rpc_control(int, void *);
   1098 #else
   1099 bool_t __rpc_control();
   1100 #endif
   1101 
   1102 #ifdef __cplusplus
   1103 }
   1104 #endif
   1105 
   1106 #ifdef PORTMAP
   1107 /* For backward compatibility */
   1108 #include <rpc/clnt_soc.h>
   1109 #endif
   1110 
   1111 #endif	/* !_RPC_CLNT_H */
   1112