【发布时间】:2023-04-08 13:55:01
【问题描述】:
当我运行以下代码时,我正在尝试使用 libnl 和通用 netlink 发送抽象数据:
struct nl_msg *msg;
struct nl_data *abstract;
int err = -1;
if ((msg = nlmsg_alloc()) == NULL)
return err;
if ((genlmsg_put(msg, ctrl->pid, NL_AUTO_SEQ, ctrl->genl_family,
0, NLM_F_REQUEST, CREATE_STATE, KLUA_VERSION) == NULL))
return err;
if ((err = nla_put_string(msg, STATE_NAME, cmd->name)))
return err;
if ((err = nl_send_auto(ctrl->sock, msg)) < 0)
return err;
nlmsg_free(msg);
内核很好地接收到消息。但是,如果我为此更改此代码:
struct nl_msg *msg;
struct nl_data *abstract;
int err = -1;
if ((msg = nlmsg_alloc()) == NULL)
return err;
if ((abstract = nl_data_alloc(cmd, sizeof(struct klua_nl_state))) == NULL)
return err;
if ((genlmsg_put(msg, ctrl->pid, NL_AUTO_SEQ, ctrl->genl_family,
0, NLM_F_REQUEST, CREATE_STATE, KLUA_VERSION) == NULL))
return err;
nla_put_data(msg, TEST_ATTR, abstract);
if ((err = nl_send_auto(ctrl->sock, msg)) < 0)
return err;
nlmsg_free(msg);
顺便说一下,我的TEST_ATTR定义为:
[TEST_ATTR] = {.type = NLA_UNSPEC}
如果我只更改消息的有效负载,为什么内核没有收到我的消息? 如何通过通用 netlink 和 libnl 发送抽象数据?
【问题讨论】:
-
是否有需要(重新)计算的 CRC(或类似的)?
-
我已经成功了,但是内核仍然没有收到消息,顺便说一下,我知道消息正在发送,因为我激活了libnl的调试功能并且消息正在发送成功,问题出在接收部分。