Browse Source

rpcd-mod-luci: expose devtype and iflink properties in getNetworkDevices

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Jo-Philipp Wich 2 months ago
parent
commit
71feaa5285
1 changed files with 32 additions and 0 deletions
  1. 32 0
      libs/rpcd-mod-luci/src/luci.c

+ 32 - 0
libs/rpcd-mod-luci/src/luci.c

@@ -659,6 +659,20 @@ rpc_luci_parse_network_device_sys(const char *name, struct ifaddrs *ifaddr)
 	if (*p)
 		blobmsg_add_string(&blob, "master", p);
 
+	p = strstr(readstr("/sys/class/net/%s/uevent", name), "DEVTYPE=");
+	if (p) {
+		for (n = 0, p += strlen("DEVTYPE=");; n++) {
+			if (p[n] == '\0' || p[n] == '\n') {
+				p[n] = 0;
+				blobmsg_add_string(&blob, "devtype", p);
+				break;
+			}
+		}
+	}
+	else {
+		blobmsg_add_string(&blob, "devtype", "ethernet");
+	}
+
 	for (af = AF_INET; af != 0; af = (af == AF_INET) ? AF_INET6 : 0) {
 		a = blobmsg_open_array(&blob,
 		                       (af == AF_INET) ? "ipaddrs" : "ip6addrs");
@@ -709,6 +723,24 @@ rpc_luci_parse_network_device_sys(const char *name, struct ifaddrs *ifaddr)
 		blobmsg_add_u32(&blob, "ifindex", sll->sll_ifindex);
 
 		ifa_flags |= ifa->ifa_flags;
+
+		n = atoi(readstr("/sys/class/net/%s/iflink", name));
+
+		if (n != sll->sll_ifindex) {
+			for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
+				if (ifa->ifa_addr == NULL || ifa->ifa_addr->sa_family != AF_PACKET)
+					continue;
+
+				sll = (struct sockaddr_ll *)ifa->ifa_addr;
+
+				if (sll->sll_ifindex != n)
+					continue;
+
+				blobmsg_add_string(&blob, "parent", ifa->ifa_name);
+				break;
+			}
+		}
+
 		break;
 	}