Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by krbdev.mit.edu (Postfix) with ESMTP id CB8C53DC44 for ; Mon, 28 Jun 2010 14:15:23 -0400 (EDT) Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5SIFM9u016607 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 28 Jun 2010 14:15:23 -0400 Received: from blade.bos.redhat.com (blade.bos.redhat.com [10.16.0.23]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5SIFLeN030716 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 28 Jun 2010 14:15:22 -0400 Received: from blade.bos.redhat.com (blade.bos.redhat.com [127.0.0.1]) by blade.bos.redhat.com (8.14.4/8.14.3) with ESMTP id o5SIFLYI019858 for ; Mon, 28 Jun 2010 14:15:21 -0400 Received: (from nalin@localhost) by blade.bos.redhat.com (8.14.4/8.14.4/Submit) id o5SIFLBQ019857 for rt@krbdev.mit.edu; Mon, 28 Jun 2010 14:15:21 -0400 Date: Mon, 28 Jun 2010 14:15:21 -0400 From: Nalin Dahyabhai To: rt@krbdev.mit.edu Subject: Re: [krbdev.mit.edu #6735] kprop and kpropd don't support IPv6 Message-ID: <20100628181521.GC27244@redhat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Red Hat, Inc. X-Disclaimer: I am not a spokesmodel. Views expressed are my own. X-Key-ID: 78688BF5 X-Key-Fingerprint: 60BC AD87 AF51 3A00 8C99 0388 379B CE57 7868 8BF5 User-Agent: Mutt/1.5.20 (2009-12-10) X-Scanned-BY: MIMEDefang 2.67 on 10.5.11.17 RT-Send-Cc: X-RT-Original-Encoding: us-ascii Content-Length: 2477 The kprop client seems to be working well, but kpropd currently gives me this warning when run in standalone mode: kpropd: Protocol not available while unsetting IPV6_V6ONLY option This appears to happen because getaddrinfo() is returning a list of two addresses (the first is the IPv4 wildcard address, and the second is the IPv6 wildcard address), and kpropd is only using the first. Checking that res->ai_family is AF_INET6 before calling setsockopt() at line 277 suppresses the warning, but then it's still listening only for IPv4 connections. I've found that asking getaddrinfo() for an AF_INET6 address with AI_ADDRCONFIG added to hints.ai_flags seems to reliably return an error when IPv6 isn't supported, and falling back from there to asking for an AF_INET address, while not particularly elegant, seems to do the job. HTH, Nalin Index: src/slave/kpropd.c =================================================================== --- src/slave/kpropd.c (revision 24148) +++ src/slave/kpropd.c (working copy) @@ -250,14 +250,22 @@ retry: memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_UNSPEC; + hints.ai_family = AF_INET6; hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE; + hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG | AI_V4MAPPED; error = getaddrinfo(NULL, port, &hints, &res); if (error != 0) { - (void) fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(error)); - exit(1); + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG; + + error = getaddrinfo(NULL, port, &hints, &res); + if (error != 0) { + (void) fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(error)); + exit(1); + } } finet = socket(res->ai_family, res->ai_socktype, res->ai_protocol); @@ -274,8 +282,9 @@ /* Typically, res will be the IPv6 wildcard address. Some systems, such as * the *BSDs, don't accept IPv4 connections on this address by default. */ val = 0; - if (setsockopt(finet, IPPROTO_IPV6, IPV6_V6ONLY, &val, sizeof(val)) < 0) - com_err(progname, errno, "while unsetting IPV6_V6ONLY option"); + if (res->ai_family == AF_INET6) + if (setsockopt(finet, IPPROTO_IPV6, IPV6_V6ONLY, &val, sizeof(val)) < 0) + com_err(progname, errno, "while unsetting IPV6_V6ONLY option"); #endif /*