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 * XDR routines for the rpcbinder version 3.
2N/A */
2N/A
2N/A#include "mt.h"
2N/A#include <rpc/rpc.h>
2N/A#include <rpc/types.h>
2N/A#include <rpc/xdr.h>
2N/A#include <rpc/rpcb_prot.h>
2N/A
2N/A
2N/Abool_t
2N/Axdr_rpcb(XDR *xdrs, RPCB *objp)
2N/A{
2N/A if (!xdr_u_int(xdrs, (uint_t *)&objp->r_prog))
2N/A return (FALSE);
2N/A if (!xdr_u_int(xdrs, (uint_t *)&objp->r_vers))
2N/A return (FALSE);
2N/A if (!xdr_string(xdrs, &objp->r_netid, ~0))
2N/A return (FALSE);
2N/A if (!xdr_string(xdrs, &objp->r_addr, ~0))
2N/A return (FALSE);
2N/A return (xdr_string(xdrs, &objp->r_owner, ~0));
2N/A}
2N/A
2N/A/*
2N/A * rpcblist_ptr implements a linked list. The RPCL definition from
2N/A * rpcb_prot.x is:
2N/A *
2N/A * struct rpcblist {
2N/A * rpcb rpcb_map;
2N/A * struct rpcblist *rpcb_next;
2N/A * };
2N/A * typedef rpcblist *rpcblist_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 rpcb, and another rpcblist_ptr (declared in RPCL as "struct
2N/A * rpcblist *").
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 rpcb elements.
2N/A */
2N/A
2N/Abool_t
2N/Axdr_rpcblist_ptr(XDR *xdrs, rpcblist_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 rpcblist_ptr next;
2N/A rpcblist_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)->rpcb_next;
2N/A if (!xdr_reference(xdrs, (caddr_t *)rp,
2N/A (uint_t)sizeof (rpcblist), (xdrproc_t)xdr_rpcb))
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)->rpcb_next);
2N/A }
2N/A }
2N/A /*NOTREACHED*/
2N/A}
2N/A
2N/A/*
2N/A * xdr_rpcblist() is specified to take a RPCBLIST **, but is identical in
2N/A * functionality to xdr_rpcblist_ptr().
2N/A */
2N/Abool_t
2N/Axdr_rpcblist(XDR *xdrs, RPCBLIST **rp)
2N/A{
2N/A return (xdr_rpcblist_ptr(xdrs, (rpcblist_ptr *)rp));
2N/A}
2N/A
2N/A
2N/Abool_t
2N/Axdr_rpcb_entry(XDR *xdrs, rpcb_entry *objp)
2N/A{
2N/A if (!xdr_string(xdrs, &objp->r_maddr, ~0))
2N/A return (FALSE);
2N/A if (!xdr_string(xdrs, &objp->r_nc_netid, ~0))
2N/A return (FALSE);
2N/A if (!xdr_u_int(xdrs, &objp->r_nc_semantics))
2N/A return (FALSE);
2N/A if (!xdr_string(xdrs, &objp->r_nc_protofmly, ~0))
2N/A return (FALSE);
2N/A return (xdr_string(xdrs, &objp->r_nc_proto, ~0));
2N/A}
2N/A
2N/Abool_t
2N/Axdr_rpcb_entry_list_ptr(XDR *xdrs, rpcb_entry_list_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 rpcb_entry_list_ptr next;
2N/A rpcb_entry_list_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)->rpcb_entry_next;
2N/A if (!xdr_reference(xdrs, (caddr_t *)rp,
2N/A (uint_t)sizeof (rpcb_entry_list),
2N/A (xdrproc_t)xdr_rpcb_entry))
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)->rpcb_entry_next);
2N/A }
2N/A }
2N/A /*NOTREACHED*/
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_rpcb_rmtcallargs(XDR *xdrs, struct r_rpcb_rmtcallargs *objp)
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 *)&objp->prog))
2N/A return (FALSE);
2N/A if (!xdr_u_int(xdrs, (uint_t *)&objp->vers))
2N/A return (FALSE);
2N/A if (!xdr_u_int(xdrs, (uint_t *)&objp->proc))
2N/A return (FALSE);
2N/A } else {
2N/A IXDR_PUT_U_INT32(buf, objp->prog);
2N/A IXDR_PUT_U_INT32(buf, objp->vers);
2N/A IXDR_PUT_U_INT32(buf, objp->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, &(objp->args.args_len)))
2N/A return (FALSE);
2N/A argposition = XDR_GETPOS(xdrs);
2N/A if (!(*objp->xdr_args)(xdrs, objp->args.args_val))
2N/A return (FALSE);
2N/A position = XDR_GETPOS(xdrs);
2N/A objp->args.args_len = (uint_t)position - (uint_t)argposition;
2N/A XDR_SETPOS(xdrs, lenposition);
2N/A if (!xdr_u_int(xdrs, &(objp->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_rpcb_rmtcallres(XDR *xdrs, struct r_rpcb_rmtcallres *objp)
2N/A{
2N/A if (!xdr_string(xdrs, &objp->addr, ~0))
2N/A return (FALSE);
2N/A if (!xdr_u_int(xdrs, &objp->results.results_len))
2N/A return (FALSE);
2N/A return ((*(objp->xdr_res))(xdrs, objp->results.results_val));
2N/A}
2N/A
2N/Abool_t
2N/Axdr_netbuf(XDR *xdrs, struct netbuf *objp)
2N/A{
2N/A if (!xdr_u_int(xdrs, (uint_t *)&objp->maxlen))
2N/A return (FALSE);
2N/A return (xdr_bytes(xdrs, (char **)&(objp->buf),
2N/A (uint_t *)&(objp->len), objp->maxlen));
2N/A}