]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
iw: add extack support
authorJohannes Berg <johannes.berg@intel.com>
Thu, 13 Apr 2017 13:53:25 +0000 (15:53 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Thu, 7 Sep 2017 08:43:07 +0000 (10:43 +0200)
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
iw.c
iw.h

diff --git a/iw.c b/iw.c
index 6ec5a12536e74f80bf3f43b0e95ae7957185d316..50fa3b8e70e996b19d9036d386c858f251bc5af7 100644 (file)
--- a/iw.c
+++ b/iw.c
@@ -62,6 +62,11 @@ 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, ignoring errors */
+       err = 1;
+       setsockopt(nl_socket_get_fd(state->nl_sock), SOL_NETLINK,
+                  NETLINK_EXT_ACK, &err, sizeof(err));
+
        state->nl80211_id = genl_ctrl_resolve(state->nl_sock, "nl80211");
        if (state->nl80211_id < 0) {
                fprintf(stderr, "nl80211 not found.\n");
@@ -273,8 +278,35 @@ static int phy_lookup(char *name)
 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[NLMSGERR_ATTR_MAX + 1];
        int *ret = arg;
+       int ack_len = sizeof(*nlh) + sizeof(int) + sizeof(*nlh);
+
        *ret = err->error;
+
+       if (!(nlh->nlmsg_flags & NLM_F_ACK_TLVS))
+               return NL_STOP;
+
+       if (!(nlh->nlmsg_flags & NLM_F_CAPPED))
+               ack_len += err->msg.nlmsg_len - sizeof(*nlh);
+
+       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;
 }
 
diff --git a/iw.h b/iw.h
index df5fb9b8265a004b0ea56eee58f7ffafed0d08d1..67e011e9e132952a842c8c2fcb75989ddf504e3e 100644 (file)
--- a/iw.h
+++ b/iw.h
 #include "nl80211.h"
 #include "ieee80211.h"
 
+/* support for extack if compilation headers are too old */
+#ifndef NETLINK_EXT_ACK
+#define NETLINK_EXT_ACK 11
+enum nlmsgerr_attrs {
+       NLMSGERR_ATTR_UNUSED,
+       NLMSGERR_ATTR_MSG,
+       NLMSGERR_ATTR_OFFS,
+       NLMSGERR_ATTR_COOKIE,
+
+       __NLMSGERR_ATTR_MAX,
+       NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1
+};
+#endif
+#ifndef NLM_F_CAPPED
+#define NLM_F_CAPPED 0x100
+#endif
+#ifndef NLM_F_ACK_TLVS
+#define NLM_F_ACK_TLVS 0x200
+#endif
+
 #define ETH_ALEN 6
 #define VHT_MUMIMO_GROUP_LEN 24