Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved IPv6 link local resolver error and add unit testing for parsing function #526

Merged
merged 4 commits into from
Mar 12, 2025

Conversation

phillip-stephens
Copy link
Contributor

Resolves #512

Following the discussion on the issue #512, I wanted to improve the error messages around why a given line will fail to parse in /etc/resolv.conf. This PR:

  • improves our parsing function to offer more granular errors
  • Make parsing function operate on an io.Reader to enable easier unit-testing of the parsing
  • Fix a bug found with the unit test where we couldn't parse an IPv6 address with a port, or certain shortened IPv6 addresses

Per man resolvctl, the dns section specifies that nameservers may take the form: "That is, the acceptable full formats are "111.222.333.444:9953%ifname#example.com" for IPv4 and "[1111:2222::3333]:9953%ifname#example.com" for IPv6."

We don't support domain names with nameservers in /etc/resolv.conf or per-interface nameservers.

Testing

Link-Local IPv6 Address

$ cat /etc/resolv.conf     
...
nameserver [2001:db8:3333:4444:5555:6666:7777:8888]:53%eth0

~/zdns on  phillip/512-improved-link-local-resolver-error ⌚ 10:42:36
$ ./zdns A prstephens.com
FATA[0000] ZDNS is unable to parse resolvers file. ZDNS only supports IPv4 and IPv6 addresses with an optional port,  either 111.222.333.444:9953 or [1111:2222::3333]:9953. Please either modify your /etc/resolv.conf file or use '--name-servers'. Error: could not parse IP address ([2001:db8:3333:4444:5555:6666:7777:8888]:53%eth0) from config. We do not support specifying link-local IPv6 addresses or per-interface nameservers 

Passing Domain Names with IP addresses

$ cat /etc/resolv.conf   
...
nameserver 1.1.1.1#cloudflare.com

~/zdns on  phillip/512-improved-link-local-resolver-error ⌚ 10:48:28
$ ./zdns A prstephens.com
FATA[0000] ZDNS is unable to parse resolvers file. ZDNS only supports IPv4 and IPv6 addresses with an optional port,  either 111.222.333.444:9953 or [1111:2222::3333]:9953. Please either modify your /etc/resolv.conf file or use '--name-servers'. Error: could not parse IP address (1.1.1.1#cloudflare.com) from config. We do not support specifying domain names for nameservers 

Base Case - Works

$ cat /etc/resolv.conf     
...
search stanford.edu
nameserver 1.1.1.1

~/zdns on  phillip/512-improved-link-local-resolver-error ⌚ 10:49:56
$ ./zdns A prstephens.com  
{"name":"prstephens.com","results":{"A":{"data":{"additionals":[{"flags":"","type":"EDNS0","udpsize":1232,"version":0}],"answers":[{"answer":"104.21.96.65","class":"IN","name":"prstephens.com","ttl":300,"type":"A"},{"answer":"172.67.173.251","class":"IN","name":"prstephens.com","ttl":300,"type":"A"}],"protocol":"udp","resolver":"1.1.1.1:53"},"duration":0.022647458,"status":"NOERROR","timestamp":"2025-03-12T10:49:59-07:00"}}}
00h:00m:00s; Scan Complete; 1 names scanned; 42.48 names/sec; 100.0% success rate; NOERROR: 1

@phillip-stephens phillip-stephens requested a review from a team as a code owner March 12, 2025 17:50
@phillip-stephens phillip-stephens requested a review from zakird March 12, 2025 18:04
@zakird zakird merged commit 7f4676a into main Mar 12, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Unable to parse IPv6 link-local resolvers from resolv.conf
2 participants