]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - utils/statd/rmtcall.c
Remove notify functionality from statd in favour of sm-notify
[nfs-utils.git] / utils / statd / rmtcall.c
index f6798f9b29b9e5623dd9617dd529b09b8b5cad34..362e1f6c7b13eadadae836c07f98abb5b79ceccd 100644 (file)
  * it won't if it's worth its money).
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/time.h>
 #include <netinet/in.h>
+#include <net/if.h>
 #include <arpa/inet.h>
 #include <rpc/rpc.h>
 #include <rpc/pmap_prot.h>
 #include <netdb.h>
 #include <string.h>
 #include <unistd.h>
+#ifdef HAVE_IFADDRS_H
+#include <ifaddrs.h>
+#endif /* HAVE_IFADDRS_H */
 #include "sm_inter.h"
 #include "statd.h"
 #include "notlist.h"
 #include "log.h"
 #include "ha-callout.h"
 
+#if SIZEOF_SOCKLEN_T - 0 == 0
+#define socklen_t int
+#endif
+
 #define MAXMSGSIZE     (2048 / sizeof(unsigned int))
 
 static unsigned long   xid = 0;        /* RPC XID counter */
@@ -49,7 +59,7 @@ static int            sockfd = -1;    /* notify socket */
  * Initialize callback socket
  */
 int
-statd_get_socket(int port)
+statd_get_socket(void)
 {
        struct sockaddr_in      sin;
 
@@ -65,22 +75,12 @@ statd_get_socket(int port)
 
        memset(&sin, 0, sizeof(sin));
        sin.sin_family = AF_INET;
-       sin.sin_port = port;
-       /*
-        * If a local hostname is given (-n option to statd), bind to the address
-        * specified. This is required to support clients that ignore the mon_name in
-        * the statd protocol but use the source address from the request packet.
-        */
-       if (MY_NAME) {
-               struct hostent *hp = gethostbyname(MY_NAME);
-               if (hp)
-                       sin.sin_addr = *(struct in_addr *) hp->h_addr;
-       }
+       sin.sin_addr.s_addr = INADDR_ANY;
+
        if (bindresvport(sockfd, &sin) < 0) {
                dprintf(N_WARNING,
                        "process_hosts: can't bind to reserved port\n");
        }
-
        return sockfd;
 }
 
