From lennox@cs.columbia.edu  Mon Jul  7 09:45:37 2003
Return-Path: <lennox@cs.columbia.edu>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id D86CA37B401
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  7 Jul 2003 09:45:37 -0700 (PDT)
Received: from cs.columbia.edu (cs.columbia.edu [128.59.16.20])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 1597B43F3F
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  7 Jul 2003 09:45:37 -0700 (PDT)
	(envelope-from lennox@cs.columbia.edu)
Received: from conrail.cs.columbia.edu (conrail.cs.columbia.edu [128.59.19.147])
	by cs.columbia.edu (8.12.9/8.12.9) with ESMTP id h67GjZkN024013
	(version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NOT)
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 7 Jul 2003 12:45:36 -0400 (EDT)
Received: from conrail.cs.columbia.edu (localhost [127.0.0.1])
	by conrail.cs.columbia.edu (8.12.8p1/8.12.8) with ESMTP id h67GjZwF041983
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 7 Jul 2003 12:45:35 -0400 (EDT)
	(envelope-from lennox@conrail.cs.columbia.edu)
Received: (from lennox@localhost)
	by conrail.cs.columbia.edu (8.12.8p1/8.12.8/Submit) id h67GjYaC041982;
	Mon, 7 Jul 2003 12:45:34 -0400 (EDT)
Message-Id: <200307071645.h67GjYaC041982@conrail.cs.columbia.edu>
Date: Mon, 7 Jul 2003 12:45:34 -0400 (EDT)
From: Jonathan Lennox <lennox@cs.columbia.edu>
Reply-To: Jonathan Lennox <lennox@cs.columbia.edu>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: DNS resolver should resolve hostnames with underscores
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         54189
>Category:       kern
>Synopsis:       [dns] resolver should resolve hostnames with underscores
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    remko
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jul 07 09:50:12 PDT 2003
>Closed-Date:    Tue Apr 17 05:56:06 GMT 2007
>Last-Modified:  Tue Apr 17 05:56:06 GMT 2007
>Originator:     Jonathan Lennox
>Release:        FreeBSD 4.8-RELEASE i386
>Organization:
Columbia University
>Environment:
System: FreeBSD conrail.cs.columbia.edu 4.8-RELEASE FreeBSD 4.8-RELEASE #4: Tue Apr 15 15:28:33 EDT 2003 lennox@conrail.cs.columbia.edu:/usr/obj/usr/src/sys/CONRAIL i386


>Description:
FreeBSD's gethostbyname() and getaddrinfo() functions refuse to resolve
hostnames with underscores in them.  They return the error codes NO_RECOVERY
and EAI_FAIL respectively.

Hostnames with underscores are ill-formed according to the DNS standards.
However, in the real Internet, hosts with underscores in their names are
reasonably common, and in many cases are not accessable through other names.

For example, the case that inspired me to file this PR: FreeBSD users are
unable to read the web log of the "Baghdad Blogger" Salam Pax, which is at
<http://dear_raed.blogspot.com>.  Linux and Windows users have no such
difficulty.

I note Jon Postel's maxim "Be liberal in what you accept, and conservative
in what you send."

(Note: this PR is in some sense a re-submission of PR misc/29388, but as a
change-request, not a sw-bug.)

>How-To-Repeat:
 Type "http://dear_raed.blogspot.com" into Mozilla running on FreeBSD.
Compare with Mozilla on other systems.

>Fix:
 Import BIND code from other Unix systems?
>Release-Note:
>Audit-Trail:

From: Jonathan Lennox <lennox@cs.columbia.edu>
To: sub_0@netcabo.pt
Cc: freebsd-bugs@FreeBSD.org, freebsd-gnats-submit@FreeBSD.org
Subject: Re: misc/54189: DNS resolver should resolve hostnames with
	underscores
