]> git.decadent.org.uk Git - nfs-utils.git/blob - utils/statd/callback.c
statd: add IPv6 support in sm_notify_1_svc()
[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 <netdb.h>
14
15 #include "rpcmisc.h"
16 #include "statd.h"
17 #include "notlist.h"
18
19 /* Callback notify list. */
20 /* notify_list *cbnl = NULL; ... never used */
21
22
23 /*
24  * Services SM_NOTIFY requests.
25  *
26  * When NLM uses an SM_MON request to tell statd to monitor a remote,
27  * the request contains a "mon_name" argument.  This is usually the
28  * "caller_name" argument of an NLMPROC_LOCK request.  On Linux, the
29  * NLM can send statd the remote's IP address instead of its
30  * caller_name.  The NSM protocol does not allow both the remote's
31  * caller_name and it's IP address to be sent in the same SM_MON
32  * request.
33  *
34  * The remote's caller_name is useful because it makes it simple
35  * to identify rebooting remotes by matching the "mon_name" argument
36  * they sent via an SM_NOTIFY request.
37  *
38  * The caller_name string may not be a fully qualified domain name,
39  * or even registered in the DNS database, however.  Having the
40  * remote's IP address is useful because then there is no ambiguity
41  * about where to send an SM_NOTIFY after the local system reboots.
42  *
43  * Without the actual caller_name, however, statd must use an
44  * heuristic to match an incoming SM_NOTIFY request to one of the
45  * hosts it is currently monitoring.  The incoming mon_name in an
46  * SM_NOTIFY address is converted to a list of IP addresses using
47  * DNS.  Each mon_name on statd's monitor list is also converted to
48  * an address list, and the two lists are checked to see if there is
49  * a matching address.
50  *
51  * There are some risks to this strategy:
52  *
53  *   1.  The external DNS database is not reliable.  It can change
54  *       over time, or the forward and reverse mappings could be
55  *       inconsistent.
56  *
57  *   2.  If statd's monitor list becomes substantial, finding a match
58  *       can generate a not inconsequential amount of DNS traffic.
59  *
60  *   3.  statd is a single-threaded service.  When DNS becomes slow or
61  *       unresponsive, statd also becomes slow or unresponsive.
62  *
63  *   4.  If the remote does not have a DNS entry at all (or if the
64  *       remote can resolve itself, but the local host can't resolve
65  *       the remote's hostname), the remote cannot be monitored, and
66  *       therefore NLM locking cannot be provided for that host.
67  *
68  *   5.  Local DNS resolution can produce different results for the
69  *       mon_name than the results the remote might see for the same
70  *       query, especially if the remote did not send a caller_name
71  *       or mon_name that is a fully qualified domain name.
72  *
73  *       Note that a caller_name is passed from NFS client to server,
74  *       but the client never knows what mon_name the server might use
75  *       to notify it of a reboot.  On Linux, the client extracts the
76  *       server's name from the devname it was passed by the mount
77  *       command.  This is often not a fully-qualified domain name.
78  */
79 void *
80 sm_notify_1_svc(struct stat_chge *argp, struct svc_req *rqstp)
81 {
82         notify_list    *lp, *call;
83         static char    *result = NULL;
84         struct sockaddr *sap = nfs_getrpccaller(rqstp->rq_xprt);
85         char            ip_addr[INET6_ADDRSTRLEN];
86
87         xlog(D_CALL, "Received SM_NOTIFY from %s, state: %d",
88                                 argp->mon_name, argp->state);
89
90         /* quick check - don't bother if we're not monitoring anyone */
91         if (rtnl == NULL) {
92                 xlog_warn("SM_NOTIFY from %s while not monitoring any hosts",
93                                 argp->mon_name);
94                 return ((void *) &result);
95         }
96
97         if (!statd_present_address(sap, ip_addr, sizeof(ip_addr))) {
98                 xlog_warn("Unrecognized sender address");
99                 return ((void *) &result);
100         }
101
102         /* okir change: statd doesn't remove the remote host from its
103          * internal monitor list when receiving an SM_NOTIFY call from
104          * it. Lockd will want to continue monitoring the remote host
105          * until it issues an SM_UNMON call.
106          */
107         for (lp = rtnl ; lp ; lp = lp->next)
108                 if (NL_STATE(lp) != argp->state &&
109                     (statd_matchhostname(argp->mon_name, lp->dns_name) ||
110                      statd_matchhostname(ip_addr, lp->dns_name))) {
111                         NL_STATE(lp) = argp->state;
112                         call = nlist_clone(lp);
113                         nlist_insert(&notify, call);
114                 }
115
116
117         return ((void *) &result);
118 }