Don't cache hosts as services
authorRafał Miłecki <rafal@milecki.pl>
Fri, 10 Mar 2017 07:59:23 +0000 (08:59 +0100)
committerRafał Miłecki <rafal@milecki.pl>
Tue, 14 Mar 2017 10:45:44 +0000 (11:45 +0100)
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 <rafal@milecki.pl>
cache.c
cache.h
ubus.c

diff --git a/cache.c b/cache.c
index 08f6308dc6fa6e6d5ba30b409cd08b06df152370..0e92137b391a2ea37f1e5716c1683d75aeaa68ba 100644 (file)
--- 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 1315aad130827f19b3aef37590a81ac04cdf91a2..10859a593a735611aac72ec5c9035075bb2d1024 100644 (file)
--- 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 cf2c05ba5856c413639318353e26e9f0dd27af1e..0cfd18f4ce783ff3489bcc6d3f13e987a2dd6011 100644 (file)
--- 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)