Re: can anybody review my patchset?
Matthew Dempsky <[email protected]>
| Newsgroups | gmane.network.djbdns |
|---|---|
| Message-ID | <[email protected]> |
On Mon, Apr 20, 2009 at 12:29 AM, Andreas Schulze <[email protected]> wrote: > 9. own Patch: let tinydns rotate multiple MX records If anyone really needs this functionality, I've rewritten this patch below. However, I do not recommend this patch for general use. If you have more than 8 MX records for a single domain name, it can cause mail delivery failures. --- tdlookup.c.orig 2009-04-20 10:09:28.000000000 -0700 +++ tdlookup.c 2009-04-20 10:12:18.000000000 -0700 @@ -103,6 +103,14 @@ return response_addname(d1); } +static void swapnames(char **a,char **b) +{ + char *t; + t = *a; + *a = *b; + *b = t; +} + static int doit(char *q,char qtype[2]) { unsigned int bpos; @@ -121,6 +129,10 @@ char addr[8][4]; int addrnum; uint32 addrttl; + char mxdist[8][2]; + static char *mxname[8]; + int mxnum; + uint32 mxttl; int i; anpos = response_len; @@ -154,6 +166,7 @@ for (;;) { addrnum = 0; addrttl = 0; + mxnum = 0; cdb_findstart(&c); while (r = find(wild,wild != q)) { if (r == -1) return 0; @@ -171,14 +184,26 @@ if (addrnum < 1000000) ++addrnum; continue; } + if (byte_equal(type,2,DNS_T_MX)) { + dpos = dns_packet_copy(data,dlen,dpos,x,2); if (!dpos) return 0; + dpos = dns_packet_getname(data,dlen,dpos,&d1); if (!dpos) return 0; + mxttl = ttl; + i = dns_random(mxnum + 1); + if (i < 8) { + if ((i < mxnum) && (mxnum < 8)) { + byte_copy(mxdist[mxnum],2,mxdist[i]); + swapnames(&mxname[mxnum],&mxname[i]); + } + byte_copy(mxdist[i],2,x); + swapnames(&mxname[i],&d1); + } + if (mxnum < 1000000) ++mxnum; + continue; + } if (!response_rstart(q,type,ttl)) return 0; if (byte_equal(type,2,DNS_T_NS) || byte_equal(type,2,DNS_T_CNAME) || byte_equal(type,2,DNS_T_PTR)) { if (!doname()) return 0; } - else if (byte_equal(type,2,DNS_T_MX)) { - if (!dobytes(2)) return 0; - if (!doname()) return 0; - } else if (byte_equal(type,2,DNS_T_SOA)) { if (!doname()) return 0; if (!doname()) return 0; @@ -195,6 +220,13 @@ if (!response_addbytes(addr[i],4)) return 0; response_rfinish(RESPONSE_ANSWER); } + for (i = 0;i < mxnum;++i) + if (i < 8) { + if (!response_rstart(q,DNS_T_MX,mxttl)) return 0; + if (!response_addbytes(mxdist[i],2)) return 0; + if (!response_addname(mxname[i])) return 0; + response_rfinish(RESPONSE_ANSWER); + } if (flagfound) break; if (wild == control) break;