Lines Matching refs:ns
179 struct nameserver *ns; /* the server which we last sent it */
398 static void nameserver_send_probe(struct nameserver *const ns);
489 struct nameserver *const ns = (struct nameserver *) arg;
493 EVDNS_LOCK(ns->base);
494 nameserver_send_probe(ns);
495 EVDNS_UNLOCK(ns->base);
502 nameserver_probe_failed(struct nameserver *const ns) {
506 ASSERT_LOCKED(ns->base);
507 (void) evtimer_del(&ns->timeout_event);
508 if (ns->state == 1) {
517 memcpy(&timeout, &ns->base->global_nameserver_probe_initial_timeout,
519 for (i=ns->failed_times; i > 0 && timeout.tv_sec < MAX_PROBE_TIMEOUT; --i) {
532 ns->failed_times++;
534 if (evtimer_add(&ns->timeout_event, &timeout) < 0) {
539 (struct sockaddr *)&ns->address,
545 request_swap_ns(struct request *req, struct nameserver *ns) {
546 if (ns && req->ns != ns) {
547 EVUTIL_ASSERT(req->ns->requests_inflight > 0);
548 req->ns->requests_inflight--;
549 ns->requests_inflight++;
551 req->ns = ns;
558 nameserver_failed(struct nameserver *const ns, const char *msg) {
560 struct evdns_base *base = ns->base;
567 if (!ns->state) return;
571 (struct sockaddr *)&ns->address,
581 ns->state = 0;
582 ns->failed_times = 1;
584 if (evtimer_add(&ns->timeout_event,
589 (struct sockaddr *)&ns->address,
606 if (req->tx_count == 0 && req->ns == ns) {
618 nameserver_up(struct nameserver *const ns)
621 ASSERT_LOCKED(ns->base);
622 if (ns->state) return;
625 (struct sockaddr *)&ns->address,
627 evtimer_del(&ns->timeout_event);
628 if (ns->probe_request) {
629 evdns_cancel_request(ns->base, ns->probe_request);
630 ns->probe_request = NULL;
632 ns->state = 1;
633 ns->failed_times = 0;
634 ns->timedout = 0;
635 ns->base->global_good_nameservers++;
662 req->ns->requests_inflight--;
669 if (req->ns &&
670 req->ns->requests_inflight == 0 &&
672 event_del(&req->ns->event);
673 evtimer_del(&req->ns->timeout_event);
716 const struct nameserver *const last_ns = req->ns;
723 if (req->ns == last_ns) {
752 req->ns = nameserver_pick(base);
753 if (!req->ns)
757 req->ns->requests_inflight++;
904 nameserver_failed(req->ns, msg);
917 (struct sockaddr *)&req->ns->address,
924 if (req->handle == req->ns->probe_request) {
926 req->ns->probe_request = NULL;
929 nameserver_up(req->ns);
952 if (req->handle == req->ns->probe_request)
953 req->ns->probe_request = NULL; /* Avoid double-free */
954 nameserver_up(req->ns);
1371 nameserver_read(struct nameserver *ns) {
1376 ASSERT_LOCKED(ns->base);
1379 const int r = recvfrom(ns->socket, (void*)packet,
1383 int err = evutil_socket_geterror(ns->socket);
1386 nameserver_failed(ns,
1391 (struct sockaddr*)&ns->address, 0)) {
1400 ns->timedout = 0;
1401 reply_parse(ns->base, packet, r);
1472 nameserver_write_waiting(struct nameserver *ns, char waiting) {
1473 ASSERT_LOCKED(ns->base);
1474 if (ns->write_waiting == waiting) return;
1476 ns->write_waiting = waiting;
1477 (void) event_del(&ns->event);
1478 event_assign(&ns->event, ns->base->event_base,
1479 ns->socket, EV_READ | (waiting ? EV_WRITE : 0) | EV_PERSIST,
1480 nameserver_ready_callback, ns);
1481 if (event_add(&ns->event, NULL) < 0) {
1485 (struct sockaddr *)&ns->address,
1495 struct nameserver *ns = (struct nameserver *) arg;
1498 EVDNS_LOCK(ns->base);
1500 ns->choked = 0;
1501 if (!evdns_transmit(ns->base)) {
1502 nameserver_write_waiting(ns, 0);
1506 nameserver_read(ns);
1508 EVDNS_UNLOCK(ns->base);
2172 struct nameserver *ns = req->ns;
2179 nameserver_failed(ns, "request timed out.");
2188 req->ns->timedout++;
2189 if (req->ns->timedout > req->base->global_max_nameserver_timeout) {
2190 req->ns->timedout = 0;
2191 nameserver_failed(req->ns, "request timed out.");
2222 nameserver_failed(req->ns, evutil_socket_error_to_string(err));
2248 if (!req->ns)
2254 if (req->ns->choked) {
2260 r = evdns_request_transmit_to(req, req->ns);
2264 req->ns->choked = 1;
2265 nameserver_write_waiting(req->ns, 1);
2275 "Setting timeout for request %p, sent to nameserver %p", req, req->ns);
2290 struct nameserver *const ns = (struct nameserver *) arg;
2303 EVDNS_LOCK(ns->base);
2304 ns->probe_request = NULL;
2307 nameserver_up(ns);
2309 nameserver_probe_failed(ns);
2311 EVDNS_UNLOCK(ns->base);
2315 nameserver_send_probe(struct nameserver *const ns) {
2322 ASSERT_LOCKED(ns->base);
2325 (struct sockaddr *)&ns->address,
2329 req = request_new(ns->base, handle, TYPE_A, "google.com", DNS_QUERY_NO_SEARCH, nameserver_probe_callback, ns);
2334 ns->probe_request = handle;
2336 request_trans_id_set(req, transaction_id_pick(ns->base));
2337 req->ns = ns;
2433 req->ns = NULL;
2489 struct nameserver *ns;
2500 if (addrlen > (int)sizeof(ns->address)) {
2505 ns = (struct nameserver *) mm_malloc(sizeof(struct nameserver));
2506 if (!ns) return -1;
2508 memset(ns, 0, sizeof(struct nameserver));
2509 ns->base = base;
2511 evtimer_assign(&ns->timeout_event, ns->base->event_base, nameserver_prod_callback, ns);
2513 ns->socket = evutil_socket_(address->sa_family,
2515 if (ns->socket < 0) { err = 1; goto out1; }
2519 if (bind(ns->socket,
2528 memcpy(&ns->address, address, addrlen);
2529 ns->addrlen = addrlen;
2530 ns->state = 1;
2531 event_assign(&ns->event, ns->base->event_base, ns->socket,
2532 EV_READ | EV_PERSIST, nameserver_ready_callback, ns);
2533 if (!base->disable_when_inactive && event_add(&ns->event, NULL) < 0) {
2539 evutil_format_sockaddr_port_(address, addrbuf, sizeof(addrbuf)), ns);
2543 ns->next = ns->prev = ns;
2544 base->server_head = ns;
2546 ns->next = base->server_head->next;
2547 ns->prev = base->server_head;
2548 base->server_head->next = ns;
2549 ns->next->prev = ns;
2557 evutil_closesocket(ns->socket);
2559 event_debug_unassign(&ns->event);
2560 mm_free(ns);
2809 req->ns = issuing_now ? nameserver_pick(base) : NULL;
2828 if (req->ns) {
2834 req->ns->requests_inflight++;
2869 if (req->ns) {
3708 IP_ADDR_STRING *ns;
3747 ns = &(fixed->DnsServerList);
3748 while (ns) {
3749 r = evdns_nameserver_ip_add_line(base, ns->IpAddress.String);
3752 (ns->IpAddress.String),(int)GetLastError());
3756 log(EVDNS_LOG_DEBUG,"Successfully added %s as nameserver",ns->IpAddress.String);
3759 ns = ns->Next;