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

posix: multiple resolv.conf entries, avoid ipv6 failure on dns functions #405

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

AtieP
Copy link
Contributor

@AtieP 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().
@ArsenArsen
Copy link
Member

Allow only IPV4 resolv.conf entries on lookup_name_dns() and lookup_addr_dns().

Why is this needed?

@AtieP
Copy link
Contributor Author

AtieP commented Apr 9, 2022

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.

@ArsenArsen
Copy link
Member

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.

@AtieP
Copy link
Contributor Author

AtieP commented Apr 9, 2022

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.

Copy link
Member

@Geertiebear Geertiebear left a 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_)
Copy link
Member

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,
Copy link
Member

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;
Copy link
Member

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) {
Copy link
Member

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>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

@AtieP
Copy link
Contributor Author

AtieP commented Apr 12, 2022

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 ret.name is empty, and by putting the string inside of a local variable first and then if everything is ok, assign it to the return struct, you avoid the complexity of doing the cleanup inside the loop.

@ArsenArsen
Copy link
Member

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.

resolv.conf changes dynamically

@Dennisbonke
Copy link
Member

Can we approve this PR for ci runs?

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.

4 participants