Wireless Daemon for Linux
 help / color / mirror / Atom feed
From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.linux.dev
Cc: James Prestwood <prestwoj@gmail.com>
Subject: [PATCH 2/7] nl80211util: use nl80211_parse_attrs/nested for get_key_seq
Date: Tue, 25 Jun 2024 06:06:19 -0700	[thread overview]
Message-ID: <20240625130624.385553-2-prestwoj@gmail.com> (raw)
In-Reply-To: <20240625130624.385553-1-prestwoj@gmail.com>

This really reduces the number of checks needed and overall function
length by using the helper APIs.
---
 src/nl80211util.c | 51 +++++++++++++++++++++++------------------------
 1 file changed, 25 insertions(+), 26 deletions(-)

diff --git a/src/nl80211util.c b/src/nl80211util.c
index ac4ad223..eaf9f610 100644
--- a/src/nl80211util.c
+++ b/src/nl80211util.c
@@ -184,6 +184,7 @@ static attr_handler handler_for_nl80211(int type)
 		return extract_iovec;
 	case NL80211_ATTR_WIPHY_BANDS:
 	case NL80211_ATTR_SURVEY_INFO:
+	case NL80211_ATTR_KEY:
 		return extract_nested;
 	case NL80211_ATTR_KEY_IDX:
 		return extract_u8;
@@ -208,6 +209,18 @@ static attr_handler handler_for_survey_info(int type)
 	return NULL;
 }
 
+static attr_handler handler_for_key(int type)
+{
+	switch (type) {
+	case NL80211_KEY_SEQ:
+		return extract_iovec;
+	default:
+		break;
+	}
+
+	return NULL;
+}
+
 struct attr_entry {
 	uint16_t type;
 	void *data;
@@ -322,6 +335,9 @@ int nl80211_parse_nested(struct l_genl_attr *attr, int type, int tag, ...)
 	case NL80211_ATTR_SURVEY_INFO:
 		handler = handler_for_survey_info;
 		break;
+	case NL80211_ATTR_KEY:
+		handler = handler_for_key;
+		break;
 	default:
 		return -ENOTSUP;
 	}
@@ -568,46 +584,29 @@ struct l_genl_msg *nl80211_build_get_key(uint32_t ifindex, uint8_t key_index)
 
 const void *nl80211_parse_get_key_seq(struct l_genl_msg *msg)
 {
-	struct l_genl_attr attr, nested;
-	uint16_t type, len;
-	const void *data;
+	struct l_genl_attr nested;
+	struct iovec iov;
 
-	if (l_genl_msg_get_error(msg) < 0 || !l_genl_attr_init(&attr, msg)) {
+	if (l_genl_msg_get_error(msg) < 0 ||
+			nl80211_parse_attrs(msg, NL80211_ATTR_KEY, &nested,
+						NL80211_ATTR_UNSPEC) < 0) {
 		l_error("GET_KEY failed for the GTK: %i",
 			l_genl_msg_get_error(msg));
 		return NULL;
 	}
 
-	while (l_genl_attr_next(&attr, &type, &len, &data)) {
-		if (type != NL80211_ATTR_KEY)
-			continue;
-
-		break;
-	}
-
-	if (type != NL80211_ATTR_KEY || !l_genl_attr_recurse(&attr, &nested)) {
+	if (nl80211_parse_nested(&nested, NL80211_ATTR_KEY, NL80211_KEY_SEQ,
+					&iov, NL80211_ATTR_UNSPEC)) {
 		l_error("Can't recurse into ATTR_KEY in GET_KEY reply");
 		return NULL;
 	}
 
-	while (l_genl_attr_next(&nested, &type, &len, &data)) {
-		if (type != NL80211_KEY_SEQ)
-			continue;
-
-		break;
-	}
-
-	if (type != NL80211_KEY_SEQ) {
-		l_error("KEY_SEQ not returned in GET_KEY reply");
-		return NULL;
-	}
-
-	if (len != 6) {
+	if (iov.iov_len != 6) {
 		l_error("KEY_SEQ length != 6 in GET_KEY reply");
 		return NULL;
 	}
 
-	return data;
+	return iov.iov_base;
 }
 
 struct l_genl_msg *nl80211_build_cmd_frame(uint32_t ifindex,
-- 
2.34.1


  reply	other threads:[~2024-06-25 13:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-25 13:06 [PATCH 1/7] netdev: use nl80211_parse_attrs for deauth event James Prestwood
2024-06-25 13:06 ` James Prestwood [this message]
2024-06-25 13:06 ` [PATCH 3/7] netdev: reuse NETDEV_EVENT_{AUTHENTICATING,ASSOCIATING} James Prestwood
2024-06-26 14:43   ` Denis Kenzior
2024-06-25 13:06 ` [PATCH 4/7] station: add auth/assoc debug events James Prestwood
2024-06-25 13:06 ` [PATCH 5/7] auto-t: add test for deauth after authentication James Prestwood
2024-06-25 13:06 ` [PATCH 6/7] station: add debug event prior to sending an FT-auth frame James Prestwood
2024-06-25 13:06 ` [PATCH 7/7] auto-t: add test for a deauth coming in during an FT-roam James Prestwood

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=20240625130624.385553-2-prestwoj@gmail.com \
    --to=prestwoj@gmail.com \
    --cc=iwd@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