klange / toaruos

A completely-from-scratch hobby operating system: bootloader, kernel, drivers, C library, and userspace including a composited graphical UI, dynamic linker, syntax-highlighting text editor, network stack, etc.
https://toaruos.org/
University of Illinois/NCSA Open Source License
6.03k stars 475 forks source link

Improve the DNS resolver #217

Open klange opened 2 years ago

klange commented 2 years ago

In toaru32, the DNS resolver lived in the kernel, inside the network stack. This was not great, but it was a requirement for the old /dev/net virtual filesystem to work with domains, so it wasn't going anywhere as long as that stuck around.

As we've switched to traditional sockets-based interface, DNS resolution moved to userspace and now lives entirely in gethostbyname in the libc. This gives us the opportunity to be more flexible and write a smarter parser, but at the moment it remains pretty naïve: It assumes the last four bytes of a response are an IP address. This works fine in most setups where a local DNS server on a router or ISP is handling recursive lookup, but in environments where that's not the case we can end up not understanding a simple CNAME or other recursive record.

On the path towards writing a better resolver, an improved nslookup or a dig tool would be a good thing to investigate: Currently, nslookup just calls gethostbyname.