tsunrpc.h - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       tsunrpc.h (7317B)
       ---
            1 /*
            2  * Sun RPC; see RFC 1057
            3  */
            4 
            5 /*
            6 #pragma lib "libsunrpc.a"
            7 #pragma src "/sys/src/libsunrpc"
            8 */
            9 AUTOLIB(sunrpc)
           10 
           11 typedef uchar u1int;
           12 
           13 typedef struct SunAuthInfo SunAuthInfo;
           14 typedef struct SunAuthUnix SunAuthUnix;
           15 typedef struct SunRpc SunRpc;
           16 typedef struct SunCall SunCall;
           17 
           18 enum
           19 {
           20         /* Authinfo.flavor */
           21         SunAuthNone = 0,
           22         SunAuthSys,
           23         SunAuthShort,
           24         SunAuthDes
           25 };
           26 
           27 typedef 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 
           52 struct SunAuthInfo
           53 {
           54         uint flavor;
           55         uchar *data;
           56         uint ndata;
           57 };
           58 
           59 struct SunAuthUnix
           60 {
           61         u32int stamp;
           62         char *sysname;
           63         u32int uid;
           64         u32int gid;
           65         u32int g[16];
           66         u32int ng;
           67 };
           68 
           69 struct 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 
           96 typedef enum
           97 {
           98         SunCallTypeTNull,
           99         SunCallTypeRNull
          100 } SunCallType;
          101 
          102 struct SunCall
          103 {
          104         SunRpc rpc;
          105         SunCallType type;
          106 };
          107 
          108 void sunerrstr(SunStatus);
          109 
          110 void sunrpcprint(Fmt*, SunRpc*);
          111 uint sunrpcsize(SunRpc*);
          112 SunStatus sunrpcpack(uchar*, uchar*, uchar**, SunRpc*);
          113 SunStatus sunrpcunpack(uchar*, uchar*, uchar**, SunRpc*);
          114 
          115 void sunauthinfoprint(Fmt*, SunAuthInfo*);
          116 uint sunauthinfosize(SunAuthInfo*);
          117 int sunauthinfopack(uchar*, uchar*, uchar**, SunAuthInfo*);
          118 int sunauthinfounpack(uchar*, uchar*, uchar**, SunAuthInfo*);
          119 
          120 void sunauthunixprint(Fmt*, SunAuthUnix*);
          121 uint sunauthunixsize(SunAuthUnix*);
          122 int sunauthunixpack(uchar*, uchar*, uchar**, SunAuthUnix*);
          123 int sunauthunixunpack(uchar*, uchar*, uchar**, SunAuthUnix*);
          124 
          125 int sunenumpack(uchar*, uchar*, uchar**, int*);
          126 int sunenumunpack(uchar*, uchar*, uchar**, int*);
          127 int sunuint1pack(uchar*, uchar*, uchar**, u1int*);
          128 int sunuint1unpack(uchar*, uchar*, uchar**, u1int*);
          129 
          130 int sunstringpack(uchar*, uchar*, uchar**, char**, u32int);
          131 int sunstringunpack(uchar*, uchar*, uchar**, char**, u32int);
          132 uint sunstringsize(char*);
          133 
          134 int sunuint32pack(uchar*, uchar*, uchar**, u32int*);
          135 int sunuint32unpack(uchar*, uchar*, uchar**, u32int*);
          136 int sunuint64pack(uchar*, uchar*, uchar**, u64int*);
          137 int sunuint64unpack(uchar*, uchar*, uchar**, u64int*);
          138 
          139 int sunvaropaquepack(uchar*, uchar*, uchar**, uchar**, u32int*, u32int);
          140 int sunvaropaqueunpack(uchar*, uchar*, uchar**, uchar**, u32int*, u32int);
          141 uint sunvaropaquesize(u32int);
          142 
          143 int sunfixedopaquepack(uchar*, uchar*, uchar**, uchar*, u32int);
          144 int sunfixedopaqueunpack(uchar*, uchar*, uchar**, uchar*, u32int);
          145 uint sunfixedopaquesize(u32int);
          146 
          147 /*
          148  * Sun RPC Program
          149  */
          150 typedef struct SunProc SunProc;
          151 typedef struct SunProg SunProg;
          152 struct SunProg
          153 {
          154         uint prog;
          155         uint vers;
          156         SunProc *proc;
          157         int nproc;
          158 };
          159 
          160 struct 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 
          169 SunStatus suncallpack(SunProg*, uchar*, uchar*, uchar**, SunCall*);
          170 SunStatus suncallunpack(SunProg*, uchar*, uchar*, uchar**, SunCall*);
          171 SunStatus suncallunpackalloc(SunProg*, SunCallType, uchar*, uchar*, uchar**, SunCall**);
          172 void suncallsetup(SunCall*, SunProg*, uint);
          173 uint suncallsize(SunProg*, SunCall*);
          174 
          175 /*
          176  * Formatting
          177 #pragma varargck type "B" SunRpc*
          178 #pragma varargck type "C" SunCall*
          179  */
          180 
          181 int        sunrpcfmt(Fmt*);
          182 int        suncallfmt(Fmt*);
          183 void        sunfmtinstall(SunProg*);
          184 
          185 
          186 /*
          187  * Sun RPC Server
          188  */
          189 typedef struct SunMsg SunMsg;
          190 typedef struct SunSrv SunSrv;
          191 
          192 enum
          193 {
          194         SunStackSize = 32768
          195 };
          196 
          197 struct 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 
          208 struct SunSrv
          209 {
          210         int chatty;
          211         int cachereplies;
          212         int alwaysreject;
          213         int localonly;
          214         int localparanoia;
          215         SunProg **map;
          216         Channel *crequest;
          217         int (*ipokay)(uchar*, ushort);
          218 
          219 /* implementation use only */
          220         Channel **cdispatch;
          221         SunProg **prog;
          222         int nprog;
          223         void *cache;
          224         Channel *creply;
          225         Channel *cthread;
          226 };
          227 
          228 SunSrv *sunsrv(void);
          229 
          230 void        sunsrvprog(SunSrv *srv, SunProg *prog, Channel *c);
          231 int        sunsrvannounce(SunSrv *srv, char *address);
          232 int        sunsrvudp(SunSrv *srv, char *address);
          233 int        sunsrvnet(SunSrv *srv, char *address);
          234 int        sunsrvfd(SunSrv *srv, int fd);
          235 void        sunsrvthreadcreate(SunSrv *srv, void (*fn)(void*), void*);
          236 void        sunsrvclose(SunSrv*);
          237 
          238 int        sunmsgreply(SunMsg*, SunCall*);
          239 int        sunmsgdrop(SunMsg*);
          240 int        sunmsgreplyerror(SunMsg*, SunStatus);
          241 
          242 /*
          243  * Sun RPC Client
          244  */
          245 typedef struct SunClient SunClient;
          246 
          247 struct 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 
          272 SunClient        *sundial(char*);
          273 
          274 int        sunclientrpc(SunClient*, ulong, SunCall*, SunCall*, uchar**);
          275 void        sunclientclose(SunClient*);
          276 void        sunclientflushrpc(SunClient*, ulong);
          277 void        sunclientprog(SunClient*, SunProg*);
          278 
          279 
          280 /*
          281  * Provided by callers.
          282  * Should remove dependence on this, but hard.
          283  */
          284 void        *emalloc(ulong);
          285 void *erealloc(void*, ulong);
          286 
          287 
          288 /*
          289  * Sun RPC port mapper; see RFC 1057 Appendix A
          290  */
          291 
          292 typedef struct PortMap PortMap;
          293 typedef struct PortTNull PortTNull;
          294 typedef struct PortRNull PortRNull;
          295 typedef struct PortTSet PortTSet;
          296 typedef struct PortRSet PortRSet;
          297 typedef struct PortTUnset PortTUnset;
          298 typedef struct PortRUnset PortRUnset;
          299 typedef struct PortTGetport PortTGetport;
          300 typedef struct PortRGetport PortRGetport;
          301 typedef struct PortTDump PortTDump;
          302 typedef struct PortRDump PortRDump;
          303 typedef struct PortTCallit PortTCallit;
          304 typedef struct PortRCallit PortRCallit;
          305 
          306 typedef 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 
          322 enum
          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 
          331 struct PortMap {
          332         u32int prog;
          333         u32int vers;
          334         u32int prot;
          335         u32int port;
          336 };
          337 
          338 struct PortTNull {
          339         SunCall call;
          340 };
          341 
          342 struct PortRNull {
          343         SunCall call;
          344 };
          345 
          346 struct PortTSet {
          347         SunCall call;
          348         PortMap map;
          349 };
          350 
          351 struct PortRSet {
          352         SunCall call;
          353         u1int b;
          354 };
          355 
          356 struct PortTUnset {
          357         SunCall call;
          358         PortMap map;
          359 };
          360 
          361 struct PortRUnset {
          362         SunCall call;
          363         u1int b;
          364 };
          365 
          366 struct PortTGetport {
          367         SunCall call;
          368         PortMap map;
          369 };
          370 
          371 struct PortRGetport {
          372         SunCall call;
          373         u32int port;
          374 };
          375 
          376 struct PortTDump {
          377         SunCall call;
          378 };
          379 
          380 struct PortRDump {
          381         SunCall call;
          382         PortMap *map;
          383         int nmap;
          384 };
          385 
          386 struct PortTCallit {
          387         SunCall call;
          388         u32int prog;
          389         u32int vers;
          390         u32int proc;
          391         uchar *data;
          392         u32int count;
          393 };
          394 
          395 struct PortRCallit {
          396         SunCall call;
          397         u32int port;
          398         uchar *data;
          399         u32int count;
          400 };
          401 
          402 extern SunProg portprog;