From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.linux.dev
Cc: James Prestwood <prestwoj@gmail.com>
Subject: [PATCH v3 1/3] netdev: move GETLINK into its own function, track command ID
Date: Mon, 19 Jun 2023 11:09:20 -0700 [thread overview]
Message-ID: <20230619180922.231506-1-prestwoj@gmail.com> (raw)
Move this logic into its own function and track the command ID
so it can be canceled in case of netdev going down.
---
src/netdev.c | 51 +++++++++++++++++++++++++++++++++------------------
1 file changed, 33 insertions(+), 18 deletions(-)
v3:
* Zero get_link_cmd_id in callback
diff --git a/src/netdev.c b/src/netdev.c
index 4ee17f3b..a72745b0 100644
--- a/src/netdev.c
+++ b/src/netdev.c
@@ -131,6 +131,7 @@ struct netdev {
uint32_t qos_map_cmd_id;
uint32_t mac_change_cmd_id;
uint32_t get_oci_cmd_id;
+ uint32_t get_link_cmd_id;
enum netdev_result result;
uint16_t last_code; /* reason or status, depending on result */
struct l_timeout *neighbor_report_timeout;
@@ -940,6 +941,11 @@ static void netdev_free(void *data)
if (netdev->fw_roam_bss)
scan_bss_free(netdev->fw_roam_bss);
+ if (netdev->get_link_cmd_id) {
+ l_netlink_cancel(rtnl, netdev->get_link_cmd_id);
+ netdev->get_link_cmd_id = 0;
+ }
+
scan_wdev_remove(netdev->wdev_id);
watchlist_destroy(&netdev->station_watches);
@@ -6116,12 +6122,14 @@ static void netdev_initial_down_cb(int error, uint16_t type, const void *data,
static void netdev_getlink_cb(int error, uint16_t type, const void *data,
uint32_t len, void *user_data)
{
+ struct netdev *netdev = user_data;
const struct ifinfomsg *ifi = data;
unsigned int bytes;
- struct netdev *netdev;
l_netlink_command_func_t cb;
bool powered;
+ netdev->get_link_cmd_id = 0;
+
if (error != 0) {
l_error("RTM_GETLINK error %i: %s", error, strerror(-error));
return;
@@ -6133,8 +6141,7 @@ static void netdev_getlink_cb(int error, uint16_t type, const void *data,
return;
}
- netdev = netdev_find(ifi->ifi_index);
- if (!netdev)
+ if (L_WARN_ON((uint32_t)ifi->ifi_index != netdev->index))
return;
bytes = len - NLMSG_ALIGN(sizeof(struct ifinfomsg));
@@ -6212,6 +6219,27 @@ error:
return NULL;
}
+static void netdev_get_link(struct netdev *netdev)
+{
+ struct ifinfomsg *rtmmsg;
+ size_t bufsize;
+
+ /* Query interface flags */
+ bufsize = NLMSG_ALIGN(sizeof(struct ifinfomsg));
+ rtmmsg = l_malloc(bufsize);
+ memset(rtmmsg, 0, bufsize);
+
+ rtmmsg->ifi_family = AF_UNSPEC;
+ rtmmsg->ifi_index = netdev->index;
+
+ netdev->get_link_cmd_id = l_netlink_send(rtnl, RTM_GETLINK, 0, rtmmsg,
+ bufsize, netdev_getlink_cb,
+ netdev, NULL);
+ L_WARN_ON(netdev->get_link_cmd_id == 0);
+
+ l_free(rtmmsg);
+}
+
struct netdev *netdev_create_from_genl(struct l_genl_msg *msg,
const uint8_t *set_mac)
{
@@ -6223,8 +6251,6 @@ struct netdev *netdev_create_from_genl(struct l_genl_msg *msg,
uint32_t wiphy_id;
struct netdev *netdev;
struct wiphy *wiphy = NULL;
- struct ifinfomsg *rtmmsg;
- size_t bufsize;
struct l_io *pae_io = NULL;
if (nl80211_parse_attrs(msg, NL80211_ATTR_IFINDEX, &ifindex,
@@ -6283,21 +6309,10 @@ struct netdev *netdev_create_from_genl(struct l_genl_msg *msg,
l_debug("Created interface %s[%d %" PRIx64 "]", netdev->name,
netdev->index, netdev->wdev_id);
- /* Query interface flags */
- bufsize = NLMSG_ALIGN(sizeof(struct ifinfomsg));
- rtmmsg = l_malloc(bufsize);
- memset(rtmmsg, 0, bufsize);
-
- rtmmsg->ifi_family = AF_UNSPEC;
- rtmmsg->ifi_index = ifindex;
-
- l_netlink_send(rtnl, RTM_GETLINK, 0, rtmmsg, bufsize,
- netdev_getlink_cb, NULL, NULL);
-
- l_free(rtmmsg);
-
netdev_setup_interface(netdev);
+ netdev_get_link(netdev);
+
return netdev;
}
--
2.25.1
next reply other threads:[~2023-06-19 18:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-19 18:09 James Prestwood [this message]
2023-06-19 18:09 ` [PATCH v3 2/3] netdev: disable power save if required James Prestwood
2023-06-19 18:09 ` [PATCH v3 3/3] wiphy: remove l_info's for control port/power save James Prestwood
2023-06-20 1:25 ` [PATCH v3 1/3] netdev: move GETLINK into its own function, track command ID 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=20230619180922.231506-1-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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).