Repository : ssh://git@diktynna/batctl
On branch : master
>---------------------------------------------------------------
commit 6ce86b601a13885f98d226e20b33a4be312c991b
Author: Sven Eckelmann <sven(a)narfation.org>
Date: Fri May 14 17:15:59 2021 +0200
batctl: netlink: Allow to use netlink_query_common hardif/vlan
The netlink_query_common didn't allow to set attributes for hardif/vlan
specific queries. Using a similar approach as sys_simple_nlquery makes it
possible to implement such a feature with a simple callback function. And
might allow later to use netlink_query_common inside sys_simple_nlquery.
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
>---------------------------------------------------------------
6ce86b601a13885f98d226e20b33a4be312c991b
netlink.c | 22 ++++++++++++++++------
netlink.h | 6 ++++--
2 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/netlink.c b/netlink.c
index 33cfa4c..e92fa80 100644
--- a/netlink.c
+++ b/netlink.c
@@ -622,8 +622,9 @@ static int nlquery_stop_cb(struct nl_msg *msg, void *arg)
int netlink_query_common(struct state *state,
unsigned int mesh_ifindex, uint8_t nl_cmd,
- nl_recvmsg_msg_cb_t callback, int flags,
- struct nlquery_opts *query_opts)
+ nl_recvmsg_msg_cb_t callback,
+ nl_recvmsg_msg_cb_t attribute_cb,
+ int flags, struct nlquery_opts *query_opts)
{
struct nl_msg *msg;
struct nl_cb *cb;
@@ -649,6 +650,15 @@ int netlink_query_common(struct state *state,
flags, nl_cmd, 1);
nla_put_u32(msg, BATADV_ATTR_MESH_IFINDEX, mesh_ifindex);
+
+ if (attribute_cb) {
+ ret = attribute_cb(msg, state);
+ if (ret < 0) {
+ nlmsg_free(msg);
+ goto err_free_cb;
+ }
+ }
+
nl_send_auto_complete(state->sock, msg);
nlmsg_free(msg);
@@ -739,7 +749,7 @@ int translate_mac_netlink(struct state *state, const struct ether_addr *mac,
ret = netlink_query_common(state, state->mesh_ifindex,
BATADV_CMD_GET_TRANSTABLE_GLOBAL,
- translate_mac_netlink_cb, NLM_F_DUMP,
+ translate_mac_netlink_cb, NULL, NLM_F_DUMP,
&opts.query_opts);
if (ret < 0)
return ret;
@@ -845,7 +855,7 @@ int get_nexthop_netlink(struct state *state, const struct ether_addr *mac,
ret = netlink_query_common(state, state->mesh_ifindex,
BATADV_CMD_GET_ORIGINATORS,
- get_nexthop_netlink_cb, NLM_F_DUMP,
+ get_nexthop_netlink_cb, NULL, NLM_F_DUMP,
&opts.query_opts);
if (ret < 0)
return ret;
@@ -921,7 +931,7 @@ int get_primarymac_netlink(struct state *state, uint8_t *primarymac)
ret = netlink_query_common(state, state->mesh_ifindex,
BATADV_CMD_GET_MESH_INFO,
- get_primarymac_netlink_cb, 0,
+ get_primarymac_netlink_cb, NULL, 0,
&opts.query_opts);
if (ret < 0)
return ret;
@@ -997,7 +1007,7 @@ int get_algoname_netlink(struct state *state, unsigned int mesh_ifindex,
int ret;
ret = netlink_query_common(state, mesh_ifindex, BATADV_CMD_GET_MESH,
- get_algoname_netlink_cb, 0,
+ get_algoname_netlink_cb, NULL, 0,
&opts.query_opts);
if (ret < 0)
return ret;
diff --git a/netlink.h b/netlink.h
index 20fb39b..237f760 100644
--- a/netlink.h
+++ b/netlink.h
@@ -58,8 +58,10 @@ int netlink_print_error(struct sockaddr_nl *nla, struct nlmsgerr *nlerr,
void *arg);
void netlink_print_remaining_header(struct print_opts *opts);
-int netlink_query_common(struct state *state, unsigned int mesh_ifindex,
- uint8_t nl_cmd, nl_recvmsg_msg_cb_t callback,
+int netlink_query_common(struct state *state,
+ unsigned int mesh_ifindex, uint8_t nl_cmd,
+ nl_recvmsg_msg_cb_t callback,
+ nl_recvmsg_msg_cb_t attribute_cb,
int flags, struct nlquery_opts *query_opts);
extern char algo_name_buf[256];