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