--- deadwood-3.0.05/src/DwRecurse.c 2011-11-10 11:46:58.000000000 -0600 +++ deadwood-3.0.05-easydns-tarpit/src/DwRecurse.c 2011-11-13 02:19:40.760441959 -0600 @@ -2542,11 +2542,28 @@ return addr; } +/* Given a NS referral list and the NS record we want to look at, tell us + * what type of record it is */ +int dwx_nsref_type(int a, int *offset, dw_str *list) { + if(list == 0 || offset == 0) { + return -1; + } + + *offset = -1 * (2 + (a * 2)); + *offset = *offset - 1; + *offset = dw_fetch_u16(list, *offset); + if(*offset < 0 || *offset > list->len) { + return -1; + } + + return dw_fetch_u8(list,*offset); +} + /* Choose which upstream NS server we will contact. "b" is the connection * number; "count" is the number of upstream NS servers; we also point * to an active random number generator */ -int dwx_choose_ns(int b, int count, dwr_rg *rng) { - int out = 0; +int dwx_choose_ns(int b, int count, dwr_rg *rng, dw_str *list) { + int out = 0, offset = 0, a = 0, type = 0; if(count <= 1) { return 0; @@ -2569,7 +2586,17 @@ * {score++}; print a " " b }print score ":" prime}}}' */ if(rem[b].current_ns < 0) { - out = dwr_rng(rng) % count; + for(a = 0; a < 5; a++) { /* Favor glued records */ + out = dwr_rng(rng) % count; + type = dwx_nsref_type(out,&offset,list); + if(type == RR_A +#ifdef IPV6 + || type == RR_AAAA +#endif /* IPV6 */ + ) { + break; + } + } } else { out = rem[b].current_ns; out = (out + 173) % count; @@ -2603,15 +2630,9 @@ } /* Choose a RR at random */ - a = dwx_choose_ns(b, count, rng); - offset = -1 * (2 + (a * 2)); - offset--; - offset = dw_fetch_u16(list, offset); - if(offset < 0 || offset > list->len) { - goto catch_dwx_ns_getip; - } + a = dwx_choose_ns(b, count, rng, list); + rr = dwx_nsref_type(a, &offset, list); - rr = dw_fetch_u8(list,offset); if(rr == RR_A) { addr = dwx_ns_getip_ipv4(list,offset); #ifdef IPV6