-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
Add Support for resolving DNS using search list for host-name loopkup. #19548
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 |
---|---|---|
|
@@ -285,6 +285,9 @@ changes: | |
When `true`, the callback receives an array of | ||
`{ address: '1.2.3.4', ttl: 60 }` objects rather than an array of strings, | ||
with the TTL expressed in seconds. | ||
- `search` {boolean} Resolve the DNS using the local domain name or the search | ||
list for host-name lookup. | ||
When `true`, the resolve will use the search list which can create extra dns queries. | ||
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. Nits:
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.
|
||
- `callback` {Function} | ||
- `err` {Error} | ||
- `addresses` {string[] | Object[]} | ||
|
@@ -310,6 +313,9 @@ changes: | |
When `true`, the callback receives an array of | ||
`{ address: '0:1:2:3:4:5:6:7', ttl: 60 }` objects rather than an array of | ||
strings, with the TTL expressed in seconds. | ||
- `search` {boolean} Resolve the DNS using the local domain name or the search | ||
list for host-name lookup. | ||
When `true`, the resolve will use the search list which can create extra dns queries. | ||
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. The same) |
||
- `callback` {Function} | ||
- `err` {Error} | ||
- `addresses` {string[] | Object[]} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,15 @@ inline v8::Local<v8::Object> BaseObject::object() { | |
} | ||
|
||
|
||
inline v8::MaybeLocal<v8::Value> BaseObject::GetField( | ||
std::string const& field) { | ||
return object()->Get(env()->context(), | ||
v8::String::NewFromUtf8(env()->isolate(), | ||
field.c_str(), | ||
v8::NewStringType::kNormal).ToLocalChecked()); | ||
} | ||
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. Can you drop this method? There is no reason for it to live on BaseObject. |
||
|
||
|
||
inline Environment* BaseObject::env() const { | ||
return env_; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -619,6 +619,14 @@ class QueryWrap : public AsyncWrap { | |
static_cast<void*>(this)); | ||
} | ||
|
||
void AresSearch(const char* name, | ||
int dnsclass, | ||
int type) { | ||
channel_->EnsureServers(); | ||
ares_search(channel_->cares_channel(), name, dnsclass, type, Callback, | ||
static_cast<void*>(this)); | ||
} | ||
|
||
static void CaresAsyncClose(uv_handle_t* handle) { | ||
uv_async_t* async = reinterpret_cast<uv_async_t*>(handle); | ||
auto data = static_cast<struct CaresAsyncData*>(async->data); | ||
|
@@ -1360,7 +1368,20 @@ class QueryAWrap: public QueryWrap { | |
} | ||
|
||
int Send(const char* name) override { | ||
AresQuery(name, ns_c_in, ns_t_a); | ||
auto prop_value = GetField("search"); | ||
bool bSearch = false; | ||
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. Style: no hungarian, just (e.g.) |
||
|
||
if (!prop_value.IsEmpty()) { | ||
auto search_prop = prop_value.ToLocalChecked()->ToBoolean(); | ||
bSearch = search_prop->Value(); | ||
} | ||
|
||
if (bSearch) { | ||
AresSearch(name, ns_c_in, ns_t_a); | ||
} else { | ||
AresQuery(name, ns_c_in, ns_t_a); | ||
} | ||
|
||
return 0; | ||
} | ||
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. Rather than looking up properties this is arguably better handled by making template <void (*F)(const char*, int, int)>
class BaseWrap {
// ...
void AresQuery(const char* name, int dnsclass, int type) {
channel_->EnsureServers();
F(channel_->cares_channel(), name, dnsclass, type, Callback,
static_cast<void*>(this));
}
// ...
};
using QueryWrap = BaseWrap<ares_query>;
using SearchWrap = BaseWrap<ares_search>; And then do the same to template <typename BaseT>
class BaseAWrap: public BaseT {
// ... - no changes needed to body
};
using QueryAWrap = BaseAWrap<QueryWrap>;
using SearchAWrap = BaseAWrap<SearchWrap>;
// Repeat for QueryAaaaWrap 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. No problem I'll make the changes.
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.
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. Re: resolveMap, that's correct. Re: testing: I don't know. It depends too much on the configuration of the system, I think. |
||
|
||
|
@@ -1404,7 +1425,20 @@ class QueryAaaaWrap: public QueryWrap { | |
} | ||
|
||
int Send(const char* name) override { | ||
AresQuery(name, ns_c_in, ns_t_aaaa); | ||
auto prop_value = GetField("search"); | ||
bool bSearch = false; | ||
|
||
if (!prop_value.IsEmpty()) { | ||
auto search_prop = prop_value.ToLocalChecked()->ToBoolean(); | ||
bSearch = search_prop->Value(); | ||
} | ||
|
||
if (bSearch) { | ||
AresSearch(name, ns_c_in, ns_t_a); | ||
} else { | ||
AresQuery(name, ns_c_in, ns_t_a); | ||
} | ||
|
||
return 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.
Resolve the DNS using
->Resolve the hostname