X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;f=system-linux.c;h=4a3de8c8eeb0714c0ad1f5f3acd20d3cb26adf63;hb=b7e1b35ff18a759a54e4033d04a3550499dd9fc1;hp=3ac55883918c5b97e10f27eb9c5f65dbf1dcc470;hpb=a2f762e2e145b7be932f25c8f1de0da2a8009d4f;p=project%2Fnetifd.git diff --git a/system-linux.c b/system-linux.c index 3ac5588..4a3de8c 100644 --- a/system-linux.c +++ b/system-linux.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -607,6 +608,37 @@ int system_if_check(struct device *dev) return 0; } +struct device * +system_if_get_parent(struct device *dev) +{ + char buf[64], *devname; + int ifindex, iflink, len; + FILE *f; + + snprintf(buf, sizeof(buf), "/sys/class/net/%s/iflink", dev->ifname); + f = fopen(buf, "r"); + if (!f) + return NULL; + + len = fread(buf, 1, sizeof(buf) - 1, f); + fclose(f); + + if (len <= 0) + return NULL; + + buf[len] = 0; + iflink = strtoul(buf, NULL, 0); + ifindex = system_if_resolve(dev); + if (!iflink || iflink == ifindex) + return NULL; + + devname = if_indextoname(iflink, buf); + if (!devname) + return NULL; + + return device_get(devname, true); +} + int system_if_dump_stats(struct device *dev, struct blob_buf *b) { const char *const counters[] = {