commit 8dced8b7f7280215f583dbe2f26210d313299544
parent 71ebc00fb72d5cca6a0fc65c2145f1213005670d
Author: Denis Kenzior <denkenz@gmail.com>
Date: Fri, 17 May 2019 17:05:52 -0500
main: Update to the new genl api
Diffstat:
3 files changed, 46 insertions(+), 40 deletions(-)
diff --git a/src/iwd.h b/src/iwd.h
@@ -22,9 +22,11 @@
#define uninitialized_var(x) x = x
+struct l_genl;
struct l_genl_family;
const struct l_settings *iwd_get_config(void);
+struct l_genl *iwd_get_genl(void);
bool netdev_init(void);
void netdev_exit(void);
diff --git a/src/main.c b/src/main.c
@@ -103,6 +103,11 @@ const struct l_settings *iwd_get_config(void)
return iwd_config;
}
+struct l_genl *iwd_get_genl(void)
+{
+ return genl;
+}
+
static void usage(void)
{
printf("iwd - Wireless daemon\n"
@@ -143,14 +148,11 @@ static void do_debug(const char *str, void *user_data)
l_info("%s%s", prefix, str);
}
-static void nl80211_appeared(void *user_data)
+static void nl80211_appeared(const struct l_genl_family_info *info,
+ void *user_data)
{
- struct l_genl_family *nl80211 = user_data;
-
- if (terminating)
- return;
-
l_debug("Found nl80211 interface");
+ nl80211 = l_genl_family_new(genl, NL80211_GENL_NAME);
manager_init(nl80211, interfaces, nointerfaces);
@@ -166,17 +168,6 @@ static void nl80211_appeared(void *user_data)
adhoc_init(nl80211);
}
-static void nl80211_vanished(void *user_data)
-{
- l_debug("Lost nl80211 interface");
-
- manager_exit();
- ap_exit();
- adhoc_exit();
- scan_exit();
- wiphy_exit();
-}
-
static void request_name_callback(struct l_dbus *dbus, bool success,
bool queued, void *user_data)
{
@@ -188,23 +179,9 @@ static void request_name_callback(struct l_dbus *dbus, bool success,
if (!l_dbus_object_manager_enable(dbus))
l_warn("Unable to register the ObjectManager");
- genl = l_genl_new_default();
- if (!genl) {
- l_error("Failed to open generic netlink socket");
- goto fail_exit;
- }
-
- if (getenv("IWD_GENL_DEBUG"))
- l_genl_set_debug(genl, do_debug, "[GENL] ", NULL);
-
- nl80211 = l_genl_family_new(genl, NL80211_GENL_NAME);
- if (!nl80211) {
- l_error("Failed to open nl80211 interface");
- goto fail_exit;
- }
-
- l_genl_family_set_watches(nl80211, nl80211_appeared, nl80211_vanished,
- nl80211, NULL);
+ /* TODO: Always request nl80211 for now, ignoring auto-loading */
+ l_genl_request_family(genl, NL80211_GENL_NAME, nl80211_appeared,
+ NULL, NULL);
return;
fail_exit:
@@ -480,6 +457,15 @@ int main(int argc, char *argv[])
goto fail_dbus;
}
+ genl = l_genl_new();
+ if (!genl) {
+ l_error("Failed to open generic netlink socket");
+ goto fail_genl;
+ }
+
+ if (getenv("IWD_GENL_DEBUG"))
+ l_genl_set_debug(genl, do_debug, "[GENL] ", NULL);
+
dbus = l_dbus_new_default(L_DBUS_SYSTEM_BUS);
if (!dbus) {
l_error("Failed to initialize D-Bus");
@@ -530,11 +516,20 @@ fail_netdev:
eapol_exit();
eap_exit();
- l_genl_family_unref(nl80211);
- l_genl_unref(genl);
+ if (nl80211) {
+ manager_exit();
+ ap_exit();
+ adhoc_exit();
+ scan_exit();
+ wiphy_exit();
+ l_genl_family_free(nl80211);
+ }
+
dbus_exit();
l_dbus_destroy(dbus);
fail_dbus:
+ l_genl_unref(genl);
+fail_genl:
l_settings_free(iwd_config);
l_timeout_remove(timeout);
diff --git a/src/netdev.c b/src/netdev.c
@@ -66,6 +66,8 @@
#define ENOTSUPP 524
#endif
+static uint32_t unicast_watch;
+
struct netdev_handshake_state {
struct handshake_state super;
uint32_t pairwise_new_key_cmd_id;
@@ -4564,6 +4566,7 @@ bool netdev_watch_remove(uint32_t id)
bool netdev_init(void)
{
+ struct l_genl *genl = iwd_get_genl();
const struct l_settings *settings = iwd_get_config();
if (rtnl)
@@ -4601,6 +4604,12 @@ bool netdev_init(void)
__eapol_set_rekey_offload_func(netdev_set_rekey_offload);
__eapol_set_tx_packet_func(netdev_control_port_frame);
+ unicast_watch = l_genl_add_unicast_watch(genl, NL80211_GENL_NAME,
+ netdev_unicast_notify,
+ NULL, NULL);
+ if (!unicast_watch)
+ l_error("Registering for unicast notification failed");
+
return true;
}
@@ -4611,17 +4620,17 @@ void netdev_set_nl80211(struct l_genl_family *in)
if (!l_genl_family_register(nl80211, "mlme", netdev_mlme_notify,
NULL, NULL))
l_error("Registering for MLME notification failed");
-
- if (!l_genl_family_set_unicast_handler(nl80211, netdev_unicast_notify,
- NULL, NULL))
- l_error("Registering for unicast notification failed");
}
void netdev_exit(void)
{
+ struct l_genl *genl = iwd_get_genl();
+
if (!rtnl)
return;
+ l_genl_remove_unicast_watch(genl, unicast_watch);
+
watchlist_destroy(&netdev_watches);
nl80211 = NULL;