@@ -137,7 +137,23 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
- if ((strcmp(argv[1], "ping") == 0) || (strcmp(argv[1], "p") == 0)) {
+ if ((strcmp(argv[1], "interface") == 0) || (strcmp(argv[1], "if") == 0)) {
+
+ ret = interface(mesh_iface, argc - 1, argv + 1);
+
+ } else if ((strcmp(argv[1], "tcpdump") == 0) || (strcmp(argv[1], "td") == 0)) {
+
+ ret = tcpdump(argc - 1, argv + 1);
+
+#ifdef BATCTL_BISECT
+ } else if ((strcmp(argv[1], "bisect_iv") == 0)) {
+
+ ret = bisect_iv(argc - 1, argv + 1);
+#endif
+ } else if (check_mesh_iface(mesh_iface) < 0) {
+ fprintf(stderr, "Error - interface %s is not present or not a batman-adv interface\n", mesh_iface);
+ exit(EXIT_FAILURE);
+ } else if ((strcmp(argv[1], "ping") == 0) || (strcmp(argv[1], "p") == 0)) {
ret = ping(mesh_iface, argc - 1, argv + 1);
@@ -145,14 +161,6 @@ int main(int argc, char **argv)
ret = traceroute(mesh_iface, argc - 1, argv + 1);
- } else if ((strcmp(argv[1], "tcpdump") == 0) || (strcmp(argv[1], "td") == 0)) {
-
- ret = tcpdump(argc - 1, argv + 1);
-
- } else if ((strcmp(argv[1], "interface") == 0) || (strcmp(argv[1], "if") == 0)) {
-
- ret = interface(mesh_iface, argc - 1, argv + 1);
-
} else if ((strcmp(argv[1], "loglevel") == 0) || (strcmp(argv[1], "ll") == 0)) {
ret = handle_loglevel(mesh_iface, argc - 1, argv + 1);
@@ -179,12 +187,6 @@ int main(int argc, char **argv)
ret = translate(mesh_iface, argc - 1, argv + 1);
-#ifdef BATCTL_BISECT
- } else if ((strcmp(argv[1], "bisect_iv") == 0)) {
-
- ret = bisect_iv(argc - 1, argv + 1);
-#endif
-
} else {
for (i = 0; i < BATCTL_SETTINGS_NUM; i++) {
@@ -566,3 +566,33 @@ out:
free(path_buff);
return res;
}
+
+int check_mesh_iface(char *mesh_iface)
+{
+ char *base_dev = NULL;
+ char *check_iface;
+ char path_buff[PATH_BUFF_LEN];
+ DIR *dir;
+ int ret = -1;
+
+ /* use the parent interface if this is a VLAN */
+ vlan_get_link(mesh_iface, &base_dev);
+ check_iface = mesh_iface;
+ if (base_dev)
+ check_iface = mesh_iface;
+
+ /* try to open the mesh sys directory */
+ snprintf(path_buff, PATH_BUFF_LEN, SYS_BATIF_PATH_FMT, check_iface);
+ dir = opendir(path_buff);
+ if (!dir)
+ goto out;
+
+ closedir(dir);
+
+ ret = 0;
+out:
+ if (base_dev)
+ free(base_dev);
+
+ return ret;
+}
@@ -71,5 +71,6 @@ int interface(char *mesh_iface, int argc, char **argv);
int handle_loglevel(char *mesh_iface, int argc, char **argv);
int handle_sys_setting(char *mesh_iface, int setting, int argc, char **argv);
int handle_gw_setting(char *mesh_iface, int argc, char **argv);
+int check_mesh_iface(char *mesh_iface);
#endif