xref: /titanic_41/usr/src/lib/libnsl/rpc/rpcb_st_xdr.c (revision 7c2fbfb345896881c631598ee3852ce9ce33fb07)
1 /*
2  * CDDL HEADER START
3  *
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
7  * with the License.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 
30 /*
31  * This file was generated from rpcb_prot.x, but includes only those
32  * routines used with the rpcbind stats facility.
33  */
34 
35 #include "mt.h"
36 #include <rpc/rpc.h>
37 
38 /* Link list of all the stats about getport and getaddr */
39 
40 bool_t
41 xdr_rpcbs_addrlist(XDR *xdrs, rpcbs_addrlist *objp)
42 {
43 	if (!xdr_u_int(xdrs, (uint_t *)&objp->prog))
44 		return (FALSE);
45 	if (!xdr_u_int(xdrs, (uint_t *)&objp->vers))
46 		return (FALSE);
47 	if (!xdr_int(xdrs, &objp->success))
48 		return (FALSE);
49 	if (!xdr_int(xdrs, &objp->failure))
50 		return (FALSE);
51 	return (xdr_string(xdrs, &objp->netid, ~0));
52 }
53 
54 /* Link list of all the stats about rmtcall */
55 
56 bool_t
57 xdr_rpcbs_rmtcalllist(XDR *xdrs, rpcbs_rmtcalllist *objp)
58 {
59 	rpc_inline_t *buf;
60 
61 	switch (xdrs->x_op) {
62 	case XDR_ENCODE:
63 		buf = XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT);
64 		if (buf == NULL) {
65 			if (!xdr_u_int(xdrs, (uint_t *)&objp->prog))
66 				return (FALSE);
67 			if (!xdr_u_int(xdrs, (uint_t *)&objp->vers))
68 				return (FALSE);
69 			if (!xdr_u_int(xdrs, (uint_t *)&objp->proc))
70 				return (FALSE);
71 			if (!xdr_int(xdrs, &objp->success))
72 				return (FALSE);
73 			if (!xdr_int(xdrs, &objp->failure))
74 				return (FALSE);
75 			if (!xdr_int(xdrs, &objp->indirect))
76 				return (FALSE);
77 		} else {
78 			IXDR_PUT_U_INT32(buf, objp->prog);
79 			IXDR_PUT_U_INT32(buf, objp->vers);
80 			IXDR_PUT_U_INT32(buf, objp->proc);
81 			IXDR_PUT_INT32(buf, objp->success);
82 			IXDR_PUT_INT32(buf, objp->failure);
83 			IXDR_PUT_INT32(buf, objp->indirect);
84 		}
85 		if (!xdr_string(xdrs, &objp->netid, ~0))
86 			return (FALSE);
87 		return (xdr_pointer(xdrs, (char **)&objp->next,
88 				(uint_t)sizeof (rpcbs_rmtcalllist),
89 				(xdrproc_t)xdr_rpcbs_rmtcalllist));
90 	case XDR_DECODE:
91 		buf = XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT);
92 		if (buf == NULL) {
93 			if (!xdr_u_int(xdrs, (uint_t *)&objp->prog))
94 				return (FALSE);
95 			if (!xdr_u_int(xdrs, (uint_t *)&objp->vers))
96 				return (FALSE);
97 			if (!xdr_u_int(xdrs, (uint_t *)&objp->proc))
98 				return (FALSE);
99 			if (!xdr_int(xdrs, &objp->success))
100 				return (FALSE);
101 			if (!xdr_int(xdrs, &objp->failure))
102 				return (FALSE);
103 			if (!xdr_int(xdrs, &objp->indirect))
104 				return (FALSE);
105 		} else {
106 			objp->prog = IXDR_GET_U_INT32(buf);
107 			objp->vers = IXDR_GET_U_INT32(buf);
108 			objp->proc = IXDR_GET_U_INT32(buf);
109 			objp->success = IXDR_GET_INT32(buf);
110 			objp->failure = IXDR_GET_INT32(buf);
111 			objp->indirect = IXDR_GET_INT32(buf);
112 		}
113 		if (!xdr_string(xdrs, &objp->netid, ~0))
114 			return (FALSE);
115 		return (xdr_pointer(xdrs, (char **)&objp->next,
116 				(uint_t)sizeof (rpcbs_rmtcalllist),
117 				(xdrproc_t)xdr_rpcbs_rmtcalllist));
118 	case XDR_FREE:
119 		if (!xdr_u_int(xdrs, (uint_t *)&objp->prog))
120 			return (FALSE);
121 		if (!xdr_u_int(xdrs, (uint_t *)&objp->vers))
122 			return (FALSE);
123 		if (!xdr_u_int(xdrs, (uint_t *)&objp->proc))
124 			return (FALSE);
125 		if (!xdr_int(xdrs, &objp->success))
126 			return (FALSE);
127 		if (!xdr_int(xdrs, &objp->failure))
128 			return (FALSE);
129 		if (!xdr_int(xdrs, &objp->indirect))
130 			return (FALSE);
131 		if (!xdr_string(xdrs, &objp->netid, ~0))
132 			return (FALSE);
133 		return (xdr_pointer(xdrs, (char **)&objp->next,
134 				(uint_t)sizeof (rpcbs_rmtcalllist),
135 				(xdrproc_t)xdr_rpcbs_rmtcalllist));
136 	default:
137 		return (FALSE);
138 	}
139 }
140 
141 bool_t
142 xdr_rpcbs_proc(XDR *xdrs, rpcbs_proc objp)
143 {
144 	return (xdr_vector(xdrs, (char *)objp, RPCBSTAT_HIGHPROC, sizeof (int),
145 			(xdrproc_t)xdr_int));
146 }
147 
148 bool_t
149 xdr_rpcbs_addrlist_ptr(XDR *xdrs, rpcbs_addrlist_ptr *objp)
150 {
151 	bool_t			more_data;
152 	rpcbs_addrlist_ptr	*nextp;
153 
154 	for (;;) {
155 		more_data = (*objp != NULL);
156 
157 		if (!xdr_bool(xdrs, &more_data))
158 			return (FALSE);
159 
160 		if (!more_data)
161 			break;
162 
163 		if (xdrs->x_op == XDR_FREE)
164 			nextp = &(*objp)->next;
165 
166 		if (!xdr_reference(xdrs, (char **)objp,
167 			(uint_t)sizeof (rpcbs_addrlist),
168 			(xdrproc_t)xdr_rpcbs_addrlist))
169 			return (FALSE);
170 
171 		objp = (xdrs->x_op == XDR_FREE) ? nextp : &(*objp)->next;
172 
173 	}
174 	*objp = NULL;
175 	return (TRUE);
176 }
177 
178 bool_t
179 xdr_rpcbs_rmtcalllist_ptr(XDR *xdrs, rpcbs_rmtcalllist_ptr *objp)
180 {
181 	return (xdr_pointer(xdrs, (char **)objp, sizeof (rpcbs_rmtcalllist),
182 			(xdrproc_t)xdr_rpcbs_rmtcalllist));
183 }
184 
185 bool_t
186 xdr_rpcb_stat(XDR *xdrs, rpcb_stat *objp)
187 {
188 	if (!xdr_rpcbs_proc(xdrs, objp->info))
189 		return (FALSE);
190 	if (!xdr_int(xdrs, &objp->setinfo))
191 		return (FALSE);
192 	if (!xdr_int(xdrs, &objp->unsetinfo))
193 		return (FALSE);
194 	if (!xdr_rpcbs_addrlist_ptr(xdrs, &objp->addrinfo))
195 		return (FALSE);
196 	return (xdr_rpcbs_rmtcalllist_ptr(xdrs, &objp->rmtinfo));
197 }
198 
199 /*
200  * One rpcb_stat structure is returned for each version of rpcbind
201  * being monitored.
202  */
203 bool_t
204 xdr_rpcb_stat_byvers(XDR *xdrs, rpcb_stat_byvers objp)
205 {
206 	return (xdr_vector(xdrs, (char *)objp, RPCBVERS_STAT,
207 		sizeof (rpcb_stat), (xdrproc_t)xdr_rpcb_stat));
208 }
209