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

feat: prioritize cached results if DNS resolver returns many results #6045

Merged
merged 1 commit into from
Oct 17, 2024

Conversation

link2xt
Copy link
Collaborator

@link2xt link2xt commented Oct 15, 2024

This ensures we do not get stuck trying DNS resolver results when we have a known to work IP address in the cache and DNS resolver returns garbage
either because it is a captive portal
or if it maliciously wants to get us stuck
trying a long list of unresponsive IP addresses.

This also limits the number of results we try to 10 overall. If there are more results, we will retry later
with new resolution results.

Closes #5918

@link2xt link2xt requested review from iequidoo and Hocuri October 15, 2024 13:29
@link2xt link2xt self-assigned this Oct 15, 2024
@link2xt link2xt force-pushed the link2xt/merge-dns-cache branch from 5ce2d8b to f7db6e9 Compare October 15, 2024 22:56
for addr in cache.into_iter().chain(rest.into_iter()) {
if !resolved_addrs.contains(&addr) {
resolved_addrs.push(addr);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

if resolved_addrs.len() >= 10 {
    break;
}

instead of truncate(), otherwise it's O(n^2)

src/net/dns.rs Outdated
}

// If cache contains address that is not in resolution results,
// it is appended in the end.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Cache is "inserted in the middle", it is only append here because resolved_addrs is short

src/net/dns.rs Outdated
);
}

// If DNS resolvers returns a lot of incorrect results,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// If DNS resolvers returns a lot of incorrect results,
// If DNS resolvers returns a lot of results,

Or "possibly incorrect" because we don't actually check them

This ensures we do not get stuck trying DNS resolver results
when we have a known to work IP address in the cache
and DNS resolver returns garbage
either because it is a captive portal
or if it maliciously wants to get us stuck
trying a long list of unresponsive IP addresses.

This also limits the number of results we try to 10 overall.
If there are more results, we will retry later
with new resolution results.
@link2xt link2xt force-pushed the link2xt/merge-dns-cache branch from f7db6e9 to a509ee9 Compare October 17, 2024 08:23
@link2xt link2xt merged commit 02b9085 into main Oct 17, 2024
29 of 37 checks passed
@link2xt link2xt deleted the link2xt/merge-dns-cache branch October 17, 2024 11:55
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.

Prioritize cached DNS results over DNS resolver results
2 participants