From patchwork Fri Aug 7 19:43:17 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 30969 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.samba.org (fn.samba.org [216.83.154.106]) by bilbo.ozlabs.org (Postfix) with ESMTP id DC2CEB7B3E for ; Sat, 8 Aug 2009 05:43:43 +1000 (EST) Received: from fn.samba.org (localhost [127.0.0.1]) by lists.samba.org (Postfix) with ESMTP id 42A8BAD0C4; Fri, 7 Aug 2009 13:39:19 -0600 (MDT) X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on fn.samba.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=3.8 tests=AWL, BAYES_00, NO_MORE_FUNN, SPF_PASS autolearn=no version=3.2.5 X-Original-To: linux-cifs-client@lists.samba.org Delivered-To: linux-cifs-client@lists.samba.org Received: from cdptpa-omtalb.mail.rr.com (cdptpa-omtalb.mail.rr.com [75.180.132.121]) by lists.samba.org (Postfix) with ESMTP id 2BE74AD05C; Fri, 7 Aug 2009 13:39:03 -0600 (MDT) Received: from mail.poochiereds.net ([71.70.153.3]) by cdptpa-omta03.mail.rr.com with ESMTP id <20090807194320040.JGQC22765@cdptpa-omta03.mail.rr.com>; Fri, 7 Aug 2009 19:43:20 +0000 Received: by mail.poochiereds.net (Postfix, from userid 4447) id F2FA558148; Fri, 7 Aug 2009 15:43:17 -0400 (EDT) From: Jeff Layton To: linux-cifs-client@lists.samba.org, samba-technical@lists.samba.org Date: Fri, 7 Aug 2009 15:43:17 -0400 Message-Id: <1249674197-1065-8-git-send-email-jlayton@redhat.com> X-Mailer: git-send-email 1.6.0.6 In-Reply-To: <1249674197-1065-1-git-send-email-jlayton@redhat.com> References: <1249674197-1065-1-git-send-email-jlayton@redhat.com> Subject: [linux-cifs-client] [PATCH 7/7] cifs.upcall: fix IPv6 addrs sent to upcall to have colon delimiters X-BeenThere: linux-cifs-client@lists.samba.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: The Linux CIFS VFS client List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-cifs-client-bounces@lists.samba.org Errors-To: linux-cifs-client-bounces@lists.samba.org Current kernels don't send IPv6 addresses with the colon delimiters, add a routine to add them when they're not present. Signed-off-by: Jeff Layton --- client/cifs.upcall.c | 33 +++++++++++++++++++++++++++++---- 1 files changed, 29 insertions(+), 4 deletions(-) diff --git a/client/cifs.upcall.c b/client/cifs.upcall.c index 1e58503..0cc72fc 100644 --- a/client/cifs.upcall.c +++ b/client/cifs.upcall.c @@ -296,18 +296,43 @@ cifs_resolver(const key_serial_t key, const char *key_descr) return 0; } +/* + * Older kernels sent IPv6 addresses without colons. Well, at least + * they're fixed-length strings. Convert these addresses to have colon + * delimiters to make getaddrinfo happy. + */ +static void +convert_inet6_addr(const char *from, char *to) +{ + int i = 1; + + while (*from) { + *to++ = *from++; + if (!(i++ % 4) && *from) + *to++ = ':'; + } + *to = 0; +} + static int -ip_to_fqdn(const char *ipaddr, char *host, size_t hostlen) +ip_to_fqdn(const char *addrstr, char *host, size_t hostlen) { int rc; struct addrinfo hints = { .ai_flags = AI_NUMERICHOST }; struct addrinfo *res; + const char *ipaddr = addrstr; + char converted[INET6_ADDRSTRLEN + 1]; + + if ((strlen(ipaddr) > INET_ADDRSTRLEN) && !strchr(ipaddr, ':')) { + convert_inet6_addr(ipaddr, converted); + ipaddr = converted; + } rc = getaddrinfo(ipaddr, NULL, &hints, &res); if (rc) { - syslog(LOG_DEBUG, "%s: failed to resolve %s to ipaddr: %s", - __func__, ipaddr, - rc == EAI_SYSTEM ? strerror(errno) : gai_strerror(rc)); + syslog(LOG_DEBUG, "%s: failed to resolve %s to " + "ipaddr: %s", __func__, ipaddr, + rc == EAI_SYSTEM ? strerror(errno) : gai_strerror(rc)); return rc; }