From: Andrew Zaborowski <andrew.zaborowski at intel.com>
To: ell at lists.01.org
Subject: [PATCH 3/3] netlink: Enable extended ACKs if debug handler set
Date: Sat, 11 Jun 2022 03:45:45 +0200 [thread overview]
Message-ID: <20220611014545.1466270-3-andrew.zaborowski@intel.com> (raw)
In-Reply-To: 20220611014545.1466270-1-andrew.zaborowski@intel.com
[-- Attachment #1: Type: text/plain, Size: 2495 bytes --]
Enable the NETLINK_EXT_ACK socket option on netlink sockets if debug
logging is enabled so as to show the error message strings from the
kernel.
---
ell/netlink.c | 36 +++++++++++++++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/ell/netlink.c b/ell/netlink.c
index 32d021b..bab76f8 100644
--- a/ell/netlink.c
+++ b/ell/netlink.c
@@ -158,6 +158,31 @@ static void process_broadcast(struct l_netlink *netlink, uint32_t group,
l_hashmap_foreach(notify_list, do_notify, nlmsg);
}
+static void process_ext_ack(struct l_netlink *netlink,
+ const struct nlmsghdr *nlmsg)
+{
+ const char *err_str = NULL;
+ uint32_t err_offset = -1U;
+ _auto_(l_free) char *dbg_str = NULL;
+
+ if (!netlink->debug_handler ||
+ !netlink_parse_ext_ack(nlmsg, &err_str, &err_offset) ||
+ (!err_str && err_offset == -1U))
+ return;
+
+ if (err_str && err_offset != -1U)
+ dbg_str = l_strdup_printf("Extended error: '%s', offset of "
+ " offending element within request: "
+ "%i bytes", err_str, (int) err_offset);
+ else if (err_str)
+ dbg_str = l_strdup_printf("Extended error: '%s'", err_str);
+ else
+ dbg_str = l_strdup_printf("Offset of offending element within "
+ "request: %i bytes", (int) err_offset);
+
+ netlink->debug_handler(dbg_str, netlink->debug_data);
+}
+
static void process_message(struct l_netlink *netlink, struct nlmsghdr *nlmsg)
{
const void *data = nlmsg;
@@ -176,10 +201,12 @@ static void process_message(struct l_netlink *netlink, struct nlmsghdr *nlmsg)
switch (nlmsg->nlmsg_type) {
case NLMSG_ERROR:
- err = data + NLMSG_HDRLEN;
+ err = NLMSG_DATA(nlmsg);
command->handler(err->error, 0, NULL, 0,
command->user_data);
+
+ process_ext_ack(netlink, nlmsg);
break;
}
} else {
@@ -597,6 +624,8 @@ LIB_EXPORT bool l_netlink_set_debug(struct l_netlink *netlink,
l_netlink_debug_func_t function,
void *user_data, l_netlink_destroy_func_t destroy)
{
+ int ext_ack;
+
if (unlikely(!netlink))
return false;
@@ -609,6 +638,11 @@ LIB_EXPORT bool l_netlink_set_debug(struct l_netlink *netlink,
/* l_io_set_debug(netlink->io, function, user_data, NULL); */
+ ext_ack = function != NULL;
+ if (setsockopt(l_io_get_fd(netlink->io), SOL_NETLINK, NETLINK_EXT_ACK,
+ &ext_ack, sizeof(ext_ack)) < 0 && function)
+ function("Failed to set NETLINK_EXT_ACK", user_data);
+
return true;
}
--
2.34.1
reply other threads:[~2022-06-11 1:45 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220611014545.1466270-3-andrew.zaborowski@intel.com \
--to=ell@lists.linux.dev \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).