From patchwork Fri Jun 10 19:41:36 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Greear X-Patchwork-Id: 870492 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p5AJgBI3019948 for ; Fri, 10 Jun 2011 19:43:07 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754222Ab1FJTnG (ORCPT ); Fri, 10 Jun 2011 15:43:06 -0400 Received: from mail.candelatech.com ([208.74.158.172]:43018 "EHLO ns3.lanforge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757878Ab1FJTnF (ORCPT ); Fri, 10 Jun 2011 15:43:05 -0400 Received: from fs3.candelatech.com (firewall.candelatech.com [70.89.124.249]) by ns3.lanforge.com (8.14.2/8.14.2) with ESMTP id p5AJfuxC003644 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 10 Jun 2011 12:41:57 -0700 From: greearb@candelatech.com To: linux-nfs@vger.kernel.org Cc: Ben Greear Subject: [PATCH v2 4/6] nfs-utils: Support srcaddr=n option for string mount. Date: Fri, 10 Jun 2011 12:41:36 -0700 Message-Id: <1307734898-12860-5-git-send-email-greearb@candelatech.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1307734898-12860-1-git-send-email-greearb@candelatech.com> References: <1307734898-12860-1-git-send-email-greearb@candelatech.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 10 Jun 2011 19:43:07 +0000 (UTC) From: Ben Greear Look for and parse the srcaddr=n argument. If parsing succeeds, pass this down the call chain. This fully implements binding to a specified source address when mounting. Signed-off-by: Ben Greear --- :100644 100644 71417df... aba4252... M utils/mount/stropts.c utils/mount/stropts.c | 29 +++++++++++++++++++++++++---- 1 files changed, 25 insertions(+), 4 deletions(-) diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c index 71417df..aba4252 100644 --- a/utils/mount/stropts.c +++ b/utils/mount/stropts.c @@ -92,6 +92,7 @@ struct nfsmount_info { int flags, /* MS_ flags */ fake, /* actually do the mount? */ child; /* forked bg child? */ + struct local_bind_info *local_ip; /* Local IP binding info */ }; #ifdef MOUNT_CONFIG @@ -345,6 +346,7 @@ static int nfs_validate_options(struct nfsmount_info *mi) }; sa_family_t family; int error; + char *option; if (!nfs_parse_devname(mi->spec, &mi->hostname, NULL)) return 0; @@ -371,6 +373,20 @@ static int nfs_validate_options(struct nfsmount_info *mi) mi->address->ai_addrlen, mi->options)) return 0; + option = po_get(mi->options, "srcaddr"); + if (option) { + struct local_bind_info *local_ip; + local_ip = malloc(sizeof(*local_ip)); + memset(local_ip, 0, sizeof(*local_ip)); + parse_local_bind(local_ip, option); + + if (!local_ip->is_set) { + free(local_ip); + return 0; + } + mi->local_ip = local_ip; + } + return 1; } @@ -484,7 +500,8 @@ static int nfs_construct_new_options(struct mount_options *options, * FALSE is returned if some failure occurred. */ static int -nfs_rewrite_pmap_mount_options(struct mount_options *options) +nfs_rewrite_pmap_mount_options(struct mount_options *options, + struct local_bind_info *local_ip) { union nfs_sockaddr nfs_address; struct sockaddr *nfs_saddr = &nfs_address.sa; @@ -534,7 +551,8 @@ nfs_rewrite_pmap_mount_options(struct mount_options *options) * negotiate. Bail now if we can't contact it. */ if (!nfs_probe_bothports(mnt_saddr, mnt_salen, &mnt_pmap, - nfs_saddr, nfs_salen, &nfs_pmap, NULL)) { + nfs_saddr, nfs_salen, &nfs_pmap, + local_ip)) { errno = ESPIPE; if (rpc_createerr.cf_stat == RPC_PROGNOTREGISTERED) errno = EOPNOTSUPP; @@ -589,7 +607,7 @@ static int nfs_sys_mount(struct nfsmount_info *mi, struct mount_options *opts) } static int nfs_do_mount_v3v2(struct nfsmount_info *mi, - struct sockaddr *sap, socklen_t salen) + struct sockaddr *sap, socklen_t salen) { struct mount_options *options = po_dup(mi->options); int result = 0; @@ -631,7 +649,7 @@ static int nfs_do_mount_v3v2(struct nfsmount_info *mi, printf(_("%s: trying text-based options '%s'\n"), progname, *mi->extra_opts); - if (!nfs_rewrite_pmap_mount_options(options)) + if (!nfs_rewrite_pmap_mount_options(options, mi->local_ip)) goto out_fail; result = nfs_sys_mount(mi, options); @@ -1039,6 +1057,7 @@ int nfsmount_string(const char *spec, const char *node, const char *type, .flags = flags, .fake = fake, .child = child, + .local_ip = NULL, }; int retval = EX_FAIL; @@ -1051,5 +1070,7 @@ int nfsmount_string(const char *spec, const char *node, const char *type, freeaddrinfo(mi.address); free(mi.hostname); + if (mi.local_ip) + free(mi.local_ip); return retval; }