Lines Matching refs:base
160 struct evdns_base *base; member
195 struct evdns_base *base; member
235 struct evdns_base *base; member
302 struct evdns_server_request base; member
392 (((char*)(base_ptr) - evutil_offsetof(struct server_request, base))))
394 #define REQ_HEAD(base, id) ((base)->req_heads[id % (base)->n_req_heads]) argument
396 static struct nameserver *nameserver_pick(struct evdns_base *base);
400 static int evdns_transmit(struct evdns_base *base);
405 static struct request *search_request_new(struct evdns_base *base, struct evdns_request *handle, in…
406 static void evdns_requests_pump_waiting_queue(struct evdns_base *base);
407 static u16 transaction_id_pick(struct evdns_base *base);
408 static struct request *request_new(struct evdns_base *base, struct evdns_request *handle, int type,…
415 static int evdns_base_resolv_conf_parse_impl(struct evdns_base *base, int flags, const char *const …
416 static int evdns_base_set_option_impl(struct evdns_base *base,
418 static void evdns_base_free_and_unlock(struct evdns_base *base, int fail_requests);
424 #define EVDNS_LOCK(base) EVUTIL_NIL_STMT_ argument
425 #define EVDNS_UNLOCK(base) EVUTIL_NIL_STMT_ argument
426 #define ASSERT_LOCKED(base) EVUTIL_NIL_STMT_ argument
428 #define EVDNS_LOCK(base) \ argument
429 EVLOCK_LOCK((base)->lock, 0)
430 #define EVDNS_UNLOCK(base) \ argument
431 EVLOCK_UNLOCK((base)->lock, 0)
432 #define ASSERT_LOCKED(base) \ argument
433 EVLOCK_ASSERT_LOCKED((base)->lock)
473 request_find_from_trans_id(struct evdns_base *base, u16 trans_id) { in request_find_from_trans_id() argument
474 struct request *req = REQ_HEAD(base, trans_id); in request_find_from_trans_id()
477 ASSERT_LOCKED(base); in request_find_from_trans_id()
497 EVDNS_LOCK(ns->base); in nameserver_prod_callback()
499 EVDNS_UNLOCK(ns->base); in nameserver_prod_callback()
510 ASSERT_LOCKED(ns->base); in nameserver_probe_failed()
521 memcpy(&timeout, &ns->base->global_nameserver_probe_initial_timeout, in nameserver_probe_failed()
564 struct evdns_base *base = ns->base; in nameserver_failed() local
568 ASSERT_LOCKED(base); in nameserver_failed()
579 base->global_good_nameservers--; in nameserver_failed()
580 EVUTIL_ASSERT(base->global_good_nameservers >= 0); in nameserver_failed()
581 if (base->global_good_nameservers == 0) { in nameserver_failed()
589 &base->global_nameserver_probe_initial_timeout) < 0) { in nameserver_failed()
604 if (!base->global_good_nameservers) return; in nameserver_failed()
606 for (i = 0; i < base->n_req_heads; ++i) { in nameserver_failed()
607 req = started_at = base->req_heads[i]; in nameserver_failed()
613 request_swap_ns(req, nameserver_pick(base)); in nameserver_failed()
625 ASSERT_LOCKED(ns->base); in nameserver_up()
633 evdns_cancel_request(ns->base, ns->probe_request); in nameserver_up()
639 ns->base->global_good_nameservers++; in nameserver_up()
654 struct evdns_base *base = req->base; in request_finished() local
655 int was_inflight = (head != &base->req_waiting_head); in request_finished()
656 EVDNS_LOCK(base); in request_finished()
665 base->global_requests_inflight--; in request_finished()
668 base->global_requests_waiting--; in request_finished()
675 req->base->disable_when_inactive) { in request_finished()
708 evdns_requests_pump_waiting_queue(base); in request_finished()
709 EVDNS_UNLOCK(base); in request_finished()
721 ASSERT_LOCKED(req->base); in request_reissue()
726 request_swap_ns(req, nameserver_pick(req->base)); in request_reissue()
747 evdns_requests_pump_waiting_queue(struct evdns_base *base) { in evdns_requests_pump_waiting_queue() argument
748 ASSERT_LOCKED(base); in evdns_requests_pump_waiting_queue()
749 while (base->global_requests_inflight < base->global_max_requests_inflight && in evdns_requests_pump_waiting_queue()
750 base->global_requests_waiting) { in evdns_requests_pump_waiting_queue()
753 EVUTIL_ASSERT(base->req_waiting_head); in evdns_requests_pump_waiting_queue()
754 req = base->req_waiting_head; in evdns_requests_pump_waiting_queue()
756 req->ns = nameserver_pick(base); in evdns_requests_pump_waiting_queue()
763 evdns_request_remove(req, &base->req_waiting_head); in evdns_requests_pump_waiting_queue()
765 base->global_requests_waiting--; in evdns_requests_pump_waiting_queue()
766 base->global_requests_inflight++; in evdns_requests_pump_waiting_queue()
768 request_trans_id_set(req, transaction_id_pick(base)); in evdns_requests_pump_waiting_queue()
770 evdns_request_insert(req, &REQ_HEAD(base, req->trans_id)); in evdns_requests_pump_waiting_queue()
772 evdns_transmit(base); in evdns_requests_pump_waiting_queue()
844 ASSERT_LOCKED(req->base); in reply_schedule_callback()
866 req->base->event_base, in reply_schedule_callback()
893 ASSERT_LOCKED(req->base); in reply_handle()
917 if (req->reissue_count < req->base->global_max_reissues) { in reply_handle()
965 request_finished(req, &REQ_HEAD(req->base, req->trans_id), 1); in reply_handle()
972 request_finished(req, &REQ_HEAD(req->base, req->trans_id), 1); in reply_handle()
1034 reply_parse(struct evdns_base *base, u8 *packet, int length) { in reply_parse() argument
1048 ASSERT_LOCKED(base); in reply_parse()
1059 req = request_find_from_trans_id(base, trans_id); in reply_parse()
1061 EVUTIL_ASSERT(req->base == base); in reply_parse()
1096 if (!base->global_randomize_case) { in reply_parse()
1267 server_req->base.flags = flags; in request_parse()
1268 server_req->base.nquestions = 0; in request_parse()
1269 server_req->base.questions = mm_calloc(sizeof(struct evdns_server_question *), questions); in request_parse()
1270 if (server_req->base.questions == NULL) in request_parse()
1288 server_req->base.questions[server_req->base.nquestions++] = q; in request_parse()
1298 evdns_server_request_respond(&(server_req->base), DNS_ERR_NOTIMPL); in request_parse()
1302 port->user_callback(&(server_req->base), port->user_data); in request_parse()
1306 if (server_req->base.questions) { in request_parse()
1307 for (i = 0; i < server_req->base.nquestions; ++i) in request_parse()
1308 mm_free(server_req->base.questions[i]); in request_parse()
1309 mm_free(server_req->base.questions); in request_parse()
1333 transaction_id_pick(struct evdns_base *base) { in transaction_id_pick() argument
1334 ASSERT_LOCKED(base); in transaction_id_pick()
1341 if (request_find_from_trans_id(base, trans_id) == NULL) in transaction_id_pick()
1350 nameserver_pick(struct evdns_base *base) { in nameserver_pick() argument
1351 struct nameserver *started_at = base->server_head, *picked; in nameserver_pick()
1352 ASSERT_LOCKED(base); in nameserver_pick()
1353 if (!base->server_head) return NULL; in nameserver_pick()
1357 if (!base->global_good_nameservers) { in nameserver_pick()
1358 base->server_head = base->server_head->next; in nameserver_pick()
1359 return base->server_head; in nameserver_pick()
1364 if (base->server_head->state) { in nameserver_pick()
1366 picked = base->server_head; in nameserver_pick()
1367 base->server_head = base->server_head->next; in nameserver_pick()
1371 base->server_head = base->server_head->next; in nameserver_pick()
1372 if (base->server_head == started_at) { in nameserver_pick()
1376 EVUTIL_ASSERT(base->global_good_nameservers == 0); in nameserver_pick()
1377 picked = base->server_head; in nameserver_pick()
1378 base->server_head = base->server_head->next; in nameserver_pick()
1391 ASSERT_LOCKED(ns->base); in nameserver_read()
1416 reply_parse(ns->base, packet, r); in nameserver_read()
1488 ASSERT_LOCKED(ns->base); in nameserver_write_waiting()
1493 event_assign(&ns->event, ns->base->event_base, in nameserver_write_waiting()
1513 EVDNS_LOCK(ns->base); in nameserver_ready_callback()
1516 if (!evdns_transmit(ns->base)) { in nameserver_ready_callback()
1523 EVDNS_UNLOCK(ns->base); in nameserver_ready_callback()
1723 evdns_add_server_port_with_base(struct event_base *base, evutil_socket_t socket, int flags, evdns_r… in evdns_add_server_port_with_base() argument
1740 port->event_base = base; in evdns_add_server_port_with_base()
1902 req->base.flags &= ~(EVDNS_FLAGS_AA|EVDNS_FLAGS_RD); in evdns_server_request_set_flags()
1903 req->base.flags |= flags; in evdns_server_request_set_flags()
1922 flags = req->base.flags; in evdns_server_request_format_response()
1928 APPEND16(req->base.nquestions); in evdns_server_request_format_response()
1934 for (i=0; i < req->base.nquestions; ++i) { in evdns_server_request_format_response()
1935 const char *s = req->base.questions[i]->name; in evdns_server_request_format_response()
1941 APPEND16(req->base.questions[i]->type); in evdns_server_request_format_response()
1942 APPEND16(req->base.questions[i]->dns_question_class); in evdns_server_request_format_response()
2093 if (req->base.questions) { in server_request_free()
2094 for (i = 0; i < req->base.nquestions; ++i) in server_request_free()
2095 mm_free(req->base.questions[i]); in server_request_free()
2096 mm_free(req->base.questions); in server_request_free()
2179 struct evdns_base *base = req->base; in evdns_request_timeout_callback() local
2185 EVDNS_LOCK(base); in evdns_request_timeout_callback()
2187 if (req->tx_count >= req->base->global_max_retransmits) { in evdns_request_timeout_callback()
2194 request_finished(req, &REQ_HEAD(req->base, req->trans_id), 1); in evdns_request_timeout_callback()
2201 request_swap_ns(req, nameserver_pick(base)); in evdns_request_timeout_callback()
2205 if (req->ns->timedout > req->base->global_max_nameserver_timeout) { in evdns_request_timeout_callback()
2211 EVDNS_UNLOCK(base); in evdns_request_timeout_callback()
2223 ASSERT_LOCKED(req->base); in evdns_request_transmit_to()
2227 req->base->disable_when_inactive && in evdns_request_transmit_to()
2257 ASSERT_LOCKED(req->base); in evdns_request_transmit()
2293 if (evtimer_add(&req->timeout_event, &req->base->global_timeout) < 0) { in evdns_request_transmit()
2320 EVDNS_LOCK(ns->base); in nameserver_probe_callback()
2328 EVDNS_UNLOCK(ns->base); in nameserver_probe_callback()
2339 ASSERT_LOCKED(ns->base); in nameserver_send_probe()
2346 …req = request_new(ns->base, handle, TYPE_A, "google.com", DNS_QUERY_NO_SEARCH, nameserver_probe_ca… in nameserver_send_probe()
2353 request_trans_id_set(req, transaction_id_pick(ns->base)); in nameserver_send_probe()
2362 evdns_transmit(struct evdns_base *base) { in evdns_transmit() argument
2366 ASSERT_LOCKED(base); in evdns_transmit()
2367 for (i = 0; i < base->n_req_heads; ++i) { in evdns_transmit()
2368 if (base->req_heads[i]) { in evdns_transmit()
2369 struct request *const started_at = base->req_heads[i], *req = started_at; in evdns_transmit()
2387 evdns_base_count_nameservers(struct evdns_base *base) in evdns_base_count_nameservers() argument
2392 EVDNS_LOCK(base); in evdns_base_count_nameservers()
2393 server = base->server_head; in evdns_base_count_nameservers()
2399 } while (server != base->server_head); in evdns_base_count_nameservers()
2401 EVDNS_UNLOCK(base); in evdns_base_count_nameservers()
2413 evdns_base_clear_nameservers_and_suspend(struct evdns_base *base) in evdns_base_clear_nameservers_and_suspend() argument
2418 EVDNS_LOCK(base); in evdns_base_clear_nameservers_and_suspend()
2419 server = base->server_head; in evdns_base_clear_nameservers_and_suspend()
2420 started_at = base->server_head; in evdns_base_clear_nameservers_and_suspend()
2422 EVDNS_UNLOCK(base); in evdns_base_clear_nameservers_and_suspend()
2431 evdns_cancel_request(server->base, server->probe_request); in evdns_base_clear_nameservers_and_suspend()
2441 base->server_head = NULL; in evdns_base_clear_nameservers_and_suspend()
2442 base->global_good_nameservers = 0; in evdns_base_clear_nameservers_and_suspend()
2444 for (i = 0; i < base->n_req_heads; ++i) { in evdns_base_clear_nameservers_and_suspend()
2446 req = req_started_at = base->req_heads[i]; in evdns_base_clear_nameservers_and_suspend()
2456 base->global_requests_waiting++; in evdns_base_clear_nameservers_and_suspend()
2457 evdns_request_insert(req, &base->req_waiting_head); in evdns_base_clear_nameservers_and_suspend()
2462 base->req_waiting_head = base->req_waiting_head->prev; in evdns_base_clear_nameservers_and_suspend()
2468 base->req_heads[i] = NULL; in evdns_base_clear_nameservers_and_suspend()
2471 base->global_requests_inflight = 0; in evdns_base_clear_nameservers_and_suspend()
2473 EVDNS_UNLOCK(base); in evdns_base_clear_nameservers_and_suspend()
2486 evdns_base_resume(struct evdns_base *base) in evdns_base_resume() argument
2488 EVDNS_LOCK(base); in evdns_base_resume()
2489 evdns_requests_pump_waiting_queue(base); in evdns_base_resume()
2490 EVDNS_UNLOCK(base); in evdns_base_resume()
2502 evdns_nameserver_add_impl_(struct evdns_base *base, const struct sockaddr *address, int addrlen) { in evdns_nameserver_add_impl_() argument
2505 const struct nameserver *server = base->server_head, *const started_at = base->server_head; in evdns_nameserver_add_impl_()
2510 ASSERT_LOCKED(base); in evdns_nameserver_add_impl_()
2526 ns->base = base; in evdns_nameserver_add_impl_()
2528 evtimer_assign(&ns->timeout_event, ns->base->event_base, nameserver_prod_callback, ns); in evdns_nameserver_add_impl_()
2534 if (base->global_outgoing_addrlen && in evdns_nameserver_add_impl_()
2537 (struct sockaddr*)&base->global_outgoing_address, in evdns_nameserver_add_impl_()
2538 base->global_outgoing_addrlen) < 0) { in evdns_nameserver_add_impl_()
2545 if (base->so_rcvbuf) { in evdns_nameserver_add_impl_()
2547 (void *)&base->so_rcvbuf, sizeof(base->so_rcvbuf))) { in evdns_nameserver_add_impl_()
2548 log(EVDNS_LOG_WARN, "Couldn't set SO_RCVBUF to %i", base->so_rcvbuf); in evdns_nameserver_add_impl_()
2553 if (base->so_sndbuf) { in evdns_nameserver_add_impl_()
2555 (void *)&base->so_sndbuf, sizeof(base->so_sndbuf))) { in evdns_nameserver_add_impl_()
2556 log(EVDNS_LOG_WARN, "Couldn't set SO_SNDBUF to %i", base->so_sndbuf); in evdns_nameserver_add_impl_()
2565 event_assign(&ns->event, ns->base->event_base, ns->socket, in evdns_nameserver_add_impl_()
2567 if (!base->disable_when_inactive && event_add(&ns->event, NULL) < 0) { in evdns_nameserver_add_impl_()
2576 if (!base->server_head) { in evdns_nameserver_add_impl_()
2578 base->server_head = ns; in evdns_nameserver_add_impl_()
2580 ns->next = base->server_head->next; in evdns_nameserver_add_impl_()
2581 ns->prev = base->server_head; in evdns_nameserver_add_impl_()
2582 base->server_head->next = ns; in evdns_nameserver_add_impl_()
2586 base->global_good_nameservers++; in evdns_nameserver_add_impl_()
2602 evdns_base_nameserver_add(struct evdns_base *base, unsigned long int address) in evdns_base_nameserver_add() argument
2610 EVDNS_LOCK(base); in evdns_base_nameserver_add()
2611 res = evdns_nameserver_add_impl_(base, (struct sockaddr*)&sin, sizeof(sin)); in evdns_base_nameserver_add()
2612 EVDNS_UNLOCK(base); in evdns_base_nameserver_add()
2647 evdns_base_nameserver_ip_add(struct evdns_base *base, const char *ip_as_string) { in evdns_base_nameserver_ip_add() argument
2662 EVDNS_LOCK(base); in evdns_base_nameserver_ip_add()
2663 res = evdns_nameserver_add_impl_(base, sa, len); in evdns_base_nameserver_ip_add()
2664 EVDNS_UNLOCK(base); in evdns_base_nameserver_ip_add()
2676 evdns_base_nameserver_sockaddr_add(struct evdns_base *base, in evdns_base_nameserver_sockaddr_add() argument
2680 EVUTIL_ASSERT(base); in evdns_base_nameserver_sockaddr_add()
2681 EVDNS_LOCK(base); in evdns_base_nameserver_sockaddr_add()
2682 res = evdns_nameserver_add_impl_(base, sa, len); in evdns_base_nameserver_sockaddr_add()
2683 EVDNS_UNLOCK(base); in evdns_base_nameserver_sockaddr_add()
2688 evdns_base_get_nameserver_addr(struct evdns_base *base, int idx, in evdns_base_get_nameserver_addr() argument
2694 EVDNS_LOCK(base); in evdns_base_get_nameserver_addr()
2695 server = base->server_head; in evdns_base_get_nameserver_addr()
2697 if (server->next == base->server_head) in evdns_base_get_nameserver_addr()
2711 EVDNS_UNLOCK(base); in evdns_base_get_nameserver_addr()
2719 ASSERT_LOCKED(req->base); in evdns_request_remove()
2756 ASSERT_LOCKED(req->base); in evdns_request_insert()
2781 request_new(struct evdns_base *base, struct evdns_request *handle, int type, in request_new() argument
2786 (base->global_requests_inflight < base->global_max_requests_inflight) ? 1 : 0; in request_new()
2790 const u16 trans_id = issuing_now ? transaction_id_pick(base) : 0xffff; in request_new()
2798 ASSERT_LOCKED(base); in request_new()
2808 req->base = base; in request_new()
2810 evtimer_assign(&req->timeout_event, req->base->event_base, evdns_request_timeout_callback, req); in request_new()
2812 if (base->global_randomize_case) { in request_new()
2843 req->ns = issuing_now ? nameserver_pick(base) : NULL; in request_new()
2848 handle->base = base; in request_new()
2859 struct evdns_base *base = req->base; in request_submit() local
2860 ASSERT_LOCKED(base); in request_submit()
2865 evdns_request_insert(req, &REQ_HEAD(base, req->trans_id)); in request_submit()
2867 base->global_requests_inflight++; in request_submit()
2872 evdns_request_insert(req, &base->req_waiting_head); in request_submit()
2873 base->global_requests_waiting++; in request_submit()
2879 evdns_cancel_request(struct evdns_base *base, struct evdns_request *handle) in evdns_cancel_request() argument
2886 if (!base) { in evdns_cancel_request()
2888 base = handle->base; in evdns_cancel_request()
2889 if (!base) in evdns_cancel_request()
2890 base = handle->current_req->base; in evdns_cancel_request()
2893 EVDNS_LOCK(base); in evdns_cancel_request()
2895 EVDNS_UNLOCK(base); in evdns_cancel_request()
2905 request_finished(req, &REQ_HEAD(base, req->trans_id), 1); in evdns_cancel_request()
2908 request_finished(req, &base->req_waiting_head, 1); in evdns_cancel_request()
2910 EVDNS_UNLOCK(base); in evdns_cancel_request()
2915 evdns_base_resolve_ipv4(struct evdns_base *base, const char *name, int flags, in evdns_base_resolve_ipv4() argument
2923 EVDNS_LOCK(base); in evdns_base_resolve_ipv4()
2926 request_new(base, handle, TYPE_A, name, flags, in evdns_base_resolve_ipv4()
2931 search_request_new(base, handle, TYPE_A, name, flags, in evdns_base_resolve_ipv4()
2938 EVDNS_UNLOCK(base); in evdns_base_resolve_ipv4()
2952 evdns_base_resolve_ipv6(struct evdns_base *base, in evdns_base_resolve_ipv6() argument
2962 EVDNS_LOCK(base); in evdns_base_resolve_ipv6()
2964 req = request_new(base, handle, TYPE_AAAA, name, flags, in evdns_base_resolve_ipv6()
2969 search_request_new(base, handle, TYPE_AAAA, name, flags, in evdns_base_resolve_ipv6()
2976 EVDNS_UNLOCK(base); in evdns_base_resolve_ipv6()
2987 evdns_base_resolve_reverse(struct evdns_base *base, const struct in_addr *in, int flags, evdns_call… in evdns_base_resolve_reverse() argument
3003 EVDNS_LOCK(base); in evdns_base_resolve_reverse()
3004 req = request_new(base, handle, TYPE_PTR, buf, flags, callback, ptr); in evdns_base_resolve_reverse()
3011 EVDNS_UNLOCK(base); in evdns_base_resolve_reverse()
3021 evdns_base_resolve_reverse_ipv6(struct evdns_base *base, const struct in6_addr *in, int flags, evdn… in evdns_base_resolve_reverse_ipv6() argument
3043 EVDNS_LOCK(base); in evdns_base_resolve_reverse_ipv6()
3044 req = request_new(base, handle, TYPE_PTR, buf, flags, callback, ptr); in evdns_base_resolve_reverse_ipv6()
3051 EVDNS_UNLOCK(base); in evdns_base_resolve_reverse_ipv6()
3112 search_postfix_clear(struct evdns_base *base) { in search_postfix_clear() argument
3113 search_state_decref(base->global_search_state); in search_postfix_clear()
3115 base->global_search_state = search_state_new(); in search_postfix_clear()
3120 evdns_base_search_clear(struct evdns_base *base) in evdns_base_search_clear() argument
3122 EVDNS_LOCK(base); in evdns_base_search_clear()
3123 search_postfix_clear(base); in evdns_base_search_clear()
3124 EVDNS_UNLOCK(base); in evdns_base_search_clear()
3133 search_postfix_add(struct evdns_base *base, const char *domain) { in search_postfix_add() argument
3139 ASSERT_LOCKED(base); in search_postfix_add()
3140 if (!base->global_search_state) base->global_search_state = search_state_new(); in search_postfix_add()
3141 if (!base->global_search_state) return; in search_postfix_add()
3142 base->global_search_state->num_domains++; in search_postfix_add()
3147 sdomain->next = base->global_search_state->head; in search_postfix_add()
3150 base->global_search_state->head = sdomain; in search_postfix_add()
3156 search_reverse(struct evdns_base *base) { in search_reverse() argument
3158 ASSERT_LOCKED(base); in search_reverse()
3159 cur = base->global_search_state->head; in search_reverse()
3167 base->global_search_state->head = prev; in search_reverse()
3172 evdns_base_search_add(struct evdns_base *base, const char *domain) { in evdns_base_search_add() argument
3173 EVDNS_LOCK(base); in evdns_base_search_add()
3174 search_postfix_add(base, domain); in evdns_base_search_add()
3175 EVDNS_UNLOCK(base); in evdns_base_search_add()
3184 evdns_base_search_ndots_set(struct evdns_base *base, const int ndots) { in evdns_base_search_ndots_set() argument
3185 EVDNS_LOCK(base); in evdns_base_search_ndots_set()
3186 if (!base->global_search_state) base->global_search_state = search_state_new(); in evdns_base_search_ndots_set()
3187 if (base->global_search_state) in evdns_base_search_ndots_set()
3188 base->global_search_state->ndots = ndots; in evdns_base_search_ndots_set()
3189 EVDNS_UNLOCK(base); in evdns_base_search_ndots_set()
3197 search_set_from_hostname(struct evdns_base *base) { in search_set_from_hostname() argument
3200 ASSERT_LOCKED(base); in search_set_from_hostname()
3201 search_postfix_clear(base); in search_set_from_hostname()
3205 search_postfix_add(base, domainname); in search_set_from_hostname()
3240 search_request_new(struct evdns_base *base, struct evdns_request *handle, in search_request_new() argument
3243 ASSERT_LOCKED(base); in search_request_new()
3247 base->global_search_state && in search_request_new()
3248 base->global_search_state->num_domains) { in search_request_new()
3251 if (string_num_dots(name) >= base->global_search_state->ndots) { in search_request_new()
3252 req = request_new(base, handle, type, name, flags, user_callback, user_arg); in search_request_new()
3256 char *const new_name = search_make_new(base->global_search_state, 0, name); in search_request_new()
3258 req = request_new(base, handle, type, new_name, flags, user_callback, user_arg); in search_request_new()
3271 handle->search_state = base->global_search_state; in search_request_new()
3273 base->global_search_state->refcount++; in search_request_new()
3277 struct request *const req = request_new(base, handle, type, name, flags, user_callback, user_arg); in search_request_new()
3292 struct evdns_base *base = req->base; in search_try_next() local
3294 ASSERT_LOCKED(base); in search_try_next()
3304 …newreq = request_new(base, NULL, req->request_type, handle->search_origname, handle->search_flags,… in search_try_next()
3317 …newreq = request_new(base, NULL, req->request_type, new_name, handle->search_flags, req->user_call… in search_try_next()
3325 request_finished(req, &REQ_HEAD(req->base, req->trans_id), 0); in search_try_next()
3334 ASSERT_LOCKED(handle->current_req->base); in search_request_finished()
3349 evdns_resolv_set_defaults(struct evdns_base *base, int flags) { in evdns_resolv_set_defaults() argument
3355 ASSERT_LOCKED(base); in evdns_resolv_set_defaults()
3357 search_set_from_hostname(base); in evdns_resolv_set_defaults()
3359 evdns_base_nameserver_ip_add(base, "127.0.0.1"); in evdns_resolv_set_defaults()
3426 evdns_base_set_max_requests_inflight(struct evdns_base *base, int maxinflight) in evdns_base_set_max_requests_inflight() argument
3428 int old_n_heads = base->n_req_heads, n_heads; in evdns_base_set_max_requests_inflight()
3429 struct request **old_heads = base->req_heads, **new_heads, *req; in evdns_base_set_max_requests_inflight()
3432 ASSERT_LOCKED(base); in evdns_base_set_max_requests_inflight()
3450 base->req_heads = new_heads; in evdns_base_set_max_requests_inflight()
3451 base->n_req_heads = n_heads; in evdns_base_set_max_requests_inflight()
3452 base->global_max_requests_inflight = maxinflight; in evdns_base_set_max_requests_inflight()
3458 evdns_base_set_option(struct evdns_base *base, in evdns_base_set_option() argument
3462 EVDNS_LOCK(base); in evdns_base_set_option()
3463 res = evdns_base_set_option_impl(base, option, val, DNS_OPTIONS_ALL); in evdns_base_set_option()
3464 EVDNS_UNLOCK(base); in evdns_base_set_option()
3485 evdns_base_set_option_impl(struct evdns_base *base, in evdns_base_set_option_impl() argument
3488 ASSERT_LOCKED(base); in evdns_base_set_option_impl()
3494 if (!base->global_search_state) base->global_search_state = search_state_new(); in evdns_base_set_option_impl()
3495 if (!base->global_search_state) return -1; in evdns_base_set_option_impl()
3496 base->global_search_state->ndots = ndots; in evdns_base_set_option_impl()
3502 memcpy(&base->global_timeout, &tv, sizeof(struct timeval)); in evdns_base_set_option_impl()
3509 memcpy(&base->global_getaddrinfo_allow_skew, &tv, in evdns_base_set_option_impl()
3517 base->global_max_nameserver_timeout = maxtimeout; in evdns_base_set_option_impl()
3524 evdns_base_set_max_requests_inflight(base, maxinflight); in evdns_base_set_option_impl()
3531 base->global_max_retransmits = retries; in evdns_base_set_option_impl()
3536 base->global_randomize_case = randcase; in evdns_base_set_option_impl()
3540 int len = sizeof(base->global_outgoing_address); in evdns_base_set_option_impl()
3543 (struct sockaddr*)&base->global_outgoing_address, &len)) in evdns_base_set_option_impl()
3545 base->global_outgoing_addrlen = len; in evdns_base_set_option_impl()
3554 memcpy(&base->global_nameserver_probe_initial_timeout, &tv, in evdns_base_set_option_impl()
3561 base->so_rcvbuf = buf; in evdns_base_set_option_impl()
3567 base->so_sndbuf = buf; in evdns_base_set_option_impl()
3581 resolv_conf_parse_line(struct evdns_base *base, char *const start, int flags) { in resolv_conf_parse_line() argument
3588 ASSERT_LOCKED(base); in resolv_conf_parse_line()
3595 evdns_base_nameserver_ip_add(base, nameserver); in resolv_conf_parse_line()
3599 search_postfix_clear(base); in resolv_conf_parse_line()
3600 search_postfix_add(base, domain); in resolv_conf_parse_line()
3604 search_postfix_clear(base); in resolv_conf_parse_line()
3607 search_postfix_add(base, domain); in resolv_conf_parse_line()
3609 search_reverse(base); in resolv_conf_parse_line()
3614 evdns_base_set_option_impl(base, option, val ? val+1 : "", flags); in resolv_conf_parse_line()
3629 evdns_base_resolv_conf_parse(struct evdns_base *base, int flags, const char *const filename) { in evdns_base_resolv_conf_parse() argument
3631 EVDNS_LOCK(base); in evdns_base_resolv_conf_parse()
3632 res = evdns_base_resolv_conf_parse_impl(base, flags, filename); in evdns_base_resolv_conf_parse()
3633 EVDNS_UNLOCK(base); in evdns_base_resolv_conf_parse()
3663 evdns_base_resolv_conf_parse_impl(struct evdns_base *base, int flags, const char *const filename) { in evdns_base_resolv_conf_parse_impl() argument
3678 evdns_base_load_hosts(base, fname); in evdns_base_resolv_conf_parse_impl()
3684 evdns_resolv_set_defaults(base, flags); in evdns_base_resolv_conf_parse_impl()
3691 evdns_resolv_set_defaults(base, flags); in evdns_base_resolv_conf_parse_impl()
3702 resolv_conf_parse_line(base, start, flags); in evdns_base_resolv_conf_parse_impl()
3706 resolv_conf_parse_line(base, start, flags); in evdns_base_resolv_conf_parse_impl()
3711 if (!base->server_head && add_default) { in evdns_base_resolv_conf_parse_impl()
3713 evdns_base_nameserver_ip_add(base, "127.0.0.1"); in evdns_base_resolv_conf_parse_impl()
3716 …if (flags & DNS_OPTION_SEARCH && (!base->global_search_state || base->global_search_state->num_dom… in evdns_base_resolv_conf_parse_impl()
3717 search_set_from_hostname(base); in evdns_base_resolv_conf_parse_impl()
3735 evdns_nameserver_ip_add_line(struct evdns_base *base, const char *ips) { in evdns_nameserver_ip_add_line() argument
3739 ASSERT_LOCKED(base); in evdns_nameserver_ip_add_line()
3751 r = evdns_base_nameserver_ip_add(base, buf); in evdns_nameserver_ip_add_line()
3763 load_nameservers_with_getnetworkparams(struct evdns_base *base) in load_nameservers_with_getnetworkparams() argument
3774 ASSERT_LOCKED(base); in load_nameservers_with_getnetworkparams()
3812 r = evdns_nameserver_ip_add_line(base, ns->IpAddress.String); in load_nameservers_with_getnetworkparams()
3842 config_nameserver_from_reg_key(struct evdns_base *base, HKEY key, const TCHAR *subkey) in config_nameserver_from_reg_key() argument
3848 ASSERT_LOCKED(base); in config_nameserver_from_reg_key()
3857 status = evdns_nameserver_ip_add_line(base,buf); in config_nameserver_from_reg_key()
3869 load_nameservers_from_registry(struct evdns_base *base) in load_nameservers_from_registry() argument
3874 if (!found && config_nameserver_from_reg_key(base,k,TEXT(name)) == 0) { \ in load_nameservers_from_registry()
3882 ASSERT_LOCKED(base); in load_nameservers_from_registry()
3925 evdns_base_config_windows_nameservers(struct evdns_base *base) in evdns_base_config_windows_nameservers() argument
3929 if (base == NULL) in evdns_base_config_windows_nameservers()
3930 base = current_base; in evdns_base_config_windows_nameservers()
3931 if (base == NULL) in evdns_base_config_windows_nameservers()
3933 EVDNS_LOCK(base); in evdns_base_config_windows_nameservers()
3936 evdns_base_load_hosts(base, fname); in evdns_base_config_windows_nameservers()
3940 if (load_nameservers_with_getnetworkparams(base) == 0) { in evdns_base_config_windows_nameservers()
3941 EVDNS_UNLOCK(base); in evdns_base_config_windows_nameservers()
3944 r = load_nameservers_from_registry(base); in evdns_base_config_windows_nameservers()
3946 EVDNS_UNLOCK(base); in evdns_base_config_windows_nameservers()
3965 struct evdns_base *base; in evdns_base_new() local
3979 base = mm_malloc(sizeof(struct evdns_base)); in evdns_base_new()
3980 if (base == NULL) in evdns_base_new()
3982 memset(base, 0, sizeof(struct evdns_base)); in evdns_base_new()
3983 base->req_waiting_head = NULL; in evdns_base_new()
3985 EVTHREAD_ALLOC_LOCK(base->lock, EVTHREAD_LOCKTYPE_RECURSIVE); in evdns_base_new()
3986 EVDNS_LOCK(base); in evdns_base_new()
3989 base->req_heads = NULL; in evdns_base_new()
3991 evdns_base_set_max_requests_inflight(base, 64); in evdns_base_new()
3993 base->server_head = NULL; in evdns_base_new()
3994 base->event_base = event_base; in evdns_base_new()
3995 base->global_good_nameservers = base->global_requests_inflight = in evdns_base_new()
3996 base->global_requests_waiting = 0; in evdns_base_new()
3998 base->global_timeout.tv_sec = 5; in evdns_base_new()
3999 base->global_timeout.tv_usec = 0; in evdns_base_new()
4000 base->global_max_reissues = 1; in evdns_base_new()
4001 base->global_max_retransmits = 3; in evdns_base_new()
4002 base->global_max_nameserver_timeout = 3; in evdns_base_new()
4003 base->global_search_state = NULL; in evdns_base_new()
4004 base->global_randomize_case = 1; in evdns_base_new()
4005 base->global_getaddrinfo_allow_skew.tv_sec = 3; in evdns_base_new()
4006 base->global_getaddrinfo_allow_skew.tv_usec = 0; in evdns_base_new()
4007 base->global_nameserver_probe_initial_timeout.tv_sec = 10; in evdns_base_new()
4008 base->global_nameserver_probe_initial_timeout.tv_usec = 0; in evdns_base_new()
4010 TAILQ_INIT(&base->hostsdb); in evdns_base_new()
4034 r = evdns_base_config_windows_nameservers(base); in evdns_base_new()
4036 r = evdns_base_resolv_conf_parse(base, opts, "/etc/resolv.conf"); in evdns_base_new()
4039 evdns_base_free_and_unlock(base, 0); in evdns_base_new()
4044 base->disable_when_inactive = 1; in evdns_base_new()
4047 EVDNS_UNLOCK(base); in evdns_base_new()
4048 return base; in evdns_base_new()
4054 struct evdns_base *base = evdns_base_new(NULL, 1); in evdns_init() local
4055 if (base) { in evdns_init()
4056 current_base = base; in evdns_init()
4094 evdns_cancel_request(server->base, server->probe_request); in evdns_nameserver_free()
4102 evdns_base_free_and_unlock(struct evdns_base *base, int fail_requests) in evdns_base_free_and_unlock() argument
4112 while (base->req_waiting_head) { in evdns_base_free_and_unlock()
4114 reply_schedule_callback(base->req_waiting_head, 0, DNS_ERR_SHUTDOWN, NULL); in evdns_base_free_and_unlock()
4115 request_finished(base->req_waiting_head, &base->req_waiting_head, 1); in evdns_base_free_and_unlock()
4117 for (i = 0; i < base->n_req_heads; ++i) { in evdns_base_free_and_unlock()
4118 while (base->req_heads[i]) { in evdns_base_free_and_unlock()
4120 reply_schedule_callback(base->req_heads[i], 0, DNS_ERR_SHUTDOWN, NULL); in evdns_base_free_and_unlock()
4121 request_finished(base->req_heads[i], &REQ_HEAD(base, base->req_heads[i]->trans_id), 1); in evdns_base_free_and_unlock()
4124 base->global_requests_inflight = base->global_requests_waiting = 0; in evdns_base_free_and_unlock()
4126 for (server = base->server_head; server; server = server_next) { in evdns_base_free_and_unlock()
4131 if (server_next == base->server_head) in evdns_base_free_and_unlock()
4134 base->server_head = NULL; in evdns_base_free_and_unlock()
4135 base->global_good_nameservers = 0; in evdns_base_free_and_unlock()
4137 if (base->global_search_state) { in evdns_base_free_and_unlock()
4138 for (dom = base->global_search_state->head; dom; dom = dom_next) { in evdns_base_free_and_unlock()
4142 mm_free(base->global_search_state); in evdns_base_free_and_unlock()
4143 base->global_search_state = NULL; in evdns_base_free_and_unlock()
4148 while ((victim = TAILQ_FIRST(&base->hostsdb))) { in evdns_base_free_and_unlock()
4149 TAILQ_REMOVE(&base->hostsdb, victim, next); in evdns_base_free_and_unlock()
4154 mm_free(base->req_heads); in evdns_base_free_and_unlock()
4156 EVDNS_UNLOCK(base); in evdns_base_free_and_unlock()
4157 EVTHREAD_FREE_LOCK(base->lock, EVTHREAD_LOCKTYPE_RECURSIVE); in evdns_base_free_and_unlock()
4159 mm_free(base); in evdns_base_free_and_unlock()
4163 evdns_base_free(struct evdns_base *base, int fail_requests) in evdns_base_free() argument
4165 EVDNS_LOCK(base); in evdns_base_free()
4166 evdns_base_free_and_unlock(base, fail_requests); in evdns_base_free()
4170 evdns_base_clear_host_addresses(struct evdns_base *base) in evdns_base_clear_host_addresses() argument
4173 EVDNS_LOCK(base); in evdns_base_clear_host_addresses()
4174 while ((victim = TAILQ_FIRST(&base->hostsdb))) { in evdns_base_clear_host_addresses()
4175 TAILQ_REMOVE(&base->hostsdb, victim, next); in evdns_base_clear_host_addresses()
4178 EVDNS_UNLOCK(base); in evdns_base_clear_host_addresses()
4193 evdns_base_parse_hosts_line(struct evdns_base *base, char *line) in evdns_base_parse_hosts_line() argument
4201 ASSERT_LOCKED(base); in evdns_base_parse_hosts_line()
4236 TAILQ_INSERT_TAIL(&base->hostsdb, he, next); in evdns_base_parse_hosts_line()
4247 evdns_base_load_hosts_impl(struct evdns_base *base, const char *hosts_fname) in evdns_base_load_hosts_impl() argument
4253 ASSERT_LOCKED(base); in evdns_base_load_hosts_impl()
4259 evdns_base_parse_hosts_line(base, tmp); in evdns_base_load_hosts_impl()
4261 evdns_base_parse_hosts_line(base, tmp); in evdns_base_load_hosts_impl()
4273 evdns_base_parse_hosts_line(base, cp); in evdns_base_load_hosts_impl()
4276 evdns_base_parse_hosts_line(base, cp); in evdns_base_load_hosts_impl()
4286 evdns_base_load_hosts(struct evdns_base *base, const char *hosts_fname) in evdns_base_load_hosts() argument
4289 if (!base) in evdns_base_load_hosts()
4290 base = current_base; in evdns_base_load_hosts()
4291 EVDNS_LOCK(base); in evdns_base_load_hosts()
4292 res = evdns_base_load_hosts_impl(base, hosts_fname); in evdns_base_load_hosts()
4293 EVDNS_UNLOCK(base); in evdns_base_load_hosts()
4643 find_hosts_entry(struct evdns_base *base, const char *hostname, in find_hosts_entry() argument
4651 e = TAILQ_FIRST(&base->hostsdb); in find_hosts_entry()
4661 evdns_getaddrinfo_fromhosts(struct evdns_base *base, in evdns_getaddrinfo_fromhosts() argument
4670 EVDNS_LOCK(base); in evdns_getaddrinfo_fromhosts()
4671 for (e = find_hosts_entry(base, nodename, NULL); e; in evdns_getaddrinfo_fromhosts()
4672 e = find_hosts_entry(base, nodename, e)) { in evdns_getaddrinfo_fromhosts()
4686 EVDNS_UNLOCK(base); in evdns_getaddrinfo_fromhosts()