From 80059fa5c5ed5b91e4239163578b37cf829d8772 Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Tue, 27 Sep 2022 18:21:06 +0800 Subject: [PATCH] libnetlink: add offset for nl_dump_ext_ack_done There is no rule to have an error code after NLMSG_DONE msg. The only reason we has this offset is that kernel function netlink_dump_done() has an error code followed by the netlink message header. Making nl_dump_ext_ack_done() has an offset parameter. So we can adjust this for NLMSG_DONE message without error code. Signed-off-by: Hangbin Liu Signed-off-by: David Ahern --- include/libnetlink.h | 2 +- lib/libnetlink.c | 9 ++++----- lib/mnl_utils.c | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/include/libnetlink.h b/include/libnetlink.h index a7b0f3523..1c49920d6 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -185,7 +185,7 @@ int rtnl_send(struct rtnl_handle *rth, const void *buf, int) int rtnl_send_check(struct rtnl_handle *rth, const void *buf, int) __attribute__((warn_unused_result)); int nl_dump_ext_ack(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn); -int nl_dump_ext_ack_done(const struct nlmsghdr *nlh, int error); +int nl_dump_ext_ack_done(const struct nlmsghdr *nlh, unsigned int offset, int error); int addattr(struct nlmsghdr *n, int maxlen, int type); int addattr8(struct nlmsghdr *n, int maxlen, int type, __u8 data); diff --git a/lib/libnetlink.c b/lib/libnetlink.c index c27627fed..1461b1ca3 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -129,13 +129,12 @@ int nl_dump_ext_ack(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn) return 0; } -int nl_dump_ext_ack_done(const struct nlmsghdr *nlh, int error) +int nl_dump_ext_ack_done(const struct nlmsghdr *nlh, unsigned int offset, int error) { struct nlattr *tb[NLMSGERR_ATTR_MAX + 1] = {}; - unsigned int hlen = sizeof(int); const char *msg = NULL; - if (mnl_attr_parse(nlh, hlen, err_attr_cb, tb) != MNL_CB_OK) + if (mnl_attr_parse(nlh, offset, err_attr_cb, tb) != MNL_CB_OK) return 0; if (tb[NLMSGERR_ATTR_MSG]) @@ -159,7 +158,7 @@ int nl_dump_ext_ack(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn) return 0; } -int nl_dump_ext_ack_done(const struct nlmsghdr *nlh, int error) +int nl_dump_ext_ack_done(const struct nlmsghdr *nlh, unsigned int offset, int error) { return 0; } @@ -747,7 +746,7 @@ static int rtnl_dump_done(struct nlmsghdr *h, return 0; /* check for any messages returned from kernel */ - if (nl_dump_ext_ack_done(h, len)) + if (nl_dump_ext_ack_done(h, sizeof(int), len)) return len; switch (errno) { diff --git a/lib/mnl_utils.c b/lib/mnl_utils.c index 79bac5cfd..f8e07d2f4 100644 --- a/lib/mnl_utils.c +++ b/lib/mnl_utils.c @@ -79,7 +79,7 @@ static int mnlu_cb_stop(const struct nlmsghdr *nlh, void *data) if (len < 0) { errno = -len; - nl_dump_ext_ack_done(nlh, len); + nl_dump_ext_ack_done(nlh, sizeof(int), len); return MNL_CB_ERROR; } return MNL_CB_STOP; -- 2.47.3