From nobody  Mon Dec 15 16:10:47 1997
Received: (from nobody@localhost)
          by hub.freebsd.org (8.8.7/8.8.7) id QAA00709;
          Mon, 15 Dec 1997 16:10:47 -0800 (PST)
          (envelope-from nobody)
Message-Id: <199712160010.QAA00709@hub.freebsd.org>
Date: Mon, 15 Dec 1997 16:10:47 -0800 (PST)
From: robert@superior.net
To: freebsd-gnats-submit@freebsd.org
Subject: gethostbyname() returns herror "Unknown host" on well known hosts
X-Send-Pr-Version: www-1.0

>Number:         5306
>Category:       bin
>Synopsis:       gethostbyname() returns herror "Unknown host" on well known hosts
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Dec 15 16:20:02 PST 1997
>Closed-Date:    Wed Apr 1 13:53:22 PST 1998
>Last-Modified:  Wed Apr  1 13:54:58 PST 1998
>Originator:     Robert Blayzor
>Release:        2.2.5-STABLE
>Organization:
Telecon Communications Corp.
>Environment:
FreeBSD nimbus.superior.net 2.2.5-STABLE FreeBSD 2.2.5-STABLE #0: Sat Dec 13 23:25:48 EST 1997     robert@nimbusII.superior.net:/usr/src/sys/compile/NIMBUS  i386
>Description:
When on a well loaded system, gethostbyname() will return "Unknown
Host" on well known hosts. (ie: mit.edu, internic.net, etc.)  On a loaded
FreeBSD machine using many daemons, httpd, etc, programs such as squid,
popper cannot do a successul gethostbyname().  For example, programs 
such as popper 2.4 return:
Dec 15 19:08:17 nimbus popper[13158]: Client at "206.1.102.139" resolves to an unknown host name "pm1-alb-42.mydomain.com"

Even though forward and reverse match and the above will get through tcpd.
>How-To-Repeat:
Not sure if this makes a difference, this kernel has:
options         "CHILD_MAX=256"
options         "OPEN_MAX=256"

Load up a BSD system in which a lot of file discriptors are used. 
Compile and run something easy such as Squid and see that it's DNS
systems fail.  On this system named is running.  This is not that 
difficult to reproduce.
>Fix:
No fix as of 2.2.5-STABLE
>Release-Note:
>Audit-Trail:

From: Bruce Evans <bde@zeta.org.au>
To: freebsd-gnats-submit@FreeBSD.ORG, robert@superior.net
Cc:  Subject: Re: bin/5306: gethostbyname() returns herror "Unknown host" on well known hosts
Date: Tue, 16 Dec 1997 18:49:02 +1100

 >>Description:
 >When on a well loaded system, gethostbyname() will return "Unknown
 >Host" on well known hosts. (ie: mit.edu, internic.net, etc.)  On a loaded
 >...
 >Not sure if this makes a difference, this kernel has:
 >options         "CHILD_MAX=256"
 >options         "OPEN_MAX=256"
 
 These are bogus, but misconfiguring the soft openfiles limit by abusing
 OPEN_MAX like this makes the problem less obvious.  The default limit
 is 64 in 2.2.5 and "infinite" in -current.
 
 >Load up a BSD system in which a lot of file discriptors are used. 
 >Compile and run something easy such as Squid and see that it's DNS
 >systems fail.  On this system named is running.  This is not that 
 >difficult to reproduce.
 >>Fix:
 >No fix as of 2.2.5-STABLE
 
 At least for the test program in PR 3622, the fix is to configure enough
 fd's using /etc/login.conf.  In 2.2.5, the default openfiles limits for
 class daemon are 1024 (hard) and OPEN_MAX (soft).  These should be set
 as large as necessary (but no larger) for each class of user.
 
 There is also an evil sysctl limit `kern.maxfilesperproc' with the
 default value of 2*NPROC.  This interferes with correct operation of
 login.conf.  If it is too small, then the easiest way to fix it is to
 edit /sys/conf/param.c and build a new kernel.  There is also a good
 sysctl limit `kern.maxfiles' with the default value of 2*NPROC.  This
 is easy to change at runtime using `sysctl -w kern.maxfiles=...'.
 (Changing kern.maxfilesperproc at runtime doesn't work well because
 it can't increase the openfiles limits in the process tree.  It can
 only decrease them.)
 
 Bruce

From: Christopher Masto <chris@netmonger.net>
To: freebsd-gnats-submit@freebsd.org, bde@zeta.org.au, robert@superior.net
Cc:  Subject: Re: bin/5306: gethostbyname() returns herror "Unknown host" on well known hosts
Date: Wed, 17 Dec 1997 11:45:10 -0500

 > At least for the test program in PR 3622, the fix is to configure enough
 > fd's using /etc/login.conf.  In 2.2.5, the default openfiles limits for
 > class daemon are 1024 (hard) and OPEN_MAX (soft).  These should be set
 > as large as necessary (but no larger) for each class of user.
 > 
 > There is also an evil sysctl limit `kern.maxfilesperproc' with the
 > default value of 2*NPROC.  This interferes with correct operation of
 > login.conf.  If it is too small, then the easiest way to fix it is to
 > edit /sys/conf/param.c and build a new kernel.  There is also a good
 > sysctl limit `kern.maxfiles' with the default value of 2*NPROC.  This
 > is easy to change at runtime using `sysctl -w kern.maxfiles=...'.
 > (Changing kern.maxfilesperproc at runtime doesn't work well because
 > it can't increase the openfiles limits in the process tree.  It can
 > only decrease them.)
 
 I don't know whether the gethostbyname() problem Robert is having is
 related to PR 3622, but I think there is a problem with the default
 login.conf.
 
 I had to lower openfiles settings to 256 because having it larger
 breaks select().  It's been a while, so I'm a bit fuzzy on the details,
 but I do remember that it was causing rxvt to fail.. a quick perusal
 of the rxvt source indicates that it does:
 
 #ifdef _POSIX_VERSION
     num_fds = sysconf(_SC_OPEN_MAX);
 #else
     num_fds = getdtablesize();
 #endif
 
 I believe that it ends up obtaining the 1024 that was defined in login.conf,
 but the FD_SETSIZE in sys/types.h is defined as 256.  IIRC, select() bombs
 out when nfds is > 256.
 
 I suppose I should test this rather than just make the claim.  Try this:
 
 #include <stdio.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/select.h>
 
 void testselect(int num)
 {
   fd_set fds;
   struct timeval tv = {0, 0};
 
   printf("testing select(%d,...)\n", num);
   FD_ZERO(&fds);
   if (select(num, &fds, &fds, &fds, &tv) < 0) {
     perror("select()");
   }
   else {
     printf("select() successful\n");
   }
 }
 
 int main(int argc, char *argv[])
 {
   int dtsize;
   int open_max;
 
   printf("FD_SETSIZE = %d\n", FD_SETSIZE);
   dtsize=getdtablesize();
   printf("getdtablesize() = %d\n", dtsize);
   open_max=(int)sysconf(_SC_OPEN_MAX);
   printf("open_max = %d\n", open_max);
 
   testselect(FD_SETSIZE);
   testselect(dtsize);
 }
 
 - - -
 
 chris@cheddar:/tmp$ ulimit -n
 1024
 chris@cheddar:/tmp$ ./seltest
 FD_SETSIZE = 256
 getdtablesize() = 1024
 open_max = 1024
 testing select(256,...)
 select() successful
 testing select(1024,...)
 select(): Bad file descriptor
 
 I hope that was clear.
 -- 
 = Christopher Masto        = chris@netmonger.net = http://www.netmonger.net/  =
 = NetMonger Communications = finger for  PGP key = $19.95/mo unlimited access =
 = Director of Operations   =   (516)  221-6664 	 = mailto:info@netmonger.net  =
 
     "... who'd want a lossy TIFF?"  -- Kibo

