Subject: lib/31184: resolv.conf "sortlist" directive nonfunctional
To: None <lib-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <tsarna@sarna.org>
List: netbsd-bugs
Date: 09/07/2005 19:03:00
>Number:         31184
>Category:       lib
>Synopsis:       resolv.conf "sortlist" directive nonfunctional
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Sep 07 19:03:00 +0000 2005
>Originator:     Ty Sarna
>Release:        NetBSD 3.99.7
>Organization:
	
>Environment:
System: NetBSD kohaku.sarna.org 3.99.7 NetBSD 3.99.7 (KOHAKU) #1: Thu Jul 14 11:57:19 EDT 2005 tsarna@talyn.frontco.com:/usr/build/KOHAKU i386
Architecture: i386
Machine: i386
>Description:
	The "sortlist" directive in resolv.conf is not honored.
>How-To-Repeat:
	The rfc1918 addresses are only visible in an internal view so
	you won't be able to reproduce this exactly, but:

: kohaku; cat /etc/resolv.conf 
nameserver 127.0.0.1
search sarna.org
sortlist 172.27.1.0/255.255.255.0 70.89.96.32/255.255.255.248
: kohaku; getent hosts asagi # getent hosts uses gethostbyname
70.89.96.37       asagi.sarna.org
: kohaku; getent hosts asagi
172.27.1.21       asagi.sarna.org
: kohaku; getent hosts asagi
70.89.96.37       asagi.sarna.org
: kohaku; getent hosts asagi
172.27.1.21       asagi.sarna.org
: kohaku; telnet asagi 42	# telnet uses getaddrinfo
Trying 70.89.96.37...
telnet: connect to address 70.89.96.37: Connection refused
Trying 172.27.1.21...
telnet: Unable to connect to remote host: Connection refused
: kohaku; telnet asagi 42
Trying 172.27.1.21...
telnet: connect to address 172.27.1.21: Connection refused
Trying 70.89.96.37...
telnet: Unable to connect to remote host: Connection refused
		
>Fix:
	The support in res_init.c (for parsing resolv.conf)
	and gethnamaddr.c (for applying the sort) is keyed on 
	the define RESOLVSORT. RESOLVSORT is #defined in res_init.c, but
	not in gethnamaddr.c. Either a define needs to be added to
	gethnamaddr.c also or the define should be moved from res_init.c
	to an include file.

	getaddrinfo.c lacks support entirely. It contains a semi-duplicate
	getanswer() from gethnamaddr.c that lacks the call to addrsort()
	(which is static to gethnamaddr.c. anyway). addrsort() needs to
	be added to that version of getanswer using gethnamaddr.c's
	getanswer as a template, and addrsort() needs to be visible to
	getaddrinfo.c somehow (perhaps de-static'd and renamed with
	underscore?)