sunrpc.h 7.0 KB

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