Klaus Demo nginx / bb612f1
Merge of r4654, r4672, r4684, r4685, r4692: resolver changes. *) Resolver: fixed format specification. Patch by Yichun Zhang (agentzh). *) Support for IPv6 literals and an optional port in resolver. *) Fixed crash in ngx_resolver_cleanup_tree(). If sending a DNS request fails with an error (e.g., when mistakenly trying to send it to a local IP broadcast), such a request is not deleted if there are clients waiting on it. However, it was still erroneously removed from the queue. Later ngx_resolver_cleanup_tree() attempted to remove it from the queue again that resulted in a NULL pointer dereference. *) When "resolver" is configured with a domain name, only the first resolved address was used. Now all addresses will be used. *) Fixed segfault with poll and resolver used. Poll event method needs ngx_cycle->files to work, and use of ngx_exit_cycle without files set caused null pointer dereference in resolver's cleanup on udp socket close. Maxim Dounin 10 years ago
2 changed file(s) with 25 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
9595 {
9696 ngx_str_t s;
9797 ngx_url_t u;
98 ngx_uint_t i;
98 ngx_uint_t i, j;
9999 ngx_resolver_t *r;
100100 ngx_pool_cleanup_t *cln;
101101 ngx_udp_connection_t *uc;
170170
171171 ngx_memzero(&u, sizeof(ngx_url_t));
172172
173 u.host = names[i];
174 u.port = 53;
175
176 if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
173 u.url = names[i];
174 u.default_port = 53;
175
176 if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
177177 if (u.err) {
178178 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
179179 "%s in resolver \"%V\"",
180 u.err, &u.host);
180 u.err, &u.url);
181181 }
182182
183183 return NULL;
184184 }
185185
186 uc = ngx_array_push(&r->udp_connections);
186 uc = ngx_array_push_n(&r->udp_connections, u.naddrs);
187187 if (uc == NULL) {
188188 return NULL;
189189 }
190190
191 ngx_memzero(uc, sizeof(ngx_udp_connection_t));
192
193 uc->sockaddr = u.addrs->sockaddr;
194 uc->socklen = u.addrs->socklen;
195 uc->server = u.addrs->name;
191 ngx_memzero(uc, u.naddrs * sizeof(ngx_udp_connection_t));
192
193 for (j = 0; j < u.naddrs; j++) {
194 uc[j].sockaddr = u.addrs[j].sockaddr;
195 uc[j].socklen = u.addrs[j].socklen;
196 uc[j].server = u.addrs[j].name;
197 }
196198 }
197199
198200 return r;
976978
977979 if (rn->waiting) {
978980
979 if (ngx_resolver_send_query(r, rn) == NGX_OK) {
980
981 rn->expire = now + r->resend_timeout;
982
983 ngx_queue_insert_head(queue, &rn->queue);
984 }
981 (void) ngx_resolver_send_query(r, rn);
982
983 rn->expire = now + r->resend_timeout;
984
985 ngx_queue_insert_head(queue, q);
985986
986987 continue;
987988 }
10391040 nan = (query->nan_hi << 8) + query->nan_lo;
10401041
10411042 ngx_log_debug6(NGX_LOG_DEBUG_CORE, r->log, 0,
1042 "resolver DNS response %ui fl:%04Xui %ui/%ui/%ui/%ui",
1043 "resolver DNS response %ui fl:%04Xui %ui/%ui/%ud/%ud",
10431044 ident, flags, nqs, nan,
10441045 (query->nns_hi << 8) + query->nns_lo,
10451046 (query->nar_hi << 8) + query->nar_lo);
21882189 ngx_socket_t s;
21892190 ngx_connection_t *c;
21902191
2191 s = ngx_socket(AF_INET, SOCK_DGRAM, 0);
2192 s = ngx_socket(uc->sockaddr->sa_family, SOCK_DGRAM, 0);
21922193
21932194 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, &uc->log, 0, "UDP socket %d", s);
21942195
710710 ngx_exit_log.file = &ngx_exit_log_file;
711711
712712 ngx_exit_cycle.log = &ngx_exit_log;
713 ngx_exit_cycle.files = ngx_cycle->files;
714 ngx_exit_cycle.files_n = ngx_cycle->files_n;
713715 ngx_cycle = &ngx_exit_cycle;
714716
715717 ngx_destroy_pool(cycle->pool);
10531055 ngx_exit_log.file = &ngx_exit_log_file;
10541056
10551057 ngx_exit_cycle.log = &ngx_exit_log;
1058 ngx_exit_cycle.files = ngx_cycle->files;
1059 ngx_exit_cycle.files_n = ngx_cycle->files_n;
10561060 ngx_cycle = &ngx_exit_cycle;
10571061
10581062 ngx_destroy_pool(cycle->pool);