1
2
3
4
5
6
7
8
9
10#ifndef _LINUX_SUNRPC_CLNT_H
11#define _LINUX_SUNRPC_CLNT_H
12
13#include <linux/types.h>
14#include <linux/socket.h>
15#include <linux/in.h>
16#include <linux/in6.h>
17
18#include <linux/sunrpc/msg_prot.h>
19#include <linux/sunrpc/sched.h>
20#include <linux/sunrpc/xprt.h>
21#include <linux/sunrpc/auth.h>
22#include <linux/sunrpc/stats.h>
23#include <linux/sunrpc/xdr.h>
24#include <linux/sunrpc/timer.h>
25#include <linux/sunrpc/rpc_pipe_fs.h>
26#include <asm/signal.h>
27#include <linux/path.h>
28#include <net/ipv6.h>
29#include <linux/sunrpc/xprtmultipath.h>
30
31struct rpc_inode;
32
33
34
35
36struct rpc_clnt {
37 atomic_t cl_count;
38 unsigned int cl_clid;
39 struct list_head cl_clients;
40 struct list_head cl_tasks;
41 spinlock_t cl_lock;
42 struct rpc_xprt __rcu * cl_xprt;
43 const struct rpc_procinfo *cl_procinfo;
44 u32 cl_prog,
45 cl_vers,
46 cl_maxproc;
47
48 struct rpc_auth * cl_auth;
49 struct rpc_stat * cl_stats;
50 struct rpc_iostats * cl_metrics;
51
52 unsigned int cl_softrtry : 1,
53 cl_softerr : 1,
54 cl_discrtry : 1,
55 cl_noretranstimeo: 1,
56 cl_autobind : 1,
57 cl_chatty : 1;
58
59 struct rpc_rtt * cl_rtt;
60 const struct rpc_timeout *cl_timeout;
61
62 atomic_t cl_swapper;
63 int cl_nodelen;
64 char cl_nodename[UNX_MAXNODENAME+1];
65 struct rpc_pipe_dir_head cl_pipedir_objects;
66 struct rpc_clnt * cl_parent;
67 struct rpc_rtt cl_rtt_default;
68 struct rpc_timeout cl_timeout_default;
69 const struct rpc_program *cl_program;
70 const char * cl_principal;
71#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
72 struct dentry *cl_debugfs;
73#endif
74 struct rpc_xprt_iter cl_xpi;
75 const struct cred *cl_cred;
76};
77
78
79
80
81#define RPC_MAXVERSION 4
82struct rpc_program {
83 const char * name;
84 u32 number;
85 unsigned int nrvers;
86 const struct rpc_version ** version;
87 struct rpc_stat * stats;
88 const char * pipe_dir_name;
89};
90
91struct rpc_version {
92 u32 number;
93 unsigned int nrprocs;
94 const struct rpc_procinfo *procs;
95 unsigned int *counts;
96};
97
98
99
100
101struct rpc_procinfo {
102 u32 p_proc;
103 kxdreproc_t p_encode;
104 kxdrdproc_t p_decode;
105 unsigned int p_arglen;
106 unsigned int p_replen;
107 unsigned int p_timer;
108 u32 p_statidx;
109 const char * p_name;
110};
111
112struct rpc_create_args {
113 struct net *net;
114 int protocol;
115 struct sockaddr *address;
116 size_t addrsize;
117 struct sockaddr *saddress;
118 const struct rpc_timeout *timeout;
119 const char *servername;
120 const char *nodename;
121 const struct rpc_program *program;
122 u32 prognumber;
123 u32 version;
124 rpc_authflavor_t authflavor;
125 u32 nconnect;
126 unsigned long flags;
127 char *client_name;
128 struct svc_xprt *bc_xprt;
129 const struct cred *cred;
130};
131
132struct rpc_add_xprt_test {
133 void (*add_xprt_test)(struct rpc_clnt *clnt,
134 struct rpc_xprt *xprt,
135 void *calldata);
136 void *data;
137};
138
139
140#define RPC_CLNT_CREATE_HARDRTRY (1UL << 0)
141#define RPC_CLNT_CREATE_AUTOBIND (1UL << 2)
142#define RPC_CLNT_CREATE_NONPRIVPORT (1UL << 3)
143#define RPC_CLNT_CREATE_NOPING (1UL << 4)
144#define RPC_CLNT_CREATE_DISCRTRY (1UL << 5)
145#define RPC_CLNT_CREATE_QUIET (1UL << 6)
146#define RPC_CLNT_CREATE_INFINITE_SLOTS (1UL << 7)
147#define RPC_CLNT_CREATE_NO_IDLE_TIMEOUT (1UL << 8)
148#define RPC_CLNT_CREATE_NO_RETRANS_TIMEOUT (1UL << 9)
149#define RPC_CLNT_CREATE_SOFTERR (1UL << 10)
150#define RPC_CLNT_CREATE_REUSEPORT (1UL << 11)
151
152struct rpc_clnt *rpc_create(struct rpc_create_args *args);
153struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *,
154 const struct rpc_program *, u32);
155struct rpc_clnt *rpc_clone_client(struct rpc_clnt *);
156struct rpc_clnt *rpc_clone_client_set_auth(struct rpc_clnt *,
157 rpc_authflavor_t);
158int rpc_switch_client_transport(struct rpc_clnt *,
159 struct xprt_create *,
160 const struct rpc_timeout *);
161
162void rpc_shutdown_client(struct rpc_clnt *);
163void rpc_release_client(struct rpc_clnt *);
164void rpc_task_release_transport(struct rpc_task *);
165void rpc_task_release_client(struct rpc_task *);
166struct rpc_xprt *rpc_task_get_xprt(struct rpc_clnt *clnt,
167 struct rpc_xprt *xprt);
168
169int rpcb_create_local(struct net *);
170void rpcb_put_local(struct net *);
171int rpcb_register(struct net *, u32, u32, int, unsigned short);
172int rpcb_v4_register(struct net *net, const u32 program,
173 const u32 version,
174 const struct sockaddr *address,
175 const char *netid);
176void rpcb_getport_async(struct rpc_task *);
177
178void rpc_prepare_reply_pages(struct rpc_rqst *req, struct page **pages,
179 unsigned int base, unsigned int len,
180 unsigned int hdrsize);
181void rpc_call_start(struct rpc_task *);
182int rpc_call_async(struct rpc_clnt *clnt,
183 const struct rpc_message *msg, int flags,
184 const struct rpc_call_ops *tk_ops,
185 void *calldata);
186int rpc_call_sync(struct rpc_clnt *clnt,
187 const struct rpc_message *msg, int flags);
188struct rpc_task *rpc_call_null(struct rpc_clnt *clnt, struct rpc_cred *cred,
189 int flags);
190int rpc_restart_call_prepare(struct rpc_task *);
191int rpc_restart_call(struct rpc_task *);
192void rpc_setbufsize(struct rpc_clnt *, unsigned int, unsigned int);
193struct net * rpc_net_ns(struct rpc_clnt *);
194size_t rpc_max_payload(struct rpc_clnt *);
195size_t rpc_max_bc_payload(struct rpc_clnt *);
196unsigned int rpc_num_bc_slots(struct rpc_clnt *);
197void rpc_force_rebind(struct rpc_clnt *);
198size_t rpc_peeraddr(struct rpc_clnt *, struct sockaddr *, size_t);
199const char *rpc_peeraddr2str(struct rpc_clnt *, enum rpc_display_format_t);
200int rpc_localaddr(struct rpc_clnt *, struct sockaddr *, size_t);
201
202int rpc_clnt_iterate_for_each_xprt(struct rpc_clnt *clnt,
203 int (*fn)(struct rpc_clnt *, struct rpc_xprt *, void *),
204 void *data);
205
206int rpc_clnt_test_and_add_xprt(struct rpc_clnt *clnt,
207 struct rpc_xprt_switch *xps,
208 struct rpc_xprt *xprt,
209 void *dummy);
210int rpc_clnt_add_xprt(struct rpc_clnt *, struct xprt_create *,
211 int (*setup)(struct rpc_clnt *,
212 struct rpc_xprt_switch *,
213 struct rpc_xprt *,
214 void *),
215 void *data);
216void rpc_set_connect_timeout(struct rpc_clnt *clnt,
217 unsigned long connect_timeout,
218 unsigned long reconnect_timeout);
219
220int rpc_clnt_setup_test_and_add_xprt(struct rpc_clnt *,
221 struct rpc_xprt_switch *,
222 struct rpc_xprt *,
223 void *);
224
225const char *rpc_proc_name(const struct rpc_task *task);
226
227void rpc_clnt_xprt_switch_put(struct rpc_clnt *);
228void rpc_clnt_xprt_switch_add_xprt(struct rpc_clnt *, struct rpc_xprt *);
229bool rpc_clnt_xprt_switch_has_addr(struct rpc_clnt *clnt,
230 const struct sockaddr *sap);
231void rpc_cleanup_clids(void);
232
233static inline int rpc_reply_expected(struct rpc_task *task)
234{
235 return (task->tk_msg.rpc_proc != NULL) &&
236 (task->tk_msg.rpc_proc->p_decode != NULL);
237}
238
239static inline void rpc_task_close_connection(struct rpc_task *task)
240{
241 if (task->tk_xprt)
242 xprt_force_disconnect(task->tk_xprt);
243}
244#endif
245