1 /* $OpenBSD: rpc_msg.h,v 1.7 2014/10/29 04:34:21 guenther Exp $ */ 2 /* $NetBSD: rpc_msg.h,v 1.5 1995/04/29 05:28:00 cgd Exp $ */ 3 4 /* 5 * Copyright (c) 2010, Oracle America, Inc. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are 9 * met: 10 * 11 * * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * * Redistributions in binary form must reproduce the above 14 * copyright notice, this list of conditions and the following 15 * disclaimer in the documentation and/or other materials 16 * provided with the distribution. 17 * * Neither the name of the "Oracle America, Inc." nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 26 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 28 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * 34 * from: @(#)rpc_msg.h 1.7 86/07/16 SMI 35 * @(#)rpc_msg.h 2.1 88/07/29 4.0 RPCSRC 36 */ 37 38 /* 39 * rpc_msg.h 40 * rpc message definition 41 */ 42 43 #ifndef _RPC_RPCMSG_H 44 #define _RPC_RPCMSG_H 45 46 #define RPC_MSG_VERSION ((unsigned long) 2) 47 #define RPC_SERVICE_PORT ((unsigned short) 2048) 48 49 /* 50 * Bottom up definition of an rpc message. 51 * NOTE: call and reply use the same overall struct but 52 * different parts of unions within it. 53 */ 54 55 enum msg_type { 56 CALL=0, 57 REPLY=1 58 }; 59 60 enum reply_stat { 61 MSG_ACCEPTED=0, 62 MSG_DENIED=1 63 }; 64 65 enum accept_stat { 66 SUCCESS=0, 67 PROG_UNAVAIL=1, 68 PROG_MISMATCH=2, 69 PROC_UNAVAIL=3, 70 GARBAGE_ARGS=4, 71 SYSTEM_ERR=5 72 }; 73 74 enum reject_stat { 75 RPC_MISMATCH=0, 76 AUTH_ERROR=1 77 }; 78 79 /* 80 * Reply part of an rpc exchange 81 */ 82 83 /* 84 * Reply to an rpc request that was accepted by the server. 85 * Note: there could be an error even though the request was 86 * accepted. 87 */ 88 struct accepted_reply { 89 struct opaque_auth ar_verf; 90 enum accept_stat ar_stat; 91 union { 92 struct { 93 u_int32_t low; 94 u_int32_t high; 95 } AR_versions; 96 struct { 97 caddr_t where; 98 xdrproc_t proc; 99 } AR_results; 100 /* and many other null cases */ 101 } ru; 102 #define ar_results ru.AR_results 103 #define ar_vers ru.AR_versions 104 }; 105 106 /* 107 * Reply to an rpc request that was rejected by the server. 108 */ 109 struct rejected_reply { 110 enum reject_stat rj_stat; 111 union { 112 struct { 113 u_int32_t low; 114 u_int32_t high; 115 } RJ_versions; 116 enum auth_stat RJ_why; /* why authentication did not work */ 117 } ru; 118 #define rj_vers ru.RJ_versions 119 #define rj_why ru.RJ_why 120 }; 121 122 /* 123 * Body of a reply to an rpc request. 124 */ 125 struct reply_body { 126 enum reply_stat rp_stat; 127 union { 128 struct accepted_reply RP_ar; 129 struct rejected_reply RP_dr; 130 } ru; 131 #define rp_acpt ru.RP_ar 132 #define rp_rjct ru.RP_dr 133 }; 134 135 /* 136 * Body of an rpc request call. 137 */ 138 struct call_body { 139 u_int32_t cb_rpcvers; /* must be equal to two */ 140 u_int32_t cb_prog; 141 u_int32_t cb_vers; 142 u_int32_t cb_proc; 143 struct opaque_auth cb_cred; 144 struct opaque_auth cb_verf; /* protocol specific - provided by client */ 145 }; 146 147 /* 148 * The rpc message 149 */ 150 struct rpc_msg { 151 u_int32_t rm_xid; 152 enum msg_type rm_direction; 153 union { 154 struct call_body RM_cmb; 155 struct reply_body RM_rmb; 156 } ru; 157 #define rm_call ru.RM_cmb 158 #define rm_reply ru.RM_rmb 159 }; 160 #define acpted_rply ru.RM_rmb.ru.RP_ar 161 #define rjcted_rply ru.RM_rmb.ru.RP_dr 162 163 __BEGIN_DECLS 164 /* 165 * XDR routine to handle a rpc message. 166 * xdr_callmsg(xdrs, cmsg) 167 * XDR *xdrs; 168 * struct rpc_msg *cmsg; 169 */ 170 extern bool_t xdr_callmsg(XDR *, struct rpc_msg *); 171 172 /* 173 * XDR routine to pre-serialize the static part of a rpc message. 174 * xdr_callhdr(xdrs, cmsg) 175 * XDR *xdrs; 176 * struct rpc_msg *cmsg; 177 */ 178 extern bool_t xdr_callhdr(XDR *, struct rpc_msg *); 179 180 /* 181 * XDR routine to handle a rpc reply. 182 * xdr_replymsg(xdrs, rmsg) 183 * XDR *xdrs; 184 * struct rpc_msg *rmsg; 185 */ 186 extern bool_t xdr_replymsg(XDR *, struct rpc_msg *); 187 188 extern bool_t xdr_accepted_reply(XDR *, struct accepted_reply *); 189 extern bool_t xdr_rejected_reply(XDR *, struct rejected_reply *); 190 191 /* 192 * Fills in the error part of a reply message. 193 * _seterr_reply(msg, error) 194 * struct rpc_msg *msg; 195 * struct rpc_err *error; 196 */ 197 extern void _seterr_reply(struct rpc_msg *, struct rpc_err *); 198 __END_DECLS 199 200 #endif /* !_RPC_RPCMSG_H */ 201