public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@redhat.com>
To: linux-nfs@vger.kernel.org
Cc: chuck.lever@oracle.com, bfields@fieldses.org
Subject: [PATCH 2/4] nfsd: break out setclientid port parsing into separate routine
Date: Wed, 17 Jun 2009 14:15:39 -0400	[thread overview]
Message-ID: <1245262541-9362-3-git-send-email-jlayton@redhat.com> (raw)
In-Reply-To: <1245262541-9362-1-git-send-email-jlayton@redhat.com>

...and change the parse_ipv4 routine to be a little more efficient with
the stack.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
 fs/nfsd/nfs4state.c |   46 ++++++++++++++++++++++++++++++----------------
 1 files changed, 30 insertions(+), 16 deletions(-)

diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index edb03d4..6a12219 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -930,15 +930,40 @@ parse_octet(unsigned int *lenp, char **addrp)
 	return n;
 }
 
+/*
+ * Parse port out of setclientid callback address
+ *
+ * @addrlen: remaining length of address string
+ * @addr: pointer to first port octet in address string
+ * @sa: pointer to port field in sockaddr
+ *
+ * Parse the port portion of a setclientid callback address. Returns true on
+ * success and false on failure.
+ */
+static bool
+parse_port(unsigned int addrlen, char *addr, __be16 *port)
+{
+	int temp = 0, i, shift = 8;
+	u16 cbport = 0;
+
+	for (i = 2; i > 0; i--) {
+		temp = parse_octet(&addrlen, &addr);
+		if (temp < 0)
+			return 0;
+		cbport |= (temp << shift);
+		if (shift > 0)
+			shift -= 8;
+	}
+	*port = htons(cbport);
+	return 1;
+}
+
 /* parse and set the setclientid ipv4 callback address */
 static int
-parse_ipv4(unsigned int addr_len, char *addr_val, struct sockaddr_in *s4)
+parse_ipv4(unsigned int addrlen, char *addr, struct sockaddr_in *s4)
 {
 	int temp = 0;
 	u32 cbaddr = 0;
-	u16 cbport = 0;
-	u32 addrlen = addr_len;
-	char *addr = addr_val;
 	int i, shift;
 
 	s4->sin_family = AF_INET;
@@ -955,18 +980,7 @@ parse_ipv4(unsigned int addr_len, char *addr_val, struct sockaddr_in *s4)
 	}
 	s4->sin_addr.s_addr = htonl(cbaddr);
 
-	/* port */
-	shift = 8;
-	for(i = 2; i > 0  ; i--) {
-		if ((temp = parse_octet(&addrlen, &addr)) < 0) {
-			return 0;
-		}
-		cbport |= (temp << shift);
-		if (shift > 0)
-			shift -= 8;
-	}
-	s4->sin_port = htons(cbport);
-	return 1;
+	return parse_port(addrlen, addr, &s4->sin_port);
 }
 
 static void
-- 
1.6.0.6


  parent reply	other threads:[~2009-06-17 18:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-17 18:15 [PATCH 0/4] nfsd: add support for NFSv4 callbacks over IPv6 Jeff Layton
2009-06-17 18:15 ` [PATCH 1/4] nfsd: convert nfs4_callback struct to hold address in sockaddr_storage Jeff Layton
2009-06-17 18:15 ` Jeff Layton [this message]
2009-06-17 18:15 ` [PATCH 3/4] nfsd: make nfs4_client->cl_addr a struct sockaddr_storage Jeff Layton
2009-06-17 18:15 ` [PATCH 4/4] nfsd: add support for NFSv4 callbacks over IPv6 Jeff Layton
2009-06-17 18:47 ` [PATCH 0/4] " J. Bruce Fields
2009-06-17 19:01   ` Jeff Layton

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=1245262541-9362-3-git-send-email-jlayton@redhat.com \
    --to=jlayton@redhat.com \
    --cc=bfields@fieldses.org \
    --cc=chuck.lever@oracle.com \
    --cc=linux-nfs@vger.kernel.org \
    /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