From owner-cvs-all Wed Aug 8 13:28: 7 2001 Delivered-To: cvs-all@freebsd.org Received: from mail.disney.com (mail.disney.com [204.128.192.15]) by hub.freebsd.org (Postfix) with ESMTP id AD73637B421; Wed, 8 Aug 2001 13:27:41 -0700 (PDT) (envelope-from Jim.Pirzyk@disney.com) Received: from pain10.corp.disney.com (root@pain10.corp.disney.com [153.7.110.100]) by mail.disney.com (Switch-2.0.1/Switch-2.0.1) with SMTP id f78KQne26060; Wed, 8 Aug 2001 13:26:49 -0700 (PDT) Received: from [172.30.50.1] by pain.corp.disney.com with ESMTP; Wed, 8 Aug 2001 13:28:37 -0700 Received: from plio.fan.fa.disney.com (plio.fan.fa.disney.com [153.7.118.2]) by pecos.fa.disney.com (8.11.3/8.11.3) with ESMTP id f78KUhs11218; Wed, 8 Aug 2001 13:30:43 -0700 (PDT) Received: from mercury.fan.fa.disney.com (mercury.fan.fa.disney.com [153.7.119.1]) by plio.fan.fa.disney.com (8.9.2/8.9.2) with ESMTP id NAA21828; Wed, 8 Aug 2001 13:27:32 -0700 (PDT) (envelope-from Jim.Pirzyk@disney.com) Received: from snoopy.fan.fa.disney.com by mercury.fan.fa.disney.com; Wed, 8 Aug 2001 13:27:31 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Jim Pirzyk Organization: Walt Disney Feature Animation To: Hajimu UMEMOTO , ru@FreeBSD.org Subject: Re: cvs commit: src/lib/libc/net gethostbyname.3 Date: Wed, 8 Aug 2001 13:27:31 -0700 X-Mailer: KMail [version 1.2] Cc: Jim.Pirzyk@disney.com, sheldonh@starjuice.net, cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org References: <55998.997269012@axl.seasidesoftware.co.za> <20010808191242.C10516@sunbay.com> <20010809.043555.104064272.ume@mahoroba.org> In-Reply-To: <20010809.043555.104064272.ume@mahoroba.org> MIME-Version: 1.0 Message-Id: <01080813273100.00624@snoopy> Content-Transfer-Encoding: 8bit Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Testing it out it does solve my problems. Thanks. So how does this patch work in that getaddrinfo came from the KAME project. Do we have to wait for the vendor branch to be upgraded with a new version of KAME that has this fix or should we patch getaddrinfo ourselves? Also in the future, how would we support sorting IPv6 addresses (we are currently not running IPv6, but eventually I would think we may have to move there). - JimP On Wednesday 08 August 2001 12:35 pm, Hajimu UMEMOTO wrote: > >>>>> On Wed, 8 Aug 2001 19:12:42 +0300 > >>>>> Ruslan Ermilov said: > > ru> On Wed, Aug 08, 2001 at 08:32:28AM -0700, Jim Pirzyk wrote: > > On Wednesday 08 August 2001 04:10 am, Sheldon Hearn wrote: > > > On Wed, 08 Aug 2001 04:05:47 MST, Ruslan Ermilov wrote: > > > > Modified files: > > > > lib/libc/net gethostbyname.3 > > > > Log: > > > > Urge the reader to start using getaddrinfo(3) and getnameinfo(3) > > > > protocol-independant functions that don't use static memory area. > > > > > > And which _rock_! > > > > Err, not quite. They do not use the DNS sortlist functionallity, > > nor do they check to see what subnet the host and remote host > > has in common to use that address first. > > This would be the #1 reason I would not use them. See PR bin/27939. > > ru> This is the implementation bug that should ideally be fixed. But > ru> this does not mean that this interface is bad, because DNS is one > ru> of the possible back ends, and the latest POSIX draft says: > > Okay, how about this patch? It supports sortlist. It affects only > IPv4 address. > > Index: lib/libc/net/getaddrinfo.c > diff -u lib/libc/net/getaddrinfo.c.orig lib/libc/net/getaddrinfo.c > --- lib/libc/net/getaddrinfo.c.orig Sat Jun 16 07:08:28 2001 > +++ lib/libc/net/getaddrinfo.c Thu Aug 9 04:32:56 2001 > @@ -99,6 +99,9 @@ > #include > #include > #include > + > +#include "res_config.h" > + > #ifdef DEBUG > #include > #endif > @@ -1194,6 +1197,72 @@ > } > #endif > > +#ifdef RESOLVSORT > +struct addr_ptr { > + struct addrinfo *ai; > + int aval; > +}; > + > +static int > +addr4sort(struct addrinfo *sentinel) > +{ > + struct addrinfo *ai; > + struct addr_ptr *addrs, addr; > + struct sockaddr_in *sin; > + int naddrs, i, j; > + int needsort = 0; > + > + if (!sentinel) > + return -1; > + naddrs = 0; > + for (ai = sentinel->ai_next; ai; ai = ai->ai_next) > + naddrs++; > + if (naddrs < 2) > + return 0; /* We don't need sorting. */ > + if ((addrs = malloc(sizeof(struct addr_ptr) * naddrs)) == NULL) > + return -1; > + i = 0; > + for (ai = sentinel->ai_next; ai; ai = ai->ai_next) { > + sin = (struct sockaddr_in *)ai->ai_addr; > + for (j = 0; (unsigned)j < _res.nsort; j++) { > + if (_res.sort_list[j].addr.s_addr == > + (sin->sin_addr.s_addr & _res.sort_list[j].mask)) > + break; > + } > + addrs[i].ai = ai; > + addrs[i].aval = j; > + if (needsort == 0 && i > 0 && j < addrs[i - 1].aval) > + needsort = i; > + i++; > + } > + if (!needsort) { > + free(addrs); > + return 0; > + } > + > + while (needsort < naddrs) { > + for (j = needsort - 1; j >= 0; j--) { > + if (addrs[j].aval > addrs[j+1].aval) { > + addr = addrs[j]; > + addrs[j] = addrs[j + 1]; > + addrs[j + 1] = addr; > + } else > + break; > + } > + needsort++; > + } > + > + ai = sentinel; > + for (i = 0; i < naddrs; ++i) { > + ai->ai_next = addrs[i].ai; > + ai = ai->ai_next; > + } > + ai->ai_next = NULL; > + free(addrs); > + return 0; > +} > +#endif /*RESOLVSORT*/ > + > #ifdef DEBUG > static const char AskedForGot[] = > "gethostby*.getanswer: asked for \"%s\", got \"%s\""; > @@ -1387,6 +1456,19 @@ > haveanswer++; > } > if (haveanswer) { > +#if defined(RESOLVSORT) > + /* > + * We support only IPv4 address for backward > + * compatibility against gethostbyname(3). > + */ > + if (_res.nsort && qtype == T_A) { > + if (addr4sort(&sentinel) < 0) { > + freeaddrinfo(sentinel.ai_next); > + h_errno = NO_RECOVERY; > + return NULL; > + } > + } > +#endif /*RESOLVSORT*/ > if (!canonname) > (void)get_canonname(pai, sentinel.ai_next, qname); > else > > -- > Hajimu UMEMOTO @ Internet Mutual Aid Society Yokohama, Japan > ume@mahoroba.org ume@bisd.hitachi.co.jp ume@{,jp.}FreeBSD.org > http://www.imasy.org/~ume/ -- --- @(#) $Id: dot.signature,v 1.10 2001/05/17 23:38:49 Jim.Pirzyk Exp $ __o Jim.Pirzyk@disney.com ------------- pirzyk@freebsd.org _'\<,_ Senior Systems Engineer, Walt Disney Feature Animation (*)/ (*) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message