home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume13 / rpc3.9 / part12 / rpc.rfc.ms next >
Encoding:
Text File  |  1988-02-27  |  31.7 KB  |  963 lines

  1. .\" @(#)rpc.rfc.ms    1.2 87/11/09 3.9 RPCSRC
  2. .de BT
  3. .if \\n%=1 .tl ''- % -''
  4. ..
  5. .ND
  6. .\" prevent excess underlining in nroff
  7. .if n .fp 2 R
  8. .OH 'Remote Procedure Calls: Protocol Specification''Page %'
  9. .EH 'Page %''Remote Procedure Calls: Protocol Specification'
  10. .if \\n%=1 .bp
  11. .SH
  12. \&Remote Procedure Calls: Protocol Specification
  13. .LP
  14. .NH 0
  15. \&Status of this Memo
  16. .LP
  17. Note: This chapter specifies a protocol that Sun Microsystems, Inc.,
  18. and others are using.  It has been submitted to the ARPA-Internet
  19. for consideration as an RFC.  \fBCertain details may change as a result
  20. of comments made during the review of this draft standard.\fP  
  21. .LP
  22. .NH 1
  23. \&Introduction
  24. .LP
  25. This chapter specifies  a  message protocol  used in implementing
  26. Sun's Remote Procedure Call (RPC) package.  (The message protocol is
  27. specified with the eXternal Data Representation (XDR) language.
  28. See the
  29. \fIeXternal Data Representation Standard\fP
  30. for the details.  Here, we assume that  the  reader is familiar  
  31. with XDR and do not attempt to justify RPC or  its uses).  The paper
  32. by Birrell and Nelson [1]  is recommended as an  excellent background
  33. to  and justification of RPC.
  34. .NH 2
  35. \&Terminology
  36. .LP
  37. This chapter discusses servers, services, programs, procedures,
  38. clients, and versions.  A server is a piece of software where network
  39. services are implemented.  A network service is a collection of one
  40. or more remote programs.  A remote program implements one or more
  41. remote procedures; the procedures, their parameters, and results are
  42. documented in the specific program's protocol specification (see the
  43. \fIPort Mapper Program Protocol\fP\, below, for an example).  Network
  44. clients are pieces of software that initiate remote procedure calls
  45. to services.  A server may support more than one version of a remote
  46. program in order to be forward compatible with changing protocols.
  47. .LP
  48. For example, a network file service may be composed of two programs.
  49. One program may deal with high-level applications such as file system
  50. access control and locking.  The other may deal with low-level file
  51. IO and have procedures like "read" and "write".  A client machine of
  52. the network file service would call the procedures associated with
  53. the two programs of the service on behalf of some user on the client
  54. machine.
  55. .NH 2
  56. \&The RPC Model
  57. .LP
  58. The remote procedure call model is similar to the local procedure
  59. call model.  In the local case, the caller places arguments to a
  60. procedure in some well-specified location (such as a result
  61. register).  It then transfers control to the procedure, and
  62. eventually gains back control.  At that point, the results of the
  63. procedure are extracted from the well-specified location, and the
  64. caller continues execution.
  65. .LP
  66. The remote procedure call is similar, in that one thread of control
  67. logically winds through two processes\(emone is the caller's process,
  68. the other is a server's process.  That is, the caller process sends a
  69. call message to the server process and waits (blocks) for a reply
  70. message.  The call message contains the procedure's parameters, among
  71. other things.  The reply message contains the procedure's results,
  72. among other things.  Once the reply message is received, the results
  73. of the procedure are extracted, and caller's execution is resumed.
  74. .LP
  75. On the server side, a process is dormant awaiting the arrival of a
  76. call message.  When one arrives, the server process extracts the
  77. procedure's parameters, computes the results, sends a reply message,
  78. and then awaits the next call message.
  79. .LP
  80. Note that in this model, only one of the two processes is active at
  81. any given time.  However, this model is only given as an example.
  82. The RPC protocol makes no restrictions on the concurrency model
  83. implemented, and others are possible.  For example, an implementation
  84. may choose to have RPC calls be asynchronous, so that the client may
  85. do useful work while waiting for the reply from the server.  Another
  86. possibility is to have the server create a task to process an
  87. incoming request, so that the server can be free to receive other
  88. requests.
  89. .NH 2
  90. \&Transports and Semantics
  91. .LP
  92. The RPC protocol is independent of transport protocols.  That is, RPC
  93. does not care how a message is passed from one process to another.
  94. The protocol deals only with specification and interpretation of
  95. messages.
  96. .LP
  97. It is important to point out that RPC does not try to implement any
  98. kind of reliability and that the application must be aware of the
  99. type of transport protocol underneath RPC.  If it knows it is running
  100. on top of a reliable transport such as TCP/IP[6], then most of the
  101. work is already done for it.  On the other hand, if it is running on
  102. top of an unreliable transport such as UDP/IP[7], it must implement
  103. is own retransmission and time-out policy as the RPC layer does not
  104. provide this service.
  105. .LP
  106. Because of transport independence, the RPC protocol does not attach
  107. specific semantics to the remote procedures or their execution.
  108. Semantics can be inferred from (but should be explicitly specified
  109. by) the underlying transport protocol.  For example, consider RPC
  110. running on top of an unreliable transport such as UDP/IP.  If an
  111. application retransmits RPC messages after short time-outs, the only
  112. thing it can infer if it receives no reply is that the procedure was
  113. executed zero or more times.  If it does receive a reply, then it can
  114. infer that the procedure was executed at least once.
  115. .LP
  116. A server may wish to remember previously granted requests from a
  117. client and not regrant them in order to insure some degree of
  118. execute-at-most-once semantics.  A server can do this by taking
  119. advantage of the transaction ID that is packaged with every RPC
  120. request.  The main use of this transaction is by the client RPC layer
  121. in matching replies to requests.  However, a client application may
  122. choose to reuse its previous transaction ID when retransmitting a
  123. request.  The server application, knowing this fact, may choose to
  124. remember this ID after granting a request and not regrant requests
  125. with the same ID in order to achieve some degree of
  126. execute-at-most-once semantics.  The server is not allowed to examine
  127. this ID in any other way except as a test for equality.
  128. .LP
  129. On the other hand, if using a reliable transport such as TCP/IP, the
  130. application can infer from a reply message that the procedure was
  131. executed exactly once, but if it receives no reply message, it cannot
  132. assume the remote procedure was not executed.  Note that even if a
  133. connection-oriented protocol like TCP is used, an application still
  134. needs time-outs and reconnection to handle server crashes.
  135. .LP
  136. There are other possibilities for transports besides datagram- or
  137. connection-oriented protocols.  For example, a request-reply protocol
  138. such as VMTP[2] is perhaps the most natural transport for RPC.
  139. .SH
  140. .I
  141. NOTE:  At Sun, RPC is currently implemented on top of both TCP/IP
  142. and UDP/IP transports.
  143. .LP
  144. .NH 2
  145. \&Binding and Rendezvous Independence
  146. .LP
  147. The act of binding a client to a service is NOT part of the remote
  148. procedure call specification.  This important and necessary function
  149. is left up to some higher-level software.  (The software may use RPC
  150. itself\(emsee the \fIPort Mapper Program Protocol\fP\, below).
  151. .LP
  152. Implementors should think of the RPC protocol as the jump-subroutine
  153. instruction ("JSR") of a network; the loader (binder) makes JSR
  154. useful, and the loader itself uses JSR to accomplish its task.
  155. Likewise, the network makes RPC useful, using RPC to accomplish this
  156. task.
  157. .NH 2
  158. \&Authentication
  159. .LP
  160. The RPC protocol provides the fields necessary for a client to
  161. identify itself to a service and vice-versa.  Security and access
  162. control mechanisms can be built on top of the message authentication.
  163. Several different authentication protocols can be supported.  A field
  164. in the RPC header indicates which protocol is being used.  More
  165. information on specific authentication protocols can be found in the
  166. \fIAuthentication Protocols\fP\,
  167. below.
  168. .KS
  169. .NH 1
  170. \&RPC Protocol Requirements
  171. .LP
  172. The RPC protocol must provide for the following:
  173. .IP  1.
  174. Unique specification of a procedure to be called.
  175. .IP  2.
  176. Provisions for matching response messages to request messages.
  177. .KE
  178. .IP  3.
  179. Provisions for authenticating the caller to service and vice-versa.
  180. .LP
  181. Besides these requirements, features that detect the following are
  182. worth supporting because of protocol roll-over errors, implementation
  183. bugs, user error, and network administration:
  184. .IP  1.
  185. RPC protocol mismatches.
  186. .IP  2.
  187. Remote program protocol version mismatches.
  188. .IP  3.
  189. Protocol errors (such as misspecification of a procedure's parameters).
  190. .IP  4.
  191. Reasons why remote authentication failed.
  192. .IP  5.
  193. Any other reasons why the desired procedure was not called.
  194. .NH 2
  195. \&Programs and Procedures
  196. .LP
  197. The RPC call message has three unsigned fields:  remote program
  198. number, remote program version number, and remote procedure number.
  199. The three fields uniquely identify the procedure to be called.
  200. Program numbers are administered by some central authority (like
  201. Sun).  Once an implementor has a program number, he can implement his
  202. remote program; the first implementation would most likely have the
  203. version number of 1.  Because most new protocols evolve into better,
  204. stable, and mature protocols, a version field of the call message
  205. identifies which version of the protocol the caller is using.
  206. Version numbers make speaking old and new protocols through the same
  207. server process possible.
  208. .LP
  209. The procedure number identifies the procedure to be called.  These
  210. numbers are documented in the specific program's protocol
  211. specification.  For example, a file service's protocol specification
  212. may state that its procedure number 5 is "read" and procedure number
  213. 12 is "write".
  214. .LP
  215. Just as remote program protocols may change over several versions,
  216. the actual RPC message protocol could also change.  Therefore, the
  217. call message also has in it the RPC version number, which is always
  218. equal to two for the version of RPC described here.
  219. .LP
  220. The reply message to a request  message  has enough  information to
  221. distinguish the following error conditions:
  222. .IP  1.
  223. The remote implementation of RPC does speak protocol version 2.
  224. The lowest and highest supported RPC version numbers are returned.
  225. .IP  2.
  226. The remote program is not available on the remote system.
  227. .IP  3.
  228. The remote program does not support the requested version number.
  229. The lowest and highest supported remote program version numbers are
  230. returned.
  231. .IP  4.
  232. The requested procedure number does not exist.  (This is usually a
  233. caller side protocol or programming error.)
  234. .IP  5.
  235. The parameters to the remote procedure appear to be garbage from the
  236. server's point of view.  (Again, this is usually caused by a
  237. disagreement about the protocol between client and service.)
  238. .NH 2
  239. \&Authentication
  240. .LP
  241. Provisions for authentication of caller to service and vice-versa are
  242. provided as a part of the RPC protocol.  The call message has two
  243. authentication fields, the credentials and verifier.  The reply
  244. message has one authentication field, the response verifier.  The RPC
  245. protocol specification defines all three fields to be the following
  246. opaque type:
  247. .DS
  248. .ft CW
  249. .vs 11
  250. enum auth_flavor {
  251.     AUTH_NULL        = 0,
  252.     AUTH_UNIX        = 1,
  253.     AUTH_SHORT       = 2,
  254.     /* \fIand more to be defined\fP */
  255. };
  256.  
  257. struct opaque_auth {
  258.     auth_flavor flavor;
  259.     opaque body<400>;
  260. };
  261. .DE
  262. .LP
  263. In simple English, any
  264. .I opaque_auth 
  265. structure is an 
  266. .I auth_flavor 
  267. enumeration followed by bytes which are  opaque to the RPC protocol
  268. implementation.
  269. .LP
  270. The interpretation and semantics  of the data contained  within the
  271. authentication   fields  is specified  by  individual,  independent
  272. authentication  protocol specifications.   (See 
  273. \fIAuthentication Protocols\fP\,
  274. below, for definitions of the various authentication protocols.)
  275. .LP
  276. If authentication parameters were   rejected, the  response message
  277. contains information stating why they were rejected.
  278. .NH 2
  279. \&Program Number Assignment
  280. .LP
  281. Program numbers are given out in groups of
  282. .I 0x20000000 
  283. (decimal 536870912) according to the following chart:
  284. .TS
  285. box tab (&) ;
  286. lfI lfI
  287. rfL cfI .
  288. Program Numbers&Description
  289. _
  290. .sp .5
  291. 0 - 1fffffff&Defined by Sun
  292. 20000000 - 3fffffff&Defined by user
  293. 40000000 - 5fffffff&Transient
  294. 60000000 - 7fffffff&Reserved
  295. 80000000 - 9fffffff&Reserved
  296. a0000000 - bfffffff&Reserved
  297. c0000000 - dfffffff&Reserved
  298. e0000000 - ffffffff&Reserved
  299. .TE
  300. .LP
  301. The first group is a range of numbers administered by Sun
  302. Microsystems and should be identical for all sites.  The second range
  303. is for applications peculiar to a particular site.  This range is
  304. intended primarily for debugging new programs.  When a site develops
  305. an application that might be of general interest, that application
  306. should be given an assigned number in the first range.  The third
  307. group is for applications that generate program numbers dynamically.
  308. The final groups are reserved for future use, and should not be used.
  309. .NH 2
  310. \&Other Uses of the RPC Protocol
  311. .LP
  312. The intended use of this protocol is for calling remote procedures.
  313. That is, each call message is matched with a response message.
  314. However, the protocol itself is a message-passing protocol with which
  315. other (non-RPC) protocols can be implemented.  Sun currently uses, or
  316. perhaps abuses, the RPC message protocol for the following two
  317. (non-RPC) protocols:  batching (or pipelining) and broadcast RPC.
  318. These two protocols are discussed but not defined below.
  319. .NH 3
  320. \&Batching
  321. .LP
  322. Batching allows a client to send an arbitrarily large sequence of
  323. call messages to a server; batching typically uses reliable byte
  324. stream protocols (like TCP/IP) for its transport.  In the case of
  325. batching, the client never waits for a reply from the server, and the
  326. server does not send replies to batch requests.  A sequence of batch
  327. calls is usually terminated by a legitimate RPC in order to flush the
  328. pipeline (with positive acknowledgement).
  329. .NH 3
  330. \&Broadcast RPC
  331. .LP
  332. In broadcast RPC-based protocols, the client sends a broadcast packet
  333. to the network and waits for numerous replies.  Broadcast RPC uses
  334. unreliable, packet-based protocols (like UDP/IP) as its transports.
  335. Servers that support broadcast protocols only respond when the
  336. request is successfully processed, and are silent in the face of
  337. errors.  Broadcast RPC uses the Port Mapper RPC service to achieve
  338. its semantics.  See the \fIPort Mapper Program Protocol\fP\, below,
  339. for more information.
  340. .KS
  341. .NH 1
  342. \&The RPC Message Protocol
  343. .LP
  344. This section defines the RPC message protocol in the XDR data
  345. description language.  The message is defined in a top-down style.
  346. .ie t .DS
  347. .el .DS L
  348. .ft CW
  349. enum msg_type {
  350.     CALL  = 0,
  351.     REPLY = 1
  352. };
  353.  
  354. .ft I
  355. /*
  356. * A reply to a call message can take on two forms:
  357. * The message was either accepted or rejected.
  358. */
  359. .ft CW
  360. enum reply_stat {
  361.     MSG_ACCEPTED = 0,
  362.     MSG_DENIED   = 1
  363. };
  364.  
  365. .ft I
  366. /*
  367. * Given that a call message was accepted,  the following is the
  368. * status of an attempt to call a remote procedure.
  369. */
  370. .ft CW
  371. enum accept_stat {
  372.     SUCCESS       = 0, /* \fIRPC executed successfully       \fP*/
  373.     PROG_UNAVAIL  = 1, /* \fIremote hasn't exported program  \fP*/
  374.     PROG_MISMATCH = 2, /* \fIremote can't support version #  \fP*/
  375.     PROC_UNAVAIL  = 3, /* \fIprogram can't support procedure \fP*/
  376.     GARBAGE_ARGS  = 4  /* \fIprocedure can't decode params   \fP*/
  377. };
  378. .DE
  379. .ie t .DS
  380. .el .DS L
  381. .ft I
  382. /*
  383. * Reasons why a call message was rejected:
  384. */
  385. .ft CW
  386. enum reject_stat {
  387.     RPC_MISMATCH = 0, /* \fIRPC version number != 2          \fP*/
  388.     AUTH_ERROR = 1    /* \fIremote can't authenticate caller \fP*/
  389. };
  390.  
  391. .ft I
  392. /*
  393. * Why authentication failed:
  394. */
  395. .ft CW
  396. enum auth_stat {
  397.     AUTH_BADCRED      = 1,  /* \fIbad credentials (seal broken) \fP*/
  398.     AUTH_REJECTEDCRED = 2,  /* \fIclient must begin new session \fP*/
  399.     AUTH_BADVERF      = 3,  /* \fIbad verifier (seal broken)    \fP*/
  400.     AUTH_REJECTEDVERF = 4,  /* \fIverifier expired or replayed  \fP*/
  401.     AUTH_TOOWEAK      = 5   /* \fIrejected for security reasons \fP*/
  402. };
  403. .DE
  404. .KE
  405. .ie t .DS
  406. .el .DS L
  407. .ft I
  408. /*
  409. * The  RPC  message: 
  410. * All   messages  start with   a transaction  identifier,  xid,
  411. * followed  by a  two-armed  discriminated union.   The union's
  412. * discriminant is a  msg_type which switches to  one of the two
  413. * types   of the message.   The xid  of a \fIREPLY\fP  message always
  414. * matches  that of the initiating \fICALL\fP   message.   NB: The xid
  415. * field is only  used for clients  matching reply messages with
  416. * call messages  or for servers detecting  retransmissions; the
  417. * service side  cannot treat this id  as any type   of sequence
  418. * number.
  419. */
  420. .ft CW
  421. struct rpc_msg {
  422.     unsigned int xid;
  423.     union switch (msg_type mtype) {
  424.         case CALL:
  425.             call_body cbody;
  426.         case REPLY:  
  427.             reply_body rbody;
  428.     } body;
  429. };
  430. .DE
  431. .ie t .DS
  432. .el .DS L
  433. .ft I
  434. /*
  435. * Body of an RPC request call: 
  436. * In version 2 of the  RPC protocol specification, rpcvers must
  437. * be equal to 2.  The  fields prog,  vers, and proc specify the
  438. * remote program, its version number, and the  procedure within
  439. * the remote program to be called.  After these  fields are two
  440. * authentication  parameters: cred (authentication credentials)
  441. * and verf  (authentication verifier).  The  two authentication
  442. * parameters are   followed by  the  parameters  to  the remote
  443. * procedure,  which  are specified  by  the  specific   program
  444. * protocol.
  445. */
  446. .ft CW
  447. struct call_body {
  448.     unsigned int rpcvers;  /* \fImust be equal to two (2) \fP*/
  449.     unsigned int prog;
  450.     unsigned int vers;
  451.     unsigned int proc;
  452.     opaque_auth cred;
  453.     opaque_auth verf;
  454.     /* \fIprocedure specific parameters start here \fP*/
  455. };
  456. .DE
  457. .ie t .DS
  458. .el .DS L
  459. .ft I
  460. /*
  461. * Body of a reply to an RPC request:
  462. * The call message was either accepted or rejected.
  463. */
  464. .ft CW
  465. union reply_body switch (reply_stat stat) {
  466.     case MSG_ACCEPTED:  
  467.         accepted_reply areply;
  468.     case MSG_DENIED:  
  469.         rejected_reply rreply;
  470. } reply;
  471. .DE
  472. .ie t .DS
  473. .el .DS L
  474. .ft I
  475. /*
  476. * Reply to   an RPC request  that  was accepted  by the server:
  477. * there could be an error even though the request was accepted.
  478. * The first field is an authentication verifier that the server
  479. * generates in order to  validate itself  to the caller.  It is
  480. * followed by    a  union whose     discriminant  is   an  enum
  481. * accept_stat.  The  \fISUCCESS\fP  arm of    the union  is  protocol
  482. * specific.  The \fIPROG_UNAVAIL\fP, \fIPROC_UNAVAIL\fP, and \fIGARBAGE_ARGP\fP
  483. * arms of the union are void.   The \fIPROG_MISMATCH\fP arm specifies
  484. * the lowest and highest version numbers of the  remote program
  485. * supported by the server.
  486. */
  487. .ft CW
  488. struct accepted_reply {
  489.     opaque_auth verf;
  490.     union switch (accept_stat stat) {
  491.         case SUCCESS:
  492.             opaque results[0];
  493.             /* \fIprocedure-specific results start here\fP */
  494.         case PROG_MISMATCH:
  495.             struct {
  496.                 unsigned int low;
  497.                 unsigned int high;
  498.             } mismatch_info;
  499.         default:
  500. .ft I
  501.             /*
  502.             * Void.  Cases include \fIPROG_UNAVAIL, PROC_UNAVAIL\fP,
  503.             * and \fIGARBAGE_ARGS\fP.
  504.             */
  505. .ft CW
  506.             void;
  507.     } reply_data;
  508. };
  509. .DE
  510. .ie t .DS
  511. .el .DS L
  512. .ft I
  513. /*
  514. * Reply to an RPC request that was rejected by the server: 
  515. * The request  can   be rejected for   two reasons:  either the
  516. * server   is not  running a   compatible  version  of the  RPC
  517. * protocol    (\fIRPC_MISMATCH\fP), or    the  server   refuses    to
  518. * authenticate the  caller  (\fIAUTH_ERROR\fP).  In  case of  an  RPC
  519. * version mismatch,  the server returns the  lowest and highest
  520. * supported    RPC  version    numbers.  In   case   of refused
  521. * authentication, failure status is returned.
  522. */
  523. .ft CW
  524. union rejected_reply switch (reject_stat stat) {
  525.     case RPC_MISMATCH:
  526.         struct {
  527.             unsigned int low;
  528.             unsigned int high;
  529.         } mismatch_info;
  530.     case AUTH_ERROR: 
  531.         auth_stat stat;
  532. };
  533. .DE
  534. .NH 1
  535. \&Authentication Protocols
  536. .LP
  537. As previously stated, authentication parameters are opaque, but
  538. open-ended to the rest of the RPC protocol.  This section defines
  539. some "flavors" of authentication implemented at (and supported by)
  540. Sun.  Other sites are free to invent new authentication types, with
  541. the same rules of flavor number assignment as there is for program
  542. number assignment.
  543. .NH 2
  544. \&Null Authentication
  545. .LP
  546. Often calls must be made where the caller does not know who he is or
  547. the server does not care who the caller is.  In this case, the flavor
  548. value (the discriminant of the \fIopaque_auth\fP's union) of the RPC
  549. message's credentials, verifier, and response verifier is
  550. .I AUTH_NULL .
  551. The  bytes of the opaque_auth's body  are undefined.
  552. It is recommended that the opaque length be zero.
  553. .NH 2
  554. \&UNIX Authentication
  555. .LP
  556. The caller of a remote procedure may wish to identify himself as he
  557. is identified on a UNIX system.  The  value of the credential's
  558. discriminant of an RPC call  message is  
  559. .I AUTH_UNIX .
  560. the credential's opaque body encode the the following structure:
  561. .DS
  562. .ft CW
  563. struct auth_unix {
  564.     unsigned int stamp;
  565.     string machinename<255>;
  566.     unsigned int uid;
  567.     unsigned int gid;
  568.     unsigned int gids<10>;
  569. };
  570. .DE
  571. The 
  572. .I stamp 
  573. is an  arbitrary    ID which the  caller machine   may
  574. generate.  The 
  575. .I machinename 
  576. is the  name of the  caller's machine (like  "krypton").  The 
  577. .I uid 
  578. is  the caller's effective user  ID.  The  
  579. .I gid 
  580. is  the caller's effective  group  ID.  The 
  581. .I gids 
  582. is  a
  583. counted array of groups which contain the caller as  a member.  The
  584. verifier accompanying the  credentials  should  be  of  
  585. .I AUTH_NULL
  586. (defined above).
  587. .LP
  588. The value of the discriminant of  the response verifier received in
  589. the  reply  message  from  the    server  may   be   
  590. .I AUTH_NULL 
  591. or
  592. .I AUTH_SHORT .
  593. In  the  case  of 
  594. .I AUTH_SHORT ,
  595. the bytes of the response verifier's string encode an opaque
  596. structure.  This new opaque structure may now be passed to the server
  597. instead of the original
  598. .I AUTH_UNIX
  599. flavor credentials.  The server keeps a cache which maps shorthand
  600. opaque structures (passed back by way of an
  601. .I AUTH_SHORT
  602. style response verifier) to the original credentials of the caller.
  603. The caller can save network bandwidth and server cpu cycles by using
  604. the new credentials.
  605. .LP
  606. The server may flush the shorthand opaque structure at any time.  If
  607. this happens, the remote procedure call message will be rejected due
  608. to an authentication error.  The reason for the failure will be
  609. .I AUTH_REJECTEDCRED .
  610. At this point, the caller may wish to try the original
  611. .I AUTH_UNIX
  612. style of credentials.
  613. .KS
  614. .NH 1
  615. \&Record Marking Standard
  616. .LP
  617. When RPC messages are passed on top of a byte stream protocol (like
  618. TCP/IP), it is necessary, or at least desirable, to delimit one
  619. message from another in order to detect and possibly recover from
  620. user protocol errors.  This is called record marking (RM).  Sun uses
  621. this RM/TCP/IP transport for passing RPC messages on TCP streams.
  622. One RPC message fits into one RM record.
  623. .LP
  624. A record is composed of one or more record fragments.  A record
  625. fragment is a four-byte header followed by 0 to (2**31) - 1 bytes of
  626. fragment data.  The bytes encode an unsigned binary number; as with
  627. DR integers, the byte order is from highest to lowest.  The number
  628. encodes two values\(ema boolean which indicates whether the fragment
  629. is the last fragment of the record (bit value 1 implies the fragment
  630. is the last fragment) and a 31-bit unsigned binary value which is the
  631. length in bytes of the fragment's data.  The boolean value is the
  632. highest-order bit of the header; the length is the 31 low-order bits.
  633. (Note that this record specification is NOT in XDR standard form!)
  634. .KE
  635. .KS
  636. .NH 1
  637. \&The RPC Language
  638. .LP
  639. Just as there was a need to describe the XDR data-types in a formal
  640. language, there is also need to describe the procedures that operate
  641. on these XDR data-types in a formal language as well.  We use the RPC
  642. Language for this purpose.  It is an extension to the XDR language.
  643. The following example is used to describe the essence of the
  644. language.
  645. .NH 2
  646. \&An Example Service Described in the RPC Language
  647. .LP
  648. Here is an example of the specification of a simple ping program.
  649. .ie t .DS
  650. .el .DS L
  651. .vs 11
  652. .ft I
  653. /*
  654. * Simple ping program
  655. */
  656. .ft CW
  657. program PING_PROG {
  658.     /* \fILatest and greatest version\fP */
  659.     version PING_VERS_PINGBACK {
  660.     void 
  661.     PINGPROC_NULL(void) = 0;
  662.  
  663. .ft I
  664.     /*
  665.     * Ping the caller, return the round-trip time
  666.     * (in microseconds). Returns -1 if the operation
  667.     * timed out.
  668.     */
  669. .ft CW
  670.     int
  671.     PINGPROC_PINGBACK(void) = 1;        
  672. } = 2;     
  673.  
  674. .ft I
  675. /*
  676. * Original version
  677. */
  678. .ft CW
  679. version PING_VERS_ORIG {
  680.     void 
  681.     PINGPROC_NULL(void) = 0;
  682.     } = 1;
  683. } = 1;
  684.  
  685. const PING_VERS = 2;      /* \fIlatest version \fP*/
  686. .vs
  687. .DE
  688. .KE
  689. .LP
  690. The first version described is
  691. .I PING_VERS_PINGBACK
  692. with  two procedures,   
  693. .I PINGPROC_NULL 
  694. and 
  695. .I PINGPROC_PINGBACK.
  696. .I PINGPROC_NULL 
  697. takes no arguments and returns no results, but it is useful for
  698. computing round-trip times from the client to the server and back
  699. again.  By convention, procedure 0 of any RPC protocol should have
  700. the same semantics, and never require any kind of authentication.
  701. The second procedure is used for the client to have the server do a
  702. reverse ping operation back to the client, and it returns the amount
  703. of time (in microseconds) that the operation used.  The next version,
  704. .I PING_VERS_ORIG ,
  705. is the original version of the protocol
  706. and it does not contain
  707. .I PINGPROC_PINGBACK
  708. procedure. It  is useful
  709. for compatibility  with old client  programs,  and as  this program
  710. matures it may be dropped from the protocol entirely.
  711. .KS
  712. .NH 2
  713. \&The RPC Language Specification
  714. .LP
  715. The  RPC language is identical to  the XDR language, except for the
  716. added definition of a
  717. .I program-def 
  718. described below.
  719. .DS
  720. .ft CW
  721. program-def:
  722.     "program" identifier "{"
  723.         version-def 
  724.         version-def *
  725.     "}" "=" constant ";"
  726.  
  727. version-def:
  728.     "version" identifier "{"
  729.         procedure-def
  730.         procedure-def *
  731.     "}" "=" constant ";"
  732.  
  733. procedure-def:
  734.     type-specifier identifier "(" type-specifier ")"
  735.     "=" constant ";"
  736. .DE
  737. .KE
  738. .NH 2
  739. \&Syntax Notes
  740. .IP  1.
  741. The following keywords  are  added  and   cannot  be used   as
  742. identifiers: "program" and "version";
  743. .IP  2.
  744. A version name cannot occur more than once within the  scope of
  745. a program definition. Nor can a version number occur more than once
  746. within the scope of a program definition.
  747. .IP  3.
  748. A procedure name cannot occur  more than once within  the scope
  749. of a version definition. Nor can a procedure number occur more than
  750. once within the scope of version definition.
  751. .IP  4.
  752. Program identifiers are in the same name space as  constant and
  753. type identifiers.
  754. .IP  5.
  755. Only unsigned constants can  be assigned to programs, versions
  756. and procedures.
  757. .NH 1
  758. \&Port Mapper Program Protocol
  759. .LP
  760. The port mapper program maps RPC program and version numbers to
  761. transport-specific port numbers.  This program makes dynamic binding
  762. of remote programs possible.
  763. .LP
  764. This is desirable because the range of reserved port numbers is very
  765. small and the number of potential remote programs is very large.  By
  766. running only the port mapper on a reserved port, the port numbers of
  767. other remote programs can be ascertained by querying the port mapper.
  768. .LP
  769. The port mapper also aids in broadcast RPC.  A given RPC program will
  770. usually have different port number bindings on different machines, so
  771. there is no way to directly broadcast to all of these programs.  The
  772. port mapper, however, does have a fixed port number.  So, to
  773. broadcast to a given program, the client actually sends its message
  774. to the port mapper located at the broadcast address.  Each port
  775. mapper that picks up the broadcast then calls the local service
  776. specified by the client.  When the port mapper gets the reply from
  777. the local service, it sends the reply on back to the client.
  778. .KS
  779. .NH 2
  780. \&Port Mapper Protocol Specification (in RPC Language)
  781. .ie t .DS
  782. .el .DS L
  783. .ft CW
  784. .vs 11
  785. const PMAP_PORT = 111;      /* \fIportmapper port number \fP*/
  786.  
  787. .ft I
  788. /*
  789. * A mapping of (program, version, protocol) to port number
  790. */
  791. .ft CW
  792. struct mapping {
  793.     unsigned int prog;
  794.     unsigned int vers;
  795.     unsigned int prot;
  796.     unsigned int port;
  797. };
  798.  
  799. .ft I
  800. /* 
  801. * Supported values for the "prot" field
  802. */
  803. .ft CW
  804. const IPPROTO_TCP = 6;      /* \fIprotocol number for TCP/IP \fP*/
  805. const IPPROTO_UDP = 17;     /* \fIprotocol number for UDP/IP \fP*/
  806.  
  807. .ft I
  808. /*
  809. * A list of mappings
  810. */
  811. .ft CW
  812. struct *pmaplist {
  813.     mapping map;
  814.     pmaplist next;
  815. };
  816. .vs
  817. .DE
  818. .ie t .DS
  819. .el .DS L
  820. .vs 11
  821. .ft I
  822. /*
  823. * Arguments to callit
  824. */
  825. .ft CW
  826. struct call_args {
  827.     unsigned int prog;
  828.     unsigned int vers;
  829.     unsigned int proc;
  830.     opaque args<>;
  831. };  
  832.  
  833. .ft I
  834. /*
  835. * Results of callit
  836. */
  837. .ft CW
  838. struct call_result {
  839.     unsigned int port;
  840.     opaque res<>;
  841. };
  842. .vs
  843. .DE
  844. .KE
  845. .ie t .DS
  846. .el .DS L
  847. .vs 11
  848. .ft I
  849. /*
  850. * Port mapper procedures
  851. */
  852. .ft CW
  853. program PMAP_PROG {
  854.     version PMAP_VERS {
  855.         void 
  856.         PMAPPROC_NULL(void)         = 0;
  857.  
  858.         bool
  859.         PMAPPROC_SET(mapping)       = 1;
  860.  
  861.         bool
  862.         PMAPPROC_UNSET(mapping)     = 2;
  863.  
  864.         unsigned int
  865.         PMAPPROC_GETPORT(mapping)   = 3;
  866.  
  867.         pmaplist
  868.         PMAPPROC_DUMP(void)         = 4;
  869.  
  870.         call_result
  871.         PMAPPROC_CALLIT(call_args)  = 5;
  872.     } = 2;
  873. } = 100000;
  874. .vs
  875. .DE
  876. .NH 2
  877. \&Port Mapper Operation
  878. .LP
  879. The portmapper program currently supports two protocols (UDP/IP and
  880. TCP/IP).  The portmapper is contacted by talking to it on assigned
  881. port number 111 (SUNRPC [8]) on either of these protocols.  The
  882. following is a description of each of the portmapper procedures:
  883. .IP \fBPMAPPROC_NULL:\fP
  884. This procedure does no work.  By convention, procedure zero of any
  885. protocol takes no parameters and returns no results.
  886. .IP \fBPMAPPROC_SET:\fP
  887. When a program first becomes available on a machine, it registers
  888. itself with the port mapper program on the same machine.  The program
  889. passes its program number "prog", version number "vers", transport
  890. protocol number "prot", and the port "port" on which it awaits
  891. service request.  The procedure returns a boolean response whose
  892. value is
  893. .I TRUE
  894. if the procedure successfully established the mapping and 
  895. .I FALSE 
  896. otherwise.  The procedure refuses to establish
  897. a mapping if one already exists for the tuple "(prog, vers, prot)".
  898. .IP \fBPMAPPROC_UNSET:\fP
  899. When a program becomes unavailable, it should unregister itself with
  900. the port mapper program on the same machine.  The parameters and
  901. results have meanings identical to those of
  902. .I PMAPPROC_SET .
  903. The protocol and port number fields of the argument are ignored.
  904. .IP \fBPMAPPROC_GETPORT:\fP
  905. Given a program number "prog", version number "vers", and transport
  906. protocol number "prot", this procedure returns the port number on
  907. which the program is awaiting call requests.  A port value of zeros
  908. means the program has not been registered.  The "port" field of the
  909. argument is ignored.
  910. .IP \fBPMAPPROC_DUMP:\fP
  911. This procedure enumerates all entries in the port mapper's database.
  912. The procedure takes no parameters and returns a list of program,
  913. version, protocol, and port values.
  914. .IP \fBPMAPPROC_CALLIT:\fP
  915. This procedure allows a caller to call another remote procedure on
  916. the same machine without knowing the remote procedure's port number.
  917. It is intended for supporting broadcasts to arbitrary remote programs
  918. via the well-known port mapper's port.  The parameters "prog",
  919. "vers", "proc", and the bytes of "args" are the program number,
  920. version number, procedure number, and parameters of the remote
  921. procedure.
  922. .LP
  923. .B Note:
  924. .RS
  925. .IP  1.
  926. This procedure only sends a response if the procedure was
  927. successfully executed and is silent (no response) otherwise.
  928. .IP  2.
  929. The port mapper communicates with the remote program using UDP/IP
  930. only.
  931. .RE
  932. .LP
  933. The procedure returns the remote program's port number, and the bytes
  934. of results are the results of the remote procedure.
  935. .bp
  936. .NH 1
  937. \&References
  938. .LP
  939. [1]  Birrell, Andrew D. & Nelson, Bruce Jay; "Implementing Remote
  940. Procedure Calls"; XEROX CSL-83-7, October 1983.
  941. .LP
  942. [2]  Cheriton, D.; "VMTP:  Versatile Message Transaction Protocol",
  943. Preliminary Version 0.3; Stanford University, January 1987.
  944. .LP
  945. [3]  Diffie & Hellman; "Net Directions in Cryptography"; IEEE
  946. Transactions on Information Theory IT-22, November 1976.
  947. .LP
  948. [4]  Harrenstien, K.; "Time Server", RFC 738; Information Sciences
  949. Institute, October 1977.
  950. .LP
  951. [5]  National Bureau of Standards; "Data Encryption Standard"; Federal
  952. Information Processing Standards Publication 46, January 1977.
  953. .LP
  954. [6]  Postel, J.; "Transmission Control Protocol - DARPA Internet
  955. Program Protocol Specification", RFC 793; Information Sciences
  956. Institute, September 1981.
  957. .LP
  958. [7]  Postel, J.; "User Datagram Protocol", RFC 768; Information Sciences
  959. Institute, August 1980.
  960. .LP
  961. [8]  Reynolds, J.  & Postel, J.; "Assigned Numbers", RFC 923; Information
  962. Sciences Institute, October 1984.
  963.