From: Bruce Evans <bde@zeta.org.au>
To: bde@zeta.org.au, chris@netmonger.net, freebsd-gnats-submit@freebsd.org,
        robert@superior.net
Cc:  Subject: Re: bin/5306: gethostbyname() returns herror "Unknown host" on well known hosts
Date: Thu, 18 Dec 1997 04:23:38 +1100

 >I don't know whether the gethostbyname() problem Robert is having is
 >related to PR 3622, but I think there is a problem with the default
 >login.conf.
 >
 >I had to lower openfiles settings to 256 because having it larger
 >breaks select().  It's been a while, so I'm a bit fuzzy on the details,
 >but I do remember that it was causing rxvt to fail.. a quick perusal
 >of the rxvt source indicates that it does:
 
 It breaks buggy applications.
 
 >I believe that it ends up obtaining the 1024 that was defined in login.conf,
 >but the FD_SETSIZE in sys/types.h is defined as 256.  IIRC, select() bombs
 >out when nfds is > 256.
 
 Naive use of the FD_* macros doesn't work if nfds > FD_SETSIZE.  The
 application should know about this and either not supports fd's >=
 FD_SETSIZE, or handle them somehow.  The documented way is to #define
 FD_SETSIZE before including <sys/types.h>.  The networking libraries
 use a more flexible way.
 
 >I suppose I should test this rather than just make the claim.  Try this:
 >
 >#include <stdio.h>
 >#include <unistd.h>
 >#include <sys/types.h>
 >#include <sys/time.h>
 >#include <sys/select.h>
 >
 >void testselect(int num)
 >{
 >  fd_set fds;
 >  struct timeval tv = {0, 0};
 >
 >  printf("testing select(%d,...)\n", num);
 >  FD_ZERO(&fds);
 >  if (select(num, &fds, &fds, &fds, &tv) < 0) {
 >    perror("select()");
 >  }
 
 If nfds > FD_SETSIZE, in FreeBSD-2.2.0 and later versions, select()
 will probably succeed and scribble on the stack beyond the end of
 fds.  In earlier versions, it rejects the request if nfds > 256.
 FD_SETSIZE happens to be 256 in 2.2.5 and 1024 in -current.  Programs
 should not depend on this (but many probably do :-().
 
 Bruce

From: "Greg A. Woods" <woods@zeus.leitch.com>
To: freebsd-gnats-submit@freebsd.org, robert@superior.net
Cc:  Subject: Re: bin/5306: gethostbyname() returns herror "Unknown host" on well known hosts
Date: Wed, 01 Apr 1998 14:49:03 -0500

 This PR should be closed with a reference to the more complete and
 correct identification of the problem given in PR # bin/6121.
 
 -- 
 							Greg A. Woods
 
 +1 416 443-1734      VE3TCP      <gwoods@acm.org>      <robohack!woods>
 Planix, Inc. <woods@planix.com>; Secrets of the Weird <woods@weird.com>
State-Changed-From-To: open->closed 
State-Changed-By: danny 
State-Changed-When: Wed Apr 1 13:53:22 PST 1998 
State-Changed-Why:  
This PR has been superseded by PR 6121, which has a more complete 
description of the problem. 
>Unformatted:
