Klaus Demo nginx / 769eded
Resolver: implemented IPv6 name to address resolving. Ruslan Ermilov 8 years ago
5 changed file(s) with 447 addition(s) and 77 deletion(s). Raw diff Collapse all Expand all
6969 static void ngx_resolver_process_response(ngx_resolver_t *r, u_char *buf,
7070 size_t n);
7171 static void ngx_resolver_process_a(ngx_resolver_t *r, u_char *buf, size_t n,
72 ngx_uint_t ident, ngx_uint_t code, ngx_uint_t nan, ngx_uint_t ans);
72 ngx_uint_t ident, ngx_uint_t code, ngx_uint_t qtype,
73 ngx_uint_t nan, ngx_uint_t ans);
7374 static void ngx_resolver_process_ptr(ngx_resolver_t *r, u_char *buf, size_t n,
7475 ngx_uint_t ident, ngx_uint_t code, ngx_uint_t nan);
7576 static ngx_resolver_node_t *ngx_resolver_lookup_name(ngx_resolver_t *r,
8788 static void ngx_resolver_free(ngx_resolver_t *r, void *p);
8889 static void ngx_resolver_free_locked(ngx_resolver_t *r, void *p);
8990 static void *ngx_resolver_dup(ngx_resolver_t *r, void *src, size_t size);
90 static ngx_addr_t *ngx_resolver_export(ngx_resolver_t *r, in_addr_t *src,
91 ngx_uint_t n, ngx_uint_t rotate);
91 static ngx_addr_t *ngx_resolver_export(ngx_resolver_t *r,
92 ngx_resolver_node_t *rn, ngx_uint_t rotate);
9293 static u_char *ngx_resolver_log_error(ngx_log_t *log, u_char *buf, size_t len);
9394
9495 #if (NGX_HAVE_INET6)
434435 }
435436
436437
437 /* NGX_RESOLVE_A only */
438
439438 static ngx_int_t
440439 ngx_resolve_name_locked(ngx_resolver_t *r, ngx_resolver_ctx_t *ctx)
441440 {
462461
463462 ngx_queue_insert_head(&r->name_expire_queue, &rn->queue);
464463
465 naddrs = rn->naddrs;
464 naddrs = (rn->naddrs == (u_short) -1) ? 0 : rn->naddrs;
465 #if (NGX_HAVE_INET6)
466 naddrs += (rn->naddrs6 == (u_short) -1) ? 0 : rn->naddrs6;
467 #endif
466468
467469 if (naddrs) {
468470
469 /* NGX_RESOLVE_A answer */
470
471 if (naddrs == 1) {
471 if (naddrs == 1 && rn->naddrs == 1) {
472472 addrs = NULL;
473473
474474 } else {
475 addrs = ngx_resolver_export(r, rn->u.addrs, naddrs, 1);
475 addrs = ngx_resolver_export(r, rn, 1);
476476 if (addrs == NULL) {
477477 return NGX_ERROR;
478478 }
557557 if (rn->query) {
558558 ngx_resolver_free_locked(r, rn->query);
559559 rn->query = NULL;
560 #if (NGX_HAVE_INET6)
561 rn->query6 = NULL;
562 #endif
560563 }
561564
562565 if (rn->cnlen) {
563566 ngx_resolver_free_locked(r, rn->u.cname);
564567 }
565568
566 if (rn->naddrs > 1) {
569 if (rn->naddrs > 1 && rn->naddrs != (u_short) -1) {
567570 ngx_resolver_free_locked(r, rn->u.addrs);
568571 }
572
573 #if (NGX_HAVE_INET6)
574 if (rn->naddrs6 > 1 && rn->naddrs6 != (u_short) -1) {
575 ngx_resolver_free_locked(r, rn->u6.addrs6);
576 }
577 #endif
569578
570579 /* unlock alloc mutex */
571580
585594 rn->node.key = hash;
586595 rn->nlen = (u_short) ctx->name.len;
587596 rn->query = NULL;
597 #if (NGX_HAVE_INET6)
598 rn->query6 = NULL;
599 #endif
588600
589601 ngx_rbtree_insert(&r->name_rbtree, &rn->node);
590602 }
607619
608620 return NGX_OK;
609621 }
622
623 rn->naddrs = (u_short) -1;
624 #if (NGX_HAVE_INET6)
625 rn->naddrs6 = (u_short) -1;
626 #endif
610627
611628 if (ngx_resolver_send_query(r, rn) != NGX_OK) {
612629 goto failed;
634651
635652 ngx_queue_insert_head(&r->name_resend_queue, &rn->queue);
636653
654 rn->code = 0;
637655 rn->cnlen = 0;
638 rn->naddrs = 0;
639656 rn->valid = 0;
640657 rn->waiting = ctx;
641658
761778
762779 ngx_resolver_free(r, rn->query);
763780 rn->query = NULL;
781 #if (NGX_HAVE_INET6)
782 rn->query6 = NULL;
783 #endif
764784
765785 } else {
766786 rn = ngx_resolver_alloc(r, sizeof(ngx_resolver_node_t));
782802 }
783803
784804 rn->query = NULL;
805 #if (NGX_HAVE_INET6)
806 rn->query6 = NULL;
807 #endif
785808
786809 ngx_rbtree_insert(tree, &rn->node);
787810 }
789812 if (ngx_resolver_create_addr_query(rn, ctx) != NGX_OK) {
790813 goto failed;
791814 }
815
816 rn->naddrs = (u_short) -1;
817 #if (NGX_HAVE_INET6)
818 rn->naddrs6 = (u_short) -1;
819 #endif
792820
793821 if (ngx_resolver_send_query(r, rn) != NGX_OK) {
794822 goto failed;
814842
815843 ngx_queue_insert_head(resend_queue, &rn->queue);
816844
845 rn->code = 0;
817846 rn->cnlen = 0;
818 rn->naddrs = 0;
819847 rn->name = NULL;
820848 rn->nlen = 0;
821849 rn->valid = 0;
10221050 uc->connection->read->resolver = 1;
10231051 }
10241052
1025 n = ngx_send(uc->connection, rn->query, rn->qlen);
1026
1027 if (n == -1) {
1028 return NGX_ERROR;
1029 }
1030
1031 if ((size_t) n != (size_t) rn->qlen) {
1032 ngx_log_error(NGX_LOG_CRIT, &uc->log, 0, "send() incomplete");
1033 return NGX_ERROR;
1034 }
1053 if (rn->naddrs == (u_short) -1) {
1054 n = ngx_send(uc->connection, rn->query, rn->qlen);
1055
1056 if (n == -1) {
1057 return NGX_ERROR;
1058 }
1059
1060 if ((size_t) n != (size_t) rn->qlen) {
1061 ngx_log_error(NGX_LOG_CRIT, &uc->log, 0, "send() incomplete");
1062 return NGX_ERROR;
1063 }
1064 }
1065
1066 #if (NGX_HAVE_INET6)
1067 if (rn->query6 && rn->naddrs6 == (u_short) -1) {
1068 n = ngx_send(uc->connection, rn->query6, rn->qlen);
1069
1070 if (n == -1) {
1071 return NGX_ERROR;
1072 }
1073
1074 if ((size_t) n != (size_t) rn->qlen) {
1075 ngx_log_error(NGX_LOG_CRIT, &uc->log, 0, "send() incomplete");
1076 return NGX_ERROR;
1077 }
1078 }
1079 #endif
10351080
10361081 return NGX_OK;
10371082 }
11731218 char *err;
11741219 ngx_uint_t i, times, ident, qident, flags, code, nqs, nan,
11751220 qtype, qclass;
1221 #if (NGX_HAVE_INET6)
1222 ngx_uint_t qident6;
1223 #endif
11761224 ngx_queue_t *q;
11771225 ngx_resolver_qs_t *qs;
11781226 ngx_resolver_hdr_t *response;
12161264 qident = (rn->query[0] << 8) + rn->query[1];
12171265
12181266 if (qident == ident) {
1219 ngx_log_error(r->log_level, r->log, 0,
1220 "DNS error (%ui: %s), query id:%ui, name:\"%*s\"",
1221 code, ngx_resolver_strerror(code), ident,
1222 rn->nlen, rn->name);
1223 return;
1224 }
1267 goto dns_error_name;
1268 }
1269
1270 #if (NGX_HAVE_INET6)
1271 if (rn->query6) {
1272 qident6 = (rn->query6[0] << 8) + rn->query6[1];
1273
1274 if (qident6 == ident) {
1275 goto dns_error_name;
1276 }
1277 }
1278 #endif
12251279 }
12261280
12271281 goto dns_error;
12781332 switch (qtype) {
12791333
12801334 case NGX_RESOLVE_A:
1281
1282 ngx_resolver_process_a(r, buf, n, ident, code, nan,
1335 #if (NGX_HAVE_INET6)
1336 case NGX_RESOLVE_AAAA:
1337 #endif
1338
1339 ngx_resolver_process_a(r, buf, n, ident, code, qtype, nan,
12831340 i + sizeof(ngx_resolver_qs_t));
12841341
12851342 break;
13081365
13091366 return;
13101367
1368 dns_error_name:
1369
1370 ngx_log_error(r->log_level, r->log, 0,
1371 "DNS error (%ui: %s), query id:%ui, name:\"%*s\"",
1372 code, ngx_resolver_strerror(code), ident,
1373 rn->nlen, rn->name);
1374 return;
1375
13111376 dns_error:
13121377
13131378 ngx_log_error(r->log_level, r->log, 0,
13191384
13201385 static void
13211386 ngx_resolver_process_a(ngx_resolver_t *r, u_char *buf, size_t last,
1322 ngx_uint_t ident, ngx_uint_t code, ngx_uint_t nan, ngx_uint_t ans)
1387 ngx_uint_t ident, ngx_uint_t code, ngx_uint_t qtype,
1388 ngx_uint_t nan, ngx_uint_t ans)
13231389 {
13241390 char *err;
13251391 u_char *cname;
13301396 ngx_str_t name;
13311397 ngx_addr_t *addrs;
13321398 ngx_uint_t type, class, qident, naddrs, a, i, n, start;
1399 #if (NGX_HAVE_INET6)
1400 struct in6_addr *addr6;
1401 #endif
13331402 ngx_resolver_an_t *an;
13341403 ngx_resolver_ctx_t *ctx, *next;
13351404 ngx_resolver_node_t *rn;
13491418
13501419 rn = ngx_resolver_lookup_name(r, &name, hash);
13511420
1352 if (rn == NULL || rn->query == NULL) {
1421 if (rn == NULL) {
13531422 ngx_log_error(r->log_level, r->log, 0,
13541423 "unexpected response for %V", &name);
13551424 ngx_resolver_free(r, name.data);
13561425 goto failed;
13571426 }
13581427
1359 qident = (rn->query[0] << 8) + rn->query[1];
1428 switch (qtype) {
1429
1430 #if (NGX_HAVE_INET6)
1431 case NGX_RESOLVE_AAAA:
1432
1433 if (rn->query6 == NULL || rn->naddrs6 != (u_short) -1) {
1434 ngx_log_error(r->log_level, r->log, 0,
1435 "unexpected response for %V", &name);
1436 ngx_resolver_free(r, name.data);
1437 goto failed;
1438 }
1439
1440 rn->naddrs6 = 0;
1441 qident = (rn->query6[0] << 8) + rn->query6[1];
1442
1443 break;
1444 #endif
1445
1446 default: /* NGX_RESOLVE_A */
1447
1448 if (rn->query == NULL || rn->naddrs != (u_short) -1) {
1449 ngx_log_error(r->log_level, r->log, 0,
1450 "unexpected response for %V", &name);
1451 ngx_resolver_free(r, name.data);
1452 goto failed;
1453 }
1454
1455 rn->naddrs = 0;
1456 qident = (rn->query[0] << 8) + rn->query[1];
1457 }
13601458
13611459 if (ident != qident) {
13621460 ngx_log_error(r->log_level, r->log, 0,
13681466
13691467 ngx_resolver_free(r, name.data);
13701468
1469 if (code == 0 && rn->code) {
1470 code = rn->code;
1471 }
1472
13711473 if (code == 0 && nan == 0) {
1474
1475 #if (NGX_HAVE_INET6)
1476 switch (qtype) {
1477
1478 case NGX_RESOLVE_AAAA:
1479
1480 if (rn->naddrs == (u_short) -1) {
1481 goto next;
1482 }
1483
1484 if (rn->naddrs) {
1485 goto export;
1486 }
1487
1488 break;
1489
1490 default: /* NGX_RESOLVE_A */
1491
1492 if (rn->naddrs6 == (u_short) -1) {
1493 goto next;
1494 }
1495
1496 if (rn->naddrs6) {
1497 goto export;
1498 }
1499 }
1500 #endif
1501
13721502 code = NGX_RESOLVE_NXDOMAIN;
13731503 }
13741504
13751505 if (code) {
1506
1507 #if (NGX_HAVE_INET6)
1508 switch (qtype) {
1509
1510 case NGX_RESOLVE_AAAA:
1511
1512 if (rn->naddrs == (u_short) -1) {
1513 rn->code = (u_char) code;
1514 goto next;
1515 }
1516
1517 break;
1518
1519 default: /* NGX_RESOLVE_A */
1520
1521 if (rn->naddrs6 == (u_short) -1) {
1522 rn->code = (u_char) code;
1523 goto next;
1524 }
1525 }
1526 #endif
1527
13761528 next = rn->waiting;
13771529 rn->waiting = NULL;
13781530
14581610
14591611 case NGX_RESOLVE_A:
14601612
1613 if (qtype != NGX_RESOLVE_A) {
1614 err = "unexpected A record in DNS response";
1615 goto invalid;
1616 }
1617
14611618 if (len != 4) {
14621619 err = "invalid A record in DNS response";
14631620 goto invalid;
14711628
14721629 break;
14731630
1631 #if (NGX_HAVE_INET6)
1632 case NGX_RESOLVE_AAAA:
1633
1634 if (qtype != NGX_RESOLVE_AAAA) {
1635 err = "unexpected AAAA record in DNS response";
1636 goto invalid;
1637 }
1638
1639 if (len != 16) {
1640 err = "invalid AAAA record in DNS response";
1641 goto invalid;
1642 }
1643
1644 if (i + 16 > last) {
1645 goto short_response;
1646 }
1647
1648 naddrs++;
1649
1650 break;
1651 #endif
1652
14741653 case NGX_RESOLVE_CNAME:
14751654
14761655 cname = &buf[i];
14961675
14971676 if (naddrs) {
14981677
1499 if (naddrs == 1) {
1500 addr = &rn->u.addr;
1501 rn->naddrs = 1;
1502
1503 } else {
1504 addr = ngx_resolver_alloc(r, naddrs * sizeof(in_addr_t));
1505 if (addr == NULL) {
1506 goto failed;
1507 }
1508
1509 rn->u.addrs = addr;
1510 rn->naddrs = (u_short) naddrs;
1511 }
1678 switch (qtype) {
1679
1680 #if (NGX_HAVE_INET6)
1681 case NGX_RESOLVE_AAAA:
1682
1683 if (naddrs == 1) {
1684 addr6 = &rn->u6.addr6;
1685 rn->naddrs6 = 1;
1686
1687 } else {
1688 addr6 = ngx_resolver_alloc(r, naddrs * sizeof(struct in6_addr));
1689 if (addr6 == NULL) {
1690 goto failed;
1691 }
1692
1693 rn->u6.addrs6 = addr6;
1694 rn->naddrs6 = (u_short) naddrs;
1695 }
1696
1697 #if (NGX_SUPPRESS_WARN)
1698 addr = NULL;
1699 #endif
1700
1701 break;
1702 #endif
1703
1704 default: /* NGX_RESOLVE_A */
1705
1706 if (naddrs == 1) {
1707 addr = &rn->u.addr;
1708 rn->naddrs = 1;
1709
1710 } else {
1711 addr = ngx_resolver_alloc(r, naddrs * sizeof(in_addr_t));
1712 if (addr == NULL) {
1713 goto failed;
1714 }
1715
1716 rn->u.addrs = addr;
1717 rn->naddrs = (u_short) naddrs;
1718 }
1719
1720 #if (NGX_HAVE_INET6 && NGX_SUPPRESS_WARN)
1721 addr6 = NULL;
1722 #endif
1723 }
1724
1725 rn->ttl = ttl;
15121726
15131727 n = 0;
15141728 i = ans;
15431757 + (buf[i + 2] << 8) + (buf[i + 3]));
15441758
15451759 if (++n == naddrs) {
1760
1761 #if (NGX_HAVE_INET6)
1762 if (rn->naddrs6 == (u_short) -1) {
1763 goto next;
1764 }
1765 #endif
1766
15461767 break;
15471768 }
15481769 }
15491770
1771 #if (NGX_HAVE_INET6)
1772 else if (type == NGX_RESOLVE_AAAA) {
1773
1774 ngx_memcpy(addr6[n].s6_addr, &buf[i], 16);
1775
1776 if (++n == naddrs) {
1777
1778 if (rn->naddrs == (u_short) -1) {
1779 goto next;
1780 }
1781
1782 break;
1783 }
1784 }
1785 #endif
1786
15501787 i += len;
15511788 }
1552
1553 if (naddrs == 1) {
1789 }
1790
1791 if (rn->naddrs != (u_short) -1
1792 #if (NGX_HAVE_INET6)
1793 && rn->naddrs6 != (u_short) -1
1794 #endif
1795 && rn->naddrs
1796 #if (NGX_HAVE_INET6)
1797 + rn->naddrs6
1798 #endif
1799 > 0)
1800 {
1801
1802 #if (NGX_HAVE_INET6)
1803 export:
1804 #endif
1805
1806 naddrs = rn->naddrs;
1807 #if (NGX_HAVE_INET6)
1808 naddrs += rn->naddrs6;
1809 #endif
1810
1811 if (naddrs == 1 && rn->naddrs == 1) {
15541812 addrs = NULL;
15551813
15561814 } else {
1557 addrs = ngx_resolver_export(r, rn->u.addrs, naddrs, 0);
1815 addrs = ngx_resolver_export(r, rn, 0);
15581816 if (addrs == NULL) {
15591817 goto failed;
15601818 }
15621820
15631821 ngx_queue_remove(&rn->queue);
15641822
1565 rn->valid = ngx_time() + (r->valid ? r->valid : ttl);
1823 rn->valid = ngx_time() + (r->valid ? r->valid : (time_t) rn->ttl);
15661824 rn->expire = ngx_time() + r->expire;
15671825
15681826 ngx_queue_insert_head(&r->name_expire_queue, &rn->queue);
16011859
16021860 ngx_resolver_free(r, rn->query);
16031861 rn->query = NULL;
1862 #if (NGX_HAVE_INET6)
1863 rn->query6 = NULL;
1864 #endif
16041865
16051866 return;
16061867 }
16081869 if (cname) {
16091870
16101871 /* CNAME only */
1872
1873 if (rn->naddrs == (u_short) -1
1874 #if (NGX_HAVE_INET6)
1875 || rn->naddrs6 == (u_short) -1
1876 #endif
1877 )
1878 {
1879 goto next;
1880 }
16111881
16121882 if (ngx_resolver_copy(r, &name, buf, cname, buf + last) != NGX_OK) {
16131883 goto failed;
16371907
16381908 ngx_resolver_free(r, rn->query);
16391909 rn->query = NULL;
1910 #if (NGX_HAVE_INET6)
1911 rn->query6 = NULL;
1912 #endif
16401913
16411914 /* unlock name mutex */
16421915
16601933 return;
16611934
16621935 failed:
1936
1937 next:
16631938
16641939 /* unlock name mutex */
16651940
21542429
21552430 len = sizeof(ngx_resolver_hdr_t) + nlen + sizeof(ngx_resolver_qs_t);
21562431
2432 #if (NGX_HAVE_INET6)
2433 p = ngx_resolver_alloc(ctx->resolver, len * 2);
2434 #else
21572435 p = ngx_resolver_alloc(ctx->resolver, len);
2436 #endif
21582437 if (p == NULL) {
21592438 return NGX_ERROR;
21602439 }
21622441 rn->qlen = (u_short) len;
21632442 rn->query = p;
21642443
2444 #if (NGX_HAVE_INET6)
2445 rn->query6 = p + len;
2446 #endif
2447
21652448 query = (ngx_resolver_hdr_t *) p;
21662449
21672450 ident = ngx_random();
21682451
21692452 ngx_log_debug2(NGX_LOG_DEBUG_CORE, ctx->resolver->log, 0,
2170 "resolve: \"%V\" %i", &ctx->name, ident & 0xffff);
2453 "resolve: \"%V\" A %i", &ctx->name, ident & 0xffff);
21712454
21722455 query->ident_hi = (u_char) ((ident >> 8) & 0xff);
21732456 query->ident_lo = (u_char) (ident & 0xff);
21862469 qs = (ngx_resolver_qs_t *) p;
21872470
21882471 /* query type */
2189 qs->type_hi = 0; qs->type_lo = (u_char) ctx->type;
2472 qs->type_hi = 0; qs->type_lo = NGX_RESOLVE_A;
21902473
21912474 /* IN query class */
21922475 qs->class_hi = 0; qs->class_lo = 1;
22232506 }
22242507
22252508 *p = (u_char) len;
2509
2510 #if (NGX_HAVE_INET6)
2511 p = rn->query6;
2512
2513 ngx_memcpy(p, rn->query, rn->qlen);
2514
2515 query = (ngx_resolver_hdr_t *) p;
2516
2517 ident = ngx_random();
2518
2519 ngx_log_debug2(NGX_LOG_DEBUG_CORE, ctx->resolver->log, 0,
2520 "resolve: \"%V\" AAAA %i", &ctx->name, ident & 0xffff);
2521
2522 query->ident_hi = (u_char) ((ident >> 8) & 0xff);
2523 query->ident_lo = (u_char) (ident & 0xff);
2524
2525 p += sizeof(ngx_resolver_hdr_t) + nlen;
2526
2527 qs = (ngx_resolver_qs_t *) p;
2528
2529 qs->type_lo = NGX_RESOLVE_AAAA;
2530 #endif
22262531
22272532 return NGX_OK;
22282533 }
24482753 ngx_resolver_free_locked(r, rn->u.cname);
24492754 }
24502755
2451 if (rn->naddrs > 1) {
2756 if (rn->naddrs > 1 && rn->naddrs != (u_short) -1) {
24522757 ngx_resolver_free_locked(r, rn->u.addrs);
24532758 }
2759
2760 #if (NGX_HAVE_INET6)
2761 if (rn->naddrs6 > 1 && rn->naddrs6 != (u_short) -1) {
2762 ngx_resolver_free_locked(r, rn->u6.addrs6);
2763 }
2764 #endif
24542765
24552766 ngx_resolver_free_locked(r, rn);
24562767
25242835
25252836
25262837 static ngx_addr_t *
2527 ngx_resolver_export(ngx_resolver_t *r, in_addr_t *src, ngx_uint_t n,
2838 ngx_resolver_export(ngx_resolver_t *r, ngx_resolver_node_t *rn,
25282839 ngx_uint_t rotate)
25292840 {
2530 ngx_addr_t *dst;
2531 ngx_uint_t i, j;
2532 struct sockaddr_in *sin;
2841 ngx_addr_t *dst;
2842 ngx_uint_t d, i, j, n;
2843 u_char (*sockaddr)[NGX_SOCKADDRLEN];
2844 in_addr_t *addr;
2845 struct sockaddr_in *sin;
2846 #if (NGX_HAVE_INET6)
2847 struct in6_addr *addr6;
2848 struct sockaddr_in6 *sin6;
2849 #endif
2850
2851 n = rn->naddrs;
2852 #if (NGX_HAVE_INET6)
2853 n += rn->naddrs6;
2854 #endif
25332855
25342856 dst = ngx_resolver_calloc(r, n * sizeof(ngx_addr_t));
25352857 if (dst == NULL) {
25362858 return NULL;
25372859 }
25382860
2539 sin = ngx_resolver_calloc(r, n * sizeof(struct sockaddr_in));
2540
2541 if (sin == NULL) {
2861 sockaddr = ngx_resolver_calloc(r, n * NGX_SOCKADDRLEN);
2862 if (sockaddr == NULL) {
25422863 ngx_resolver_free(r, dst);
25432864 return NULL;
25442865 }
25452866
2546 j = rotate ? ngx_random() % n : 0;
2547
2548 for (i = 0; i < n; i++) {
2549 dst[i].sockaddr = (struct sockaddr *) &sin[i];
2550 dst[i].socklen = sizeof(struct sockaddr_in);
2551 sin[i].sin_family = AF_INET;
2552 sin[i].sin_addr.s_addr = src[j++];
2553
2554 if (j == n) {
2555 j = 0;
2556 }
2557 }
2867 i = 0;
2868 d = rotate ? ngx_random() % n : 0;
2869
2870 if (rn->naddrs) {
2871 j = rotate ? ngx_random() % rn->naddrs : 0;
2872
2873 addr = (rn->naddrs == 1) ? &rn->u.addr : rn->u.addrs;
2874
2875 do {
2876 sin = (struct sockaddr_in *) sockaddr[d];
2877 sin->sin_family = AF_INET;
2878 sin->sin_addr.s_addr = addr[j++];
2879 dst[d].sockaddr = (struct sockaddr *) sin;
2880 dst[d++].socklen = sizeof(struct sockaddr_in);
2881
2882 if (d == n) {
2883 d = 0;
2884 }
2885
2886 if (j == rn->naddrs) {
2887 j = 0;
2888 }
2889 } while (++i < rn->naddrs);
2890 }
2891
2892 #if (NGX_HAVE_INET6)
2893 if (rn->naddrs6) {
2894 j = rotate ? ngx_random() % rn->naddrs6 : 0;
2895
2896 addr6 = (rn->naddrs6 == 1) ? &rn->u6.addr6 : rn->u6.addrs6;
2897
2898 do {
2899 sin6 = (struct sockaddr_in6 *) sockaddr[d];
2900 sin6->sin6_family = AF_INET6;
2901 ngx_memcpy(sin6->sin6_addr.s6_addr, addr6[j++].s6_addr, 16);
2902 dst[d].sockaddr = (struct sockaddr *) sin6;
2903 dst[d++].socklen = sizeof(struct sockaddr_in6);
2904
2905 if (d == n) {
2906 d = 0;
2907 }
2908
2909 if (j == rn->naddrs6) {
2910 j = 0;
2911 }
2912 } while (++i < n);
2913 }
2914 #endif
25582915
25592916 return dst;
25602917 }
1717 #define NGX_RESOLVE_PTR 12
1818 #define NGX_RESOLVE_MX 15
1919 #define NGX_RESOLVE_TXT 16
20 #if (NGX_HAVE_INET6)
21 #define NGX_RESOLVE_AAAA 28
22 #endif
2023 #define NGX_RESOLVE_DNAME 39
2124
2225 #define NGX_RESOLVE_FORMERR 1
6265 u_short qlen;
6366
6467 u_char *query;
68 #if (NGX_HAVE_INET6)
69 u_char *query6;
70 #endif
6571
6672 union {
6773 in_addr_t addr;
6975 u_char *cname;
7076 } u;
7177
78 u_char code;
7279 u_short naddrs;
7380 u_short cnlen;
7481
82 #if (NGX_HAVE_INET6)
83 union {
84 struct in6_addr addr6;
85 struct in6_addr *addrs6;
86 } u6;
87
88 u_short naddrs6;
89 #endif
90
7591 time_t expire;
7692 time_t valid;
93 uint32_t ttl;
7794
7895 ngx_resolver_ctx_t *waiting;
7996 } ngx_resolver_node_t;
128145 ngx_int_t ident;
129146
130147 ngx_int_t state;
131 ngx_int_t type;
132148 ngx_str_t name;
133149
134150 ngx_uint_t naddrs;
791791 }
792792
793793 resolve->name = ctx->host;
794 resolve->type = NGX_RESOLVE_A;
795794 resolve->handler = ngx_ssl_ocsp_resolve_handler;
796795 resolve->data = ctx;
797796 resolve->timeout = ctx->resolver_timeout;
643643 }
644644
645645 ctx->name = *host;
646 ctx->type = NGX_RESOLVE_A;
647646 ctx->handler = ngx_http_upstream_resolve_handler;
648647 ctx->data = r;
649648 ctx->timeout = clcf->resolver_timeout;
164164 }
165165
166166 ctx->name = s->host;
167 ctx->type = NGX_RESOLVE_A;
168167 ctx->handler = ngx_mail_smtp_resolve_name_handler;
169168 ctx->data = s;
170169 ctx->timeout = cscf->resolver_timeout;