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 4/7] nfs-utils:  Implement srcaddr binding in network.c
Date: Fri, 10 Jun 2011 11:09:36 -0700	[thread overview]
Message-ID: <1307729379-7702-5-git-send-email-greearb@candelatech.com> (raw)
In-Reply-To: <1307729379-7702-1-git-send-email-greearb@candelatech.com>

From: Ben Greear <greearb@candelatech.com>

Implement binding logic in get_socket() if local_ip
argument is not NULL.

Note that this method had issues with supporting IPv6 before
this patch, and this patch does NOT resolve them.

Signed-off-by: Ben Greear <greearb@candelatech.com>
---
:100644 100644 36c2e94... 5419c5d... M	utils/mount/network.c
 utils/mount/network.c |   21 ++++++++++++++++++---
 1 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/utils/mount/network.c b/utils/mount/network.c
index 36c2e94..5419c5d 100644
--- a/utils/mount/network.c
+++ b/utils/mount/network.c
@@ -461,19 +461,34 @@ static int get_socket(struct sockaddr_in *saddr, unsigned int p_prot,
 	int so, cc, type;
 	struct sockaddr_in laddr;
 	socklen_t namelen = sizeof(laddr);
+	int f = AF_INET;
+
+	if (local_ip && local_ip->is_set)
+		f = local_ip->addr.sa.sa_family;
 
 	type = (p_prot == IPPROTO_UDP ? SOCK_DGRAM : SOCK_STREAM);
-	if ((so = socket (AF_INET, type, p_prot)) < 0)
+
+	so = socket(f, type, p_prot);
+	if (so < 0)
 		goto err_socket;
 
-	laddr.sin_family = AF_INET;
+	laddr.sin_family = f;
 	laddr.sin_port = 0;
 	laddr.sin_addr.s_addr = htonl(INADDR_ANY);
 	if (resvp) {
+		/* TODO:  Support IPv6 */
+		if (local_ip && local_ip->is_set
+		    && local_ip->addr.sa.sa_family == AF_INET) {
+			struct sockaddr_in *si = &local_ip->addr.s4;
+			laddr.sin_addr.s_addr = si->sin_addr.s_addr;
+		}
 		if (bindresvport(so, &laddr) < 0)
 			goto err_bindresvport;
 	} else {
-		cc = bind(so, SAFE_SOCKADDR(&laddr), namelen);
+		if (local_ip && local_ip->is_set)
+			cc = bind(so, &local_ip->addr.sa, local_ip->addrlen);
+		else
+			cc = bind(so, SAFE_SOCKADDR(&laddr), namelen);
 		if (cc < 0)
 			goto err_bind;
 	}
-- 
1.7.3.4


  parent reply	other threads:[~2011-06-10 18:10 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-10 18:09 [PATCH 0/7] nfs-utils: Support binding to source address greearb
2011-06-10 18:09 ` [PATCH 1/7] nfs-utils: Add structure for passing local binding info greearb
2011-06-10 18:09 ` [PATCH 2/7] nfs-utils: Add patch to parse srcaddr= option greearb
2011-06-10 18:09 ` [PATCH 3/7] nfs-utils: Implement srcaddr binding in rpc_socket greearb
2011-06-10 18:09 ` greearb [this message]
2011-06-10 18:29   ` [PATCH 4/7] nfs-utils: Implement srcaddr binding in network.c Chuck Lever
2011-06-10 18:40     ` Ben Greear
2011-06-10 18:09 ` [PATCH 5/7] nfs-utils: Support srcaddr=n option for string mount greearb
2011-06-10 18:39   ` Chuck Lever
2011-06-10 18:09 ` [PATCH 6/7] nfs-utils: Implement srcaddr=n binding for unmount greearb
2011-06-10 18:09 ` [PATCH 7/7] nfs-utils: Update man page for srcaddr= option greearb

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=1307729379-7702-5-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.