Repository : ssh://git@open-mesh.org/alfred
On branch : master
commit 241cda1d3ecc501eb67cbfc5dc144c7cc17f7023 Author: Sven Eckelmann sven@open-mesh.com Date: Thu Jan 3 16:51:08 2013 +0100
alfred: Only start when listening on batman-adv soft-interfaces
Signed-off-by: Sven Eckelmann sven@open-mesh.com
241cda1d3ecc501eb67cbfc5dc144c7cc17f7023 batadv_query.c | 37 +++++++++++++++++++++++++++++++++++++ batadv_query.h | 1 + server.c | 4 ++++ 3 files changed, 42 insertions(+)
diff --git a/batadv_query.c b/batadv_query.c index e56ad60..1390f57 100644 --- a/batadv_query.c +++ b/batadv_query.c @@ -29,6 +29,43 @@ #define DEBUG_TRANSTABLE_GLOBAL "transtable_global" #define DEBUG_ORIGINATORS "originators"
+int batadv_interface_check(char *mesh_iface) +{ + char *debugfs_mnt; + char full_path[MAX_PATH+1]; + FILE *f; + + debugfs_mnt = debugfs_mount(NULL); + if (!debugfs_mnt) { + fprintf(stderr, "Could not find debugfs path\n"); + return -1; + } + + debugfs_make_path(DEBUG_BATIF_PATH_FMT "/" DEBUG_TRANSTABLE_GLOBAL, + mesh_iface, full_path, sizeof(full_path)); + f = fopen(full_path, "r"); + if (!f) { + fprintf(stderr, + "Could not find %s for interface %s. Make sure it is a valid batman-adv soft-interface\n", + DEBUG_TRANSTABLE_GLOBAL, mesh_iface); + return -1; + } + fclose(f); + + debugfs_make_path(DEBUG_BATIF_PATH_FMT "/" DEBUG_ORIGINATORS, + mesh_iface, full_path, sizeof(full_path)); + f = fopen(full_path, "r"); + if (!f) { + fprintf(stderr, + "Could not find %s for interface %s. Make sure it is a valid batman-adv soft-interface\n", + DEBUG_ORIGINATORS, mesh_iface); + return -1; + } + fclose(f); + + return 0; +} + struct ether_addr *translate_mac(char *mesh_iface, struct ether_addr *mac) { enum { diff --git a/batadv_query.h b/batadv_query.h index d4a3b79..f2a1f32 100644 --- a/batadv_query.h +++ b/batadv_query.h @@ -25,5 +25,6 @@
struct ether_addr *translate_mac(char *mesh_iface, struct ether_addr *mac); uint8_t get_tq(char *mesh_iface, struct ether_addr *mac); +int batadv_interface_check(char *mesh_iface);
#endif diff --git a/server.c b/server.c index 91a65e6..55844c2 100644 --- a/server.c +++ b/server.c @@ -29,6 +29,7 @@ #include <sys/select.h> #include <sys/time.h> #include "alfred.h" +#include "batadv_query.h"
static int server_compare(void *d1, void *d2) { @@ -169,6 +170,9 @@ int alfred_server(struct globals *globals) return -1; }
+ if (batadv_interface_check(globals->interface) < 0) + return -1; + if (netsock_open(globals)) return -1;