gluon-mesh-batman-adv-core: respondd: correctly detect lower interface types (#954)

Fixes #941
This commit is contained in:
Matthias Schiffer 2016-12-03 13:22:22 +01:00 committed by GitHub
parent 1f3e789463
commit b32ed384c7
1 changed files with 24 additions and 2 deletions

View File

@ -121,9 +121,31 @@ static void mesh_add_subif(const char *ifname, struct json_object *wireless,
struct json_object *tunnel, struct json_object *other) {
struct json_object *address = gluonutil_wrap_and_free_string(gluonutil_get_interface_address(ifname));
if (interface_file_exists(ifname, "wireless"))
char lowername[IFNAMSIZ];
strncpy(lowername, ifname, sizeof(lowername)-1);
lowername[sizeof(lowername)-1] = 0;
const char *format = "/sys/class/net/%s/lower_*";
char pattern[strlen(format) + IFNAMSIZ];
/* In case of VLAN and bridge interfaces, we want the lower interface
* to determine the interface type (but not for the interface address) */
while (true) {
snprintf(pattern, sizeof(pattern), format, lowername);
size_t pattern_len = strlen(pattern);
glob_t lower;
if (glob(pattern, GLOB_NOSORT, NULL, &lower))
break;
strncpy(lowername, lower.gl_pathv[0] + pattern_len - 1, sizeof(lowername)-1);
globfree(&lower);
}
if (interface_file_exists(lowername, "wireless"))
json_object_array_add(wireless, address);
else if (interface_file_exists(ifname, "tun_flags"))
else if (interface_file_exists(lowername, "tun_flags"))
json_object_array_add(tunnel, address);
else
json_object_array_add(other, address);