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...@dektech.com.au>
---
 tipc/link.c   | 15 +++++++++++++--
 tipc/socket.c | 17 +++++++++++++++--
 2 files changed, 28 insertions(+), 4 deletions(-)

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



_______________________________________________
tipc-discussion mailing list
tipc-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tipc-discussion

Reply via email to