rpc_msg.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * rpc_msg.h
  3. * rpc message definition
  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. #ifndef _RPC_MSG_H
  35. #define _RPC_MSG_H 1
  36. #include <sys/cdefs.h>
  37. #include <rpc/xdr.h>
  38. #include <rpc/clnt.h>
  39. #define RPC_MSG_VERSION ((u_long) 2)
  40. #define RPC_SERVICE_PORT ((u_short) 2048)
  41. __BEGIN_DECLS
  42. /*
  43. * Bottom up definition of an rpc message.
  44. * NOTE: call and reply use the same overall struct but
  45. * different parts of unions within it.
  46. */
  47. enum msg_type {
  48. CALL=0,
  49. REPLY=1
  50. };
  51. enum reply_stat {
  52. MSG_ACCEPTED=0,
  53. MSG_DENIED=1
  54. };
  55. enum accept_stat {
  56. SUCCESS=0,
  57. PROG_UNAVAIL=1,
  58. PROG_MISMATCH=2,
  59. PROC_UNAVAIL=3,
  60. GARBAGE_ARGS=4,
  61. SYSTEM_ERR=5
  62. };
  63. enum reject_stat {
  64. RPC_MISMATCH=0,
  65. AUTH_ERROR=1
  66. };
  67. /*
  68. * Reply part of an rpc exchange
  69. */
  70. /*
  71. * Reply to an rpc request that was accepted by the server.
  72. * Note: there could be an error even though the request was
  73. * accepted.
  74. */
  75. struct accepted_reply {
  76. struct opaque_auth ar_verf;
  77. enum accept_stat ar_stat;
  78. union {
  79. struct {
  80. u_long low;
  81. u_long high;
  82. } AR_versions;
  83. struct {
  84. caddr_t where;
  85. xdrproc_t proc;
  86. } AR_results;
  87. /* and many other null cases */
  88. } ru;
  89. #define ar_results ru.AR_results
  90. #define ar_vers ru.AR_versions
  91. };
  92. /*
  93. * Reply to an rpc request that was rejected by the server.
  94. */
  95. struct rejected_reply {
  96. enum reject_stat rj_stat;
  97. union {
  98. struct {
  99. u_long low;
  100. u_long high;
  101. } RJ_versions;
  102. enum auth_stat RJ_why; /* why authentication did not work */
  103. } ru;
  104. #define rj_vers ru.RJ_versions
  105. #define rj_why ru.RJ_why
  106. };
  107. /*
  108. * Body of a reply to an rpc request.
  109. */
  110. struct reply_body {
  111. enum reply_stat rp_stat;
  112. union {
  113. struct accepted_reply RP_ar;
  114. struct rejected_reply RP_dr;
  115. } ru;
  116. #define rp_acpt ru.RP_ar
  117. #define rp_rjct ru.RP_dr
  118. };
  119. /*
  120. * Body of an rpc request call.
  121. */
  122. struct call_body {
  123. u_long cb_rpcvers; /* must be equal to two */
  124. u_long cb_prog;
  125. u_long cb_vers;
  126. u_long cb_proc;
  127. struct opaque_auth cb_cred;
  128. struct opaque_auth cb_verf; /* protocol specific - provided by client */
  129. };
  130. /*
  131. * The rpc message
  132. */
  133. struct rpc_msg {
  134. u_long rm_xid;
  135. enum msg_type rm_direction;
  136. union {
  137. struct call_body RM_cmb;
  138. struct reply_body RM_rmb;
  139. } ru;
  140. #define rm_call ru.RM_cmb
  141. #define rm_reply ru.RM_rmb
  142. };
  143. #define acpted_rply ru.RM_rmb.ru.RP_ar
  144. #define rjcted_rply ru.RM_rmb.ru.RP_dr
  145. /*
  146. * XDR routine to handle a rpc message.
  147. * xdr_callmsg(xdrs, cmsg)
  148. * XDR *xdrs;
  149. * struct rpc_msg *cmsg;
  150. */
  151. extern bool_t xdr_callmsg (XDR *__xdrs, struct rpc_msg *__cmsg) __THROW;
  152. /*
  153. * XDR routine to pre-serialize the static part of a rpc message.
  154. * xdr_callhdr(xdrs, cmsg)
  155. * XDR *xdrs;
  156. * struct rpc_msg *cmsg;
  157. */
  158. extern bool_t xdr_callhdr (XDR *__xdrs, struct rpc_msg *__cmsg) __THROW;
  159. /*
  160. * XDR routine to handle a rpc reply.
  161. * xdr_replymsg(xdrs, rmsg)
  162. * XDR *xdrs;
  163. * struct rpc_msg *rmsg;
  164. */
  165. extern bool_t xdr_replymsg (XDR *__xdrs, struct rpc_msg *__rmsg) __THROW;
  166. /*
  167. * Fills in the error part of a reply message.
  168. * _seterr_reply(msg, error)
  169. * struct rpc_msg *msg;
  170. * struct rpc_err *error;
  171. */
  172. extern void _seterr_reply (struct rpc_msg *__msg, struct rpc_err *__error)
  173. __THROW;
  174. __END_DECLS
  175. #endif /* rpc/rpc_msg.h */