Skip to content

Commit 22e0d17

Browse files
avivkellermarco-ippolito
authored andcommitted
dns: stop using deprecated ares_query
PR-URL: #55430 Refs: #52464 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 12bd57f commit 22e0d17

File tree

2 files changed

+31
-28
lines changed

2 files changed

+31
-28
lines changed

src/cares_wrap.cc

+12-12
Original file line numberDiff line numberDiff line change
@@ -829,62 +829,62 @@ void ChannelWrap::EnsureServers() {
829829
}
830830

831831
int AnyTraits::Send(QueryWrap<AnyTraits>* wrap, const char* name) {
832-
wrap->AresQuery(name, ns_c_in, ns_t_any);
832+
wrap->AresQuery(name, ARES_CLASS_IN, ARES_REC_TYPE_ANY);
833833
return ARES_SUCCESS;
834834
}
835835

836836
int ATraits::Send(QueryWrap<ATraits>* wrap, const char* name) {
837-
wrap->AresQuery(name, ns_c_in, ns_t_a);
837+
wrap->AresQuery(name, ARES_CLASS_IN, ARES_REC_TYPE_A);
838838
return ARES_SUCCESS;
839839
}
840840

841841
int AaaaTraits::Send(QueryWrap<AaaaTraits>* wrap, const char* name) {
842-
wrap->AresQuery(name, ns_c_in, ns_t_aaaa);
842+
wrap->AresQuery(name, ARES_CLASS_IN, ARES_REC_TYPE_AAAA);
843843
return ARES_SUCCESS;
844844
}
845845

846846
int CaaTraits::Send(QueryWrap<CaaTraits>* wrap, const char* name) {
847-
wrap->AresQuery(name, ns_c_in, T_CAA);
847+
wrap->AresQuery(name, ARES_CLASS_IN, ARES_REC_TYPE_CAA);
848848
return ARES_SUCCESS;
849849
}
850850

851851
int CnameTraits::Send(QueryWrap<CnameTraits>* wrap, const char* name) {
852-
wrap->AresQuery(name, ns_c_in, ns_t_cname);
852+
wrap->AresQuery(name, ARES_CLASS_IN, ARES_REC_TYPE_CNAME);
853853
return ARES_SUCCESS;
854854
}
855855

856856
int MxTraits::Send(QueryWrap<MxTraits>* wrap, const char* name) {
857-
wrap->AresQuery(name, ns_c_in, ns_t_mx);
857+
wrap->AresQuery(name, ARES_CLASS_IN, ARES_REC_TYPE_MX);
858858
return ARES_SUCCESS;
859859
}
860860

861861
int NsTraits::Send(QueryWrap<NsTraits>* wrap, const char* name) {
862-
wrap->AresQuery(name, ns_c_in, ns_t_ns);
862+
wrap->AresQuery(name, ARES_CLASS_IN, ARES_REC_TYPE_NS);
863863
return ARES_SUCCESS;
864864
}
865865

866866
int TxtTraits::Send(QueryWrap<TxtTraits>* wrap, const char* name) {
867-
wrap->AresQuery(name, ns_c_in, ns_t_txt);
867+
wrap->AresQuery(name, ARES_CLASS_IN, ARES_REC_TYPE_TXT);
868868
return ARES_SUCCESS;
869869
}
870870

871871
int SrvTraits::Send(QueryWrap<SrvTraits>* wrap, const char* name) {
872-
wrap->AresQuery(name, ns_c_in, ns_t_srv);
872+
wrap->AresQuery(name, ARES_CLASS_IN, ARES_REC_TYPE_SRV);
873873
return ARES_SUCCESS;
874874
}
875875

876876
int PtrTraits::Send(QueryWrap<PtrTraits>* wrap, const char* name) {
877-
wrap->AresQuery(name, ns_c_in, ns_t_ptr);
877+
wrap->AresQuery(name, ARES_CLASS_IN, ARES_REC_TYPE_PTR);
878878
return ARES_SUCCESS;
879879
}
880880

881881
int NaptrTraits::Send(QueryWrap<NaptrTraits>* wrap, const char* name) {
882-
wrap->AresQuery(name, ns_c_in, ns_t_naptr);
882+
wrap->AresQuery(name, ARES_CLASS_IN, ARES_REC_TYPE_NAPTR);
883883
return ARES_SUCCESS;
884884
}
885885

886886
int SoaTraits::Send(QueryWrap<SoaTraits>* wrap, const char* name) {
887-
wrap->AresQuery(name, ns_c_in, ns_t_soa);
887+
wrap->AresQuery(name, ARES_CLASS_IN, ARES_REC_TYPE_SOA);
888888
return ARES_SUCCESS;
889889
}
890890

src/cares_wrap.h

+19-16
Original file line numberDiff line numberDiff line change
@@ -246,18 +246,20 @@ class QueryWrap final : public AsyncWrap {
246246
return Traits::Send(this, name);
247247
}
248248

249-
void AresQuery(const char* name, int dnsclass, int type) {
249+
void AresQuery(const char* name,
250+
ares_dns_class_t dnsclass,
251+
ares_dns_rec_type_t type) {
250252
channel_->EnsureServers();
251253
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(
252254
TRACING_CATEGORY_NODE2(dns, native), trace_name_, this,
253255
"name", TRACE_STR_COPY(name));
254-
ares_query(
255-
channel_->cares_channel(),
256-
name,
257-
dnsclass,
258-
type,
259-
Callback,
260-
MakeCallbackPointer());
256+
ares_query_dnsrec(channel_->cares_channel(),
257+
name,
258+
dnsclass,
259+
type,
260+
Callback,
261+
MakeCallbackPointer(),
262+
nullptr);
261263
}
262264

263265
void ParseError(int status) {
@@ -304,19 +306,20 @@ class QueryWrap final : public AsyncWrap {
304306
return wrap;
305307
}
306308

307-
static void Callback(
308-
void* arg,
309-
int status,
310-
int timeouts,
311-
unsigned char* answer_buf,
312-
int answer_len) {
309+
static void Callback(void* arg,
310+
ares_status_t status,
311+
size_t timeouts,
312+
const ares_dns_record_t* dnsrec) {
313313
QueryWrap<Traits>* wrap = FromCallbackPointer(arg);
314314
if (wrap == nullptr) return;
315315

316316
unsigned char* buf_copy = nullptr;
317+
size_t answer_len = 0;
317318
if (status == ARES_SUCCESS) {
318-
buf_copy = node::Malloc<unsigned char>(answer_len);
319-
memcpy(buf_copy, answer_buf, answer_len);
319+
// No need to explicitly call ares_free_string here,
320+
// as it is a wrapper around free, which is already
321+
// invoked when MallocedBuffer is destructed.
322+
ares_dns_write(dnsrec, &buf_copy, &answer_len);
320323
}
321324

322325
wrap->response_data_ = std::make_unique<ResponseData>();

0 commit comments

Comments
 (0)