| 1 |
/* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 |
/* |
| 3 |
* msg.c Messaging (netlink) helper functions. |
| 4 |
* |
| 5 |
* Authors: Richard Alpe <[email protected]> |
| 6 |
*/ |
| 7 |
|
| 8 |
#include <stdio.h> |
| 9 |
#include <time.h> |
| 10 |
#include <errno.h> |
| 11 |
|
| 12 |
#include <libmnl/libmnl.h> |
| 13 |
|
| 14 |
#include "mnl_utils.h" |
| 15 |
#include "msg.h" |
| 16 |
|
| 17 |
extern struct mnlu_gen_socket tipc_nlg; |
| 18 |
|
| 19 |
int parse_attrs(const struct nlattr *attr, void *data) |
| 20 |
{ |
| 21 |
const struct nlattr **tb = data; |
| 22 |
int type = mnl_attr_get_type(attr); |
| 23 |
|
| 24 |
tb[type] = attr; |
| 25 |
|
| 26 |
return MNL_CB_OK; |
| 27 |
} |
| 28 |
|
| 29 |
int msg_doit(struct nlmsghdr *nlh, mnl_cb_t callback, void *data) |
| 30 |
{ |
| 31 |
nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; |
| 32 |
return mnlu_gen_socket_sndrcv(&tipc_nlg, nlh, callback, data); |
| 33 |
} |
| 34 |
|
| 35 |
int msg_dumpit(struct nlmsghdr *nlh, mnl_cb_t callback, void *data) |
| 36 |
{ |
| 37 |
nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP; |
| 38 |
return mnlu_gen_socket_sndrcv(&tipc_nlg, nlh, callback, data); |
| 39 |
} |
| 40 |
|
| 41 |
struct nlmsghdr *msg_init(int cmd) |
| 42 |
{ |
| 43 |
struct nlmsghdr *nlh; |
| 44 |
|
| 45 |
nlh = mnlu_gen_socket_cmd_prepare(&tipc_nlg, cmd, 0); |
| 46 |
|
| 47 |
return nlh; |
| 48 |
} |