Home | History | Annotate | Line # | Download | only in rpc
svc_vc.c revision 1.26
      1  1.26      matt /*	$NetBSD: svc_vc.c,v 1.26 2012/03/20 17:14:50 matt Exp $	*/
      2   1.1      fvdl 
      3   1.1      fvdl /*
      4   1.1      fvdl  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
      5   1.1      fvdl  * unrestricted use provided that this legend is included on all tape
      6   1.1      fvdl  * media and as a part of the software program in whole or part.  Users
      7   1.1      fvdl  * may copy or modify Sun RPC without charge, but are not authorized
      8   1.1      fvdl  * to license or distribute it to anyone else except as part of a product or
      9   1.1      fvdl  * program developed by the user.
     10   1.1      fvdl  *
     11   1.1      fvdl  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
     12   1.1      fvdl  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
     13   1.1      fvdl  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
     14   1.1      fvdl  *
     15   1.1      fvdl  * Sun RPC is provided with no support and without any obligation on the
     16   1.1      fvdl  * part of Sun Microsystems, Inc. to assist in its use, correction,
     17   1.1      fvdl  * modification or enhancement.
     18   1.1      fvdl  *
     19   1.1      fvdl  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
     20   1.1      fvdl  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
     21   1.1      fvdl  * OR ANY PART THEREOF.
     22   1.1      fvdl  *
     23   1.1      fvdl  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
     24   1.1      fvdl  * or profits or other special, indirect and consequential damages, even if
     25   1.1      fvdl  * Sun has been advised of the possibility of such damages.
     26   1.1      fvdl  *
     27   1.1      fvdl  * Sun Microsystems, Inc.
     28   1.1      fvdl  * 2550 Garcia Avenue
     29   1.1      fvdl  * Mountain View, California  94043
     30   1.1      fvdl  */
     31   1.1      fvdl 
     32   1.1      fvdl #include <sys/cdefs.h>
     33   1.1      fvdl #if defined(LIBC_SCCS) && !defined(lint)
     34   1.1      fvdl #if 0
     35   1.1      fvdl static char *sccsid = "@(#)svc_tcp.c 1.21 87/08/11 Copyr 1984 Sun Micro";
     36   1.1      fvdl static char *sccsid = "@(#)svc_tcp.c	2.2 88/08/01 4.0 RPCSRC";
     37   1.1      fvdl #else
     38  1.26      matt __RCSID("$NetBSD: svc_vc.c,v 1.26 2012/03/20 17:14:50 matt Exp $");
     39   1.1      fvdl #endif
     40   1.1      fvdl #endif
     41   1.1      fvdl 
     42   1.1      fvdl /*
     43   1.1      fvdl  * svc_vc.c, Server side for Connection Oriented based RPC.
     44   1.1      fvdl  *
     45   1.1      fvdl  * Actually implements two flavors of transporter -
     46   1.1      fvdl  * a tcp rendezvouser (a listner and connection establisher)
     47   1.1      fvdl  * and a record/tcp stream.
     48   1.1      fvdl  */
     49   1.1      fvdl 
     50   1.1      fvdl #include "namespace.h"
     51   1.1      fvdl #include "reentrant.h"
     52   1.1      fvdl #include <sys/types.h>
     53   1.1      fvdl #include <sys/param.h>
     54   1.1      fvdl #include <sys/poll.h>
     55   1.1      fvdl #include <sys/socket.h>
     56   1.1      fvdl #include <sys/un.h>
     57  1.10      fvdl #include <sys/time.h>
     58   1.1      fvdl #include <netinet/in.h>
     59   1.1      fvdl 
     60   1.1      fvdl #include <assert.h>
     61   1.1      fvdl #include <err.h>
     62   1.1      fvdl #include <errno.h>
     63  1.10      fvdl #include <fcntl.h>
     64   1.1      fvdl #include <stdio.h>
     65   1.1      fvdl #include <stdlib.h>
     66   1.1      fvdl #include <string.h>
     67   1.1      fvdl #include <unistd.h>
     68   1.1      fvdl 
     69   1.1      fvdl #include <rpc/rpc.h>
     70   1.1      fvdl 
     71  1.10      fvdl #include "rpc_internal.h"
     72   1.1      fvdl 
     73   1.1      fvdl #ifdef __weak_alias
     74   1.1      fvdl __weak_alias(svc_fd_create,_svc_fd_create)
     75   1.1      fvdl __weak_alias(svc_vc_create,_svc_vc_create)
     76  1.11     skrll #endif
     77  1.11     skrll 
     78  1.12   thorpej #ifdef _REENTRANT
     79  1.11     skrll extern rwlock_t svc_fd_lock;
     80   1.1      fvdl #endif
     81   1.1      fvdl 
     82  1.23  christos static SVCXPRT *makefd_xprt(int, u_int, u_int);
     83  1.23  christos static bool_t rendezvous_request(SVCXPRT *, struct rpc_msg *);
     84  1.23  christos static enum xprt_stat rendezvous_stat(SVCXPRT *);
     85  1.23  christos static void svc_vc_destroy(SVCXPRT *);
     86  1.23  christos static void __svc_vc_dodestroy(SVCXPRT *);
     87  1.23  christos static int read_vc(caddr_t, caddr_t, int);
     88  1.23  christos static int write_vc(caddr_t, caddr_t, int);
     89  1.23  christos static enum xprt_stat svc_vc_stat(SVCXPRT *);
     90  1.23  christos static bool_t svc_vc_recv(SVCXPRT *, struct rpc_msg *);
     91  1.23  christos static bool_t svc_vc_getargs(SVCXPRT *, xdrproc_t, caddr_t);
     92  1.23  christos static bool_t svc_vc_freeargs(SVCXPRT *, xdrproc_t, caddr_t);
     93  1.23  christos static bool_t svc_vc_reply(SVCXPRT *, struct rpc_msg *);
     94  1.23  christos static void svc_vc_rendezvous_ops(SVCXPRT *);
     95  1.23  christos static void svc_vc_ops(SVCXPRT *);
     96  1.23  christos static bool_t svc_vc_control(SVCXPRT *, const u_int, void *);
     97  1.23  christos static bool_t svc_vc_rendezvous_control(SVCXPRT *, const u_int, void *);
     98   1.1      fvdl 
     99   1.1      fvdl struct cf_rendezvous { /* kept in xprt->xp_p1 for rendezvouser */
    100   1.1      fvdl 	u_int sendsize;
    101   1.1      fvdl 	u_int recvsize;
    102  1.10      fvdl 	int maxrec;
    103   1.1      fvdl };
    104   1.1      fvdl 
    105   1.1      fvdl struct cf_conn {  /* kept in xprt->xp_p1 for actual connection */
    106   1.1      fvdl 	enum xprt_stat strm_stat;
    107   1.1      fvdl 	u_int32_t x_id;
    108   1.1      fvdl 	XDR xdrs;
    109   1.1      fvdl 	char verf_body[MAX_AUTH_BYTES];
    110  1.10      fvdl 	u_int sendsize;
    111  1.10      fvdl 	u_int recvsize;
    112  1.10      fvdl 	int maxrec;
    113  1.10      fvdl 	bool_t nonblock;
    114  1.10      fvdl 	struct timeval last_recv_time;
    115   1.1      fvdl };
    116   1.1      fvdl 
    117   1.1      fvdl /*
    118   1.1      fvdl  * Usage:
    119   1.1      fvdl  *	xprt = svc_vc_create(sock, send_buf_size, recv_buf_size);
    120   1.1      fvdl  *
    121   1.1      fvdl  * Creates, registers, and returns a (rpc) tcp based transporter.
    122   1.1      fvdl  * Once *xprt is initialized, it is registered as a transporter
    123   1.1      fvdl  * see (svc.h, xprt_register).  This routine returns
    124   1.1      fvdl  * a NULL if a problem occurred.
    125   1.1      fvdl  *
    126   1.1      fvdl  * The filedescriptor passed in is expected to refer to a bound, but
    127   1.1      fvdl  * not yet connected socket.
    128   1.1      fvdl  *
    129   1.1      fvdl  * Since streams do buffered io similar to stdio, the caller can specify
    130   1.1      fvdl  * how big the send and receive buffers are via the second and third parms;
    131   1.1      fvdl  * 0 => use the system default.
    132   1.1      fvdl  */
    133   1.1      fvdl SVCXPRT *
    134  1.23  christos svc_vc_create(int fd, u_int sendsize, u_int recvsize)
    135   1.1      fvdl {
    136   1.1      fvdl 	SVCXPRT *xprt;
    137   1.1      fvdl 	struct cf_rendezvous *r = NULL;
    138   1.1      fvdl 	struct __rpc_sockinfo si;
    139   1.1      fvdl 	struct sockaddr_storage sslocal;
    140   1.1      fvdl 	socklen_t slen;
    141   1.3   thorpej 	int one = 1;
    142   1.1      fvdl 
    143  1.17  christos 	if (!__rpc_fd2sockinfo(fd, &si))
    144  1.17  christos 		return NULL;
    145  1.17  christos 
    146   1.5  christos 	r = mem_alloc(sizeof(*r));
    147   1.1      fvdl 	if (r == NULL) {
    148   1.1      fvdl 		warnx("svc_vc_create: out of memory");
    149  1.18  drochner 		return NULL;
    150   1.1      fvdl 	}
    151   1.5  christos 	r->sendsize = __rpc_get_t_size(si.si_af, si.si_proto, (int)sendsize);
    152   1.5  christos 	r->recvsize = __rpc_get_t_size(si.si_af, si.si_proto, (int)recvsize);
    153  1.10      fvdl 	r->maxrec = __svc_maxrec;
    154   1.5  christos 	xprt = mem_alloc(sizeof(SVCXPRT));
    155   1.1      fvdl 	if (xprt == NULL) {
    156   1.1      fvdl 		warnx("svc_vc_create: out of memory");
    157   1.1      fvdl 		goto cleanup_svc_vc_create;
    158   1.1      fvdl 	}
    159   1.1      fvdl 	xprt->xp_tp = NULL;
    160   1.1      fvdl 	xprt->xp_p1 = (caddr_t)(void *)r;
    161   1.1      fvdl 	xprt->xp_p2 = NULL;
    162   1.1      fvdl 	xprt->xp_p3 = NULL;
    163   1.1      fvdl 	xprt->xp_verf = _null_auth;
    164   1.6    kleink 	svc_vc_rendezvous_ops(xprt);
    165   1.5  christos 	xprt->xp_port = (u_short)-1;	/* It is the rendezvouser */
    166   1.1      fvdl 	xprt->xp_fd = fd;
    167   1.1      fvdl 
    168   1.1      fvdl 	slen = sizeof (struct sockaddr_storage);
    169   1.5  christos 	if (getsockname(fd, (struct sockaddr *)(void *)&sslocal, &slen) < 0) {
    170   1.1      fvdl 		warnx("svc_vc_create: could not retrieve local addr");
    171   1.1      fvdl 		goto cleanup_svc_vc_create;
    172   1.1      fvdl 	}
    173   1.1      fvdl 
    174   1.1      fvdl 	/*
    175   1.1      fvdl 	 * We want to be able to check credentials on local sockets.
    176   1.1      fvdl 	 */
    177   1.1      fvdl 	if (sslocal.ss_family == AF_LOCAL)
    178  1.25  christos 		if (setsockopt(fd, 0, LOCAL_CREDS, &one, (socklen_t)sizeof one)
    179  1.25  christos 		    == -1)
    180   1.1      fvdl 			goto cleanup_svc_vc_create;
    181   1.1      fvdl 
    182   1.1      fvdl 	xprt->xp_ltaddr.maxlen = xprt->xp_ltaddr.len = sslocal.ss_len;
    183   1.5  christos 	xprt->xp_ltaddr.buf = mem_alloc((size_t)sslocal.ss_len);
    184   1.1      fvdl 	if (xprt->xp_ltaddr.buf == NULL) {
    185   1.1      fvdl 		warnx("svc_vc_create: no mem for local addr");
    186   1.1      fvdl 		goto cleanup_svc_vc_create;
    187   1.1      fvdl 	}
    188   1.5  christos 	memcpy(xprt->xp_ltaddr.buf, &sslocal, (size_t)sslocal.ss_len);
    189   1.1      fvdl 
    190   1.1      fvdl 	xprt->xp_rtaddr.maxlen = sizeof (struct sockaddr_storage);
    191   1.1      fvdl 	xprt_register(xprt);
    192  1.23  christos 	return xprt;
    193   1.1      fvdl cleanup_svc_vc_create:
    194  1.16  christos 	if (xprt)
    195  1.16  christos 		mem_free(xprt, sizeof(*xprt));
    196   1.1      fvdl 	if (r != NULL)
    197   1.1      fvdl 		mem_free(r, sizeof(*r));
    198  1.23  christos 	return NULL;
    199   1.1      fvdl }
    200   1.1      fvdl 
    201   1.1      fvdl /*
    202   1.1      fvdl  * Like svtcp_create(), except the routine takes any *open* UNIX file
    203   1.1      fvdl  * descriptor as its first input.
    204   1.1      fvdl  */
    205   1.1      fvdl SVCXPRT *
    206  1.23  christos svc_fd_create(int fd, u_int sendsize, u_int recvsize)
    207   1.1      fvdl {
    208   1.1      fvdl 	struct sockaddr_storage ss;
    209   1.1      fvdl 	socklen_t slen;
    210   1.1      fvdl 	SVCXPRT *ret;
    211   1.1      fvdl 
    212   1.1      fvdl 	_DIAGASSERT(fd != -1);
    213   1.1      fvdl 
    214   1.1      fvdl 	ret = makefd_xprt(fd, sendsize, recvsize);
    215   1.1      fvdl 	if (ret == NULL)
    216   1.1      fvdl 		return NULL;
    217   1.1      fvdl 
    218   1.1      fvdl 	slen = sizeof (struct sockaddr_storage);
    219   1.5  christos 	if (getsockname(fd, (struct sockaddr *)(void *)&ss, &slen) < 0) {
    220   1.4      fvdl 		warnx("svc_fd_create: could not retrieve local addr");
    221   1.1      fvdl 		goto freedata;
    222   1.1      fvdl 	}
    223   1.1      fvdl 	ret->xp_ltaddr.maxlen = ret->xp_ltaddr.len = ss.ss_len;
    224   1.5  christos 	ret->xp_ltaddr.buf = mem_alloc((size_t)ss.ss_len);
    225   1.1      fvdl 	if (ret->xp_ltaddr.buf == NULL) {
    226   1.1      fvdl 		warnx("svc_fd_create: no mem for local addr");
    227   1.1      fvdl 		goto freedata;
    228   1.1      fvdl 	}
    229   1.5  christos 	memcpy(ret->xp_ltaddr.buf, &ss, (size_t)ss.ss_len);
    230   1.1      fvdl 
    231   1.1      fvdl 	slen = sizeof (struct sockaddr_storage);
    232   1.5  christos 	if (getpeername(fd, (struct sockaddr *)(void *)&ss, &slen) < 0) {
    233   1.4      fvdl 		warnx("svc_fd_create: could not retrieve remote addr");
    234   1.1      fvdl 		goto freedata;
    235   1.1      fvdl 	}
    236   1.1      fvdl 	ret->xp_rtaddr.maxlen = ret->xp_rtaddr.len = ss.ss_len;
    237   1.5  christos 	ret->xp_rtaddr.buf = mem_alloc((size_t)ss.ss_len);
    238   1.1      fvdl 	if (ret->xp_rtaddr.buf == NULL) {
    239   1.1      fvdl 		warnx("svc_fd_create: no mem for local addr");
    240   1.1      fvdl 		goto freedata;
    241   1.1      fvdl 	}
    242   1.5  christos 	memcpy(ret->xp_rtaddr.buf, &ss, (size_t)ss.ss_len);
    243   1.1      fvdl #ifdef PORTMAP
    244   1.1      fvdl 	if (ss.ss_family == AF_INET) {
    245   1.1      fvdl 		ret->xp_raddr = *(struct sockaddr_in *)ret->xp_rtaddr.buf;
    246   1.1      fvdl 		ret->xp_addrlen = sizeof (struct sockaddr_in);
    247   1.1      fvdl 	}
    248   1.1      fvdl #endif
    249   1.1      fvdl 
    250   1.1      fvdl 	return ret;
    251   1.1      fvdl 
    252   1.1      fvdl freedata:
    253   1.1      fvdl 	if (ret->xp_ltaddr.buf != NULL)
    254   1.1      fvdl 		mem_free(ret->xp_ltaddr.buf, rep->xp_ltaddr.maxlen);
    255   1.1      fvdl 
    256   1.1      fvdl 	return NULL;
    257   1.1      fvdl }
    258   1.1      fvdl 
    259   1.1      fvdl static SVCXPRT *
    260  1.23  christos makefd_xprt(int fd, u_int sendsize, u_int recvsize)
    261   1.1      fvdl {
    262   1.1      fvdl 	SVCXPRT *xprt;
    263   1.1      fvdl 	struct cf_conn *cd;
    264   1.7      fvdl 	const char *netid;
    265   1.7      fvdl 	struct __rpc_sockinfo si;
    266   1.1      fvdl 
    267   1.1      fvdl 	_DIAGASSERT(fd != -1);
    268   1.1      fvdl 
    269   1.5  christos 	xprt = mem_alloc(sizeof(SVCXPRT));
    270  1.21  christos 	if (xprt == NULL)
    271  1.21  christos 		goto out;
    272   1.2      fvdl 	memset(xprt, 0, sizeof *xprt);
    273   1.5  christos 	cd = mem_alloc(sizeof(struct cf_conn));
    274  1.21  christos 	if (cd == NULL)
    275  1.21  christos 		goto out;
    276   1.1      fvdl 	cd->strm_stat = XPRT_IDLE;
    277   1.1      fvdl 	xdrrec_create(&(cd->xdrs), sendsize, recvsize,
    278   1.1      fvdl 	    (caddr_t)(void *)xprt, read_vc, write_vc);
    279   1.1      fvdl 	xprt->xp_p1 = (caddr_t)(void *)cd;
    280   1.1      fvdl 	xprt->xp_verf.oa_base = cd->verf_body;
    281   1.1      fvdl 	svc_vc_ops(xprt);  /* truely deals with calls */
    282   1.1      fvdl 	xprt->xp_port = 0;  /* this is a connection, not a rendezvouser */
    283   1.1      fvdl 	xprt->xp_fd = fd;
    284   1.8     lukem 	if (__rpc_fd2sockinfo(fd, &si) && __rpc_sockinfo2netid(&si, &netid))
    285  1.21  christos 		if ((xprt->xp_netid = strdup(netid)) == NULL)
    286  1.21  christos 			goto out;
    287   1.7      fvdl 
    288   1.1      fvdl 	xprt_register(xprt);
    289  1.23  christos 	return xprt;
    290  1.21  christos out:
    291  1.21  christos 	warn("svc_tcp: makefd_xprt");
    292  1.21  christos 	if (xprt)
    293  1.21  christos 		mem_free(xprt, sizeof(SVCXPRT));
    294  1.21  christos 	return NULL;
    295   1.1      fvdl }
    296   1.1      fvdl 
    297   1.1      fvdl /*ARGSUSED*/
    298   1.1      fvdl static bool_t
    299  1.23  christos rendezvous_request(SVCXPRT *xprt, struct rpc_msg *msg)
    300   1.1      fvdl {
    301  1.10      fvdl 	int sock, flags;
    302   1.1      fvdl 	struct cf_rendezvous *r;
    303  1.10      fvdl 	struct cf_conn *cd;
    304   1.1      fvdl 	struct sockaddr_storage addr;
    305   1.1      fvdl 	socklen_t len;
    306   1.1      fvdl 	struct __rpc_sockinfo si;
    307  1.10      fvdl 	SVCXPRT *newxprt;
    308  1.10      fvdl 	fd_set cleanfds;
    309   1.1      fvdl 
    310   1.1      fvdl 	_DIAGASSERT(xprt != NULL);
    311   1.1      fvdl 	_DIAGASSERT(msg != NULL);
    312   1.1      fvdl 
    313   1.1      fvdl 	r = (struct cf_rendezvous *)xprt->xp_p1;
    314   1.1      fvdl again:
    315   1.1      fvdl 	len = sizeof addr;
    316   1.5  christos 	if ((sock = accept(xprt->xp_fd, (struct sockaddr *)(void *)&addr,
    317   1.5  christos 	    &len)) < 0) {
    318   1.1      fvdl 		if (errno == EINTR)
    319   1.1      fvdl 			goto again;
    320  1.10      fvdl 		/*
    321  1.10      fvdl 		 * Clean out the most idle file descriptor when we're
    322  1.10      fvdl 		 * running out.
    323  1.10      fvdl 		 */
    324  1.10      fvdl 		if (errno == EMFILE || errno == ENFILE) {
    325  1.10      fvdl 			cleanfds = svc_fdset;
    326  1.20  christos 			if (__svc_clean_idle(&cleanfds, 0, FALSE))
    327  1.20  christos 				goto again;
    328  1.10      fvdl 		}
    329  1.23  christos 		return FALSE;
    330   1.1      fvdl 	}
    331   1.1      fvdl 	/*
    332   1.1      fvdl 	 * make a new transporter (re-uses xprt)
    333   1.1      fvdl 	 */
    334  1.10      fvdl 	newxprt = makefd_xprt(sock, r->sendsize, r->recvsize);
    335  1.21  christos 	if (newxprt == NULL)
    336  1.21  christos 		goto out;
    337  1.10      fvdl 	newxprt->xp_rtaddr.buf = mem_alloc(len);
    338  1.10      fvdl 	if (newxprt->xp_rtaddr.buf == NULL)
    339  1.21  christos 		goto out;
    340  1.10      fvdl 	memcpy(newxprt->xp_rtaddr.buf, &addr, len);
    341  1.10      fvdl 	newxprt->xp_rtaddr.len = len;
    342   1.1      fvdl #ifdef PORTMAP
    343   1.1      fvdl 	if (addr.ss_family == AF_INET) {
    344  1.10      fvdl 		newxprt->xp_raddr = *(struct sockaddr_in *)newxprt->xp_rtaddr.buf;
    345  1.10      fvdl 		newxprt->xp_addrlen = sizeof (struct sockaddr_in);
    346   1.1      fvdl 	}
    347   1.1      fvdl #endif
    348  1.19  christos 	if (__rpc_fd2sockinfo(sock, &si))
    349  1.19  christos 		__rpc_setnodelay(sock, &si);
    350  1.10      fvdl 
    351  1.10      fvdl 	cd = (struct cf_conn *)newxprt->xp_p1;
    352  1.10      fvdl 
    353  1.10      fvdl 	cd->recvsize = r->recvsize;
    354  1.10      fvdl 	cd->sendsize = r->sendsize;
    355  1.10      fvdl 	cd->maxrec = r->maxrec;
    356  1.10      fvdl 
    357  1.10      fvdl 	if (cd->maxrec != 0) {
    358  1.10      fvdl 		flags = fcntl(sock, F_GETFL, 0);
    359  1.10      fvdl 		if (flags  == -1)
    360  1.21  christos 			goto out;
    361  1.10      fvdl 		if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) == -1)
    362  1.21  christos 			goto out;
    363  1.22     lukem 		if (cd->recvsize > (u_int)cd->maxrec)
    364  1.10      fvdl 			cd->recvsize = cd->maxrec;
    365  1.10      fvdl 		cd->nonblock = TRUE;
    366  1.10      fvdl 		__xdrrec_setnonblock(&cd->xdrs, cd->maxrec);
    367  1.10      fvdl 	} else
    368  1.10      fvdl 		cd->nonblock = FALSE;
    369  1.10      fvdl 
    370  1.21  christos 	(void)gettimeofday(&cd->last_recv_time, NULL);
    371  1.10      fvdl 
    372  1.23  christos 	return FALSE; /* there is never an rpc msg to be processed */
    373  1.21  christos out:
    374  1.21  christos 	(void)close(sock);
    375  1.23  christos 	return FALSE; /* there was an error */
    376   1.1      fvdl }
    377   1.1      fvdl 
    378   1.1      fvdl /*ARGSUSED*/
    379   1.1      fvdl static enum xprt_stat
    380  1.23  christos rendezvous_stat(SVCXPRT *xprt)
    381   1.1      fvdl {
    382   1.1      fvdl 
    383  1.23  christos 	return XPRT_IDLE;
    384   1.1      fvdl }
    385   1.1      fvdl 
    386   1.1      fvdl static void
    387  1.23  christos svc_vc_destroy(SVCXPRT *xprt)
    388   1.1      fvdl {
    389  1.10      fvdl 	_DIAGASSERT(xprt != NULL);
    390  1.10      fvdl 
    391  1.10      fvdl 	xprt_unregister(xprt);
    392  1.10      fvdl 	__svc_vc_dodestroy(xprt);
    393  1.10      fvdl }
    394  1.10      fvdl 
    395  1.10      fvdl static void
    396  1.23  christos __svc_vc_dodestroy(SVCXPRT *xprt)
    397  1.10      fvdl {
    398   1.1      fvdl 	struct cf_conn *cd;
    399   1.1      fvdl 	struct cf_rendezvous *r;
    400   1.1      fvdl 
    401   1.1      fvdl 	cd = (struct cf_conn *)xprt->xp_p1;
    402   1.1      fvdl 
    403   1.1      fvdl 	if (xprt->xp_fd != RPC_ANYFD)
    404   1.1      fvdl 		(void)close(xprt->xp_fd);
    405   1.1      fvdl 	if (xprt->xp_port != 0) {
    406   1.1      fvdl 		/* a rendezvouser socket */
    407   1.1      fvdl 		r = (struct cf_rendezvous *)xprt->xp_p1;
    408   1.1      fvdl 		mem_free(r, sizeof (struct cf_rendezvous));
    409   1.1      fvdl 		xprt->xp_port = 0;
    410   1.1      fvdl 	} else {
    411   1.1      fvdl 		/* an actual connection socket */
    412   1.1      fvdl 		XDR_DESTROY(&(cd->xdrs));
    413   1.1      fvdl 		mem_free(cd, sizeof(struct cf_conn));
    414   1.1      fvdl 	}
    415   1.1      fvdl 	if (xprt->xp_rtaddr.buf)
    416   1.1      fvdl 		mem_free(xprt->xp_rtaddr.buf, xprt->xp_rtaddr.maxlen);
    417   1.1      fvdl 	if (xprt->xp_ltaddr.buf)
    418   1.1      fvdl 		mem_free(xprt->xp_ltaddr.buf, xprt->xp_ltaddr.maxlen);
    419   1.1      fvdl 	if (xprt->xp_tp)
    420   1.1      fvdl 		free(xprt->xp_tp);
    421   1.1      fvdl 	if (xprt->xp_netid)
    422   1.1      fvdl 		free(xprt->xp_netid);
    423   1.1      fvdl 	mem_free(xprt, sizeof(SVCXPRT));
    424   1.1      fvdl }
    425   1.1      fvdl 
    426   1.5  christos /*ARGSUSED*/
    427   1.1      fvdl static bool_t
    428  1.23  christos svc_vc_control(SVCXPRT *xprt, const u_int rq, void *in)
    429   1.1      fvdl {
    430  1.23  christos 	return FALSE;
    431   1.1      fvdl }
    432   1.1      fvdl 
    433  1.10      fvdl /*ARGSUSED*/
    434  1.10      fvdl static bool_t
    435  1.23  christos svc_vc_rendezvous_control(SVCXPRT *xprt, const u_int rq, void *in)
    436  1.10      fvdl {
    437  1.10      fvdl 	struct cf_rendezvous *cfp;
    438  1.10      fvdl 
    439  1.10      fvdl 	cfp = (struct cf_rendezvous *)xprt->xp_p1;
    440  1.10      fvdl 	if (cfp == NULL)
    441  1.23  christos 		return FALSE;
    442  1.10      fvdl 	switch (rq) {
    443  1.10      fvdl 		case SVCGET_CONNMAXREC:
    444  1.10      fvdl 			*(int *)in = cfp->maxrec;
    445  1.10      fvdl 			break;
    446  1.10      fvdl 		case SVCSET_CONNMAXREC:
    447  1.10      fvdl 			cfp->maxrec = *(int *)in;
    448  1.10      fvdl 			break;
    449  1.10      fvdl 		default:
    450  1.23  christos 			return FALSE;
    451  1.10      fvdl 	}
    452  1.23  christos 	return TRUE;
    453  1.10      fvdl }
    454  1.10      fvdl 
    455   1.1      fvdl /*
    456   1.9      cjep  * reads data from the tcp connection.
    457   1.1      fvdl  * any error is fatal and the connection is closed.
    458   1.1      fvdl  * (And a read of zero bytes is a half closed stream => error.)
    459   1.1      fvdl  * All read operations timeout after 35 seconds.  A timeout is
    460   1.1      fvdl  * fatal for the connection.
    461   1.1      fvdl  */
    462   1.1      fvdl static int
    463  1.23  christos read_vc(caddr_t xprtp, caddr_t buf, int len)
    464   1.1      fvdl {
    465   1.1      fvdl 	SVCXPRT *xprt;
    466   1.1      fvdl 	int sock;
    467   1.1      fvdl 	struct pollfd pollfd;
    468   1.1      fvdl 	struct sockaddr *sa;
    469   1.1      fvdl 	struct msghdr msg;
    470   1.1      fvdl 	struct cmsghdr *cmp;
    471   1.3   thorpej 	void *crmsg = NULL;
    472   1.1      fvdl 	struct sockcred *sc;
    473   1.3   thorpej 	socklen_t crmsgsize;
    474  1.10      fvdl 	struct cf_conn *cfp;
    475  1.13  christos 	static const struct timespec ts = { 35, 0 };
    476   1.1      fvdl 
    477   1.1      fvdl 	xprt = (SVCXPRT *)(void *)xprtp;
    478   1.1      fvdl 	_DIAGASSERT(xprt != NULL);
    479   1.1      fvdl 
    480   1.1      fvdl 	sock = xprt->xp_fd;
    481   1.1      fvdl 
    482   1.1      fvdl 	sa = (struct sockaddr *)xprt->xp_rtaddr.buf;
    483   1.1      fvdl 	if (sa->sa_family == AF_LOCAL && xprt->xp_p2 == NULL) {
    484   1.1      fvdl 		memset(&msg, 0, sizeof msg);
    485   1.3   thorpej 		crmsgsize = CMSG_SPACE(SOCKCREDSIZE(NGROUPS));
    486   1.3   thorpej 		crmsg = malloc(crmsgsize);
    487   1.3   thorpej 		if (crmsg == NULL)
    488   1.3   thorpej 			goto fatal_err;
    489   1.3   thorpej 		memset(crmsg, 0, crmsgsize);
    490   1.3   thorpej 
    491   1.3   thorpej 		msg.msg_control = crmsg;
    492   1.3   thorpej 		msg.msg_controllen = crmsgsize;
    493   1.1      fvdl 
    494   1.1      fvdl 		if (recvmsg(sock, &msg, 0) < 0)
    495   1.1      fvdl 			goto fatal_err;
    496   1.1      fvdl 
    497   1.3   thorpej 		if (msg.msg_controllen == 0 ||
    498   1.3   thorpej 		    (msg.msg_flags & MSG_CTRUNC) != 0)
    499   1.3   thorpej 			goto fatal_err;
    500   1.3   thorpej 
    501   1.1      fvdl 		cmp = CMSG_FIRSTHDR(&msg);
    502   1.1      fvdl 		if (cmp->cmsg_level != SOL_SOCKET ||
    503   1.1      fvdl 		    cmp->cmsg_type != SCM_CREDS)
    504   1.1      fvdl 			goto fatal_err;
    505   1.1      fvdl 
    506   1.5  christos 		sc = (struct sockcred *)(void *)CMSG_DATA(cmp);
    507   1.1      fvdl 
    508   1.1      fvdl 		xprt->xp_p2 = mem_alloc(SOCKCREDSIZE(sc->sc_ngroups));
    509   1.1      fvdl 		if (xprt->xp_p2 == NULL)
    510   1.1      fvdl 			goto fatal_err;
    511   1.1      fvdl 
    512   1.1      fvdl 		memcpy(xprt->xp_p2, sc, SOCKCREDSIZE(sc->sc_ngroups));
    513   1.3   thorpej 		free(crmsg);
    514   1.3   thorpej 		crmsg = NULL;
    515   1.1      fvdl 	}
    516  1.10      fvdl 
    517  1.10      fvdl 	cfp = (struct cf_conn *)xprt->xp_p1;
    518  1.10      fvdl 
    519  1.10      fvdl 	if (cfp->nonblock) {
    520  1.25  christos 		len = (int)read(sock, buf, (size_t)len);
    521  1.10      fvdl 		if (len < 0) {
    522  1.10      fvdl 			if (errno == EAGAIN)
    523  1.10      fvdl 				len = 0;
    524  1.10      fvdl 			else
    525  1.10      fvdl 				goto fatal_err;
    526  1.10      fvdl 		}
    527  1.10      fvdl 		if (len != 0)
    528  1.10      fvdl 			gettimeofday(&cfp->last_recv_time, NULL);
    529  1.10      fvdl 		return len;
    530  1.10      fvdl 	}
    531  1.10      fvdl 
    532   1.1      fvdl 	do {
    533   1.1      fvdl 		pollfd.fd = sock;
    534   1.1      fvdl 		pollfd.events = POLLIN;
    535  1.13  christos 		switch (pollts(&pollfd, 1, &ts, NULL)) {
    536   1.1      fvdl 		case -1:
    537   1.1      fvdl 			if (errno == EINTR) {
    538   1.1      fvdl 				continue;
    539   1.1      fvdl 			}
    540   1.1      fvdl 			/*FALLTHROUGH*/
    541   1.1      fvdl 		case 0:
    542   1.1      fvdl 			goto fatal_err;
    543   1.1      fvdl 
    544   1.1      fvdl 		default:
    545   1.1      fvdl 			break;
    546   1.1      fvdl 		}
    547   1.1      fvdl 	} while ((pollfd.revents & POLLIN) == 0);
    548   1.1      fvdl 
    549  1.25  christos 	if ((len = (int)read(sock, buf, (size_t)len)) > 0) {
    550  1.10      fvdl 		gettimeofday(&cfp->last_recv_time, NULL);
    551  1.23  christos 		return len;
    552  1.10      fvdl 	}
    553   1.1      fvdl 
    554   1.1      fvdl fatal_err:
    555   1.3   thorpej 	if (crmsg != NULL)
    556   1.3   thorpej 		free(crmsg);
    557   1.1      fvdl 	((struct cf_conn *)(xprt->xp_p1))->strm_stat = XPRT_DIED;
    558  1.23  christos 	return -1;
    559   1.1      fvdl }
    560   1.1      fvdl 
    561   1.1      fvdl /*
    562   1.1      fvdl  * writes data to the tcp connection.
    563   1.1      fvdl  * Any error is fatal and the connection is closed.
    564   1.1      fvdl  */
    565   1.1      fvdl static int
    566  1.23  christos write_vc(caddr_t xprtp, caddr_t buf, int len)
    567   1.1      fvdl {
    568   1.1      fvdl 	SVCXPRT *xprt;
    569   1.1      fvdl 	int i, cnt;
    570  1.10      fvdl 	struct cf_conn *cd;
    571  1.10      fvdl 	struct timeval tv0, tv1;
    572   1.1      fvdl 
    573   1.1      fvdl 	xprt = (SVCXPRT *)(void *)xprtp;
    574   1.1      fvdl 	_DIAGASSERT(xprt != NULL);
    575   1.1      fvdl 
    576  1.10      fvdl 	cd = (struct cf_conn *)xprt->xp_p1;
    577  1.10      fvdl 
    578  1.10      fvdl 	if (cd->nonblock)
    579  1.10      fvdl 		gettimeofday(&tv0, NULL);
    580  1.10      fvdl 
    581   1.1      fvdl 	for (cnt = len; cnt > 0; cnt -= i, buf += i) {
    582  1.25  christos 		if ((i = (int)write(xprt->xp_fd, buf, (size_t)cnt)) < 0) {
    583  1.10      fvdl 			if (errno != EAGAIN || !cd->nonblock) {
    584  1.10      fvdl 				cd->strm_stat = XPRT_DIED;
    585  1.23  christos 				return -1;
    586  1.10      fvdl 			}
    587  1.24  christos 			if (cd->nonblock) {
    588  1.10      fvdl 				/*
    589  1.10      fvdl 				 * For non-blocking connections, do not
    590  1.10      fvdl 				 * take more than 2 seconds writing the
    591  1.10      fvdl 				 * data out.
    592  1.10      fvdl 				 *
    593  1.10      fvdl 				 * XXX 2 is an arbitrary amount.
    594  1.10      fvdl 				 */
    595  1.10      fvdl 				gettimeofday(&tv1, NULL);
    596  1.10      fvdl 				if (tv1.tv_sec - tv0.tv_sec >= 2) {
    597  1.10      fvdl 					cd->strm_stat = XPRT_DIED;
    598  1.23  christos 					return -1;
    599  1.10      fvdl 				}
    600  1.10      fvdl 			}
    601  1.24  christos 			i = 0;
    602   1.1      fvdl 		}
    603   1.1      fvdl 	}
    604  1.23  christos 	return len;
    605   1.1      fvdl }
    606   1.1      fvdl 
    607   1.1      fvdl static enum xprt_stat
    608  1.23  christos svc_vc_stat(SVCXPRT *xprt)
    609   1.1      fvdl {
    610   1.1      fvdl 	struct cf_conn *cd;
    611   1.1      fvdl 
    612   1.1      fvdl 	_DIAGASSERT(xprt != NULL);
    613   1.1      fvdl 
    614   1.1      fvdl 	cd = (struct cf_conn *)(xprt->xp_p1);
    615   1.1      fvdl 
    616   1.1      fvdl 	if (cd->strm_stat == XPRT_DIED)
    617  1.23  christos 		return XPRT_DIED;
    618   1.1      fvdl 	if (! xdrrec_eof(&(cd->xdrs)))
    619  1.23  christos 		return XPRT_MOREREQS;
    620  1.23  christos 	return XPRT_IDLE;
    621   1.1      fvdl }
    622   1.1      fvdl 
    623   1.1      fvdl static bool_t
    624  1.23  christos svc_vc_recv(SVCXPRT *xprt, struct rpc_msg *msg)
    625   1.1      fvdl {
    626   1.1      fvdl 	struct cf_conn *cd;
    627   1.1      fvdl 	XDR *xdrs;
    628   1.1      fvdl 
    629   1.1      fvdl 	_DIAGASSERT(xprt != NULL);
    630   1.1      fvdl 	_DIAGASSERT(msg != NULL);
    631   1.1      fvdl 
    632   1.1      fvdl 	cd = (struct cf_conn *)(xprt->xp_p1);
    633   1.1      fvdl 	xdrs = &(cd->xdrs);
    634   1.1      fvdl 
    635  1.10      fvdl 	if (cd->nonblock) {
    636  1.10      fvdl 		if (!__xdrrec_getrec(xdrs, &cd->strm_stat, TRUE))
    637  1.10      fvdl 			return FALSE;
    638  1.10      fvdl 	}
    639  1.10      fvdl 
    640   1.1      fvdl 	xdrs->x_op = XDR_DECODE;
    641   1.1      fvdl 	(void)xdrrec_skiprecord(xdrs);
    642  1.10      fvdl 
    643   1.1      fvdl 	if (xdr_callmsg(xdrs, msg)) {
    644   1.1      fvdl 		cd->x_id = msg->rm_xid;
    645  1.23  christos 		return TRUE;
    646   1.1      fvdl 	}
    647   1.1      fvdl 	cd->strm_stat = XPRT_DIED;
    648  1.23  christos 	return FALSE;
    649   1.1      fvdl }
    650   1.1      fvdl 
    651   1.1      fvdl static bool_t
    652  1.23  christos svc_vc_getargs(SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr)
    653   1.1      fvdl {
    654   1.1      fvdl 
    655   1.1      fvdl 	_DIAGASSERT(xprt != NULL);
    656   1.1      fvdl 	/* args_ptr may be NULL */
    657   1.1      fvdl 
    658  1.23  christos 	return (*xdr_args)(&(((struct cf_conn *)(xprt->xp_p1))->xdrs),
    659  1.23  christos 	    args_ptr);
    660   1.1      fvdl }
    661   1.1      fvdl 
    662   1.1      fvdl static bool_t
    663  1.23  christos svc_vc_freeargs(SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr)
    664   1.1      fvdl {
    665   1.1      fvdl 	XDR *xdrs;
    666   1.1      fvdl 
    667   1.1      fvdl 	_DIAGASSERT(xprt != NULL);
    668   1.1      fvdl 	/* args_ptr may be NULL */
    669   1.1      fvdl 
    670   1.1      fvdl 	xdrs = &(((struct cf_conn *)(xprt->xp_p1))->xdrs);
    671   1.1      fvdl 
    672   1.1      fvdl 	xdrs->x_op = XDR_FREE;
    673  1.23  christos 	return (*xdr_args)(xdrs, args_ptr);
    674   1.1      fvdl }
    675   1.1      fvdl 
    676   1.1      fvdl static bool_t
    677  1.23  christos svc_vc_reply(SVCXPRT *xprt, struct rpc_msg *msg)
    678   1.1      fvdl {
    679   1.1      fvdl 	struct cf_conn *cd;
    680   1.1      fvdl 	XDR *xdrs;
    681  1.10      fvdl 	bool_t rstat;
    682   1.1      fvdl 
    683   1.1      fvdl 	_DIAGASSERT(xprt != NULL);
    684   1.1      fvdl 	_DIAGASSERT(msg != NULL);
    685   1.1      fvdl 
    686   1.1      fvdl 	cd = (struct cf_conn *)(xprt->xp_p1);
    687   1.1      fvdl 	xdrs = &(cd->xdrs);
    688   1.1      fvdl 
    689   1.1      fvdl 	xdrs->x_op = XDR_ENCODE;
    690   1.1      fvdl 	msg->rm_xid = cd->x_id;
    691  1.10      fvdl 	rstat = xdr_replymsg(xdrs, msg);
    692   1.1      fvdl 	(void)xdrrec_endofrecord(xdrs, TRUE);
    693  1.23  christos 	return rstat;
    694   1.1      fvdl }
    695   1.1      fvdl 
    696   1.1      fvdl static void
    697  1.23  christos svc_vc_ops(SVCXPRT *xprt)
    698   1.1      fvdl {
    699   1.1      fvdl 	static struct xp_ops ops;
    700   1.1      fvdl 	static struct xp_ops2 ops2;
    701  1.12   thorpej #ifdef _REENTRANT
    702   1.1      fvdl 	extern mutex_t ops_lock;
    703   1.1      fvdl #endif
    704   1.1      fvdl 
    705   1.1      fvdl /* VARIABLES PROTECTED BY ops_lock: ops, ops2 */
    706   1.1      fvdl 
    707   1.1      fvdl 	mutex_lock(&ops_lock);
    708   1.1      fvdl 	if (ops.xp_recv == NULL) {
    709   1.1      fvdl 		ops.xp_recv = svc_vc_recv;
    710   1.1      fvdl 		ops.xp_stat = svc_vc_stat;
    711   1.1      fvdl 		ops.xp_getargs = svc_vc_getargs;
    712   1.1      fvdl 		ops.xp_reply = svc_vc_reply;
    713   1.1      fvdl 		ops.xp_freeargs = svc_vc_freeargs;
    714   1.1      fvdl 		ops.xp_destroy = svc_vc_destroy;
    715   1.1      fvdl 		ops2.xp_control = svc_vc_control;
    716   1.1      fvdl 	}
    717   1.1      fvdl 	xprt->xp_ops = &ops;
    718   1.1      fvdl 	xprt->xp_ops2 = &ops2;
    719   1.1      fvdl 	mutex_unlock(&ops_lock);
    720   1.1      fvdl }
    721   1.1      fvdl 
    722   1.1      fvdl static void
    723  1.26      matt svc_vc_rendezvous_ops(SVCXPRT *xprt)
    724   1.1      fvdl {
    725   1.1      fvdl 	static struct xp_ops ops;
    726   1.1      fvdl 	static struct xp_ops2 ops2;
    727  1.12   thorpej #ifdef _REENTRANT
    728   1.1      fvdl 	extern mutex_t ops_lock;
    729   1.1      fvdl #endif
    730   1.1      fvdl 	mutex_lock(&ops_lock);
    731   1.1      fvdl 	if (ops.xp_recv == NULL) {
    732   1.1      fvdl 		ops.xp_recv = rendezvous_request;
    733   1.1      fvdl 		ops.xp_stat = rendezvous_stat;
    734   1.1      fvdl 		ops.xp_getargs =
    735  1.23  christos 		    (bool_t (*)(SVCXPRT *, xdrproc_t, caddr_t))abort;
    736   1.1      fvdl 		ops.xp_reply =
    737  1.23  christos 		    (bool_t (*)(SVCXPRT *, struct rpc_msg *))abort;
    738   1.1      fvdl 		ops.xp_freeargs =
    739  1.23  christos 		    (bool_t (*)(SVCXPRT *, xdrproc_t, caddr_t))abort;
    740   1.1      fvdl 		ops.xp_destroy = svc_vc_destroy;
    741  1.10      fvdl 		ops2.xp_control = svc_vc_rendezvous_control;
    742   1.1      fvdl 	}
    743   1.1      fvdl 	xprt->xp_ops = &ops;
    744   1.1      fvdl 	xprt->xp_ops2 = &ops2;
    745   1.1      fvdl 	mutex_unlock(&ops_lock);
    746  1.10      fvdl }
    747  1.10      fvdl 
    748  1.10      fvdl /*
    749  1.10      fvdl  * Destroy xprts that have not have had any activity in 'timeout' seconds.
    750  1.10      fvdl  * If 'cleanblock' is true, blocking connections (the default) are also
    751  1.10      fvdl  * cleaned. If timeout is 0, the least active connection is picked.
    752  1.10      fvdl  */
    753  1.10      fvdl bool_t
    754  1.10      fvdl __svc_clean_idle(fd_set *fds, int timeout, bool_t cleanblock)
    755  1.10      fvdl {
    756  1.10      fvdl 	int i, ncleaned;
    757  1.10      fvdl 	SVCXPRT *xprt, *least_active;
    758  1.10      fvdl 	struct timeval tv, tdiff, tmax;
    759  1.10      fvdl 	struct cf_conn *cd;
    760  1.10      fvdl 
    761  1.10      fvdl 	gettimeofday(&tv, NULL);
    762  1.10      fvdl 	tmax.tv_sec = tmax.tv_usec = 0;
    763  1.10      fvdl 	least_active = NULL;
    764  1.10      fvdl 	rwlock_wrlock(&svc_fd_lock);
    765  1.10      fvdl 	for (i = ncleaned = 0; i <= svc_maxfd; i++) {
    766  1.10      fvdl 		if (FD_ISSET(i, fds)) {
    767  1.10      fvdl 			xprt = __svc_xports[i];
    768  1.10      fvdl 			if (xprt == NULL || xprt->xp_ops == NULL ||
    769  1.10      fvdl 			    xprt->xp_ops->xp_recv != svc_vc_recv)
    770  1.10      fvdl 				continue;
    771  1.10      fvdl 			cd = (struct cf_conn *)xprt->xp_p1;
    772  1.10      fvdl 			if (!cleanblock && !cd->nonblock)
    773  1.10      fvdl 				continue;
    774  1.10      fvdl 			if (timeout == 0) {
    775  1.10      fvdl 				timersub(&tv, &cd->last_recv_time, &tdiff);
    776  1.10      fvdl 				if (timercmp(&tdiff, &tmax, >)) {
    777  1.10      fvdl 					tmax = tdiff;
    778  1.10      fvdl 					least_active = xprt;
    779  1.10      fvdl 				}
    780  1.10      fvdl 				continue;
    781  1.10      fvdl 			}
    782  1.10      fvdl 			if (tv.tv_sec - cd->last_recv_time.tv_sec > timeout) {
    783  1.10      fvdl 				__xprt_unregister_unlocked(xprt);
    784  1.10      fvdl 				__svc_vc_dodestroy(xprt);
    785  1.10      fvdl 				ncleaned++;
    786  1.10      fvdl 			}
    787  1.10      fvdl 		}
    788  1.10      fvdl 	}
    789  1.10      fvdl 	if (timeout == 0 && least_active != NULL) {
    790  1.10      fvdl 		__xprt_unregister_unlocked(least_active);
    791  1.10      fvdl 		__svc_vc_dodestroy(least_active);
    792  1.10      fvdl 		ncleaned++;
    793  1.10      fvdl 	}
    794  1.10      fvdl 	rwlock_unlock(&svc_fd_lock);
    795  1.10      fvdl 	return ncleaned > 0 ? TRUE : FALSE;
    796   1.1      fvdl }
    797