xref: /freebsd/include/rpc/rpc_msg.h (revision d4eeb02986980bf33dd56c41ceb9fc5f180c0d47)
1 /*	$NetBSD: rpc_msg.h,v 1.11 2000/06/02 22:57:56 fvdl Exp $	*/
2 
3 /*-
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  * Copyright (c) 2009, Sun Microsystems, Inc.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  * - Redistributions of source code must retain the above copyright notice,
12  *   this list of conditions and the following disclaimer.
13  * - Redistributions in binary form must reproduce the above copyright notice,
14  *   this list of conditions and the following disclaimer in the documentation
15  *   and/or other materials provided with the distribution.
16  * - Neither the name of Sun Microsystems, 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 "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  *	from: @(#)rpc_msg.h 1.7 86/07/16 SMI
33  *	from: @(#)rpc_msg.h	2.1 88/07/29 4.0 RPCSRC
34  * $FreeBSD$
35  */
36 
37 /*
38  * rpc_msg.h
39  * rpc message definition
40  *
41  * Copyright (C) 1984, Sun Microsystems, Inc.
42  */
43 
44 #ifndef _RPC_RPC_MSG_H
45 #define _RPC_RPC_MSG_H
46 
47 #define RPC_MSG_VERSION		((u_int32_t) 2)
48 #define RPC_SERVICE_PORT	((u_short) 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 	u_int32_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 __BEGIN_DECLS
165 /*
166  * XDR routine to handle a rpc message.
167  * xdr_callmsg(xdrs, cmsg)
168  * 	XDR *xdrs;
169  * 	struct rpc_msg *cmsg;
170  */
171 extern bool_t	xdr_callmsg(XDR *, struct rpc_msg *);
172 
173 /*
174  * XDR routine to pre-serialize the static part of a rpc message.
175  * xdr_callhdr(xdrs, cmsg)
176  * 	XDR *xdrs;
177  * 	struct rpc_msg *cmsg;
178  */
179 extern bool_t	xdr_callhdr(XDR *, struct rpc_msg *);
180 
181 /*
182  * XDR routine to handle a rpc reply.
183  * xdr_replymsg(xdrs, rmsg)
184  * 	XDR *xdrs;
185  * 	struct rpc_msg *rmsg;
186  */
187 extern bool_t	xdr_replymsg(XDR *, struct rpc_msg *);
188 
189 
190 /*
191  * XDR routine to handle an accepted rpc reply.
192  * xdr_accepted_reply(xdrs, rej)
193  * 	XDR *xdrs;
194  * 	struct accepted_reply *rej;
195  */
196 extern bool_t	xdr_accepted_reply(XDR *, struct accepted_reply *);
197 
198 /*
199  * XDR routine to handle a rejected rpc reply.
200  * xdr_rejected_reply(xdrs, rej)
201  * 	XDR *xdrs;
202  * 	struct rejected_reply *rej;
203  */
204 extern bool_t	xdr_rejected_reply(XDR *, struct rejected_reply *);
205 
206 /*
207  * Fills in the error part of a reply message.
208  * _seterr_reply(msg, error)
209  * 	struct rpc_msg *msg;
210  * 	struct rpc_err *error;
211  */
212 extern void	_seterr_reply(struct rpc_msg *, struct rpc_err *);
213 __END_DECLS
214 
215 #endif /* !_RPC_RPC_MSG_H */
216