All of lore.kernel.org
 help / color / mirror / Atom feed
From: greearb@candelatech.com
To: linux-nfs@vger.kernel.org
Cc: Ben Greear <greearb@candelatech.com>
Subject: [PATCH v2 12/12] nfs: Support srcaddr= to bind to specific IP address.
Date: Thu, 23 Jun 2011 12:29:48 -0700	[thread overview]
Message-ID: <1308857388-12243-15-git-send-email-greearb@candelatech.com> (raw)
In-Reply-To: <1308857388-12243-1-git-send-email-greearb@candelatech.com>

From: Ben Greear <greearb@candelatech.com>

In order to have more control on multi-homed machines, it is
nice to be able to bind to a specific IP address.  This can aid
with interface selection, policy based routing, multiple unique
mounts to the same server, and similar things.

This patch allows srcaddr= option for NFS.  The key 'srcaddr'
was chosen to match the similar patch for cifs.

For NFSv4, if one is specifying clientaddr, it must be the same as
srcaddr or things may not work properly.

NFSv3, NFSv4 over TCP/IPv4 and TCP/IPv6 has been successfully tested.

Usage:
  mount -t nfs4 [2002::1]:/rpool/ben /mnt/foo/ben-1 -o srcaddr=2002::2,clientaddr=2002::2
  mount -t nfs4 192.168.100.3:/foo /mnt/foo/ben-2 -o srcaddr=192.168.100.174

Signed-off-by: Ben Greear <greearb@candelatech.com>
---
:100644 100644 e45f616... 5d88e7b... M	fs/nfs/super.c
 fs/nfs/super.c |   29 ++++++++++++++++++++++++++++-
 1 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index e45f616..5d88e7b 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -103,7 +103,7 @@ enum {
 
 	/* Mount options that take string arguments */
 	Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
-	Opt_addr, Opt_mountaddr, Opt_clientaddr,
+	Opt_addr, Opt_mountaddr, Opt_clientaddr, Opt_srcaddr,
 	Opt_lookupcache,
 	Opt_fscache_uniq,
 	Opt_local_lock,
@@ -173,6 +173,7 @@ static const match_table_t nfs_mount_option_tokens = {
 	{ Opt_mountproto, "mountproto=%s" },
 	{ Opt_addr, "addr=%s" },
 	{ Opt_clientaddr, "clientaddr=%s" },
+	{ Opt_srcaddr, "srcaddr=%s" },
 	{ Opt_mounthost, "mounthost=%s" },
 	{ Opt_mountaddr, "mountaddr=%s" },
 
@@ -695,6 +696,15 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
 	else
 		nfs_show_nfsv4_options(m, nfss, showdefaults);
 
+	if (clp->srcaddr.ss_family == AF_INET6) {
+		struct sockaddr_in6 *sin6;
+		sin6 = (struct sockaddr_in6 *)(&clp->srcaddr);
+		seq_printf(m, ",srcaddr=%pI6c", &sin6->sin6_addr);
+	} else if (clp->srcaddr.ss_family == AF_INET) {
+		struct sockaddr_in *sin = (struct sockaddr_in *)&clp->srcaddr;
+		seq_printf(m, ",srcaddr=%pI4", &sin->sin_addr.s_addr);
+	}
+
 	if (nfss->options & NFS_OPTION_FSCACHE)
 		seq_printf(m, ",fsc");
 
@@ -1448,6 +1458,23 @@ static int nfs_parse_mount_options(char *raw,
 				goto out_nomem;
 			mnt->options |= NFS_OPTION_FSCACHE;
 			break;
+		case Opt_srcaddr:
+			string = match_strdup(args);
+			if (string == NULL)
+				goto out_nomem;
+			mnt->srcaddr.addrlen =
+				rpc_pton(string, strlen(string),
+					 (struct sockaddr *)
+					 &mnt->srcaddr.address,
+					 sizeof(mnt->srcaddr.address));
+			kfree(string);
+			if (mnt->srcaddr.addrlen == 0) {
+				printk(KERN_WARNING
+				       "nfs: Could not parse srcaddr: %s\n",
+				       string);
+				goto out_invalid_address;
+			}
+			break;
 		case Opt_local_lock:
 			string = match_strdup(args);
 			if (string == NULL)
-- 
1.7.3.4


  parent reply	other threads:[~2011-06-23 19:30 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-23 19:29 [PATCH v2 00/12] NFS: Support binding to source address greearb
2011-06-23 19:29 ` [PATCH v2 01/12] sunrpc: Don't attempt to bind to AF_UNSPEC address greearb
2011-06-23 19:29 ` [PATCH v2 02/12] nfs: Two AF_UNSPEC addresses should always match each other greearb
2011-06-23 19:29 ` [PATCH v2 03/12] nfs: Add srcaddr member to nfs_client greearb
2011-06-23 19:29 ` [PATCH v2 04/12] nfs: Use request destination addr as callback source addr greearb
2011-06-23 19:29 ` [PATCH v2 05/12] nfs: Pay attention to srcaddr in v4.1 callback logic greearb
2011-06-23 19:29 ` [PATCH v2 06/12] nfs: Use srcaddr in nfs_match_client greearb
2011-06-23 19:29 ` [PATCH v2 07/12] nfs: Add srcaddr to /proc/fs/nfsfs/servers greearb
2011-06-23 19:29 ` [PATCH v2 08/12] nfs: Pass srcaddr into mount request greearb
2011-06-23 19:29 ` [PATCH v2 09/12] nfs: Propagate src-addr in client code greearb
2011-06-23 19:29 ` [PATCH v2 10/12] nfs: Bind to srcaddr in rpcb_create greearb
2011-06-23 19:29 ` [PATCH v2 11/12] lockd: Support binding nlm client to specific address greearb
2011-06-23 19:29 ` [PATCH v2 11/12] nfs: Support srcaddr= to bind to specific IP address greearb
2011-06-23 19:29 ` [PATCH v2 12/12] lockd: Support binding nlm client to specific address greearb
2011-06-23 19:29 ` greearb [this message]
2011-07-07 21:26 ` [PATCH v2 00/12] NFS: Support binding to source address Ben Greear

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=1308857388-12243-15-git-send-email-greearb@candelatech.com \
    --to=greearb@candelatech.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.