From cbf13a2a6da62b6ca817fdd7022eacd8d9efb40e Mon Sep 17 00:00:00 2001 From: Simon Kelley Date: Sat, 25 Jan 2014 17:59:14 +0000 Subject: [PATCH] Class specifier in --dnskey, instead of hardwiring C_IN. --- src/cache.c | 2 +- src/dns-protocol.h | 1 + src/dnsmasq.h | 2 +- src/option.c | 31 +++++++++++++++++++++++++------ 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/cache.c b/src/cache.c index d5e91b0..01fee3f 100644 --- a/src/cache.c +++ b/src/cache.c @@ -1003,7 +1003,7 @@ void cache_reload(void) cache->addr.key.algo = key->algo; cache->addr.key.flags = key->flags; cache->addr.key.keytag = dnskey_keytag(key->algo, key->flags, (unsigned char *)key->key, key->keylen); - cache->uid = C_IN; /* TODO - in option? */ + cache->uid = key->class; cache_hash(cache); } #endif diff --git a/src/dns-protocol.h b/src/dns-protocol.h index 6507642..a3ad14b 100644 --- a/src/dns-protocol.h +++ b/src/dns-protocol.h @@ -36,6 +36,7 @@ #define C_IN 1 /* the arpa internet */ #define C_CHAOS 3 /* for chaos net (MIT) */ +#define C_HESIOD 4 /* hesiod */ #define C_ANY 255 /* wildcard match */ #define T_A 1 diff --git a/src/dnsmasq.h b/src/dnsmasq.h index f919222..c5436f5 100644 --- a/src/dnsmasq.h +++ b/src/dnsmasq.h @@ -297,7 +297,7 @@ struct cname { struct dnskey { char *name, *key; - int keylen, algo, flags; + int keylen, class, algo, flags; struct dnskey *next; }; diff --git a/src/option.c b/src/option.c index 88a569d..22edeca 100644 --- a/src/option.c +++ b/src/option.c @@ -3682,13 +3682,32 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma { struct dnskey *new = opt_malloc(sizeof(struct dnskey)); char *key64, *algo; - - if (!(comma = split(arg)) || !(algo = split(comma)) || !(key64 = split(algo)) || - !atoi_check16(comma, &new->flags) || !atoi_check16(algo, &new->algo) || - !(new->name = canonicalise_opt(arg))) - ret_err(_("bad DNSKEY")); - + + new->class = C_IN; + if ((comma = split(arg)) && (algo = split(comma))) + { + int class = 0; + if (strcmp(comma, "IN") == 0) + class = C_IN; + else if (strcmp(comma, "CH") == 0) + class = C_CHAOS; + else if (strcmp(comma, "HS") == 0) + class = C_HESIOD; + + if (class != 0) + { + new->class = class; + comma = algo; + algo = split(comma); + } + } + + if (!comma || !algo || !(key64 = split(algo)) || + !atoi_check16(comma, &new->flags) || !atoi_check16(algo, &new->algo) || + !(new->name = canonicalise_opt(arg))) + ret_err(_("bad DNSKEY")); + /* Upper bound on length */ new->key = opt_malloc((3*strlen(key64)/4)+1); unhide_metas(key64);