1 /* $NetBSD: rpcb_prot.c,v 1.3 2000/07/14 08:40:42 fvdl Exp $ */
4 * SPDX-License-Identifier: BSD-3-Clause
6 * Copyright (c) 2009, Sun Microsystems, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 * - Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 * - Neither the name of Sun Microsystems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (c) 1986-1991 by Sun Microsystems Inc.
36 /* #ident "@(#)rpcb_prot.c 1.13 94/04/24 SMI" */
38 #if defined(LIBC_SCCS) && !defined(lint)
39 static char sccsid[] = "@(#)rpcb_prot.c 1.9 89/04/21 Copyr 1984 Sun Micro";
41 #include <sys/cdefs.h>
42 __FBSDID("$FreeBSD$");
46 * XDR routines for the rpcbinder version 3.
48 * Copyright (C) 1984, 1988, Sun Microsystems, Inc.
51 #include <sys/param.h>
52 #include <sys/systm.h>
53 #include <sys/kernel.h>
54 #include <sys/malloc.h>
57 #include <rpc/rpc_com.h>
58 #include <rpc/rpcb_prot.h>
61 xdr_portmap(XDR *xdrs, struct portmap *regs)
64 if (xdr_u_long(xdrs, ®s->pm_prog) &&
65 xdr_u_long(xdrs, ®s->pm_vers) &&
66 xdr_u_long(xdrs, ®s->pm_prot))
67 return (xdr_u_long(xdrs, ®s->pm_port));
72 xdr_rpcb(XDR *xdrs, RPCB *objp)
74 if (!xdr_uint32_t(xdrs, &objp->r_prog)) {
77 if (!xdr_uint32_t(xdrs, &objp->r_vers)) {
80 if (!xdr_string(xdrs, &objp->r_netid, RPC_MAXDATASIZE)) {
83 if (!xdr_string(xdrs, &objp->r_addr, RPC_MAXDATASIZE)) {
86 if (!xdr_string(xdrs, &objp->r_owner, RPC_MAXDATASIZE)) {
93 * rpcblist_ptr implements a linked list. The RPCL definition from
98 * struct rpcblist *rpcb_next;
100 * typedef rpcblist *rpcblist_ptr;
102 * Recall that "pointers" in XDR are encoded as a boolean, indicating whether
103 * there's any data behind the pointer, followed by the data (if any exists).
104 * The boolean can be interpreted as ``more data follows me''; if FALSE then
105 * nothing follows the boolean; if TRUE then the boolean is followed by an
106 * actual struct rpcb, and another rpcblist_ptr (declared in RPCL as "struct
109 * This could be implemented via the xdr_pointer type, though this would
110 * result in one recursive call per element in the list. Rather than do that
111 * we can ``unwind'' the recursion into a while loop and use xdr_reference to
112 * serialize the rpcb elements.
116 xdr_rpcblist_ptr(XDR *xdrs, rpcblist_ptr *rp)
119 * more_elements is pre-computed in case the direction is
120 * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
121 * xdr_bool when the direction is XDR_DECODE.
123 bool_t more_elements;
124 int freeing = (xdrs->x_op == XDR_FREE);
126 rpcblist_ptr next_copy;
130 more_elements = (bool_t)(*rp != NULL);
131 if (! xdr_bool(xdrs, &more_elements)) {
134 if (! more_elements) {
135 return (TRUE); /* we are done */
138 * the unfortunate side effect of non-recursion is that in
139 * the case of freeing we must remember the next object
140 * before we free the current object ...
143 next = (*rp)->rpcb_next;
144 if (! xdr_reference(xdrs, (caddr_t *)rp,
145 (u_int)sizeof (RPCBLIST), (xdrproc_t)xdr_rpcb)) {
152 * Note that in the subsequent iteration, next_copy
153 * gets nulled out by the xdr_reference
154 * but next itself survives.
157 rp = &((*rp)->rpcb_next);
165 * xdr_rpcblist() is specified to take a RPCBLIST **, but is identical in
166 * functionality to xdr_rpcblist_ptr().
169 xdr_rpcblist(XDR *xdrs, RPCBLIST **rp)
173 dummy = xdr_rpcblist_ptr(xdrs, (rpcblist_ptr *)rp);
179 xdr_rpcb_entry(XDR *xdrs, rpcb_entry *objp)
181 if (!xdr_string(xdrs, &objp->r_maddr, RPC_MAXDATASIZE)) {
184 if (!xdr_string(xdrs, &objp->r_nc_netid, RPC_MAXDATASIZE)) {
187 if (!xdr_uint32_t(xdrs, &objp->r_nc_semantics)) {
190 if (!xdr_string(xdrs, &objp->r_nc_protofmly, RPC_MAXDATASIZE)) {
193 if (!xdr_string(xdrs, &objp->r_nc_proto, RPC_MAXDATASIZE)) {
200 xdr_rpcb_entry_list_ptr(XDR *xdrs, rpcb_entry_list_ptr *rp)
203 * more_elements is pre-computed in case the direction is
204 * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
205 * xdr_bool when the direction is XDR_DECODE.
207 bool_t more_elements;
208 int freeing = (xdrs->x_op == XDR_FREE);
209 rpcb_entry_list_ptr next;
210 rpcb_entry_list_ptr next_copy;
214 more_elements = (bool_t)(*rp != NULL);
215 if (! xdr_bool(xdrs, &more_elements)) {
218 if (! more_elements) {
219 return (TRUE); /* we are done */
222 * the unfortunate side effect of non-recursion is that in
223 * the case of freeing we must remember the next object
224 * before we free the current object ...
227 next = (*rp)->rpcb_entry_next;
228 if (! xdr_reference(xdrs, (caddr_t *)rp,
229 (u_int)sizeof (rpcb_entry_list),
230 (xdrproc_t)xdr_rpcb_entry)) {
233 if (freeing && *rp) {
237 * Note that in the subsequent iteration, next_copy
238 * gets nulled out by the xdr_reference
239 * but next itself survives.
242 rp = &((*rp)->rpcb_entry_next);