xref: /titanic_52/usr/src/uts/common/rpc/clnt.h (revision 1cb6af97c6f66f456d4f726ef056e1ebc0f73305)
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	"%Z%%M%	%I%	%E% 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@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@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 int clnt_tli_kcreate(struct knetconfig *config, struct netbuf *svcaddr,
344 	rpcprog_t, rpcvers_t, uint_t max_msgsize, int retrys,
345 	struct cred *cred, CLIENT **ncl);
346 
347 extern int clnt_tli_kinit(CLIENT *h, struct knetconfig *config,
348 	struct netbuf *addr, uint_t max_msgsize, int retries,
349 	struct cred *cred);
350 
351 extern int rpc_uaddr2port(int af, char *addr);
352 
353 /*
354  * kRPC internal function. Not for general use. Subject to rapid change.
355  */
356 extern int bindresvport(TIUSER *tiptr, struct netbuf *addr,
357 	struct netbuf *bound_addr, bool_t istcp);
358 
359 /*
360  * kRPC internal function. Not for general use. Subject to rapid change.
361  */
362 extern int clnt_clts_kcreate(struct knetconfig *config, struct netbuf *addr,
363 	rpcprog_t, rpcvers_t, int retries, struct cred *cred, CLIENT **cl);
364 
365 /*
366  * kRPC internal function. Not for general use. Subject to rapid change.
367  */
368 extern int clnt_cots_kcreate(dev_t dev, struct netbuf *addr, int family,
369 	rpcprog_t, rpcvers_t, uint_t max_msgsize, struct cred *cred,
370 	CLIENT **ncl);
371 /*
372  * kRPC internal function. Not for general use. Subject to rapid change.
373  */
374 extern int clnt_rdma_kcreate(char *proto, void *handle, struct netbuf *raddr,
375 	int family, rpcprog_t pgm, rpcvers_t vers, struct cred *cred,
376 	CLIENT **cl);
377 /*
378  * kRPC internal function. Not for general use. Subject to rapid change.
379  */
380 extern int rdma_reachable(int addr_type, struct netbuf *addr,
381 	struct knetconfig **knconf);
382 
383 /*
384  * kRPC internal function. Not for general use. Subject to rapid change.
385  */
386 extern void clnt_clts_kinit(CLIENT *h, struct netbuf *addr, int retries,
387 	struct cred *cred);
388 
389 /*
390  * kRPC internal function. Not for general use. Subject to rapid change.
391  */
392 extern void clnt_cots_kinit(CLIENT *h, dev_t dev, int family,
393 	struct netbuf *addr, int max_msgsize, struct cred *cred);
394 
395 /*
396  * kRPC internal function. Not for general use. Subject to rapid change.
397  */
398 extern void clnt_rdma_kinit(CLIENT *h, char *proto, void *handle,
399 	struct netbuf *addr, struct cred *cred);
400 
401 /*
402  * kRPC internal function. Not for general use. Subject to rapid change.
403  */
404 extern bool_t clnt_dispatch_notify(mblk_t *, zoneid_t);
405 
406 /*
407  * kRPC internal function. Not for general use. Subject to rapid change.
408  */
409 extern bool_t clnt_dispatch_notifyconn(queue_t *, mblk_t *);
410 
411 /*
412  * kRPC internal function. Not for general use. Subject to rapid change.
413  */
414 extern void clnt_dispatch_notifyall(queue_t *, int32_t, int32_t);
415 
416 /*
417  * kRPC internal function. Not for general use. Subject to rapid change.
418  */
419 extern enum clnt_stat clnt_clts_kcallit_addr(CLIENT *, rpcproc_t, xdrproc_t,
420 	caddr_t, xdrproc_t, caddr_t, struct timeval, struct netbuf *);
421 
422 /*
423  * kRPC internal function. Not for general use. Subject to rapid change.
424  */
425 extern call_table_t *call_table_init(int);
426 
427 /*
428  * kRPC internal function. Not for general use. Subject to rapid change.
429  */
430 extern void clnt_init(void);
431 
432 /*
433  * kRPC internal function. Not for general use. Subject to rapid change.
434  */
435 extern void clnt_fini(void);
436 
437 /*
438  * kRPC internal function. Not for general use. Subject to rapid change.
439  */
440 extern void clnt_clts_init(void);
441 
442 /*
443  * kRPC internal function. Not for general use. Subject to rapid change.
444  */
445 extern void clnt_clts_fini(void);
446 
447 /*
448  * kRPC internal function. Not for general use. Subject to rapid change.
449  */
450 extern void clnt_cots_init(void);
451 
452 /*
453  * kRPC internal function. Not for general use. Subject to rapid change.
454  */
455 extern void clnt_cots_fini(void);
456 
457 /*
458  * kRPC internal function. Not for general use. Subject to rapid change.
459  */
460 extern void clnt_clts_dispatch_notify(mblk_t *, int, zoneid_t);
461 
462 extern void rpc_poptimod(struct vnode *);
463 extern int kstr_push(struct vnode *, char *);
464 extern void t_kadvise(TIUSER *, uchar_t *, int);
465 
466 extern boolean_t connmgr_cpr_reset(void *, int);
467 
468 extern void put_inet_port(struct netbuf *, ushort_t);
469 extern void put_inet6_port(struct netbuf *, ushort_t);
470 extern void put_loopback_port(struct netbuf *, char *);
471 extern enum clnt_stat rpcbind_getaddr(struct knetconfig *, rpcprog_t,
472     rpcvers_t, struct netbuf *);
473 
474 /*
475  * Kstat stuff
476  */
477 #include <sys/zone.h>
478 
479 extern zone_key_t rpcstat_zone_key;
480 
481 struct rpc_clts_client;		/* unix:0:rpc_clts_client */
482 struct rpc_clts_server;		/* unix:0:rpc_clts_server */
483 struct rpc_cots_client;		/* unix:0:rpc_cots_client */
484 struct rpc_cots_server;		/* unix:0:rpc_cots_server */
485 
486 struct rpcstat {
487 	struct rpc_clts_client *rpc_clts_client;
488 	struct rpc_clts_server *rpc_clts_server;
489 	struct rpc_cots_client *rpc_cots_client;
490 	struct rpc_cots_server *rpc_cots_server;
491 };
492 
493 extern kstat_named_t *rpcstat_zone_init_common(zoneid_t, const char *,
494     const char *, const kstat_named_t *, size_t);
495 extern void rpcstat_zone_fini_common(zoneid_t, const char *, const char *);
496 
497 extern void clnt_clts_stats_init(zoneid_t, struct rpc_clts_client **);
498 extern void clnt_clts_stats_fini(zoneid_t, struct rpc_clts_client **);
499 
500 extern void svc_clts_stats_init(zoneid_t, struct rpc_clts_server **);
501 extern void svc_clts_stats_fini(zoneid_t, struct rpc_clts_server **);
502 
503 extern void clnt_cots_stats_init(zoneid_t, struct rpc_cots_client **);
504 extern void clnt_cots_stats_fini(zoneid_t, struct rpc_cots_client **);
505 
506 extern void svc_cots_stats_init(zoneid_t, struct rpc_cots_server **);
507 extern void svc_cots_stats_fini(zoneid_t, struct rpc_cots_server **);
508 
509 #endif /* _KERNEL */
510 
511 /*
512  * client side rpc interface ops
513  */
514 
515 /*
516  * enum clnt_stat
517  * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
518  * 	CLIENT *rh;
519  *	rpcproc_t proc;
520  *	xdrproc_t xargs;
521  *	caddr_t argsp;
522  *	xdrproc_t xres;
523  *	caddr_t resp;
524  *	struct timeval timeout;
525  *
526  * PSARC 2003/523 Contract Private Interface
527  * CLNT_CALL
528  * Changes must be reviewed by Solaris File Sharing
529  * Changes must be communicated to contract-2003-523@sun.com
530  */
531 #define	CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs)	\
532 	((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
533 #define	clnt_call(rh, proc, xargs, argsp, xres, resp, secs)	\
534 	((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
535 
536 #ifndef _KERNEL
537 /*
538  * enum clnt_stat
539  * CLNT_SEND(rh, proc, xargs, argsp)
540  * 	CLIENT *rh;
541  *	rpcproc_t proc;
542  *	xdrproc_t xargs;
543  *	caddr_t argsp;
544  *
545  * PSARC 2000/428  Contract Private Interface
546  */
547 #define	CLNT_SEND(rh, proc, xargs, argsp)	\
548 	((*(rh)->cl_ops->cl_send)(rh, proc, xargs, argsp))
549 #define	clnt_send(rh, proc, xargs, argsp)	\
550 	((*(rh)->cl_ops->cl_send)(rh, proc, xargs, argsp))
551 #endif /* !_KERNEL */
552 
553 /*
554  * void
555  * CLNT_ABORT(rh);
556  * 	CLIENT *rh;
557  */
558 #define	CLNT_ABORT(rh)	((*(rh)->cl_ops->cl_abort)(rh))
559 #define	clnt_abort(rh)	((*(rh)->cl_ops->cl_abort)(rh))
560 
561 /*
562  * struct rpc_err
563  * CLNT_GETERR(rh);
564  * 	CLIENT *rh;
565  */
566 #define	CLNT_GETERR(rh, errp)	((*(rh)->cl_ops->cl_geterr)(rh, errp))
567 #define	clnt_geterr(rh, errp)	((*(rh)->cl_ops->cl_geterr)(rh, errp))
568 
569 /*
570  * bool_t
571  * CLNT_FREERES(rh, xres, resp);
572  * 	CLIENT *rh;
573  *	xdrproc_t xres;
574  *	caddr_t resp;
575  */
576 #define	CLNT_FREERES(rh, xres, resp) \
577 		((*(rh)->cl_ops->cl_freeres)(rh, xres, resp))
578 #define	clnt_freeres(rh, xres, resp) \
579 		((*(rh)->cl_ops->cl_freeres)(rh, xres, resp))
580 
581 /*
582  * bool_t
583  * CLNT_CONTROL(cl, request, info)
584  *	CLIENT *cl;
585  *	uint_t request;
586  *	char *info;
587  *
588  * PSARC 2003/523 Contract Private Interface
589  * CLNT_CONTROL
590  * Changes must be reviewed by Solaris File Sharing
591  * Changes must be communicated to contract-2003-523@sun.com
592  */
593 #define	CLNT_CONTROL(cl, rq, in) ((*(cl)->cl_ops->cl_control)(cl, rq, in))
594 #define	clnt_control(cl, rq, in) ((*(cl)->cl_ops->cl_control)(cl, rq, in))
595 
596 
597 /*
598  * control operations that apply to all transports
599  */
600 #define	CLSET_TIMEOUT		1	/* set timeout (timeval) */
601 #define	CLGET_TIMEOUT		2	/* get timeout (timeval) */
602 #define	CLGET_SERVER_ADDR	3	/* get server's address (sockaddr) */
603 #define	CLGET_FD		6	/* get connections file descriptor */
604 #define	CLGET_SVC_ADDR		7	/* get server's address (netbuf) */
605 #define	CLSET_FD_CLOSE		8	/* close fd while clnt_destroy */
606 #define	CLSET_FD_NCLOSE		9	/* Do not close fd while clnt_destroy */
607 #define	CLGET_XID 		10	/* Get xid */
608 #define	CLSET_XID		11	/* Set xid */
609 #define	CLGET_VERS		12	/* Get version number */
610 #define	CLSET_VERS		13	/* Set version number */
611 #define	CLGET_PROG		14	/* Get program number */
612 #define	CLSET_PROG		15	/* Set program number */
613 #define	CLSET_SVC_ADDR		16	/* get server's address (netbuf) */
614 #define	CLSET_PUSH_TIMOD	17	/* push timod if not already present */
615 #define	CLSET_POP_TIMOD		18	/* pop timod */
616 #ifndef _KERNEL
617 /* 00-08-17 - NON STANDARD CONTROL PARAMETER */
618 #define	CLSET_IO_MODE		19	/* clnt_send behavior */
619 #define	CLGET_IO_MODE		20	/* clnt_send behavior */
620 #define	CLSET_FLUSH_MODE	21	/* flush behavior */
621 #define	CLGET_FLUSH_MODE	22	/* flush behavior */
622 #define	CLFLUSH			23	/* flush now (user wants it) */
623 #define	CLSET_CONNMAXREC_SIZE	24	/* set pending request buffer size */
624 #define	CLGET_CONNMAXREC_SIZE	25	/* set pending request buffer size */
625 #define	CLGET_CURRENT_REC_SIZE	26	/* get pending request buffer size */
626 
627 typedef enum {
628 	RPC_CL_BESTEFFORT_FLUSH = 100,	/* flush as much as possible */
629 					/* without blocking */
630 	RPC_CL_BLOCKING_FLUSH,		/* flush the buffer completely */
631 					/* (possibly blocking) */
632 	RPC_CL_DEFAULT_FLUSH		/* flush according to the currently */
633 					/* defined policy. */
634 } rpcflushmode_t;
635 
636 
637 typedef enum {
638 	RPC_CL_BLOCKING = 10,	/* PASSED CLNT_CONTROL SET_IO_MODE */
639 	RPC_CL_NONBLOCKING
640 } rpciomode_t;
641 #endif /* !_KERNEL */
642 /*
643  * Connectionless only control operations
644  */
645 #define	CLSET_RETRY_TIMEOUT 4   /* set retry timeout (timeval) */
646 #define	CLGET_RETRY_TIMEOUT 5   /* get retry timeout (timeval) */
647 
648 #ifdef	_KERNEL
649 /*
650  * Connection oriented only control operation.
651  */
652 #define	CLSET_PROGRESS		10000	/* Report RPC_INPROGRESS if a request */
653 					/* has been sent but no reply */
654 					/* received yet. */
655 #define	CLSET_BCAST		10001	/* Set RPC Broadcast hint */
656 #define	CLGET_BCAST		10002	/* Get RPC Broadcast hint */
657 #define	CLSET_NODELAYONERR	10003	/* Set enable/disable of delay on */
658 					/* connection setup error	  */
659 #define	CLGET_NODELAYONERR	10004	/* Get enable/disable of delay on */
660 					/* connection setup error	  */
661 #define	CLSET_BINDRESVPORT	10005	/* Set preference for reserve port */
662 #define	CLGET_BINDRESVPORT	10006	/* Get preference for reserve port */
663 #endif
664 
665 /*
666  * void
667  * CLNT_SETTIMERS(rh);
668  *	CLIENT *rh;
669  *	struct rpc_timers *t;
670  *	struct rpc_timers *all;
671  *	unsigned int min;
672  *	void    (*fdbck)();
673  *	caddr_t arg;
674  *	uint_t  xid;
675  */
676 #define	CLNT_SETTIMERS(rh, t, all, min, fdbck, arg, xid) \
677 		((*(rh)->cl_ops->cl_settimers)(rh, t, all, min, \
678 		fdbck, arg, xid))
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 
683 
684 /*
685  * void
686  * CLNT_DESTROY(rh);
687  * 	CLIENT *rh;
688  *
689  * PSARC 2003/523 Contract Private Interface
690  * CLNT_DESTROY
691  * Changes must be reviewed by Solaris File Sharing
692  * Changes must be communicated to contract-2003-523@sun.com
693  */
694 #define	CLNT_DESTROY(rh)	((*(rh)->cl_ops->cl_destroy)(rh))
695 #define	clnt_destroy(rh)	((*(rh)->cl_ops->cl_destroy)(rh))
696 
697 
698 /*
699  * RPCTEST is a test program which is accessable on every rpc
700  * transport/port.  It is used for testing, performance evaluation,
701  * and network administration.
702  */
703 
704 #define	RPCTEST_PROGRAM		((rpcprog_t)1)
705 #define	RPCTEST_VERSION		((rpcvers_t)1)
706 #define	RPCTEST_NULL_PROC	((rpcproc_t)2)
707 #define	RPCTEST_NULL_BATCH_PROC	((rpcproc_t)3)
708 
709 /*
710  * By convention, procedure 0 takes null arguments and returns them
711  */
712 
713 #define	NULLPROC ((rpcproc_t)0)
714 
715 /*
716  * Below are the client handle creation routines for the various
717  * implementations of client side rpc.  They can return NULL if a
718  * creation failure occurs.
719  */
720 
721 #ifndef _KERNEL
722 
723 /*
724  * Generic client creation routine. Supported protocols are which belong
725  * to the nettype name space
726  */
727 #ifdef __STDC__
728 extern  CLIENT * clnt_create(const char *, const rpcprog_t, const rpcvers_t,
729 	const char *);
730 /*
731  *
732  * 	const char *hostname;			-- hostname
733  *	const rpcprog_t prog;			-- program number
734  *	const rpcvers_t vers;			-- version number
735  *	const char *nettype;			-- network type
736  */
737 #else
738 extern CLIENT * clnt_create();
739 #endif
740 
741 /*
742  * Generic client creation routine. Just like clnt_create(), except
743  * it takes an additional timeout parameter.
744  */
745 #ifdef __STDC__
746 extern  CLIENT * clnt_create_timed(const char *, const rpcprog_t,
747 	const rpcvers_t, const char *, const struct timeval *);
748 /*
749  *
750  * 	const char *hostname;			-- hostname
751  *	const rpcprog_t prog;			-- program number
752  *	const rpcvers_t vers;			-- version number
753  *	const char *nettype;			-- network type
754  *	const struct timeval *tp;		-- timeout
755  */
756 #else
757 extern CLIENT * clnt_create_timed();
758 #endif
759 
760 /*
761  * Generic client creation routine. Supported protocols are which belong
762  * to the nettype name space.
763  */
764 #ifdef __STDC__
765 extern CLIENT * clnt_create_vers(const char *, const rpcprog_t, rpcvers_t *,
766 	const rpcvers_t, const rpcvers_t, const char *);
767 /*
768  *	const char *host;		-- hostname
769  *	const rpcprog_t prog;		-- program number
770  *	rpcvers_t *vers_out;	-- servers highest available version number
771  *	const rpcvers_t vers_low;	-- low version number
772  *	const rpcvers_t vers_high;	-- high version number
773  *	const char *nettype;		-- network type
774  */
775 #else
776 extern CLIENT * clnt_create_vers();
777 #endif
778 
779 /*
780  * Generic client creation routine. Supported protocols are which belong
781  * to the nettype name space.
782  */
783 #ifdef __STDC__
784 extern CLIENT * clnt_create_vers_timed(const char *, const rpcprog_t,
785 	rpcvers_t *, const rpcvers_t, const rpcvers_t, const char *,
786 	const struct timeval *);
787 /*
788  *	const char *host;		-- hostname
789  *	const rpcprog_t prog;		-- program number
790  *	rpcvers_t *vers_out;	-- servers highest available version number
791  *	const rpcvers_t vers_low;	-- low version number
792  *	const prcvers_t vers_high;	-- high version number
793  *	const char *nettype;		-- network type
794  *	const struct timeval *tp	-- timeout
795  */
796 #else
797 extern CLIENT * clnt_create_vers_timed();
798 #endif
799 
800 
801 /*
802  * Generic client creation routine. It takes a netconfig structure
803  * instead of nettype
804  */
805 #ifdef __STDC__
806 extern CLIENT * clnt_tp_create(const char *, const rpcprog_t, const rpcvers_t,
807 	const struct netconfig *);
808 /*
809  *	const char *hostname;			-- hostname
810  *	const rpcprog_t prog;			-- program number
811  *	const rpcvers_t vers;			-- version number
812  *	const struct netconfig *netconf; 	-- network config structure
813  */
814 #else
815 extern CLIENT * clnt_tp_create();
816 #endif
817 
818 /*
819  * Generic client creation routine. Just like clnt_tp_create(), except
820  * it takes an additional timeout parameter.
821  */
822 #ifdef __STDC__
823 extern CLIENT * clnt_tp_create_timed(const char *, const rpcprog_t,
824 	const rpcvers_t, const struct netconfig *, const struct timeval *);
825 /*
826  *	const char *hostname;			-- hostname
827  *	const rpcprog_t prog;			-- program number
828  *	const rpcvers_t vers;			-- version number
829  *	const struct netconfig *netconf; 	-- network config structure
830  *	const struct timeval *tp;		-- timeout
831  */
832 #else
833 extern CLIENT * clnt_tp_create_timed();
834 #endif
835 
836 /*
837  * Generic TLI create routine
838  */
839 
840 #ifdef __STDC__
841 extern CLIENT * clnt_tli_create(const int, const struct netconfig *,
842 	struct netbuf *, const rpcprog_t, const rpcvers_t, const uint_t,
843 	const uint_t);
844 /*
845  *	const int fd;		-- fd
846  *	const struct netconfig *nconf;	-- netconfig structure
847  *	struct netbuf *svcaddr;		-- servers address
848  *	const rpcprog_t prog;		-- program number
849  *	const rpcvers_t vers;		-- version number
850  *	const uint_t sendsz;		-- send size
851  *	const uint_t recvsz;		-- recv size
852  */
853 
854 #else
855 extern CLIENT * clnt_tli_create();
856 #endif
857 
858 /*
859  * Low level clnt create routine for connectionful transports, e.g. tcp.
860  */
861 #ifdef __STDC__
862 extern  CLIENT * clnt_vc_create(const int, struct netbuf *,
863 	const rpcprog_t, const rpcvers_t, const uint_t, const uint_t);
864 /*
865  *	const int fd;				-- open file descriptor
866  *	const struct netbuf *svcaddr;		-- servers address
867  *	const rpcprog_t prog;			-- program number
868  *	const rpcvers_t vers;			-- version number
869  *	const uint_t sendsz;			-- buffer recv size
870  *	const uint_t recvsz;			-- buffer send size
871  */
872 #else
873 extern CLIENT * clnt_vc_create();
874 #endif
875 
876 /*
877  * Low level clnt create routine for connectionless transports, e.g. udp.
878  */
879 #ifdef __STDC__
880 extern  CLIENT * clnt_dg_create(const int, struct netbuf *,
881 	const rpcprog_t, const rpcvers_t, const uint_t, const uint_t);
882 /*
883  *	const int fd;				-- open file descriptor
884  *	const struct netbuf *svcaddr;		-- servers address
885  *	const rpcprog_t program;		-- program number
886  *	const rpcvers_t version;		-- version number
887  *	const uint_t sendsz;			-- buffer recv size
888  *	const uint_t recvsz;			-- buffer send size
889  */
890 #else
891 extern CLIENT * clnt_dg_create();
892 #endif
893 
894 /*
895  * Memory based rpc (for speed check and testing)
896  * CLIENT *
897  * clnt_raw_create(prog, vers)
898  *	const rpcprog_t prog;			-- program number
899  *	const rpcvers_t vers;			-- version number
900  */
901 #ifdef __STDC__
902 extern CLIENT *clnt_raw_create(const rpcprog_t, const rpcvers_t);
903 #else
904 extern CLIENT *clnt_raw_create();
905 #endif
906 
907 /*
908  * Client creation routine over doors transport.
909  */
910 #ifdef __STDC__
911 extern  CLIENT * clnt_door_create(const rpcprog_t, const rpcvers_t,
912 	const uint_t);
913 /*
914  *	const rpcprog_t prog;			-- program number
915  *	const rpcvers_t vers;			-- version number
916  *	const uint_t sendsz;			-- max send size
917  */
918 #else
919 extern CLIENT * clnt_door_create();
920 #endif
921 
922 /*
923  * internal function. Not for general use. Subject to rapid change.
924  */
925 #ifdef __STDC__
926 extern CLIENT *clnt_create_service_timed(const char *,
927 					const char *,
928 					const rpcprog_t,
929 					const rpcvers_t,
930 					const ushort_t,
931 					const char *,
932 					const struct timeval *);
933 #else
934 extern CLIENT *clnt_create_service_timed();
935 #endif
936 
937 /*
938  * Print why creation failed
939  */
940 #ifdef __STDC__
941 void clnt_pcreateerror(const char *);	/* stderr */
942 char *clnt_spcreateerror(const char *);	/* string */
943 #else
944 void clnt_pcreateerror();
945 char *clnt_spcreateerror();
946 #endif
947 
948 /*
949  * Like clnt_perror(), but is more verbose in its output
950  */
951 #ifdef __STDC__
952 void clnt_perrno(const enum clnt_stat);	/* stderr */
953 #else
954 void clnt_perrno();
955 #endif
956 
957 /*
958  * Print an error message, given the client error code
959  */
960 #ifdef __STDC__
961 void clnt_perror(const CLIENT *, const char *);
962 #else
963 void clnt_perror();
964 #endif
965 
966 /*
967  * If a creation fails, the following allows the user to figure out why.
968  */
969 struct rpc_createerr {
970 	enum clnt_stat cf_stat;
971 	struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
972 };
973 
974 #ifdef	_REENTRANT
975 extern struct rpc_createerr	*__rpc_createerr();
976 #define	rpc_createerr	(*(__rpc_createerr()))
977 #else
978 extern struct rpc_createerr rpc_createerr;
979 #endif	/* _REENTRANT */
980 
981 /*
982  * The simplified interface:
983  * enum clnt_stat
984  * rpc_call(host, prognum, versnum, procnum, inproc, in, outproc, out, nettype)
985  *	const char *host;
986  *	const rpcprog_t prognum;
987  *	const rpcvers_t versnum;
988  *	const rpcproc_t procnum;
989  *	const xdrproc_t inproc, outproc;
990  *	const char *in;
991  *	char *out;
992  *	const char *nettype;
993  */
994 #ifdef __STDC__
995 extern enum clnt_stat rpc_call(const char *, const rpcprog_t, const rpcvers_t,
996 	const rpcproc_t, const xdrproc_t, const char *, const xdrproc_t,
997 	char *, const char *);
998 #else
999 extern enum clnt_stat rpc_call();
1000 #endif
1001 
1002 #ifdef	_REENTRANT
1003 extern struct rpc_err	*__rpc_callerr();
1004 #define	rpc_callerr	(*(__rpc_callerr()))
1005 #else
1006 extern struct rpc_err rpc_callerr;
1007 #endif	/* _REENTRANT */
1008 
1009 /*
1010  * RPC broadcast interface
1011  * The call is broadcasted to all locally connected nets.
1012  *
1013  * extern enum clnt_stat
1014  * rpc_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp,
1015  *			eachresult, nettype)
1016  *	const rpcprog_t		prog;		-- program number
1017  *	const rpcvers_t		vers;		-- version number
1018  *	const rpcproc_t		proc;		-- procedure number
1019  *	const xdrproc_t	xargs;		-- xdr routine for args
1020  *	caddr_t		argsp;		-- pointer to args
1021  *	const xdrproc_t	xresults;	-- xdr routine for results
1022  *	caddr_t		resultsp;	-- pointer to results
1023  *	const resultproc_t	eachresult;	-- call with each result
1024  *	const char		*nettype;	-- Transport type
1025  *
1026  * For each valid response received, the procedure eachresult is called.
1027  * Its form is:
1028  *		done = eachresult(resp, raddr, nconf)
1029  *			bool_t done;
1030  *			caddr_t resp;
1031  *			struct netbuf *raddr;
1032  *			struct netconfig *nconf;
1033  * where resp points to the results of the call and raddr is the
1034  * address if the responder to the broadcast.  nconf is the transport
1035  * on which the response was received.
1036  *
1037  * extern enum clnt_stat
1038  * rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp,
1039  *			eachresult, inittime, waittime, nettype)
1040  *	const rpcprog_t		prog;		-- program number
1041  *	const rpcvers_t		vers;		-- version number
1042  *	const rpcproc_t		proc;		-- procedure number
1043  *	const xdrproc_t	xargs;		-- xdr routine for args
1044  *	caddr_t		argsp;		-- pointer to args
1045  *	const xdrproc_t	xresults;	-- xdr routine for results
1046  *	caddr_t		resultsp;	-- pointer to results
1047  *	const resultproc_t	eachresult;	-- call with each result
1048  *	const int 		inittime;	-- how long to wait initially
1049  *	const int 		waittime;	-- maximum time to wait
1050  *	const char		*nettype;	-- Transport type
1051  */
1052 
1053 typedef bool_t(*resultproc_t)(
1054 #ifdef	__STDC__
1055 	caddr_t,
1056 	... /* for backward compatibility */
1057 #endif				/* __STDC__ */
1058 );
1059 #ifdef __STDC__
1060 extern enum clnt_stat rpc_broadcast(const rpcprog_t, const rpcvers_t,
1061 	const rpcproc_t, const xdrproc_t, caddr_t, const xdrproc_t,
1062 	caddr_t, const resultproc_t, const char *);
1063 extern enum clnt_stat rpc_broadcast_exp(const rpcprog_t, const rpcvers_t,
1064 	const rpcproc_t, const xdrproc_t, caddr_t, const xdrproc_t, caddr_t,
1065 	const resultproc_t, const int, const int, const char *);
1066 #else
1067 extern enum clnt_stat rpc_broadcast();
1068 extern enum clnt_stat rpc_broadcast_exp();
1069 #endif
1070 #endif /* !_KERNEL */
1071 
1072 /*
1073  * Copy error message to buffer.
1074  */
1075 #ifdef __STDC__
1076 const char *clnt_sperrno(const enum clnt_stat);
1077 #else
1078 char *clnt_sperrno();	/* string */
1079 #endif
1080 
1081 /*
1082  * Print an error message, given the client error code
1083  */
1084 #ifdef __STDC__
1085 char *clnt_sperror(const CLIENT *, const char *);
1086 #else
1087 char *clnt_sperror();
1088 #endif
1089 
1090 /*
1091  * Client side rpc control routine for rpcbind.
1092  */
1093 #ifdef __STDC__
1094 bool_t __rpc_control(int, void *);
1095 #else
1096 bool_t __rpc_control();
1097 #endif
1098 
1099 #ifdef __cplusplus
1100 }
1101 #endif
1102 
1103 #ifdef PORTMAP
1104 /* For backward compatibility */
1105 #include <rpc/clnt_soc.h>
1106 #endif
1107 
1108 #endif	/* !_RPC_CLNT_H */
1109