* [PATCH ethtool] netlink: show netlink error even without extack
@ 2020-03-30 7:28 Michal Kubecek
0 siblings, 0 replies; 3+ messages in thread
From: Michal Kubecek @ 2020-03-30 7:28 UTC (permalink / raw)
To: John Linville, netdev
Even if the NLMSG_ERROR message has no extack (NLM_F_ACK_TLVS not set, i.e.
no error/warning message and bad attribute offset), we still want to
display the error code (unless suppressed) and, if pretty printing is
enabled, the embedded client message (if present).
Fixes: 50efb3cdd2bb ("netlink: netlink socket wrapper and helpers")
Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
---
netlink/nlsock.c | 37 +++++++++++++++++--------------------
1 file changed, 17 insertions(+), 20 deletions(-)
diff --git a/netlink/nlsock.c b/netlink/nlsock.c
index 22abb68b6646..2c760b770ec5 100644
--- a/netlink/nlsock.c
+++ b/netlink/nlsock.c
@@ -173,25 +173,25 @@ static int nlsock_process_ack(struct nlmsghdr *nlhdr, ssize_t len,
{
const struct nlattr *tb[NLMSGERR_ATTR_MAX + 1] = {};
DECLARE_ATTR_TB_INFO(tb);
+ unsigned int err_offset = 0;
unsigned int tlv_offset;
struct nlmsgerr *nlerr;
bool silent;
- if (len < NLMSG_HDRLEN + sizeof(*nlerr))
+ if ((len < NLMSG_HDRLEN + sizeof(*nlerr)) || (len < nlhdr->nlmsg_len))
return -EFAULT;
nlerr = mnl_nlmsg_get_payload(nlhdr);
- silent = (!(nlhdr->nlmsg_flags & NLM_F_ACK_TLVS) ||
- suppress_nlerr >= 2 ||
- (suppress_nlerr && nlerr->error == -EOPNOTSUPP));
- if (silent)
- goto out;
+ silent = suppress_nlerr >= 2 ||
+ (suppress_nlerr && nlerr->error == -EOPNOTSUPP);
+ if (silent || !(nlhdr->nlmsg_flags & NLM_F_ACK_TLVS))
+ goto tlv_done;
tlv_offset = sizeof(*nlerr);
if (!(nlhdr->nlmsg_flags & NLM_F_CAPPED))
tlv_offset += MNL_ALIGN(mnl_nlmsg_get_payload_len(&nlerr->msg));
-
if (mnl_attr_parse(nlhdr, tlv_offset, attr_cb, &tb_info) < 0)
- goto out;
+ goto tlv_done;
+
if (tb[NLMSGERR_ATTR_MSG]) {
const char *msg = mnl_attr_get_str(tb[NLMSGERR_ATTR_MSG]);
@@ -202,24 +202,21 @@ static int nlsock_process_ack(struct nlmsghdr *nlhdr, ssize_t len,
mnl_attr_get_u32(tb[NLMSGERR_ATTR_OFFS]));
fputc('\n', stderr);
}
+ if (tb[NLMSGERR_ATTR_OFFS])
+ err_offset = mnl_attr_get_u32(tb[NLMSGERR_ATTR_OFFS]);
- if (nlerr->error && pretty) {
- unsigned int err_offset = 0;
-
- if (tb[NLMSGERR_ATTR_OFFS])
- err_offset = mnl_attr_get_u32(tb[NLMSGERR_ATTR_OFFS]);
+tlv_done:
+ if (nlerr->error && !silent) {
+ errno = -nlerr->error;
+ perror("netlink error");
+ }
+ if (pretty && !(nlhdr->nlmsg_flags & NLM_F_CAPPED) &&
+ nlhdr->nlmsg_len >= NLMSG_HDRLEN + nlerr->msg.nlmsg_len) {
fprintf(stderr, "offending message%s:\n",
err_offset ? " and attribute" : "");
pretty_print_genlmsg(&nlerr->msg, ethnl_umsg_desc,
ethnl_umsg_n_desc, err_offset);
}
-
-out:
- if (nlerr->error) {
- errno = -nlerr->error;
- if (!silent)
- perror("netlink error");
- }
return nlerr->error;
}
--
2.26.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH ethtool] netlink: show netlink error even without extack
2020-03-30 7:33 Michal Kubecek
@ 2020-03-30 7:54 ` Michal Kubecek
0 siblings, 0 replies; 3+ messages in thread
From: Michal Kubecek @ 2020-03-30 7:54 UTC (permalink / raw)
To: John Linville, netdev
Sorry for the resend, I sent the first from wrong machine and thought it
was rejected because of that; as it shows, it was only greylisted.
The two mails differ only in SMTP headers.
Michal
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH ethtool] netlink: show netlink error even without extack
@ 2020-03-30 7:33 Michal Kubecek
2020-03-30 7:54 ` Michal Kubecek
0 siblings, 1 reply; 3+ messages in thread
From: Michal Kubecek @ 2020-03-30 7:33 UTC (permalink / raw)
To: John Linville, netdev
Even if the NLMSG_ERROR message has no extack (NLM_F_ACK_TLVS not set, i.e.
no error/warning message and bad attribute offset), we still want to
display the error code (unless suppressed) and, if pretty printing is
enabled, the embedded client message (if present).
Fixes: 50efb3cdd2bb ("netlink: netlink socket wrapper and helpers")
Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
---
netlink/nlsock.c | 37 +++++++++++++++++--------------------
1 file changed, 17 insertions(+), 20 deletions(-)
diff --git a/netlink/nlsock.c b/netlink/nlsock.c
index 22abb68b6646..2c760b770ec5 100644
--- a/netlink/nlsock.c
+++ b/netlink/nlsock.c
@@ -173,25 +173,25 @@ static int nlsock_process_ack(struct nlmsghdr *nlhdr, ssize_t len,
{
const struct nlattr *tb[NLMSGERR_ATTR_MAX + 1] = {};
DECLARE_ATTR_TB_INFO(tb);
+ unsigned int err_offset = 0;
unsigned int tlv_offset;
struct nlmsgerr *nlerr;
bool silent;
- if (len < NLMSG_HDRLEN + sizeof(*nlerr))
+ if ((len < NLMSG_HDRLEN + sizeof(*nlerr)) || (len < nlhdr->nlmsg_len))
return -EFAULT;
nlerr = mnl_nlmsg_get_payload(nlhdr);
- silent = (!(nlhdr->nlmsg_flags & NLM_F_ACK_TLVS) ||
- suppress_nlerr >= 2 ||
- (suppress_nlerr && nlerr->error == -EOPNOTSUPP));
- if (silent)
- goto out;
+ silent = suppress_nlerr >= 2 ||
+ (suppress_nlerr && nlerr->error == -EOPNOTSUPP);
+ if (silent || !(nlhdr->nlmsg_flags & NLM_F_ACK_TLVS))
+ goto tlv_done;
tlv_offset = sizeof(*nlerr);
if (!(nlhdr->nlmsg_flags & NLM_F_CAPPED))
tlv_offset += MNL_ALIGN(mnl_nlmsg_get_payload_len(&nlerr->msg));
-
if (mnl_attr_parse(nlhdr, tlv_offset, attr_cb, &tb_info) < 0)
- goto out;
+ goto tlv_done;
+
if (tb[NLMSGERR_ATTR_MSG]) {
const char *msg = mnl_attr_get_str(tb[NLMSGERR_ATTR_MSG]);
@@ -202,24 +202,21 @@ static int nlsock_process_ack(struct nlmsghdr *nlhdr, ssize_t len,
mnl_attr_get_u32(tb[NLMSGERR_ATTR_OFFS]));
fputc('\n', stderr);
}
+ if (tb[NLMSGERR_ATTR_OFFS])
+ err_offset = mnl_attr_get_u32(tb[NLMSGERR_ATTR_OFFS]);
- if (nlerr->error && pretty) {
- unsigned int err_offset = 0;
-
- if (tb[NLMSGERR_ATTR_OFFS])
- err_offset = mnl_attr_get_u32(tb[NLMSGERR_ATTR_OFFS]);
+tlv_done:
+ if (nlerr->error && !silent) {
+ errno = -nlerr->error;
+ perror("netlink error");
+ }
+ if (pretty && !(nlhdr->nlmsg_flags & NLM_F_CAPPED) &&
+ nlhdr->nlmsg_len >= NLMSG_HDRLEN + nlerr->msg.nlmsg_len) {
fprintf(stderr, "offending message%s:\n",
err_offset ? " and attribute" : "");
pretty_print_genlmsg(&nlerr->msg, ethnl_umsg_desc,
ethnl_umsg_n_desc, err_offset);
}
-
-out:
- if (nlerr->error) {
- errno = -nlerr->error;
- if (!silent)
- perror("netlink error");
- }
return nlerr->error;
}
--
2.26.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-03-30 7:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-30 7:28 [PATCH ethtool] netlink: show netlink error even without extack Michal Kubecek
2020-03-30 7:33 Michal Kubecek
2020-03-30 7:54 ` Michal Kubecek
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).