blob: baafa0f1e555e9a95822536db4bc67b32a11fceb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/fs/nfs/callback.c
3 *
4 * Copyright (C) 2004 Trond Myklebust
5 *
6 * NFSv4 callback handling
7 */
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/completion.h>
10#include <linux/ip.h>
11#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/sunrpc/svc.h>
13#include <linux/sunrpc/svcsock.h>
14#include <linux/nfs_fs.h>
Ingo Molnar353ab6e2006-03-26 01:37:12 -080015#include <linux/mutex.h>
Rafael J. Wysocki83144182007-07-17 04:03:35 -070016#include <linux/freezer.h>
Jeff Laytona277e332008-02-20 08:55:30 -050017#include <linux/kthread.h>
Olga Kornievskaia945b34a2008-12-23 16:18:34 -050018#include <linux/sunrpc/svcauth_gss.h>
Ricardo Labiagaa43cde92009-04-01 09:23:08 -040019#include <linux/sunrpc/bc_xprt.h>
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020020
21#include <net/inet_sock.h>
22
Trond Myklebust4ce79712005-06-22 17:16:21 +000023#include "nfs4_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include "callback.h"
David Howells24c8dbb2006-08-22 20:06:10 -040025#include "internal.h"
Stanislav Kinsburskybbe0a3a2012-08-20 18:00:36 +040026#include "netns.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28#define NFSDBG_FACILITY NFSDBG_CALLBACK
29
30struct nfs_callback_data {
31 unsigned int users;
Ricardo Labiagaa43cde92009-04-01 09:23:08 -040032 struct svc_serv *serv;
Jeff Layton5afc5972008-06-11 10:03:11 -040033 struct svc_rqst *rqst;
Jeff Laytona277e332008-02-20 08:55:30 -050034 struct task_struct *task;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035};
36
Andy Adamsone82dc222009-04-01 09:23:14 -040037static struct nfs_callback_data nfs_callback_info[NFS4_MAX_MINOR_VERSION + 1];
Ingo Molnar353ab6e2006-03-26 01:37:12 -080038static DEFINE_MUTEX(nfs_callback_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039static struct svc_program nfs4_callback_program;
40
Stanislav Kinsburskyc9465562012-08-20 18:00:16 +040041static int nfs4_callback_up_net(struct svc_serv *serv, struct net *net)
42{
43 int ret;
Stanislav Kinsburskybbe0a3a2012-08-20 18:00:36 +040044 struct nfs_net *nn = net_generic(net, nfs_net_id);
Stanislav Kinsburskyc9465562012-08-20 18:00:16 +040045
46 ret = svc_create_xprt(serv, "tcp", net, PF_INET,
47 nfs_callback_set_tcpport, SVC_SOCK_ANONYMOUS);
48 if (ret <= 0)
49 goto out_err;
Stanislav Kinsburskybbe0a3a2012-08-20 18:00:36 +040050 nn->nfs_callback_tcpport = ret;
Stanislav Kinsburskyc9465562012-08-20 18:00:16 +040051 dprintk("NFS: Callback listener port = %u (af %u, net %p)\n",
Stanislav Kinsburskybbe0a3a2012-08-20 18:00:36 +040052 nn->nfs_callback_tcpport, PF_INET, net);
Stanislav Kinsburskyc9465562012-08-20 18:00:16 +040053
54 ret = svc_create_xprt(serv, "tcp", net, PF_INET6,
55 nfs_callback_set_tcpport, SVC_SOCK_ANONYMOUS);
56 if (ret > 0) {
Stanislav Kinsbursky29dcc162012-08-20 18:00:41 +040057 nn->nfs_callback_tcpport6 = ret;
Stanislav Kinsburskyc9465562012-08-20 18:00:16 +040058 dprintk("NFS: Callback listener port = %u (af %u, net %p)\n",
Stanislav Kinsbursky29dcc162012-08-20 18:00:41 +040059 nn->nfs_callback_tcpport6, PF_INET6, net);
Stanislav Kinsburskyc9465562012-08-20 18:00:16 +040060 } else if (ret != -EAFNOSUPPORT)
61 goto out_err;
62 return 0;
63
64out_err:
65 return (ret) ? ret : -ENOMEM;
66}
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068/*
Andy Adamsone82dc222009-04-01 09:23:14 -040069 * This is the NFSv4 callback kernel thread.
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 */
Jeff Laytona277e332008-02-20 08:55:30 -050071static int
Benny Halevy71468512009-04-01 09:22:56 -040072nfs4_callback_svc(void *vrqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073{
Jeff Layton06e02d62008-04-08 15:40:07 -040074 int err, preverr = 0;
Jeff Laytona277e332008-02-20 08:55:30 -050075 struct svc_rqst *rqstp = vrqstp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Rafael J. Wysocki83144182007-07-17 04:03:35 -070077 set_freezable();
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Jeff Laytona277e332008-02-20 08:55:30 -050079 while (!kthread_should_stop()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 /*
81 * Listen for a request on the socket
82 */
NeilBrown6fb2b472006-10-02 02:17:50 -070083 err = svc_recv(rqstp, MAX_SCHEDULE_TIMEOUT);
Jeff Layton06e02d62008-04-08 15:40:07 -040084 if (err == -EAGAIN || err == -EINTR) {
85 preverr = err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 }
Jeff Layton06e02d62008-04-08 15:40:07 -040088 if (err < 0) {
89 if (err != preverr) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -050090 printk(KERN_WARNING "NFS: %s: unexpected error "
Jeff Layton06e02d62008-04-08 15:40:07 -040091 "from svc_recv (%d)\n", __func__, err);
92 preverr = err;
93 }
94 schedule_timeout_uninterruptible(HZ);
95 continue;
96 }
97 preverr = err;
NeilBrown6fb2b472006-10-02 02:17:50 -070098 svc_process(rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 }
Jeff Laytona277e332008-02-20 08:55:30 -0500100 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101}
102
103/*
Benny Halevy71468512009-04-01 09:22:56 -0400104 * Prepare to bring up the NFSv4 callback service
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 */
Trond Myklebust17280172012-03-11 13:11:00 -0400106static struct svc_rqst *
Stanislav Kinsbursky691c4572012-08-20 18:00:21 +0400107nfs4_callback_up(struct svc_serv *serv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
Eric Dumazet11fd1652011-07-28 20:04:09 +0200109 return svc_prepare_thread(serv, &serv->sv_pools[0], NUMA_NO_NODE);
Benny Halevy71468512009-04-01 09:22:56 -0400110}
111
Ricardo Labiagaa43cde92009-04-01 09:23:08 -0400112#if defined(CONFIG_NFS_V4_1)
Stanislav Kinsburskyc9465562012-08-20 18:00:16 +0400113static int nfs41_callback_up_net(struct svc_serv *serv, struct net *net)
114{
115 /*
116 * Create an svc_sock for the back channel service that shares the
117 * fore channel connection.
118 * Returns the input port (0) and sets the svc_serv bc_xprt on success
119 */
120 return svc_create_xprt(serv, "tcp-bc", net, PF_INET, 0,
121 SVC_SOCK_ANONYMOUS);
122}
123
Ricardo Labiagaa43cde92009-04-01 09:23:08 -0400124/*
125 * The callback service for NFSv4.1 callbacks
126 */
127static int
128nfs41_callback_svc(void *vrqstp)
129{
130 struct svc_rqst *rqstp = vrqstp;
131 struct svc_serv *serv = rqstp->rq_server;
132 struct rpc_rqst *req;
133 int error;
134 DEFINE_WAIT(wq);
135
136 set_freezable();
137
Ricardo Labiagaa43cde92009-04-01 09:23:08 -0400138 while (!kthread_should_stop()) {
139 prepare_to_wait(&serv->sv_cb_waitq, &wq, TASK_INTERRUPTIBLE);
140 spin_lock_bh(&serv->sv_cb_lock);
141 if (!list_empty(&serv->sv_cb_list)) {
142 req = list_first_entry(&serv->sv_cb_list,
143 struct rpc_rqst, rq_bc_list);
144 list_del(&req->rq_bc_list);
145 spin_unlock_bh(&serv->sv_cb_lock);
146 dprintk("Invoking bc_svc_process()\n");
147 error = bc_svc_process(serv, req, rqstp);
148 dprintk("bc_svc_process() returned w/ error code= %d\n",
149 error);
150 } else {
151 spin_unlock_bh(&serv->sv_cb_lock);
152 schedule();
153 }
154 finish_wait(&serv->sv_cb_waitq, &wq);
155 }
Ricardo Labiagaa43cde92009-04-01 09:23:08 -0400156 return 0;
157}
158
159/*
160 * Bring up the NFSv4.1 callback service
161 */
Trond Myklebust17280172012-03-11 13:11:00 -0400162static struct svc_rqst *
Stanislav Kinsbursky691c4572012-08-20 18:00:21 +0400163nfs41_callback_up(struct svc_serv *serv)
Ricardo Labiagaa43cde92009-04-01 09:23:08 -0400164{
Andy Adamson01c9a0b2011-01-06 02:04:28 +0000165 struct svc_rqst *rqstp;
Benny Halevy8f975242009-04-01 09:23:11 -0400166
Ricardo Labiagaa43cde92009-04-01 09:23:08 -0400167 INIT_LIST_HEAD(&serv->sv_cb_list);
168 spin_lock_init(&serv->sv_cb_lock);
169 init_waitqueue_head(&serv->sv_cb_waitq);
Eric Dumazet11fd1652011-07-28 20:04:09 +0200170 rqstp = svc_prepare_thread(serv, &serv->sv_pools[0], NUMA_NO_NODE);
Andy Adamson01c9a0b2011-01-06 02:04:28 +0000171 if (IS_ERR(rqstp)) {
Andy Adamson4a19de02011-01-06 02:04:35 +0000172 svc_xprt_put(serv->sv_bc_xprt);
173 serv->sv_bc_xprt = NULL;
Andy Adamson01c9a0b2011-01-06 02:04:28 +0000174 }
Andy Adamson01c9a0b2011-01-06 02:04:28 +0000175 dprintk("--> %s return %ld\n", __func__,
176 IS_ERR(rqstp) ? PTR_ERR(rqstp) : 0);
Benny Halevy8f975242009-04-01 09:23:11 -0400177 return rqstp;
Ricardo Labiagaa43cde92009-04-01 09:23:08 -0400178}
179
180static inline int nfs_minorversion_callback_svc_setup(u32 minorversion,
Stanislav Kinsbursky691c4572012-08-20 18:00:21 +0400181 struct svc_serv *serv,
Ricardo Labiagaa43cde92009-04-01 09:23:08 -0400182 struct svc_rqst **rqstpp, int (**callback_svc)(void *vrqstp))
183{
184 if (minorversion) {
Stanislav Kinsbursky691c4572012-08-20 18:00:21 +0400185 *rqstpp = nfs41_callback_up(serv);
Ricardo Labiagaa43cde92009-04-01 09:23:08 -0400186 *callback_svc = nfs41_callback_svc;
187 }
188 return minorversion;
189}
190
191static inline void nfs_callback_bc_serv(u32 minorversion, struct rpc_xprt *xprt,
Stanislav Kinsbursky691c4572012-08-20 18:00:21 +0400192 struct svc_serv *serv)
Ricardo Labiagaa43cde92009-04-01 09:23:08 -0400193{
194 if (minorversion)
Stanislav Kinsbursky691c4572012-08-20 18:00:21 +0400195 /*
196 * Save the svc_serv in the transport so that it can
197 * be referenced when the session backchannel is initialized
198 */
199 xprt->bc_serv = serv;
Ricardo Labiagaa43cde92009-04-01 09:23:08 -0400200}
201#else
Stanislav Kinsburskyc9465562012-08-20 18:00:16 +0400202static int nfs41_callback_up_net(struct svc_serv *serv, struct net *net)
203{
204 return 0;
205}
206
Ricardo Labiagaa43cde92009-04-01 09:23:08 -0400207static inline int nfs_minorversion_callback_svc_setup(u32 minorversion,
Stanislav Kinsbursky691c4572012-08-20 18:00:21 +0400208 struct svc_serv *serv,
Ricardo Labiagaa43cde92009-04-01 09:23:08 -0400209 struct svc_rqst **rqstpp, int (**callback_svc)(void *vrqstp))
210{
211 return 0;
212}
213
214static inline void nfs_callback_bc_serv(u32 minorversion, struct rpc_xprt *xprt,
Stanislav Kinsbursky691c4572012-08-20 18:00:21 +0400215 struct svc_serv *serv)
Ricardo Labiagaa43cde92009-04-01 09:23:08 -0400216{
217}
218#endif /* CONFIG_NFS_V4_1 */
219
Stanislav Kinsbursky8e246142012-08-20 18:00:26 +0400220static int nfs_callback_start_svc(int minorversion, struct rpc_xprt *xprt,
221 struct svc_serv *serv)
222{
223 struct svc_rqst *rqstp;
224 int (*callback_svc)(void *vrqstp);
225 struct nfs_callback_data *cb_info = &nfs_callback_info[minorversion];
226 char svc_name[12];
227 int ret;
228 int minorversion_setup;
229
230 nfs_callback_bc_serv(minorversion, xprt, serv);
231
Stanislav Kinsbursky23c20ec2012-08-20 18:00:31 +0400232 if (cb_info->task)
233 return 0;
234
Stanislav Kinsbursky8e246142012-08-20 18:00:26 +0400235 minorversion_setup = nfs_minorversion_callback_svc_setup(minorversion,
236 serv, &rqstp, &callback_svc);
237 if (!minorversion_setup) {
238 /* v4.0 callback setup */
239 rqstp = nfs4_callback_up(serv);
240 callback_svc = nfs4_callback_svc;
241 }
242
243 if (IS_ERR(rqstp))
244 return PTR_ERR(rqstp);
245
246 svc_sock_update_bufs(serv);
247
248 sprintf(svc_name, "nfsv4.%u-svc", minorversion);
249 cb_info->serv = serv;
250 cb_info->rqst = rqstp;
251 cb_info->task = kthread_run(callback_svc, cb_info->rqst, svc_name);
252 if (IS_ERR(cb_info->task)) {
253 ret = PTR_ERR(cb_info->task);
254 svc_exit_thread(cb_info->rqst);
255 cb_info->rqst = NULL;
256 cb_info->task = NULL;
257 return PTR_ERR(cb_info->task);
258 }
259 dprintk("nfs_callback_up: service started\n");
260 return 0;
261}
262
Stanislav Kinsburskyc9465562012-08-20 18:00:16 +0400263static int nfs_callback_up_net(int minorversion, struct svc_serv *serv, struct net *net)
264{
265 int ret;
266
267 dprintk("NFS: create per-net callback data; net=%p\n", net);
268
269 ret = svc_bind(serv, net);
270 if (ret < 0) {
271 printk(KERN_WARNING "NFS: bind callback service failed\n");
272 goto err_bind;
273 }
274
275 switch (minorversion) {
276 case 0:
277 ret = nfs4_callback_up_net(serv, net);
278 break;
279 case 1:
280 ret = nfs41_callback_up_net(serv, net);
281 break;
282 default:
283 printk(KERN_ERR "NFS: unknown callback version: %d\n",
284 minorversion);
285 ret = -EINVAL;
286 break;
287 }
288
289 if (ret < 0) {
290 printk(KERN_ERR "NFS: callback service start failed\n");
291 goto err_socks;
292 }
293 return 0;
294
295err_socks:
296 svc_rpcb_cleanup(serv, net);
297err_bind:
Stanislav Kinsbursky23c20ec2012-08-20 18:00:31 +0400298 dprintk("NFS: Couldn't create callback socket: err = %d; "
299 "net = %p\n", ret, net);
Stanislav Kinsburskyc9465562012-08-20 18:00:16 +0400300 return ret;
301}
302
Stanislav Kinsburskydd018422012-08-20 18:00:11 +0400303static struct svc_serv *nfs_callback_create_svc(int minorversion)
304{
305 struct nfs_callback_data *cb_info = &nfs_callback_info[minorversion];
306 struct svc_serv *serv;
307
308 /*
309 * Check whether we're already up and running.
310 */
311 if (cb_info->task) {
312 /*
313 * Note: increase service usage, because later in case of error
314 * svc_destroy() will be called.
315 */
316 svc_get(cb_info->serv);
317 return cb_info->serv;
318 }
319
320 /*
321 * Sanity check: if there's no task,
322 * we should be the first user ...
323 */
324 if (cb_info->users)
325 printk(KERN_WARNING "nfs_callback_create_svc: no kthread, %d users??\n",
326 cb_info->users);
327
328 serv = svc_create(&nfs4_callback_program, NFS4_CALLBACK_BUFSIZE, NULL);
329 if (!serv) {
330 printk(KERN_ERR "nfs_callback_create_svc: create service failed\n");
331 return ERR_PTR(-ENOMEM);
332 }
333 /* As there is only one thread we need to over-ride the
334 * default maximum of 80 connections
335 */
336 serv->sv_maxconn = 1024;
337 dprintk("nfs_callback_create_svc: service created\n");
338 return serv;
339}
340
Benny Halevy71468512009-04-01 09:22:56 -0400341/*
342 * Bring up the callback thread if it is not already up.
343 */
344int nfs_callback_up(u32 minorversion, struct rpc_xprt *xprt)
345{
Stanislav Kinsburskydd018422012-08-20 18:00:11 +0400346 struct svc_serv *serv;
Andy Adamsone82dc222009-04-01 09:23:14 -0400347 struct nfs_callback_data *cb_info = &nfs_callback_info[minorversion];
Stanislav Kinsbursky23c20ec2012-08-20 18:00:31 +0400348 int ret;
Stanislav Kinsburskyc9465562012-08-20 18:00:16 +0400349 struct net *net = xprt->xprt_net;
Benny Halevy71468512009-04-01 09:22:56 -0400350
351 mutex_lock(&nfs_callback_mutex);
Stanislav Kinsburskydd018422012-08-20 18:00:11 +0400352
353 serv = nfs_callback_create_svc(minorversion);
354 if (IS_ERR(serv)) {
355 ret = PTR_ERR(serv);
356 goto err_create;
357 }
358
Stanislav Kinsburskyc9465562012-08-20 18:00:16 +0400359 ret = nfs_callback_up_net(minorversion, serv, net);
360 if (ret < 0)
361 goto err_net;
Stanislav Kinsbursky9793f7c2012-05-02 16:08:38 +0400362
Stanislav Kinsbursky8e246142012-08-20 18:00:26 +0400363 ret = nfs_callback_start_svc(minorversion, xprt, serv);
364 if (ret < 0)
365 goto err_start;
Stanislav Kinsbursky691c4572012-08-20 18:00:21 +0400366
Stanislav Kinsbursky23c20ec2012-08-20 18:00:31 +0400367 cb_info->users++;
Jeff Layton8e600292008-02-11 10:00:20 -0500368 /*
369 * svc_create creates the svc_serv with sv_nrthreads == 1, and then
Jeff Laytona277e332008-02-20 08:55:30 -0500370 * svc_prepare_thread increments that. So we need to call svc_destroy
Jeff Layton8e600292008-02-11 10:00:20 -0500371 * on both success and failure so that the refcount is 1 when the
372 * thread exits.
373 */
Stanislav Kinsbursky23c20ec2012-08-20 18:00:31 +0400374err_net:
Stanislav Kinsburskydd018422012-08-20 18:00:11 +0400375 svc_destroy(serv);
376err_create:
Ingo Molnar353ab6e2006-03-26 01:37:12 -0800377 mutex_unlock(&nfs_callback_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 return ret;
Stanislav Kinsbursky8e246142012-08-20 18:00:26 +0400379
380err_start:
Stanislav Kinsburskyc9465562012-08-20 18:00:16 +0400381 svc_shutdown_net(serv, net);
Stanislav Kinsbursky23c20ec2012-08-20 18:00:31 +0400382 dprintk("NFS: Couldn't create server thread; err = %d\n", ret);
383 goto err_net;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384}
385
386/*
Jeff Layton5afc5972008-06-11 10:03:11 -0400387 * Kill the callback thread if it's no longer being used.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 */
Stanislav Kinsburskyc8ceb412012-08-20 18:00:06 +0400389void nfs_callback_down(int minorversion, struct net *net)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390{
Andy Adamsone82dc222009-04-01 09:23:14 -0400391 struct nfs_callback_data *cb_info = &nfs_callback_info[minorversion];
392
Ingo Molnar353ab6e2006-03-26 01:37:12 -0800393 mutex_lock(&nfs_callback_mutex);
Andy Adamsone82dc222009-04-01 09:23:14 -0400394 cb_info->users--;
395 if (cb_info->users == 0 && cb_info->task != NULL) {
396 kthread_stop(cb_info->task);
Stanislav Kinsburskyc8ceb412012-08-20 18:00:06 +0400397 svc_shutdown_net(cb_info->serv, net);
Andy Adamsone82dc222009-04-01 09:23:14 -0400398 svc_exit_thread(cb_info->rqst);
399 cb_info->serv = NULL;
400 cb_info->rqst = NULL;
401 cb_info->task = NULL;
Jeff Layton5afc5972008-06-11 10:03:11 -0400402 }
Ingo Molnar353ab6e2006-03-26 01:37:12 -0800403 mutex_unlock(&nfs_callback_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404}
405
Andy Adamson778be232011-01-25 15:38:01 +0000406/* Boolean check of RPC_AUTH_GSS principal */
407int
408check_gss_callback_principal(struct nfs_client *clp, struct svc_rqst *rqstp)
Olga Kornievskaia945b34a2008-12-23 16:18:34 -0500409{
J. Bruce Fields03a4e1f2012-05-14 19:55:22 -0400410 char *p = rqstp->rq_cred.cr_principal;
Olga Kornievskaia945b34a2008-12-23 16:18:34 -0500411
Andy Adamson778be232011-01-25 15:38:01 +0000412 if (rqstp->rq_authop->flavour != RPC_AUTH_GSS)
413 return 1;
414
Andy Adamsonece0de62011-01-06 02:04:33 +0000415 /* No RPC_AUTH_GSS on NFSv4.1 back channel yet */
416 if (clp->cl_minorversion != 0)
Andy Adamson778be232011-01-25 15:38:01 +0000417 return 0;
Olga Kornievskaia945b34a2008-12-23 16:18:34 -0500418 /*
419 * It might just be a normal user principal, in which case
420 * userspace won't bother to tell us the name at all.
421 */
422 if (p == NULL)
Andy Adamson778be232011-01-25 15:38:01 +0000423 return 0;
Olga Kornievskaia945b34a2008-12-23 16:18:34 -0500424
425 /* Expect a GSS_C_NT_HOSTBASED_NAME like "nfs@serverhostname" */
426
427 if (memcmp(p, "nfs@", 4) != 0)
Andy Adamson778be232011-01-25 15:38:01 +0000428 return 0;
Olga Kornievskaia945b34a2008-12-23 16:18:34 -0500429 p += 4;
Trond Myklebust4e0038b2012-03-01 17:01:05 -0500430 if (strcmp(p, clp->cl_hostname) != 0)
Andy Adamson778be232011-01-25 15:38:01 +0000431 return 0;
432 return 1;
Olga Kornievskaia945b34a2008-12-23 16:18:34 -0500433}
434
Andy Adamson778be232011-01-25 15:38:01 +0000435/*
436 * pg_authenticate method for nfsv4 callback threads.
437 *
438 * The authflavor has been negotiated, so an incorrect flavor is a server
439 * bug. Drop packets with incorrect authflavor.
440 *
441 * All other checking done after NFS decoding where the nfs_client can be
442 * found in nfs4_callback_compound
443 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444static int nfs_callback_authenticate(struct svc_rqst *rqstp)
445{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 switch (rqstp->rq_authop->flavour) {
Andy Adamson778be232011-01-25 15:38:01 +0000447 case RPC_AUTH_NULL:
448 if (rqstp->rq_proc != CB_NULL)
449 return SVC_DROP;
450 break;
451 case RPC_AUTH_GSS:
452 /* No RPC_AUTH_GSS support yet in NFSv4.1 */
453 if (svc_is_backchannel(rqstp))
454 return SVC_DROP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 }
Andy Adamson778be232011-01-25 15:38:01 +0000456 return SVC_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457}
458
459/*
460 * Define NFS4 callback program
461 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462static struct svc_version *nfs4_callback_version[] = {
463 [1] = &nfs4_callback_version1,
Alexandros Batsakis07bccc22009-12-05 13:19:01 -0500464 [4] = &nfs4_callback_version4,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465};
466
467static struct svc_stat nfs4_callback_stats;
468
469static struct svc_program nfs4_callback_program = {
470 .pg_prog = NFS4_CALLBACK, /* RPC service number */
471 .pg_nvers = ARRAY_SIZE(nfs4_callback_version), /* Number of entries */
472 .pg_vers = nfs4_callback_version, /* version table */
473 .pg_name = "NFSv4 callback", /* service name */
474 .pg_class = "nfs", /* authentication class */
475 .pg_stats = &nfs4_callback_stats,
476 .pg_authenticate = nfs_callback_authenticate,
477};