-
-
Notifications
You must be signed in to change notification settings - Fork 134
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
posix: multiple resolv.conf entries, avoid ipv6 failure on dns functions #405
base: master
Are you sure you want to change the base?
Conversation
AtieP
commented
Apr 9, 2022
- Allow any resolv.conf entry to be retrieved.
- Allow only IPV4 resolv.conf entries on lookup_name_dns() and lookup_addr_dns().
- If one resolv.conf entry doesn't work on lookup_nane_dns() and lookup_addr_dns(), use the next one.
* Allow any resolv.conf entry to be retrieved. * Allow only IPV4 resolv.conf entries on lookup_name_dns() and lookup_addr_dns().
Why is this needed? |
Because having an IPV6 address breaks the code, since there isn't support for them yet in inet_pton(), and the DNS code at all. |
What special work is even needed for them to work in the DNS code? This is not AAAA records, this is socket(AF_INET6) instead of AF_INET. |
I meant that there isn't IPV6 inet_pton() support yet, so passing a IPV6 address to it just breaks, and what lookup_name_dns()/lookup_addr_dns() do is use that exact function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments, nothing major. Another improvement that could be made is caching resolv.conf
entries so we don't have to parse the file on every request.
@@ -10,11 +10,15 @@ namespace mlibc { | |||
struct nameserver_data { | |||
nameserver_data() | |||
: name(getAllocator()) {} | |||
nameserver_data(const char *name_, int af_) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really minor nitpick, but we don't do this in the managarm code style, nor is it necessary.
while (true) { | ||
auto nameserver = get_nameserver(nameserver_idx++); | ||
if (!nameserver) { | ||
// no more nameservers in resolf.conf, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another style note: comments should be formally written. So with proper punctuation and capitalization.
if (!inet_aton(nameserver ? nameserver->name.data() : "127.0.0.1", &sin.sin_addr)) { | ||
mlibc::infoLogger() << "lookup_name_dns(): inet_aton() failed!" << frg::endlog; | ||
return -EAI_SYSTEM; | ||
int nameserver_idx = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this routine can be split up into a function.
mlibc::infoLogger() << "lookup_name_dns(): inet_aton() failed!" << frg::endlog; | ||
return -EAI_SYSTEM; | ||
int nameserver_idx = 0; | ||
while (true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this while loop doesn't need to be a while(true)
loop, you can also write while(nameserver = get_nameserver())
.
char *end; | ||
for (pos = line + 11; isspace(*pos); pos++); | ||
for (end = pos; *end && !isspace(*end); end++); | ||
*end = '\0'; | ||
ret.name = frg::string<MemoryAllocator>( | ||
auto str = frg::string<MemoryAllocator>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
Sure @Geertiebear , I will improve everything you mentioned. The rationale behind the last snippet is to make error handling easier, since outside of the while loop the code checks if an error happened by seeing if |
|
Can we approve this PR for ci runs? |