public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Chuck Lever <chuck.lever@oracle.com>
To: steved@redhat.com
Cc: linux-nfs@vger.kernel.org, Chris.Mason@oracle.com
Subject: [PATCH 10/29] statd: Support sending SM_NOTIFY requests to IPv6 remotes
Date: Tue, 10 Nov 2009 16:57:57 -0500	[thread overview]
Message-ID: <20091110215757.23822.85641.stgit@matisse.1015granger.net> (raw)
In-Reply-To: <20091110215447.23822.15275.stgit-RytpoXr2tKZ9HhUboXbp9zCvJB+x5qRC@public.gmane.org>

Replace the open code to construct SM_NOTIFY and PMAP_GETPORT RPC
requests with calls to our new library routines that support
IPv6 and RPCB_GETADDR as well.

This change allows sm-notify to send RPCB_GETADDR, but it won't do
that until the main sm-notify socket supports PF_INET6, and the DNS
resolution logic is updated to return IPv6 addresses.

I would prefer to use high level RPC client library calls to send
these requests instead of this open coded solution.  That would give
us a number of benefits, including support for sending SM_NOTIFY via
TCP so we can penetrate firewalls that block UDP.

However, that would also involve replacing the scheduler logic in
sm-notify with something like fork(3) or pthreads, to deal with the
synchronous RPC client library calls.  That's probably too much for
folks to swallow right now.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---

 utils/statd/sm-notify.c |  110 +++++++++++------------------------------------
 1 files changed, 26 insertions(+), 84 deletions(-)

diff --git a/utils/statd/sm-notify.c b/utils/statd/sm-notify.c
index 6466d8a..9ed5df1 100644
--- a/utils/statd/sm-notify.c
+++ b/utils/statd/sm-notify.c
@@ -38,7 +38,6 @@
 #define NSM_TIMEOUT	2
 #define NSM_NOTIFY	6
 #define NSM_MAX_TIMEOUT	120	/* don't make this too big */
-#define MAXMSGSIZE	256
 
 struct nsm_host {
 	struct nsm_host *	next;
@@ -388,14 +387,6 @@ notify_host(int sock, struct nsm_host *host)
 {
 	struct sockaddr_storage address;
 	struct sockaddr *dest = (struct sockaddr *)&address;
-	static unsigned int	xid = 0;
-	uint32_t		msgbuf[MAXMSGSIZE], *p;
-	unsigned int		len;
-
-	if (!xid)
-		xid = getpid() + time(NULL);
-	if (!host->xid)
-		host->xid = xid++;
 
 	if (host->ai == NULL) {
 		host->ai = smn_lookup(host->name);
@@ -406,12 +397,6 @@ notify_host(int sock, struct nsm_host *host)
 		}
 	}
 
-	memset(msgbuf, 0, sizeof(msgbuf));
-	p = msgbuf;
-	*p++ = htonl(host->xid);
-	*p++ = 0;
-	*p++ = htonl(2);
-
 	/* If we retransmitted 4 times, reset the port to force
 	 * a new portmap lookup (in case statd was restarted).
 	 * We also rotate through multiple IP addresses at this
@@ -446,48 +431,13 @@ notify_host(int sock, struct nsm_host *host)
 	}
 
 	memcpy(dest, &host->addr, host->addrlen);
-	if (nfs_get_port(dest) == 0) {
-		/* Build a PMAP packet */
-		xlog(D_GENERAL, "Sending portmap query to %s", host->name);
-
-		nfs_set_port(dest, 111);
-		*p++ = htonl(100000);
-		*p++ = htonl(2);
-		*p++ = htonl(3);
-
-		/* Auth and verf */
-		*p++ = 0; *p++ = 0;
-		*p++ = 0; *p++ = 0;
-
-		*p++ = htonl(NSM_PROGRAM);
-		*p++ = htonl(NSM_VERSION);
-		*p++ = htonl(IPPROTO_UDP);
-		*p++ = 0;
-	} else {
-		/* Build an SM_NOTIFY packet */
-		xlog(D_GENERAL, "Sending SM_NOTIFY to %s", host->name);
-
-		*p++ = htonl(NSM_PROGRAM);
-		*p++ = htonl(NSM_VERSION);
-		*p++ = htonl(NSM_NOTIFY);
-
-		/* Auth and verf */
-		*p++ = 0; *p++ = 0;
-		*p++ = 0; *p++ = 0;
-
-		/* state change */
-		len = strlen(nsm_hostname);
-		*p++ = htonl(len);
-		memcpy(p, nsm_hostname, len);
-		p += (len + 3) >> 2;
-		*p++ = htonl(nsm_state);
-	}
-	len = (p - msgbuf) << 2;
-
-	if (sendto(sock, msgbuf, len, 0, dest, host->addrlen) < 0)
-		xlog_warn("Sending Reboot Notification to "
-			"'%s' failed: errno %d (%m)", host->name, errno);
-
+	if (nfs_get_port(dest) == 0)
+		host->xid = nsm_xmit_rpcbind(sock, dest,
+				NSM_PROGRAM, NSM_VERSION);
+	else
+		host->xid = nsm_xmit_notify(sock, dest, host->addrlen,
+				NSM_PROGRAM, nsm_hostname, nsm_state);
+	
 	return 0;
 }
 
