[LEDE-DEV] [PATCH umdns 1/3] Access cached records (instead of services) to read list of hosts
Rafał Miłecki
zajec5 at gmail.com
Thu Mar 9 23:59:21 PST 2017
From: Rafał Miłecki <rafal at milecki.pl>
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 <rafal at milecki.pl>
---
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.11.0
More information about the Lede-dev
mailing list