From: greearb@candelatech.com
To: linux-nfs@vger.kernel.org
Cc: Ben Greear <greearb@candelatech.com>
Subject: [PATCH v3 3/6] nfs-utils: Implement srcaddr binding in rpc_socket
Date: Fri, 10 Jun 2011 14:08:13 -0700 [thread overview]
Message-ID: <1307740096-19933-4-git-send-email-greearb@candelatech.com> (raw)
In-Reply-To: <1307740096-19933-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... 4bcbdf0... 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..4bcbdf0 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 && local_ip->is_set) {
+ 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 && local_ip->is_set) {
+ 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 && local_ip->is_set) {
+ 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-10 21:09 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-10 21:08 [PATCH v3 0/6] nfs-utils: Support binding to source address greearb
2011-06-10 21:08 ` [PATCH v3 1/6] nfs-utils: Add structure for passing local binding info greearb
2011-06-10 21:08 ` [PATCH v3 2/6] nfs-utils: Add patch to parse srcaddr= option greearb
2011-06-10 21:08 ` greearb [this message]
2011-06-10 22:06 ` [PATCH v3 3/6] nfs-utils: Implement srcaddr binding in rpc_socket Chuck Lever
2011-06-10 22:19 ` Ben Greear
2011-06-10 22:37 ` Chuck Lever
2011-06-10 22:50 ` Ben Greear
2011-06-10 21:08 ` [PATCH v3 4/6] nfs-utils: Support srcaddr=n option for string mount greearb
2011-06-10 22:07 ` Chuck Lever
2011-06-10 22:30 ` Ben Greear
2011-06-10 22:35 ` Chuck Lever
2011-06-13 20:37 ` Steve Dickson
2011-06-10 21:08 ` [PATCH v3 5/6] nfs-utils: Implement srcaddr=n binding for unmount greearb
2011-06-10 21:08 ` [PATCH v3 6/6] 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=1307740096-19933-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).