When receiving a result from first query to netlink, we may exec
a another query inside the callback. If calling this sub-routine
in the same socket, it will be discarded the result from previous
exection.
To avoid this we perform a nested query in separate socket.
Fixes: 202102830663 ("tipc: use the libmnl functions in lib/mnl_utils.c")
Signed-off-by: Hoang Le
Acked-by: Jon Maloy
---
tipc/bearer.c | 50 +-
tipc/link.c | 15 +--
tipc/socket.c | 17 +++--
3 files changed, 73 insertions(+), 9 deletions(-)
diff --git a/tipc/bearer.c b/tipc/bearer.c
index 2afc48b9b108..968293bc9160 100644
--- a/tipc/bearer.c
+++ b/tipc/bearer.c
@@ -20,7 +20,9 @@
#include
#include
#include
+#include
+#include "mnl_utils.h"
#include "utils.h"
#include "cmdl.h"
#include "msg.h"
@@ -98,16 +100,28 @@ static int get_netid_cb(const struct nlmsghdr *nlh, void
*data)
static int generate_multicast(short af, char *buf, int bufsize)
{
+ struct mnlu_gen_socket bearer_nlg;
struct nlmsghdr *nlh;
int netid;
+ int err = 0;
- nlh = msg_init(TIPC_NL_NET_GET);
+ err = mnlu_gen_socket_open(_nlg, TIPC_GENL_V2_NAME,
+ TIPC_GENL_V2_VERSION);
+ if (err)
+ return -1;
+
+ nlh = mnlu_gen_socket_cmd_prepare(_nlg, TIPC_NL_NET_GET,
+ NLM_F_REQUEST | NLM_F_DUMP);
if (!nlh) {
fprintf(stderr, "error, message initialization failed\n");
+ mnlu_gen_socket_close(_nlg);
return -1;
}
- if (msg_dumpit(nlh, get_netid_cb, )) {
+
+ err = mnlu_gen_socket_sndrcv(_nlg, nlh, get_netid_cb, );
+ if (err) {
fprintf(stderr, "error, failed to fetch TIPC network id from
kernel\n");
+ mnlu_gen_socket_close(_nlg);
return -EINVAL;
}
if (af == AF_INET)
@@ -115,6 +129,7 @@ static int generate_multicast(short af, char *buf, int
bufsize)
else
snprintf(buf, bufsize, "ff02::%u", netid);
+ mnlu_gen_socket_close(_nlg);
return 0;
}
@@ -794,10 +809,35 @@ static int bearer_get_udp_cb(const struct nlmsghdr *nlh,
void *data)
if ((cb_data->attr == TIPC_NLA_UDP_REMOTE) &&
(cb_data->prop == UDP_PROP_IP) &&
opts[TIPC_NLA_UDP_MULTI_REMOTEIP]) {
- struct genlmsghdr *genl = mnl_nlmsg_get_payload(cb_data->nlh);
+ struct mnlu_gen_socket bearer_nlg;
+ struct nlattr *attr;
+ struct nlmsghdr *h;
+ const char *bname;
+ int err = 0;
+
+ err = mnlu_gen_socket_open(_nlg, TIPC_GENL_V2_NAME,
+ TIPC_GENL_V2_VERSION);
+ if (err)
+ return -1;
+
+ h = mnlu_gen_socket_cmd_prepare(_nlg,
+ TIPC_NL_UDP_GET_REMOTEIP,
+ NLM_F_REQUEST | NLM_F_DUMP);
+ if (!h) {
+ fprintf(stderr, "error, message initialization
failed\n");
+ mnlu_gen_socket_close(_nlg);
+ return -1;
+ }
- genl->cmd = TIPC_NL_UDP_GET_REMOTEIP;
- return msg_dumpit(cb_data->nlh, bearer_dump_udp_cb, NULL);
+ attr = mnl_attr_nest_start(h, TIPC_NLA_BEARER);
+ bname = mnl_attr_get_str(attrs[TIPC_NLA_BEARER_NAME]);
+ mnl_attr_put_strz(h, TIPC_NLA_BEARER_NAME, bname);
+ mnl_attr_nest_end(h, attr);
+
+ err = mnlu_gen_socket_sndrcv(_nlg, h,
+bearer_dump_udp_cb, NULL);
+ mnlu_gen_socket_close(_nlg);
+ return err;
}
addr = mnl_attr_get_payload(opts[cb_data->attr]);
diff --git a/tipc/link.c b/tipc/link.c
index 2123f109c694..9994ada2a367 100644
--- a/tipc/link.c
+++ b/tipc/link.c
@@ -17,7 +17,9 @@
#include
#include
#include
+#include
+#include "mnl_utils.h"
#include "cmdl.h"
#include "msg.h"
#include "link.h"
@@ -993,13 +995,20 @@ exit:
static int link_mon_peer_list(uint32_t mon_ref)
{
+ struct mnlu_gen_socket link_nlg;
struct nlmsghdr *nlh;
struct nlattr *nest;
int err = 0;
- nlh = msg_init(TIPC_NL_MON_PEER_GET);
+ err = mnlu_gen_socket_open(_nlg, TIPC_GENL_V2_NAME,
+ TIPC_GENL_V2_VERSION);
+ if (err)
+ return -1;
+ nlh = mnlu_gen_socket_cmd_prepare(_nlg, TIPC_NL_MON_PEER_GET,
+ NLM_F_REQUEST | NLM_F_DUMP);
if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
+ mnlu_gen_socket_close(_nlg);
return -1;
}
@@ -1007,7 +1016,9 @@ static