CVSROOT: /cvs Module name: src Changes by: k...@cvs.openbsd.org 2022/11/14 06:57:46
Modified files: sbin/resolvd : resolvd.c Log message: Preserve original order of nameservers RFC 2132 "DHCP Options and BOOTP Vendor Extensions" 3.8. Domain Name Server Option says Servers SHOULD be listed in order of preference. tcpdump(8), route(8) monitor and dhcpleasectl(8) -l athn0 show servers from the DHCP OFFER in their original order, as expected. resolvd(8) however sorts proposals by priority and IP address before writing them to resolv.conf(5). But as the system resolver tries this file's `nameserver' options in the order appearance, sorting by IP breaks DHCP's intended order and thus may result in the wrong nameserver being queried. Sorting by IP is done to later remove duplicates from the file. Sort by priority alone and ensure uniqueness by iterating over the list of of proposals and zeroeing duplicates instead to preserve any proposal's original order. Spotted on a public wifi OFFERing two local IPs plus 8.8.8.8 in this order which ended up with 8.8.8.8 being the first entry in my /etc/resolv.conf. In other words, `route nameserver lo0 2.2.2.2 1.1.1.1 1.1.1.1' now yields nameserver 2.2.2.2 # resolvd: lo0 nameserver 1.1.1.1 # resolvd: lo0 rather than nameserver 1.1.1.1 # resolvd: lo0 nameserver 2.2.2.2 # resolvd: lo0 Feedback OK deraadt