[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210506032724.4111-1-hoang.h.le@dektech.com.au>
Date: Thu, 6 May 2021 10:27:24 +0700
From: Hoang Le <hoang.h.le@...tech.com.au>
To: netdev@...r.kernel.org, dsahern@...il.com,
tipc-discussion@...ts.sourceforge.net, jmaloy@...hat.com,
maloy@...jonn.com, ying.xue@...driver.com,
tung.q.nguyen@...tech.com.au
Subject: [iproute2] tipc: call a sub-routine in separate socket
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 <hoang.h.le@...tech.com.au>
Acked-by: Jon Maloy <jmaloy@...hat.com>
---
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 <linux/tipc.h>
#include <linux/genetlink.h>
#include <linux/if.h>
+#include <libmnl/libmnl.h>
+#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(&bearer_nlg, TIPC_GENL_V2_NAME,
+ TIPC_GENL_V2_VERSION);
+ if (err)
+ return -1;
+
+ nlh = mnlu_gen_socket_cmd_prepare(&bearer_nlg, TIPC_NL_NET_GET,
+ NLM_F_REQUEST | NLM_F_DUMP);
if (!nlh) {
fprintf(stderr, "error, message initialization failed\n");
+ mnlu_gen_socket_close(&bearer_nlg);
return -1;
}
- if (msg_dumpit(nlh, get_netid_cb, &netid)) {
+
+ err = mnlu_gen_socket_sndrcv(&bearer_nlg, nlh, get_netid_cb, &netid);
+ if (err) {
fprintf(stderr, "error, failed to fetch TIPC network id from kernel\n");
+ mnlu_gen_socket_close(&bearer_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(&bearer_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(&bearer_nlg, TIPC_GENL_V2_NAME,
+ TIPC_GENL_V2_VERSION);
+ if (err)
+ return -1;
+
+ h = mnlu_gen_socket_cmd_prepare(&bearer_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(&bearer_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(&bearer_nlg, h,
+ bearer_dump_udp_cb, NULL);
+ mnlu_gen_socket_close(&bearer_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 <linux/tipc_netlink.h>
#include <linux/tipc.h>
#include <linux/genetlink.h>
+#include <libmnl/libmnl.h>
+#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(&link_nlg, TIPC_GENL_V2_NAME,
+ TIPC_GENL_V2_VERSION);
+ if (err)
+ return -1;
+ nlh = mnlu_gen_socket_cmd_prepare(&link_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(&link_nlg);
return -1;
}
@@ -1007,7 +1016,9 @@ static int link_mon_peer_list(uint32_t mon_ref)
mnl_attr_put_u32(nlh, TIPC_NLA_MON_REF, mon_ref);
mnl_attr_nest_end(nlh, nest);
- err = msg_dumpit(nlh, link_mon_peer_list_cb, NULL);
+ err = mnlu_gen_socket_sndrcv(&link_nlg, nlh, link_mon_peer_list_cb,
+ NULL);
+ mnlu_gen_socket_close(&link_nlg);
return err;
}
diff --git a/tipc/socket.c b/tipc/socket.c
index deae12af4409..597ffd91af52 100644
--- a/tipc/socket.c
+++ b/tipc/socket.c
@@ -15,7 +15,9 @@
#include <linux/tipc.h>
#include <linux/tipc_netlink.h>
#include <linux/genetlink.h>
+#include <libmnl/libmnl.h>
+#include "mnl_utils.h"
#include "cmdl.h"
#include "msg.h"
#include "socket.h"
@@ -44,12 +46,21 @@ static int publ_list_cb(const struct nlmsghdr *nlh, void *data)
static int publ_list(uint32_t sock)
{
+ struct mnlu_gen_socket sock_nlg;
struct nlmsghdr *nlh;
struct nlattr *nest;
+ int err;
- nlh = msg_init(TIPC_NL_PUBL_GET);
+ err = mnlu_gen_socket_open(&sock_nlg, TIPC_GENL_V2_NAME,
+ TIPC_GENL_V2_VERSION);
+ if (err)
+ return -1;
+
+ nlh = mnlu_gen_socket_cmd_prepare(&sock_nlg, TIPC_NL_PUBL_GET,
+ NLM_F_REQUEST | NLM_F_DUMP);
if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
+ mnlu_gen_socket_close(&sock_nlg);
return -1;
}
@@ -57,7 +68,9 @@ static int publ_list(uint32_t sock)
mnl_attr_put_u32(nlh, TIPC_NLA_SOCK_REF, sock);
mnl_attr_nest_end(nlh, nest);
- return msg_dumpit(nlh, publ_list_cb, NULL);
+ err = mnlu_gen_socket_sndrcv(&sock_nlg, nlh, publ_list_cb, NULL);
+ mnlu_gen_socket_close(&sock_nlg);
+ return err;
}
static int sock_list_cb(const struct nlmsghdr *nlh, void *data)
--
2.25.1
Powered by blists - more mailing lists