rpcd-mod-luci: add link details to ubus netdev information
authorJo-Philipp Wich <jo@mein.io>
Wed, 9 Jun 2021 17:18:04 +0000 (19:18 +0200)
committerJo-Philipp Wich <jo@mein.io>
Sat, 12 Jun 2021 18:01:57 +0000 (20:01 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit 113c0b0d26b2f60c38a605732ce4c0fb3bdfc7dc)

libs/rpcd-mod-luci/src/luci.c

index 030dabb82371a2e76171dd07f0343e8c6488602d..7a13bfefdaadff4ee8118100353601dfc951cabc 100644 (file)
@@ -765,6 +765,30 @@ rpc_luci_parse_network_device_sys(const char *name, struct ifaddrs *ifaddr)
        blobmsg_add_u8(&blob, "pointtopoint", ifa_flags & IFF_POINTOPOINT);
        blobmsg_close_table(&blob, o2);
 
+       o2 = blobmsg_open_table(&blob, "link");
+
+       p = readstr("/sys/class/net/%s/speed", name);
+       if (*p)
+               blobmsg_add_u32(&blob, "speed", atoi(p));
+
+       p = readstr("/sys/class/net/%s/duplex", name);
+       if (*p)
+               blobmsg_add_string(&blob, "duplex", p);
+
+       n = atoi(readstr("/sys/class/net/%s/carrier", name));
+       blobmsg_add_u8(&blob, "carrier", n == 1);
+
+       n = atoi(readstr("/sys/class/net/%s/carrier_changes", name));
+       blobmsg_add_u32(&blob, "changes", n);
+
+       n = atoi(readstr("/sys/class/net/%s/carrier_up_count", name));
+       blobmsg_add_u32(&blob, "up_count", n);
+
+       n = atoi(readstr("/sys/class/net/%s/carrier_down_count", name));
+       blobmsg_add_u32(&blob, "down_count", n);
+
+       blobmsg_close_table(&blob, o2);
+
        blobmsg_close_table(&blob, o);
 }