From: greearb@candelatech.com
To: linux-nfs@vger.kernel.org
Cc: Ben Greear <greearb@candelatech.com>
Subject: [PATCH v4 3/6] nfs-utils: Implement srcaddr binding in rpc_socket
Date: Mon, 13 Jun 2011 14:26:45 -0700 [thread overview]
Message-ID: <1308000408-13690-4-git-send-email-greearb@candelatech.com> (raw)
In-Reply-To: <1308000408-13690-1-git-send-email-greearb@candelatech.com>
From: Ben Greear <greearb@candelatech.com>
This implements the actual binding, if we are passed
a non-null local_ip structure.
Signed-off-by: Ben Greear <greearb@candelatech.com>
---
:100644 100644 5652f6c... 936319b... M support/nfs/rpc_socket.c
support/nfs/rpc_socket.c | 59 +++++++++++++++++++++++++++++++++++----------
1 files changed, 46 insertions(+), 13 deletions(-)
diff --git a/support/nfs/rpc_socket.c b/support/nfs/rpc_socket.c
index 5652f6c..936319b 100644
--- a/support/nfs/rpc_socket.c
+++ b/support/nfs/rpc_socket.c
@@ -115,6 +115,8 @@ static CLIENT *nfs_get_localclient(const struct sockaddr *sap,
static int nfs_bind(const int sock, const sa_family_t family,
struct local_bind_info *local_ip)
{
+ struct sockaddr *sa = NULL;
+ socklen_t salen = 0;
struct sockaddr_in sin = {
.sin_family = AF_INET,
.sin_addr.s_addr = htonl(INADDR_ANY),
@@ -124,15 +126,26 @@ static int nfs_bind(const int sock, const sa_family_t family,
.sin6_addr = IN6ADDR_ANY_INIT,
};
- switch (family) {
- case AF_INET:
- return bind(sock, (struct sockaddr *)(char *)&sin,
- (socklen_t)sizeof(sin));
- case AF_INET6:
- return bind(sock, (struct sockaddr *)(char *)&sin6,
- (socklen_t)sizeof(sin6));
+ if (local_ip) {
+ sa = &local_ip->addr.sa;
+ salen = local_ip->addrlen;
+ } else {
+ switch (family) {
+ case AF_INET:
+ sa = (struct sockaddr *)&sin;
+ salen = sizeof(sin);
+ break;
+ case AF_INET6:
+ sa = (struct sockaddr *)&sin6;
+ salen = sizeof(sin6);
+ default:
+ break;
+ }
}
+ if (sa)
+ return bind(sock, sa, salen);
+
errno = EAFNOSUPPORT;
return -1;
}
@@ -148,6 +161,7 @@ static int nfs_bind(const int sock, const sa_family_t family,
static int nfs_bindresvport(const int sock, const sa_family_t family,
struct local_bind_info *local_ip)
{
+ struct sockaddr *sa = NULL;
struct sockaddr_in sin = {
.sin_family = AF_INET,
.sin_addr.s_addr = htonl(INADDR_ANY),
@@ -157,13 +171,23 @@ static int nfs_bindresvport(const int sock, const sa_family_t family,
.sin6_addr = IN6ADDR_ANY_INIT,
};
- switch (family) {
- case AF_INET:
- return bindresvport_sa(sock, (struct sockaddr *)(char *)&sin);
- case AF_INET6:
- return bindresvport_sa(sock, (struct sockaddr *)(char *)&sin6);
+ if (local_ip) {
+ sa = &local_ip->addr.sa;
+ } else {
+ switch (family) {
+ case AF_INET:
+ sa = (struct sockaddr *)&sin;
+ break;
+ case AF_INET6:
+ sa = (struct sockaddr *)&sin6;
+ default:
+ break;
+ }
}
+ if (sa)
+ return bindresvport_sa(sock, sa);
+
errno = EAFNOSUPPORT;
return -1;
}
@@ -179,12 +203,21 @@ static int nfs_bindresvport(const int sock, const sa_family_t family,
static int nfs_bindresvport(const int sock, const sa_family_t family,
struct local_bind_info *local_ip)
{
+ struct sockaddr_in laddr;
if (family != AF_INET) {
errno = EAFNOSUPPORT;
return -1;
}
- return bindresvport(sock, NULL);
+ laddr.sin_family = family;
+ laddr.sin_port = 0;
+ if (local_ip) {
+ struct sockaddr_in *si = &local_ip->addr.s4;
+ laddr.sin_addr.s_addr = si->sin_addr.s_addr;
+ } else {
+ laddr.sin_addr.s_addr = htonl(INADDR_ANY);
+ }
+ return bindresvport(sock, &laddr);
}
#endif /* !HAVE_LIBTIRPC */
--
1.7.3.4
next prev parent reply other threads:[~2011-06-13 21:27 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-13 21:26 [PATCH v4 0/6] nfs-utils: Support binding to source address greearb
2011-06-13 21:26 ` [PATCH v4 1/6] nfs-utils: Add structure for passing local binding info greearb
2011-06-13 21:26 ` [PATCH v4 2/6] nfs-utils: Add patch to parse srcaddr= option greearb
2011-06-13 21:26 ` greearb [this message]
2011-06-13 21:26 ` [PATCH v4 4/6] nfs-utils: Support srcaddr=n option for string mount greearb
2011-06-13 21:26 ` [PATCH v4 5/6] nfs-utils: Implement srcaddr=n binding for unmount greearb
2011-06-13 21:26 ` [PATCH v4 6/6] nfs-utils: Update man page for srcaddr= option greearb
2011-06-20 17:40 ` [PATCH v4 0/6] nfs-utils: Support binding to source address Ben Greear
2011-06-22 14:29 ` Steve Dickson
2011-06-22 14:53 ` Ben Greear
2011-06-22 18:57 ` Steve Dickson
2011-06-22 19:11 ` 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=1308000408-13690-4-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).