summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Fietkau2023-10-18 13:28:59 +0000
committerFelix Fietkau2023-10-18 13:29:01 +0000
commit26c97a5a50bf914eb8551685b9c0d4e52d9a168b (patch)
treeae32044150f9bc511bdf07394b5b0157ecd79119
parent479c7f8676d9cb6543ef516dc82cc53ed11b1142 (diff)
downloadmdnsd-26c97a5a50bf914eb8551685b9c0d4e52d9a168b.tar.gz
ubus: add a browse flag for suppressing cached ip addresses
Reduces the response size when they are not needed, or queried separately Signed-off-by: Felix Fietkau <nbd@nbd.name>
-rw-r--r--ubus.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/ubus.c b/ubus.c
index b9ed695..8d10eca 100644
--- a/ubus.c
+++ b/ubus.c
@@ -50,12 +50,14 @@ umdns_update(struct ubus_context *ctx, struct ubus_object *obj,
enum {
BROWSE_SERVICE,
BROWSE_ARRAY,
+ BROWSE_ADDRESS,
BROWSE_MAX
};
static const struct blobmsg_policy browse_policy[] = {
[BROWSE_SERVICE] = { "service", BLOBMSG_TYPE_STRING },
[BROWSE_ARRAY] = { "array", BLOBMSG_TYPE_BOOL },
+ [BROWSE_ADDRESS] = { "address", BLOBMSG_TYPE_BOOL },
};
static int
@@ -69,12 +71,15 @@ umdns_browse(struct ubus_context *ctx, struct ubus_object *obj,
void *c1 = NULL, *c2;
char *service = NULL;
int array = 0;
+ bool address = true;
blobmsg_parse(browse_policy, BROWSE_MAX, data, blob_data(msg), blob_len(msg));
if (data[BROWSE_SERVICE])
service = blobmsg_get_string(data[BROWSE_SERVICE]);
if (data[BROWSE_ARRAY])
array = blobmsg_get_u8(data[BROWSE_ARRAY]);
+ if (data[BROWSE_ADDRESS])
+ address = blobmsg_get_bool(data[BROWSE_ADDRESS]);
blob_buf_init(&b, 0);
avl_for_each_element(&services, s, avl) {
@@ -98,7 +103,8 @@ umdns_browse(struct ubus_context *ctx, struct ubus_object *obj,
c2 = blobmsg_open_table(&b, buffer);
strncat(buffer, ".local", MAX_NAME_LEN);
blobmsg_add_string(&b, "iface", s->iface->name);
- cache_dump_records(&b, buffer, array);
+ if (address)
+ cache_dump_records(&b, buffer, array);
cache_dump_records(&b, s->entry, array);
blobmsg_close_table(&b, c2);
q = avl_next_element(s, avl);