svc_xprt.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * linux/include/linux/sunrpc/svc_xprt.h
  3. *
  4. * RPC server transport I/O
  5. */
  6. #ifndef SUNRPC_SVC_XPRT_H
  7. #define SUNRPC_SVC_XPRT_H
  8. #include <linux/sunrpc/svc.h>
  9. struct module;
  10. struct svc_xprt_ops {
  11. struct svc_xprt *(*xpo_create)(struct svc_serv *,
  12. struct net *net,
  13. struct sockaddr *, int,
  14. int);
  15. struct svc_xprt *(*xpo_accept)(struct svc_xprt *);
  16. int (*xpo_has_wspace)(struct svc_xprt *);
  17. int (*xpo_recvfrom)(struct svc_rqst *);
  18. void (*xpo_prep_reply_hdr)(struct svc_rqst *);
  19. int (*xpo_sendto)(struct svc_rqst *);
  20. void (*xpo_release_rqst)(struct svc_rqst *);
  21. void (*xpo_detach)(struct svc_xprt *);
  22. void (*xpo_free)(struct svc_xprt *);
  23. int (*xpo_secure_port)(struct svc_rqst *);
  24. void (*xpo_adjust_wspace)(struct svc_xprt *);
  25. };
  26. struct svc_xprt_class {
  27. const char *xcl_name;
  28. struct module *xcl_owner;
  29. struct svc_xprt_ops *xcl_ops;
  30. struct list_head xcl_list;
  31. u32 xcl_max_payload;
  32. int xcl_ident;
  33. };
  34. /*
  35. * This is embedded in an object that wants a callback before deleting
  36. * an xprt; intended for use by NFSv4.1, which needs to know when a
  37. * client's tcp connection (and hence possibly a backchannel) goes away.
  38. */
  39. struct svc_xpt_user {
  40. struct list_head list;
  41. void (*callback)(struct svc_xpt_user *);
  42. };
  43. struct svc_xprt {
  44. struct svc_xprt_class *xpt_class;
  45. struct svc_xprt_ops *xpt_ops;
  46. struct kref xpt_ref;
  47. struct list_head xpt_list;
  48. struct list_head xpt_ready;
  49. unsigned long xpt_flags;
  50. #define XPT_BUSY 0 /* enqueued/receiving */
  51. #define XPT_CONN 1 /* conn pending */
  52. #define XPT_CLOSE 2 /* dead or dying */
  53. #define XPT_DATA 3 /* data pending */
  54. #define XPT_TEMP 4 /* connected transport */
  55. #define XPT_DEAD 6 /* transport closed */
  56. #define XPT_CHNGBUF 7 /* need to change snd/rcv buf sizes */
  57. #define XPT_DEFERRED 8 /* deferred request pending */
  58. #define XPT_OLD 9 /* used for xprt aging mark+sweep */
  59. #define XPT_LISTENER 10 /* listening endpoint */
  60. #define XPT_CACHE_AUTH 11 /* cache auth info */
  61. #define XPT_LOCAL 12 /* connection from loopback interface */
  62. struct svc_serv *xpt_server; /* service for transport */
  63. atomic_t xpt_reserved; /* space on outq that is rsvd */
  64. struct mutex xpt_mutex; /* to serialize sending data */
  65. spinlock_t xpt_lock; /* protects sk_deferred
  66. * and xpt_auth_cache */
  67. void *xpt_auth_cache;/* auth cache */
  68. struct list_head xpt_deferred; /* deferred requests that need
  69. * to be revisted */
  70. struct sockaddr_storage xpt_local; /* local address */
  71. size_t xpt_locallen; /* length of address */
  72. struct sockaddr_storage xpt_remote; /* remote peer's address */
  73. size_t xpt_remotelen; /* length of address */
  74. struct rpc_wait_queue xpt_bc_pending; /* backchannel wait queue */
  75. struct list_head xpt_users; /* callbacks on free */
  76. struct net *xpt_net;
  77. struct rpc_xprt *xpt_bc_xprt; /* NFSv4.1 backchannel */
  78. };
  79. static inline void unregister_xpt_user(struct svc_xprt *xpt, struct svc_xpt_user *u)
  80. {
  81. spin_lock(&xpt->xpt_lock);
  82. list_del_init(&u->list);
  83. spin_unlock(&xpt->xpt_lock);
  84. }
  85. static inline int register_xpt_user(struct svc_xprt *xpt, struct svc_xpt_user *u)
  86. {
  87. spin_lock(&xpt->xpt_lock);
  88. if (test_bit(XPT_CLOSE, &xpt->xpt_flags)) {
  89. /*
  90. * The connection is about to be deleted soon (or,
  91. * worse, may already be deleted--in which case we've
  92. * already notified the xpt_users).
  93. */
  94. spin_unlock(&xpt->xpt_lock);
  95. return -ENOTCONN;
  96. }
  97. list_add(&u->list, &xpt->xpt_users);
  98. spin_unlock(&xpt->xpt_lock);
  99. return 0;
  100. }
  101. int svc_reg_xprt_class(struct svc_xprt_class *);
  102. void svc_unreg_xprt_class(struct svc_xprt_class *);
  103. void svc_xprt_init(struct net *, struct svc_xprt_class *, struct svc_xprt *,
  104. struct svc_serv *);
  105. int svc_create_xprt(struct svc_serv *, const char *, struct net *,
  106. const int, const unsigned short, int);
  107. void svc_xprt_do_enqueue(struct svc_xprt *xprt);
  108. void svc_xprt_enqueue(struct svc_xprt *xprt);
  109. void svc_xprt_put(struct svc_xprt *xprt);
  110. void svc_xprt_copy_addrs(struct svc_rqst *rqstp, struct svc_xprt *xprt);
  111. void svc_close_xprt(struct svc_xprt *xprt);
  112. int svc_port_is_privileged(struct sockaddr *sin);
  113. int svc_print_xprts(char *buf, int maxlen);
  114. struct svc_xprt *svc_find_xprt(struct svc_serv *serv, const char *xcl_name,
  115. struct net *net, const sa_family_t af,
  116. const unsigned short port);
  117. int svc_xprt_names(struct svc_serv *serv, char *buf, const int buflen);
  118. void svc_add_new_perm_xprt(struct svc_serv *serv, struct svc_xprt *xprt);
  119. static inline void svc_xprt_get(struct svc_xprt *xprt)
  120. {
  121. kref_get(&xprt->xpt_ref);
  122. }
  123. static inline void svc_xprt_set_local(struct svc_xprt *xprt,
  124. const struct sockaddr *sa,
  125. const size_t salen)
  126. {
  127. memcpy(&xprt->xpt_local, sa, salen);
  128. xprt->xpt_locallen = salen;
  129. }
  130. static inline void svc_xprt_set_remote(struct svc_xprt *xprt,
  131. const struct sockaddr *sa,
  132. const size_t salen)
  133. {
  134. memcpy(&xprt->xpt_remote, sa, salen);
  135. xprt->xpt_remotelen = salen;
  136. }
  137. static inline unsigned short svc_addr_port(const struct sockaddr *sa)
  138. {
  139. const struct sockaddr_in *sin = (const struct sockaddr_in *)sa;
  140. const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)sa;
  141. switch (sa->sa_family) {
  142. case AF_INET:
  143. return ntohs(sin->sin_port);
  144. case AF_INET6:
  145. return ntohs(sin6->sin6_port);
  146. }
  147. return 0;
  148. }
  149. static inline size_t svc_addr_len(const struct sockaddr *sa)
  150. {
  151. switch (sa->sa_family) {
  152. case AF_INET:
  153. return sizeof(struct sockaddr_in);
  154. case AF_INET6:
  155. return sizeof(struct sockaddr_in6);
  156. }
  157. BUG();
  158. }
  159. static inline unsigned short svc_xprt_local_port(const struct svc_xprt *xprt)
  160. {
  161. return svc_addr_port((const struct sockaddr *)&xprt->xpt_local);
  162. }
  163. static inline unsigned short svc_xprt_remote_port(const struct svc_xprt *xprt)
  164. {
  165. return svc_addr_port((const struct sockaddr *)&xprt->xpt_remote);
  166. }
  167. static inline char *__svc_print_addr(const struct sockaddr *addr,
  168. char *buf, const size_t len)
  169. {
  170. const struct sockaddr_in *sin = (const struct sockaddr_in *)addr;
  171. const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)addr;
  172. switch (addr->sa_family) {
  173. case AF_INET:
  174. snprintf(buf, len, "%pI4, port=%u", &sin->sin_addr,
  175. ntohs(sin->sin_port));
  176. break;
  177. case AF_INET6:
  178. snprintf(buf, len, "%pI6, port=%u",
  179. &sin6->sin6_addr,
  180. ntohs(sin6->sin6_port));
  181. break;
  182. default:
  183. snprintf(buf, len, "unknown address type: %d", addr->sa_family);
  184. break;
  185. }
  186. return buf;
  187. }
  188. #endif /* SUNRPC_SVC_XPRT_H */