diff options
author | Steven Barth <steven@midlink.org> | 2013-10-14 13:12:28 +0200 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2013-10-14 13:12:28 +0200 |
commit | 78c5e4b032c420852abc2a9e1e6f429a4d803c21 (patch) | |
tree | 76c0f1f4c08571516b70d7f5575f7cec7cf02adf /src/ubus.c | |
parent | 2a80a389e1df5341ada9a9f66ce0ad9844ef65f7 (diff) |
Various fixes
Diffstat (limited to 'src/ubus.c')
-rw-r--r-- | src/ubus.c | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -160,6 +160,7 @@ enum { IFACE_ATTR_IFNAME, IFACE_ATTR_UP, IFACE_ATTR_DATA, + IFACE_ATTR_PREFIX, IFACE_ATTR_MAX, }; @@ -168,6 +169,7 @@ static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = { [IFACE_ATTR_IFNAME] = { .name = "ifname", .type = BLOBMSG_TYPE_STRING }, [IFACE_ATTR_UP] = { .name = "up", .type = BLOBMSG_TYPE_BOOL }, [IFACE_ATTR_DATA] = { .name = "data", .type = BLOBMSG_TYPE_TABLE }, + [IFACE_ATTR_PREFIX] = { .name = "ipv6-prefix", .type = BLOBMSG_TYPE_ARRAY }, }; static void handle_dump(_unused struct ubus_request *req, _unused int type, struct blob_attr *msg) @@ -308,6 +310,41 @@ const char* ubus_get_ifname(const char *name) } +bool ubus_has_prefix(const char *name, const char *ifname) +{ + struct blob_attr *c, *cur; + int rem; + + if (!dump) + return NULL; + + blobmsg_for_each_attr(c, dump, rem) { + struct blob_attr *tb[IFACE_ATTR_MAX]; + blobmsg_parse(iface_attrs, IFACE_ATTR_MAX, tb, blob_data(c), blob_len(c)); + + if (!tb[IFACE_ATTR_INTERFACE] || !tb[IFACE_ATTR_IFNAME]) + continue; + + if (!strcmp(name, blobmsg_get_string(tb[IFACE_ATTR_INTERFACE])) || + !strcmp(ifname, blobmsg_get_string(tb[IFACE_ATTR_IFNAME]))) + continue; + + if ((cur = tb[IFACE_ATTR_PREFIX])) { + if (blobmsg_type(cur) != BLOBMSG_TYPE_ARRAY || !blobmsg_check_attr(cur, NULL)) + continue; + + struct blob_attr *d; + int drem; + blobmsg_for_each_attr(d, cur, drem) { + return true; + } + } + } + + return false; +} + + int init_ubus(void) { if (!(ubus = ubus_connect(NULL))) { |