160 Commits

Author SHA1 Message Date
Azat Khuzhin
213a822aa7 test: increase timeout significantly in dns/getaddrinfo_cancel_stress (for TSan)
Fixes: #1304
2022-07-11 22:53:57 +03:00
Azat Khuzhin
5ff98dc1f3 evdns: accept domains up to 254 long (previosly only 63 long was accepted)
Previously evdns was using HOST_NAME_MAX, and define it to 255 *only* if
it not set, however it does set on linux:

    $ egrep -r define.*HOST_NAME_MAX /usr/include/bits
    /usr/include/bits/local_lim.h:#define HOST_NAME_MAX             64
    /usr/include/bits/posix1_lim.h:#define _POSIX_HOST_NAME_MAX     255
    /usr/include/bits/confname.h:#define _SC_HOST_NAME_MAX          _SC_HOST_NAME_MAX

But 64 should be the limit of the host component, not for the whole
hostname, as also noted by @ploxiln

So use our own EVDNS_NAME_MAX const, which is set to 255.

Fixes: #1280
2022-07-10 18:10:35 +03:00
Azat Khuzhin
1933f6aadd test: make dns/getaddrinfo_cancel_stress more deterministic
Fixes: #1271
Follow-up for: 90bcf2d660b9b43cb8e747421d4938f08f935bd7
2022-07-10 16:32:36 +03:00
Yongsheng Xu
cd6a41ecdd feat: add evdns_base_get_nameserver_fd method
To get underlying udp socket fd.
2021-12-10 11:05:13 +08:00
Azat Khuzhin
7855900c01 test/dns: mark TCP tests as retriable
CI: https://github.com/azat/libevent/runs/3643912296 # tcp_resolve_many_clients
CI: https://github.com/azat/libevent/runs/3643912192 # tcp_timeout
CI: https://github.com/azat/libevent/runs/3643912336 # tcp_resolve
CI: https://github.com/azat/libevent/runs/3643912174 # tcp_resolve_pipeline
2021-09-19 12:29:02 +03:00
Pierce Lopez
fabbf3b310 test: skip dns_initialize_nameservers if missing /etc/resolv.conf
some build systems run tests in minimal containers with no resolv.conf,
and the primary thing this test does is load the default /etc/resolv.conf
2021-09-14 01:19:36 -04:00
Alex Budovski
8f74b30c40 Replace gettimeofday with the portable wrapper
Otherwise the Win32 build fails.
2021-05-30 13:35:41 -05:00
Sergey Matveychuk
19b3fd0bf0 evdns: add ability to get CNAME
Add new flag (DNS_CNAME_CALLBACK) for
evdns_base_resolve_ipv4()/evdns_base_resolve_ipv6().

If set, you will get one more callback with type == DNS_CNAME and CNAME
in addrs argument.
2021-05-24 21:03:45 +03:00
chux0519
617ba83874 evdns: add max-probe-timeout/probe-backoff-factor settings
I recently found that when the network status changed when calling
bufferevent_socket_connect_hostname (e.g. switching between several
WIFIs), all DNS servers would fail, and the timeout of probe would be
very long if there were many DNS requests. I want libevent to support
manual setting of MAX_PROBE_TIMEOUT and TIMEOUT_BACKOFF_FACTOR

So move hardcoded MAX_PROBE_TIMEOUT and TIMEOUT_BACKOFF_FACTOR into
struct, and allow changing them.
2021-01-12 10:56:13 +03:00
Azat Khuzhin
2338f27e69 test/regress_dns: fix -Wmaybe-uninitialized
Was not noticed since it is reported only with optimization enabled, as
stated in gcc(1):

   The effectiveness of some warnings depends on optimizations also
   being enabled. For example -Wsuggest-final-types is more effective with
   link-time optimization and -Wmaybe-uninitialized does not warn at all
   unless optimization is enabled.

And interesting thing is that it is reported only for -O2, not for -O3,
that's why I did not catched it in both cmake env that I had:
- debug (it has -O0)
- release (it has -O3)

