From 65151014cf120bdd53acee9e9b9bf97ccd49efbf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Fri, 10 Mar 2017 08:59:21 +0100 Subject: [PATCH] Access cached records (instead of services) to read list of hosts MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit We don't need to access hosts stored as services. It's enough to look for cached A and AAAA DNS records. Signed-off-by: Rafał Miłecki --- cache.c | 2 +- cache.h | 1 + ubus.c | 17 +++++++++++------ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/cache.c b/cache.c index 756ae68..3f3f617 100644 --- a/cache.c +++ b/cache.c @@ -42,7 +42,7 @@ static struct uloop_timeout cache_gc; struct avl_tree services; -static AVL_TREE(records, avl_strcmp, true, NULL); +AVL_TREE(records, avl_strcmp, true, NULL); static void cache_record_free(struct cache_record *r) diff --git a/cache.h b/cache.h index 7830b4f..cfd6368 100644 --- a/cache.h +++ b/cache.h @@ -47,6 +47,7 @@ struct cache_record { }; extern struct avl_tree services; +extern struct avl_tree records; int cache_init(void); void cache_update(void); diff --git a/ubus.c b/ubus.c index 4120fd5..cf2c05b 100644 --- a/ubus.c +++ b/ubus.c @@ -96,16 +96,21 @@ umdns_hosts(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - struct cache_service *s; + struct cache_record *prev = NULL; + struct cache_record *r; void *c; blob_buf_init(&b, 0); - avl_for_each_element(&services, s, avl) { - if (!cache_service_is_host(s)) + avl_for_each_element(&records, r, avl) { + if (r->type != TYPE_A && r->type != TYPE_AAAA) continue; - c = blobmsg_open_table(&b, s->entry); - cache_dump_records(&b, s->entry); - blobmsg_close_table(&b, c); + /* Query each domain just once */ + if (!prev || strcmp(r->record, prev->record)) { + c = blobmsg_open_table(&b, r->record); + cache_dump_records(&b, r->record); + blobmsg_close_table(&b, c); + } + prev = r; } ubus_send_reply(ctx, req, b.head); -- 2.25.1