1 /* $NetBSD: res_debug.c,v 1.13 2012/06/25 22:32:45 abs Exp $ */
2
3 /*
4 * Portions Copyright (C) 2004, 2005, 2008, 2009 Internet Systems Consortium, Inc. ("ISC")
5 * Portions Copyright (C) 1996-2003 Internet Software Consortium.
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
18 */
19
20 /*
21 * Copyright (c) 1985
22 * The Regents of the University of California. All rights reserved.
23 *
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
26 * are met:
27 * 1. Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * 2. Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in the
31 * documentation and/or other materials provided with the distribution.
32 * 3. All advertising materials mentioning features or use of this software
33 * must display the following acknowledgement:
34 * This product includes software developed by the University of
35 * California, Berkeley and its contributors.
36 * 4. Neither the name of the University nor the names of its contributors
37 * may be used to endorse or promote products derived from this software
38 * without specific prior written permission.
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
44 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50 * SUCH DAMAGE.
51 */
52
53 /*
54 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
55 *
56 * Permission to use, copy, modify, and distribute this software for any
57 * purpose with or without fee is hereby granted, provided that the above
58 * copyright notice and this permission notice appear in all copies, and that
59 * the name of Digital Equipment Corporation not be used in advertising or
60 * publicity pertaining to distribution of the document or software without
61 * specific, written prior permission.
62 *
63 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
64 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
65 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
66 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
67 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
68 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
69 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
70 * SOFTWARE.
71 */
72
73 /*
74 * Portions Copyright (c) 1995 by International Business Machines, Inc.
75 *
76 * International Business Machines, Inc. (hereinafter called IBM) grants
77 * permission under its copyrights to use, copy, modify, and distribute this
78 * Software with or without fee, provided that the above copyright notice and
79 * all paragraphs of this notice appear in all copies, and that the name of IBM
80 * not be used in connection with the marketing of any product incorporating
81 * the Software or modifications thereof, without specific, written prior
82 * permission.
83 *
84 * To the extent it has a right to do so, IBM grants an immunity from suit
85 * under its patents, if any, for the use, sale or manufacture of products to
86 * the extent that such products are used for performing Domain Name System
87 * dynamic updates in TCP/IP networks by means of the Software. No immunity is
88 * granted for any product per se or for any other function of any product.
89 *
90 * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
91 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
92 * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
93 * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
94 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
95 * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
96 */
97
98 #define LOG_TAG "resolv"
99
100 #include "res_debug.h"
101
102 #include <sys/param.h>
103 #include <sys/socket.h>
104
105 #include <arpa/inet.h>
106 #include <arpa/nameser.h>
107 #include <netinet/in.h>
108
109 #include <aidl/android/net/IDnsResolver.h>
110 #include <android-base/logging.h>
111 #include <ctype.h>
112 #include <errno.h>
113 #include <inttypes.h>
114 #include <math.h>
115 #include <netdb.h>
116 #include <stdlib.h>
117 #include <string.h>
118 #include <strings.h>
119 #include <time.h>
120
121 #include "doh.h"
122 #include "resolv_private.h"
123
124 // Default to disabling verbose logging unless overridden by Android.bp
125 // for debuggable builds.
126 //
127 // NOTE: Verbose resolver logs could contain PII -- do NOT enable in production builds
128 #ifndef RESOLV_ALLOW_VERBOSE_LOGGING
129 #define RESOLV_ALLOW_VERBOSE_LOGGING 0
130 #endif
131
132 using fmt::format_to;
133
134 struct res_sym {
135 int number; /* Identifying number, like T_MX */
136 const char* name; /* Its symbolic name, like "MX" */
137 const char* humanname; /* Its fun name, like "mail exchanger" */
138 };
139
do_section(ns_msg * handle,ns_sect section)140 static void do_section(ns_msg* handle, ns_sect section) {
141 int n, rrnum = 0;
142 int buflen = 2048;
143 ns_rr rr;
144 std::string s;
145 auto out = std::back_inserter(s);
146 /*
147 * Print answer records.
148 */
149 for (;;) {
150 if (ns_parserr(handle, section, rrnum, &rr)) {
151 if (errno != ENODEV) format_to(out, "ns_parserr: {}", strerror(errno));
152
153 LOG(VERBOSE) << s;
154 return;
155 }
156 if (rrnum == 0) {
157 int opcode = ns_msg_getflag(*handle, ns_f_opcode);
158 format_to(out, ";; {} SECTION:\n", p_section(section, opcode));
159 }
160 if (section == ns_s_qd)
161 format_to(out, ";;\t{}, type = {}, class = {}\n", ns_rr_name(rr),
162 p_type(ns_rr_type(rr)), p_class(ns_rr_class(rr)));
163 else if (section == ns_s_ar && ns_rr_type(rr) == ns_t_opt) {
164 size_t rdatalen;
165 uint16_t optcode, optlen;
166
167 rdatalen = ns_rr_rdlen(rr);
168 format_to(out, "; EDNS: version: {}, udp={}, flags={}\n", (rr.ttl >> 16) & 0xff,
169 ns_rr_class(rr), rr.ttl & 0xffff);
170 const uint8_t* cp = ns_rr_rdata(rr);
171 while (rdatalen <= ns_rr_rdlen(rr) && rdatalen >= 4) {
172 int i;
173
174 GETSHORT(optcode, cp);
175 GETSHORT(optlen, cp);
176
177 if (optcode == NS_OPT_NSID) {
178 format_to(out, "; NSID: ");
179 if (optlen == 0) {
180 format_to(out, "; NSID\n");
181 } else {
182 format_to(out, "; NSID: ");
183 for (i = 0; i < optlen; i++) {
184 format_to(out, "{:02x} ", cp[i]);
185 }
186 format_to(out, " (");
187 for (i = 0; i < optlen; i++) {
188 format_to(out, "{} ", isprint(cp[i]) ? cp[i] : '.');
189 }
190 format_to(out, ")\n");
191 }
192 } else {
193 if (optlen == 0) {
194 format_to(out, "; OPT={}\n", optcode);
195 } else {
196 format_to(out, "; OPT={}: ", optcode);
197 for (i = 0; i < optlen; i++) {
198 format_to(out, "{:02x} ", cp[i]);
199 }
200 format_to(out, " (");
201 for (i = 0; i < optlen; i++) {
202 format_to(out, "{}", isprint(cp[i]) ? cp[i] : '.');
203 }
204 format_to(out, ")\n");
205 }
206 }
207 rdatalen -= 4 + optlen;
208 cp += optlen;
209 }
210 } else {
211 auto buf = std::make_unique<char[]>(buflen);
212 n = ns_sprintrr(handle, &rr, NULL, NULL, buf.get(), (uint32_t)buflen);
213 if (n < 0) {
214 if (errno == ENOSPC) {
215 if (buflen < 131072) {
216 buflen += 1024;
217 continue;
218 } else {
219 format_to(out, "buflen over 131072");
220 PLOG(VERBOSE) << s;
221 return;
222 }
223 }
224 format_to(out, "ns_sprintrr failed");
225 PLOG(VERBOSE) << s;
226 return;
227 }
228 format_to(out, ";; {}\n", buf.get());
229 }
230 rrnum++;
231 }
232 }
233
234 // Convert bytes to its hexadecimal representation.
235 // The returned string is double the size of input.
bytesToHexStr(std::span<const uint8_t> bytes)236 std::string bytesToHexStr(std::span<const uint8_t> bytes) {
237 static char const hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7',
238 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
239 std::string str;
240 str.reserve(bytes.size() * 2);
241 for (uint8_t ch : bytes) {
242 str.append({hex[(ch & 0xf0) >> 4], hex[ch & 0xf]});
243 }
244 return str;
245 }
246
247 /*
248 * Print the contents of a query.
249 * This is intended to be primarily a debugging routine.
250 */
res_pquery(std::span<const uint8_t> msg)251 void res_pquery(std::span<const uint8_t> msg) {
252 if (!WOULD_LOG(VERBOSE)) return;
253
254 ns_msg handle;
255 int qdcount, ancount, nscount, arcount;
256 uint32_t opcode, rcode, id;
257
258 if (ns_initparse(msg.data(), msg.size(), &handle) < 0) {
259 PLOG(VERBOSE) << "ns_initparse failed";
260 return;
261 }
262 opcode = ns_msg_getflag(handle, ns_f_opcode);
263 rcode = ns_msg_getflag(handle, ns_f_rcode);
264 id = ns_msg_id(handle);
265 qdcount = ns_msg_count(handle, ns_s_qd);
266 ancount = ns_msg_count(handle, ns_s_an);
267 nscount = ns_msg_count(handle, ns_s_ns);
268 arcount = ns_msg_count(handle, ns_s_ar);
269
270 /*
271 * Print header fields.
272 */
273 std::string s = fmt::format(";; ->>HEADER<<- opcode: {}, status: {}, id: {}\n",
274 _res_opcodes[opcode], p_rcode((int)rcode), id);
275 auto out = std::back_inserter(s);
276 format_to(out, ";; flags:");
277 if (ns_msg_getflag(handle, ns_f_qr)) format_to(out, " qr");
278 if (ns_msg_getflag(handle, ns_f_aa)) format_to(out, " aa");
279 if (ns_msg_getflag(handle, ns_f_tc)) format_to(out, " tc");
280 if (ns_msg_getflag(handle, ns_f_rd)) format_to(out, " rd");
281 if (ns_msg_getflag(handle, ns_f_ra)) format_to(out, " ra");
282 if (ns_msg_getflag(handle, ns_f_z)) format_to(out, " ??");
283 if (ns_msg_getflag(handle, ns_f_ad)) format_to(out, " ad");
284 if (ns_msg_getflag(handle, ns_f_cd)) format_to(out, " cd");
285 format_to(out, "; {}: {}", p_section(ns_s_qd, (int)opcode), qdcount);
286 format_to(out, ", {}: {}", p_section(ns_s_an, (int)opcode), ancount);
287 format_to(out, ", {}: {}", p_section(ns_s_ns, (int)opcode), nscount);
288 format_to(out, ", {}: {}", p_section(ns_s_ar, (int)opcode), arcount);
289
290 LOG(VERBOSE) << s;
291
292 /*
293 * Print the various sections.
294 */
295 do_section(&handle, ns_s_qd);
296 do_section(&handle, ns_s_an);
297 do_section(&handle, ns_s_ns);
298 do_section(&handle, ns_s_ar);
299
300 LOG(VERBOSE) << "Hex dump:";
301 LOG(VERBOSE) << bytesToHexStr(msg);
302 }
303
304 /*
305 * Names of RR classes and qclasses. Classes and qclasses are the same, except
306 * that C_ANY is a qclass but not a class. (You can ask for records of class
307 * C_ANY, but you can't have any records of that class in the database.)
308 */
309 static const struct res_sym p_class_syms[] = {
310 {C_IN, "IN", (char*) 0}, {C_CHAOS, "CH", (char*) 0}, {C_CHAOS, "CHAOS", (char*) 0},
311 {C_HS, "HS", (char*) 0}, {C_HS, "HESIOD", (char*) 0}, {C_ANY, "ANY", (char*) 0},
312 {C_NONE, "NONE", (char*) 0}, {C_IN, (char*) 0, (char*) 0}};
313
314 /*
315 * Names of message sections.
316 */
317 static const struct res_sym p_default_section_syms[] = {{ns_s_qd, "QUERY", (char*) 0},
318 {ns_s_an, "ANSWER", (char*) 0},
319 {ns_s_ns, "AUTHORITY", (char*) 0},
320 {ns_s_ar, "ADDITIONAL", (char*) 0},
321 {0, (char*) 0, (char*) 0}};
322
323 static const struct res_sym p_update_section_syms[] = {{S_ZONE, "ZONE", (char*) 0},
324 {S_PREREQ, "PREREQUISITE", (char*) 0},
325 {S_UPDATE, "UPDATE", (char*) 0},
326 {S_ADDT, "ADDITIONAL", (char*) 0},
327 {0, (char*) 0, (char*) 0}};
328
329 /*
330 * Names of RR types and qtypes. Types and qtypes are the same, except
331 * that T_ANY is a qtype but not a type. (You can ask for records of type
332 * T_ANY, but you can't have any records of that type in the database.)
333 */
334 const struct res_sym p_type_syms[] = {
335 {ns_t_a, "A", "address"},
336 {ns_t_ns, "NS", "name server"},
337 {ns_t_md, "MD", "mail destination (deprecated)"},
338 {ns_t_mf, "MF", "mail forwarder (deprecated)"},
339 {ns_t_cname, "CNAME", "canonical name"},
340 {ns_t_soa, "SOA", "start of authority"},
341 {ns_t_mb, "MB", "mailbox"},
342 {ns_t_mg, "MG", "mail group member"},
343 {ns_t_mr, "MR", "mail rename"},
344 {ns_t_null, "NULL", "null"},
345 {ns_t_wks, "WKS", "well-known service (deprecated)"},
346 {ns_t_ptr, "PTR", "domain name pointer"},
347 {ns_t_hinfo, "HINFO", "host information"},
348 {ns_t_minfo, "MINFO", "mailbox information"},
349 {ns_t_mx, "MX", "mail exchanger"},
350 {ns_t_txt, "TXT", "text"},
351 {ns_t_rp, "RP", "responsible person"},
352 {ns_t_afsdb, "AFSDB", "DCE or AFS server"},
353 {ns_t_x25, "X25", "X25 address"},
354 {ns_t_isdn, "ISDN", "ISDN address"},
355 {ns_t_rt, "RT", "router"},
356 {ns_t_nsap, "NSAP", "nsap address"},
357 {ns_t_nsap_ptr, "NSAP_PTR", "domain name pointer"},
358 {ns_t_sig, "SIG", "signature"},
359 {ns_t_key, "KEY", "key"},
360 {ns_t_px, "PX", "mapping information"},
361 {ns_t_gpos, "GPOS", "geographical position (withdrawn)"},
362 {ns_t_aaaa, "AAAA", "IPv6 address"},
363 {ns_t_loc, "LOC", "location"},
364 {ns_t_nxt, "NXT", "next valid name (unimplemented)"},
365 {ns_t_eid, "EID", "endpoint identifier (unimplemented)"},
366 {ns_t_nimloc, "NIMLOC", "NIMROD locator (unimplemented)"},
367 {ns_t_srv, "SRV", "server selection"},
368 {ns_t_atma, "ATMA", "ATM address (unimplemented)"},
369 {ns_t_naptr, "NAPTR", "naptr"},
370 {ns_t_kx, "KX", "key exchange"},
371 {ns_t_cert, "CERT", "certificate"},
372 {ns_t_a6, "A", "IPv6 address (experminental)"},
373 {ns_t_dname, "DNAME", "non-terminal redirection"},
374 {ns_t_opt, "OPT", "opt"},
375 {ns_t_apl, "apl", "apl"},
376 {ns_t_ds, "DS", "delegation signer"},
377 {ns_t_sshfp, "SSFP", "SSH fingerprint"},
378 {ns_t_ipseckey, "IPSECKEY", "IPSEC key"},
379 {ns_t_rrsig, "RRSIG", "rrsig"},
380 {ns_t_nsec, "NSEC", "nsec"},
381 {ns_t_dnskey, "DNSKEY", "DNS key"},
382 {ns_t_dhcid, "DHCID", "dynamic host configuration identifier"},
383 {ns_t_nsec3, "NSEC3", "nsec3"},
384 {ns_t_nsec3param, "NSEC3PARAM", "NSEC3 parameters"},
385 {ns_t_hip, "HIP", "host identity protocol"},
386 {ns_t_spf, "SPF", "sender policy framework"},
387 {ns_t_tkey, "TKEY", "tkey"},
388 {ns_t_tsig, "TSIG", "transaction signature"},
389 {ns_t_ixfr, "IXFR", "incremental zone transfer"},
390 {ns_t_axfr, "AXFR", "zone transfer"},
391 {ns_t_zxfr, "ZXFR", "compressed zone transfer"},
392 {ns_t_mailb, "MAILB", "mailbox-related data (deprecated)"},
393 {ns_t_maila, "MAILA", "mail agent (deprecated)"},
394 {ns_t_naptr, "NAPTR", "URN Naming Authority"},
395 {ns_t_kx, "KX", "Key Exchange"},
396 {ns_t_cert, "CERT", "Certificate"},
397 {ns_t_a6, "A6", "IPv6 Address"},
398 {ns_t_dname, "DNAME", "dname"},
399 {ns_t_sink, "SINK", "Kitchen Sink (experimental)"},
400 {ns_t_opt, "OPT", "EDNS Options"},
401 {ns_t_any, "ANY", "\"any\""},
402 {ns_t_dlv, "DLV", "DNSSEC look-aside validation"},
403 {0, NULL, NULL}};
404
405 /*
406 * Names of DNS rcodes.
407 */
408 static const struct res_sym p_rcode_syms[] = {{ns_r_noerror, "NOERROR", "no error"},
409 {ns_r_formerr, "FORMERR", "format error"},
410 {ns_r_servfail, "SERVFAIL", "server failed"},
411 {ns_r_nxdomain, "NXDOMAIN", "no such domain name"},
412 {ns_r_notimpl, "NOTIMP", "not implemented"},
413 {ns_r_refused, "REFUSED", "refused"},
414 {ns_r_yxdomain, "YXDOMAIN", "domain name exists"},
415 {ns_r_yxrrset, "YXRRSET", "rrset exists"},
416 {ns_r_nxrrset, "NXRRSET", "rrset doesn't exist"},
417 {ns_r_notauth, "NOTAUTH", "not authoritative"},
418 {ns_r_notzone, "NOTZONE", "Not in zone"},
419 {ns_r_max, "", ""},
420 {ns_r_badsig, "BADSIG", "bad signature"},
421 {ns_r_badkey, "BADKEY", "bad key"},
422 {ns_r_badtime, "BADTIME", "bad time"},
423 {0, NULL, NULL}};
424
sym_ntos(const struct res_sym * syms,int number,int * success)425 static const char* sym_ntos(const struct res_sym* syms, int number, int* success) {
426 static char unname[20];
427
428 for (; syms->name != 0; syms++) {
429 if (number == syms->number) {
430 if (success) *success = 1;
431 return (syms->name);
432 }
433 }
434
435 snprintf(unname, sizeof(unname), "%d", number); /* XXX nonreentrant */
436 if (success) *success = 0;
437 return (unname);
438 }
439
440 /*
441 * Return a string for the type.
442 */
p_type(int type)443 const char* p_type(int type) {
444 int success;
445 const char* result;
446 static char typebuf[20];
447
448 result = sym_ntos(p_type_syms, type, &success);
449 if (success) return (result);
450 if (type < 0 || type > 0xffff) return ("BADTYPE");
451 snprintf(typebuf, sizeof(typebuf), "TYPE%d", type);
452 return (typebuf);
453 }
454
455 /*
456 * Return a string for the type.
457 */
p_section(int section,int opcode)458 const char* p_section(int section, int opcode) {
459 const struct res_sym* symbols;
460
461 switch (opcode) {
462 case ns_o_update:
463 symbols = p_update_section_syms;
464 break;
465 default:
466 symbols = p_default_section_syms;
467 break;
468 }
469 return (sym_ntos(symbols, section, (int*) 0));
470 }
471
472 /*
473 * Return a mnemonic for class.
474 */
p_class(int cl)475 const char* p_class(int cl) {
476 int success;
477 const char* result;
478 static char classbuf[20];
479
480 result = sym_ntos(p_class_syms, cl, &success);
481 if (success) return (result);
482 if (cl < 0 || cl > 0xffff) return ("BADCLASS");
483 snprintf(classbuf, sizeof(classbuf), "CLASS%d", cl);
484 return (classbuf);
485 }
486
487 /*
488 * Return a string for the rcode.
489 */
p_rcode(int rcode)490 const char* p_rcode(int rcode) {
491 return (sym_ntos(p_rcode_syms, rcode, (int*) 0));
492 }
493
resolv_set_log_severity(uint32_t logSeverity)494 int resolv_set_log_severity(uint32_t logSeverity) {
495 switch (logSeverity) {
496 case aidl::android::net::IDnsResolver::DNS_RESOLVER_LOG_VERBOSE:
497 logSeverity = android::base::VERBOSE;
498 doh_set_log_level(DOH_LOG_LEVEL_TRACE);
499 // *** enable verbose logging only when DBG is set. It prints sensitive data ***
500 if (RESOLV_ALLOW_VERBOSE_LOGGING == false) {
501 logSeverity = android::base::DEBUG;
502 doh_set_log_level(DOH_LOG_LEVEL_DEBUG);
503 LOG(ERROR) << "Refusing to set VERBOSE logging in non-debuggable build";
504 // TODO: Return EACCES then callers could know if the log
505 // severity is acceptable
506 }
507 break;
508 case aidl::android::net::IDnsResolver::DNS_RESOLVER_LOG_DEBUG:
509 logSeverity = android::base::DEBUG;
510 doh_set_log_level(DOH_LOG_LEVEL_DEBUG);
511 break;
512 case aidl::android::net::IDnsResolver::DNS_RESOLVER_LOG_INFO:
513 logSeverity = android::base::INFO;
514 doh_set_log_level(DOH_LOG_LEVEL_INFO);
515 break;
516 case aidl::android::net::IDnsResolver::DNS_RESOLVER_LOG_WARNING:
517 logSeverity = android::base::WARNING;
518 doh_set_log_level(DOH_LOG_LEVEL_WARN);
519 break;
520 case aidl::android::net::IDnsResolver::DNS_RESOLVER_LOG_ERROR:
521 logSeverity = android::base::ERROR;
522 doh_set_log_level(DOH_LOG_LEVEL_ERROR);
523 break;
524 default:
525 LOG(ERROR) << __func__ << ": invalid log severity: " << logSeverity;
526 return -EINVAL;
527 }
528 android::base::SetMinimumLogSeverity(static_cast<android::base::LogSeverity>(logSeverity));
529 return 0;
530 }
531