@@ -39,6 +39,7 @@
#include "version.h"
#include "list.h"
#include "mnlg.h"
+#include "mnl_utils.h"
#include "json_print.h"
#include "utils.h"
#include "namespace.h"
@@ -148,24 +149,11 @@ static void __pr_out_newline(void)
g_new_line_count++;
}
-static int _mnlg_socket_recv_run(struct mnlg_socket *nlg,
- mnl_cb_t data_cb, void *data)
-{
- int err;
-
- err = mnlg_socket_recv_run(nlg, data_cb, data);
- if (err < 0) {
- pr_err("devlink answers: %s\n", strerror(errno));
- return -errno;
- }
- return 0;
-}
-
static void dummy_signal_handler(int signum)
{
}
-static int _mnlg_socket_recv_run_intr(struct mnlg_socket *nlg,
+static int _mnlg_socket_recv_run_intr(struct mnlu_gen_socket *nlg,
mnl_cb_t data_cb, void *data)
{
struct sigaction act, oact;
@@ -176,7 +164,7 @@ static int _mnlg_socket_recv_run_intr(struct mnlg_socket *nlg,
act.sa_flags = SA_NODEFER;
sigaction(SIGINT, &act, &oact);
- err = mnlg_socket_recv_run(nlg, data_cb, data);
+ err = mnlu_gen_socket_recv_run(nlg, data_cb, data);
sigaction(SIGINT, &oact, NULL);
if (err < 0 && errno != EINTR) {
pr_err("devlink answers: %s\n", strerror(errno));
@@ -185,7 +173,7 @@ static int _mnlg_socket_recv_run_intr(struct mnlg_socket *nlg,
return 0;
}
-static int _mnlg_socket_send(struct mnlg_socket *nlg,
+static int _mnlg_socket_send(struct mnlu_gen_socket *nlg,
const struct nlmsghdr *nlh)
{
int err;
@@ -198,19 +186,7 @@ static int _mnlg_socket_send(struct mnlg_socket *nlg,
return 0;
}
-static int _mnlg_socket_sndrcv(struct mnlg_socket *nlg,
- const struct nlmsghdr *nlh,
- mnl_cb_t data_cb, void *data)
-{
- int err;
-
- err = _mnlg_socket_send(nlg, nlh);
- if (err)
- return err;
- return _mnlg_socket_recv_run(nlg, data_cb, data);
-}
-
-static int _mnlg_socket_group_add(struct mnlg_socket *nlg,
+static int _mnlg_socket_group_add(struct mnlu_gen_socket *nlg,
const char *group_name)
{
int err;
@@ -367,7 +343,7 @@ struct dl_opts {
};
struct dl {
- struct mnlg_socket *nlg;
+ struct mnlu_gen_socket nlg;
struct list_head ifname_map_list;
int argc;
char **argv;
@@ -821,10 +797,11 @@ static int ifname_map_init(struct dl *dl)
INIT_LIST_HEAD(&dl->ifname_map_list);
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_GET,
+
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_PORT_GET,
NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP);
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, ifname_map_cb, dl);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, ifname_map_cb, dl);
if (err) {
ifname_map_fini(dl);
return err;
@@ -2550,7 +2527,7 @@ static int cmd_dev_eswitch_show(struct dl *dl)
struct nlmsghdr *nlh;
int err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_ESWITCH_GET,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_ESWITCH_GET,
NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, 0);
@@ -2558,7 +2535,7 @@ static int cmd_dev_eswitch_show(struct dl *dl)
return err;
pr_out_section_start(dl, "dev");
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dev_eswitch_show_cb, dl);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_dev_eswitch_show_cb, dl);
pr_out_section_end(dl);
return err;
}
@@ -2568,7 +2545,7 @@ static int cmd_dev_eswitch_set(struct dl *dl)
struct nlmsghdr *nlh;
int err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_ESWITCH_SET,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_ESWITCH_SET,
NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE,
@@ -2584,7 +2561,7 @@ static int cmd_dev_eswitch_set(struct dl *dl)
return -ENOENT;
}
- return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+ return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL);
}
static int cmd_dev_eswitch(struct dl *dl)
@@ -2948,16 +2925,16 @@ static int cmd_dev_param_set(struct dl *dl)
return err;
/* Get value type */
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PARAM_GET,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_PARAM_GET,
NLM_F_REQUEST | NLM_F_ACK);
dl_opts_put(nlh, dl);
ctx.dl = dl;
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dev_param_set_cb, &ctx);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_dev_param_set_cb, &ctx);
if (err)
return err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PARAM_SET,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_PARAM_SET,
NLM_F_REQUEST | NLM_F_ACK);
dl_opts_put(nlh, dl);
@@ -3035,7 +3012,7 @@ static int cmd_dev_param_set(struct dl *dl)
printf("Value type not supported\n");
return -ENOTSUP;
}
- return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+ return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL);
err_param_value_parse:
pr_err("Value \"%s\" is not a number or not within range\n",
@@ -3067,7 +3044,7 @@ static int cmd_dev_param_show(struct dl *dl)
if (dl_argc(dl) == 0)
flags |= NLM_F_DUMP;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PARAM_GET, flags);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_PARAM_GET, flags);
if (dl_argc(dl) > 0) {
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE |
@@ -3077,7 +3054,7 @@ static int cmd_dev_param_show(struct dl *dl)
}
pr_out_section_start(dl, "param");
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dev_param_show_cb, dl);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_dev_param_show_cb, dl);
pr_out_section_end(dl);
return err;
}
@@ -3223,7 +3200,7 @@ static int cmd_dev_show(struct dl *dl)
if (dl_argc(dl) == 0)
flags |= NLM_F_DUMP;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_GET, flags);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_GET, flags);
if (dl_argc(dl) > 0) {
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, 0);
@@ -3232,7 +3209,7 @@ static int cmd_dev_show(struct dl *dl)
}
pr_out_section_start(dl, "dev");
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dev_show_cb, dl);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_dev_show_cb, dl);
pr_out_section_end(dl);
return err;
}
@@ -3298,7 +3275,7 @@ static int cmd_dev_reload(struct dl *dl)
return 0;
}
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_RELOAD,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_RELOAD,
NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE,
@@ -3307,7 +3284,7 @@ static int cmd_dev_reload(struct dl *dl)
if (err)
return err;
- return _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dev_reload_cb, dl);
+ return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_dev_reload_cb, dl);
}
static void pr_out_versions_single(struct dl *dl, const struct nlmsghdr *nlh,
@@ -3443,7 +3420,7 @@ static int cmd_dev_info(struct dl *dl)
if (dl_argc(dl) == 0)
flags |= NLM_F_DUMP;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_INFO_GET, flags);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_INFO_GET, flags);
if (dl_argc(dl) > 0) {
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, 0);
@@ -3452,7 +3429,7 @@ static int cmd_dev_info(struct dl *dl)
}
pr_out_section_start(dl, "info");
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_versions_show_cb, dl);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_versions_show_cb, dl);
pr_out_section_end(dl);
return err;
}
@@ -3637,7 +3614,7 @@ static void cmd_dev_flash_time_elapsed(struct cmd_dev_flash_status_ctx *ctx)
}
static int cmd_dev_flash_fds_process(struct cmd_dev_flash_status_ctx *ctx,
- struct mnlg_socket *nlg_ntf,
+ struct mnlu_gen_socket *nlg_ntf,
int pipe_r)
{
int nlfd = mnlg_socket_get_fd(nlg_ntf);
@@ -3670,8 +3647,8 @@ static int cmd_dev_flash_fds_process(struct cmd_dev_flash_status_ctx *ctx,
return -errno;
}
if (FD_ISSET(nlfd, &fds[0])) {
- err = _mnlg_socket_recv_run(nlg_ntf,
- cmd_dev_flash_status_cb, ctx);
+ err = mnlu_gen_socket_recv_run(nlg_ntf,
+ cmd_dev_flash_status_cb, ctx);
if (err)
return err;
}
@@ -3693,7 +3670,7 @@ static int cmd_dev_flash_fds_process(struct cmd_dev_flash_status_ctx *ctx,
static int cmd_dev_flash(struct dl *dl)
{
struct cmd_dev_flash_status_ctx ctx = {.dl = dl,};
- struct mnlg_socket *nlg_ntf;
+ struct mnlu_gen_socket nlg_ntf;
struct nlmsghdr *nlh;
int pipe_r, pipe_w;
int pipe_fds[2];
@@ -3705,7 +3682,7 @@ static int cmd_dev_flash(struct dl *dl)
return 0;
}
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_FLASH_UPDATE,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_FLASH_UPDATE,
NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE | DL_OPT_FLASH_FILE_NAME,
@@ -3713,11 +3690,12 @@ static int cmd_dev_flash(struct dl *dl)
if (err)
return err;
- nlg_ntf = mnlg_socket_open(DEVLINK_GENL_NAME, DEVLINK_GENL_VERSION);
- if (!nlg_ntf)
+ err = mnlu_gen_socket_open(&nlg_ntf, DEVLINK_GENL_NAME,
+ DEVLINK_GENL_VERSION);
+ if (err)
return err;
- err = _mnlg_socket_group_add(nlg_ntf, DEVLINK_GENL_MCGRP_CONFIG_NAME);
+ err = _mnlg_socket_group_add(&nlg_ntf, DEVLINK_GENL_MCGRP_CONFIG_NAME);
if (err)
goto err_socket;
@@ -3741,7 +3719,7 @@ static int cmd_dev_flash(struct dl *dl)
int cc;
close(pipe_r);
- err = _mnlg_socket_send(dl->nlg, nlh);
+ err = _mnlg_socket_send(&dl->nlg, nlh);
cc = write(pipe_w, &err, sizeof(err));
close(pipe_w);
exit(cc != sizeof(err));
@@ -3754,16 +3732,17 @@ static int cmd_dev_flash(struct dl *dl)
clock_gettime(CLOCK_MONOTONIC, &ctx.time_of_last_status);
do {
- err = cmd_dev_flash_fds_process(&ctx, nlg_ntf, pipe_r);
+ err = cmd_dev_flash_fds_process(&ctx, &nlg_ntf, pipe_r);
if (err)
goto out;
} while (!ctx.flash_done || (ctx.not_first && !ctx.received_end));
- err = _mnlg_socket_recv_run(dl->nlg, NULL, NULL);
+ err = mnlu_gen_socket_recv_run(&dl->nlg, NULL, NULL);
+
out:
close(pipe_r);
err_socket:
- mnlg_socket_close(nlg_ntf);
+ mnlu_gen_socket_close(&nlg_ntf);
return err;
}
@@ -4008,7 +3987,7 @@ static int cmd_port_show(struct dl *dl)
if (dl_argc(dl) == 0)
flags |= NLM_F_DUMP;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_GET, flags);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_PORT_GET, flags);
if (dl_argc(dl) > 0) {
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP, 0);
@@ -4017,7 +3996,7 @@ static int cmd_port_show(struct dl *dl)
}
pr_out_section_start(dl, "port");
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_port_show_cb, dl);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_port_show_cb, dl);
pr_out_section_end(dl);
return err;
}
@@ -4027,14 +4006,14 @@ static int cmd_port_set(struct dl *dl)
struct nlmsghdr *nlh;
int err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_SET,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_PORT_SET,
NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP | DL_OPT_PORT_TYPE, 0);
if (err)
return err;
- return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+ return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL);
}
static int cmd_port_split(struct dl *dl)
@@ -4042,14 +4021,14 @@ static int cmd_port_split(struct dl *dl)
struct nlmsghdr *nlh;
int err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_SPLIT,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_PORT_SPLIT,
NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP | DL_OPT_PORT_COUNT, 0);
if (err)
return err;
- return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+ return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL);
}
static int cmd_port_unsplit(struct dl *dl)
@@ -4057,14 +4036,14 @@ static int cmd_port_unsplit(struct dl *dl)
struct nlmsghdr *nlh;
int err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_UNSPLIT,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_PORT_UNSPLIT,
NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP, 0);
if (err)
return err;
- return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+ return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL);
}
static int cmd_port_param_show(struct dl *dl)
@@ -4076,7 +4055,8 @@ static int cmd_port_param_show(struct dl *dl)
if (dl_argc(dl) == 0)
flags |= NLM_F_DUMP;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_PARAM_GET, flags);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_PORT_PARAM_GET,
+ flags);
if (dl_argc(dl) > 0) {
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP |
@@ -4086,7 +4066,7 @@ static int cmd_port_param_show(struct dl *dl)
}
pr_out_section_start(dl, "param");
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_port_param_show_cb, dl);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_port_param_show_cb, dl);
pr_out_section_end(dl);
return err;
@@ -4106,14 +4086,15 @@ static int cmd_port_function_set(struct dl *dl)
cmd_port_function_help();
return 0;
}
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_SET, NLM_F_REQUEST | NLM_F_ACK);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_PORT_SET,
+ NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP,
DL_OPT_PORT_FUNCTION_HW_ADDR | DL_OPT_PORT_FUNCTION_STATE);
if (err)
return err;
- return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+ return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL);
}
static int cmd_port_param_set_cb(const struct nlmsghdr *nlh, void *data)
@@ -4203,17 +4184,17 @@ static int cmd_port_param_set(struct dl *dl)
return err;
/* Get value type */
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_PARAM_GET,
- NLM_F_REQUEST | NLM_F_ACK);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_PORT_PARAM_GET,
+ NLM_F_REQUEST | NLM_F_ACK);
dl_opts_put(nlh, dl);
ctx.dl = dl;
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_port_param_set_cb, &ctx);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_port_param_set_cb, &ctx);
if (err)
return err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_PARAM_SET,
- NLM_F_REQUEST | NLM_F_ACK);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_PORT_PARAM_SET,
+ NLM_F_REQUEST | NLM_F_ACK);
dl_opts_put(nlh, dl);
conv_exists = param_val_conv_exists(param_val_conv, PARAM_VAL_CONV_LEN,
@@ -4290,7 +4271,7 @@ static int cmd_port_param_set(struct dl *dl)
printf("Value type not supported\n");
return -ENOTSUP;
}
- return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+ return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL);
err_param_value_parse:
pr_err("Value \"%s\" is not a number or not within range\n",
@@ -4346,8 +4327,8 @@ static int cmd_port_add(struct dl *dl)
return 0;
}
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_NEW,
- NLM_F_REQUEST | NLM_F_ACK);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_PORT_NEW,
+ NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE | DL_OPT_HANDLEP |
DL_OPT_PORT_FLAVOUR | DL_OPT_PORT_PFNUMBER,
@@ -4355,7 +4336,7 @@ static int cmd_port_add(struct dl *dl)
if (err)
return err;
- return _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_port_show_cb, dl);
+ return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_port_show_cb, dl);
}
static void cmd_port_del_help(void)
@@ -4373,14 +4354,14 @@ static int cmd_port_del(struct dl *dl)
return 0;
}
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_DEL,
- NLM_F_REQUEST | NLM_F_ACK);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_PORT_DEL,
+ NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP, 0);
if (err)
return err;
- return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+ return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL);
}
static int cmd_port(struct dl *dl)
@@ -4494,7 +4475,7 @@ static int cmd_sb_show(struct dl *dl)
if (dl_argc(dl) == 0)
flags |= NLM_F_DUMP;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_GET, flags);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_SB_GET, flags);
if (dl_argc(dl) > 0) {
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, DL_OPT_SB);
@@ -4503,7 +4484,7 @@ static int cmd_sb_show(struct dl *dl)
}
pr_out_section_start(dl, "sb");
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_sb_show_cb, dl);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_sb_show_cb, dl);
pr_out_section_end(dl);
return err;
}
@@ -4571,7 +4552,7 @@ static int cmd_sb_pool_show(struct dl *dl)
if (dl_argc(dl) == 0)
flags |= NLM_F_DUMP;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_POOL_GET, flags);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_SB_POOL_GET, flags);
if (dl_argc(dl) > 0) {
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE | DL_OPT_SB_POOL,
@@ -4581,7 +4562,7 @@ static int cmd_sb_pool_show(struct dl *dl)
}
pr_out_section_start(dl, "pool");
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_sb_pool_show_cb, dl);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_sb_pool_show_cb, dl);
pr_out_section_end(dl);
return err;
}
@@ -4591,7 +4572,7 @@ static int cmd_sb_pool_set(struct dl *dl)
struct nlmsghdr *nlh;
int err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_POOL_SET,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_SB_POOL_SET,
NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE | DL_OPT_SB_POOL |
@@ -4599,7 +4580,7 @@ static int cmd_sb_pool_set(struct dl *dl)
if (err)
return err;
- return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+ return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL);
}
static int cmd_sb_pool(struct dl *dl)
@@ -4656,7 +4637,7 @@ static int cmd_sb_port_pool_show(struct dl *dl)
if (dl_argc(dl) == 0)
flags |= NLM_F_DUMP;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_PORT_POOL_GET, flags);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_SB_PORT_POOL_GET, flags);
if (dl_argc(dl) > 0) {
err = dl_argv_parse_put(nlh, dl,
@@ -4667,7 +4648,7 @@ static int cmd_sb_port_pool_show(struct dl *dl)
}
pr_out_section_start(dl, "port_pool");
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_sb_port_pool_show_cb, dl);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_sb_port_pool_show_cb, dl);
pr_out_section_end(dl);
return 0;
}
@@ -4677,7 +4658,7 @@ static int cmd_sb_port_pool_set(struct dl *dl)
struct nlmsghdr *nlh;
int err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_PORT_POOL_SET,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_SB_PORT_POOL_SET,
NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP | DL_OPT_SB_POOL |
@@ -4685,7 +4666,7 @@ static int cmd_sb_port_pool_set(struct dl *dl)
if (err)
return err;
- return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+ return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL);
}
static int cmd_sb_port_pool(struct dl *dl)
@@ -4760,7 +4741,7 @@ static int cmd_sb_tc_bind_show(struct dl *dl)
if (dl_argc(dl) == 0)
flags |= NLM_F_DUMP;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_TC_POOL_BIND_GET, flags);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_SB_TC_POOL_BIND_GET, flags);
if (dl_argc(dl) > 0) {
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP | DL_OPT_SB_TC |
@@ -4770,7 +4751,7 @@ static int cmd_sb_tc_bind_show(struct dl *dl)
}
pr_out_section_start(dl, "tc_bind");
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_sb_tc_bind_show_cb, dl);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_sb_tc_bind_show_cb, dl);
pr_out_section_end(dl);
return err;
}
@@ -4780,7 +4761,7 @@ static int cmd_sb_tc_bind_set(struct dl *dl)
struct nlmsghdr *nlh;
int err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_TC_POOL_BIND_SET,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_SB_TC_POOL_BIND_SET,
NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP | DL_OPT_SB_TC |
@@ -4789,7 +4770,7 @@ static int cmd_sb_tc_bind_set(struct dl *dl)
if (err)
return err;
- return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+ return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL);
}
static int cmd_sb_tc_bind(struct dl *dl)
@@ -5106,16 +5087,16 @@ static int cmd_sb_occ_show(struct dl *dl)
if (!occ_show)
return -ENOMEM;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_PORT_POOL_GET, flags);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_SB_PORT_POOL_GET, flags);
- err = _mnlg_socket_sndrcv(dl->nlg, nlh,
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh,
cmd_sb_occ_port_pool_process_cb, occ_show);
if (err)
goto out;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_TC_POOL_BIND_GET, flags);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_SB_TC_POOL_BIND_GET, flags);
- err = _mnlg_socket_sndrcv(dl->nlg, nlh,
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh,
cmd_sb_occ_tc_pool_process_cb, occ_show);
if (err)
goto out;
@@ -5134,14 +5115,14 @@ static int cmd_sb_occ_snapshot(struct dl *dl)
struct nlmsghdr *nlh;
int err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_OCC_SNAPSHOT,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_SB_OCC_SNAPSHOT,
NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, DL_OPT_SB);
if (err)
return err;
- return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+ return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL);
}
static int cmd_sb_occ_clearmax(struct dl *dl)
@@ -5149,14 +5130,14 @@ static int cmd_sb_occ_clearmax(struct dl *dl)
struct nlmsghdr *nlh;
int err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_OCC_MAX_CLEAR,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_SB_OCC_MAX_CLEAR,
NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, DL_OPT_SB);
if (err)
return err;
- return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+ return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL);
}
static int cmd_sb_occ(struct dl *dl)
@@ -5513,12 +5494,12 @@ static int cmd_mon_show(struct dl *dl)
return -EINVAL;
}
}
- err = _mnlg_socket_group_add(dl->nlg, DEVLINK_GENL_MCGRP_CONFIG_NAME);
+ err = _mnlg_socket_group_add(&dl->nlg, DEVLINK_GENL_MCGRP_CONFIG_NAME);
if (err)
return err;
open_json_object(NULL);
open_json_array(PRINT_JSON, "mon");
- err = _mnlg_socket_recv_run_intr(dl->nlg, cmd_mon_show_cb, dl);
+ err = _mnlg_socket_recv_run_intr(&dl->nlg, cmd_mon_show_cb, dl);
close_json_array(PRINT_JSON, NULL);
close_json_object();
if (err)
@@ -6034,7 +6015,7 @@ static int cmd_dpipe_headers_show(struct dl *dl)
uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
int err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_HEADERS_GET, flags);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_DPIPE_HEADERS_GET, flags);
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, 0);
if (err)
@@ -6047,7 +6028,7 @@ static int cmd_dpipe_headers_show(struct dl *dl)
ctx.print_headers = true;
pr_out_section_start(dl, "header");
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_header_cb, &ctx);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_dpipe_header_cb, &ctx);
if (err)
pr_err("error get headers %s\n", strerror(ctx.err));
pr_out_section_end(dl);
@@ -6436,7 +6417,7 @@ static int cmd_dpipe_table_show(struct dl *dl)
if (err)
return err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_HEADERS_GET, flags);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_DPIPE_HEADERS_GET, flags);
err = dpipe_ctx_init(&dpipe_ctx, dl);
if (err)
@@ -6445,7 +6426,7 @@ static int cmd_dpipe_table_show(struct dl *dl)
dpipe_ctx.print_tables = true;
dl_opts_put(nlh, dl);
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_header_cb,
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_dpipe_header_cb,
&dpipe_ctx);
if (err) {
pr_err("error get headers %s\n", strerror(dpipe_ctx.err));
@@ -6457,19 +6438,19 @@ static int cmd_dpipe_table_show(struct dl *dl)
goto err_resource_ctx_init;
resource_ctx.print_resources = false;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_RESOURCE_DUMP, flags);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_RESOURCE_DUMP, flags);
dl_opts_put(nlh, dl);
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_resource_dump_cb,
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_resource_dump_cb,
&resource_ctx);
if (!err)
dpipe_ctx.resources = resource_ctx.resources;
flags = NLM_F_REQUEST | NLM_F_ACK;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_TABLE_GET, flags);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_DPIPE_TABLE_GET, flags);
dl_opts_put(nlh, dl);
pr_out_section_start(dl, "table");
- _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_table_show_cb, &dpipe_ctx);
+ mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_dpipe_table_show_cb, &dpipe_ctx);
pr_out_section_end(dl);
resource_ctx_fini(&resource_ctx);
@@ -6487,7 +6468,7 @@ static int cmd_dpipe_table_set(struct dl *dl)
struct nlmsghdr *nlh;
int err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_TABLE_COUNTERS_SET,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_DPIPE_TABLE_COUNTERS_SET,
NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse_put(nlh, dl,
@@ -6496,7 +6477,7 @@ static int cmd_dpipe_table_set(struct dl *dl)
if (err)
return err;
- return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+ return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL);
}
enum dpipe_value_type {
@@ -6864,20 +6845,20 @@ static int cmd_dpipe_table_dump(struct dl *dl)
if (err)
goto out;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_HEADERS_GET, flags);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_DPIPE_HEADERS_GET, flags);
dl_opts_put(nlh, dl);
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_header_cb, &ctx);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_dpipe_header_cb, &ctx);
if (err) {
pr_err("error get headers %s\n", strerror(ctx.err));
goto out;
}
flags = NLM_F_REQUEST | NLM_F_ACK;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_ENTRIES_GET, flags);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_DPIPE_ENTRIES_GET, flags);
dl_opts_put(nlh, dl);
pr_out_section_start(dl, "table_entry");
- _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_table_entry_dump_cb, &ctx);
+ mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_dpipe_table_entry_dump_cb, &ctx);
pr_out_section_end(dl);
out:
dpipe_ctx_fini(&ctx);
@@ -7141,7 +7122,7 @@ static int cmd_resource_show(struct dl *dl)
if (err)
return err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_TABLE_GET,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_DPIPE_TABLE_GET,
NLM_F_REQUEST);
dl_opts_put(nlh, dl);
@@ -7149,7 +7130,7 @@ static int cmd_resource_show(struct dl *dl)
if (err)
return err;
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_table_show_cb,
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_dpipe_table_show_cb,
&dpipe_ctx);
if (err) {
pr_err("error get tables %s\n", strerror(dpipe_ctx.err));
@@ -7162,11 +7143,11 @@ static int cmd_resource_show(struct dl *dl)
resource_ctx.print_resources = true;
resource_ctx.tables = dpipe_ctx.tables;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_RESOURCE_DUMP,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_RESOURCE_DUMP,
NLM_F_REQUEST | NLM_F_ACK);
dl_opts_put(nlh, dl);
pr_out_section_start(dl, "resources");
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_resource_dump_cb,
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_resource_dump_cb,
&resource_ctx);
pr_out_section_end(dl);
resource_ctx_fini(&resource_ctx);
@@ -7242,10 +7223,10 @@ static int cmd_resource_set(struct dl *dl)
if (err)
goto out;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_RESOURCE_DUMP,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_RESOURCE_DUMP,
NLM_F_REQUEST);
dl_opts_put(nlh, dl);
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_resource_dump_cb, &ctx);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_resource_dump_cb, &ctx);
if (err) {
pr_err("error getting resources %s\n", strerror(ctx.err));
goto out;
@@ -7259,11 +7240,11 @@ static int cmd_resource_set(struct dl *dl)
goto out;
}
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_RESOURCE_SET,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_RESOURCE_SET,
NLM_F_REQUEST | NLM_F_ACK);
dl_opts_put(nlh, dl);
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL);
out:
resource_ctx_fini(&ctx);
return err;
@@ -7404,7 +7385,7 @@ static int cmd_region_show(struct dl *dl)
if (dl_argc(dl) == 0)
flags |= NLM_F_DUMP;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_REGION_GET, flags);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_REGION_GET, flags);
if (dl_argc(dl) > 0) {
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE_REGION, 0);
@@ -7413,7 +7394,7 @@ static int cmd_region_show(struct dl *dl)
}
pr_out_section_start(dl, "regions");
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_region_show_cb, dl);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_region_show_cb, dl);
pr_out_section_end(dl);
return err;
}
@@ -7423,7 +7404,7 @@ static int cmd_region_snapshot_del(struct dl *dl)
struct nlmsghdr *nlh;
int err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_REGION_DEL,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_REGION_DEL,
NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE_REGION |
@@ -7431,7 +7412,7 @@ static int cmd_region_snapshot_del(struct dl *dl)
if (err)
return err;
- return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+ return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL);
}
static int cmd_region_read_cb(const struct nlmsghdr *nlh, void *data)
@@ -7473,7 +7454,7 @@ static int cmd_region_dump(struct dl *dl)
struct nlmsghdr *nlh;
int err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_REGION_READ,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_REGION_READ,
NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP);
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE_REGION |
@@ -7482,7 +7463,7 @@ static int cmd_region_dump(struct dl *dl)
return err;
pr_out_section_start(dl, "dump");
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_region_read_cb, dl);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_region_read_cb, dl);
pr_out_section_end(dl);
if (!dl->json_output)
pr_out("\n");
@@ -7494,7 +7475,7 @@ static int cmd_region_read(struct dl *dl)
struct nlmsghdr *nlh;
int err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_REGION_READ,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_REGION_READ,
NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP);
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE_REGION |
@@ -7504,7 +7485,7 @@ static int cmd_region_read(struct dl *dl)
return err;
pr_out_section_start(dl, "read");
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_region_read_cb, dl);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_region_read_cb, dl);
pr_out_section_end(dl);
if (!dl->json_output)
pr_out("\n");
@@ -7533,7 +7514,7 @@ static int cmd_region_snapshot_new(struct dl *dl)
struct nlmsghdr *nlh;
int err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_REGION_NEW,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_REGION_NEW,
NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE_REGION,
@@ -7542,7 +7523,7 @@ static int cmd_region_snapshot_new(struct dl *dl)
return err;
pr_out_section_start(dl, "regions");
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_region_snapshot_new_cb, dl);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_region_snapshot_new_cb, dl);
pr_out_section_end(dl);
return err;
}
@@ -7588,7 +7569,7 @@ static int cmd_health_set_params(struct dl *dl)
struct nlmsghdr *nlh;
int err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_HEALTH_REPORTER_SET,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_HEALTH_REPORTER_SET,
NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse(dl, DL_OPT_HANDLE | DL_OPT_HANDLEP | DL_OPT_HEALTH_REPORTER_NAME,
DL_OPT_HEALTH_REPORTER_GRACEFUL_PERIOD |
@@ -7598,7 +7579,7 @@ static int cmd_health_set_params(struct dl *dl)
return err;
dl_opts_put(nlh, dl);
- return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+ return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL);
}
static int cmd_health_dump_clear(struct dl *dl)
@@ -7606,7 +7587,7 @@ static int cmd_health_dump_clear(struct dl *dl)
struct nlmsghdr *nlh;
int err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_HEALTH_REPORTER_DUMP_CLEAR,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_HEALTH_REPORTER_DUMP_CLEAR,
NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse_put(nlh, dl,
@@ -7616,7 +7597,7 @@ static int cmd_health_dump_clear(struct dl *dl)
return err;
dl_opts_put(nlh, dl);
- return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+ return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL);
}
static int fmsg_value_show(struct dl *dl, int type, struct nlattr *nl_data)
@@ -7855,7 +7836,7 @@ static int cmd_health_object_common(struct dl *dl, uint8_t cmd, uint16_t flags)
struct nlmsghdr *nlh;
int err;
- nlh = mnlg_msg_prepare(dl->nlg, cmd, flags | NLM_F_REQUEST | NLM_F_ACK);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, cmd, flags | NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse_put(nlh, dl,
DL_OPT_HANDLE | DL_OPT_HANDLEP |
@@ -7864,7 +7845,7 @@ static int cmd_health_object_common(struct dl *dl, uint8_t cmd, uint16_t flags)
return err;
cmd_fmsg_init(dl, &data);
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_fmsg_object_cb, &data);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_fmsg_object_cb, &data);
free(data.name);
return err;
}
@@ -7895,7 +7876,7 @@ static int cmd_health_recover(struct dl *dl)
struct nlmsghdr *nlh;
int err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_HEALTH_REPORTER_RECOVER,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_HEALTH_REPORTER_RECOVER,
NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse_put(nlh, dl,
@@ -7905,7 +7886,7 @@ static int cmd_health_recover(struct dl *dl)
return err;
dl_opts_put(nlh, dl);
- return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+ return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL);
}
enum devlink_health_reporter_state {
@@ -8071,7 +8052,7 @@ static int __cmd_health_show(struct dl *dl, bool show_device, bool show_port)
if (dl_argc(dl) == 0)
flags |= NLM_F_DUMP;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_HEALTH_REPORTER_GET,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_HEALTH_REPORTER_GET,
flags);
if (dl_argc(dl) > 0) {
@@ -8084,7 +8065,7 @@ static int __cmd_health_show(struct dl *dl, bool show_device, bool show_port)
}
pr_out_section_start(dl, "health");
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_health_show_cb, &ctx);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_health_show_cb, &ctx);
pr_out_section_end(dl);
return err;
}
@@ -8253,7 +8234,7 @@ static int cmd_trap_show(struct dl *dl)
if (dl_argc(dl) == 0)
flags |= NLM_F_DUMP;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_TRAP_GET, flags);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_TRAP_GET, flags);
if (dl_argc(dl) > 0) {
err = dl_argv_parse_put(nlh, dl,
@@ -8263,7 +8244,7 @@ static int cmd_trap_show(struct dl *dl)
}
pr_out_section_start(dl, "trap");
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_trap_show_cb, dl);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_trap_show_cb, dl);
pr_out_section_end(dl);
return err;
@@ -8274,7 +8255,7 @@ static int cmd_trap_set(struct dl *dl)
struct nlmsghdr *nlh;
int err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_TRAP_SET,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_TRAP_SET,
NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE | DL_OPT_TRAP_NAME,
@@ -8282,7 +8263,7 @@ static int cmd_trap_set(struct dl *dl)
if (err)
return err;
- return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+ return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL);
}
static void pr_out_trap_group(struct dl *dl, struct nlattr **tb, bool array)
@@ -8328,7 +8309,7 @@ static int cmd_trap_group_show(struct dl *dl)
if (dl_argc(dl) == 0)
flags |= NLM_F_DUMP;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_TRAP_GROUP_GET, flags);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_TRAP_GROUP_GET, flags);
if (dl_argc(dl) > 0) {
err = dl_argv_parse_put(nlh, dl,
@@ -8339,7 +8320,7 @@ static int cmd_trap_group_show(struct dl *dl)
}
pr_out_section_start(dl, "trap_group");
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_trap_group_show_cb, dl);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_trap_group_show_cb, dl);
pr_out_section_end(dl);
return err;
@@ -8350,7 +8331,7 @@ static int cmd_trap_group_set(struct dl *dl)
struct nlmsghdr *nlh;
int err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_TRAP_GROUP_SET,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_TRAP_GROUP_SET,
NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse_put(nlh, dl,
@@ -8359,7 +8340,7 @@ static int cmd_trap_group_set(struct dl *dl)
if (err)
return err;
- return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+ return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL);
}
static int cmd_trap_group(struct dl *dl)
@@ -8425,7 +8406,7 @@ static int cmd_trap_policer_show(struct dl *dl)
if (dl_argc(dl) == 0)
flags |= NLM_F_DUMP;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_TRAP_POLICER_GET, flags);
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_TRAP_POLICER_GET, flags);
if (dl_argc(dl) > 0) {
err = dl_argv_parse_put(nlh, dl,
@@ -8436,7 +8417,7 @@ static int cmd_trap_policer_show(struct dl *dl)
}
pr_out_section_start(dl, "trap_policer");
- err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_trap_policer_show_cb, dl);
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_trap_policer_show_cb, dl);
pr_out_section_end(dl);
return err;
@@ -8447,7 +8428,7 @@ static int cmd_trap_policer_set(struct dl *dl)
struct nlmsghdr *nlh;
int err;
- nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_TRAP_POLICER_SET,
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_TRAP_POLICER_SET,
NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse_put(nlh, dl,
@@ -8457,7 +8438,7 @@ static int cmd_trap_policer_set(struct dl *dl)
if (err)
return err;
- return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+ return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL);
}
static int cmd_trap_policer(struct dl *dl)
@@ -8552,8 +8533,9 @@ static int dl_init(struct dl *dl)
{
int err;
- dl->nlg = mnlg_socket_open(DEVLINK_GENL_NAME, DEVLINK_GENL_VERSION);
- if (!dl->nlg) {
+ err = mnlu_gen_socket_open(&dl->nlg, DEVLINK_GENL_NAME,
+ DEVLINK_GENL_VERSION);
+ if (err) {
pr_err("Failed to connect to devlink Netlink\n");
return -errno;
}
@@ -8567,7 +8549,7 @@ static int dl_init(struct dl *dl)
return 0;
err_ifname_map_create:
- mnlg_socket_close(dl->nlg);
+ mnlu_gen_socket_close(&dl->nlg);
return err;
}
@@ -8575,7 +8557,7 @@ static void dl_fini(struct dl *dl)
{
delete_json_obj_plain();
ifname_map_fini(dl);
- mnlg_socket_close(dl->nlg);
+ mnlu_gen_socket_close(&dl->nlg);
}
static struct dl *dl_alloc(void)
@@ -30,38 +30,11 @@ struct mnlg_socket {
unsigned int seq;
};
-static struct nlmsghdr *__mnlg_msg_prepare(struct mnlg_socket *nlg, uint8_t cmd,
- uint16_t flags, uint32_t id,
- uint8_t version)
-{
- struct genlmsghdr genl = {
- .cmd = cmd,
- .version = version,
- };
- struct nlmsghdr *nlh;
-
- nlh = mnlu_msg_prepare(nlg->buf, id, flags, &genl, sizeof(genl));
- nlg->seq = nlh->nlmsg_seq;
- return nlh;
-}
-
-struct nlmsghdr *mnlg_msg_prepare(struct mnlg_socket *nlg, uint8_t cmd,
- uint16_t flags)
-{
- return __mnlg_msg_prepare(nlg, cmd, flags, nlg->id, nlg->version);
-}
-
-int mnlg_socket_send(struct mnlg_socket *nlg, const struct nlmsghdr *nlh)
+int mnlg_socket_send(struct mnlu_gen_socket *nlg, const struct nlmsghdr *nlh)
{
return mnl_socket_sendto(nlg->nl, nlh, nlh->nlmsg_len);
}
-int mnlg_socket_recv_run(struct mnlg_socket *nlg, mnl_cb_t data_cb, void *data)
-{
- return mnlu_socket_recv_run(nlg->nl, nlg->seq, nlg->buf, MNL_SOCKET_BUFFER_SIZE,
- data_cb, data);
-}
-
struct group_info {
bool found;
uint32_t id;
@@ -141,15 +114,17 @@ static int get_group_id_cb(const struct nlmsghdr *nlh, void *data)
return MNL_CB_OK;
}
-int mnlg_socket_group_add(struct mnlg_socket *nlg, const char *group_name)
+int mnlg_socket_group_add(struct mnlu_gen_socket *nlg, const char *group_name)
{
struct nlmsghdr *nlh;
struct group_info group_info;
int err;
- nlh = __mnlg_msg_prepare(nlg, CTRL_CMD_GETFAMILY,
- NLM_F_REQUEST | NLM_F_ACK, GENL_ID_CTRL, 1);
- mnl_attr_put_u16(nlh, CTRL_ATTR_FAMILY_ID, nlg->id);
+ nlh = _mnlu_gen_socket_cmd_prepare(nlg, CTRL_CMD_GETFAMILY,
+ NLM_F_REQUEST | NLM_F_ACK,
+ GENL_ID_CTRL, 1);
+
+ mnl_attr_put_u16(nlh, CTRL_ATTR_FAMILY_ID, nlg->family);
err = mnlg_socket_send(nlg, nlh);
if (err < 0)
@@ -157,7 +132,7 @@ int mnlg_socket_group_add(struct mnlg_socket *nlg, const char *group_name)
group_info.found = false;
group_info.name = group_name;
- err = mnlg_socket_recv_run(nlg, get_group_id_cb, &group_info);
+ err = mnlu_gen_socket_recv_run(nlg, get_group_id_cb, &group_info);
if (err < 0)
return err;
@@ -174,85 +149,7 @@ int mnlg_socket_group_add(struct mnlg_socket *nlg, const char *group_name)
return 0;
}
-static int get_family_id_attr_cb(const struct nlattr *attr, void *data)
-{
- const struct nlattr **tb = data;
- int type = mnl_attr_get_type(attr);
-
- if (mnl_attr_type_valid(attr, CTRL_ATTR_MAX) < 0)
- return MNL_CB_ERROR;
-
- if (type == CTRL_ATTR_FAMILY_ID &&
- mnl_attr_validate(attr, MNL_TYPE_U16) < 0)
- return MNL_CB_ERROR;
- tb[type] = attr;
- return MNL_CB_OK;
-}
-
-static int get_family_id_cb(const struct nlmsghdr *nlh, void *data)
-{
- uint32_t *p_id = data;
- struct nlattr *tb[CTRL_ATTR_MAX + 1] = {};
- struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-
- mnl_attr_parse(nlh, sizeof(*genl), get_family_id_attr_cb, tb);
- if (!tb[CTRL_ATTR_FAMILY_ID])
- return MNL_CB_ERROR;
- *p_id = mnl_attr_get_u16(tb[CTRL_ATTR_FAMILY_ID]);
- return MNL_CB_OK;
-}
-
-struct mnlg_socket *mnlg_socket_open(const char *family_name, uint8_t version)
-{
- struct mnlg_socket *nlg;
- struct nlmsghdr *nlh;
- int err;
-
- nlg = malloc(sizeof(*nlg));
- if (!nlg)
- return NULL;
-
- nlg->buf = malloc(MNL_SOCKET_BUFFER_SIZE);
- if (!nlg->buf)
- goto err_buf_alloc;
-
- nlg->nl = mnlu_socket_open(NETLINK_GENERIC);
- if (!nlg->nl)
- goto err_socket_open;
-
- nlh = __mnlg_msg_prepare(nlg, CTRL_CMD_GETFAMILY,
- NLM_F_REQUEST | NLM_F_ACK, GENL_ID_CTRL, 1);
- mnl_attr_put_strz(nlh, CTRL_ATTR_FAMILY_NAME, family_name);
-
- err = mnlg_socket_send(nlg, nlh);
- if (err < 0)
- goto err_mnlg_socket_send;
-
- err = mnlg_socket_recv_run(nlg, get_family_id_cb, &nlg->id);
- if (err < 0)
- goto err_mnlg_socket_recv_run;
-
- nlg->version = version;
- return nlg;
-
-err_mnlg_socket_recv_run:
-err_mnlg_socket_send:
- mnl_socket_close(nlg->nl);
-err_socket_open:
- free(nlg->buf);
-err_buf_alloc:
- free(nlg);
- return NULL;
-}
-
-void mnlg_socket_close(struct mnlg_socket *nlg)
-{
- mnl_socket_close(nlg->nl);
- free(nlg->buf);
- free(nlg);
-}
-
-int mnlg_socket_get_fd(struct mnlg_socket *nlg)
+int mnlg_socket_get_fd(struct mnlu_gen_socket *nlg)
{
return mnl_socket_get_fd(nlg->nl);
}
@@ -14,15 +14,10 @@
#include <libmnl/libmnl.h>
-struct mnlg_socket;
+struct mnlu_gen_socket;
-struct nlmsghdr *mnlg_msg_prepare(struct mnlg_socket *nlg, uint8_t cmd,
- uint16_t flags);
-int mnlg_socket_send(struct mnlg_socket *nlg, const struct nlmsghdr *nlh);
-int mnlg_socket_recv_run(struct mnlg_socket *nlg, mnl_cb_t data_cb, void *data);
-int mnlg_socket_group_add(struct mnlg_socket *nlg, const char *group_name);
-struct mnlg_socket *mnlg_socket_open(const char *family_name, uint8_t version);
-void mnlg_socket_close(struct mnlg_socket *nlg);
-int mnlg_socket_get_fd(struct mnlg_socket *nlg);
+int mnlg_socket_send(struct mnlu_gen_socket *nlg, const struct nlmsghdr *nlh);
+int mnlg_socket_group_add(struct mnlu_gen_socket *nlg, const char *group_name);
+int mnlg_socket_get_fd(struct mnlu_gen_socket *nlg);
#endif /* _MNLG_H_ */