blob: 569dc722a600d55834055cf22474858ef69f5bae [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Levera02d6922009-08-09 15:09:34 -040012#include <linux/socket.h>
13#include <linux/in.h>
14#include <linux/in6.h>
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#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 Myklebust7d217ca2009-08-09 15:14:24 -040024#include <linux/path.h>
Jeff Layton4516fc02009-08-14 12:57:54 -040025#include <net/ipv6.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Linus Torvalds1da177e2005-04-16 15:20:36 -070027struct rpc_inode;
28
29/*
30 * The high-level client handle
31 */
32struct rpc_clnt {
Trond Myklebust34f52e32007-06-14 16:40:31 -040033 struct kref cl_kref; /* Number of references */
Trond Myklebust6529eba2007-06-14 16:40:14 -040034 struct list_head cl_clients; /* Global list of clients */
35 struct list_head cl_tasks; /* List of tasks */
Trond Myklebust4bef61f2007-06-16 14:17:01 -040036 spinlock_t cl_lock; /* spinlock */
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 struct rpc_xprt * cl_xprt; /* transport */
38 struct rpc_procinfo * cl_procinfo; /* procedure info */
Chuck Lever4a681792006-08-22 20:06:15 -040039 u32 cl_prog, /* RPC program number */
40 cl_vers, /* RPC version number */
41 cl_maxproc; /* max procedure number */
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43 char * cl_server; /* server machine name */
44 char * cl_protname; /* protocol name */
45 struct rpc_auth * cl_auth; /* authenticator */
Chuck Lever11c556b2006-03-20 13:44:22 -050046 struct rpc_stat * cl_stats; /* per-program statistics */
47 struct rpc_iostats * cl_metrics; /* per-client statistics */
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49 unsigned int cl_softrtry : 1,/* soft timeouts */
Chuck Lever43d78ef2007-02-06 18:26:11 -050050 cl_discrtry : 1,/* disconnect before retry */
Olga Kornievskaiab6b61522008-06-09 16:51:31 -040051 cl_autobind : 1,/* use getport() */
52 cl_chatty : 1;/* be verbose */
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54 struct rpc_rtt * cl_rtt; /* RTO estimator data */
Trond Myklebustba7392b2007-12-20 16:03:55 -050055 const struct rpc_timeout *cl_timeout; /* Timeout strategy */
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57 int cl_nodelen; /* nodename length */
58 char cl_nodename[UNX_MAXNODENAME];
Trond Myklebust7d217ca2009-08-09 15:14:24 -040059 struct path cl_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 struct rpc_clnt * cl_parent; /* Points to parent of clones */
61 struct rpc_rtt cl_rtt_default;
Trond Myklebustba7392b2007-12-20 16:03:55 -050062 struct rpc_timeout cl_timeout_default;
Trond Myklebust3e32a5d2006-11-16 11:37:27 -050063 struct rpc_program * cl_program;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 char cl_inline_name[32];
Olga Kornievskaia608207e2008-12-23 16:17:40 -050065 char *cl_principal; /* target to authenticate to */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066};
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68/*
69 * General RPC program info
70 */
71#define RPC_MAXVERSION 4
72struct 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
81struct 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 */
90struct 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 Lever2bea90d2007-03-29 16:47:53 -040094 unsigned int p_arglen; /* argument hdr length (u32) */
95 unsigned int p_replen; /* reply hdr length (u32) */
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 unsigned int p_count; /* call count */
97 unsigned int p_timer; /* Which RTT timer to use */
Chuck Levercc0175c2006-03-20 13:44:22 -050098 u32 p_statidx; /* Which procedure to account */
99 char * p_name; /* name of procedure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100};
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#ifdef __KERNEL__
103
Chuck Leverc2866762006-08-22 20:06:20 -0400104struct rpc_create_args {
105 int protocol;
106 struct sockaddr *address;
107 size_t addrsize;
Frank van Maarseveend3bc9a12007-07-09 22:23:35 +0200108 struct sockaddr *saddress;
Trond Myklebustba7392b2007-12-20 16:03:55 -0500109 const struct rpc_timeout *timeout;
Chuck Leverc2866762006-08-22 20:06:20 -0400110 char *servername;
111 struct rpc_program *program;
Benny Halevyd5b337b2008-09-28 09:21:26 +0300112 u32 prognumber; /* overrides program->number */
Chuck Leverc2866762006-08-22 20:06:20 -0400113 u32 version;
114 rpc_authflavor_t authflavor;
115 unsigned long flags;
Olga Kornievskaia608207e2008-12-23 16:17:40 -0500116 char *client_name;
Alexandros Batsakisf300bab2009-09-10 17:33:30 +0300117 struct svc_xprt *bc_xprt; /* NFSv4.1 backchannel */
Chuck Leverc2866762006-08-22 20:06:20 -0400118};
119
120/* Values for "flags" field */
121#define RPC_CLNT_CREATE_HARDRTRY (1UL << 0)
Chuck Leverc2866762006-08-22 20:06:20 -0400122#define RPC_CLNT_CREATE_AUTOBIND (1UL << 2)
Trond Myklebust90c57552007-06-09 19:49:36 -0400123#define RPC_CLNT_CREATE_NONPRIVPORT (1UL << 3)
124#define RPC_CLNT_CREATE_NOPING (1UL << 4)
125#define RPC_CLNT_CREATE_DISCRTRY (1UL << 5)
Olga Kornievskaiab6b61522008-06-09 16:51:31 -0400126#define RPC_CLNT_CREATE_QUIET (1UL << 6)
Chuck Leverc2866762006-08-22 20:06:20 -0400127
128struct rpc_clnt *rpc_create(struct rpc_create_args *args);
Andreas Gruenbacher007e2512005-06-22 17:16:23 +0000129struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *,
Chuck Lever89eb21c2007-09-11 18:00:09 -0400130 struct rpc_program *, u32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131struct rpc_clnt *rpc_clone_client(struct rpc_clnt *);
Trond Myklebust4c402b42007-06-14 16:40:32 -0400132void rpc_shutdown_client(struct rpc_clnt *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133void rpc_release_client(struct rpc_clnt *);
Trond Myklebust58f96122010-07-31 14:29:08 -0400134void rpc_task_release_client(struct rpc_task *);
Chuck Levercce63cd2007-07-01 12:13:12 -0400135
Chuck Lever14aeb212008-08-18 19:34:00 -0400136int rpcb_register(u32, u32, int, unsigned short);
Chuck Leverc2e1b092008-07-14 16:03:30 -0400137int rpcb_v4_register(const u32 program, const u32 version,
138 const struct sockaddr *address,
Chuck Lever14aeb212008-08-18 19:34:00 -0400139 const char *netid);
Chuck Leverf1ec08c2008-01-14 15:11:53 -0500140int rpcb_getport_sync(struct sockaddr_in *, u32, u32, int);
Chuck Lever45160d62007-07-01 12:13:17 -0400141void rpcb_getport_async(struct rpc_task *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Trond Myklebust77de2c52007-10-25 18:40:21 -0400143void rpc_call_start(struct rpc_task *);
Trond Myklebustcbc20052008-02-14 11:11:30 -0500144int rpc_call_async(struct rpc_clnt *clnt,
145 const struct rpc_message *msg, int flags,
146 const struct rpc_call_ops *tk_ops,
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100147 void *calldata);
Trond Myklebustcbc20052008-02-14 11:11:30 -0500148int rpc_call_sync(struct rpc_clnt *clnt,
149 const struct rpc_message *msg, int flags);
Trond Myklebust5e1550d2007-06-23 10:17:16 -0400150struct rpc_task *rpc_call_null(struct rpc_clnt *clnt, struct rpc_cred *cred,
151 int flags);
Trond Myklebustf1f88fc2010-07-31 14:29:07 -0400152int rpc_restart_call_prepare(struct rpc_task *);
153int rpc_restart_call(struct rpc_task *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154void rpc_setbufsize(struct rpc_clnt *, unsigned int, unsigned int);
155size_t rpc_max_payload(struct rpc_clnt *);
Chuck Lever35f5a422006-01-03 09:55:50 +0100156void rpc_force_rebind(struct rpc_clnt *);
Chuck Levered394402006-08-22 20:06:17 -0400157size_t rpc_peeraddr(struct rpc_clnt *, struct sockaddr *, size_t);
Chuck Leverb454ae92008-01-07 18:34:48 -0500158const char *rpc_peeraddr2str(struct rpc_clnt *, enum rpc_display_format_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Chuck Levera02d6922009-08-09 15:09:34 -0400160size_t rpc_ntop(const struct sockaddr *, char *, const size_t);
161size_t rpc_pton(const char *, const size_t,
162 struct sockaddr *, const size_t);
163char * rpc_sockaddr2uaddr(const struct sockaddr *);
164size_t rpc_uaddr2sockaddr(const char *, const size_t,
165 struct sockaddr *, const size_t);
166
167static 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
178static 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 Layton4516fc02009-08-14 12:57:54 -0400194static 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 Laytonbe3ad6b2009-08-14 12:57:55 -0400203static 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 Layton4516fc02009-08-14 12:57:54 -0400214#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
215static 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 Laytonbe3ad6b2009-08-14 12:57:55 -0400222
223static 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 Layton4516fc02009-08-14 12:57:54 -0400233#else /* !(CONFIG_IPV6 || CONFIG_IPV6_MODULE) */
234static inline bool __rpc_cmp_addr6(const struct sockaddr *sap1,
235 const struct sockaddr *sap2)
236{
237 return false;
238}
Jeff Laytonbe3ad6b2009-08-14 12:57:55 -0400239
240static inline bool __rpc_copy_addr6(struct sockaddr *dst,
241 const struct sockaddr *src)
242{
243 return false;
244}
Jeff Layton4516fc02009-08-14 12:57:54 -0400245#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 */
255static 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 Laytonbe3ad6b2009-08-14 12:57:55 -0400269/**
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 */
279static 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 Laytonfbf46652009-08-14 12:57:59 -0400291/**
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 */
298static 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 Torvalds1da177e2005-04-16 15:20:36 -0700306#endif /* __KERNEL__ */
307#endif /* _LINUX_SUNRPC_CLNT_H */