4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
24 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
28 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
31 * Portions of this source code were derived from Berkeley
32 * 4.3 BSD under license from the Regents of the University of
37 * XDR routines for the rpcbinder version 3.
42 #include <rpc/types.h>
44 #include <rpc/rpcb_prot.h>
48 xdr_rpcb(XDR
*xdrs
, RPCB
*objp
)
50 if (!xdr_u_int(xdrs
, (uint_t
*)&objp
->r_prog
))
52 if (!xdr_u_int(xdrs
, (uint_t
*)&objp
->r_vers
))
54 if (!xdr_string(xdrs
, &objp
->r_netid
, ~0))
56 if (!xdr_string(xdrs
, &objp
->r_addr
, ~0))
58 return (xdr_string(xdrs
, &objp
->r_owner
, ~0));
62 * rpcblist_ptr implements a linked list. The RPCL definition from
67 * struct rpcblist *rpcb_next;
69 * typedef rpcblist *rpcblist_ptr;
71 * Recall that "pointers" in XDR are encoded as a boolean, indicating whether
72 * there's any data behind the pointer, followed by the data (if any exists).
73 * The boolean can be interpreted as ``more data follows me''; if FALSE then
74 * nothing follows the boolean; if TRUE then the boolean is followed by an
75 * actual struct rpcb, and another rpcblist_ptr (declared in RPCL as "struct
78 * This could be implemented via the xdr_pointer type, though this would
79 * result in one recursive call per element in the list. Rather than do that
80 * we can ``unwind'' the recursion into a while loop and use xdr_reference to
81 * serialize the rpcb elements.
85 xdr_rpcblist_ptr(XDR
*xdrs
, rpcblist_ptr
*rp
)
88 * more_elements is pre-computed in case the direction is
89 * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
90 * xdr_bool when the direction is XDR_DECODE.
93 int freeing
= (xdrs
->x_op
== XDR_FREE
);
95 rpcblist_ptr next_copy
;
98 more_elements
= (bool_t
)(*rp
!= NULL
);
99 if (!xdr_bool(xdrs
, &more_elements
))
102 return (TRUE
); /* we are done */
104 * the unfortunate side effect of non-recursion is that in
105 * the case of freeing we must remember the next object
106 * before we free the current object ...
109 next
= (*rp
)->rpcb_next
;
110 if (!xdr_reference(xdrs
, (caddr_t
*)rp
,
111 (uint_t
)sizeof (rpcblist
), (xdrproc_t
)xdr_rpcb
))
117 * Note that in the subsequent iteration, next_copy
118 * gets nulled out by the xdr_reference
119 * but next itself survives.
122 rp
= &((*rp
)->rpcb_next
);
129 * xdr_rpcblist() is specified to take a RPCBLIST **, but is identical in
130 * functionality to xdr_rpcblist_ptr().
133 xdr_rpcblist(XDR
*xdrs
, RPCBLIST
**rp
)
135 return (xdr_rpcblist_ptr(xdrs
, (rpcblist_ptr
*)rp
));
140 xdr_rpcb_entry(XDR
*xdrs
, rpcb_entry
*objp
)
142 if (!xdr_string(xdrs
, &objp
->r_maddr
, ~0))
144 if (!xdr_string(xdrs
, &objp
->r_nc_netid
, ~0))
146 if (!xdr_u_int(xdrs
, &objp
->r_nc_semantics
))
148 if (!xdr_string(xdrs
, &objp
->r_nc_protofmly
, ~0))
150 return (xdr_string(xdrs
, &objp
->r_nc_proto
, ~0));
154 xdr_rpcb_entry_list_ptr(XDR
*xdrs
, rpcb_entry_list_ptr
*rp
)
157 * more_elements is pre-computed in case the direction is
158 * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
159 * xdr_bool when the direction is XDR_DECODE.
161 bool_t more_elements
;
162 int freeing
= (xdrs
->x_op
== XDR_FREE
);
163 rpcb_entry_list_ptr next
;
164 rpcb_entry_list_ptr next_copy
;
167 more_elements
= (bool_t
)(*rp
!= NULL
);
168 if (!xdr_bool(xdrs
, &more_elements
))
171 return (TRUE
); /* we are done */
173 * the unfortunate side effect of non-recursion is that in
174 * the case of freeing we must remember the next object
175 * before we free the current object ...
178 next
= (*rp
)->rpcb_entry_next
;
179 if (!xdr_reference(xdrs
, (caddr_t
*)rp
,
180 (uint_t
)sizeof (rpcb_entry_list
),
181 (xdrproc_t
)xdr_rpcb_entry
))
187 * Note that in the subsequent iteration, next_copy
188 * gets nulled out by the xdr_reference
189 * but next itself survives.
192 rp
= &((*rp
)->rpcb_entry_next
);
199 * XDR remote call arguments
200 * written for XDR_ENCODE direction only
203 xdr_rpcb_rmtcallargs(XDR
*xdrs
, struct r_rpcb_rmtcallargs
*objp
)
205 uint_t lenposition
, argposition
, position
;
208 buf
= XDR_INLINE(xdrs
, 3 * BYTES_PER_XDR_UNIT
);
210 if (!xdr_u_int(xdrs
, (uint_t
*)&objp
->prog
))
212 if (!xdr_u_int(xdrs
, (uint_t
*)&objp
->vers
))
214 if (!xdr_u_int(xdrs
, (uint_t
*)&objp
->proc
))
217 IXDR_PUT_U_INT32(buf
, objp
->prog
);
218 IXDR_PUT_U_INT32(buf
, objp
->vers
);
219 IXDR_PUT_U_INT32(buf
, objp
->proc
);
223 * All the jugglery for just getting the size of the arguments
225 lenposition
= XDR_GETPOS(xdrs
);
226 if (!xdr_u_int(xdrs
, &(objp
->args
.args_len
)))
228 argposition
= XDR_GETPOS(xdrs
);
229 if (!(*objp
->xdr_args
)(xdrs
, objp
->args
.args_val
))
231 position
= XDR_GETPOS(xdrs
);
232 objp
->args
.args_len
= (uint_t
)position
- (uint_t
)argposition
;
233 XDR_SETPOS(xdrs
, lenposition
);
234 if (!xdr_u_int(xdrs
, &(objp
->args
.args_len
)))
236 XDR_SETPOS(xdrs
, position
);
241 * XDR remote call results
242 * written for XDR_DECODE direction only
245 xdr_rpcb_rmtcallres(XDR
*xdrs
, struct r_rpcb_rmtcallres
*objp
)
247 if (!xdr_string(xdrs
, &objp
->addr
, ~0))
249 if (!xdr_u_int(xdrs
, &objp
->results
.results_len
))
251 return ((*(objp
->xdr_res
))(xdrs
, objp
->results
.results_val
));
255 xdr_netbuf(XDR
*xdrs
, struct netbuf
*objp
)
260 * Save the passed in maxlen value and buf pointer. We might
263 uint_t maxlen_save
= objp
->maxlen
;
264 void *buf_save
= objp
->buf
;
266 if (!xdr_u_int(xdrs
, &objp
->maxlen
))
270 * We need to free maxlen, not len, so do it explicitly now.
272 if (xdrs
->x_op
== XDR_FREE
)
273 return (xdr_bytes(xdrs
, &objp
->buf
, &objp
->maxlen
,
277 * If we're decoding and the caller has already allocated a
278 * buffer restore the maxlen value since the decoded value
279 * doesn't apply to the caller's buffer. xdr_bytes() will
280 * return an error if the buffer isn't big enough.
282 if (xdrs
->x_op
== XDR_DECODE
&& objp
->buf
!= NULL
)
283 objp
->maxlen
= maxlen_save
;
285 res
= xdr_bytes(xdrs
, &objp
->buf
, &objp
->len
, objp
->maxlen
);
288 * If we are decoding and the buffer was allocated in the
289 * xdr_bytes() function we need to set maxlen properly to
290 * follow the netbuf semantics.
292 if (xdrs
->x_op
== XDR_DECODE
&& objp
->buf
!= buf_save
)
293 objp
->maxlen
= objp
->len
;