Re: wildcard domain serving
Laurent Bercot <[email protected]> Sun, 18 Apr 2010 12:43:09 +0200
| Newsgroups | gmane.network.djbdns |
|---|---|
| Message-ID | <[email protected]> |
> can someone help djbize this? I'd like to get rid of stdio and inet and
> use djb's routines.. just don't know how :)
Here are a few ideas:
* replace strlen() with str_len() (there's no real point in this because
compilers optimize strlen() whereas they don't know str_len(), but if
you want code consistency, str_len() is what DJB uses, for some reason.
Maybe to avoid old problems with the string.h header dependency, or with
broken libcs. I'm not aware of any modern libc that fails to implement
strlen() properly, though.)
* Single Unix v3 doesn't know inet_aton(), only inet_ntoa() and inet_addr().
If what you want is scan IP addresses, here is how I think DJB would do it:
#include "ip4.h"
...
if (lame_a) {
char ip[4];
if (!ip4_scan(lame_a,ip)) return 0;
if (!response_rstart(q,DNS_T_A,3600)) return 0;
if (!response_addbytes(ip,4)) return 0;
}
...
* I couldn't find any stdio dependency in your patch. Nice. :)
* For TXT, you might want to return an error if strlen(lame_txt) is
greater than 256. Also, you could support several character-strings,
but as it has already been said, nobody uses this. Additionally,
it would require some parsing of lame_txt.
> i couldnt figure out how to make the MX answer buildable via the
> environment like i've done with A and TXT.
That requires parsing, because you have to specify both a preference
and a domain-name in a single environment variable.
Here is how you could do it, expecting a variable of the form
"preference:exchange" :
#include "uint16.h"
#include "scan.h"
...
if (lame_mx) {
unsigned long u;
unsigned int n = scan_ulong(lame_mx,&u);
char pack[2];
if (!n) return 0;
if (lame_mx[n] != ':') return 0;
if (u > 65535) return 0;
uint16_pack_big(pack,(uint16)u);
/* TODO: check and encode the domain at lame_mx+n+1 */
if (!response_rstart(q,DNS_T_MX,3600)) return 0;
if (!response_addbytes(pack,2)) return 0;
/* TODO: response_addname() the domain */
}
I didn't bother to code the domain encoding part, because it involves
dns_domain_fromdot(), which allocates memory and is in my opinion more
complex than is necessary. (I don't know what DJB was smoking when he
wrote his domain encoding/decoding functions, allocating dynamic memory
all over the place. I'm in the process of rewriting the whole DNS library
because I find DJB's APIs to be - for once - inconvenient and inefficient.)
But anyway, I think you're doing a lot of superfluous work. If you
want tinydns to answer *something* to lame queries, why not make an
empty response with a RCODE of 5 (refused), instead of making up
dummy RRs ?
--
Laurent