From fd5a160a15c48a97f7fc755c1310f17c869f0233 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Fri, 10 Mar 2017 08:59:23 +0100 Subject: [PATCH] Don't cache hosts as services MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This was kind of abuse of struct cache_service and the tree storing all cached entries. Host isn't really a service, treating it so required extra checks whenever dealing with cached entries. Now we converted all code to read DNS records A and AAAA directly we don't need to store these faked services. Signed-off-by: Rafał Miłecki --- cache.c | 7 ++----- cache.h | 3 --- ubus.c | 3 +-- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/cache.c b/cache.c index 08f6308..0e92137 100644 --- a/cache.c +++ b/cache.c @@ -101,8 +101,6 @@ cache_gc_timer(struct uloop_timeout *timeout) continue; } s->refresh += 50; - if (cache_service_is_host(s)) - continue; dns_send_question(s->iface, s->entry, TYPE_PTR, 0); } @@ -276,7 +274,8 @@ cache_answer(struct interface *iface, uint8_t *base, int blen, char *name, struc nlen + 1 < rdlength && !strcmp(rdata_buffer + rdlength - nlen, name)) host_len = rdlength - nlen - 1; - cache_service(iface, rdata_buffer, host_len, a->ttl); + if (name[0] == '_') + cache_service(iface, rdata_buffer, host_len, a->ttl); dlen = strlen(rdata_buffer) + 1; rdata = (uint8_t*)rdata_buffer; @@ -317,14 +316,12 @@ cache_answer(struct interface *iface, uint8_t *base, int blen, char *name, struc break; case TYPE_A: - cache_service(iface, name, strlen(name), a->ttl); if (a->rdlength != 4) return; dlen = 4; break; case TYPE_AAAA: - cache_service(iface, name, strlen(name), a->ttl); if (a->rdlength != 16) return; dlen = 16; diff --git a/cache.h b/cache.h index 1315aad..10859a5 100644 --- a/cache.h +++ b/cache.h @@ -56,9 +56,6 @@ void cache_cleanup(struct interface *iface); void cache_answer(struct interface *iface, uint8_t *base, int blen, char *name, struct dns_answer *a, uint8_t *rdata, int flush); int cache_host_is_known(char *record); -static inline bool cache_service_is_host(struct cache_service *s) { - return *((char *)s->avl.key) != '_'; -} void cache_dump_records(struct blob_buf *buf, const char *name); void cache_dump_recursive(struct blob_buf *b, const char *name, uint16_t type, struct interface *iface); diff --git a/ubus.c b/ubus.c index cf2c05b..0cfd18f 100644 --- a/ubus.c +++ b/ubus.c @@ -59,8 +59,7 @@ umdns_browse(struct ubus_context *ctx, struct ubus_object *obj, blob_buf_init(&b, 0); avl_for_each_element(&services, s, avl) { char *local; - if (cache_service_is_host(s)) - continue; + snprintf(buffer, MAX_NAME_LEN, "%s", (const char *) s->avl.key); local = strstr(buffer, ".local"); if (local) -- 2.30.2