1
0

sunrpc.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. /*
  10. * Sun RPC; see RFC 1057
  11. */
  12. typedef uint8_t u1int;
  13. typedef struct SunAuthInfo SunAuthInfo;
  14. typedef struct SunAuthUnix SunAuthUnix;
  15. typedef struct SunRpc SunRpc;
  16. typedef struct SunCall SunCall;
  17. enum
  18. {
  19. /* Authinfo.flavor */
  20. SunAuthNone = 0,
  21. SunAuthSys,
  22. SunAuthShort,
  23. SunAuthDes,
  24. };
  25. typedef enum {
  26. SunAcceptError = 0x10000,
  27. SunRejectError = 0x20000,
  28. SunAuthError = 0x40000,
  29. /* Reply.status */
  30. SunSuccess = 0,
  31. SunProgUnavail = SunAcceptError | 1,
  32. SunProgMismatch,
  33. SunProcUnavail,
  34. SunGarbageArgs,
  35. SunSystemErr,
  36. SunRpcMismatch = SunRejectError | 0,
  37. SunAuthBadCred = SunAuthError | 1,
  38. SunAuthRejectedCred,
  39. SunAuthBadVerf,
  40. SunAuthRejectedVerf,
  41. SunAuthTooWeak,
  42. SunAuthInvalidResp,
  43. SunAuthFailed,
  44. } SunStatus;
  45. struct SunAuthInfo
  46. {
  47. uint flavor;
  48. uint8_t *data;
  49. uint ndata;
  50. };
  51. struct SunAuthUnix
  52. {
  53. uint32_t stamp;
  54. char *sysname;
  55. uint32_t uid;
  56. uint32_t gid;
  57. uint32_t g[16];
  58. uint32_t ng;
  59. };
  60. struct SunRpc
  61. {
  62. uint32_t xid;
  63. uint iscall;
  64. /*
  65. * only sent on wire in call
  66. * caller fills in for the reply unpackers.
  67. */
  68. uint32_t proc;
  69. /* call */
  70. // uint proc;
  71. uint32_t prog, vers;
  72. SunAuthInfo cred;
  73. SunAuthInfo verf;
  74. uint8_t *data;
  75. uint ndata;
  76. /* reply */
  77. uint32_t status;
  78. // SunAuthInfo verf;
  79. uint32_t low, high;
  80. // uchar *data;
  81. // uint ndata;
  82. };
  83. typedef enum
  84. {
  85. SunCallTypeTNull,
  86. SunCallTypeRNull,
  87. } SunCallType;
  88. struct SunCall
  89. {
  90. SunRpc rpc;
  91. SunCallType type;
  92. };
  93. void sunErrstr(SunStatus);
  94. void sunRpcPrint(Fmt*, SunRpc*);
  95. uint sunRpcSize(SunRpc*);
  96. SunStatus sunRpcPack(uint8_t*, uint8_t*, uint8_t**, SunRpc*);
  97. SunStatus sunRpcUnpack(uint8_t*, uint8_t*, uint8_t**, SunRpc*);
  98. void sunAuthInfoPrint(Fmt*, SunAuthInfo*);
  99. uint sunAuthInfoSize(SunAuthInfo*);
  100. int sunAuthInfoPack(uint8_t*, uint8_t*, uint8_t**, SunAuthInfo*);
  101. int sunAuthInfoUnpack(uint8_t*, uint8_t*, uint8_t**, SunAuthInfo*);
  102. void sunAuthUnixPrint(Fmt*, SunAuthUnix*);
  103. uint sunAuthUnixSize(SunAuthUnix*);
  104. int sunAuthUnixPack(uint8_t*, uint8_t*, uint8_t**, SunAuthUnix*);
  105. int sunAuthUnixUnpack(uint8_t*, uint8_t*, uint8_t**, SunAuthUnix*);
  106. int sunEnumPack(uint8_t*, uint8_t*, uint8_t**, int*);
  107. int sunEnumUnpack(uint8_t*, uint8_t*, uint8_t**, int*);
  108. int sunUint1Pack(uint8_t*, uint8_t*, uint8_t**, u1int*);
  109. int sunUint1Unpack(uint8_t*, uint8_t*, uint8_t**, u1int*);
  110. int sunStringPack(uint8_t*, uint8_t*, uint8_t**, char**, uint32_t);
  111. int sunStringUnpack(uint8_t*, uint8_t*, uint8_t**, char**, uint32_t);
  112. uint sunStringSize(char*);
  113. int sunUint32Pack(uint8_t*, uint8_t*, uint8_t**, uint32_t*);
  114. int sunUint32Unpack(uint8_t*, uint8_t*, uint8_t**, uint32_t*);
  115. int sunUint64Pack(uint8_t*, uint8_t*, uint8_t**, uint64_t*);
  116. int sunUint64Unpack(uint8_t*, uint8_t*, uint8_t**, uint64_t*);
  117. int sunVarOpaquePack(uint8_t*, uint8_t*, uint8_t**, uint8_t**, uint32_t*,
  118. uint32_t);
  119. int sunVarOpaqueUnpack(uint8_t*, uint8_t*, uint8_t**, uint8_t**, uint32_t*,
  120. uint32_t);
  121. uint sunVarOpaqueSize(uint32_t);
  122. int sunFixedOpaquePack(uint8_t*, uint8_t*, uint8_t**, uint8_t*, uint32_t);
  123. int sunFixedOpaqueUnpack(uint8_t*, uint8_t*, uint8_t**, uint8_t*, uint32_t);
  124. uint sunFixedOpaqueSize(uint32_t);
  125. /*
  126. * Sun RPC Program
  127. */
  128. typedef struct SunProc SunProc;
  129. typedef struct SunProg SunProg;
  130. struct SunProg
  131. {
  132. uint prog;
  133. uint vers;
  134. SunProc *proc;
  135. int nproc;
  136. };
  137. struct SunProc
  138. {
  139. int (*pack)(uint8_t*, uint8_t*, uint8_t**, SunCall*);
  140. int (*unpack)(uint8_t*, uint8_t*, uint8_t**, SunCall*);
  141. uint (*size)(SunCall*);
  142. void (*fmt)(Fmt*, SunCall*);
  143. uint sizeoftype;
  144. };
  145. SunStatus sunCallPack(SunProg*, uint8_t*, uint8_t*, uint8_t**, SunCall*);
  146. SunStatus sunCallUnpack(SunProg*, uint8_t*, uint8_t*, uint8_t**, SunCall*);
  147. SunStatus sunCallUnpackAlloc(SunProg*, SunCallType, uint8_t*, uint8_t*,
  148. uint8_t**, SunCall**);
  149. uint sunCallSize(SunProg*, SunCall*);
  150. void sunCallSetup(SunCall*, SunProg*, uint);
  151. /*
  152. * Formatting
  153. */
  154. int sunRpcFmt(Fmt*);
  155. int sunCallFmt(Fmt*);
  156. void sunFmtInstall(SunProg*);
  157. /*
  158. * Sun RPC Server
  159. */
  160. typedef struct SunMsg SunMsg;
  161. typedef struct SunSrv SunSrv;
  162. enum
  163. {
  164. SunStackSize = 8192,
  165. };
  166. struct SunMsg
  167. {
  168. uint8_t *data;
  169. int count;
  170. SunSrv *srv;
  171. SunRpc rpc;
  172. SunProg *pg;
  173. SunCall *call;
  174. Channel *creply; /* chan(SunMsg*) */
  175. };
  176. struct SunSrv
  177. {
  178. int chatty;
  179. int cacheReplies;
  180. int alwaysReject;
  181. SunProg **map;
  182. Channel *crequest;
  183. /* implementation use only */
  184. Channel **cdispatch;
  185. SunProg **prog;
  186. int nprog;
  187. void *cache;
  188. Channel *creply;
  189. Channel *cthread;
  190. };
  191. SunSrv *sunSrv(void);
  192. void sunSrvProg(SunSrv *srv, SunProg *prog, Channel *c);
  193. int sunSrvAnnounce(SunSrv *srv, char *address);
  194. int sunSrvUdp(SunSrv *srv, char *address);
  195. int sunSrvNet(SunSrv *srv, char *address);
  196. int sunSrvFd(SunSrv *srv, int fd);
  197. void sunSrvThreadCreate(SunSrv *srv, void (*fn)(void*), void*);
  198. void sunSrvClose(SunSrv*);
  199. int sunMsgReply(SunMsg*, SunCall*);
  200. int sunMsgDrop(SunMsg*);
  201. int sunMsgReplyError(SunMsg*, SunStatus);
  202. /*
  203. * Sun RPC Client
  204. */
  205. typedef struct SunClient SunClient;
  206. struct SunClient
  207. {
  208. int fd;
  209. int chatty;
  210. int needcount;
  211. uint32_t maxwait;
  212. uint32_t xidgen;
  213. int nsend;
  214. int nresend;
  215. struct {
  216. uint32_t min;
  217. uint32_t max;
  218. uint32_t avg;
  219. } rtt;
  220. Channel *dying;
  221. Channel *rpcchan;
  222. Channel *timerchan;
  223. Channel *flushchan;
  224. Channel *readchan;
  225. SunProg **prog;
  226. int nprog;
  227. int timertid;
  228. int nettid;
  229. };
  230. SunClient *sunDial(char*);
  231. int sunClientRpc(SunClient*, uint32_t, SunCall*, SunCall*, uint8_t**);
  232. void sunClientClose(SunClient*);
  233. void sunClientFlushRpc(SunClient*, uint32_t);
  234. void sunClientProg(SunClient*, SunProg*);
  235. /*
  236. * Provided by callers.
  237. * Should remove dependence on this, but hard.
  238. */
  239. void *emalloc(uint32_t);
  240. void *erealloc(void*, uint32_t);
  241. /*
  242. * Sun RPC port mapper; see RFC 1057 Appendix A
  243. */
  244. typedef struct PortMap PortMap;
  245. typedef struct PortTNull PortTNull;
  246. typedef struct PortRNull PortRNull;
  247. typedef struct PortTSet PortTSet;
  248. typedef struct PortRSet PortRSet;
  249. typedef struct PortTUnset PortTUnset;
  250. typedef struct PortRUnset PortRUnset;
  251. typedef struct PortTGetport PortTGetport;
  252. typedef struct PortRGetport PortRGetport;
  253. typedef struct PortTDump PortTDump;
  254. typedef struct PortRDump PortRDump;
  255. typedef struct PortTCallit PortTCallit;
  256. typedef struct PortRCallit PortRCallit;
  257. typedef enum
  258. {
  259. PortCallTNull,
  260. PortCallRNull,
  261. PortCallTSet,
  262. PortCallRSet,
  263. PortCallTUnset,
  264. PortCallRUnset,
  265. PortCallTGetport,
  266. PortCallRGetport,
  267. PortCallTDump,
  268. PortCallRDump,
  269. PortCallTCallit,
  270. PortCallRCallit,
  271. } PortCallType;
  272. enum
  273. {
  274. PortProgram = 100000,
  275. PortVersion = 2,
  276. PortProtoTcp = 6, /* protocol number for TCP/IP */
  277. PortProtoUdp = 17 /* protocol number for UDP/IP */
  278. };
  279. struct PortMap {
  280. uint32_t prog;
  281. uint32_t vers;
  282. uint32_t prot;
  283. uint32_t port;
  284. };
  285. struct PortTNull {
  286. SunCall call;
  287. };
  288. struct PortRNull {
  289. SunCall call;
  290. };
  291. struct PortTSet {
  292. SunCall call;
  293. PortMap map;
  294. };
  295. struct PortRSet {
  296. SunCall call;
  297. u1int b;
  298. };
  299. struct PortTUnset {
  300. SunCall call;
  301. PortMap map;
  302. };
  303. struct PortRUnset {
  304. SunCall call;
  305. u1int b;
  306. };
  307. struct PortTGetport {
  308. SunCall call;
  309. PortMap map;
  310. };
  311. struct PortRGetport {
  312. SunCall call;
  313. uint32_t port;
  314. };
  315. struct PortTDump {
  316. SunCall call;
  317. };
  318. struct PortRDump {
  319. SunCall call;
  320. PortMap *map;
  321. int nmap;
  322. };
  323. struct PortTCallit {
  324. SunCall call;
  325. uint32_t prog;
  326. uint32_t vers;
  327. uint32_t proc;
  328. uint8_t *data;
  329. uint32_t count;
  330. };
  331. struct PortRCallit {
  332. SunCall call;
  333. uint32_t port;
  334. uint8_t *data;
  335. uint32_t count;
  336. };
  337. extern SunProg portProg;