From patchwork Mon Jun 13 21:26:44 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Greear X-Patchwork-Id: 876532 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p5DM75uk030937 for ; Mon, 13 Jun 2011 22:07:05 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754002Ab1FMV11 (ORCPT ); Mon, 13 Jun 2011 17:27:27 -0400 Received: from mail.candelatech.com ([208.74.158.172]:55405 "EHLO ns3.lanforge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754409Ab1FMV11 (ORCPT ); Mon, 13 Jun 2011 17:27:27 -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 p5DLQofF001061 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 13 Jun 2011 14:26:51 -0700 From: greearb@candelatech.com To: linux-nfs@vger.kernel.org Cc: Ben Greear Subject: [PATCH v4 2/6] nfs-utils: Add patch to parse srcaddr= option. Date: Mon, 13 Jun 2011 14:26:44 -0700 Message-Id: <1308000408-13690-3-git-send-email-greearb@candelatech.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1308000408-13690-1-git-send-email-greearb@candelatech.com> References: <1308000408-13690-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 (demeter2.kernel.org [140.211.167.43]); Mon, 13 Jun 2011 22:07:05 +0000 (UTC) From: Ben Greear This will be used to parse the IP address used for binding to a particular local IP address. Signed-off-by: Ben Greear --- :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 };