From: Denis Kenzior <denkenz@gmail.com>
To: iwd@lists.linux.dev
Cc: Denis Kenzior <denkenz@gmail.com>
Subject: [PATCH 11/11] netdev: disambiguate between disconnection types
Date: Tue, 14 Nov 2023 11:14:34 -0600 [thread overview]
Message-ID: <20231114171455.1108856-11-denkenz@gmail.com> (raw)
In-Reply-To: <20231114171455.1108856-1-denkenz@gmail.com>
There are generally three scenarios where iwd generates a disconnection
command to the kernel:
1. Error conditions stemming from a connection related event. For
example if SAE/FT/FILS authentication fails during Authenticate or
Associate steps and the kernel doesn't disconnect properly.
2. Deauthentication after the connection has been established and not
related to a connection attempt in progress. For example, SA Query
processing that triggers an disconnect.
3. Disconnects that are triggered due to a handshake failure or if
setting keys resulting from the handshake fails. These disconnects
can be triggered as a result of a pending connection or when a
connection has been established (e.g. due to rekeying).
Distinguish between 1 and 2/3 by having the disconnect procedure take
different paths. For now there are no functional changes since all
paths end up in netdev_connect_failed(), but this will change in the
future.
---
src/netdev.c | 126 +++++++++++++++++++++++++++++++--------------------
1 file changed, 76 insertions(+), 50 deletions(-)
diff --git a/src/netdev.c b/src/netdev.c
index 418626d72579..d0ce0aaad5e7 100644
--- a/src/netdev.c
+++ b/src/netdev.c
@@ -858,7 +858,7 @@ static void netdev_connect_failed(struct netdev *netdev,
}
}
-static void netdev_disconnect_cb(struct l_genl_msg *msg, void *user_data)
+static void netdev_connect_failed_cb(struct l_genl_msg *msg, void *user_data)
{
struct netdev *netdev = user_data;
@@ -866,6 +866,63 @@ static void netdev_disconnect_cb(struct l_genl_msg *msg, void *user_data)
netdev_connect_failed(netdev, netdev->result, netdev->last_code);
}
+static void netdev_send_and_fail_connection(struct netdev *netdev,
+ enum netdev_result result,
+ uint16_t status_code,
+ struct l_genl_msg *msg)
+{
+ netdev->result = result;
+ netdev->last_code = status_code;
+
+ netdev->disconnect_cmd_id =
+ l_genl_family_send(nl80211, msg, netdev_connect_failed_cb,
+ netdev, NULL);
+}
+
+static void netdev_disconnect_and_fail_connection(struct netdev *netdev,
+ enum netdev_result result,
+ uint16_t status_code)
+{
+ struct l_genl_msg *msg = nl80211_build_disconnect(netdev->index,
+ MMPDU_REASON_CODE_UNSPECIFIED);
+
+ netdev_send_and_fail_connection(netdev, result, status_code, msg);
+}
+
+static void netdev_deauth_and_fail_connection(struct netdev *netdev,
+ enum netdev_result result,
+ uint16_t status_code)
+{
+ struct l_genl_msg *msg = nl80211_build_deauthenticate(netdev->index,
+ netdev->handshake->aa,
+ MMPDU_REASON_CODE_UNSPECIFIED);
+
+ netdev_send_and_fail_connection(netdev, result, status_code, msg);
+}
+
+static void netdev_disconnect_sme_cb(struct l_genl_msg *msg, void *user_data)
+{
+ struct netdev *netdev = user_data;
+
+ netdev->disconnect_cmd_id = 0;
+ netdev_connect_failed(netdev, netdev->result, netdev->last_code);
+}
+
+static void netdev_disconnect_by_sme(struct netdev *netdev,
+ enum netdev_result result,
+ uint16_t reason_code)
+{
+ struct l_genl_msg *msg = nl80211_build_disconnect(netdev->index,
+ reason_code);
+
+ netdev->result = result;
+ netdev->last_code = reason_code;
+
+ netdev->disconnect_cmd_id = l_genl_family_send(nl80211, msg,
+ netdev_disconnect_sme_cb,
+ netdev, NULL);
+}
+
static void netdev_free(void *data)
{
struct netdev *netdev = data;
@@ -1388,11 +1445,9 @@ static void netdev_setting_keys_failed(struct netdev_handshake_state *nhs,
return;
}
- msg = nl80211_build_disconnect(netdev->index,
- MMPDU_REASON_CODE_UNSPECIFIED);
- netdev->disconnect_cmd_id = l_genl_family_send(nl80211, msg,
- netdev_disconnect_cb,
- netdev, NULL);
+ netdev_disconnect_by_sme(netdev,
+ NETDEV_RESULT_KEY_SETTING_FAILED,
+ MMPDU_REASON_CODE_UNSPECIFIED);
break;
case NL80211_IFTYPE_AP:
if (err == -ENETDOWN)
@@ -1407,7 +1462,6 @@ static void netdev_setting_keys_failed(struct netdev_handshake_state *nhs,
break;
}
- netdev->result = NETDEV_RESULT_KEY_SETTING_FAILED;
handshake_event(&nhs->super, HANDSHAKE_EVENT_SETTING_KEYS_FAILED, &err);
}
@@ -2118,16 +2172,11 @@ void netdev_handshake_failed(struct handshake_state *hs, uint16_t reason_code)
netdev->sm = NULL;
- netdev->result = NETDEV_RESULT_HANDSHAKE_FAILED;
- netdev->last_code = reason_code;
-
switch (netdev->type) {
case NL80211_IFTYPE_STATION:
case NL80211_IFTYPE_P2P_CLIENT:
- msg = nl80211_build_disconnect(netdev->index, reason_code);
- netdev->disconnect_cmd_id = l_genl_family_send(nl80211, msg,
- netdev_disconnect_cb,
- netdev, NULL);
+ netdev_disconnect_by_sme(netdev, NETDEV_RESULT_HANDSHAKE_FAILED,
+ reason_code);
break;
case NL80211_IFTYPE_AP:
case NL80211_IFTYPE_P2P_GO:
@@ -2842,14 +2891,9 @@ error:
return;
deauth:
- netdev->result = NETDEV_RESULT_ASSOCIATION_FAILED;
- netdev->last_code = MMPDU_STATUS_CODE_UNSPECIFIED;
- msg = nl80211_build_disconnect(netdev->index,
- MMPDU_REASON_CODE_UNSPECIFIED);
- netdev->disconnect_cmd_id = l_genl_family_send(nl80211,
- msg,
- netdev_disconnect_cb,
- netdev, NULL);
+ netdev_disconnect_and_fail_connection(netdev,
+ NETDEV_RESULT_ASSOCIATION_FAILED,
+ MMPDU_STATUS_CODE_UNSPECIFIED);
}
static struct l_genl_msg *netdev_build_cmd_associate_common(
@@ -2890,19 +2934,12 @@ static void netdev_cmd_ft_reassociate_cb(struct l_genl_msg *msg,
netdev->connect_cmd_id = 0;
- if (l_genl_msg_get_error(msg) < 0) {
- struct l_genl_msg *cmd_deauth;
+ if (l_genl_msg_get_error(msg) >= 0)
+ return;
- netdev->result = NETDEV_RESULT_ASSOCIATION_FAILED;
- netdev->last_code = MMPDU_STATUS_CODE_UNSPECIFIED;
- cmd_deauth = nl80211_build_deauthenticate(netdev->index,
- netdev->handshake->aa,
- MMPDU_REASON_CODE_UNSPECIFIED);
- netdev->disconnect_cmd_id = l_genl_family_send(nl80211,
- cmd_deauth,
- netdev_disconnect_cb,
- netdev, NULL);
- }
+ netdev_deauth_and_fail_connection(netdev,
+ NETDEV_RESULT_ASSOCIATION_FAILED,
+ MMPDU_STATUS_CODE_UNSPECIFIED);
}
static bool kernel_will_retry_auth(uint16_t status_code,
@@ -3027,17 +3064,9 @@ static void netdev_authenticate_event(struct l_genl_msg *msg,
* to keep retrying, tell it to stop
*/
if (retry) {
- struct l_genl_msg *cmd_deauth;
-
- netdev->result = NETDEV_RESULT_ASSOCIATION_FAILED;
- netdev->last_code = MMPDU_STATUS_CODE_UNSPECIFIED;
- cmd_deauth = nl80211_build_deauthenticate(netdev->index,
- netdev->handshake->aa,
- MMPDU_REASON_CODE_UNSPECIFIED);
- netdev->disconnect_cmd_id = l_genl_family_send(nl80211,
- cmd_deauth,
- netdev_disconnect_cb,
- netdev, NULL);
+ netdev_deauth_and_fail_connection(netdev,
+ NETDEV_RESULT_ASSOCIATION_FAILED,
+ MMPDU_STATUS_CODE_UNSPECIFIED);
return;
}
}
@@ -4545,17 +4574,14 @@ static void netdev_sa_query_timeout(struct l_timeout *timeout,
void *user_data)
{
struct netdev *netdev = user_data;
- struct l_genl_msg *msg;
l_info("SA Query timed out, connection is invalid. Disconnecting...");
l_timeout_remove(netdev->sa_query_timeout);
netdev->sa_query_timeout = NULL;
- msg = nl80211_build_disconnect(netdev->index,
- MMPDU_REASON_CODE_PREV_AUTH_NOT_VALID);
- netdev->disconnect_cmd_id = l_genl_family_send(nl80211, msg,
- netdev_disconnect_cb, netdev, NULL);
+ netdev_disconnect_by_sme(netdev, NETDEV_RESULT_ABORTED,
+ MMPDU_REASON_CODE_PREV_AUTH_NOT_VALID);
}
static void netdev_sa_query_req_cb(struct l_genl_msg *msg, void *user_data)
--
2.42.0
next prev parent reply other threads:[~2023-11-14 17:15 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-14 17:14 [PATCH 01/11] netdev: Fix obtaining reason code from deauth frames Denis Kenzior
2023-11-14 17:14 ` [PATCH 02/11] netdev: sa_query: Fix reason code handling Denis Kenzior
2023-11-14 17:14 ` [PATCH 03/11] netdev: Use CMD_DISCONNECT if OCI fails Denis Kenzior
2023-11-14 17:14 ` [PATCH 04/11] netdev: Don't unnecessarily call netdev_connect_failed Denis Kenzior
2023-11-14 17:14 ` [PATCH 05/11] netdev: Move CMD_DISCONNECT builder to nl80211util Denis Kenzior
2023-11-14 17:14 ` [PATCH 06/11] netdev: Move CMD_DEAUTHENTICATE " Denis Kenzior
2023-11-14 17:14 ` [PATCH 07/11] netdev: Move CMD_DEL_STATION " Denis Kenzior
2023-11-14 17:14 ` [PATCH 08/11] netdev: Move pairwise NEW_KEY " Denis Kenzior
2023-11-14 17:14 ` [PATCH 09/11] netdev: Move CMD_NEW_KEY RX-only " Denis Kenzior
2023-11-14 17:14 ` [PATCH 10/11] netdev: Move CMD_REKEY_OFFLOAD " Denis Kenzior
2023-11-14 17:14 ` Denis Kenzior [this message]
2023-11-14 17:39 ` [PATCH 11/11] netdev: disambiguate between disconnection types James Prestwood
2023-11-14 20:09 ` Denis Kenzior
2023-11-14 20:11 ` James Prestwood
2023-11-24 12:20 ` Alvin Šipraga
2023-11-24 16:25 ` Denis Kenzior
2023-11-25 20:57 ` Alvin Šipraga
2023-11-14 20:48 ` [PATCH 01/11] netdev: Fix obtaining reason code from deauth frames Denis Kenzior
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=20231114171455.1108856-11-denkenz@gmail.com \
--to=denkenz@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