aboutsummaryrefslogtreecommitdiff
path: root/sethostent.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Merge tag 'android-14.0.0_r50' of ↵HEADu14.0George Zacharia2024-07-041-1/+6
|\ | | | | | | | | | | https://android.googlesource.com/platform/packages/modules/DnsResolver into u14.0 Android 14.0.0 Release 50 (AP2A.240605.024)
| * [Code Health] Delete spurious codeKen Chen2024-01-121-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | "num >= MAXADDRS" can never happen in the for-loop. Test: 1. Modify system/etc/hosts to have over than MAXADDRS records, like 10.0.0.1 www.test.com 10.0.0.2 www.test.com ... 10.0.0.36 www.test.com 2. Trigger gethostbyname by "adb shell ping www.test.com" 3. Observe the result and there is no failure Change-Id: I4347307be9479214c48492aee180d46e1b97d3f4
| * Closing the stream when the function returnsKen Chen2023-12-071-0/+6
| | | | | | | | | | | | | | Porting aosp/2856549 from bionic to DNS resolver. Change-Id: I76999cbc352094055807aa7ded03b0363912c980 Test: presubmit
* | DnsResolver: Sort and cache hosts file data for fast lookupTom Marshall2024-06-011-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The hosts file is normally searched linearly. This is very slow when the file is large. To mitigate this, read the hosts file and sort the entries in an in-memory cache. When an address is requested via gethostbyname or getaddrinfo, binary search the cache. In case where the cache is not available, return a suitable error code and fall back to the existing lookup code. This has been written to behave as much like the existing lookup code as possible. But note bionic and glibc differ in behavior for some corner cases. Choose the most standard compliant behavior for these where possible. Otherwise choose the behavior that seems most reasonable. Note: this change is the analogue of the bionic change of the same name. Both should be kept in sync. u14.0: Replace usage of MIN with std::min Change-Id: I5926493864d4b1291ae83f8b601bf5dcc54085cd
* | Toggle-able adblock hosts file [1/3]SpiritCroc2024-05-081-1/+3
|/ | | | Change-Id: I0f5ab2ec4a6f1855abd65f371a8960087db49994
* Fix -Wnullable-to-nonnull-conversion errorsKen Chen2023-05-091-6/+6
| | | | | | | | | | | | | | Aosp/2566619 added Nonnull annotations in strcasecmp, which causes build break in DNS resolver module and tests. This commit: 1. Checks if a nullable variable is null before passing it to the strcasecmp. 2. Adds a hacky way to avoid -Wnullable-to-nonnull-conversion errors. Bug: 278513807 Test: presubmit Change-Id: I146f5b91114dd7c934c9e3fb12477e4563005c5f
* Fix -Wnullable-to-nonnull-conversion errorsKen Chen2023-04-271-7/+30
| | | | | | | | | | | | | | | | | | Aosp/2522835 adds _Nullable/_Nonnull annotations which causes build break in DNS resolver module and tests. This commit tries to: 1. Check if a nullable variable is non-null before passing it to a function with a non-null parameter annotation. This is necessary because passing null pointers to memcpy(), strlen(), strdup(), etc is undefined behavior. 2. Add a hacky way to avoid -Wnullable-to-nonnull-conversion errors. Compiler is not smart enough to know if a variable is guaranteed non-null from context. Bug: 278513807 Test: presubmit Change-Id: I2bcf887e31a2d9716c1da75431280ec29d4e5c34
* Sanitize buffer alignment macrosBernie Innocenti2021-06-231-4/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | The ancient ALIGN() macros caused clang-tidy to complain: packages/modules/DnsResolver/gethnamaddr.cpp:367:10: error: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr,-warnings-as-errors] bp = (char*) ALIGN(bp); The new inline template align_ptr() sidesteps this issue as recommended by the clang-tidy documentation: https://clang.llvm.org/extra/clang-tidy/checks/performance-no-int-to-ptr.html Furthermore, align_ptr() is used to replace this... surprising piece of code: bp += sizeof(align) - (size_t)((uintptr_t)bp % sizeof(align)); See the bug there? When bp is already aligned to a multiple of sizeof(align), it will overalign! Also, 'align' was a union of a uint32_t and a char, which is obviously the same alignment of a plain uint32_t on any architecture ever created! Bug: 182416023 Change-Id: Id39c3030025e4510feeb55723760a2950067cece
* Cull res_staticBernie Innocenti2019-10-111-1/+3
| | | | | | | | res_static was used by the non-reentrant legacy resolver calls to hold a per-thread buffer for the hostent struct and its associated 8KB buffer, which is now stack allocated by the caller. Change-Id: I01a2ea4c2e290d8e4f19fc3be3ebf827c8200b0e
* Delete unused variable res_state.rstaticBernie Innocenti2019-10-101-0/+1
| | | | | | | | Also stop including resolv_static.h from resolv_private.h, and other minor fixes. Test: m, flash, atest Change-Id: I2ba6fdf10900ddbd5afed1cec14a91bfad862d43
* [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
* Remap existing EAI_SYSTEM to avoid relying on global errno variableHungming Chen2019-04-031-11/+19
| | | | | | | | | | In order to not rely on errno, remap the existing error code pair of EAI_SYSTEM and errno to other EAI_* error codes. Unused errno is removed as well. Test: built, flashed, booted system/netd/tests/runtests.sh pass Change-Id: I8a4450df3c27a12db790756ba545787bd0570402
* Remove h_errno container from struct getnamaddrHungming Chen2019-01-151-11/+11
| | | | | | | Test: built, flashed, booted system/netd/tests/runtests.sh pass Change-Id: I9fd8735b2ea7565342b899715afef13b1c0692f6
* Expose DNS response code to netdHungming Chen2019-01-151-0/+2
| | | | | | | | | | | | | | | | | | | | | | 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-11/+13
| | | | | | | | | | 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
* gethtbyname: Reserve space for mapping IPv4 address to IPv6 addressnuccachen2018-10-241-1/+8
| | | | | | | | | | | | | | | | Currently function return address space size is reserved by the address family. When Netd does IPv6 prefix synthesis on an IPv4 resource record, hostent structure has no enough address space for synthesized IPv6 address. Reserving enough address space for either IPv4 or IPv6 avoids buffer overflow while doing address family remapping in Netd. Be aware of that we don't reserve address space for family remapping in numeric hostname query which returns a fake address from numeric hostname. The reason is this case doesn't trigger DNS64 synthesis in Netd. Bug: 78545619 Test: netd_{unit,integration}_test pass Change-Id: I506026cfa38c107e06440806a3080dd8d52a3bf2
* nsdispatch removal from gethostbyaddr()Bernie Innocenti2018-09-251-34/+22
| | | | | Test: atest netd_integration_test Change-Id: I41d1de68296e6201e6b0f20d390eaf1d12aa49f9
* nsdispatch removal from gethostbyname()Bernie Innocenti2018-09-121-40/+5
| | | | | | | | | | | | | | This gets rid of several layers of obfuscation in between nsdispatch() and the functions which actually lookup for a hostname in the hosts file and dns. This opens the way for even more cleanups, which I will leave for another day; let's first rip off nsdispatch() from everywhere, which lets us kill another dependency on an internal bionic header. Test: atest netd_integration_test Change-Id: I911fb254939ecc9661695d0ca5474c3caeb4c1d9
* Minimal changes to bring the resolver into the C++ eraBernie Innocenti2018-09-111-0/+232
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