From 5bdbcd785b0a08e866631a6a062ea9ced1f6dce8 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Thu, 4 Sep 2014 20:26:43 +0200 Subject: [PATCH] basic support for the cache flush bit Signed-off-by: John Crispin --- cache.c | 5 +---- cache.h | 2 +- dns.c | 5 ++++- dns.h | 1 + 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cache.c b/cache.c index 6240e2f..af6cbba 100644 --- a/cache.c +++ b/cache.c @@ -216,7 +216,7 @@ cache_host_is_known(char *record) } void -cache_answer(struct interface *iface, uint8_t *base, int blen, char *name, struct dns_answer *a, uint8_t *rdata) +cache_answer(struct interface *iface, uint8_t *base, int blen, char *name, struct dns_answer *a, uint8_t *rdata, int flush) { struct dns_srv_data *dsd = (struct dns_srv_data *) rdata; struct cache_record *r; @@ -227,9 +227,6 @@ cache_answer(struct interface *iface, uint8_t *base, int blen, char *name, struc int host_len = 0; static char *rdata_buffer = (char *) mdns_buf; - if (!(a->class & CLASS_IN)) - return; - nlen = strlen(name); switch (a->type) { diff --git a/cache.h b/cache.h index b4433eb..df3593f 100644 --- a/cache.h +++ b/cache.h @@ -48,7 +48,7 @@ int cache_init(void); void cache_scan(void); void cache_cleanup(void); void cache_answer(struct interface *iface, uint8_t *base, int blen, - char *name, struct dns_answer *a, uint8_t *rdata); + char *name, struct dns_answer *a, uint8_t *rdata, int flush); int cache_host_is_known(char *record); char *cache_lookup_name(const char *key); void cache_dump_records(struct blob_buf *buf, const char *name); diff --git a/dns.c b/dns.c index 3f6ecbe..c5323e5 100644 --- a/dns.c +++ b/dns.c @@ -299,6 +299,9 @@ parse_answer(struct interface *iface, uint8_t *buffer, int len, uint8_t **b, int return -1; } + if ((a->class & ~CLASS_FLUSH) != CLASS_IN) + return -1; + rdata = *b; if (a->rdlength > *rlen) { fprintf(stderr, "dropping: bad question\n"); @@ -309,7 +312,7 @@ parse_answer(struct interface *iface, uint8_t *buffer, int len, uint8_t **b, int *b += a->rdlength; if (cache) - cache_answer(iface, buffer, len, name, a, rdata); + cache_answer(iface, buffer, len, name, a, rdata, a->class & CLASS_FLUSH); return 0; } diff --git a/dns.h b/dns.h index 47727dd..791159f 100644 --- a/dns.h +++ b/dns.h @@ -33,6 +33,7 @@ #define MCAST_ADDR6 "ff02::fb" #define MCAST_PORT 5353 +#define CLASS_FLUSH 0x8000 #define CLASS_UNICAST 0x8000 #define CLASS_IN 0x0001 -- 2.11.0