Skip to content

Instantly share code, notes, and snippets.

@danny8376
Last active December 9, 2015 18:06
Show Gist options
  • Save danny8376/588965a1dd6b1d975745 to your computer and use it in GitHub Desktop.
Save danny8376/588965a1dd6b1d975745 to your computer and use it in GitHub Desktop.
nginx resolve ptr cname patch
--- src/core/ngx_resolver.c.orig 2015-04-21 22:11:59.000000000 +0800
+++ src/core/ngx_resolver.c 2015-12-10 01:13:54.230523751 +0800
@@ -2012,7 +2012,7 @@
int32_t ttl;
ngx_int_t octet;
ngx_str_t name;
- ngx_uint_t i, mask, qident, class;
+ ngx_uint_t i, mask, qident, type, class;
ngx_queue_t *expire_queue;
ngx_rbtree_t *tree;
ngx_resolver_an_t *an;
@@ -2176,9 +2176,14 @@
goto invalid;
}
+
+
an = (ngx_resolver_an_t *) &buf[i + 2];
+cname_continue:
+
class = (an->class_hi << 8) + an->class_lo;
+ type = (an->type_hi << 8) + an->type_lo;
len = (an->len_hi << 8) + an->len_lo;
ttl = (an->ttl[0] << 24) + (an->ttl[1] << 16)
+ (an->ttl[2] << 8) + (an->ttl[3]);
@@ -2193,6 +2198,34 @@
ttl = 0;
}
+ /* CNAME processing */
+ if (type == NGX_RESOLVE_CNAME) {
+ do {
+ if (buf[i] == 0xc0) {
+ i += 2;
+ break;
+ } else {
+ i += 1 + buf[i];
+ }
+ } while (buf[i] != 0);
+ an = (ngx_resolver_an_t *) &buf[i];
+ len = (an->len_hi << 8) + an->len_lo;
+ i += sizeof(ngx_resolver_an_t) + len;
+
+ ngx_uint_t nameidx = i;
+ do {
+ if (buf[nameidx] == 0xc0) {
+ nameidx += 2;
+ break;
+ } else {
+ nameidx += 1 + buf[nameidx];
+ }
+ } while (buf[nameidx] != 0);
+ an = (ngx_resolver_an_t *) &buf[nameidx];
+
+ goto cname_continue;
+ }
+
ngx_log_debug3(NGX_LOG_DEBUG_CORE, r->log, 0,
"resolver qt:%ui cl:%ui len:%uz",
(an->type_hi << 8) + an->type_lo,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment