From: Felix Fietkau Date: Wed, 2 Jul 2014 18:23:10 +0000 (+0200) Subject: ubus: add support for fetching firewall rules from procd X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=94e7253a1166c1a03061c12e7e469433111f8f6f;p=oweals%2Ffirewall3.git ubus: add support for fetching firewall rules from procd Signed-off-by: Felix Fietkau --- diff --git a/ubus.c b/ubus.c index 877104a..581f51c 100644 --- a/ubus.c +++ b/ubus.c @@ -19,6 +19,7 @@ #include "ubus.h" static struct blob_attr *interfaces = NULL; +static struct blob_attr *procd_data; static void dump_cb(struct ubus_request *req, int type, struct blob_attr *msg) @@ -31,12 +32,18 @@ static void dump_cb(struct ubus_request *req, int type, struct blob_attr *msg) interfaces = blob_memdup(cur); } +static void procd_data_cb(struct ubus_request *req, int type, struct blob_attr *msg) +{ + procd_data = blob_memdup(msg); +} + bool fw3_ubus_connect(void) { bool status = false; uint32_t id; struct ubus_context *ctx = ubus_connect(NULL); + struct blob_buf b = { }; if (!ctx) goto out; @@ -49,6 +56,14 @@ fw3_ubus_connect(void) status = true; + if (ubus_lookup_id(ctx, "service", &id)) + goto out; + + blob_buf_init(&b, 0); + blobmsg_add_string(&b, "type", "firewall"); + ubus_invoke(ctx, id, "get_data", b.head, procd_data_cb, NULL, 2000); + blob_buf_free(&b); + out: if (ctx) ubus_free(ctx); @@ -257,4 +272,28 @@ fw3_ubus_rules(struct blob_buf *b) } } } + + if (!procd_data) + return; + + /* service */ + blobmsg_for_each_attr(c, procd_data, r) { + if (!blobmsg_check_attr(c, true)) + continue; + + /* instance */ + blobmsg_for_each_attr(cur, c, rem) { + if (!blobmsg_check_attr(cur, true)) + continue; + + /* type */ + blobmsg_for_each_attr(dcur, cur, drem) { + if (!blobmsg_check_attr(dcur, true)) + continue; + + blobmsg_for_each_attr(rule, dcur, rrem) + blobmsg_add_blob(b, rule); + } + } + } }