xref: /netbsd-src/lib/libc/rpc/rpcb_st_xdr.c (revision 626fa0a1b6a63f5e9c3323515ad2f84ab84fa749)
1 /*	$NetBSD: rpcb_st_xdr.c,v 1.12 2017/08/13 01:08:41 ginsbach 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.12 2017/08/13 01:08:41 ginsbach Exp $");
46 #endif
47 
48 #include "namespace.h"
49 #include <rpc/rpc.h>
50 #include <rpc/rpc_com.h>
51 
52 #include <assert.h>
53 
54 /* Link list of all the stats about getport and getaddr */
55 
56 #ifdef __weak_alias
__weak_alias(xdr_rpcbs_addrlist,_xdr_rpcbs_addrlist)57 __weak_alias(xdr_rpcbs_addrlist,_xdr_rpcbs_addrlist)
58 __weak_alias(xdr_rpcbs_rmtcalllist,_xdr_rpcbs_rmtcalllist)
59 __weak_alias(xdr_rpcbs_proc,_xdr_rpcbs_proc)
60 __weak_alias(xdr_rpcbs_addrlist_ptr,_xdr_rpcbs_addrlist_ptr)
61 __weak_alias(xdr_rpcbs_rmtcalllist_ptr,_xdr_rpcbs_rmtcalllist_ptr)
62 __weak_alias(xdr_rpcb_stat,_xdr_rpcb_stat)
63 __weak_alias(xdr_rpcb_stat_byvers,_xdr_rpcb_stat_byvers)
64 #endif
65 
66 bool_t
67 xdr_rpcbs_addrlist(XDR *xdrs, rpcbs_addrlist *objp)
68 {
69 
70 	_DIAGASSERT(objp != NULL);
71 
72 	    if (!xdr_u_int32_t(xdrs, &objp->prog)) {
73 		return (FALSE);
74 	    }
75 	    if (!xdr_u_int32_t(xdrs, &objp->vers)) {
76 		return (FALSE);
77 	    }
78 	    if (!xdr_int(xdrs, &objp->success)) {
79 		return (FALSE);
80 	    }
81 	    if (!xdr_int(xdrs, &objp->failure)) {
82 		return (FALSE);
83 	    }
84 	    if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) {
85 		return (FALSE);
86 	    }
87 
88 	    if (!xdr_pointer(xdrs, (char **)(void *)&objp->next,
89 			(u_int)sizeof (rpcbs_addrlist),
90 			(xdrproc_t)xdr_rpcbs_addrlist)) {
91 		return (FALSE);
92 	    }
93 
94 	return (TRUE);
95 }
96 
97 /* Link list of all the stats about rmtcall */
98 
99 bool_t
xdr_rpcbs_rmtcalllist(XDR * xdrs,rpcbs_rmtcalllist * objp)100 xdr_rpcbs_rmtcalllist(XDR *xdrs, rpcbs_rmtcalllist *objp)
101 {
102 	int32_t *buf;
103 
104 	_DIAGASSERT(xdrs != NULL);
105 	_DIAGASSERT(objp != NULL);
106 
107 	if (xdrs->x_op == XDR_ENCODE) {
108 	buf = XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT);
109 	if (buf == NULL) {
110 		if (!xdr_u_int32_t(xdrs, &objp->prog)) {
111 			return (FALSE);
112 		}
113 		if (!xdr_u_int32_t(xdrs, &objp->vers)) {
114 			return (FALSE);
115 		}
116 		if (!xdr_u_int32_t(xdrs, &objp->proc)) {
117 			return (FALSE);
118 		}
119 		if (!xdr_int(xdrs, &objp->success)) {
120 			return (FALSE);
121 		}
122 		if (!xdr_int(xdrs, &objp->failure)) {
123 			return (FALSE);
124 		}
125 		if (!xdr_int(xdrs, &objp->indirect)) {
126 			return (FALSE);
127 		}
128 	} else {
129 		IXDR_PUT_U_INT32(buf, objp->prog);
130 		IXDR_PUT_U_INT32(buf, objp->vers);
131 		IXDR_PUT_U_INT32(buf, objp->proc);
132 		IXDR_PUT_INT32(buf, objp->success);
133 		IXDR_PUT_INT32(buf, objp->failure);
134 		IXDR_PUT_INT32(buf, objp->indirect);
135 	}
136 	if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) {
137 		return (FALSE);
138 	}
139 	if (!xdr_pointer(xdrs, (char **)(void *)&objp->next,
140 			(u_int)sizeof (rpcbs_rmtcalllist),
141 			(xdrproc_t)xdr_rpcbs_rmtcalllist)) {
142 		return (FALSE);
143 	}
144 	return (TRUE);
145 	} else if (xdrs->x_op == XDR_DECODE) {
146 	buf = XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT);
147 	if (buf == NULL) {
148 		if (!xdr_u_int32_t(xdrs, &objp->prog)) {
149 			return (FALSE);
150 		}
151 		if (!xdr_u_int32_t(xdrs, &objp->vers)) {
152 			return (FALSE);
153 		}
154 		if (!xdr_u_int32_t(xdrs, &objp->proc)) {
155 			return (FALSE);
156 		}
157 		if (!xdr_int(xdrs, &objp->success)) {
158 			return (FALSE);
159 		}
160 		if (!xdr_int(xdrs, &objp->failure)) {
161 			return (FALSE);
162 		}
163 		if (!xdr_int(xdrs, &objp->indirect)) {
164 			return (FALSE);
165 		}
166 	} else {
167 		objp->prog = (rpcprog_t)IXDR_GET_U_INT32(buf);
168 		objp->vers = (rpcvers_t)IXDR_GET_U_INT32(buf);
169 		objp->proc = (rpcproc_t)IXDR_GET_U_INT32(buf);
170 		objp->success = (int)IXDR_GET_INT32(buf);
171 		objp->failure = (int)IXDR_GET_INT32(buf);
172 		objp->indirect = (int)IXDR_GET_INT32(buf);
173 	}
174 	if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) {
175 		return (FALSE);
176 	}
177 	if (!xdr_pointer(xdrs, (char **)(void *)&objp->next,
178 			(u_int)sizeof (rpcbs_rmtcalllist),
179 			(xdrproc_t)xdr_rpcbs_rmtcalllist)) {
180 		return (FALSE);
181 	}
182 	return (TRUE);
183 	}
184 	if (!xdr_u_int32_t(xdrs, &objp->prog)) {
185 		return (FALSE);
186 	}
187 	if (!xdr_u_int32_t(xdrs, &objp->vers)) {
188 		return (FALSE);
189 	}
190 	if (!xdr_u_int32_t(xdrs, &objp->proc)) {
191 		return (FALSE);
192 	}
193 	if (!xdr_int(xdrs, &objp->success)) {
194 		return (FALSE);
195 	}
196 	if (!xdr_int(xdrs, &objp->failure)) {
197 		return (FALSE);
198 	}
199 	if (!xdr_int(xdrs, &objp->indirect)) {
200 		return (FALSE);
201 	}
202 	if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) {
203 		return (FALSE);
204 	}
205 	if (!xdr_pointer(xdrs, (char **)(void *)&objp->next,
206 			(u_int)sizeof (rpcbs_rmtcalllist),
207 			(xdrproc_t)xdr_rpcbs_rmtcalllist)) {
208 		return (FALSE);
209 	}
210 	return (TRUE);
211 }
212 
213 bool_t
xdr_rpcbs_proc(XDR * xdrs,rpcbs_proc objp)214 xdr_rpcbs_proc(XDR *xdrs, rpcbs_proc objp)
215 {
216 	if (!xdr_vector(xdrs, (char *)(void *)objp, RPCBSTAT_HIGHPROC,
217 	    (u_int)sizeof (int), (xdrproc_t)xdr_int)) {
218 		return (FALSE);
219 	}
220 	return (TRUE);
221 }
222 
223 bool_t
xdr_rpcbs_addrlist_ptr(XDR * xdrs,rpcbs_addrlist_ptr * objp)224 xdr_rpcbs_addrlist_ptr(XDR *xdrs, rpcbs_addrlist_ptr *objp)
225 {
226 	if (!xdr_pointer(xdrs, (char **)objp, (u_int)sizeof (rpcbs_addrlist),
227 			(xdrproc_t)xdr_rpcbs_addrlist)) {
228 		return (FALSE);
229 	}
230 	return (TRUE);
231 }
232 
233 bool_t
xdr_rpcbs_rmtcalllist_ptr(XDR * xdrs,rpcbs_rmtcalllist_ptr * objp)234 xdr_rpcbs_rmtcalllist_ptr(XDR *xdrs, rpcbs_rmtcalllist_ptr *objp)
235 {
236 	if (!xdr_pointer(xdrs, (char **)objp, (u_int)sizeof (rpcbs_rmtcalllist),
237 			(xdrproc_t)xdr_rpcbs_rmtcalllist)) {
238 		return (FALSE);
239 	}
240 	return (TRUE);
241 }
242 
243 bool_t
xdr_rpcb_stat(XDR * xdrs,rpcb_stat * objp)244 xdr_rpcb_stat(XDR *xdrs, rpcb_stat *objp)
245 {
246 
247 	_DIAGASSERT(objp != NULL);
248 
249 	if (!xdr_rpcbs_proc(xdrs, objp->info)) {
250 		return (FALSE);
251 	}
252 	if (!xdr_int(xdrs, &objp->setinfo)) {
253 		return (FALSE);
254 	}
255 	if (!xdr_int(xdrs, &objp->unsetinfo)) {
256 		return (FALSE);
257 	}
258 	if (!xdr_rpcbs_addrlist_ptr(xdrs, &objp->addrinfo)) {
259 		return (FALSE);
260 	}
261 	if (!xdr_rpcbs_rmtcalllist_ptr(xdrs, &objp->rmtinfo)) {
262 		return (FALSE);
263 	}
264 	return (TRUE);
265 }
266 
267 /*
268  * One rpcb_stat structure is returned for each version of rpcbind
269  * being monitored.
270  */
271 bool_t
xdr_rpcb_stat_byvers(XDR * xdrs,rpcb_stat_byvers objp)272 xdr_rpcb_stat_byvers(XDR *xdrs, rpcb_stat_byvers objp)
273 {
274 	if (!xdr_vector(xdrs, (char *)(void *)objp, RPCBVERS_STAT,
275 	    (u_int)sizeof (rpcb_stat), (xdrproc_t)xdr_rpcb_stat)) {
276 		return (FALSE);
277 	}
278 	return (TRUE);
279 }
280