Initial import from FreeBSD RELENG_4:
[dragonfly.git] / include / rpc / rpc_msg.h
1 /*
2  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3  * unrestricted use provided that this legend is included on all tape
4  * media and as a part of the software program in whole or part.  Users
5  * may copy or modify Sun RPC without charge, but are not authorized
6  * to license or distribute it to anyone else except as part of a product or
7  * program developed by the user.
8  *
9  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10  * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
11  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
12  *
13  * Sun RPC is provided with no support and without any obligation on the
14  * part of Sun Microsystems, Inc. to assist in its use, correction,
15  * modification or enhancement.
16  *
17  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19  * OR ANY PART THEREOF.
20  *
21  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22  * or profits or other special, indirect and consequential damages, even if
23  * Sun has been advised of the possibility of such damages.
24  *
25  * Sun Microsystems, Inc.
26  * 2550 Garcia Avenue
27  * Mountain View, California  94043
28  *
29  *      from: @(#)rpc_msg.h 1.7 86/07/16 SMI
30  *      from: @(#)rpc_msg.h     2.1 88/07/29 4.0 RPCSRC
31  * $FreeBSD: src/include/rpc/rpc_msg.h,v 1.12 1999/08/27 23:45:05 peter Exp $
32  */
33
34 /*
35  * rpc_msg.h
36  * rpc message definition
37  *
38  * Copyright (C) 1984, Sun Microsystems, Inc.
39  */
40
41 #ifndef _RPC_RPCMSG_H
42 #define _RPC_RPCMSG_H
43
44 #define RPC_MSG_VERSION         ((u_long) 2)
45 #define RPC_SERVICE_PORT        ((u_short) 2048)
46
47 /*
48  * Bottom up definition of an rpc message.
49  * NOTE: call and reply use the same overall stuct but
50  * different parts of unions within it.
51  */
52
53 enum msg_type {
54         CALL=0,
55         REPLY=1
56 };
57
58 enum reply_stat {
59         MSG_ACCEPTED=0,
60         MSG_DENIED=1
61 };
62
63 enum accept_stat {
64         SUCCESS=0,
65         PROG_UNAVAIL=1,
66         PROG_MISMATCH=2,
67         PROC_UNAVAIL=3,
68         GARBAGE_ARGS=4,
69         SYSTEM_ERR=5
70 };
71
72 enum reject_stat {
73         RPC_MISMATCH=0,
74         AUTH_ERROR=1
75 };
76
77 /*
78  * Reply part of an rpc exchange
79  */
80
81 /*
82  * Reply to an rpc request that was accepted by the server.
83  * Note: there could be an error even though the request was
84  * accepted.
85  */
86 struct accepted_reply {
87         struct opaque_auth      ar_verf;
88         enum accept_stat        ar_stat;
89         union {
90                 struct {
91                         u_int32_t       low;
92                         u_int32_t       high;
93                 } AR_versions;
94                 struct {
95                         caddr_t where;
96                         xdrproc_t proc;
97                 } AR_results;
98                 /* and many other null cases */
99         } ru;
100 #define ar_results      ru.AR_results
101 #define ar_vers         ru.AR_versions
102 };
103
104 /*
105  * Reply to an rpc request that was rejected by the server.
106  */
107 struct rejected_reply {
108         enum reject_stat rj_stat;
109         union {
110                 struct {
111                         u_int32_t low;
112                         u_int32_t high;
113                 } RJ_versions;
114                 enum auth_stat RJ_why;  /* why authentication did not work */
115         } ru;
116 #define rj_vers ru.RJ_versions
117 #define rj_why  ru.RJ_why
118 };
119
120 /*
121  * Body of a reply to an rpc request.
122  */
123 struct reply_body {
124         enum reply_stat rp_stat;
125         union {
126                 struct accepted_reply RP_ar;
127                 struct rejected_reply RP_dr;
128         } ru;
129 #define rp_acpt ru.RP_ar
130 #define rp_rjct ru.RP_dr
131 };
132
133 /*
134  * Body of an rpc request call.
135  */
136 struct call_body {
137         u_int32_t cb_rpcvers;   /* must be equal to two */
138         u_int32_t cb_prog;
139         u_int32_t cb_vers;
140         u_int32_t cb_proc;
141         struct opaque_auth cb_cred;
142         struct opaque_auth cb_verf; /* protocol specific - provided by client */
143 };
144
145 /*
146  * The rpc message
147  */
148 struct rpc_msg {
149         u_int32_t               rm_xid;
150         enum msg_type           rm_direction;
151         union {
152                 struct call_body RM_cmb;
153                 struct reply_body RM_rmb;
154         } ru;
155 #define rm_call         ru.RM_cmb
156 #define rm_reply        ru.RM_rmb
157 };
158 #define acpted_rply     ru.RM_rmb.ru.RP_ar
159 #define rjcted_rply     ru.RM_rmb.ru.RP_dr
160
161 __BEGIN_DECLS
162 /*
163  * XDR routine to handle a rpc message.
164  * xdr_callmsg(xdrs, cmsg)
165  *      XDR *xdrs;
166  *      struct rpc_msg *cmsg;
167  */
168 extern bool_t   xdr_callmsg     __P((XDR *, struct rpc_msg *));
169
170 /*
171  * XDR routine to pre-serialize the static part of a rpc message.
172  * xdr_callhdr(xdrs, cmsg)
173  *      XDR *xdrs;
174  *      struct rpc_msg *cmsg;
175  */
176 extern bool_t   xdr_callhdr     __P((XDR *, struct rpc_msg *));
177
178 /*
179  * XDR routine to handle a rpc reply.
180  * xdr_replymsg(xdrs, rmsg)
181  *      XDR *xdrs;
182  *      struct rpc_msg *rmsg;
183  */
184 extern bool_t   xdr_replymsg    __P((XDR *, struct rpc_msg *));
185
186 /*
187  * Fills in the error part of a reply message.
188  * _seterr_reply(msg, error)
189  *      struct rpc_msg *msg;
190  *      struct rpc_err *error;
191  */
192 struct rpc_err;
193 extern void     _seterr_reply   __P((struct rpc_msg *, struct rpc_err *));
194 __END_DECLS
195
196 #endif /* !_RPC_RPCMSG_H */