1/*	$NetBSD: rpcb_st_xdr.c,v 1.7 2006/05/11 17:11:57 mrg Exp $	*/
2
3/*
4 * Copyright (c) 2010, Oracle America, Inc.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 *     * Redistributions of source code must retain the above copyright
11 *       notice, this list of conditions and the following disclaimer.
12 *     * Redistributions in binary form must reproduce the above
13 *       copyright notice, this list of conditions and the following
14 *       disclaimer in the documentation and/or other materials
15 *       provided with the distribution.
16 *     * Neither the name of the "Oracle America, 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.
19 *
20 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27 *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33/*
34 * Copyright 1991 Sun Microsystems, Inc.
35 * rpcb_stat_xdr.c
36 */
37
38/*
39 * This file was generated from rpcb_prot.x, but includes only those
40 * routines used with the rpcbind stats facility.
41 */
42
43#include <sys/cdefs.h>
44#if defined(LIBC_SCCS) && !defined(lint)
45__RCSID("$NetBSD: rpcb_st_xdr.c,v 1.7 2006/05/11 17:11:57 mrg Exp $");
46#endif
47
48#include "namespace.h"
49#include <rpc/rpc.h>
50
51#include <assert.h>
52
53/* Link list of all the stats about getport and getaddr */
54
55#ifdef __weak_alias
56__weak_alias(xdr_rpcbs_addrlist,_xdr_rpcbs_addrlist)
57__weak_alias(xdr_rpcbs_rmtcalllist,_xdr_rpcbs_rmtcalllist)
58__weak_alias(xdr_rpcbs_proc,_xdr_rpcbs_proc)
59__weak_alias(xdr_rpcbs_addrlist_ptr,_xdr_rpcbs_addrlist_ptr)
60__weak_alias(xdr_rpcbs_rmtcalllist_ptr,_xdr_rpcbs_rmtcalllist_ptr)
61__weak_alias(xdr_rpcb_stat,_xdr_rpcb_stat)
62__weak_alias(xdr_rpcb_stat_byvers,_xdr_rpcb_stat_byvers)
63#endif
64
65bool_t
66xdr_rpcbs_addrlist(xdrs, objp)
67	XDR *xdrs;
68	rpcbs_addrlist *objp;
69{
70
71	_DIAGASSERT(objp != NULL);
72
73	    if (!xdr_u_int32_t(xdrs, &objp->prog)) {
74		return (FALSE);
75	    }
76	    if (!xdr_u_int32_t(xdrs, &objp->vers)) {
77		return (FALSE);
78	    }
79	    if (!xdr_int(xdrs, &objp->success)) {
80		return (FALSE);
81	    }
82	    if (!xdr_int(xdrs, &objp->failure)) {
83		return (FALSE);
84	    }
85	    if (!xdr_string(xdrs, &objp->netid, (u_int)~0)) {
86		return (FALSE);
87	    }
88
89	    if (!xdr_pointer(xdrs, (char **)(void *)&objp->next,
90			sizeof (rpcbs_addrlist),
91			(xdrproc_t)xdr_rpcbs_addrlist)) {
92		return (FALSE);
93	    }
94
95	return (TRUE);
96}
97
98/* Link list of all the stats about rmtcall */
99
100bool_t
101xdr_rpcbs_rmtcalllist(xdrs, objp)
102	XDR *xdrs;
103	rpcbs_rmtcalllist *objp;
104{
105	int32_t *buf;
106
107	_DIAGASSERT(xdrs != NULL);
108	_DIAGASSERT(objp != NULL);
109
110	if (xdrs->x_op == XDR_ENCODE) {
111	buf = XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT);
112	if (buf == NULL) {
113		if (!xdr_u_int32_t(xdrs, &objp->prog)) {
114			return (FALSE);
115		}
116		if (!xdr_u_int32_t(xdrs, &objp->vers)) {
117			return (FALSE);
118		}
119		if (!xdr_u_int32_t(xdrs, &objp->proc)) {
120			return (FALSE);
121		}
122		if (!xdr_int(xdrs, &objp->success)) {
123			return (FALSE);
124		}
125		if (!xdr_int(xdrs, &objp->failure)) {
126			return (FALSE);
127		}
128		if (!xdr_int(xdrs, &objp->indirect)) {
129			return (FALSE);
130		}
131	} else {
132		IXDR_PUT_U_INT32(buf, objp->prog);
133		IXDR_PUT_U_INT32(buf, objp->vers);
134		IXDR_PUT_U_INT32(buf, objp->proc);
135		IXDR_PUT_INT32(buf, objp->success);
136		IXDR_PUT_INT32(buf, objp->failure);
137		IXDR_PUT_INT32(buf, objp->indirect);
138	}
139	if (!xdr_string(xdrs, &objp->netid, (u_int)~0)) {
140		return (FALSE);
141	}
142	if (!xdr_pointer(xdrs, (char **)(void *)&objp->next,
143			sizeof (rpcbs_rmtcalllist),
144			(xdrproc_t)xdr_rpcbs_rmtcalllist)) {
145		return (FALSE);
146	}
147	return (TRUE);
148	} else if (xdrs->x_op == XDR_DECODE) {
149	buf = XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT);
150	if (buf == NULL) {
151		if (!xdr_u_int32_t(xdrs, &objp->prog)) {
152			return (FALSE);
153		}
154		if (!xdr_u_int32_t(xdrs, &objp->vers)) {
155			return (FALSE);
156		}
157		if (!xdr_u_int32_t(xdrs, &objp->proc)) {
158			return (FALSE);
159		}
160		if (!xdr_int(xdrs, &objp->success)) {
161			return (FALSE);
162		}
163		if (!xdr_int(xdrs, &objp->failure)) {
164			return (FALSE);
165		}
166		if (!xdr_int(xdrs, &objp->indirect)) {
167			return (FALSE);
168		}
169	} else {
170		objp->prog = (rpcprog_t)IXDR_GET_U_INT32(buf);
171		objp->vers = (rpcvers_t)IXDR_GET_U_INT32(buf);
172		objp->proc = (rpcproc_t)IXDR_GET_U_INT32(buf);
173		objp->success = (int)IXDR_GET_INT32(buf);
174		objp->failure = (int)IXDR_GET_INT32(buf);
175		objp->indirect = (int)IXDR_GET_INT32(buf);
176	}
177	if (!xdr_string(xdrs, &objp->netid, (u_int)~0)) {
178		return (FALSE);
179	}
180	if (!xdr_pointer(xdrs, (char **)(void *)&objp->next,
181			sizeof (rpcbs_rmtcalllist),
182			(xdrproc_t)xdr_rpcbs_rmtcalllist)) {
183		return (FALSE);
184	}
185	return (TRUE);
186	}
187	if (!xdr_u_int32_t(xdrs, &objp->prog)) {
188		return (FALSE);
189	}
190	if (!xdr_u_int32_t(xdrs, &objp->vers)) {
191		return (FALSE);
192	}
193	if (!xdr_u_int32_t(xdrs, &objp->proc)) {
194		return (FALSE);
195	}
196	if (!xdr_int(xdrs, &objp->success)) {
197		return (FALSE);
198	}
199	if (!xdr_int(xdrs, &objp->failure)) {
200		return (FALSE);
201	}
202	if (!xdr_int(xdrs, &objp->indirect)) {
203		return (FALSE);
204	}
205	if (!xdr_string(xdrs, &objp->netid, (u_int)~0)) {
206		return (FALSE);
207	}
208	if (!xdr_pointer(xdrs, (char **)(void *)&objp->next,
209			sizeof (rpcbs_rmtcalllist),
210			(xdrproc_t)xdr_rpcbs_rmtcalllist)) {
211		return (FALSE);
212	}
213	return (TRUE);
214}
215
216bool_t
217xdr_rpcbs_proc(xdrs, objp)
218	XDR *xdrs;
219	rpcbs_proc objp;
220{
221	if (!xdr_vector(xdrs, (char *)(void *)objp, RPCBSTAT_HIGHPROC,
222	    sizeof (int), (xdrproc_t)xdr_int)) {
223		return (FALSE);
224	}
225	return (TRUE);
226}
227
228bool_t
229xdr_rpcbs_addrlist_ptr(xdrs, objp)
230	XDR *xdrs;
231	rpcbs_addrlist_ptr *objp;
232{
233	if (!xdr_pointer(xdrs, (char **)objp, sizeof (rpcbs_addrlist),
234			(xdrproc_t)xdr_rpcbs_addrlist)) {
235		return (FALSE);
236	}
237	return (TRUE);
238}
239
240bool_t
241xdr_rpcbs_rmtcalllist_ptr(xdrs, objp)
242	XDR *xdrs;
243	rpcbs_rmtcalllist_ptr *objp;
244{
245	if (!xdr_pointer(xdrs, (char **)objp, sizeof (rpcbs_rmtcalllist),
246			(xdrproc_t)xdr_rpcbs_rmtcalllist)) {
247		return (FALSE);
248	}
249	return (TRUE);
250}
251
252bool_t
253xdr_rpcb_stat(xdrs, objp)
254	XDR *xdrs;
255	rpcb_stat *objp;
256{
257
258	_DIAGASSERT(objp != NULL);
259
260	if (!xdr_rpcbs_proc(xdrs, objp->info)) {
261		return (FALSE);
262	}
263	if (!xdr_int(xdrs, &objp->setinfo)) {
264		return (FALSE);
265	}
266	if (!xdr_int(xdrs, &objp->unsetinfo)) {
267		return (FALSE);
268	}
269	if (!xdr_rpcbs_addrlist_ptr(xdrs, &objp->addrinfo)) {
270		return (FALSE);
271	}
272	return (TRUE);
273}
274
275/*
276 * One rpcb_stat structure is returned for each version of rpcbind
277 * being monitored.
278 */
279bool_t
280xdr_rpcb_stat_byvers(xdrs, objp)
281	XDR *xdrs;
282	rpcb_stat_byvers objp;
283{
284	if (!xdr_vector(xdrs, (char *)(void *)objp, RPCBVERS_STAT,
285	    sizeof (rpcb_stat), (xdrproc_t)xdr_rpcb_stat)) {
286		return (FALSE);
287	}
288	return (TRUE);
289}
290