2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
2N/A/* All Rights Reserved */
2N/A/*
2N/A * Portions of this source code were derived from Berkeley
2N/A * 4.3 BSD under license from the Regents of the University of
2N/A * California.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*
2N/A * Protocol for the local binder service, or pmap.
2N/A * All the pmap xdr routines here.
2N/A */
2N/A
2N/A#include "mt.h"
2N/A#include <rpc/types.h>
2N/A#include <rpc/xdr.h>
2N/A#include <rpc/pmap_prot.h>
2N/A#include <rpc/pmap_rmt.h>
2N/A
2N/Abool_t
2N/Axdr_pmap(XDR *xdrs, struct pmap *objp)
2N/A{
2N/A rpc_inline_t *buf;
2N/A
2N/A switch (xdrs->x_op) {
2N/A case XDR_ENCODE:
2N/A buf = XDR_INLINE(xdrs, 4 * BYTES_PER_XDR_UNIT);
2N/A if (buf == NULL) {
2N/A if (!XDR_PUTINT32(xdrs, (int32_t *)&objp->pm_prog))
2N/A return (FALSE);
2N/A if (!XDR_PUTINT32(xdrs, (int32_t *)&objp->pm_vers))
2N/A return (FALSE);
2N/A if (!XDR_PUTINT32(xdrs, (int32_t *)&objp->pm_prot))
2N/A return (FALSE);
2N/A if (!XDR_PUTINT32(xdrs, (int32_t *)&objp->pm_port))
2N/A return (FALSE);
2N/A } else {
2N/A IXDR_PUT_U_INT32(buf, objp->pm_prog);
2N/A IXDR_PUT_U_INT32(buf, objp->pm_vers);
2N/A IXDR_PUT_U_INT32(buf, objp->pm_prot);
2N/A IXDR_PUT_U_INT32(buf, objp->pm_port);
2N/A }
2N/A return (TRUE);
2N/A case XDR_DECODE:
2N/A buf = XDR_INLINE(xdrs, 4 * BYTES_PER_XDR_UNIT);
2N/A if (buf == NULL) {
2N/A if (!XDR_GETINT32(xdrs, (int32_t *)&objp->pm_prog))
2N/A return (FALSE);
2N/A if (!XDR_GETINT32(xdrs, (int32_t *)&objp->pm_vers))
2N/A return (FALSE);
2N/A if (!XDR_GETINT32(xdrs, (int32_t *)&objp->pm_prot))
2N/A return (FALSE);
2N/A if (!XDR_GETINT32(xdrs, (int32_t *)&objp->pm_port))
2N/A return (FALSE);
2N/A } else {
2N/A objp->pm_prog = IXDR_GET_U_INT32(buf);
2N/A objp->pm_vers = IXDR_GET_U_INT32(buf);
2N/A objp->pm_prot = IXDR_GET_U_INT32(buf);
2N/A objp->pm_port = IXDR_GET_U_INT32(buf);
2N/A }
2N/A return (TRUE);
2N/A case XDR_FREE:
2N/A return (TRUE);
2N/A }
2N/A return (FALSE);
2N/A}
2N/A
2N/A/*
2N/A * pmaplist_ptr implements a linked list. The RPCL definition from
2N/A * pmap_prot.x is:
2N/A *
2N/A * struct pm__list {
2N/A * pmap pml_map;
2N/A * struct pm__list *pml_next;
2N/A * };
2N/A * typedef pm__list *pmaplist_ptr;
2N/A *
2N/A * Recall that "pointers" in XDR are encoded as a boolean, indicating whether
2N/A * there's any data behind the pointer, followed by the data (if any exists).
2N/A * The boolean can be interpreted as ``more data follows me''; if FALSE then
2N/A * nothing follows the boolean; if TRUE then the boolean is followed by an
2N/A * actual struct pmap, and another pmaplist_ptr (declared in RPCL as "struct
2N/A * pmaplist *").
2N/A *
2N/A * This could be implemented via the xdr_pointer type, though this would
2N/A * result in one recursive call per element in the list. Rather than do that
2N/A * we can ``unwind'' the recursion into a while loop and use xdr_reference to
2N/A * serialize the pmap elements.
2N/A */
2N/Abool_t
2N/Axdr_pmaplist_ptr(XDR *xdrs, pmaplist_ptr *rp)
2N/A{
2N/A /*
2N/A * more_elements is pre-computed in case the direction is
2N/A * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
2N/A * xdr_bool when the direction is XDR_DECODE.
2N/A */
2N/A bool_t more_elements;
2N/A int freeing = (xdrs->x_op == XDR_FREE);
2N/A pmaplist_ptr next;
2N/A pmaplist_ptr next_copy;
2N/A
2N/A for (;;) {
2N/A more_elements = (bool_t)(*rp != NULL);
2N/A if (!xdr_bool(xdrs, &more_elements))
2N/A return (FALSE);
2N/A if (!more_elements)
2N/A return (TRUE); /* we are done */
2N/A /*
2N/A * the unfortunate side effect of non-recursion is that in
2N/A * the case of freeing we must remember the next object
2N/A * before we free the current object ...
2N/A */
2N/A if (freeing)
2N/A next = (*rp)->pml_next;
2N/A if (!xdr_reference(xdrs, (caddr_t *)rp,
2N/A (uint_t)sizeof (struct pmaplist), (xdrproc_t)xdr_pmap))
2N/A return (FALSE);
2N/A if (freeing) {
2N/A next_copy = next;
2N/A rp = &next_copy;
2N/A /*
2N/A * Note that in the subsequent iteration, next_copy
2N/A * gets nulled out by the xdr_reference
2N/A * but next itself survives.
2N/A */
2N/A } else {
2N/A rp = &((*rp)->pml_next);
2N/A }
2N/A }
2N/A /*NOTREACHED*/
2N/A}
2N/A
2N/A/*
2N/A * xdr_pmaplist() is specified to take a PMAPLIST **, but is identical in
2N/A * functionality to xdr_pmaplist_ptr().
2N/A */
2N/Abool_t
2N/Axdr_pmaplist(XDR *xdrs, PMAPLIST **rp)
2N/A{
2N/A return (xdr_pmaplist_ptr(xdrs, (pmaplist_ptr *)rp));
2N/A}
2N/A
2N/A
2N/A/*
2N/A * XDR remote call arguments
2N/A * written for XDR_ENCODE direction only
2N/A */
2N/Abool_t
2N/Axdr_rmtcallargs(XDR *xdrs, struct p_rmtcallargs *cap)
2N/A{
2N/A uint_t lenposition, argposition, position;
2N/A rpc_inline_t *buf;
2N/A
2N/A buf = XDR_INLINE(xdrs, 3 * BYTES_PER_XDR_UNIT);
2N/A if (buf == NULL) {
2N/A if (!xdr_u_int(xdrs, (uint_t *)&(cap->prog)) ||
2N/A !xdr_u_int(xdrs, (uint_t *)&(cap->vers)) ||
2N/A !xdr_u_int(xdrs, (uint_t *)&(cap->proc)))
2N/A return (FALSE);
2N/A } else {
2N/A IXDR_PUT_U_INT32(buf, cap->prog);
2N/A IXDR_PUT_U_INT32(buf, cap->vers);
2N/A IXDR_PUT_U_INT32(buf, cap->proc);
2N/A }
2N/A
2N/A /*
2N/A * All the jugglery for just getting the size of the arguments
2N/A */
2N/A lenposition = XDR_GETPOS(xdrs);
2N/A if (!xdr_u_int(xdrs, &(cap->args.args_len)))
2N/A return (FALSE);
2N/A argposition = XDR_GETPOS(xdrs);
2N/A if (!(*cap->xdr_args)(xdrs, cap->args.args_val))
2N/A return (FALSE);
2N/A position = XDR_GETPOS(xdrs);
2N/A cap->args.args_len = position - argposition;
2N/A XDR_SETPOS(xdrs, lenposition);
2N/A if (!xdr_u_int(xdrs, &(cap->args.args_len)))
2N/A return (FALSE);
2N/A XDR_SETPOS(xdrs, position);
2N/A return (TRUE);
2N/A}
2N/A
2N/A/*
2N/A * XDR remote call results
2N/A * written for XDR_DECODE direction only
2N/A */
2N/Abool_t
2N/Axdr_rmtcallres(XDR *xdrs, struct p_rmtcallres *crp)
2N/A{
2N/A if (xdr_u_int(xdrs, (uint_t *)&crp->port) &&
2N/A xdr_u_int(xdrs, &crp->res.res_len))
2N/A return ((*(crp->xdr_res))(xdrs, crp->res.res_val));
2N/A return (FALSE);
2N/A}