alfred: Check batadv interfaces via netlink
PATCH v7 1/1 alfred: Check batadv interfaces via netlink
From: Jean-Jacques Sarton <[email protected]>
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.
[[email protected]: 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]
---
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(-)
batadv_query.c +15 -1
@@ -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)
netlink.c +25 -0
@@ -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 ; +}
netlink.h +1 -0
@@ -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[];
Signature · 1 line
2.10.2
Simon Wunderlich
AppliedQuoted 11 lines · CET Sven Eckelmann
From: Jean-Jacques Sarton <[email protected]>
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.
Quoted 6 lines
Signed-off-by Jean-Jacques Sarton <[email protected]>[[email protected]: fixed commit message, mark debugfs function static,
fix whitespaces, fix unused init of variable, only fallback to debugfs on EOPNOTSUPP, rewrittenbatadv_interface_check_netlink, fix return ofbatadv_interface_check]Signed-off-by Sven Eckelmann <[email protected]>
Applied in 2310c47.
Thanks!
Simon