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