]> git.decadent.org.uk Git - nfs-utils.git/blob - utils/statd/callback.c
nfs-utils: Provide type-checked version of svc_getcaller()
[nfs-utils.git] / utils / statd / callback.c
1 /*
2  * Copyright (C) 1995, 1997-1999 Jeffrey A. Uphoff
3  * Modified by Olaf Kirch, Oct. 1996.
4  * Modified by Lon Hohberger, Oct. 2000.
5  *
6  * NSM for Linux.
7  */
8
9 #ifdef HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12
13 #include <arpa/inet.h>
14
15 #include "rpcmisc.h"
16 #include "misc.h"
17 #include "statd.h"
18 #include "notlist.h"
19
20 /* Callback notify list. */
21 /* notify_list *cbnl = NULL; ... never used */
22
23
24 /* 
25  * Services SM_NOTIFY requests.
26  * Any clients that have asked us to monitor that host are put on
27  * the global callback list, which is processed as soon as statd
28  * returns to svc_run.
29  */
30 void *
31 sm_notify_1_svc(struct stat_chge *argp, struct svc_req *rqstp)
32 {
33         notify_list    *lp, *call;
34         static char    *result = NULL;
35         struct sockaddr_in *sin = nfs_getrpccaller_in(rqstp->rq_xprt);
36         char *ip_addr = xstrdup(inet_ntoa(sin->sin_addr));
37
38         dprintf(N_DEBUG, "Received SM_NOTIFY from %s, state: %d",
39                                 argp->mon_name, argp->state);
40
41         /* quick check - don't bother if we're not monitoring anyone */
42         if (rtnl == NULL) {
43                 note(N_WARNING, "SM_NOTIFY from %s while not monitoring any hosts.",
44                                 argp->mon_name);
45                 return ((void *) &result);
46         }
47
48         /* okir change: statd doesn't remove the remote host from its
49          * internal monitor list when receiving an SM_NOTIFY call from
50          * it. Lockd will want to continue monitoring the remote host
51          * until it issues an SM_UNMON call.
52          */
53         for (lp = rtnl ; lp ; lp = lp->next)
54                 if (NL_STATE(lp) != argp->state &&
55                     (matchhostname(argp->mon_name, lp->dns_name) ||
56                      matchhostname(ip_addr, lp->dns_name))) {
57                         NL_STATE(lp) = argp->state;
58                         call = nlist_clone(lp);
59                         nlist_insert(&notify, call);
60                 }
61
62
63         return ((void *) &result);
64 }