summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2014-07-02 20:23:10 +0200
committerFelix Fietkau <nbd@openwrt.org>2014-07-02 20:23:10 +0200
commit94e7253a1166c1a03061c12e7e469433111f8f6f (patch)
treede45c7a58cdee021d6d9f4c3df5e32dfb3629524
parent203d616e3ce62d9d8cd3b2e11b8a757c97d7da0f (diff)
downloadfirewall3-94e7253a1166c1a03061c12e7e469433111f8f6f.tar.gz
ubus: add support for fetching firewall rules from procd
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
-rw-r--r--ubus.c39
1 files changed, 39 insertions, 0 deletions
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);
+ }
+ }
+ }
}