blob: 4f108aa0bf3d2efd39f02f44c0145a06b42f4fcf [file] [log] [blame]
rsc2277c5d2004-03-21 04:33:13 +00001/*
2 * Sun RPC; see RFC 1057
3 */
4
5/*
6#pragma lib "libsunrpc.a"
7#pragma src "/sys/src/libsunrpc"
8*/
9
10typedef uchar u1int;
11
12typedef struct SunAuthInfo SunAuthInfo;
13typedef struct SunAuthUnix SunAuthUnix;
14typedef struct SunRpc SunRpc;
15typedef struct SunCall SunCall;
16
17enum
18{
19 /* Authinfo.flavor */
20 SunAuthNone = 0,
21 SunAuthSys,
22 SunAuthShort,
23 SunAuthDes,
24};
25
26typedef enum {
27 SunAcceptError = 0x10000,
28 SunRejectError = 0x20000,
29 SunAuthError = 0x40000,
30
31 /* Reply.status */
32 SunSuccess = 0,
33
34 SunProgUnavail = SunAcceptError | 1,
35 SunProgMismatch,
36 SunProcUnavail,
37 SunGarbageArgs,
38 SunSystemErr,
39
40 SunRpcMismatch = SunRejectError | 0,
41
42 SunAuthBadCred = SunAuthError | 1,
43 SunAuthRejectedCred,
44 SunAuthBadVerf,
45 SunAuthRejectedVerf,
46 SunAuthTooWeak,
47 SunAuthInvalidResp,
48 SunAuthFailed,
49} SunStatus;
50
51struct SunAuthInfo
52{
53 uint flavor;
54 uchar *data;
55 uint ndata;
56};
57
58struct SunAuthUnix
59{
60 u32int stamp;
61 char *sysname;
62 u32int uid;
63 u32int gid;
64 u32int g[16];
65 u32int ng;
66};
67
68struct SunRpc
69{
70 u32int xid;
71 uint iscall;
72
73 /*
74 * only sent on wire in call
75 * caller fills in for the reply unpackers.
76 */
77 u32int proc;
78
79 /* call */
80 // uint proc;
81 u32int prog, vers;
82 SunAuthInfo cred;
83 SunAuthInfo verf;
84 uchar *data;
85 uint ndata;
86
87 /* reply */
88 u32int status;
89 // SunAuthInfo verf;
90 u32int low, high;
91 // uchar *data;
92 // uint ndata;
93};
94
95typedef enum
96{
97 SunCallTypeTNull,
98 SunCallTypeRNull,
99} SunCallType;
100
101struct SunCall
102{
103 SunRpc rpc;
104 SunCallType type;
105};
106
107void sunerrstr(SunStatus);
108
109void sunrpcprint(Fmt*, SunRpc*);
110uint sunrpcsize(SunRpc*);
111SunStatus sunrpcpack(uchar*, uchar*, uchar**, SunRpc*);
112SunStatus sunrpcunpack(uchar*, uchar*, uchar**, SunRpc*);
113
114void sunauthinfoprint(Fmt*, SunAuthInfo*);
115uint sunauthinfosize(SunAuthInfo*);
116int sunauthinfopack(uchar*, uchar*, uchar**, SunAuthInfo*);
117int sunauthinfounpack(uchar*, uchar*, uchar**, SunAuthInfo*);
118
119void sunauthunixprint(Fmt*, SunAuthUnix*);
120uint sunauthunixsize(SunAuthUnix*);
121int sunauthunixpack(uchar*, uchar*, uchar**, SunAuthUnix*);
122int sunauthunixunpack(uchar*, uchar*, uchar**, SunAuthUnix*);
123
124int sunenumpack(uchar*, uchar*, uchar**, int*);
125int sunenumunpack(uchar*, uchar*, uchar**, int*);
126int sunuint1pack(uchar*, uchar*, uchar**, u1int*);
127int sunuint1unpack(uchar*, uchar*, uchar**, u1int*);
128
129int sunstringpack(uchar*, uchar*, uchar**, char**, u32int);
130int sunstringunpack(uchar*, uchar*, uchar**, char**, u32int);
131uint sunstringsize(char*);
132
133int sunuint32pack(uchar*, uchar*, uchar**, u32int*);
134int sunuint32unpack(uchar*, uchar*, uchar**, u32int*);
135int sunuint64pack(uchar*, uchar*, uchar**, u64int*);
136int sunuint64unpack(uchar*, uchar*, uchar**, u64int*);
137
138int sunvaropaquepack(uchar*, uchar*, uchar**, uchar**, u32int*, u32int);
139int sunvaropaqueunpack(uchar*, uchar*, uchar**, uchar**, u32int*, u32int);
140uint sunvaropaquesize(u32int);
141
142int sunfixedopaquepack(uchar*, uchar*, uchar**, uchar*, u32int);
143int sunfixedopaqueunpack(uchar*, uchar*, uchar**, uchar*, u32int);
144uint sunfixedopaquesize(u32int);
145
146/*
147 * Sun RPC Program
148 */
149typedef struct SunProc SunProc;
150typedef struct SunProg SunProg;
151struct SunProg
152{
153 uint prog;
154 uint vers;
155 SunProc *proc;
156 int nproc;
157};
158
159struct SunProc
160{
161 int (*pack)(uchar*, uchar*, uchar**, SunCall*);
162 int (*unpack)(uchar*, uchar*, uchar**, SunCall*);
163 uint (*size)(SunCall*);
164 void (*fmt)(Fmt*, SunCall*);
165 uint sizeoftype;
166};
167
168SunStatus suncallpack(SunProg*, uchar*, uchar*, uchar**, SunCall*);
169SunStatus suncallunpack(SunProg*, uchar*, uchar*, uchar**, SunCall*);
170SunStatus suncallunpackalloc(SunProg*, SunCallType, uchar*, uchar*, uchar**, SunCall**);
171void suncallsetup(SunCall*, SunProg*, uint);
172uint suncallsize(SunProg*, SunCall*);
173
174/*
175 * Formatting
176#pragma varargck type "B" SunRpc*
177#pragma varargck type "C" SunCall*
178 */
179
180int sunrpcfmt(Fmt*);
181int suncallfmt(Fmt*);
182void sunfmtinstall(SunProg*);
183
184
185/*
186 * Sun RPC Server
187 */
188typedef struct SunMsg SunMsg;
189typedef struct SunSrv SunSrv;
190
191enum
192{
193 SunStackSize = 32768,
194};
195
196struct SunMsg
197{
198 uchar *data;
199 int count;
200 SunSrv *srv;
201 SunRpc rpc;
202 SunProg *pg;
203 SunCall *call;
204 Channel *creply; /* chan(SunMsg*) */
205};
206
207struct SunSrv
208{
209 int chatty;
210 int cachereplies;
211 int alwaysreject;
212 int localonly;
213 int localparanoia;
214 SunProg **map;
215 Channel *crequest;
216
217/* implementation use only */
218 Channel **cdispatch;
219 SunProg **prog;
220 int nprog;
221 void *cache;
222 Channel *creply;
223 Channel *cthread;
224};
225
226SunSrv *sunsrv(void);
227
228void sunsrvprog(SunSrv *srv, SunProg *prog, Channel *c);
229int sunsrvannounce(SunSrv *srv, char *address);
230int sunsrvudp(SunSrv *srv, char *address);
231int sunsrvnet(SunSrv *srv, char *address);
232int sunsrvfd(SunSrv *srv, int fd);
233void sunsrvthreadcreate(SunSrv *srv, void (*fn)(void*), void*);
234void sunsrvclose(SunSrv*);
235
236int sunmsgreply(SunMsg*, SunCall*);
237int sunmsgdrop(SunMsg*);
238int sunmsgreplyerror(SunMsg*, SunStatus);
239
240/*
241 * Sun RPC Client
242 */
243typedef struct SunClient SunClient;
244
245struct SunClient
246{
247 int fd;
248 int chatty;
249 int needcount;
250 ulong maxwait;
251 ulong xidgen;
252 int nsend;
253 int nresend;
254 struct {
255 ulong min;
256 ulong max;
257 ulong avg;
258 } rtt;
259 Channel *dying;
260 Channel *rpcchan;
261 Channel *timerchan;
262 Channel *flushchan;
263 Channel *readchan;
264 SunProg **prog;
265 int nprog;
266 int timertid;
267 int nettid;
268};
269
270SunClient *sundial(char*);
271
272int sunclientrpc(SunClient*, ulong, SunCall*, SunCall*, uchar**);
273void sunclientclose(SunClient*);
274void sunclientflushrpc(SunClient*, ulong);
275void sunclientprog(SunClient*, SunProg*);
276
277
278/*
279 * Provided by callers.
280 * Should remove dependence on this, but hard.
281 */
282void *emalloc(ulong);
283void *erealloc(void*, ulong);
284
285
286/*
287 * Sun RPC port mapper; see RFC 1057 Appendix A
288 */
289
290typedef struct PortMap PortMap;
291typedef struct PortTNull PortTNull;
292typedef struct PortRNull PortRNull;
293typedef struct PortTSet PortTSet;
294typedef struct PortRSet PortRSet;
295typedef struct PortTUnset PortTUnset;
296typedef struct PortRUnset PortRUnset;
297typedef struct PortTGetport PortTGetport;
298typedef struct PortRGetport PortRGetport;
299typedef struct PortTDump PortTDump;
300typedef struct PortRDump PortRDump;
301typedef struct PortTCallit PortTCallit;
302typedef struct PortRCallit PortRCallit;
303
304typedef enum
305{
306 PortCallTNull,
307 PortCallRNull,
308 PortCallTSet,
309 PortCallRSet,
310 PortCallTUnset,
311 PortCallRUnset,
312 PortCallTGetport,
313 PortCallRGetport,
314 PortCallTDump,
315 PortCallRDump,
316 PortCallTCallit,
317 PortCallRCallit,
318} PortCallType;
319
320enum
321{
322 PortProgram = 100000,
323 PortVersion = 2,
324
325 PortProtoTcp = 6, /* protocol number for TCP/IP */
326 PortProtoUdp = 17 /* protocol number for UDP/IP */
327};
328
329struct PortMap {
330 u32int prog;
331 u32int vers;
332 u32int prot;
333 u32int port;
334};
335
336struct PortTNull {
337 SunCall call;
338};
339
340struct PortRNull {
341 SunCall call;
342};
343
344struct PortTSet {
345 SunCall call;
346 PortMap map;
347};
348
349struct PortRSet {
350 SunCall call;
351 u1int b;
352};
353
354struct PortTUnset {
355 SunCall call;
356 PortMap map;
357};
358
359struct PortRUnset {
360 SunCall call;
361 u1int b;
362};
363
364struct PortTGetport {
365 SunCall call;
366 PortMap map;
367};
368
369struct PortRGetport {
370 SunCall call;
371 u32int port;
372};
373
374struct PortTDump {
375 SunCall call;
376};
377
378struct PortRDump {
379 SunCall call;
380 PortMap *map;
381 int nmap;
382};
383
384struct PortTCallit {
385 SunCall call;
386 u32int prog;
387 u32int vers;
388 u32int proc;
389 uchar *data;
390 u32int count;
391};
392
393struct PortRCallit {
394 SunCall call;
395 u32int port;
396 uchar *data;
397 u32int count;
398};
399
400extern SunProg portprog;