While autoconf has -O2.
2020-08-29 01:15:20 +03:00
Azat Khuzhin
eeeed1e1bb test/dns: fix initialize_nameservers when there is ipv6 in /etc/resolv.conf
Fixes: #1060
2020-07-28 01:19:55 +03:00
Azat Khuzhin
90bcf2d660 test: fix leak in dns/getaddrinfo_cancel_stress
Some requests may get response (evutil_addrinfo) from gaic_server_cb,
in case of cancel_event (10000ms) will not be fast enough.
2020-07-05 12:16:52 +03:00
Azat Khuzhin
271c5aaa81 test/regress_dns: use tt_int_op() over tt_assert() in assert_request_results() 2020-06-02 10:00:38 +03:00
seleznevae
83c58d4985 evdns: Add support for setting maximum UDP DNS message size.
Added new option `edns-udp-size` for evdns_base which allows
to control maximum allowed size of UDP DNS messages. This
maximum size is passed to the DNS server via edns mechanism.
2020-05-31 19:59:49 +03:00
ayuseleznev
0f6ee89a39 evdns: Implement dns requests via tcp 2020-05-21 12:46:20 +03:00
ayuseleznev
8fe35c7614 evdns: Add additional validation for values of dns options 2020-05-18 14:31:49 +03:00
ayuseleznev
4da9f87ccb evdns: fix a crash when evdns_base with waiting requests is freed
Fix undefined behaviour and application crash that might take
place in some rare cases after calling evdns_base_free when
there are requests in the waiting queue.

Current cleanup procedure in evdns_base_free_and_unlock
function includes 2 steps:
1. Finish all inflight requests.
2. Finish all waiting requests.
During the first step we iterate over each list in req_heads
structure and finish all requests in these lists. With current
logic finishing an inflight request (function request_finished)
removes it from the inflight requests container and forces
a wating connection to be sent (by calling
evdns_requests_pump_waiting_queue). When these new requests are
sent it is possible that they will be inserted to the list in
req_heads that we've already cleaned.
So in some cases container of the inflight requests is not empty
after this procedure and some requests are not finished and
deleted. When timeouts for these requests expire
evdns_request_timeout_callback is called but corresponding
evdns_base has been already deleted which causes undefined
behaviour and possible applicaton crash.

It is interesting to note that in old versions of libevent such
situation was not possible. This bug was introduced by the commit
14f84bbdc77d90b1d936076661443cdbf516c593. Before this commit
nameservers were deleted before finishing the requests. Therefore
it was not possible that requests from the waiting queue be sent
while we finish the inflight requests.
2020-02-28 15:06:24 +03:00
Azat Khuzhin
4436287d12 Relax bufferevent_connect_hostname_emfile
Do not do any assumptions on the error for the EMFILE from
getaddrinfo(), expect just any error.

Fixes: #924
2019-10-31 09:20:49 +03:00
Azat Khuzhin
538141eb7e
evdns: add new options -- so-rcvbuf/so-sndbuf
This will allow to customize SO_RCVBUF/SO_SNDBUF for nameservers in this
evdns_base, you may want to adjust them if the kernel starts dropping
udp packages.
2019-06-15 23:32:39 +03:00
Azat Khuzhin
51ac04ac62
test: mark bev_connect_hostname() as static (to avoid prototype requirement) 2019-05-25 17:29:55 +03:00
Joseph Spadavecchia
5e137f3776
Implement bufferevent_socket_connect_hostname_hints()
So that ai_flags (such as AI_ADDRCONFIG) can be specified.

Closes: #193 (cherry-picked with conflicts resolved)
2019-05-13 11:13:04 +03:00
Azat Khuzhin
47d348a631
Disable logging for tests that assume printing warnings
To avoid possible confusion

But there is still one test that has some messages on windows:
  main/methods