@@ -499,40 +449,32 @@ recv_reply(int sock)
 {
 	struct nsm_host	*hp;
 	struct sockaddr *sap;
-	uint32_t	msgbuf[MAXMSGSIZE], *p, *end;
+	uint32_t	msgbuf[NSM_MAXMSGSIZE];
 	uint32_t	xid;
-	int		res;
+	ssize_t		msglen;
+	XDR		xdr, *xdrs = &xdr;
 
-	res = recv(sock, msgbuf, sizeof(msgbuf), 0);
-	if (res < 0)
+	msglen = recv(sock, msgbuf, sizeof(msgbuf), 0);
+	if (msglen < 0)
 		return;
 
 	xlog(D_GENERAL, "Received packet...");
 
-	p = msgbuf;
-	end = p + (res >> 2);
-
-	xid = ntohl(*p++);
-	if (*p++ != htonl(1)	/* must be REPLY */
-	 || *p++ != htonl(0)	/* must be ACCEPTED */
-	 || *p++ != htonl(0)	/* must be NULL verifier */
-	 || *p++ != htonl(0)
-	 || *p++ != htonl(0))	/* must be SUCCESS */
-		return;
+	xdrmem_create(xdrs, (caddr_t)msgbuf, msglen, XDR_DECODE);
+	xid = nsm_parse_reply(xdrs);
+	if (xid == 0)
+		goto out;
 
 	/* Before we look at the data, find the host struct for
 	   this reply */
 	if ((hp = find_host(xid)) == NULL)
-		return;
+		goto out;
 	sap = (struct sockaddr *)&hp->addr;
 
 	if (nfs_get_port(sap) == 0) {
-		/* This was a portmap request */
-		unsigned int	port;
+		uint16_t port;
 
-		port = ntohl(*p++);
-		if (p > end)
-			goto fail;
+		port = nsm_recv_rpcbind(sap->sa_family, xdrs);
 
 		hp->send_next = time(NULL);
 		if (port == 0) {
@@ -553,16 +495,16 @@ recv_reply(int sock)
 		 * check that we didn't read past the end of the
 		 * packet)
 		 */
-		if (p <= end) {
-			xlog(D_GENERAL, "Host %s notified successfully",
-					hp->name);
-			smn_forget_host(hp);
-			return;
-		}
+		xlog(D_GENERAL, "Host %s notified successfully",
+				hp->name);
+		smn_forget_host(hp);
+		goto out;
 	}
 
-fail:	/* Re-insert the host */
 	insert_host(hp);
+
+out:
+	xdr_destroy(xdrs);
 }
 
 /*


  parent reply	other threads:[~2009-11-10 21:58 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-10 21:56 [PATCH 00/29] IPv6 support for statd Chuck Lever
     [not found] ` <20091110215447.23822.15275.stgit-RytpoXr2tKZ9HhUboXbp9zCvJB+x5qRC@public.gmane.org>
2009-11-10 21:56   ` [PATCH 01/29] statd: Replace note() with xlog() in rpc.statd Chuck Lever
2009-11-10 21:56   ` [PATCH 02/29] statd: Replace nsm_log() with xlog() in sm-notify command Chuck Lever
2009-11-10 21:56   ` [PATCH 03/29] statd: replace smn_{get, set}_port() with the shared equivalents Chuck Lever
2009-11-10 21:56   ` [PATCH 04/29] statd: fix address copy in sm-notify.c Chuck Lever
2009-11-10 21:56   ` [PATCH 05/29] libnsm.a: Move the sm_inter XDR pieces to libnsm.a Chuck Lever
2009-11-10 21:57   ` [PATCH 06/29] libnsm.a: Introduce common routines to handle persistent storage Chuck Lever
2009-11-10 21:57   ` [PATCH 07/29] statd: Use the new nsm_ file.c calls in sm_notify Chuck Lever
2009-11-10 21:57   ` [PATCH 08/29] statd: Use the new nsm_ file.c calls in rpc.statd Chuck Lever
2009-11-10 21:57   ` [PATCH 09/29] libnsm.a: Add RPC construction helper functions Chuck Lever
2009-11-10 21:57   ` Chuck Lever [this message]
2009-11-10 21:58   ` [PATCH 11/29] statd: Update rmtcall.c Chuck Lever
2009-11-10 21:58   ` [PATCH 12/29] statd: factor socket creation out of notify() Chuck Lever
2009-11-10 21:58   ` [PATCH 13/29] statd: Support creating a PF_INET6 socket in smn_create_socket() Chuck Lever
2009-11-10 21:58   ` [PATCH 14/29] statd: IPv6 support in reserved port binding " Chuck Lever
2009-11-10 21:58   ` [PATCH 15/29] statd: Use getaddrinfo(3) to generate bind address " Chuck Lever
2009-11-10 21:58   ` [PATCH 16/29] statd: Support IPv6 DNS lookups in smn_lookup Chuck Lever
2009-11-10 21:59   ` [PATCH 17/29] statd: squelch compiler warning in sm-notify.c Chuck Lever
2009-11-10 21:59   ` [PATCH 19/29] statd: add nsm_present_address() API Chuck Lever
2009-11-10 21:59   ` [PATCH 20/29] statd: add IPv6 support in sm_notify_1_svc() Chuck Lever
2009-11-10 21:59   ` [PATCH 21/29] statd: Support IPv6 is caller_is_localhost() Chuck Lever
2009-11-10 21:59   ` [PATCH 22/29] statd: Support IPv6 in sm_simu_crash_1_svc Chuck Lever
2009-11-10 21:59   ` [PATCH 23/29] statd: Support IPv6 in sm_mon_1_svc() Chuck Lever
2009-11-10 22:00   ` [PATCH 24/29] statd: Support IPv6 in sm_stat_1_svc() Chuck Lever
2009-11-10 22:00   ` [PATCH 25/29] libnsm.a: retain CAP_NET_BIND when dropping privileges Chuck Lever
2009-11-10 22:00   ` [PATCH 26/29] statd: Support TI-RPC statd listener Chuck Lever
2009-11-10 22:00   ` [PATCH 27/29] statd: update rpc.statd(8) and sm-notify(8) to reflect IPv6 support Chuck Lever
2009-11-10 22:01   ` [PATCH 28/29] statd: Use my_name when sending SM_NOTIFY requests Chuck Lever
2009-11-10 22:01   ` [PATCH 29/29] statd: Send unqualified and fully qualified mon_name in SM_NOTIFY Chuck Lever
2009-11-12 16:04   ` [PATCH 00/29] IPv6 support for statd Chuck Lever
2009-11-12 16:33     ` Steve Dickson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091110215757.23822.85641.stgit@matisse.1015granger.net \
    --to=chuck.lever@oracle.com \
    --cc=Chris.Mason@oracle.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=steved@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox