From: Rafał Miłecki Date: Fri, 10 Mar 2017 07:59:21 +0000 (+0100) Subject: Access cached records (instead of services) to read list of hosts X-Git-Url: http://git.openwrt.org/?p=project%2Fmdnsd.git;a=commitdiff_plain;h=65151014cf120bdd53acee9e9b9bf97ccd49efbf Access cached records (instead of services) to read list of hosts 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 --- 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);