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