aboutsummaryrefslogtreecommitdiff
path: root/src/core/ngx_resolver.c
Commit message (Collapse)AuthorAge
* Resolver: fixed memory leak for the "ipv4=off" case.Sergey Kandaurov2022-07-14
| | | | | | This change partially reverts 2a77754cd9fe to properly free rn->query. Found by Coverity (CID 1507244).
* The "ipv4=" parameter of the "resolver" directive.Ruslan Ermilov2022-07-12
| | | | | When set to "off", only IPv6 addresses will be resolved, and no A queries are ever sent (ticket #2196).
* Resolver: make TCP write timer event cancelable.Aleksei Bavshin2022-06-01
| | | | | | | | | | | | | | | | | | | Similar to 70e65bf8dfd7, the change is made to ensure that the ability to cancel resolver tasks is fully controlled by the caller. As mentioned in the referenced commit, it is safe to make this timer cancelable because resolve tasks can have their own timeouts that are not cancelable. The scenario where this may become a problem is a periodic background resolve task (not tied to a specific request or a client connection), which receives a response with short TTL, large enough to warrant fallback to a TCP query. With each event loop wakeup, we either have a previously set write timer instance or schedule a new one. The non-cancelable write timer can delay or block graceful shutdown of a worker even if the ngx_resolver_ctx_t->cancelable flag is set by the API user, and there are no other tasks or connections. We use the resolver API in this way to maintain the list of upstream server addresses specified with the 'resolve' parameter, and there could be third-party modules implementing similar logic.
* Core: added the ngx_rbtree_data() macro.Vladimir Homutov2021-06-21
|
* Resolver: explicit check for compression pointers in question.Maxim Dounin2021-05-25
| | | | | | | | | | | | | | | Since nginx always uses exactly one entry in the question section of a DNS query, and never uses compression pointers in this entry, parsing of a DNS response in ngx_resolver_process_response() does not expect compression pointers to appear in the question section of the DNS response. Indeed, compression pointers in the first name of a DNS response hardly make sense, do not seem to be allowed by RFC 1035 (which says "a pointer to a prior occurance of the same name", note "prior"), and were never observed in practice. Added an explicit check to ngx_resolver_process_response()'s parsing of the question section to properly report an error if compression pointers nevertheless appear in the question section.
* Resolver: simplified ngx_resolver_copy().Maxim Dounin2021-05-25
| | | | | | Instead of checking on each label if we need to place a dot or not, now it always adds a dot after a label, and reduces the resulting length afterwards.
* Resolver: reworked ngx_resolver_copy() copy loop.Maxim Dounin2021-05-25
| | | | | | To make the code easier to read, reworked the ngx_resolver_copy() copy loop to match the one used to calculate length. No functional changes.
* Resolver: fixed label types handling in ngx_resolver_copy().Maxim Dounin2021-05-25
| | | | | | | | | | | Previously, anything with any of the two high bits set were interpreted as compression pointers. This is incorrect, as RFC 1035 clearly states that "The 10 and 01 combinations are reserved for future use". Further, the 01 combination is actually allocated for EDNS extended label type (see RFC 2671 and RFC 6891), not really used though. Fix is to reject unrecognized label types rather than misinterpreting them as compression pointers.
* Resolver: fixed off-by-one read in ngx_resolver_copy().Maxim Dounin2021-05-25
| | | | | | It is believed to be harmless, and in the worst case it uses some uninitialized memory as a part of the compression pointer length, eventually leading to the "name is out of DNS response" error.
* Resolver: fixed off-by-one write in ngx_resolver_copy().Maxim Dounin2021-05-25
| | | | Reported by Luis Merino, Markus Vervier, Eric Sesterhenn, X41 D-Sec GmbH.
* Introduced the "keepalive_time" directive.Maxim Dounin2021-04-08
| | | | | | | Similar to lingering_time, it limits total connection lifetime before keepalive is switched off. The default is 1 hour, which is close to the total maximum connection lifetime possible with default keepalive_requests and keepalive_timeout.
* Resolver: added missing event handling after reading.Maxim Dounin2021-03-28
| | | | | | | | | | | If we need to be notified about further events, ngx_handle_read_event() needs to be called after a read event is processed. Without this, an event can be removed from the kernel and won't be reported again, notably when using oneshot event methods, such as eventport on Solaris. While here, error handling is also added, similar to one present in ngx_resolver_tcp_read(). This is not expected to make a difference and mostly added for consistency.
* Resolver: improved error messages (ticket #2024).Maxim Dounin2020-09-28
|
* Resolver: fixed possible use-after-free while resolving PTR.Sergey Kandaurov2019-09-10
| | | | | | | | | | Previously, if a response to the PTR request was cached, and ngx_resolver_dup() failed to allocate memory for the resulting name, then the original node was freed but left in expire_queue. A subsequent address resolving would end up in a use-after-free memory access of the node either in ngx_resolver_expire() or ngx_resolver_process_ptr(), when accessing it through expire_queue. The fix is to leave the resolver node intact.
* Resolver: report SRV resolve failure if all A resolves failed.Roman Arutyunyan2018-12-11
| | | | | | | | | | Previously, if an SRV record was successfully resolved, but all of its A records failed to resolve, NXDOMAIN was returned to the caller, which is considered a successful resolve rather than an error. This could result in losing the result of a previous successful resolve by the caller. Now NXDOMAIN is only returned if at least one A resolve completed with this code. Otherwise the error state of the first A resolve is returned.
* Resolver: retry sending queries on errors (ticket #1511).Maxim Dounin2018-07-05
| | | | | | | | | | Errors when sending UDP datagrams can happen, e.g., when local IP address changes (see fa0e093b64d7), or an unavailable DNS server on the LAN can cause send() to fail with EHOSTDOWN on BSD systems. If this happens during initial query, retry sending immediately, to a different DNS server when possible. If this is not enough, allow normal resend to happen by ignoring the return code of the second ngx_resolver_send_query() call, much like we do in ngx_resolver_resend().
* Resolver: require name servers.Ruslan Ermilov2018-06-13
|
* Resolver: allocate resolver from configuration pool.Ruslan Ermilov2018-06-13
| | | | | | | | Before 4a8c9139e579, ngx_resolver_create() didn't use configuration pool, and allocations were done using malloc(). In 016352c19049, when resolver gained support of several servers, new allocations were done from the pool.
* Added missing space after ngx_close_socket_n.Maxim Dounin2018-06-05
|
* Resolver: close UDP socket on error or incomplete send.Ruslan Ermilov2018-05-23
|
* Resolver: style.Ruslan Ermilov2018-05-23
|
* Resolver: cancelable resend timer event.Ruslan Ermilov2017-07-04
| | | | | | | | | It is safe because re-sending still works during graceful shutdown as long as resolving takes place (and resolve tasks set their own timeouts that are not cancelable). Also, the new ctx->cancelable flag can be set to make resolve task's timeout event cancelable.
* Resolver: factored out setting a timer for resolver timeout.Sergey Kandaurov2017-07-04
| | | | No functional changes.
* Resolver: fixed possible use-after-free while resolving SRV.Roman Arutyunyan2017-07-04
| | | | | | | | | | | | | Resolving an SRV record includes resolving its host names in subrequests. Previously, if memory allocation failed while reporting a subrequest result after receiving a response from a DNS server, the SRV resolve handler was called immediately with the NGX_ERROR state. However, if the SRV record included another copy of the resolved name, it was reported once again. This could trigger the use-after-free memory access after SRV resolve handler freed the resolve context by calling ngx_resolve_name_done(). Now the SRV resolve handler is called only when all its subrequests are completed.
* Resolver: added the "async" flag to resolver context.Roman Arutyunyan2017-06-14
| | | | | The flag indicates that the resolve handler is called asynchronously after the resolve function ngx_resolve_name()/ngx_resolve_addr() exited.
* Resolver: fixed allocation error handling while resolving SRV.Bart Warmerdam2017-06-19
|
* Added missing static specifiers.Eran Kornblau2017-03-02
|
* Win32: fixed some warnings reported by Borland C.Maxim Dounin2016-12-24
| | | | | | | | | Most notably, warning W8012 (comparing signed and unsigned values) reported in multiple places where an unsigned value of small type (e.g., u_short) is promoted to an int and compared to an unsigned value. Warning W8072 (suspicious pointer arithmetic) disabled, it is reported when we increment base pointer in ngx_shm_alloc().
* Resolver: fixed handling of partially resolved SRV.Dmitry Volyntsev2016-12-16
| | | | | | | | | | | | | | | | | | The resolver handles SRV requests in two stages. In the first stage it gets all SRV RRs, and in the second stage it resolves the names from SRV RRs into addresses. Previously, if a response to an SRV request was cached, the queries to resolve names were not limited by a timeout. If a response to any of these queries was not received, the SRV request could never complete. If a response to an SRV request was not cached, and some of the queries to resolve names timed out, NGX_RESOLVE_TIMEDOUT was returned instead of successfully resolved addresses. To fix both issues, resolving of names is now always limited by a timeout.
* Resolver: fixed a race between parallel name and addr resolves.Dmitry Volyntsev2016-12-16
| | | | | Previously, ngx_resolve_name() and ngx_resolve_addr() may have rescheduled the resend timer while it was already in progress.
* Resolver: fixed possible premature stop of the resend timer.Dmitry Volyntsev2016-12-16
| | | | | | Previously, ngx_resolve_name_done() and ngx_resolve_addr_done() may have stopped the resend timer prematurely while srv_resend_queue was not empty.
* Resolver: fixed possible use-after-free in worker on fast shutdown.Ruslan Ermilov2016-12-16
| | | | The fix in a3dc657f4e95 was incomplete.
* Resolver: fixed possible use-after-free in worker on fast shutdown.Ruslan Ermilov2016-12-15
|
* Resolver: introduced state field in ngx_resolver_srv_name_t.Dmitry Volyntsev2016-09-29
| | | | | | It keeps the actual state value of a DNS SRV subrequest and can be used to report a more detailed log for failed SRV records.
* Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.Roman Arutyunyan2016-06-20
|
* Introduced the ngx_sockaddr_t type.Ruslan Ermilov2016-05-23
| | | | It's properly aligned and can hold any supported sockaddr.
* Removed redundant "u" format specifier.Ruslan Ermilov2016-04-08
| | | | It is implied for "x" and "X".
* Fixed logging with variable field width.Sergey Kandaurov2016-03-31
|
* Win32: fixed build after 384154fc634f.Dmitry Volyntsev2016-03-23
|
* Resolver: added support for SRV records.Dmitry Volyntsev2016-03-23
|
* Resolver: do not enable resolve timer if provided timeout is zero.Dmitry Volyntsev2016-03-23
|
* Resolver: introduced valid field in resolver responses.Dmitry Volyntsev2016-03-23
| | | | | It hints the amount of time a response could be considered as valid.
* Resolver: style.Ruslan Ermilov2015-12-17
| | | | | Use the original query name in error and debug messages when processing PTR responses.
* Resolver: improved PTR response processing.Ruslan Ermilov2015-12-17
| | | | | | | | | | | | | | The previous code only parsed the first answer, without checking its type, and required a compressed RR name. The new code checks the RR type, supports responses with multiple answers, and doesn't require the RR name to be compressed. This has a side effect in limited support of CNAME. If a response includes both CNAME and PTR RRs, like when recursion is enabled on the server, PTR RR is handled. Full CNAME support in PTR response is not implemented in this change.
* Resolver: style.Ruslan Ermilov2015-12-17
| | | | Renamed argument in ngx_resolver_process_a() for consistency.
* Resolver: free TCP buffers on resolver cleanup.Roman Arutyunyan2016-02-02
|
* Resolver: fixed possible resource leak introduced in 5a16d40c63de.Ruslan Ermilov2016-02-02
| | | | Found by Coverity (CID 1351175).
* Resolver: TCP support.Roman Arutyunyan2016-01-28
| | | | Resend DNS query over TCP once UDP response came truncated.
* Resolver: per-request DNS server balancer.Roman Arutyunyan2016-01-28
| | | | | | | | | | | Previously, a global server balancer was used to assign the next DNS server to send a query to. That could lead to a non-uniform distribution of servers per request. A request could be assigned to the same dead server several times in a row and wait longer for a valid server or even time out without being processed. Now each query is sent to all servers sequentially in a circle until a response is received or timeout expires. Initial server for each request is still globally balanced.
* Resolver: renamed UDP-specific structures, fields and variables.Roman Arutyunyan2016-01-28
| | | | They will be used for TCP connections as well.