Repository : ssh://git@open-mesh.org/alfred
On branch : master
commit 2310c47f0ad7aadff0adac6f9879bf849c3a6356 Author: Jean-Jacques Sarton jj.sarton@t-online.de Date: Sun Nov 6 10:37:38 2016 +0100
alfred: Check batadv interfaces via netlink
alfred is checking the status of the mesh interface before it starts. The mesh interface has to have accessible debugfs files "transtable_global" and "originators" before alfred will accept it.
batman-adv will not create debugfs entries for network namespaces. Thus this check has to be modified to first check via netlink if the interface is providing the same information without debugfs. If it does then no check for the debugfs files is necessary anymore.
Signed-off-by: Jean-Jacques Sarton jj.sarton@t-online.de [sven@narfation.org: fixed commit message, mark debugfs function static, fix whitespaces, fix unused init of variable, only fallback to debugfs on EOPNOTSUPP, rewritten batadv_interface_check_netlink, fix return of batadv_interface_check] Signed-off-by: Sven Eckelmann sven@narfation.org Signed-off-by: Simon Wunderlich sw@simonwunderlich.de
2310c47f0ad7aadff0adac6f9879bf849c3a6356 batadv_query.c | 16 +++++++++++++++- netlink.c | 25 +++++++++++++++++++++++++ netlink.h | 1 + 3 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/batadv_query.c b/batadv_query.c index a671b79..c17132f 100644 --- a/batadv_query.c +++ b/batadv_query.c @@ -136,7 +136,7 @@ int ipv6_to_mac(const struct in6_addr *addr, struct ether_addr *mac) return 0; }
-int batadv_interface_check(const char *mesh_iface) +static int batadv_interface_check_debugfs(const char *mesh_iface) { char full_path[MAX_PATH + 1]; FILE *f; @@ -166,6 +166,20 @@ int batadv_interface_check(const char *mesh_iface) return 0; }
+int batadv_interface_check(const char *mesh_iface) +{ + int ret; + + enable_net_admin_capability(1); + ret = batadv_interface_check_netlink(mesh_iface); + enable_net_admin_capability(0); + + if (ret == -EOPNOTSUPP) + ret = batadv_interface_check_debugfs(mesh_iface); + + return ret; +} + static int translate_mac_debugfs(const char *mesh_iface, const struct ether_addr *mac, struct ether_addr *mac_out) diff --git a/netlink.c b/netlink.c index 1b5695c..73fab28 100644 --- a/netlink.c +++ b/netlink.c @@ -365,3 +365,28 @@ int get_tq_netlink(const char *mesh_iface, const struct ether_addr *mac,
return 0; } + +static int check_nlcmd_cb(struct nl_msg *msg __unused, void *arg __unused) +{ + return NL_STOP; +} + +int batadv_interface_check_netlink(const char *mesh_iface) +{ + struct nlquery_opts opts = { + .err = 0, + }; + int ret; + + ret = netlink_query_common(mesh_iface, BATADV_CMD_GET_ORIGINATORS, + check_nlcmd_cb, &opts); + if (ret < 0) + return ret; + + ret = netlink_query_common(mesh_iface, BATADV_CMD_GET_TRANSTABLE_GLOBAL, + check_nlcmd_cb, &opts); + if (ret < 0) + return ret; + + return 0; +} diff --git a/netlink.h b/netlink.h index b08e872..9bc75a1 100644 --- a/netlink.h +++ b/netlink.h @@ -49,6 +49,7 @@ int translate_mac_netlink(const char *mesh_iface, const struct ether_addr *mac, struct ether_addr *mac_out); int get_tq_netlink(const char *mesh_iface, const struct ether_addr *mac, uint8_t *tq); +int batadv_interface_check_netlink(const char *mesh_iface);
extern struct nla_policy batadv_netlink_policy[];