Because this test needs >1 of avaiable methods, otherwise it will warn.
2019-04-03 08:00:12 +03:00
Azat Khuzhin
e5b8f4c192
evdns: add DNS_OPTION_NAMESERVERS_NO_DEFAULT/EVDNS_BASE_NAMESERVERS_NO_DEFAULT
- DNS_OPTION_NAMESERVERS_NO_DEFAULT
  Do not "default" nameserver (i.e. "127.0.0.1:53") if there is no nameservers
  in resolv.conf, (iff DNS_OPTION_NAMESERVERS is set)

- EVDNS_BASE_NAMESERVERS_NO_DEFAULT
  If EVDNS_BASE_INITIALIZE_NAMESERVERS isset, do not add default
  nameserver if there are no nameservers in resolv.conf (just set
  DNS_OPTION_NAMESERVERS_NO_DEFAULT internally)

Fixes: #569
2019-04-01 02:18:59 +03:00
Azat Khuzhin
6dbad0f671
test/dns: in solaris under EMFILE devpoll does not dispatch (due DP_POLL failure) 2019-02-04 22:43:47 +03:00
Azat Khuzhin
d234902da7
test/dns: in solaris under EMFILE the error is EAI_FAIL 2019-02-03 18:56:01 +03:00
Azat Khuzhin
4ffc711617
test: adjust expecting error for getaddrinfo() under EMFILE
When getaddrinfo() cannot allocate file descriptor glibc/musl-libc on
linux report EAI_SYSTEM error. But this is not true for freebsd libc [1]
(and hence apple libc [2]), they report EAI_NONAME error instead, so
adjust expectation.

  [1]: https://github.com/freebsd/freebsd/blob/master/lib/libc/net/getaddrinfo.c
  [2]: https://opensource.apple.com/source/Libc/

Refs: #749
Refs: https://github.com/libevent/libevent/issues/749#issuecomment-457838159
2019-01-26 19:57:37 +03:00
Azat Khuzhin
2cb8eae795
Do not rely on getservbyname() for most of the dns regression tests
There is only one test that uses service name getaddrinfo_async, which
manually check whether it works or not, other should not assume that it
is available and works.

