Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 9 | #ifndef _LINUX_SUNRPC_CLNT_H |
| 10 | #define _LINUX_SUNRPC_CLNT_H |
| 11 | |
Chuck Lever | a02d692 | 2009-08-09 15:09:34 -0400 | [diff] [blame] | 12 | #include <linux/socket.h> |
| 13 | #include <linux/in.h> |
| 14 | #include <linux/in6.h> |
| 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/sunrpc/msg_prot.h> |
| 17 | #include <linux/sunrpc/sched.h> |
| 18 | #include <linux/sunrpc/xprt.h> |
| 19 | #include <linux/sunrpc/auth.h> |
| 20 | #include <linux/sunrpc/stats.h> |
| 21 | #include <linux/sunrpc/xdr.h> |
| 22 | #include <linux/sunrpc/timer.h> |
| 23 | #include <asm/signal.h> |
Trond Myklebust | 7d217ca | 2009-08-09 15:14:24 -0400 | [diff] [blame] | 24 | #include <linux/path.h> |
Jeff Layton | 4516fc0 | 2009-08-14 12:57:54 -0400 | [diff] [blame] | 25 | #include <net/ipv6.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | struct rpc_inode; |
| 28 | |
| 29 | /* |
| 30 | * The high-level client handle |
| 31 | */ |
| 32 | struct rpc_clnt { |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 33 | struct kref cl_kref; /* Number of references */ |
Trond Myklebust | 6529eba | 2007-06-14 16:40:14 -0400 | [diff] [blame] | 34 | struct list_head cl_clients; /* Global list of clients */ |
| 35 | struct list_head cl_tasks; /* List of tasks */ |
Trond Myklebust | 4bef61f | 2007-06-16 14:17:01 -0400 | [diff] [blame] | 36 | spinlock_t cl_lock; /* spinlock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | struct rpc_xprt * cl_xprt; /* transport */ |
| 38 | struct rpc_procinfo * cl_procinfo; /* procedure info */ |
Chuck Lever | 4a68179 | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 39 | u32 cl_prog, /* RPC program number */ |
| 40 | cl_vers, /* RPC version number */ |
| 41 | cl_maxproc; /* max procedure number */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | char * cl_server; /* server machine name */ |
| 44 | char * cl_protname; /* protocol name */ |
| 45 | struct rpc_auth * cl_auth; /* authenticator */ |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 46 | struct rpc_stat * cl_stats; /* per-program statistics */ |
| 47 | struct rpc_iostats * cl_metrics; /* per-client statistics */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | unsigned int cl_softrtry : 1,/* soft timeouts */ |
Chuck Lever | 43d78ef | 2007-02-06 18:26:11 -0500 | [diff] [blame] | 50 | cl_discrtry : 1,/* disconnect before retry */ |
Olga Kornievskaia | b6b6152 | 2008-06-09 16:51:31 -0400 | [diff] [blame] | 51 | cl_autobind : 1,/* use getport() */ |
| 52 | cl_chatty : 1;/* be verbose */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | struct rpc_rtt * cl_rtt; /* RTO estimator data */ |
Trond Myklebust | ba7392b | 2007-12-20 16:03:55 -0500 | [diff] [blame] | 55 | const struct rpc_timeout *cl_timeout; /* Timeout strategy */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | int cl_nodelen; /* nodename length */ |
| 58 | char cl_nodename[UNX_MAXNODENAME]; |
Trond Myklebust | 7d217ca | 2009-08-09 15:14:24 -0400 | [diff] [blame] | 59 | struct path cl_path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | struct rpc_clnt * cl_parent; /* Points to parent of clones */ |
| 61 | struct rpc_rtt cl_rtt_default; |
Trond Myklebust | ba7392b | 2007-12-20 16:03:55 -0500 | [diff] [blame] | 62 | struct rpc_timeout cl_timeout_default; |
Trond Myklebust | 3e32a5d | 2006-11-16 11:37:27 -0500 | [diff] [blame] | 63 | struct rpc_program * cl_program; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | char cl_inline_name[32]; |
Olga Kornievskaia | 608207e | 2008-12-23 16:17:40 -0500 | [diff] [blame] | 65 | char *cl_principal; /* target to authenticate to */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | /* |
| 69 | * General RPC program info |
| 70 | */ |
| 71 | #define RPC_MAXVERSION 4 |
| 72 | struct rpc_program { |
| 73 | char * name; /* protocol name */ |
| 74 | u32 number; /* program number */ |
| 75 | unsigned int nrvers; /* number of versions */ |
| 76 | struct rpc_version ** version; /* version array */ |
| 77 | struct rpc_stat * stats; /* statistics */ |
| 78 | char * pipe_dir_name; /* path to rpc_pipefs dir */ |
| 79 | }; |
| 80 | |
| 81 | struct rpc_version { |
| 82 | u32 number; /* version number */ |
| 83 | unsigned int nrprocs; /* number of procs */ |
| 84 | struct rpc_procinfo * procs; /* procedure array */ |
| 85 | }; |
| 86 | |
| 87 | /* |
| 88 | * Procedure information |
| 89 | */ |
| 90 | struct rpc_procinfo { |
| 91 | u32 p_proc; /* RPC procedure number */ |
| 92 | kxdrproc_t p_encode; /* XDR encode function */ |
| 93 | kxdrproc_t p_decode; /* XDR decode function */ |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 94 | unsigned int p_arglen; /* argument hdr length (u32) */ |
| 95 | unsigned int p_replen; /* reply hdr length (u32) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | unsigned int p_count; /* call count */ |
| 97 | unsigned int p_timer; /* Which RTT timer to use */ |
Chuck Lever | cc0175c | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 98 | u32 p_statidx; /* Which procedure to account */ |
| 99 | char * p_name; /* name of procedure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | }; |
| 101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | #ifdef __KERNEL__ |
| 103 | |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 104 | struct rpc_create_args { |
| 105 | int protocol; |
| 106 | struct sockaddr *address; |
| 107 | size_t addrsize; |
Frank van Maarseveen | d3bc9a1 | 2007-07-09 22:23:35 +0200 | [diff] [blame] | 108 | struct sockaddr *saddress; |
Trond Myklebust | ba7392b | 2007-12-20 16:03:55 -0500 | [diff] [blame] | 109 | const struct rpc_timeout *timeout; |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 110 | char *servername; |
| 111 | struct rpc_program *program; |
Benny Halevy | d5b337b | 2008-09-28 09:21:26 +0300 | [diff] [blame] | 112 | u32 prognumber; /* overrides program->number */ |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 113 | u32 version; |
| 114 | rpc_authflavor_t authflavor; |
| 115 | unsigned long flags; |
Olga Kornievskaia | 608207e | 2008-12-23 16:17:40 -0500 | [diff] [blame] | 116 | char *client_name; |
Alexandros Batsakis | f300bab | 2009-09-10 17:33:30 +0300 | [diff] [blame] | 117 | struct svc_xprt *bc_xprt; /* NFSv4.1 backchannel */ |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | /* Values for "flags" field */ |
| 121 | #define RPC_CLNT_CREATE_HARDRTRY (1UL << 0) |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 122 | #define RPC_CLNT_CREATE_AUTOBIND (1UL << 2) |
Trond Myklebust | 90c5755 | 2007-06-09 19:49:36 -0400 | [diff] [blame] | 123 | #define RPC_CLNT_CREATE_NONPRIVPORT (1UL << 3) |
| 124 | #define RPC_CLNT_CREATE_NOPING (1UL << 4) |
| 125 | #define RPC_CLNT_CREATE_DISCRTRY (1UL << 5) |
Olga Kornievskaia | b6b6152 | 2008-06-09 16:51:31 -0400 | [diff] [blame] | 126 | #define RPC_CLNT_CREATE_QUIET (1UL << 6) |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 127 | |
| 128 | struct rpc_clnt *rpc_create(struct rpc_create_args *args); |
Andreas Gruenbacher | 007e251 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 129 | struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *, |
Chuck Lever | 89eb21c | 2007-09-11 18:00:09 -0400 | [diff] [blame] | 130 | struct rpc_program *, u32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | struct rpc_clnt *rpc_clone_client(struct rpc_clnt *); |
Trond Myklebust | 4c402b4 | 2007-06-14 16:40:32 -0400 | [diff] [blame] | 132 | void rpc_shutdown_client(struct rpc_clnt *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | void rpc_release_client(struct rpc_clnt *); |
Trond Myklebust | 58f9612 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 134 | void rpc_task_release_client(struct rpc_task *); |
Chuck Lever | cce63cd | 2007-07-01 12:13:12 -0400 | [diff] [blame] | 135 | |
Chuck Lever | 14aeb21 | 2008-08-18 19:34:00 -0400 | [diff] [blame] | 136 | int rpcb_register(u32, u32, int, unsigned short); |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 137 | int rpcb_v4_register(const u32 program, const u32 version, |
| 138 | const struct sockaddr *address, |
Chuck Lever | 14aeb21 | 2008-08-18 19:34:00 -0400 | [diff] [blame] | 139 | const char *netid); |
Chuck Lever | f1ec08c | 2008-01-14 15:11:53 -0500 | [diff] [blame] | 140 | int rpcb_getport_sync(struct sockaddr_in *, u32, u32, int); |
Chuck Lever | 45160d6 | 2007-07-01 12:13:17 -0400 | [diff] [blame] | 141 | void rpcb_getport_async(struct rpc_task *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
Trond Myklebust | 77de2c5 | 2007-10-25 18:40:21 -0400 | [diff] [blame] | 143 | void rpc_call_start(struct rpc_task *); |
Trond Myklebust | cbc2005 | 2008-02-14 11:11:30 -0500 | [diff] [blame] | 144 | int rpc_call_async(struct rpc_clnt *clnt, |
| 145 | const struct rpc_message *msg, int flags, |
| 146 | const struct rpc_call_ops *tk_ops, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 147 | void *calldata); |
Trond Myklebust | cbc2005 | 2008-02-14 11:11:30 -0500 | [diff] [blame] | 148 | int rpc_call_sync(struct rpc_clnt *clnt, |
| 149 | const struct rpc_message *msg, int flags); |
Trond Myklebust | 5e1550d | 2007-06-23 10:17:16 -0400 | [diff] [blame] | 150 | struct rpc_task *rpc_call_null(struct rpc_clnt *clnt, struct rpc_cred *cred, |
| 151 | int flags); |
Trond Myklebust | f1f88fc | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 152 | int rpc_restart_call_prepare(struct rpc_task *); |
| 153 | int rpc_restart_call(struct rpc_task *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | void rpc_setbufsize(struct rpc_clnt *, unsigned int, unsigned int); |
| 155 | size_t rpc_max_payload(struct rpc_clnt *); |
Chuck Lever | 35f5a42 | 2006-01-03 09:55:50 +0100 | [diff] [blame] | 156 | void rpc_force_rebind(struct rpc_clnt *); |
Chuck Lever | ed39440 | 2006-08-22 20:06:17 -0400 | [diff] [blame] | 157 | size_t rpc_peeraddr(struct rpc_clnt *, struct sockaddr *, size_t); |
Chuck Lever | b454ae9 | 2008-01-07 18:34:48 -0500 | [diff] [blame] | 158 | const char *rpc_peeraddr2str(struct rpc_clnt *, enum rpc_display_format_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
Chuck Lever | a02d692 | 2009-08-09 15:09:34 -0400 | [diff] [blame] | 160 | size_t rpc_ntop(const struct sockaddr *, char *, const size_t); |
| 161 | size_t rpc_pton(const char *, const size_t, |
| 162 | struct sockaddr *, const size_t); |
| 163 | char * rpc_sockaddr2uaddr(const struct sockaddr *); |
| 164 | size_t rpc_uaddr2sockaddr(const char *, const size_t, |
| 165 | struct sockaddr *, const size_t); |
| 166 | |
| 167 | static inline unsigned short rpc_get_port(const struct sockaddr *sap) |
| 168 | { |
| 169 | switch (sap->sa_family) { |
| 170 | case AF_INET: |
| 171 | return ntohs(((struct sockaddr_in *)sap)->sin_port); |
| 172 | case AF_INET6: |
| 173 | return ntohs(((struct sockaddr_in6 *)sap)->sin6_port); |
| 174 | } |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | static inline void rpc_set_port(struct sockaddr *sap, |
| 179 | const unsigned short port) |
| 180 | { |
| 181 | switch (sap->sa_family) { |
| 182 | case AF_INET: |
| 183 | ((struct sockaddr_in *)sap)->sin_port = htons(port); |
| 184 | break; |
| 185 | case AF_INET6: |
| 186 | ((struct sockaddr_in6 *)sap)->sin6_port = htons(port); |
| 187 | break; |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | #define IPV6_SCOPE_DELIMITER '%' |
| 192 | #define IPV6_SCOPE_ID_LEN sizeof("%nnnnnnnnnn") |
| 193 | |
Jeff Layton | 4516fc0 | 2009-08-14 12:57:54 -0400 | [diff] [blame] | 194 | static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1, |
| 195 | const struct sockaddr *sap2) |
| 196 | { |
| 197 | const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sap1; |
| 198 | const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sap2; |
| 199 | |
| 200 | return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr; |
| 201 | } |
| 202 | |
Jeff Layton | be3ad6b | 2009-08-14 12:57:55 -0400 | [diff] [blame] | 203 | static inline bool __rpc_copy_addr4(struct sockaddr *dst, |
| 204 | const struct sockaddr *src) |
| 205 | { |
| 206 | const struct sockaddr_in *ssin = (struct sockaddr_in *) src; |
| 207 | struct sockaddr_in *dsin = (struct sockaddr_in *) dst; |
| 208 | |
| 209 | dsin->sin_family = ssin->sin_family; |
| 210 | dsin->sin_addr.s_addr = ssin->sin_addr.s_addr; |
| 211 | return true; |
| 212 | } |
| 213 | |
Jeff Layton | 4516fc0 | 2009-08-14 12:57:54 -0400 | [diff] [blame] | 214 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
| 215 | static inline bool __rpc_cmp_addr6(const struct sockaddr *sap1, |
| 216 | const struct sockaddr *sap2) |
| 217 | { |
| 218 | const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sap1; |
| 219 | const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sap2; |
| 220 | return ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr); |
| 221 | } |
Jeff Layton | be3ad6b | 2009-08-14 12:57:55 -0400 | [diff] [blame] | 222 | |
| 223 | static inline bool __rpc_copy_addr6(struct sockaddr *dst, |
| 224 | const struct sockaddr *src) |
| 225 | { |
| 226 | const struct sockaddr_in6 *ssin6 = (const struct sockaddr_in6 *) src; |
| 227 | struct sockaddr_in6 *dsin6 = (struct sockaddr_in6 *) dst; |
| 228 | |
| 229 | dsin6->sin6_family = ssin6->sin6_family; |
| 230 | ipv6_addr_copy(&dsin6->sin6_addr, &ssin6->sin6_addr); |
| 231 | return true; |
| 232 | } |
Jeff Layton | 4516fc0 | 2009-08-14 12:57:54 -0400 | [diff] [blame] | 233 | #else /* !(CONFIG_IPV6 || CONFIG_IPV6_MODULE) */ |
| 234 | static inline bool __rpc_cmp_addr6(const struct sockaddr *sap1, |
| 235 | const struct sockaddr *sap2) |
| 236 | { |
| 237 | return false; |
| 238 | } |
Jeff Layton | be3ad6b | 2009-08-14 12:57:55 -0400 | [diff] [blame] | 239 | |
| 240 | static inline bool __rpc_copy_addr6(struct sockaddr *dst, |
| 241 | const struct sockaddr *src) |
| 242 | { |
| 243 | return false; |
| 244 | } |
Jeff Layton | 4516fc0 | 2009-08-14 12:57:54 -0400 | [diff] [blame] | 245 | #endif /* !(CONFIG_IPV6 || CONFIG_IPV6_MODULE) */ |
| 246 | |
| 247 | /** |
| 248 | * rpc_cmp_addr - compare the address portion of two sockaddrs. |
| 249 | * @sap1: first sockaddr |
| 250 | * @sap2: second sockaddr |
| 251 | * |
| 252 | * Just compares the family and address portion. Ignores port, scope, etc. |
| 253 | * Returns true if the addrs are equal, false if they aren't. |
| 254 | */ |
| 255 | static inline bool rpc_cmp_addr(const struct sockaddr *sap1, |
| 256 | const struct sockaddr *sap2) |
| 257 | { |
| 258 | if (sap1->sa_family == sap2->sa_family) { |
| 259 | switch (sap1->sa_family) { |
| 260 | case AF_INET: |
| 261 | return __rpc_cmp_addr4(sap1, sap2); |
| 262 | case AF_INET6: |
| 263 | return __rpc_cmp_addr6(sap1, sap2); |
| 264 | } |
| 265 | } |
| 266 | return false; |
| 267 | } |
| 268 | |
Jeff Layton | be3ad6b | 2009-08-14 12:57:55 -0400 | [diff] [blame] | 269 | /** |
| 270 | * rpc_copy_addr - copy the address portion of one sockaddr to another |
| 271 | * @dst: destination sockaddr |
| 272 | * @src: source sockaddr |
| 273 | * |
| 274 | * Just copies the address portion and family. Ignores port, scope, etc. |
| 275 | * Caller is responsible for making certain that dst is large enough to hold |
| 276 | * the address in src. Returns true if address family is supported. Returns |
| 277 | * false otherwise. |
| 278 | */ |
| 279 | static inline bool rpc_copy_addr(struct sockaddr *dst, |
| 280 | const struct sockaddr *src) |
| 281 | { |
| 282 | switch (src->sa_family) { |
| 283 | case AF_INET: |
| 284 | return __rpc_copy_addr4(dst, src); |
| 285 | case AF_INET6: |
| 286 | return __rpc_copy_addr6(dst, src); |
| 287 | } |
| 288 | return false; |
| 289 | } |
| 290 | |
Jeff Layton | fbf4665 | 2009-08-14 12:57:59 -0400 | [diff] [blame] | 291 | /** |
| 292 | * rpc_get_scope_id - return scopeid for a given sockaddr |
| 293 | * @sa: sockaddr to get scopeid from |
| 294 | * |
| 295 | * Returns the value of the sin6_scope_id for AF_INET6 addrs, or 0 if |
| 296 | * not an AF_INET6 address. |
| 297 | */ |
| 298 | static inline u32 rpc_get_scope_id(const struct sockaddr *sa) |
| 299 | { |
| 300 | if (sa->sa_family != AF_INET6) |
| 301 | return 0; |
| 302 | |
| 303 | return ((struct sockaddr_in6 *) sa)->sin6_scope_id; |
| 304 | } |
| 305 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | #endif /* __KERNEL__ */ |
| 307 | #endif /* _LINUX_SUNRPC_CLNT_H */ |