diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2013-11-20 22:35:52 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2013-11-20 22:35:52 +0100 |
commit | 2cc152f9e1c7435ff0a5bcc7c4467249afe227e9 (patch) | |
tree | 000c74a760717218dacbb0df503faf68b9b1d8cb /sys/src/cmd/ndb/dn.c | |
parent | 9155b30f6d436d2197dcad2e75dac6de146f9499 (diff) |
ndb/dns: filter dns answers avoiding cache poisoning
only cache what we asked for or need to resolve the
query. filter out everything else.
Diffstat (limited to 'sys/src/cmd/ndb/dn.c')
-rw-r--r-- | sys/src/cmd/ndb/dn.c | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/sys/src/cmd/ndb/dn.c b/sys/src/cmd/ndb/dn.c index fcf262259..0628f8ee5 100644 --- a/sys/src/cmd/ndb/dn.c +++ b/sys/src/cmd/ndb/dn.c @@ -1085,54 +1085,69 @@ rrcat(RR **start, RR *rp) return *start; } -/* - * remove negative cache rr's from an rr list - */ RR* -rrremneg(RR **l) +rrremfilter(RR **l, int (*filter)(RR*, void*), void *arg) { - RR **nl, *rp; - RR *first; + RR *first, *rp; + RR **nl; first = nil; nl = &first; while(*l != nil){ rp = *l; - if(rp->negative){ + if((*filter)(rp, arg)){ *l = rp->next; *nl = rp; nl = &rp->next; *nl = nil; } else - l = &rp->next; + l = &(*l)->next; } return first; } +static int +filterneg(RR *rp, void*) +{ + return rp->negative; +} +static int +filtertype(RR *rp, void *arg) +{ + return rp->type == *((int*)arg); +} +static int +filterowner(RR *rp, void *arg) +{ + return rp->owner == (DN*)arg; +} + +/* + * remove negative cache rr's from an rr list + */ +RR* +rrremneg(RR **l) +{ + return rrremfilter(l, filterneg, nil); +} + /* * remove rr's of a particular type from an rr list */ RR* rrremtype(RR **l, int type) { - RR *first, *rp; - RR **nl; - - first = nil; - nl = &first; - while(*l != nil){ - rp = *l; - if(rp->type == type){ - *l = rp->next; - *nl = rp; - nl = &rp->next; - *nl = nil; - } else - l = &(*l)->next; - } + return rrremfilter(l, filtertype, &type); +} - return first; +/* + * remove rr's of a particular owner from an rr list + */ +RR* +rrremowner(RR **l, DN *owner) +{ + return rrremfilter(l, filterowner, owner); } static char * |