10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
21132Srobinson */
22132Srobinson
23132Srobinson /*
24*1219Sraf * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
250Sstevel@tonic-gate * Use is subject to license terms.
260Sstevel@tonic-gate */
27*1219Sraf
280Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
290Sstevel@tonic-gate /* All Rights Reserved */
300Sstevel@tonic-gate /*
310Sstevel@tonic-gate * Portions of this source code were derived from Berkeley
320Sstevel@tonic-gate * 4.3 BSD under license from the Regents of the University of
330Sstevel@tonic-gate * California.
340Sstevel@tonic-gate */
350Sstevel@tonic-gate
360Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
370Sstevel@tonic-gate
380Sstevel@tonic-gate /*
390Sstevel@tonic-gate * XDR routines for the rpcbinder version 3.
400Sstevel@tonic-gate */
410Sstevel@tonic-gate
42*1219Sraf #include "mt.h"
430Sstevel@tonic-gate #include <rpc/rpc.h>
440Sstevel@tonic-gate #include <rpc/types.h>
450Sstevel@tonic-gate #include <rpc/xdr.h>
460Sstevel@tonic-gate #include <rpc/rpcb_prot.h>
470Sstevel@tonic-gate
480Sstevel@tonic-gate
490Sstevel@tonic-gate bool_t
xdr_rpcb(XDR * xdrs,RPCB * objp)50132Srobinson xdr_rpcb(XDR *xdrs, RPCB *objp)
510Sstevel@tonic-gate {
52132Srobinson if (!xdr_u_int(xdrs, (uint_t *)&objp->r_prog))
530Sstevel@tonic-gate return (FALSE);
54132Srobinson if (!xdr_u_int(xdrs, (uint_t *)&objp->r_vers))
550Sstevel@tonic-gate return (FALSE);
56132Srobinson if (!xdr_string(xdrs, &objp->r_netid, ~0))
570Sstevel@tonic-gate return (FALSE);
58132Srobinson if (!xdr_string(xdrs, &objp->r_addr, ~0))
590Sstevel@tonic-gate return (FALSE);
60132Srobinson return (xdr_string(xdrs, &objp->r_owner, ~0));
610Sstevel@tonic-gate }
620Sstevel@tonic-gate
630Sstevel@tonic-gate /*
640Sstevel@tonic-gate * rpcblist_ptr implements a linked list. The RPCL definition from
650Sstevel@tonic-gate * rpcb_prot.x is:
660Sstevel@tonic-gate *
670Sstevel@tonic-gate * struct rpcblist {
680Sstevel@tonic-gate * rpcb rpcb_map;
690Sstevel@tonic-gate * struct rpcblist *rpcb_next;
700Sstevel@tonic-gate * };
710Sstevel@tonic-gate * typedef rpcblist *rpcblist_ptr;
720Sstevel@tonic-gate *
730Sstevel@tonic-gate * Recall that "pointers" in XDR are encoded as a boolean, indicating whether
740Sstevel@tonic-gate * there's any data behind the pointer, followed by the data (if any exists).
750Sstevel@tonic-gate * The boolean can be interpreted as ``more data follows me''; if FALSE then
760Sstevel@tonic-gate * nothing follows the boolean; if TRUE then the boolean is followed by an
770Sstevel@tonic-gate * actual struct rpcb, and another rpcblist_ptr (declared in RPCL as "struct
780Sstevel@tonic-gate * rpcblist *").
790Sstevel@tonic-gate *
800Sstevel@tonic-gate * This could be implemented via the xdr_pointer type, though this would
810Sstevel@tonic-gate * result in one recursive call per element in the list. Rather than do that
820Sstevel@tonic-gate * we can ``unwind'' the recursion into a while loop and use xdr_reference to
830Sstevel@tonic-gate * serialize the rpcb elements.
840Sstevel@tonic-gate */
850Sstevel@tonic-gate
860Sstevel@tonic-gate bool_t
xdr_rpcblist_ptr(XDR * xdrs,rpcblist_ptr * rp)87132Srobinson xdr_rpcblist_ptr(XDR *xdrs, rpcblist_ptr *rp)
880Sstevel@tonic-gate {
890Sstevel@tonic-gate /*
900Sstevel@tonic-gate * more_elements is pre-computed in case the direction is
910Sstevel@tonic-gate * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
920Sstevel@tonic-gate * xdr_bool when the direction is XDR_DECODE.
930Sstevel@tonic-gate */
940Sstevel@tonic-gate bool_t more_elements;
95132Srobinson int freeing = (xdrs->x_op == XDR_FREE);
960Sstevel@tonic-gate rpcblist_ptr next;
970Sstevel@tonic-gate rpcblist_ptr next_copy;
980Sstevel@tonic-gate
99132Srobinson for (;;) {
1000Sstevel@tonic-gate more_elements = (bool_t)(*rp != NULL);
101132Srobinson if (!xdr_bool(xdrs, &more_elements))
1020Sstevel@tonic-gate return (FALSE);
103132Srobinson if (!more_elements)
1040Sstevel@tonic-gate return (TRUE); /* we are done */
1050Sstevel@tonic-gate /*
1060Sstevel@tonic-gate * the unfortunate side effect of non-recursion is that in
1070Sstevel@tonic-gate * the case of freeing we must remember the next object
1080Sstevel@tonic-gate * before we free the current object ...
1090Sstevel@tonic-gate */
1100Sstevel@tonic-gate if (freeing)
1110Sstevel@tonic-gate next = (*rp)->rpcb_next;
112132Srobinson if (!xdr_reference(xdrs, (caddr_t *)rp,
113132Srobinson (uint_t)sizeof (rpcblist), (xdrproc_t)xdr_rpcb))
1140Sstevel@tonic-gate return (FALSE);
1150Sstevel@tonic-gate if (freeing) {
1160Sstevel@tonic-gate next_copy = next;
1170Sstevel@tonic-gate rp = &next_copy;
1180Sstevel@tonic-gate /*
1190Sstevel@tonic-gate * Note that in the subsequent iteration, next_copy
1200Sstevel@tonic-gate * gets nulled out by the xdr_reference
1210Sstevel@tonic-gate * but next itself survives.
1220Sstevel@tonic-gate */
1230Sstevel@tonic-gate } else {
1240Sstevel@tonic-gate rp = &((*rp)->rpcb_next);
1250Sstevel@tonic-gate }
1260Sstevel@tonic-gate }
1270Sstevel@tonic-gate /*NOTREACHED*/
1280Sstevel@tonic-gate }
1290Sstevel@tonic-gate
1300Sstevel@tonic-gate /*
1310Sstevel@tonic-gate * xdr_rpcblist() is specified to take a RPCBLIST **, but is identical in
1320Sstevel@tonic-gate * functionality to xdr_rpcblist_ptr().
1330Sstevel@tonic-gate */
1340Sstevel@tonic-gate bool_t
xdr_rpcblist(XDR * xdrs,RPCBLIST ** rp)135132Srobinson xdr_rpcblist(XDR *xdrs, RPCBLIST **rp)
1360Sstevel@tonic-gate {
137132Srobinson return (xdr_rpcblist_ptr(xdrs, (rpcblist_ptr *)rp));
1380Sstevel@tonic-gate }
1390Sstevel@tonic-gate
1400Sstevel@tonic-gate
1410Sstevel@tonic-gate bool_t
xdr_rpcb_entry(XDR * xdrs,rpcb_entry * objp)142132Srobinson xdr_rpcb_entry(XDR *xdrs, rpcb_entry *objp)
1430Sstevel@tonic-gate {
144132Srobinson if (!xdr_string(xdrs, &objp->r_maddr, ~0))
1450Sstevel@tonic-gate return (FALSE);
146132Srobinson if (!xdr_string(xdrs, &objp->r_nc_netid, ~0))
1470Sstevel@tonic-gate return (FALSE);
148132Srobinson if (!xdr_u_int(xdrs, &objp->r_nc_semantics))
1490Sstevel@tonic-gate return (FALSE);
150132Srobinson if (!xdr_string(xdrs, &objp->r_nc_protofmly, ~0))
1510Sstevel@tonic-gate return (FALSE);
152132Srobinson return (xdr_string(xdrs, &objp->r_nc_proto, ~0));
1530Sstevel@tonic-gate }
1540Sstevel@tonic-gate
1550Sstevel@tonic-gate bool_t
xdr_rpcb_entry_list_ptr(XDR * xdrs,rpcb_entry_list_ptr * rp)156132Srobinson xdr_rpcb_entry_list_ptr(XDR *xdrs, rpcb_entry_list_ptr *rp)
1570Sstevel@tonic-gate {
1580Sstevel@tonic-gate /*
1590Sstevel@tonic-gate * more_elements is pre-computed in case the direction is
1600Sstevel@tonic-gate * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
1610Sstevel@tonic-gate * xdr_bool when the direction is XDR_DECODE.
1620Sstevel@tonic-gate */
1630Sstevel@tonic-gate bool_t more_elements;
164132Srobinson int freeing = (xdrs->x_op == XDR_FREE);
1650Sstevel@tonic-gate rpcb_entry_list_ptr next;
1660Sstevel@tonic-gate rpcb_entry_list_ptr next_copy;
1670Sstevel@tonic-gate
168132Srobinson for (;;) {
1690Sstevel@tonic-gate more_elements = (bool_t)(*rp != NULL);
170132Srobinson if (!xdr_bool(xdrs, &more_elements))
1710Sstevel@tonic-gate return (FALSE);
172132Srobinson if (!more_elements)
1730Sstevel@tonic-gate return (TRUE); /* we are done */
1740Sstevel@tonic-gate /*
1750Sstevel@tonic-gate * the unfortunate side effect of non-recursion is that in
1760Sstevel@tonic-gate * the case of freeing we must remember the next object
1770Sstevel@tonic-gate * before we free the current object ...
1780Sstevel@tonic-gate */
1790Sstevel@tonic-gate if (freeing)
1800Sstevel@tonic-gate next = (*rp)->rpcb_entry_next;
181132Srobinson if (!xdr_reference(xdrs, (caddr_t *)rp,
182132Srobinson (uint_t)sizeof (rpcb_entry_list),
183132Srobinson (xdrproc_t)xdr_rpcb_entry))
1840Sstevel@tonic-gate return (FALSE);
1850Sstevel@tonic-gate if (freeing) {
1860Sstevel@tonic-gate next_copy = next;
1870Sstevel@tonic-gate rp = &next_copy;
1880Sstevel@tonic-gate /*
1890Sstevel@tonic-gate * Note that in the subsequent iteration, next_copy
1900Sstevel@tonic-gate * gets nulled out by the xdr_reference
1910Sstevel@tonic-gate * but next itself survives.
1920Sstevel@tonic-gate */
1930Sstevel@tonic-gate } else {
1940Sstevel@tonic-gate rp = &((*rp)->rpcb_entry_next);
1950Sstevel@tonic-gate }
1960Sstevel@tonic-gate }
1970Sstevel@tonic-gate /*NOTREACHED*/
1980Sstevel@tonic-gate }
1990Sstevel@tonic-gate
2000Sstevel@tonic-gate /*
2010Sstevel@tonic-gate * XDR remote call arguments
2020Sstevel@tonic-gate * written for XDR_ENCODE direction only
2030Sstevel@tonic-gate */
2040Sstevel@tonic-gate bool_t
xdr_rpcb_rmtcallargs(XDR * xdrs,struct r_rpcb_rmtcallargs * objp)205132Srobinson xdr_rpcb_rmtcallargs(XDR *xdrs, struct r_rpcb_rmtcallargs *objp)
2060Sstevel@tonic-gate {
207132Srobinson uint_t lenposition, argposition, position;
208132Srobinson rpc_inline_t *buf;
2090Sstevel@tonic-gate
2100Sstevel@tonic-gate buf = XDR_INLINE(xdrs, 3 * BYTES_PER_XDR_UNIT);
2110Sstevel@tonic-gate if (buf == NULL) {
212132Srobinson if (!xdr_u_int(xdrs, (uint_t *)&objp->prog))
2130Sstevel@tonic-gate return (FALSE);
214132Srobinson if (!xdr_u_int(xdrs, (uint_t *)&objp->vers))
2150Sstevel@tonic-gate return (FALSE);
216132Srobinson if (!xdr_u_int(xdrs, (uint_t *)&objp->proc))
2170Sstevel@tonic-gate return (FALSE);
2180Sstevel@tonic-gate } else {
2190Sstevel@tonic-gate IXDR_PUT_U_INT32(buf, objp->prog);
2200Sstevel@tonic-gate IXDR_PUT_U_INT32(buf, objp->vers);
2210Sstevel@tonic-gate IXDR_PUT_U_INT32(buf, objp->proc);
2220Sstevel@tonic-gate }
2230Sstevel@tonic-gate
2240Sstevel@tonic-gate /*
2250Sstevel@tonic-gate * All the jugglery for just getting the size of the arguments
2260Sstevel@tonic-gate */
2270Sstevel@tonic-gate lenposition = XDR_GETPOS(xdrs);
228132Srobinson if (!xdr_u_int(xdrs, &(objp->args.args_len)))
2290Sstevel@tonic-gate return (FALSE);
2300Sstevel@tonic-gate argposition = XDR_GETPOS(xdrs);
231132Srobinson if (!(*objp->xdr_args)(xdrs, objp->args.args_val))
2320Sstevel@tonic-gate return (FALSE);
2330Sstevel@tonic-gate position = XDR_GETPOS(xdrs);
234132Srobinson objp->args.args_len = (uint_t)position - (uint_t)argposition;
2350Sstevel@tonic-gate XDR_SETPOS(xdrs, lenposition);
236132Srobinson if (!xdr_u_int(xdrs, &(objp->args.args_len)))
2370Sstevel@tonic-gate return (FALSE);
2380Sstevel@tonic-gate XDR_SETPOS(xdrs, position);
2390Sstevel@tonic-gate return (TRUE);
2400Sstevel@tonic-gate }
2410Sstevel@tonic-gate
2420Sstevel@tonic-gate /*
2430Sstevel@tonic-gate * XDR remote call results
2440Sstevel@tonic-gate * written for XDR_DECODE direction only
2450Sstevel@tonic-gate */
2460Sstevel@tonic-gate bool_t
xdr_rpcb_rmtcallres(XDR * xdrs,struct r_rpcb_rmtcallres * objp)247132Srobinson xdr_rpcb_rmtcallres(XDR *xdrs, struct r_rpcb_rmtcallres *objp)
2480Sstevel@tonic-gate {
249132Srobinson if (!xdr_string(xdrs, &objp->addr, ~0))
2500Sstevel@tonic-gate return (FALSE);
251132Srobinson if (!xdr_u_int(xdrs, &objp->results.results_len))
2520Sstevel@tonic-gate return (FALSE);
253132Srobinson return ((*(objp->xdr_res))(xdrs, objp->results.results_val));
2540Sstevel@tonic-gate }
2550Sstevel@tonic-gate
2560Sstevel@tonic-gate bool_t
xdr_netbuf(XDR * xdrs,struct netbuf * objp)257132Srobinson xdr_netbuf(XDR *xdrs, struct netbuf *objp)
2580Sstevel@tonic-gate {
259132Srobinson if (!xdr_u_int(xdrs, (uint_t *)&objp->maxlen))
2600Sstevel@tonic-gate return (FALSE);
261132Srobinson return (xdr_bytes(xdrs, (char **)&(objp->buf),
262132Srobinson (uint_t *)&(objp->len), objp->maxlen));
2630Sstevel@tonic-gate }
264