diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2013-11-22 16:10:05 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2013-11-22 16:11:22 +0000 |
commit | 4015365f1b73eed1833f87aaf895259df2ea73c0 (patch) | |
tree | 376ee892e644fe768720d7d1fb16b0859d956b2f /luci2 | |
parent | 02f6823105cf1e21145d01fae18dd1abcf4fca77 (diff) | |
download | luci2-ui-4015365f1b73eed1833f87aaf895259df2ea73c0.tar.gz |
rpcd: expose interface up state in luci2.network.device_list
Diffstat (limited to 'luci2')
-rw-r--r-- | luci2/src/rpcd/luci2.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/luci2/src/rpcd/luci2.c b/luci2/src/rpcd/luci2.c index a736dd8..3dc7b9e 100644 --- a/luci2/src/rpcd/luci2.c +++ b/luci2/src/rpcd/luci2.c @@ -2205,7 +2205,7 @@ rpc_luci2_network_dev_list(struct ubus_context *ctx, struct ubus_object *obj, struct stat s; void *c, *t; bool wireless, bridge, tuntap; - int type; + int type, flags; DIR *d; FILE *f; @@ -2230,6 +2230,18 @@ rpc_luci2_network_dev_list(struct ubus_context *ctx, struct ubus_object *obj, fclose(f); + snprintf(path, sizeof(path) - 1, "/sys/class/net/%s/flags", e->d_name); + + if (stat(path, &s) || !S_ISREG(s.st_mode) || !(f = fopen(path, "r"))) + continue; + + flags = 0; + memset(path, 0, sizeof(path)); + + if (fread(path, 1, sizeof(path) - 1, f) > 0) + flags = strtoul(path, NULL, 16); + + fclose(f); snprintf(path, sizeof(path) - 1, "/sys/class/net/%s/wireless", e->d_name); @@ -2255,6 +2267,7 @@ rpc_luci2_network_dev_list(struct ubus_context *ctx, struct ubus_object *obj, blobmsg_add_string(&buf, "device", e->d_name); blobmsg_add_u32(&buf, "type", type); + blobmsg_add_u8(&buf, "is_up", flags & 1); blobmsg_add_u8(&buf, "is_bridge", bridge); blobmsg_add_u8(&buf, "is_tuntap", tuntap); blobmsg_add_u8(&buf, "is_wireless", wireless); |