Browse Source

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

Fixes #941
Matthias Schiffer 7 years ago
parent
commit
185d3eb8c8
1 changed files with 24 additions and 2 deletions
  1. 24 2
      package/gluon-mesh-batman-adv-core/src/respondd.c

+ 24 - 2
package/gluon-mesh-batman-adv-core/src/respondd.c

@@ -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);