-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Handle unsupported AliasMode records #9656
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,26 +105,27 @@ class StateMachineDnsCall( | |
| return | ||
| } | ||
|
|
||
| val queries = | ||
| questions.map { question -> | ||
| val questionToQuery = | ||
| questions.associateWith { question -> | ||
| queryFactory.newQuery(question) | ||
| } | ||
|
|
||
| val next = | ||
| State.Running( | ||
| canceled = false, | ||
| callback = callback, | ||
| runningQueries = queries, | ||
| runningQueries = questionToQuery.values.toList(), | ||
| ) | ||
|
|
||
| if (!state.compareAndSet(previous, next)) continue // Lost a race, retry. | ||
|
|
||
| for (query in queries) { | ||
| for ((question, query) in questionToQuery) { | ||
| query.enqueue( | ||
| callback = | ||
| object : DnsQuery.Callback { | ||
| override fun onResponse(dnsResponse: DnsMessage) { | ||
| updateStateAndCallCallbacks( | ||
| question = question, | ||
| completedQuery = query, | ||
| dnsResponse = dnsResponse, | ||
| ) | ||
|
|
@@ -160,6 +161,7 @@ class StateMachineDnsCall( | |
| } | ||
|
|
||
| private fun updateStateAndCallCallbacks( | ||
| question: Question, | ||
| completedQuery: DnsQuery, | ||
| dnsResponse: DnsMessage, | ||
| ) { | ||
|
|
@@ -177,10 +179,21 @@ class StateMachineDnsCall( | |
| ) | ||
| } | ||
|
|
||
| val dnsRecords = | ||
| resourceRecords.map { resourceRecord -> | ||
| when (resourceRecord) { | ||
| is ResourceRecord.Https -> { | ||
| val dnsRecords: List<Dns.Record> = | ||
| when (question.type) { | ||
| TYPE_HTTPS -> { | ||
| resourceRecords.mapNotNull { resourceRecord -> | ||
| // Discard resource records that don't fit the query. | ||
| if (resourceRecord !is ResourceRecord.Https) return@mapNotNull null | ||
|
|
||
| // OkHttp doesn't yet implement AliasMode resource records. If any AliasMode record is | ||
| // returned, we must ignore ALL returned resource records. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO log something observable?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think the recipient of the warning is the person who can do anything about it. There's probably a DNS record linter tool for DNS admins to learn that their records are malformed. |
||
| if (resourceRecord.priority == 0) { | ||
| return updateStateAndCallCallbacks( | ||
| completedQuery = completedQuery, | ||
| ) | ||
| } | ||
|
|
||
| Dns.Record.ServiceMetadata( | ||
| hostname = resourceRecord.targetName.takeIf { it != "" } ?: request.hostname, | ||
| alpnIds = | ||
|
|
@@ -196,14 +209,23 @@ class StateMachineDnsCall( | |
| echConfigList = resourceRecord.echConfigList, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| TYPE_A, TYPE_AAAA -> { | ||
| resourceRecords.mapNotNull { resourceRecord -> | ||
| // Discard resource records that don't fit the query. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this seems unlikely and worth warning about, but I assume we think it won't happen, so ignore? Arguably ew should throw away A answers for a AAAA query, but I'm guessing this is a smart cast.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah even if we did warn, it's unlikely the recipient of the warning would be able to do something with it. |
||
| if (resourceRecord !is ResourceRecord.IpAddress) return@mapNotNull null | ||
|
|
||
| is ResourceRecord.IpAddress -> { | ||
| Dns.Record.IpAddress( | ||
| hostname = request.hostname, | ||
| address = resourceRecord.address, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| else -> { | ||
| error("unexpected question type") | ||
| } | ||
| } | ||
|
|
||
| updateStateAndCallCallbacks( | ||
|
|
||
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.
TIL The returned map preserves the entry iteration order of the original array.