aboutsummaryrefslogtreecommitdiff
path: root/res_query.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Accommodate a change in the type of std::span's sizeRyan Prichard2023-09-211-1/+1
| | | | | | | | | | | The WIP version of std::span in external/libcxx uses a ptrdiff_t size, but the final standardized version of std::span uses size_t instead. Use std::span() constructor calls rather than {}-syntax, which will convert the signed length to unsigned and works with either the old or the new libc++. Test: treehugger Change-Id: I5b5a16d0949e77a74269b9f6cf24382dd69a5973
* Clean up the flag parallel_lookup_releaseMike Yu2023-04-131-2/+2
| | | | | | | | | | The flag has been enabled by default for more than 2 years since aosp/1517564. This change removes not only the flag but also the dead code res_queryN(). Bug: 277699672 Test: atest Change-Id: I3445f9ccdbb9746c0f78ad8b50e3193c6a1868a3
* Fix unused-but-set-variable in res_query.cppKen Chen2022-10-121-7/+1
| | | | | | | | warning: variable 'done' set but not used [-Wunused-but-set-variable] Bug: N/A Test: atest Change-Id: I1e0ce0dea8cedae7520613597d2f48fa77200d1c
* Revet part of aosp/2163902martinwu2022-08-151-0/+1
| | | | | | | | Some "errno = 0" were removed in aosp/2163902, but we are not sure those changes are safe after review. To mitigate the risk, we add those "errno = 0" back. Bug: 242471229 Test: atest pass Change-Id: I02257a3b8bc23c1c2b71942b939b9818617984c9
* Remove accessing errno in setQueryId()martinwu2022-07-231-1/+0
| | | | | | | | Clean up errno in setQueryId() and adjust the error messages/errno. test: atest bug: 238040801 Change-Id: I663b63da6b57d57cbd188826033beb048a3c6ab8
* Enable some DNS logs in userdebug buildKen Chen2022-05-041-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1. Set DNS default logging level to INFO. 2. Adjust logging level on some traces. Output: [Success] resolv : GetAddrInfoHandler::run: {100 983140 100 983140 1021 0} resolv : res_nmkquery: (QUERY, IN, A) resolv : res_nsend: used send_dg 97 terrno: 0 resolv : doQuery: rcode=0, ancount=4 [Cache hit] resolv : GetAddrInfoHandler::run: {100 786532 100 983140 0 0} resolv : res_nmkquery: (QUERY, IN, AAAA) resolv : resolv_cache_lookup: FOUND IN CACHE entry=0xb4000075f51973d0 resolv : doQuery: rcode=0, ancount=1 [Error - NXDOMAIN] resolv : GetAddrInfoHandler::run: {100 786532 100 983140 0 0} resolv : res_nmkquery: (QUERY, IN, AAAA) resolv : res_nsend: used send_dg 104 terrno: 0 resolv : doQuery: rcode=3, ancount=0 [Timeout] resolv : GetAddrInfoHandler::run: {30 983070 30 983070 0 0} resolv : res_nmkquery: (QUERY, IN, A) resolv : res_nsend: used send_dg 0 terrno: 110 resolv : res_nsend: used send_dg 0 terrno: 110 resolv : doQuery: rcode=255, ancount=0 ... Bug: N/A Test: m; adb logcat Change-Id: I2a0ea2b416264d59382ef121d6d7755f8c7ffdf7
* Replace manual buffer handling with std::spanchenbruce2021-08-311-19/+14
| | | | | | Bug: 196298216 Test: cd packages/modules/DnsResolver && atest Change-Id: I8b0b8b0cc0c1185eb9a9e99ed10a2fc109bfa1d7
* Rename ResState::_flags to ResState::flagsBernie Innocenti2021-07-011-2/+2
| | | | Change-Id: I2f6b634f12bba687be7846abba09da75eef1ab72
* Remove the obsolete res_state typedefBernie Innocenti2021-07-011-3/+3
| | | | Change-Id: Ia6b623628e8b2a5799246280198e20c950c30093
* Enable mDNS .local resolutionchenbruce2021-06-251-1/+1
| | | | | | | | | | | | | | This change implements "5.1 One-Shot multicast DNS Queries" in RFC 6762 to send standard DNS queries blindly to 224.0.0.251:5353 or [FF02::FB]:5353. mDNS resolution is transparently supported by calling getaddrinfo() with a hostname ending in "*.local". If the device exists, getaddrinfo() returns the local addresses. Otherwise, the query will timeout and return NODATA. This feature doesn't support reverse-lookups with getnameinfo(). Bug: 140857615 Test: cd packages/modules/DnsResolver && atest Change-Id: Ie65f220de8c6e5c6e21403ec1f717cf6929023a6
* Merge "Replace addrinfo with IPSockAddr to store dns addresses"Mike Yu2019-10-251-1/+1
|\
| * Replace addrinfo with IPSockAddr to store dns addressesMike Yu2019-10-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | The struct addrinfo is designed to store multi-addresses and it might cause memory leaks if improperly used. IPSockAddr is safer and is extensible. It also helps simplify the struct resolv_cache_info, where nameservers and nscount is no longer necessary. Bug: 130686826 Test: atest --include-subdirs packages/modules/DnsResolver Change-Id: I3243f2f79c94ebe3d03503914d25b5863da20c09
* | Unify MAXPACKET and refactor buffer allocation of getaddrinfoLuke Huang2019-10-221-6/+0
|/ | | | | | | | We have many copies of MAXPACKET Use vector instead of old struct Test: atest Change-Id: I406a52855814646814d19dfdc083cd27e1aa6813
* Explicitly allocate ResState on the call stackBernie Innocenti2019-10-171-1/+2
| | | | | | | | | | | | | | | | | | | | | Previously known as __res_state, res_state, res or even statp, the ResState struct holds the context of a query in progress. After a long series of preparatory patches, the thread-local storage nonsense that's been plaguing this fine codebase for decades is finally gone. Sayonara! ResState is now explicitly allocated on the stack at the beginning of each query and passed down as a regular function argument. To keep this patch reviewable, I threw in two compatibility typedefs for the legacy names. We'll get rid of them in a separate mechanical patch. Next steps: - Give ResState a regular constructor and, crucially, a real destructor - Move the definition to ResState.h, like it's a real class - Populate the nameservers immediately on construction - Switch to safe C++ data structures Change-Id: I5c0b85da3ad9a55fa41dca6c87e57fe8f50c6abc
* Resolv: Replace BSD types with regular C99 typeschenbruce2019-09-181-9/+8
| | | | | | | | | Replace BSD types (u_long, u_int, u_char) with regular C99 types Bug: 140910031 Test: built, flashed, booted Test: atest Change-Id: I88829906f8e5be89ef3d5b222ebd4e4091a41b57
* Delete dump_bytes() and its helper functionsMike Yu2019-08-221-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change removes dump_bytes() as well as bprint_* functions which are used for debugging purpose. Instead, use netdutils Slice for hex dump since it's simpler and safer. Log example from res_pquery(): V resolv : ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37806 V resolv : ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 V resolv : ;; QUERY SECTION: V resolv : ;; google.com, type = A, class = IN V resolv : V resolv : ;; ANSWER SECTION: V resolv : ;; google.com. 4m59s IN A X.X.X.X V resolv : V resolv : V resolv : ;; ADDITIONAL SECTION: V resolv : ; EDNS: version: 0, udp=512, flags=8000 V resolv : V resolv : Hex dump: V resolv : 93ae8180000100010000000106676f6f676c6503636f6d0000010001c00c0001 V resolv : 00010000012b0004acd9a06e0000290200000080000000 For debugging, we can use scapy to parse the hex dump: pkt = "93ae8180000100010000000106676f6f676c6503636f6d0000010001c00c000100010000012b0004acd9a06e0000290200000080000000" DNS(pkt.decode("hex")).show2() Bug: 130686826 Bug: 139332724 Test: adb shell service call dnsresolver 10 i32 0 && atest --include-subdirs packages/modules/DnsResolver Test: debugging logs were printed correctly Test: No PII logs are revealed in default log severity Change-Id: Ia298ff3e4ce5c9ff42a1a84cf3e34a7bda818519
* Dead code removal - remove res->optionschenbruce2019-07-241-4/+10
| | | | | | | Bug: 135660701 Test: built, flashed, booted Test: atest Change-Id: Ic604d18e635a9cb373b9e258f4524a20fb1e393f
* Use std::vector to store domains of nameservers and minor changeLuke Huang2019-07-031-7/+4
| | | | | | | | | | | | | | | 1. Drop the old C style used to store domains. Previously, resolv is limited to use 6 search domains with total 255 length. (including zero padding) After this change, the length of each domain could exactly be at most 255. (rfc 1035) Also, invalid or duplicate domains will be dropped. 2. rename resolv_set_nameservers_for_net to resolv_set_nameservers Bug: 135506574 Test: cd system/netd && atest Change-Id: I94129ea521522c817d087332a7b467f616cc4895
* Dead code removal - Remove res_setoptions()chenbruce2019-06-181-20/+9
| | | | | | | | | | - It’s been dead code for a long time, and adds lots of complexity - Keep options used by DoT Bug: 135094436 Test: built, flashed, booted Test: atest Change-Id: Id34c6850f07733219b576d1ee2cf1dd3b7c52fc1
* [Resolver-log]: Some modifications for debug loggingchenbruce2019-04-161-1/+0
| | | | | | | | - Remove stdio.h from all files now that we're no longer using printf() etc - Use std::string to buffer the output and android::base::StringAppendF() to write into it. Test: Test: make; flash; runtests.sh Change-Id: Iea268dbf3e799c04b0812926ca8e381be213c9b4
* Unify log tag of DNS resolverKen Chen2019-04-151-1/+1
| | | | | | | | | Set LOG_TAG to "resolv" on DNS resolver. Then, the log can be filtered by "adb logcat [filterspecs]", such as "adb logcat *:S resolv:*", or 'grep'. Test: resolv_integration_test pass Change-Id: Ic4f97685d487257560ec3dfe62bab0d187bf9d93
* Disable sensitive logsKen Chen2019-03-211-8/+7
| | | | | | | | | | | | | | | | | - PII logs can only appear in VERBOSE level - logSeverityStrToEnum() no more support VERBOSE level input, only accept DEBUG, INFO, WARNING, and ERROR. - developer can set DBG flag from code to have a debug build, the DEBUG level is automatically promote to VERBOSE. - uniform log format to [FILE NAME]: [FUNC NAME]: [MSG] - move from ALOG to LOG on DnsProxyListener - adjust severity for some logs - correct print format on uint8_t type Bug: 128736560 Test: builds, boots Test: atest resolv_integration_test Change-Id: I0ff03824901168165bbe1f5abae9ff3e74db63d6
* resolv: small improvements for debug loggingBernie Innocenti2019-03-081-0/+2
| | | | | | | | | | | | | | | | | | | - use __func__ instead of the hand-written and often incorrect names - fix a few cosmetic issues, such as those ugly ";;" prefixes - add some logging around explore_fqdn and explore_numeric - change the verbosity of a few messages - replace compile-time DBG macro with verbosity checks in DnsProxyListener - delete various unused functions in res_debug - skip slow res_pquery() if log level is less than VERBOSE TODO: convert the remaining ALOGx() lines to LOG(x). Leaving this for a future patch. Test: as follows: adb shell setprop persist.sys.nw_dns_resolver_log DEBUG atest reolv_integration_test Change-Id: I7153f0c75d39d513fa006e0c1e5bf649d47ba154
* [Resolver-log] Replacing unused debuging functions by LOG(x).chenbruce2019-02-271-25/+14
| | | | | | | | | | | | | Removing printf/vlog/syslog/ ...etc debuging functions and using LOG(x). Then we can configure the log verbosity in the resolver with: // Set the minimum severity level for logging, returning the old severity. LogSeverity SetMinimumLogSeverity(LogSeverity new_severity); Bug: 121176138 Test: make; flash; Test: The default severity is WARNING. Reboot device and check that only WARNING/ERROR logs are printed. Change-Id: Ib8de89a4cba96ded186579ccefaf88031066e508
* Fix potential bugs that may cause resolver to retry endlesslyKen Chen2019-01-221-7/+4
| | | | | | | | | | | | | | | | | | [1] If DNS-over-TLS validation success, but server does not respond to DNS-over-TLS query after a while (the server can still respond to DNS-over-UDP). Then, query a non-exist domain. [2] If DNS-over-TLS validation success, but server does not respond to DNS-over-TLS query after a while. Also, the server always responds RCODE=RES_F_EDNS0ERR on DNS-over-UDP. These strange network behaviors should not happen. However, once they happen (maybe by bogus servers), the resolver should be able to handle it gracefully. Bug: 120910570 Test: runtests.sh pass Change-Id: I7e3044e012303a7991b04e7d38e55340e2a5db1a
* Implementation of control flags in asynchronous DNS query APILuke Huang2019-01-161-1/+1
| | | | | | | | | Flags definitions are in multinetwork.h Test: built, flashed, booted system/netd/tests/runtests.sh passes Change-Id: Iab1983b783d1470bc1cf23489abbef7a2d88e860
* Expose DNS response code to netdHungming Chen2019-01-151-13/+31
| | | | | | | | | | | | | | | | | | | | | | Currently, DNS query returns error code which may consider rcode only. That may not respond corresponding error what we need. For example, rcode NOERROR doesn't really mean no error for the whole DNS query progress. DNS server may respond a DNS packet without any answer for queried address. In this case, return error code from h_errno NO_DATA rather than rcode NOERROR. Changes: 1. Expose timeout error to netd. 2. Not only consider rcode for returning DNS query error code. 3. Enable the following test cases. - ResolverTest.GetHostByName2_Dns64Synthesize - ResolverTest.GetAddrInfo_Dns64QuerySpecified - GetAddrInfoForNetContextTest.AlphabeticalHostname_NoData Test: built, flashed, booted system/netd/tests/runtests.sh pass manual test with unmerged commit aosp/861310 Change-Id: I6723d133afbe56728ecaf35245d1037efc8d6da6
* Remove thread-local variable h_errno in gethostby{name, addr} related APIsHungming Chen2019-01-141-24/+28
| | | | | | | | | | Using a thread-local variable to return an int to the caller is a hack and adds a lot of complexity. Return error code with an int pointer instead. Test: built, flashed, booted system/netd/tests/runtests.sh pass Change-Id: Ie9da1a6b18525967f0e8fe3d54b0df18e37d2b0e
* Expose DNS timeout error to netdMike Yu2018-11-141-14/+19
| | | | | | | | | | | | | | | | | | | | For resolver stats, RCODE_TIMEOUT has been used for catching DNS timeout error. This change adds the Support for reporting NETD_RESOLV_TIMEOUT to frameworks. Also clean up res_data.cpp as these functions are not used. - res_init - res_mkquery - res_query - res_send - res_search Bug: 113916551 Test: as follows - built and flash netd - system/netd/tests/runtests.sh passed - silently drop packets by iptables, the return error is correct Change-Id: I62ba6759b519d42aef62ae5b756a3c1ae3cb00d8
* Move resolver public headers to separate include pathBernie Innocenti2018-10-181-2/+3
| | | | | | | | | | Additionally rename functions and structs to eliminate those ugly underscores from the public API (with the notable exception of __res_params, which will come in its own separate change to keep this one from growing too large). Test: build, flash, then 'atest netd_integration_test' Change-Id: I7e9b0ee6cdbec889e9c35b5a17b5daa65533686e
* Move a few internal constants out of resolv_params.hBernie Innocenti2018-10-171-4/+0
| | | | | | | | | | | | | | | | | This is a preliminary step to cleanly separate the public headers from the internal ones. No funtionality changes. In the process, I also un-ifdefd RES_USE_EDNS0 and EDNS0_PADDING, since they were always defined. For now I'm leaving alone these #ifdefs, which need some more thought: - HAVE_SIN6_SCOPE_ID: currently disabled, but <linux/in6.h> has it - HAS_INET6_STRUCTS: currently disabled, will need test coverage? - CANNOT_CONNECT_DGRAM: currently disabled Test: build, flash, then 'atest netd_integration_test' Change-Id: I4cee37d484a5183a2db082d502b2badcaa83e7e4
* Turn implicit fallthrow warnings into errorsBernie Innocenti2018-10-121-1/+1
| | | | | Test: m netd ndc bpfloader libnetd_client netd_integration_test netd_unit_test netd_benchmark Change-Id: Ie607ab784fd6470d7dc7654b07f33f7f5b943118
* Fix -Wimplicit-fallthrough warnings in netdBernie Innocenti2018-10-121-2/+2
| | | | | Test: atest netd_integration_test Change-Id: Ib5ab9661fb429fdccd6a4c4b5893831ff5fe104e
* resolv: dead code removalBernie Innocenti2018-10-031-10/+0
| | | | | | | | | | | | | | | | - hostalias() and res_hostalias(): these were no-ops - res_opt(), res_querydomain(), p_option(), p_query(), res_isourserver(), res_nisourserver(): had no callers - res_ourserver_p(): made local to res_data.cpp - res_send_setqhook(): unused, DnsProxyListener sets the qhook directly in android_net_context, which is then copied to res_state by res_setnetcontext(). We can further simplify it later on. Test: atest netd_integration_test Change-Id: I70f72202e5b940986cac67dc99ab9461af882187
* Minimal changes to bring the resolver into the C++ eraBernie Innocenti2018-09-111-0/+379
It took surprisingly few changes, considering the leap from C with some K&R constructs to C++17; most of the diffs are adding explicit pointer casts and renaming variables called 'class' or 'try'. As a result of building as C++, some of the names are now mangled, making clashes with bionic harder. However, some names remain C due to the __BEGIN_DECLS / __END_DECLS macros, scheduled to be removed in a later cleanup pass. Test: atest netd_integration_test Change-Id: I3aefb9078421ec42f98f97d917785b365545feba