1 /* $OpenBSD: res_send_async.c,v 1.27 2015/09/20 14:19:21 eric Exp $ */ 2 /* 3 * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #include <sys/types.h> 19 #include <sys/socket.h> 20 #include <sys/uio.h> 21 #include <netinet/in.h> 22 #include <arpa/nameser.h> 23 #include <netdb.h> 24 25 #include <asr.h> 26 #include <errno.h> 27 #include <fcntl.h> 28 #include <poll.h> 29 #include <resolv.h> /* for res_random */ 30 #include <stdlib.h> 31 #include <string.h> 32 #include <unistd.h> 33 34 #include "asr_private.h" 35 36 #define OP_QUERY (0) 37 38 static int res_send_async_run(struct asr_query *, struct asr_result *); 39 static int sockaddr_connect(const struct sockaddr *, int); 40 static int udp_send(struct asr_query *); 41 static int udp_recv(struct asr_query *); 42 static int tcp_write(struct asr_query *); 43 static int tcp_read(struct asr_query *); 44 static int validate_packet(struct asr_query *); 45 static int setup_query(struct asr_query *, const char *, const char *, int, int); 46 static int ensure_ibuf(struct asr_query *, size_t); 47 static int iter_ns(struct asr_query *); 48 49 #define AS_NS_SA(p) ((p)->as_ctx->ac_ns[(p)->as.dns.nsidx - 1]) 50 51 52 struct asr_query * 53 res_send_async(const unsigned char *buf, int buflen, void *asr) 54 { 55 struct asr_ctx *ac; 56 struct asr_query *as; 57 struct asr_unpack p; 58 struct asr_dns_header h; 59 struct asr_dns_query q; 60 61 DPRINT_PACKET("asr: res_send_async()", buf, buflen); 62 63 ac = _asr_use_resolver(asr); 64 if ((as = _asr_async_new(ac, ASR_SEND)) == NULL) { 65 _asr_ctx_unref(ac); 66 return (NULL); /* errno set */ 67 } 68 as->as_run = res_send_async_run; 69 70 as->as.dns.flags |= ASYNC_EXTOBUF; 71 as->as.dns.obuf = (unsigned char *)buf; 72 as->as.dns.obuflen = buflen; 73 as->as.dns.obufsize = buflen; 74 75 _asr_unpack_init(&p, buf, buflen); 76 _asr_unpack_header(&p, &h); 77 _asr_unpack_query(&p, &q); 78 if (p.err) { 79 errno = EINVAL; 80 goto err; 81 } 82 as->as.dns.reqid = h.id; 83 as->as.dns.type = q.q_type; 84 as->as.dns.class = q.q_class; 85 as->as.dns.dname = strdup(q.q_dname); 86 if (as->as.dns.dname == NULL) 87 goto err; /* errno set */ 88 89 _asr_ctx_unref(ac); 90 return (as); 91 err: 92 if (as) 93 _asr_async_free(as); 94 _asr_ctx_unref(ac); 95 return (NULL); 96 } 97 DEF_WEAK(res_send_async); 98 99 /* 100 * Unlike res_query(), this version will actually return the packet 101 * if it has received a valid one (errno == 0) even if h_errno is 102 * not NETDB_SUCCESS. So the packet *must* be freed if necessary. 103 */ 104 struct asr_query * 105 res_query_async(const char *name, int class, int type, void *asr) 106 { 107 struct asr_ctx *ac; 108 struct asr_query *as; 109 110 DPRINT("asr: res_query_async(\"%s\", %i, %i)\n", name, class, type); 111 112 ac = _asr_use_resolver(asr); 113 as = _res_query_async_ctx(name, class, type, ac); 114 _asr_ctx_unref(ac); 115 116 return (as); 117 } 118 DEF_WEAK(res_query_async); 119 120 struct asr_query * 121 _res_query_async_ctx(const char *name, int class, int type, struct asr_ctx *a_ctx) 122 { 123 struct asr_query *as; 124 125 DPRINT("asr: res_query_async_ctx(\"%s\", %i, %i)\n", name, class, type); 126 127 if ((as = _asr_async_new(a_ctx, ASR_SEND)) == NULL) 128 return (NULL); /* errno set */ 129 as->as_run = res_send_async_run; 130 131 /* This adds a "." to name if it doesn't already has one. 132 * That's how res_query() behaves (through res_mkquery"). 133 */ 134 if (setup_query(as, name, NULL, class, type) == -1) 135 goto err; /* errno set */ 136 137 return (as); 138 139 err: 140 if (as) 141 _asr_async_free(as); 142 143 return (NULL); 144 } 145 146 static int 147 res_send_async_run(struct asr_query *as, struct asr_result *ar) 148 { 149 next: 150 switch (as->as_state) { 151 152 case ASR_STATE_INIT: 153 154 if (as->as_ctx->ac_nscount == 0) { 155 ar->ar_errno = ECONNREFUSED; 156 async_set_state(as, ASR_STATE_HALT); 157 break; 158 } 159 160 async_set_state(as, ASR_STATE_NEXT_NS); 161 break; 162 163 case ASR_STATE_NEXT_NS: 164 165 if (iter_ns(as) == -1) { 166 ar->ar_errno = ETIMEDOUT; 167 async_set_state(as, ASR_STATE_HALT); 168 break; 169 } 170 171 if (as->as_ctx->ac_options & RES_USEVC || 172 as->as.dns.obuflen > PACKETSZ) 173 async_set_state(as, ASR_STATE_TCP_WRITE); 174 else 175 async_set_state(as, ASR_STATE_UDP_SEND); 176 break; 177 178 case ASR_STATE_UDP_SEND: 179 180 if (udp_send(as) == -1) { 181 async_set_state(as, ASR_STATE_NEXT_NS); 182 break; 183 } 184 async_set_state(as, ASR_STATE_UDP_RECV); 185 ar->ar_cond = ASR_WANT_READ; 186 ar->ar_fd = as->as_fd; 187 ar->ar_timeout = as->as_timeout; 188 return (ASYNC_COND); 189 break; 190 191 case ASR_STATE_UDP_RECV: 192 193 if (udp_recv(as) == -1) { 194 if (errno == ENOMEM) { 195 ar->ar_errno = errno; 196 async_set_state(as, ASR_STATE_HALT); 197 break; 198 } 199 if (errno != EOVERFLOW) { 200 /* Fail or timeout */ 201 async_set_state(as, ASR_STATE_NEXT_NS); 202 break; 203 } 204 if (as->as_ctx->ac_options & RES_IGNTC) 205 async_set_state(as, ASR_STATE_PACKET); 206 else 207 async_set_state(as, ASR_STATE_TCP_WRITE); 208 } else 209 async_set_state(as, ASR_STATE_PACKET); 210 break; 211 212 case ASR_STATE_TCP_WRITE: 213 214 switch (tcp_write(as)) { 215 case -1: /* fail or timeout */ 216 async_set_state(as, ASR_STATE_NEXT_NS); 217 break; 218 case 0: 219 async_set_state(as, ASR_STATE_TCP_READ); 220 ar->ar_cond = ASR_WANT_READ; 221 ar->ar_fd = as->as_fd; 222 ar->ar_timeout = as->as_timeout; 223 return (ASYNC_COND); 224 case 1: 225 ar->ar_cond = ASR_WANT_WRITE; 226 ar->ar_fd = as->as_fd; 227 ar->ar_timeout = as->as_timeout; 228 return (ASYNC_COND); 229 } 230 break; 231 232 case ASR_STATE_TCP_READ: 233 234 switch (tcp_read(as)) { 235 case -1: /* Fail or timeout */ 236 if (errno == ENOMEM) { 237 ar->ar_errno = errno; 238 async_set_state(as, ASR_STATE_HALT); 239 } else 240 async_set_state(as, ASR_STATE_NEXT_NS); 241 break; 242 case 0: 243 async_set_state(as, ASR_STATE_PACKET); 244 break; 245 case 1: 246 ar->ar_cond = ASR_WANT_READ; 247 ar->ar_fd = as->as_fd; 248 ar->ar_timeout = as->as_timeout; 249 return (ASYNC_COND); 250 } 251 break; 252 253 case ASR_STATE_PACKET: 254 255 memmove(&ar->ar_ns, AS_NS_SA(as), AS_NS_SA(as)->sa_len); 256 ar->ar_datalen = as->as.dns.ibuflen; 257 ar->ar_data = as->as.dns.ibuf; 258 as->as.dns.ibuf = NULL; 259 ar->ar_errno = 0; 260 ar->ar_rcode = as->as.dns.rcode; 261 async_set_state(as, ASR_STATE_HALT); 262 break; 263 264 case ASR_STATE_HALT: 265 266 if (ar->ar_errno) { 267 ar->ar_h_errno = TRY_AGAIN; 268 ar->ar_count = 0; 269 ar->ar_datalen = -1; 270 ar->ar_data = NULL; 271 } else if (as->as.dns.ancount) { 272 ar->ar_h_errno = NETDB_SUCCESS; 273 ar->ar_count = as->as.dns.ancount; 274 } else { 275 ar->ar_count = 0; 276 switch (as->as.dns.rcode) { 277 case NXDOMAIN: 278 ar->ar_h_errno = HOST_NOT_FOUND; 279 break; 280 case SERVFAIL: 281 ar->ar_h_errno = TRY_AGAIN; 282 break; 283 case NOERROR: 284 ar->ar_h_errno = NO_DATA; 285 break; 286 default: 287 ar->ar_h_errno = NO_RECOVERY; 288 } 289 } 290 return (ASYNC_DONE); 291 292 default: 293 294 ar->ar_errno = EOPNOTSUPP; 295 ar->ar_h_errno = NETDB_INTERNAL; 296 async_set_state(as, ASR_STATE_HALT); 297 break; 298 } 299 goto next; 300 } 301 302 static int 303 sockaddr_connect(const struct sockaddr *sa, int socktype) 304 { 305 int errno_save, sock; 306 307 if ((sock = socket(sa->sa_family, socktype | SOCK_NONBLOCK, 0)) == -1) 308 goto fail; 309 310 if (connect(sock, sa, sa->sa_len) == -1) { 311 /* 312 * In the TCP case, the caller will be asked to poll for 313 * POLLOUT so that we start writing the packet in tcp_write() 314 * when the connection is established, or fail there on error. 315 */ 316 if (errno == EINPROGRESS) 317 return (sock); 318 goto fail; 319 } 320 321 return (sock); 322 323 fail: 324 325 if (sock != -1) { 326 errno_save = errno; 327 close(sock); 328 errno = errno_save; 329 } 330 331 return (-1); 332 } 333 334 /* 335 * Prepare the DNS packet for the query type "type", class "class" and domain 336 * name created by the concatenation on "name" and "dom". 337 * Return 0 on success, set errno and return -1 on error. 338 */ 339 static int 340 setup_query(struct asr_query *as, const char *name, const char *dom, 341 int class, int type) 342 { 343 struct asr_pack p; 344 struct asr_dns_header h; 345 char fqdn[MAXDNAME]; 346 char dname[MAXDNAME]; 347 348 if (as->as.dns.flags & ASYNC_EXTOBUF) { 349 errno = EINVAL; 350 DPRINT("attempting to write in user packet"); 351 return (-1); 352 } 353 354 if (_asr_make_fqdn(name, dom, fqdn, sizeof(fqdn)) > sizeof(fqdn)) { 355 errno = EINVAL; 356 DPRINT("asr_make_fqdn: name too long\n"); 357 return (-1); 358 } 359 360 if (_asr_dname_from_fqdn(fqdn, dname, sizeof(dname)) == -1) { 361 errno = EINVAL; 362 DPRINT("asr_dname_from_fqdn: invalid\n"); 363 return (-1); 364 } 365 366 if (as->as.dns.obuf == NULL) { 367 as->as.dns.obufsize = PACKETSZ; 368 as->as.dns.obuf = malloc(as->as.dns.obufsize); 369 if (as->as.dns.obuf == NULL) 370 return (-1); /* errno set */ 371 } 372 as->as.dns.obuflen = 0; 373 374 memset(&h, 0, sizeof h); 375 h.id = res_randomid(); 376 if (as->as_ctx->ac_options & RES_RECURSE) 377 h.flags |= RD_MASK; 378 h.qdcount = 1; 379 380 _asr_pack_init(&p, as->as.dns.obuf, as->as.dns.obufsize); 381 _asr_pack_header(&p, &h); 382 _asr_pack_query(&p, type, class, dname); 383 if (p.err) { 384 DPRINT("error packing query"); 385 errno = EINVAL; 386 return (-1); 387 } 388 389 /* Remember the parameters. */ 390 as->as.dns.reqid = h.id; 391 as->as.dns.type = type; 392 as->as.dns.class = class; 393 if (as->as.dns.dname) 394 free(as->as.dns.dname); 395 as->as.dns.dname = strdup(dname); 396 if (as->as.dns.dname == NULL) { 397 DPRINT("strdup"); 398 return (-1); /* errno set */ 399 } 400 as->as.dns.obuflen = p.offset; 401 402 DPRINT_PACKET("asr_setup_query", as->as.dns.obuf, as->as.dns.obuflen); 403 404 return (0); 405 } 406 407 /* 408 * Create a connect UDP socket and send the output packet. 409 * 410 * Return 0 on success, or -1 on error (errno set). 411 */ 412 static int 413 udp_send(struct asr_query *as) 414 { 415 ssize_t n; 416 int save_errno; 417 #ifdef DEBUG 418 char buf[256]; 419 #endif 420 421 DPRINT("asr: [%p] connecting to %s UDP\n", as, 422 _asr_print_sockaddr(AS_NS_SA(as), buf, sizeof buf)); 423 424 as->as_fd = sockaddr_connect(AS_NS_SA(as), SOCK_DGRAM); 425 if (as->as_fd == -1) 426 return (-1); /* errno set */ 427 428 n = send(as->as_fd, as->as.dns.obuf, as->as.dns.obuflen, 0); 429 if (n == -1) { 430 save_errno = errno; 431 close(as->as_fd); 432 errno = save_errno; 433 as->as_fd = -1; 434 return (-1); 435 } 436 437 return (0); 438 } 439 440 /* 441 * Try to receive a valid packet from the current UDP socket. 442 * 443 * Return 0 if a full packet could be read, or -1 on error (errno set). 444 */ 445 static int 446 udp_recv(struct asr_query *as) 447 { 448 ssize_t n; 449 int save_errno; 450 451 if (ensure_ibuf(as, PACKETSZ) == -1) { 452 save_errno = errno; 453 close(as->as_fd); 454 errno = save_errno; 455 as->as_fd = -1; 456 return (-1); 457 } 458 459 n = recv(as->as_fd, as->as.dns.ibuf, as->as.dns.ibufsize, 0); 460 save_errno = errno; 461 close(as->as_fd); 462 errno = save_errno; 463 as->as_fd = -1; 464 if (n == -1) 465 return (-1); 466 467 as->as.dns.ibuflen = n; 468 469 DPRINT_PACKET("asr_udp_recv()", as->as.dns.ibuf, as->as.dns.ibuflen); 470 471 if (validate_packet(as) == -1) 472 return (-1); /* errno set */ 473 474 return (0); 475 } 476 477 /* 478 * Write the output packet to the TCP socket. 479 * 480 * Return 0 when all bytes have been sent, 1 there is no buffer space on the 481 * socket or it is not connected yet, or -1 on error (errno set). 482 */ 483 static int 484 tcp_write(struct asr_query *as) 485 { 486 struct msghdr msg; 487 struct iovec iov[2]; 488 uint16_t len; 489 ssize_t n; 490 size_t offset; 491 int i; 492 #ifdef DEBUG 493 char buf[256]; 494 #endif 495 496 /* First try to connect if not already */ 497 if (as->as_fd == -1) { 498 DPRINT("asr: [%p] connecting to %s TCP\n", as, 499 _asr_print_sockaddr(AS_NS_SA(as), buf, sizeof buf)); 500 as->as_fd = sockaddr_connect(AS_NS_SA(as), SOCK_STREAM); 501 if (as->as_fd == -1) 502 return (-1); /* errno set */ 503 as->as.dns.datalen = 0; /* bytes sent */ 504 return (1); 505 } 506 507 i = 0; 508 509 /* Prepend de packet length if not sent already. */ 510 if (as->as.dns.datalen < sizeof(len)) { 511 offset = 0; 512 len = htons(as->as.dns.obuflen); 513 iov[i].iov_base = (char *)(&len) + as->as.dns.datalen; 514 iov[i].iov_len = sizeof(len) - as->as.dns.datalen; 515 i++; 516 } else 517 offset = as->as.dns.datalen - sizeof(len); 518 519 iov[i].iov_base = as->as.dns.obuf + offset; 520 iov[i].iov_len = as->as.dns.obuflen - offset; 521 i++; 522 523 memset(&msg, 0, sizeof msg); 524 msg.msg_iov = iov; 525 msg.msg_iovlen = i; 526 527 send_again: 528 n = sendmsg(as->as_fd, &msg, MSG_NOSIGNAL); 529 if (n == -1) { 530 if (errno == EINTR) 531 goto send_again; 532 goto close; /* errno set */ 533 } 534 535 as->as.dns.datalen += n; 536 537 if (as->as.dns.datalen == as->as.dns.obuflen + sizeof(len)) { 538 /* All sent. Prepare for TCP read */ 539 as->as.dns.datalen = 0; 540 return (0); 541 } 542 543 /* More data to write */ 544 return (1); 545 546 close: 547 close(as->as_fd); 548 as->as_fd = -1; 549 return (-1); 550 } 551 552 /* 553 * Try to read a valid packet from the current TCP socket. 554 * 555 * Return 0 if a full packet could be read, 1 if more data is needed and the 556 * socket must be read again, or -1 on error (errno set). 557 */ 558 static int 559 tcp_read(struct asr_query *as) 560 { 561 ssize_t n; 562 size_t offset, len; 563 char *pos; 564 int save_errno, nfds; 565 struct pollfd pfd; 566 567 /* We must read the packet len first */ 568 if (as->as.dns.datalen < sizeof(as->as.dns.pktlen)) { 569 570 pos = (char *)(&as->as.dns.pktlen) + as->as.dns.datalen; 571 len = sizeof(as->as.dns.pktlen) - as->as.dns.datalen; 572 573 n = read(as->as_fd, pos, len); 574 if (n == -1) 575 goto close; /* errno set */ 576 577 as->as.dns.datalen += n; 578 if (as->as.dns.datalen < sizeof(as->as.dns.pktlen)) 579 return (1); /* need more data */ 580 581 as->as.dns.ibuflen = ntohs(as->as.dns.pktlen); 582 if (ensure_ibuf(as, as->as.dns.ibuflen) == -1) 583 goto close; /* errno set */ 584 585 pfd.fd = as->as_fd; 586 pfd.events = POLLIN; 587 poll_again: 588 nfds = poll(&pfd, 1, 0); 589 if (nfds == -1) { 590 if (errno == EINTR) 591 goto poll_again; 592 goto close; /* errno set */ 593 } 594 if (nfds == 0) 595 return (1); /* no more data available */ 596 } 597 598 offset = as->as.dns.datalen - sizeof(as->as.dns.pktlen); 599 pos = as->as.dns.ibuf + offset; 600 len = as->as.dns.ibuflen - offset; 601 602 read_again: 603 n = read(as->as_fd, pos, len); 604 if (n == -1) { 605 if (errno == EINTR) 606 goto read_again; 607 goto close; /* errno set */ 608 } 609 if (n == 0) { 610 errno = ECONNRESET; 611 goto close; 612 } 613 as->as.dns.datalen += n; 614 615 /* See if we got all the advertised bytes. */ 616 if (as->as.dns.datalen != as->as.dns.ibuflen + sizeof(as->as.dns.pktlen)) 617 return (1); 618 619 DPRINT_PACKET("asr_tcp_read()", as->as.dns.ibuf, as->as.dns.ibuflen); 620 621 if (validate_packet(as) == -1) 622 goto close; /* errno set */ 623 624 errno = 0; 625 close: 626 save_errno = errno; 627 close(as->as_fd); 628 errno = save_errno; 629 as->as_fd = -1; 630 return (errno ? -1 : 0); 631 } 632 633 /* 634 * Make sure the input buffer is at least "n" bytes long, and allocate or 635 * extend it if necessary. Return 0 on success, or set errno and return -1. 636 */ 637 static int 638 ensure_ibuf(struct asr_query *as, size_t n) 639 { 640 char *t; 641 642 if (as->as.dns.ibuf == NULL) { 643 as->as.dns.ibuf = malloc(n); 644 if (as->as.dns.ibuf == NULL) 645 return (-1); /* errno set */ 646 as->as.dns.ibufsize = n; 647 return (0); 648 } 649 650 if (as->as.dns.ibufsize >= n) 651 return (0); 652 653 t = realloc(as->as.dns.ibuf, n); 654 if (t == NULL) 655 return (-1); /* errno set */ 656 as->as.dns.ibuf = t; 657 as->as.dns.ibufsize = n; 658 659 return (0); 660 } 661 662 /* 663 * Check if the received packet is valid. 664 * Return 0 on success, or set errno and return -1. 665 */ 666 static int 667 validate_packet(struct asr_query *as) 668 { 669 struct asr_unpack p; 670 struct asr_dns_header h; 671 struct asr_dns_query q; 672 struct asr_dns_rr rr; 673 int r; 674 675 _asr_unpack_init(&p, as->as.dns.ibuf, as->as.dns.ibuflen); 676 677 _asr_unpack_header(&p, &h); 678 if (p.err) 679 goto inval; 680 681 if (h.id != as->as.dns.reqid) { 682 DPRINT("incorrect reqid\n"); 683 goto inval; 684 } 685 if (h.qdcount != 1) 686 goto inval; 687 /* Should be zero, we could allow this */ 688 if ((h.flags & Z_MASK) != 0) 689 goto inval; 690 /* Actually, it depends on the request but we only use OP_QUERY */ 691 if (OPCODE(h.flags) != OP_QUERY) 692 goto inval; 693 /* Must be a response */ 694 if ((h.flags & QR_MASK) == 0) 695 goto inval; 696 697 as->as.dns.rcode = RCODE(h.flags); 698 as->as.dns.ancount = h.ancount; 699 700 _asr_unpack_query(&p, &q); 701 if (p.err) 702 goto inval; 703 704 if (q.q_type != as->as.dns.type || 705 q.q_class != as->as.dns.class || 706 strcasecmp(q.q_dname, as->as.dns.dname)) { 707 DPRINT("incorrect type/class/dname '%s' != '%s'\n", 708 q.q_dname, as->as.dns.dname); 709 goto inval; 710 } 711 712 /* Check for truncation */ 713 if (h.flags & TC_MASK) { 714 errno = EOVERFLOW; 715 return (-1); 716 } 717 718 /* Validate the rest of the packet */ 719 for (r = h.ancount + h.nscount + h.arcount; r; r--) 720 _asr_unpack_rr(&p, &rr); 721 722 if (p.err || (p.offset != as->as.dns.ibuflen)) 723 goto inval; 724 725 return (0); 726 727 inval: 728 errno = EINVAL; 729 return (-1); 730 } 731 732 /* 733 * Set the async context nameserver index to the next nameserver, cycling 734 * over the list until the maximum retry counter is reached. Return 0 on 735 * success, or -1 if all nameservers were used. 736 */ 737 static int 738 iter_ns(struct asr_query *as) 739 { 740 for (;;) { 741 if (as->as.dns.nsloop >= as->as_ctx->ac_nsretries) 742 return (-1); 743 744 as->as.dns.nsidx += 1; 745 if (as->as.dns.nsidx <= as->as_ctx->ac_nscount) 746 break; 747 as->as.dns.nsidx = 0; 748 as->as.dns.nsloop++; 749 DPRINT("asr: iter_ns(): cycle %i\n", as->as.dns.nsloop); 750 } 751 752 as->as_timeout = 1000 * (as->as_ctx->ac_nstimeout << as->as.dns.nsloop); 753 if (as->as.dns.nsloop > 0) 754 as->as_timeout /= as->as_ctx->ac_nscount; 755 if (as->as_timeout < 1000) 756 as->as_timeout = 1000; 757 758 return (0); 759 } 760