From: greearb@candelatech.com
To: linux-nfs@vger.kernel.org
Cc: Ben Greear <greearb@candelatech.com>
Subject: [PATCH v4 2/6] nfs-utils: Add patch to parse srcaddr= option.
Date: Mon, 13 Jun 2011 14:26:44 -0700 [thread overview]
Message-ID: <1308000408-13690-3-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 will be used to parse the IP address used for
binding to a particular local IP address.
Signed-off-by: Ben Greear <greearb@candelatech.com>
---
:100644 100644 bbe92e9... b046874... M utils/mount/network.c
:100644 100644 4debfaa... 292ad1f... M utils/mount/network.h
utils/mount/network.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
utils/mount/network.h | 3 ++
2 files changed, 54 insertions(+), 0 deletions(-)
diff --git a/utils/mount/network.c b/utils/mount/network.c
index bbe92e9..b046874 100644
--- a/utils/mount/network.c
+++ b/utils/mount/network.c
@@ -405,6 +405,57 @@ out:
}
/*
+ * node should be an IPv4 or IPv6 address numeric notation.
+ * The value will be parsed in placed into laddr.
+ * Returns < 0 on failure to parse.
+ */
+int
+nfs_parse_local_bind(struct local_bind_info *laddr, const char* node,
+ sa_family_t family) {
+ /* str is an IP address. */
+ int aiErr;
+ struct addrinfo *aiHead;
+ struct addrinfo hints;
+
+ memset(&hints, 0, sizeof(hints));
+
+ hints.ai_flags = AI_NUMERICSERV;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_protocol = IPPROTO_TCP;
+ hints.ai_family = family;
+
+ aiErr = getaddrinfo(node, NULL, &hints, &aiHead);
+
+ if (aiErr != 0) {
+ char *f;
+ switch (family) {
+ case AF_INET:
+ f = "AF_INET";
+ break;
+ case AF_INET6:
+ f = "AF_INET6";
+ break;
+ default:
+ f = "UNKNOWN";
+ break;
+ }
+
+ nfs_error(_("%s: parse srcaddr failed, "
+ "node: %s family: %s aiErr: %i %s\n"),
+ progname, node, f, aiErr, gai_strerror(aiErr));
+ } else {
+ if (aiHead) {
+ memcpy(&laddr->addr, aiHead->ai_addr,
+ aiHead->ai_addrlen);
+ laddr->addrlen = aiHead->ai_addrlen;
+ freeaddrinfo(aiHead);
+ return 0;
+ }
+ }
+ return -1;
+}
+
+/*
* Create a socket that is locally bound to a reserved or non-reserved port.
*
* The caller should check rpc_createerr to determine the cause of any error.
diff --git a/utils/mount/network.h b/utils/mount/network.h
index 4debfaa..292ad1f 100644
--- a/utils/mount/network.h
+++ b/utils/mount/network.h
@@ -36,6 +36,9 @@ typedef struct {
struct pmap pmap;
} clnt_addr_t;
+int nfs_parse_local_bind(struct local_bind_info *laddr, const char* str,
+ sa_family_t family);
+
/* RPC call timeout values */
static const struct timeval TIMEOUT = { 20, 0 };
static const struct timeval RETRY_TIMEOUT = { 3, 0 };
--
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 ` greearb [this message]
2011-06-13 21:26 ` [PATCH v4 3/6] nfs-utils: Implement srcaddr binding in rpc_socket greearb
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-3-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).