comparison src/core/ngx_resolver.c @ 6370:8c8739bdd3f1

Resolver: style. Renamed argument in ngx_resolver_process_a() for consistency.
author Ruslan Ermilov <ru@nginx.com>
date Thu, 17 Dec 2015 17:21:12 +0300
parents 06459bc8b92f
children 33c4d319f08f
comparison
equal deleted inserted replaced
6369:06459bc8b92f 6370:8c8739bdd3f1
1736 return; 1736 return;
1737 } 1737 }
1738 1738
1739 1739
1740 static void 1740 static void
1741 ngx_resolver_process_a(ngx_resolver_t *r, u_char *buf, size_t last, 1741 ngx_resolver_process_a(ngx_resolver_t *r, u_char *buf, size_t n,
1742 ngx_uint_t ident, ngx_uint_t code, ngx_uint_t qtype, 1742 ngx_uint_t ident, ngx_uint_t code, ngx_uint_t qtype,
1743 ngx_uint_t nan, ngx_uint_t trunc, ngx_uint_t ans) 1743 ngx_uint_t nan, ngx_uint_t trunc, ngx_uint_t ans)
1744 { 1744 {
1745 char *err; 1745 char *err;
1746 u_char *cname; 1746 u_char *cname;
1748 int32_t ttl; 1748 int32_t ttl;
1749 uint32_t hash; 1749 uint32_t hash;
1750 in_addr_t *addr; 1750 in_addr_t *addr;
1751 ngx_str_t name; 1751 ngx_str_t name;
1752 ngx_addr_t *addrs; 1752 ngx_addr_t *addrs;
1753 ngx_uint_t type, class, qident, naddrs, a, i, n, start; 1753 ngx_uint_t type, class, qident, naddrs, a, i, j, start;
1754 #if (NGX_HAVE_INET6) 1754 #if (NGX_HAVE_INET6)
1755 struct in6_addr *addr6; 1755 struct in6_addr *addr6;
1756 #endif 1756 #endif
1757 ngx_resolver_an_t *an; 1757 ngx_resolver_an_t *an;
1758 ngx_resolver_ctx_t *ctx, *next; 1758 ngx_resolver_ctx_t *ctx, *next;
1759 ngx_resolver_node_t *rn; 1759 ngx_resolver_node_t *rn;
1760 ngx_resolver_connection_t *rec; 1760 ngx_resolver_connection_t *rec;
1761 1761
1762 if (ngx_resolver_copy(r, &name, buf, 1762 if (ngx_resolver_copy(r, &name, buf,
1763 buf + sizeof(ngx_resolver_hdr_t), buf + last) 1763 buf + sizeof(ngx_resolver_hdr_t), buf + n)
1764 != NGX_OK) 1764 != NGX_OK)
1765 { 1765 {
1766 return; 1766 return;
1767 } 1767 }
1768 1768
1964 1964
1965 for (a = 0; a < nan; a++) { 1965 for (a = 0; a < nan; a++) {
1966 1966
1967 start = i; 1967 start = i;
1968 1968
1969 while (i < last) { 1969 while (i < n) {
1970 1970
1971 if (buf[i] & 0xc0) { 1971 if (buf[i] & 0xc0) {
1972 i += 2; 1972 i += 2;
1973 goto found; 1973 goto found;
1974 } 1974 }
1990 goto invalid; 1990 goto invalid;
1991 } 1991 }
1992 1992
1993 found: 1993 found:
1994 1994
1995 if (i + sizeof(ngx_resolver_an_t) >= last) { 1995 if (i + sizeof(ngx_resolver_an_t) >= n) {
1996 goto short_response; 1996 goto short_response;
1997 } 1997 }
1998 1998
1999 an = (ngx_resolver_an_t *) &buf[i]; 1999 an = (ngx_resolver_an_t *) &buf[i];
2000 2000
2030 if (len != 4) { 2030 if (len != 4) {
2031 err = "invalid A record in DNS response"; 2031 err = "invalid A record in DNS response";
2032 goto invalid; 2032 goto invalid;
2033 } 2033 }
2034 2034
2035 if (i + 4 > last) { 2035 if (i + 4 > n) {
2036 goto short_response; 2036 goto short_response;
2037 } 2037 }
2038 2038
2039 naddrs++; 2039 naddrs++;
2040 2040
2051 if (len != 16) { 2051 if (len != 16) {
2052 err = "invalid AAAA record in DNS response"; 2052 err = "invalid AAAA record in DNS response";
2053 goto invalid; 2053 goto invalid;
2054 } 2054 }
2055 2055
2056 if (i + 16 > last) { 2056 if (i + 16 > n) {
2057 goto short_response; 2057 goto short_response;
2058 } 2058 }
2059 2059
2060 naddrs++; 2060 naddrs++;
2061 2061
2132 #if (NGX_HAVE_INET6 && NGX_SUPPRESS_WARN) 2132 #if (NGX_HAVE_INET6 && NGX_SUPPRESS_WARN)
2133 addr6 = NULL; 2133 addr6 = NULL;
2134 #endif 2134 #endif
2135 } 2135 }
2136 2136
2137 n = 0; 2137 j = 0;
2138 i = ans; 2138 i = ans;
2139 2139
2140 for (a = 0; a < nan; a++) { 2140 for (a = 0; a < nan; a++) {
2141 2141
2142 for ( ;; ) { 2142 for ( ;; ) {
2161 2161
2162 i += sizeof(ngx_resolver_an_t); 2162 i += sizeof(ngx_resolver_an_t);
2163 2163
2164 if (type == NGX_RESOLVE_A) { 2164 if (type == NGX_RESOLVE_A) {
2165 2165
2166 addr[n] = htonl((buf[i] << 24) + (buf[i + 1] << 16) 2166 addr[j] = htonl((buf[i] << 24) + (buf[i + 1] << 16)
2167 + (buf[i + 2] << 8) + (buf[i + 3])); 2167 + (buf[i + 2] << 8) + (buf[i + 3]));
2168 2168
2169 if (++n == naddrs) { 2169 if (++j == naddrs) {
2170 2170
2171 #if (NGX_HAVE_INET6) 2171 #if (NGX_HAVE_INET6)
2172 if (rn->naddrs6 == (u_short) -1) { 2172 if (rn->naddrs6 == (u_short) -1) {
2173 goto next; 2173 goto next;
2174 } 2174 }
2179 } 2179 }
2180 2180
2181 #if (NGX_HAVE_INET6) 2181 #if (NGX_HAVE_INET6)
2182 else if (type == NGX_RESOLVE_AAAA) { 2182 else if (type == NGX_RESOLVE_AAAA) {
2183 2183
2184 ngx_memcpy(addr6[n].s6_addr, &buf[i], 16); 2184 ngx_memcpy(addr6[j].s6_addr, &buf[i], 16);
2185 2185
2186 if (++n == naddrs) { 2186 if (++j == naddrs) {
2187 2187
2188 if (rn->naddrs == (u_short) -1) { 2188 if (rn->naddrs == (u_short) -1) {
2189 goto next; 2189 goto next;
2190 } 2190 }
2191 2191
2306 ) 2306 )
2307 { 2307 {
2308 goto next; 2308 goto next;
2309 } 2309 }
2310 2310
2311 if (ngx_resolver_copy(r, &name, buf, cname, buf + last) != NGX_OK) { 2311 if (ngx_resolver_copy(r, &name, buf, cname, buf + n) != NGX_OK) {
2312 goto failed; 2312 goto failed;
2313 } 2313 }
2314 2314
2315 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, 2315 ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0,
2316 "resolver cname:\"%V\"", &name); 2316 "resolver cname:\"%V\"", &name);