Date: Mon, 28 Jul 2003 12:40:51 -0400

 --p4dH/IeS7Q
 Content-Type: text/plain; charset=iso-8859-1
 Content-Description: message body text
 Content-Transfer-Encoding: quoted-printable
 
 On , July 19 2003, "M=E1rio Freitas" wrote to "freebsd-bugs@FreeBSD.org, lennox@cs.columbia.edu" saying:
 
 > The problem you submitted is due to mozilla's gethostbyname() own(bad)
 > implementation. FreeBSD's resolver can deal with underscores in
 > hostnames without any problem at all. I think you should submit that
 > problem to mozilla's bug tracking system(yes I succeded resolving that
 > hostname in FreeBSD 4.8 and 5.1).
 
 Not so, at least if you go through the gethostbyname() or getaddrinfo()
 APIs.  I've attached a small program that exercises both APIs, compiled
 it on both FreeBSD 4.8-RELEASE and on Red Hat Linux 7.1, and executed both
 on the same FreeBSD 4.8 machine (the Linux binary running under emulation):
 
 conrail $ ./gethostbyname dear_raed.blogspot.com
 dear_raed.blogspot.com: gethostbyname lookup failed: Unknown server error (3)
 dear_raed.blogspot.com: getaddrinfo lookup failed: Non-recoverable failure in name resolution (4)
 conrail $ ./gethostbyname-linux dear_raed.blogspot.com
 dear_raed.blogspot.com [ghbn]: 216.34.7.189
 dear_raed.blogspot.com [gai]: 216.34.7.189 216.34.7.189 216.34.7.189
 
 The FreeBSD 'nslookup' and 'host' programs, which bypass these APIs and do
 DNS queries directly, can indeed resolve the hostname:
 
 conrail $ nslookup dear_raed.blogspot.com
 Server:  sutton.cs.columbia.edu
 Address:  128.59.22.38
 
 Non-authoritative answer:
 Name:    dear_raed.blogspot.com
 Address:  216.34.7.189
 conrail $ host dear_raed.blogspot.com
 dear_raed.blogspot.com has address 216.34.7.189
 
 
 --p4dH/IeS7Q
 Content-Type: text/plain
 Content-Disposition: inline;
 	filename="gethostbyname.c"
 Content-Transfer-Encoding: 7bit
 
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <string.h>
 
 #include <stdlib.h>
 
 #include <netdb.h>
 
 int main(int argc, char *argv[])
 {
   int i;
 
   struct addrinfo hints;
 
   if (argc < 2) {
     fprintf(stderr, "Usage: %s hostname [...]", argv[0]);
     exit(1);
   }
 
   memset(&hints, 0, sizeof(hints));
   hints.ai_family = AF_INET;
 
   for (i = 1; i < argc; i++) {
     int ret;
     struct hostent *he;
     struct addrinfo *ai;
 
     he = gethostbyname(argv[i]);
     if (he == NULL) {
       printf("%s: gethostbyname lookup failed: %s (%d)\n", argv[i],
              hstrerror(h_errno), h_errno);
     }
     else {
       int j;
 
       printf("%s [ghbn]: ", argv[i]);
       for (j = 0; he->h_addr_list[j] != NULL; j++) {
         printf("%s ", inet_ntoa(*(struct in_addr*)(he->h_addr_list[j])));
       }
       printf("\n");
     }
     
     ret = getaddrinfo(argv[i], NULL, &hints, &ai);
     if (ret != 0) {
       printf("%s: getaddrinfo lookup failed: %s (%d)\n", argv[i],
              gai_strerror(ret), ret);
     }
     else {
       struct addrinfo* this_ai;
 
       printf("%s [gai]: ", argv[i]);
       for (this_ai = ai; this_ai != NULL; this_ai = this_ai->ai_next) {
         printf("%s ",
                inet_ntoa(((struct sockaddr_in*)(this_ai->ai_addr))->sin_addr));
       }
       printf("\n");
 
       freeaddrinfo(ai);
     }
 
   }
   return 0;
 }
 
 --p4dH/IeS7Q
 Content-Type: text/plain; charset=us-ascii
 Content-Description: .signature
 Content-Transfer-Encoding: 7bit
 
 
 -- 
 Jonathan Lennox
 lennox@cs.columbia.edu
 
 --p4dH/IeS7Q--

From: Pav Lucistnik <pav@FreeBSD.org>
To: lennox@cs.columbia.edu, bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/54189: [dns] resolver should resolve hostnames with
	underscores
Date: Mon, 06 Jun 2005 23:18:18 +0200

 Patch to allow underscores as "middlechars" in domain names. Works for me.
 
 
 --- /home/pav/res_comp.c	Mon Jun  6 23:13:29 2005
 +++ net/res_comp.c	Mon Jun  6 23:08:14 2005
 @@ -143,6 +143,7 @@
   */
  #define PERIOD 0x2e
  #define	hyphenchar(c) ((c) == 0x2d)
 +#define underscorechar(c)  ((c) == 0x5f)
  #define bslashchar(c) ((c) == 0x5c)
  #define periodchar(c) ((c) == PERIOD)
  #define asterchar(c) ((c) == 0x2a)
 @@ -151,7 +152,7 @@
  #define digitchar(c) ((c) >= 0x30 && (c) <= 0x39)
  
  #define borderchar(c) (alphachar(c) || digitchar(c))
 -#define middlechar(c) (borderchar(c) || hyphenchar(c))
 +#define middlechar(c) (borderchar(c) || hyphenchar(c) || underscorechar(c))
  #define	domainchar(c) ((c) > 0x20 && (c) < 0x7f)
  
  int
 
 
 -- 
 Pav Lucistnik <pav@oook.cz>
               <pav@FreeBSD.org>
 
 Thank God we're theoretical physicists so we don't have to get our
 hands dirty with particle accelerators and other heavy machinery.
Responsible-Changed-From-To: freebsd-bugs->remko 
Responsible-Changed-By: remko 
Responsible-Changed-When: Sun Mar 11 20:58:25 UTC 2007 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=54189 
State-Changed-From-To: open->closed 
State-Changed-By: remko 
State-Changed-When: Tue Apr 17 05:56:05 UTC 2007 
State-Changed-Why:  
OK. I discussed a bit with Rui Paolo about this and he had strong 
arguments to not proceed with this. NetBSD for instance does not allow _ 
's in the domain name, and the RFC's mention this should not be used. I 
do not want to break any RFC, better yet I want to comply with this as 
much as possible. I will close the ticket and not resolve this. If 
someone feels different about this, please discuss this and report it to 
me so that I can reopen the ticket if needed 

http://www.freebsd.org/cgi/query-pr.cgi?pr=54189 
>Unformatted:
