@@ -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]);
@@ -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;
}
@@ -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)