diff mbox

[v7] alfred: Check batadv interfaces via netlink

Message ID 20161106093738.17010-1-sven@narfation.org
State Accepted, archived
Commit 2310c47f0ad7aadff0adac6f9879bf849c3a6356
Delegated to: Simon Wunderlich
Headers show

Commit Message

Sven Eckelmann Nov. 6, 2016, 9:37 a.m. UTC
From: Jean-Jacques Sarton <jj.sarton@t-online.de>

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>
---
v7:
 - rewritten commit message
 - mark batadv_interface_check_debugfs static
 - fix whitespaces
 - fix unused init of variable ret
 - fix return of batadv_interface_check
 - only fallback to debugfs on -EOPNOTSUPP
 - introduce check_nlcmd_cb to stop netlink processing early
 - rewritten batadv_interface_check_netlink to not misuse get_tq_netlink_cb
v6:
 - sixth submission from Jean-Jacques
 - dropped basically the complete patch (doesn't apply)
v5:
 - fifth submission from Jean-Jacques
 - rewritten commit message
v4:
 - fourth submission from Jean-Jacques
 - rewritten commit message
 - introduced check for BATADV_CMD_GET_TRANSTABLE_GLOBAL
v3:
 - third submission from Jean-Jacques (corrupt)
v2:
 - second submission from Jean-Jacques (corrupt)
v1:
 - first submission from Jean-Jacques (corrupt)
---
 batadv_query.c | 16 +++++++++++++++-
 netlink.c      | 25 +++++++++++++++++++++++++
 netlink.h      |  1 +
 3 files changed, 41 insertions(+), 1 deletion(-)

Comments

Simon Wunderlich Nov. 8, 2016, 4:21 p.m. UTC | #1
On Sunday, November 6, 2016 10:37:38 AM CET Sven Eckelmann wrote:
> From: Jean-Jacques Sarton <jj.sarton@t-online.de>
> 
> 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>

Applied in 2310c47.

Thanks!
     Simon
diff mbox

Patch

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[];