There was already an attempt to overcome some possible limitations, like
lack of "http" in /etc/services in
d6bafbbeb27ff3943d6f3b6783bcded76384c31e ("test/dns: replace servname
since solaris does not have "http"")
2018-10-21 03:12:24 +03:00
Azat Khuzhin
7198bbb8f1
Turn off dns/getaddrinfo_race_gotresolve by default
It is:
- pretty internal regression
- CPU bound
- right now failed on travis-ci machines
2018-10-21 03:11:00 +03:00
Azat Khuzhin
09c74f7121
Fix an error for debug locking in dns/getaddrinfo_race_gotresolve
When there is no /etc/services file evdns_getaddrinfo() will fail (with
service="ssh") and hence it will go to then "end" label with locked
rp.lock which in case of debug locking checks will bail with:
  [err] ../evthread.c:220: Assertion lock->count == 0 failed in debug_lock_free

So add rp.locked flag, and unlock the lock before freeing it if it is in
locked state.

And here is how you can reproduce the issue:
  $ docker run -e LD_LIBRARY_PATH=$PWD/lib -e PATH=/usr/bin:/bin:$PWD/bin -v $PWD:$PWD --rm -it debian:testing regress dns/getaddrinfo_race_gotresolve
(since debian:testing does not have /etc/services)
2018-10-21 03:10:12 +03:00
Philip Prindeville
be37116302
Eliminate compiler warnings (at least for gcc/linux)
Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
Closes: #646 # cherry-picked from the PR
2018-08-17 03:21:49 +03:00
Sergey Fionov
4802c132a2
evdns: add regress test for getaddrinfo race 2018-08-02 09:26:51 +03:00
Leo Zhang
d9ffd22137
test: make regress_dns C89 compatible
Closes: #635 (cherry-picked)
2018-06-21 03:07:55 +03:00
Azat Khuzhin
d1c8993c3c test/dns: install correct RLIMIT_NOFILE in bufferevent_connect_hostname_emfile
Otherwise poll() will fail with EINVAL:
       EINVAL The nfds value exceeds the RLIMIT_NOFILE value.

P.S. and cleanup this test a little, with early-return.

CI: https://travis-ci.org/libevent/libevent/jobs/370350426
2018-04-24 14:47:58 +03:00
Azat Khuzhin
a3d8f2e093 test/dns: verify bufferevent_socket_connect() errorcb invoking if socket() fails
Refs: #600
2018-04-24 02:05:30 +03:00
Azat Khuzhin
623ef3ccdc test/dns: cleanup test_bufferevent_connect_hostname() 2018-04-24 02:05:30 +03:00
Azat Khuzhin
8acfb0cd21 test: do not return void 2017-03-14 13:21:16 +03:00
Azat Khuzhin
d6bafbbeb2 test/dns: replace servname since solaris does not have "http"
Yes, by default solaris (solaris10.dev 5.10 Generic_147148-26 i86pc i386 i86pc)
does not have "http" in /etc/services
2017-01-20 02:16:50 +03:00
Azat Khuzhin
0786253115 test/dns: run async resolving after sync one (to avoid timeouts)
If system resolver (sync one) will respond too slow, then we can fail async
request and evdns will retransmit tham again, but evdns server will accept that
failed requets, so we will have not 2 requests but 4.

Reproduced on centos box sometimes.
2017-01-19 20:50:22 +03:00
Azat Khuzhin
d7348bab60 test/dns: regression for empty hostname
Refs: #332
2016-03-25 00:33:43 +03:00
Azat Khuzhin
0b9d43249b test/dns: check exit code of evdns_getaddrinfo()
By some reason all autotools builds failed:
CI: https://travis-ci.org/libevent/libevent/builds/93125954
2015-11-25 17:30:31 +03:00
Azat Khuzhin
4ad348310c test/dns: cover evdns_getaddrinfo() and evdns_base_free() with @fail_requests 2015-11-25 13:09:02 +03:00
Azat Khuzhin
d6c6fb4200 test/dns: cover @fail_requests for evdns_base_free() 2015-11-25 13:09:02 +03:00
Azat Khuzhin
123d372864 test/dns: more graceful coverage of @fail_requests
In case when evdns_base_free() called with @fail_requests, we can potentially
have leaks, but we can avoid them if we will run event loop once again to
trigger defer cbs, so let's do this, instead of magical decrements (and also
this will give an example how to avoid leaks for evdns).
2015-11-25 13:09:01 +03:00
Azat Khuzhin
f55db9856e test/regress_dns: fix compilation warnings (-Wmissing-field-initializers/for)
I don't have an error for loop because gcc5 have --std=gnu11 by default.
We need some options-consistency for all versions/compilers and build systems
to avoid such patches.

Fixes: https://travis-ci.org/libevent/libevent/jobs/84403473
Fixes: https://travis-ci.org/libevent/libevent/builds/84403463
2015-10-09 01:47:44 +03:00
Azat Khuzhin
1e8bfbc6bc tests/regress_dns: cover that randomize-case works case-insensitive
Regression-for: #288
2015-10-09 01:12:12 +03:00
Nick Mathewson
51821e20b2 Merge pull request #207 from azat/avoid-leaking-of-event_debug_map_HT_GROW
Avoid leaking of event_debug_map_HT_GROW
2015-02-04 08:33:42 -05:00
Nick Mathewson
537177d315 New function to get address for nameserver. 2015-02-02 13:57:22 -05:00
Azat Khuzhin
3540a193b5 regress_dns: drop hack for event_debug_map_HT_GROW in leak tests 2015-01-08 04:51:27 +03:00
Azat Khuzhin
3ca9d43d32 evdns: add retry/reissue tests for EVDNS_BASE_DISABLE_WHEN_INACTIVE 2014-09-30 01:39:51 +04:00
Nick Mathewson
89c1a3b7fe Fix several memory leaks in the unit tests.
Also add a comment to buffer.c about why we call
evbuffer_file_segment_free on failure to add the segment.
2014-09-18 12:40:38 -04:00