All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: linux-wireless@vger.kernel.org, netdev@vger.kernel.org
Cc: pablo@netfilter.org, Jamal Hadi Salim <jhs@mojatatu.com>,
	Jiri Benc <jbenc@redhat.com>,
	David Ahern <dsa@cumulusnetworks.com>,
	jiri@resnulli.us
Subject: Re: [PATCH v3 0/5] netlink extended ACK reporting
Date: Mon, 10 Apr 2017 13:38:25 +0200	[thread overview]
Message-ID: <1491824305.2455.10.camel@sipsolutions.net> (raw)
In-Reply-To: <20170408202434.12018-1-johannes@sipsolutions.net> (sfid-20170408_222447_224133_39B19566)

Here's a simple iw patch that shows the error message string:

--- a/iw.c
+++ b/iw.c
@@ -62,6 +62,10 @@ static int nl80211_init(struct nl80211_state *state)
 
 	nl_socket_set_buffer_size(state->nl_sock, 8192, 8192);
 
+	/* try to set NETLINK_EXT_ACK to 1 (ignore errors) */
+	err = 1;
+	setsockopt(nl_socket_get_fd(state->nl_sock), SOL_NETLINK, 11, &err, sizeof(err));
+
 	state->nl80211_id = genl_ctrl_resolve(state->nl_sock, "nl80211");
 	if (state->nl80211_id < 0) {
 		fprintf(stderr, "nl80211 not found.\n");
@@ -270,11 +274,45 @@ static int phy_lookup(char *name)
 	return atoi(buf);
 }
 
+#ifndef NETLINK_EXT_ACK
+enum nlmsgerr_attrs {
+	NLMSGERR_ATTR_UNUSED,
+	NLMSGERR_ATTR_MSG,
+	NLMSGERR_ATTR_OFFS,
+	NLMSGERR_ATTR_ATTR,
+	NLMSGERR_ATTR_COOKIE,
+
+	NUM_NLMSGERR_ATTRS,
+	NLMSGERR_ATTR_MAX = NUM_NLMSGERR_ATTRS - 1
+};
+#endif
+
 static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err,
 			 void *arg)
 {
+	struct nlmsghdr *nlh = (struct nlmsghdr *)err - 1;
+	int len = nlh->nlmsg_len;
+	struct nlattr *attrs;
+	struct nlattr *tb[NUM_NLMSGERR_ATTRS];
 	int *ret = arg;
+	int ack_len = sizeof(*nlh) + sizeof(int) + err->msg.nlmsg_len;
+
 	*ret = err->error;
+
+	if (len <= ack_len)
+		return NL_STOP;
+
+	attrs = (void *)((unsigned char *)nlh + ack_len);
+	len -= ack_len;
+
+	nla_parse(tb, NLMSGERR_ATTR_MAX, attrs, len, NULL);
+	if (tb[NLMSGERR_ATTR_MSG]) {
+		len = strnlen((char *)nla_data(tb[NLMSGERR_ATTR_MSG]),
+			      nla_len(tb[NLMSGERR_ATTR_MSG]));
+		fprintf(stderr, "kernel reports: %*s\n", len,
+			(char *)nla_data(tb[NLMSGERR_ATTR_MSG]));
+	}
+
 	return NL_STOP;
 }
 

johannes

      parent reply	other threads:[~2017-04-10 11:38 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-08 20:24 [PATCH v3 0/5] netlink extended ACK reporting Johannes Berg
2017-04-08 20:24 ` Johannes Berg
2017-04-08 20:24 ` [PATCH v3 1/5] netlink: " Johannes Berg
2017-04-08 20:24   ` Johannes Berg
2017-04-10 15:26   ` David Ahern
2017-04-10 15:30     ` Johannes Berg
2017-04-10 15:30       ` Johannes Berg
2017-04-10 15:35       ` David Ahern
2017-04-10 15:40         ` Johannes Berg
2017-04-10 15:40           ` Johannes Berg
2017-04-10 18:38           ` Johannes Berg
2017-04-11  6:59         ` Pablo Neira Ayuso
2017-04-11  7:02           ` Johannes Berg
2017-04-11 14:25             ` David Ahern
2017-04-11 14:25               ` David Ahern
2017-04-11 17:31               ` Pablo Neira Ayuso
2017-04-11 17:31                 ` Pablo Neira Ayuso
2017-04-11 17:42                 ` David Miller
2017-04-11 18:57                   ` David Ahern
2017-04-11 19:05                     ` David Miller
2017-04-11 19:12                       ` David Ahern
2017-04-11 19:12                         ` David Ahern
2017-04-11 19:43                   ` Johannes Berg
2017-04-08 20:24 ` [PATCH v3 2/5] genetlink: pass extended ACK report down Johannes Berg
2017-04-08 20:24   ` Johannes Berg
2017-04-08 20:24 ` [PATCH v3 3/5] netlink: allow sending extended ACK with cookie on success Johannes Berg
2017-04-08 20:24 ` [PATCH v3 4/5] netlink: pass extended ACK struct to parsing functions Johannes Berg
2017-04-08 20:24 ` [PATCH v3 5/5] netlink: pass extended ACK struct where available Johannes Berg
2017-04-10 11:20 ` [PATCH v3 0/5] netlink extended ACK reporting Johannes Berg
2017-04-10 11:38 ` Johannes Berg [this message]

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=1491824305.2455.10.camel@sipsolutions.net \
    --to=johannes@sipsolutions.net \
    --cc=dsa@cumulusnetworks.com \
    --cc=jbenc@redhat.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=linux-wireless@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pablo@netfilter.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.