@@ -96,10 +96,7 @@ try_to_resolve(notify_list *lp)
 {
        char            *hname;
 
-       if (NL_TYPE(lp) == NOTIFY_REBOOT)
-               hname = NL_MON_NAME(lp);
-       else
-               hname = NL_MY_NAME(lp);
+       hname = NL_MY_NAME(lp);
        if (!inet_aton(hname, &(NL_ADDR(lp)))) {
                note(N_ERROR, "%s is not an dotted-quad address", hname);
                NL_TIMES(lp) = 0;
@@ -119,10 +116,7 @@ try_to_resolve(notify_list *lp)
        struct hostent  *hp;
        char            *hname;
 
-       if (NL_TYPE(lp) == NOTIFY_REBOOT)
-               hname = NL_MON_NAME(lp);
-       else
-               hname = NL_MY_NAME(lp);
+       hname = NL_MY_NAME(lp);
 
        dprintf(N_DEBUG, "Trying to resolve %s.", hname);
        if (!(hp = gethostbyname(hname))) {
@@ -219,7 +213,7 @@ recv_rply(int sockfd, struct sockaddr_in *sin, u_long *portp)
        struct rpc_msg          mesg;
        notify_list             *lp = NULL;
        XDR                     xdr, *xdrs = &xdr;
-       int                     alen = sizeof(*sin);
+       socklen_t               alen = sizeof(*sin);
 
        /* Receive message */
        if ((msglen = recvfrom(sockfd, msgbuf, sizeof(msgbuf), 0,
@@ -311,38 +305,19 @@ process_entry(int sockfd, notify_list *lp)
        sin.sin_port   = lp->port;
        /* LH - moved address into switch */
 
-       switch (NL_TYPE(lp)) {
-       case NOTIFY_REBOOT:
-               prog = SM_PROG;
-               vers = SM_VERS;
-               proc = SM_NOTIFY;
+       prog = NL_MY_PROG(lp);
+       vers = NL_MY_VERS(lp);
+       proc = NL_MY_PROC(lp);
 
-               /* Use source address for notify replies */
-               sin.sin_addr   = lp->addr;
+       /* __FORCE__ loopback for callbacks to lockd ... */
+       /* Just in case we somehow ignored it thus far */
+       sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
 
-               func = (xdrproc_t) xdr_stat_chge;
-               objp = &SM_stat_chge;
-               break;
-       case NOTIFY_CALLBACK:
-               prog = NL_MY_PROG(lp);
-               vers = NL_MY_VERS(lp);
-               proc = NL_MY_PROC(lp);
-
-               /* __FORCE__ loopback for callbacks to lockd ... */
-               /* Just in case we somehow ignored it thus far */
-               sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
-
-               func = (xdrproc_t) xdr_status;
-               objp = &new_status;
-               new_status.mon_name = NL_MON_NAME(lp);
-               new_status.state    = NL_STATE(lp);
-               memcpy(new_status.priv, NL_PRIV(lp), SM_PRIV_SIZE);
-               break;
-       default:
-               note(N_ERROR, "notify_host: unknown notify type %d",
-                               NL_TYPE(lp));
-               return 0;
-       }
+       func = (xdrproc_t) xdr_status;
+       objp = &new_status;
+       new_status.mon_name = NL_MON_NAME(lp);
+       new_status.state    = NL_STATE(lp);
+       memcpy(new_status.priv, NL_PRIV(lp), SM_PRIV_SIZE);
 
        lp->xid = xmit_call(sockfd, &sin, prog, vers, proc, func, objp);
        if (!lp->xid) {
@@ -380,12 +355,7 @@ process_reply(FD_SET_TYPE *rfds)
                        return 1;
                }
                note(N_WARNING, "recv_rply: [%s] service %d not registered",
-                       inet_ntoa(lp->addr),
-                       NL_TYPE(lp) == NOTIFY_REBOOT? SM_PROG : NL_MY_PROG(lp));
-       } else if (NL_TYPE(lp) == NOTIFY_REBOOT) {
-               dprintf(N_DEBUG, "Notification of %s succeeded.",
-                       NL_MON_NAME(lp));
-               xunlink(SM_BAK_DIR, NL_MON_NAME(lp), 0);
+                       inet_ntoa(lp->addr), NL_MY_PROG(lp));
        } else {
                dprintf(N_DEBUG, "Callback to %s (for %d) succeeded.",
                        NL_MY_NAME(lp), NL_MON_NAME(lp));
@@ -406,7 +376,7 @@ process_notify_list(void)
        time_t          now;
        int             fd;
 
-       if ((fd = statd_get_socket(0)) < 0)
+       if ((fd = statd_get_socket()) < 0)
                return 0;
 
        while ((entry = notify) != NULL && NL_WHEN(entry) < time(&now)) {
@@ -414,21 +384,13 @@ process_notify_list(void)
                        NL_WHEN(entry) = time(NULL) + NOTIFY_TIMEOUT;
                        nlist_remove(&notify, entry);
                        nlist_insert_timer(&notify, entry);
-               } else if (NL_TYPE(entry) == NOTIFY_CALLBACK) {
+               } else {
                        note(N_ERROR,
                                "Can't callback %s (%d,%d), giving up.",
                                        NL_MY_NAME(entry),
                                        NL_MY_PROG(entry),
                                        NL_MY_VERS(entry));
                        nlist_free(&notify, entry);
-               } else {
-                       note(N_ERROR,
-                               "Can't notify %s, giving up.",
-                                       NL_MON_NAME(entry));
-                       /* PRC: do the HA callout */
-                       ha_callout("del-client", NL_MON_NAME(entry), NL_MY_NAME(entry), -1);
-                       xunlink(SM_BAK_DIR, NL_MON_NAME(entry), 0);
-                       nlist_free(&notify, entry);
                }
        }