1
0

sunrpc.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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. void sunCallSetup(SunCall*, SunProg*, uint);
  142. /*
  143. * Formatting
  144. */
  145. #pragma varargck type "B" SunRpc*
  146. #pragma varargck type "C" SunCall*
  147. int sunRpcFmt(Fmt*);
  148. int sunCallFmt(Fmt*);
  149. void sunFmtInstall(SunProg*);
  150. /*
  151. * Sun RPC Server
  152. */
  153. typedef struct SunMsg SunMsg;
  154. typedef struct SunSrv SunSrv;
  155. enum
  156. {
  157. SunStackSize = 8192,
  158. };
  159. struct SunMsg
  160. {
  161. uchar *data;
  162. int count;
  163. SunSrv *srv;
  164. SunRpc rpc;
  165. SunProg *pg;
  166. SunCall *call;
  167. Channel *creply; /* chan(SunMsg*) */
  168. };
  169. struct SunSrv
  170. {
  171. int chatty;
  172. int cacheReplies;
  173. int alwaysReject;
  174. SunProg **map;
  175. Channel *crequest;
  176. /* implementation use only */
  177. Channel **cdispatch;
  178. SunProg **prog;
  179. int nprog;
  180. void *cache;
  181. Channel *creply;
  182. Channel *cthread;
  183. };
  184. SunSrv *sunSrv(void);
  185. void sunSrvProg(SunSrv *srv, SunProg *prog, Channel *c);
  186. int sunSrvAnnounce(SunSrv *srv, char *address);
  187. int sunSrvUdp(SunSrv *srv, char *address);
  188. int sunSrvNet(SunSrv *srv, char *address);
  189. int sunSrvFd(SunSrv *srv, int fd);
  190. void sunSrvThreadCreate(SunSrv *srv, void (*fn)(void*), void*);
  191. void sunSrvClose(SunSrv*);
  192. int sunMsgReply(SunMsg*, SunCall*);
  193. int sunMsgDrop(SunMsg*);
  194. int sunMsgReplyError(SunMsg*, SunStatus);
  195. /*
  196. * Sun RPC Client
  197. */
  198. typedef struct SunClient SunClient;
  199. struct SunClient
  200. {
  201. int fd;
  202. int chatty;
  203. int needcount;
  204. ulong maxwait;
  205. ulong xidgen;
  206. int nsend;
  207. int nresend;
  208. struct {
  209. ulong min;
  210. ulong max;
  211. ulong avg;
  212. } rtt;
  213. Channel *dying;
  214. Channel *rpcchan;
  215. Channel *timerchan;
  216. Channel *flushchan;
  217. Channel *readchan;
  218. SunProg **prog;
  219. int nprog;
  220. int timertid;
  221. int nettid;
  222. };
  223. SunClient *sunDial(char*);
  224. int sunClientRpc(SunClient*, ulong, SunCall*, SunCall*, uchar**);
  225. void sunClientClose(SunClient*);
  226. void sunClientFlushRpc(SunClient*, ulong);
  227. void sunClientProg(SunClient*, SunProg*);
  228. /*
  229. * Provided by callers.
  230. * Should remove dependence on this, but hard.
  231. */
  232. void *emalloc(ulong);
  233. void *erealloc(void*, ulong);
  234. /*
  235. * Sun RPC port mapper; see RFC 1057 Appendix A
  236. */
  237. typedef struct PortMap PortMap;
  238. typedef struct PortTNull PortTNull;
  239. typedef struct PortRNull PortRNull;
  240. typedef struct PortTSet PortTSet;
  241. typedef struct PortRSet PortRSet;
  242. typedef struct PortTUnset PortTUnset;
  243. typedef struct PortRUnset PortRUnset;
  244. typedef struct PortTGetport PortTGetport;
  245. typedef struct PortRGetport PortRGetport;
  246. typedef struct PortTDump PortTDump;
  247. typedef struct PortRDump PortRDump;
  248. typedef struct PortTCallit PortTCallit;
  249. typedef struct PortRCallit PortRCallit;
  250. typedef enum
  251. {
  252. PortCallTNull,
  253. PortCallRNull,
  254. PortCallTSet,
  255. PortCallRSet,
  256. PortCallTUnset,
  257. PortCallRUnset,
  258. PortCallTGetport,
  259. PortCallRGetport,
  260. PortCallTDump,
  261. PortCallRDump,
  262. PortCallTCallit,
  263. PortCallRCallit,
  264. } PortCallType;
  265. enum
  266. {
  267. PortProgram = 100000,
  268. PortVersion = 2,
  269. PortProtoTcp = 6, /* protocol number for TCP/IP */
  270. PortProtoUdp = 17 /* protocol number for UDP/IP */
  271. };
  272. struct PortMap {
  273. u32int prog;
  274. u32int vers;
  275. u32int prot;
  276. u32int port;
  277. };
  278. struct PortTNull {
  279. SunCall call;
  280. };
  281. struct PortRNull {
  282. SunCall call;
  283. };
  284. struct PortTSet {
  285. SunCall call;
  286. PortMap map;
  287. };
  288. struct PortRSet {
  289. SunCall call;
  290. u1int b;
  291. };
  292. struct PortTUnset {
  293. SunCall call;
  294. PortMap map;
  295. };
  296. struct PortRUnset {
  297. SunCall call;
  298. u1int b;
  299. };
  300. struct PortTGetport {
  301. SunCall call;
  302. PortMap map;
  303. };
  304. struct PortRGetport {
  305. SunCall call;
  306. u32int port;
  307. };
  308. struct PortTDump {
  309. SunCall call;
  310. };
  311. struct PortRDump {
  312. SunCall call;
  313. PortMap *map;
  314. int nmap;
  315. };
  316. struct PortTCallit {
  317. SunCall call;
  318. u32int prog;
  319. u32int vers;
  320. u32int proc;
  321. uchar *data;
  322. u32int count;
  323. };
  324. struct PortRCallit {
  325. SunCall call;
  326. u32int port;
  327. uchar *data;
  328. u32int count;
  329. };
  330. extern SunProg portProg;