From: Hangbin Liu <liuhangbin@gmail.com>
To: netdev@vger.kernel.org
Cc: Jamal Hadi Salim <jhs@mojatatu.com>,
Cong Wang <xiyou.wangcong@gmail.com>,
Jiri Pirko <jiri@resnulli.us>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
David Ahern <dsahern@kernel.org>,
Hangbin Liu <liuhangbin@gmail.com>
Subject: [PATCH iproute2-next 1/2] libnetlink: add offset for nl_dump_ext_ack_done
Date: Tue, 27 Sep 2022 18:21:06 +0800 [thread overview]
Message-ID: <20220927102107.191852-1-liuhangbin@gmail.com> (raw)
In-Reply-To: <20220927101755.191352-1-liuhangbin@gmail.com>
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 <liuhangbin@gmail.com>
---
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 a7b0f352..1c49920d 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 c27627fe..1461b1ca 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 79bac5cf..f8e07d2f 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.37.2
next prev parent reply other threads:[~2022-09-27 10:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-27 10:17 [PATCH net-next] sched: add extack for tfilter_notify Hangbin Liu
2022-09-27 10:21 ` Hangbin Liu [this message]
2022-09-28 3:30 ` [PATCH iproute2-next 1/2] libnetlink: add offset for nl_dump_ext_ack_done patchwork-bot+netdevbpf
2022-09-27 10:21 ` [PATCH iproute2-next 2/2] tc/tc_monitor: print netlink extack message Hangbin Liu
2022-09-28 3:30 ` [PATCH net-next] sched: add extack for tfilter_notify patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220927102107.191852-1-liuhangbin@gmail.com \
--to=liuhangbin@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=xiyou.wangcong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).