xref: /illumos-gate/usr/src/uts/common/rpc/rpc_msg.h (revision cbea7aca3fd7787405cbdbd93752998f03dfc25f)
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  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
28 /*
29  * Portions of this source code were derived from Berkeley
30  * 4.3 BSD under license from the Regents of the University of
31  * California.
32  */
33 
34 #ifndef _RPC_RPC_MSG_H
35 #define	_RPC_RPC_MSG_H
36 
37 #include <rpc/clnt.h>
38 /*
39  * rpc_msg.h
40  * rpc message definition
41  */
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 #define	RPC_MSG_VERSION		((uint32_t)2)
48 #define	RPC_SERVICE_PORT	((ushort_t)2048)
49 
50 /*
51  * Bottom up definition of an rpc message.
52  * NOTE: call and reply use the same overall stuct but
53  * different parts of unions within it.
54  */
55 
56 enum msg_type {
57 	CALL = 0,
58 	REPLY = 1
59 };
60 
61 enum reply_stat {
62 	MSG_ACCEPTED = 0,
63 	MSG_DENIED = 1
64 };
65 
66 enum accept_stat {
67 	SUCCESS = 0,
68 	PROG_UNAVAIL = 1,
69 	PROG_MISMATCH = 2,
70 	PROC_UNAVAIL = 3,
71 	GARBAGE_ARGS = 4,
72 	SYSTEM_ERR = 5
73 };
74 
75 enum reject_stat {
76 	RPC_MISMATCH = 0,
77 	AUTH_ERROR = 1
78 };
79 
80 /*
81  * Reply part of an rpc exchange
82  */
83 
84 /*
85  * Reply to an rpc request that was accepted by the server.
86  * Note: there could be an error even though the request was
87  * accepted.
88  */
89 struct accepted_reply {
90 	struct opaque_auth	ar_verf;
91 	enum accept_stat	ar_stat;
92 	union {
93 		struct {
94 			rpcvers_t low;
95 			rpcvers_t high;
96 		} AR_versions;
97 		struct {
98 			caddr_t	where;
99 			xdrproc_t proc;
100 		} AR_results;
101 		/* and many other null cases */
102 	} ru;
103 #define	ar_results	ru.AR_results
104 #define	ar_vers		ru.AR_versions
105 };
106 
107 /*
108  * Reply to an rpc request that was rejected by the server.
109  */
110 struct rejected_reply {
111 	enum reject_stat rj_stat;
112 	union {
113 		struct {
114 			rpcvers_t low;
115 			rpcvers_t high;
116 		} RJ_versions;
117 		enum auth_stat RJ_why;  /* why authentication did not work */
118 	} ru;
119 #define	rj_vers	ru.RJ_versions
120 #define	rj_why	ru.RJ_why
121 };
122 
123 /*
124  * Body of a reply to an rpc request.
125  */
126 struct reply_body {
127 	enum reply_stat rp_stat;
128 	union {
129 		struct accepted_reply RP_ar;
130 		struct rejected_reply RP_dr;
131 	} ru;
132 #define	rp_acpt	ru.RP_ar
133 #define	rp_rjct	ru.RP_dr
134 };
135 
136 /*
137  * Body of an rpc request call.
138  */
139 struct call_body {
140 	rpcvers_t cb_rpcvers;	/* must be equal to two */
141 	rpcprog_t cb_prog;
142 	rpcvers_t cb_vers;
143 	rpcproc_t cb_proc;
144 	struct opaque_auth cb_cred;
145 	struct opaque_auth cb_verf; /* protocol specific - provided by client */
146 };
147 
148 /*
149  * The rpc message
150  */
151 struct rpc_msg {
152 	uint32_t		rm_xid;
153 	enum msg_type		rm_direction;
154 	union {
155 		struct call_body RM_cmb;
156 		struct reply_body RM_rmb;
157 	} ru;
158 #define	rm_call		ru.RM_cmb
159 #define	rm_reply	ru.RM_rmb
160 };
161 #define	acpted_rply	ru.RM_rmb.ru.RP_ar
162 #define	rjcted_rply	ru.RM_rmb.ru.RP_dr
163 
164 
165 /*
166  * XDR routine to handle a rpc message.
167  * xdr_callmsg(xdrs, cmsg)
168  * 	XDR *xdrs;
169  * 	struct rpc_msg *cmsg;
170  */
171 #ifdef __STDC__
172 extern bool_t	xdr_callmsg(XDR *, struct rpc_msg *);
173 #else
174 extern bool_t	xdr_callmsg();
175 #endif
176 
177 
178 /*
179  * XDR routine to pre-serialize the static part of a rpc message.
180  * xdr_callhdr(xdrs, cmsg)
181  * 	XDR *xdrs;
182  * 	struct rpc_msg *cmsg;
183  */
184 #ifdef __STDC__
185 extern bool_t	xdr_callhdr(XDR *, struct rpc_msg *);
186 #else
187 extern bool_t	xdr_callhdr();
188 #endif
189 
190 
191 /*
192  * XDR routine to handle a rpc reply.
193  * xdr_replymsg(xdrs, rmsg)
194  * 	XDR *xdrs;
195  * 	struct rpc_msg *rmsg;
196  *
197  * xdr_accepted_reply(xdrs, ar)
198  *	XDR *xdrs;
199  *	const struct accepted_reply *ar;
200  *
201  * xdr_rejected_reply(xdrs, rr)
202  *	XDR *xdrs;
203  *	const struct rejected_reply *rr;
204  */
205 #ifdef __STDC__
206 extern bool_t	xdr_replymsg(XDR *, struct rpc_msg *);
207 extern bool_t	xdr_accepted_reply(XDR *, struct accepted_reply *);
208 extern bool_t	xdr_rejected_reply(XDR *, struct rejected_reply *);
209 #else
210 extern bool_t	xdr_replymsg();
211 extern bool_t	xdr_accepted_reply();
212 extern bool_t	xdr_rejected_reply();
213 #endif
214 
215 
216 #ifdef _KERNEL
217 /*
218  * Fills in the error part of a reply message.
219  * _seterr_reply(msg, error)
220  * 	struct rpc_msg *msg;
221  * 	struct rpc_err *error;
222  */
223 #ifdef __STDC__
224 extern void	_seterr_reply(struct rpc_msg *, struct rpc_err *);
225 #else
226 extern void	_seterr_reply();
227 #endif
228 #else
229 /*
230  * Fills in the error part of a reply message.
231  * __seterr_reply(msg, error)
232  * 	struct rpc_msg *msg;
233  * 	struct rpc_err *error;
234  */
235 #ifdef __STDC__
236 extern void	__seterr_reply(struct rpc_msg *, struct rpc_err *);
237 #else
238 extern void	__seterr_reply();
239 #endif
240 #endif
241 
242 #ifdef _KERNEL
243 /*
244  * Frees any verifier that xdr_replymsg() (DECODE) allocated.
245  */
246 bool_t xdr_rpc_free_verifier(register XDR *xdrs, register struct rpc_msg *msg);
247 
248 #endif
249 
250 #ifdef __cplusplus
251 }
252 #endif
253 
254 #endif	/* _RPC_RPC_MSG_H */
255