clnt.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * linux/include/linux/sunrpc/clnt.h
  3. *
  4. * Declarations for the high-level RPC client interface
  5. *
  6. * Copyright (C) 1995, 1996, Olaf Kirch <okir@monad.swb.de>
  7. */
  8. #ifndef _LINUX_SUNRPC_CLNT_H
  9. #define _LINUX_SUNRPC_CLNT_H
  10. #include <linux/socket.h>
  11. #include <linux/in.h>
  12. #include <linux/in6.h>
  13. #include <linux/sunrpc/msg_prot.h>
  14. #include <linux/sunrpc/sched.h>
  15. #include <linux/sunrpc/xprt.h>
  16. #include <linux/sunrpc/auth.h>
  17. #include <linux/sunrpc/stats.h>
  18. #include <linux/sunrpc/xdr.h>
  19. #include <linux/sunrpc/timer.h>
  20. #include <asm/signal.h>
  21. #include <linux/path.h>
  22. struct rpc_inode;
  23. /*
  24. * The high-level client handle
  25. */
  26. struct rpc_clnt {
  27. struct kref cl_kref; /* Number of references */
  28. struct list_head cl_clients; /* Global list of clients */
  29. struct list_head cl_tasks; /* List of tasks */
  30. spinlock_t cl_lock; /* spinlock */
  31. struct rpc_xprt * cl_xprt; /* transport */
  32. struct rpc_procinfo * cl_procinfo; /* procedure info */
  33. u32 cl_prog, /* RPC program number */
  34. cl_vers, /* RPC version number */
  35. cl_maxproc; /* max procedure number */
  36. char * cl_server; /* server machine name */
  37. char * cl_protname; /* protocol name */
  38. struct rpc_auth * cl_auth; /* authenticator */
  39. struct rpc_stat * cl_stats; /* per-program statistics */
  40. struct rpc_iostats * cl_metrics; /* per-client statistics */
  41. unsigned int cl_softrtry : 1,/* soft timeouts */
  42. cl_discrtry : 1,/* disconnect before retry */
  43. cl_autobind : 1,/* use getport() */
  44. cl_chatty : 1;/* be verbose */
  45. struct rpc_rtt * cl_rtt; /* RTO estimator data */
  46. const struct rpc_timeout *cl_timeout; /* Timeout strategy */
  47. int cl_nodelen; /* nodename length */
  48. char cl_nodename[UNX_MAXNODENAME];
  49. struct path cl_path;
  50. struct rpc_clnt * cl_parent; /* Points to parent of clones */
  51. struct rpc_rtt cl_rtt_default;
  52. struct rpc_timeout cl_timeout_default;
  53. struct rpc_program * cl_program;
  54. char cl_inline_name[32];
  55. char *cl_principal; /* target to authenticate to */
  56. };
  57. /*
  58. * General RPC program info
  59. */
  60. #define RPC_MAXVERSION 4
  61. struct rpc_program {
  62. char * name; /* protocol name */
  63. u32 number; /* program number */
  64. unsigned int nrvers; /* number of versions */
  65. struct rpc_version ** version; /* version array */
  66. struct rpc_stat * stats; /* statistics */
  67. char * pipe_dir_name; /* path to rpc_pipefs dir */
  68. };
  69. struct rpc_version {
  70. u32 number; /* version number */
  71. unsigned int nrprocs; /* number of procs */
  72. struct rpc_procinfo * procs; /* procedure array */
  73. };
  74. /*
  75. * Procedure information
  76. */
  77. struct rpc_procinfo {
  78. u32 p_proc; /* RPC procedure number */
  79. kxdrproc_t p_encode; /* XDR encode function */
  80. kxdrproc_t p_decode; /* XDR decode function */
  81. unsigned int p_arglen; /* argument hdr length (u32) */
  82. unsigned int p_replen; /* reply hdr length (u32) */
  83. unsigned int p_count; /* call count */
  84. unsigned int p_timer; /* Which RTT timer to use */
  85. u32 p_statidx; /* Which procedure to account */
  86. char * p_name; /* name of procedure */
  87. };
  88. #ifdef __KERNEL__
  89. struct rpc_create_args {
  90. int protocol;
  91. struct sockaddr *address;
  92. size_t addrsize;
  93. struct sockaddr *saddress;
  94. const struct rpc_timeout *timeout;
  95. char *servername;
  96. struct rpc_program *program;
  97. u32 prognumber; /* overrides program->number */
  98. u32 version;
  99. rpc_authflavor_t authflavor;
  100. unsigned long flags;
  101. char *client_name;
  102. };
  103. /* Values for "flags" field */
  104. #define RPC_CLNT_CREATE_HARDRTRY (1UL << 0)
  105. #define RPC_CLNT_CREATE_AUTOBIND (1UL << 2)
  106. #define RPC_CLNT_CREATE_NONPRIVPORT (1UL << 3)
  107. #define RPC_CLNT_CREATE_NOPING (1UL << 4)
  108. #define RPC_CLNT_CREATE_DISCRTRY (1UL << 5)
  109. #define RPC_CLNT_CREATE_QUIET (1UL << 6)
  110. struct rpc_clnt *rpc_create(struct rpc_create_args *args);
  111. struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *,
  112. struct rpc_program *, u32);
  113. struct rpc_clnt *rpc_clone_client(struct rpc_clnt *);
  114. void rpc_shutdown_client(struct rpc_clnt *);
  115. void rpc_release_client(struct rpc_clnt *);
  116. int rpcb_register(u32, u32, int, unsigned short);
  117. int rpcb_v4_register(const u32 program, const u32 version,
  118. const struct sockaddr *address,
  119. const char *netid);
  120. int rpcb_getport_sync(struct sockaddr_in *, u32, u32, int);
  121. void rpcb_getport_async(struct rpc_task *);
  122. void rpc_call_start(struct rpc_task *);
  123. int rpc_call_async(struct rpc_clnt *clnt,
  124. const struct rpc_message *msg, int flags,
  125. const struct rpc_call_ops *tk_ops,
  126. void *calldata);
  127. int rpc_call_sync(struct rpc_clnt *clnt,
  128. const struct rpc_message *msg, int flags);
  129. struct rpc_task *rpc_call_null(struct rpc_clnt *clnt, struct rpc_cred *cred,
  130. int flags);
  131. void rpc_restart_call_prepare(struct rpc_task *);
  132. void rpc_restart_call(struct rpc_task *);
  133. void rpc_setbufsize(struct rpc_clnt *, unsigned int, unsigned int);
  134. size_t rpc_max_payload(struct rpc_clnt *);
  135. void rpc_force_rebind(struct rpc_clnt *);
  136. size_t rpc_peeraddr(struct rpc_clnt *, struct sockaddr *, size_t);
  137. const char *rpc_peeraddr2str(struct rpc_clnt *, enum rpc_display_format_t);
  138. size_t rpc_ntop(const struct sockaddr *, char *, const size_t);
  139. size_t rpc_pton(const char *, const size_t,
  140. struct sockaddr *, const size_t);
  141. char * rpc_sockaddr2uaddr(const struct sockaddr *);
  142. size_t rpc_uaddr2sockaddr(const char *, const size_t,
  143. struct sockaddr *, const size_t);
  144. static inline unsigned short rpc_get_port(const struct sockaddr *sap)
  145. {
  146. switch (sap->sa_family) {
  147. case AF_INET:
  148. return ntohs(((struct sockaddr_in *)sap)->sin_port);
  149. case AF_INET6:
  150. return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
  151. }
  152. return 0;
  153. }
  154. static inline void rpc_set_port(struct sockaddr *sap,
  155. const unsigned short port)
  156. {
  157. switch (sap->sa_family) {
  158. case AF_INET:
  159. ((struct sockaddr_in *)sap)->sin_port = htons(port);
  160. break;
  161. case AF_INET6:
  162. ((struct sockaddr_in6 *)sap)->sin6_port = htons(port);
  163. break;
  164. }
  165. }
  166. #define IPV6_SCOPE_DELIMITER '%'
  167. #define IPV6_SCOPE_ID_LEN sizeof("%nnnnnnnnnn")
  168. #endif /* __KERNEL__ */
  169. #endif /* _LINUX_SUNRPC_CLNT_H */