Wireless Daemon for Linux
 help / color / mirror / Atom feed
* [PATCH 01/11] main: move module init into nl80211_appeared
@ 2019-10-11 17:24 James Prestwood
  2019-10-11 17:24 ` [PATCH 02/11] netdev: utilize IWD_MODULE James Prestwood
                   ` (9 more replies)
  0 siblings, 10 replies; 13+ messages in thread
From: James Prestwood @ 2019-10-11 17:24 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 1374 bytes --]

In preparation for integrating IWD_MODULE into modules which require
nl80211 we move the module init into the nl80211_appeared callback.
This will guarentee that the nl80211 is available during module init
and allow modules to get their own copy of nl80211 rather than needing
a set function (e.g. netdev_set_nl80211).

Since the dbus name request callback happens before this as well any
dbus module can also use IWD_MODULE and simply assume the dbus object
is ready.
---
 src/main.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/main.c b/src/main.c
index b34da3d0..786b30d6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -147,6 +147,11 @@ static void nl80211_appeared(const struct l_genl_family_info *info,
 	l_debug("Found nl80211 interface");
 	nl80211 = l_genl_family_new(genl, NL80211_GENL_NAME);
 
+	if (iwd_modules_init() < 0) {
+		l_main_quit();
+		return;
+	}
+
 	manager_init(nl80211, interfaces, nointerfaces);
 	anqp_init(nl80211);
 
@@ -482,14 +487,10 @@ int main(int argc, char *argv[])
 	if (!netdev_init())
 		goto fail_netdev;
 
-	if (iwd_modules_init() < 0)
-		goto fail_modules;
-
 	plugin_init(plugins, noplugins);
 	exit_status = l_main_run_with_signal(signal_handler, NULL);
 	plugin_exit();
 
-fail_modules:
 	iwd_modules_exit();
 	netdev_exit();
 fail_netdev:
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 02/11] netdev: utilize IWD_MODULE
  2019-10-11 17:24 [PATCH 01/11] main: move module init into nl80211_appeared James Prestwood
@ 2019-10-11 17:24 ` James Prestwood
  2019-10-11 17:24 ` [PATCH 03/11] eapol: " James Prestwood
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: James Prestwood @ 2019-10-11 17:24 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 3489 bytes --]

Since iwd_modules_init is now defered until nl80211_appeared, we can
assume the nl80211 object is available. This removes the need for
netdev_set_nl80211 completely.
---
 src/iwd.h    |  3 ---
 src/main.c   |  8 +-------
 src/netdev.c | 25 +++++++++++++------------
 3 files changed, 14 insertions(+), 22 deletions(-)

diff --git a/src/iwd.h b/src/iwd.h
index 8bb4f64f..7ae7e4b4 100644
--- a/src/iwd.h
+++ b/src/iwd.h
@@ -28,9 +28,6 @@ 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);
-void netdev_set_nl80211(struct l_genl_family *nl80211);
 void netdev_shutdown(void);
 
 bool manager_init(struct l_genl_family *in,
diff --git a/src/main.c b/src/main.c
index 786b30d6..7707dfb8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -157,8 +157,6 @@ static void nl80211_appeared(const struct l_genl_family_info *info,
 
 	if (!wiphy_init(nl80211, phys, nophys))
 		l_error("Unable to init wiphy functionality");
-
-	netdev_set_nl80211(nl80211);
 }
 
 static void request_name_callback(struct l_dbus *dbus, bool success,
@@ -484,16 +482,12 @@ int main(int argc, char *argv[])
 	eap_init(eap_mtu);
 	eapol_init();
 
-	if (!netdev_init())
-		goto fail_netdev;
-
 	plugin_init(plugins, noplugins);
 	exit_status = l_main_run_with_signal(signal_handler, NULL);
 	plugin_exit();
 
 	iwd_modules_exit();
-	netdev_exit();
-fail_netdev:
+
 	eapol_exit();
 	eap_exit();
 
diff --git a/src/netdev.c b/src/netdev.c
index 773f0795..1828f5d0 100644
--- a/src/netdev.c
+++ b/src/netdev.c
@@ -4755,20 +4755,22 @@ bool netdev_watch_remove(uint32_t id)
 	return watchlist_remove(&netdev_watches, id);
 }
 
-bool netdev_init(void)
+static int netdev_init(void)
 {
 	struct l_genl *genl = iwd_get_genl();
 	const struct l_settings *settings = iwd_get_config();
 
+	nl80211 = l_genl_family_new(genl, NL80211_GENL_NAME);
+
 	if (rtnl)
-		return false;
+		return -EALREADY;
 
 	l_debug("Opening route netlink socket");
 
 	rtnl = l_netlink_new(NETLINK_ROUTE);
 	if (!rtnl) {
 		l_error("Failed to open route netlink socket");
-		return false;
+		return -EIO;
 	}
 
 	if (getenv("IWD_RTNL_DEBUG"))
@@ -4778,7 +4780,7 @@ bool netdev_init(void)
 				netdev_link_notify, NULL, NULL)) {
 		l_error("Failed to register for RTNL link notifications");
 		l_netlink_destroy(rtnl);
-		return false;
+		return -EIO;
 	}
 
 	if (!l_settings_get_int(settings, "General", "roam_rssi_threshold",
@@ -4801,19 +4803,14 @@ bool netdev_init(void)
 	if (!unicast_watch)
 		l_error("Registering for unicast notification failed");
 
-	return true;
-}
-
-void netdev_set_nl80211(struct l_genl_family *in)
-{
-	nl80211 = in;
-
 	if (!l_genl_family_register(nl80211, "mlme", netdev_mlme_notify,
 								NULL, NULL))
 		l_error("Registering for MLME notification failed");
+
+	return 0;
 }
 
-void netdev_exit(void)
+static void netdev_exit(void)
 {
 	struct l_genl *genl = iwd_get_genl();
 
@@ -4823,6 +4820,8 @@ void netdev_exit(void)
 	l_genl_remove_unicast_watch(genl, unicast_watch);
 
 	watchlist_destroy(&netdev_watches);
+
+	l_genl_family_free(nl80211);
 	nl80211 = NULL;
 
 	l_debug("Closing route netlink socket");
@@ -4840,3 +4839,5 @@ void netdev_shutdown(void)
 	l_queue_destroy(netdev_list, netdev_free);
 	netdev_list = NULL;
 }
+
+IWD_MODULE(netdev, netdev_init, netdev_exit);
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 03/11] eapol: utilize IWD_MODULE
  2019-10-11 17:24 [PATCH 01/11] main: move module init into nl80211_appeared James Prestwood
  2019-10-11 17:24 ` [PATCH 02/11] netdev: utilize IWD_MODULE James Prestwood
@ 2019-10-11 17:24 ` James Prestwood
  2019-10-11 17:24 ` [PATCH 04/11] anqp: " James Prestwood
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: James Prestwood @ 2019-10-11 17:24 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 2396 bytes --]

This converts eapol to using IWD modules. The init/exit APIs did need
to remain exposed for unit tests.

Netdev was updated to depend on eapol.
---
 src/eapol.c  | 11 ++++++-----
 src/eapol.h  |  4 ++--
 src/main.c   |  2 --
 src/netdev.c |  1 +
 4 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/eapol.c b/src/eapol.c
index 414d1c69..6732b370 100644
--- a/src/eapol.c
+++ b/src/eapol.c
@@ -40,6 +40,7 @@
 #include "src/handshake.h"
 #include "src/watchlist.h"
 #include "src/erp.h"
+#include "src/iwd.h"
 
 static struct l_queue *state_machines;
 static struct l_queue *preauths;
@@ -2705,16 +2706,16 @@ void __eapol_set_config(struct l_settings *config)
 		eapol_4way_handshake_time = 5;
 }
 
-bool eapol_init()
+int eapol_init(void)
 {
 	state_machines = l_queue_new();
 	preauths = l_queue_new();
 	watchlist_init(&frame_watches, &eapol_frame_watch_ops);
 
-	return true;
+	return 0;
 }
 
-bool eapol_exit()
+void eapol_exit(void)
 {
 	if (!l_queue_isempty(state_machines))
 		l_warn("stale eapol state machines found");
@@ -2727,6 +2728,6 @@ bool eapol_exit()
 	l_queue_destroy(preauths, preauth_sm_destroy);
 
 	watchlist_destroy(&frame_watches);
-
-	return true;
 }
+
+IWD_MODULE(eapol, eapol_init, eapol_exit);
diff --git a/src/eapol.h b/src/eapol.h
index 1a1862bd..9462b56d 100644
--- a/src/eapol.h
+++ b/src/eapol.h
@@ -128,5 +128,5 @@ struct preauth_sm *eapol_preauth_start(const uint8_t *aa,
 					eapol_preauth_destroy_func_t destroy);
 void eapol_preauth_cancel(uint32_t ifindex);
 
-bool eapol_init();
-bool eapol_exit();
+int eapol_init(void);
+void eapol_exit(void);
diff --git a/src/main.c b/src/main.c
index 7707dfb8..2e8d4a6d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -480,7 +480,6 @@ int main(int argc, char *argv[])
 	dbus_init(dbus);
 
 	eap_init(eap_mtu);
-	eapol_init();
 
 	plugin_init(plugins, noplugins);
 	exit_status = l_main_run_with_signal(signal_handler, NULL);
@@ -488,7 +487,6 @@ int main(int argc, char *argv[])
 
 	iwd_modules_exit();
 
-	eapol_exit();
 	eap_exit();
 
 	if (nl80211) {
diff --git a/src/netdev.c b/src/netdev.c
index 1828f5d0..0785f0c4 100644
--- a/src/netdev.c
+++ b/src/netdev.c
@@ -4841,3 +4841,4 @@ void netdev_shutdown(void)
 }
 
 IWD_MODULE(netdev, netdev_init, netdev_exit);
+IWD_MODULE_DEPENDS(netdev, eapol);
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 04/11] anqp: utilize IWD_MODULE
  2019-10-11 17:24 [PATCH 01/11] main: move module init into nl80211_appeared James Prestwood
  2019-10-11 17:24 ` [PATCH 02/11] netdev: utilize IWD_MODULE James Prestwood
  2019-10-11 17:24 ` [PATCH 03/11] eapol: " James Prestwood
@ 2019-10-11 17:24 ` James Prestwood
  2019-10-11 17:24 ` [PATCH 05/11] agent: " James Prestwood
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: James Prestwood @ 2019-10-11 17:24 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 2145 bytes --]

This converts anqp into an IWD module.
---
 src/anqp.c | 12 ++++++++----
 src/anqp.h |  3 ---
 src/main.c |  2 --
 3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/anqp.c b/src/anqp.c
index 9f006bd6..a47530ab 100644
--- a/src/anqp.c
+++ b/src/anqp.c
@@ -474,11 +474,11 @@ static void anqp_mlme_notify(struct l_genl_msg *msg, void *user_data)
 	}
 }
 
-bool anqp_init(struct l_genl_family *in)
+static int anqp_init(void)
 {
 	struct l_genl *genl = iwd_get_genl();
 
-	nl80211 = in;
+	nl80211 = l_genl_family_new(genl, NL80211_GENL_NAME);
 
 	anqp_requests = l_queue_new();
 
@@ -492,13 +492,14 @@ bool anqp_init(struct l_genl_family *in)
 								NULL, NULL))
 		l_error("Registering for MLME notification failed");
 
-	return true;
+	return 0;
 }
 
-void anqp_exit(void)
+static void anqp_exit(void)
 {
 	struct l_genl *genl = iwd_get_genl();
 
+	l_genl_family_free(nl80211);
 	nl80211 = NULL;
 
 	l_queue_destroy(anqp_requests, anqp_destroy);
@@ -507,3 +508,6 @@ void anqp_exit(void)
 
 	l_genl_remove_unicast_watch(genl, unicast_watch);
 }
+
+IWD_MODULE(anqp, anqp_init, anqp_exit);
+IWD_MODULE_DEPENDS(anqp, netdev);
diff --git a/src/anqp.h b/src/anqp.h
index 62d097d1..998277dd 100644
--- a/src/anqp.h
+++ b/src/anqp.h
@@ -38,6 +38,3 @@ uint32_t anqp_request(uint32_t ifindex, const uint8_t *addr,
 			struct scan_bss *bss, const uint8_t *anqp, size_t len,
 			anqp_response_func_t cb, void *user_data,
 			anqp_destroy_func_t destroy);
-
-bool anqp_init(struct l_genl_family *in);
-void anqp_exit(void);
diff --git a/src/main.c b/src/main.c
index 2e8d4a6d..4619a84c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -153,7 +153,6 @@ static void nl80211_appeared(const struct l_genl_family_info *info,
 	}
 
 	manager_init(nl80211, interfaces, nointerfaces);
-	anqp_init(nl80211);
 
 	if (!wiphy_init(nl80211, phys, nophys))
 		l_error("Unable to init wiphy functionality");
@@ -491,7 +490,6 @@ int main(int argc, char *argv[])
 
 	if (nl80211) {
 		manager_exit();
-		anqp_exit();
 		wiphy_exit();
 		l_genl_family_free(nl80211);
 	}
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 05/11] agent: utilize IWD_MODULE
  2019-10-11 17:24 [PATCH 01/11] main: move module init into nl80211_appeared James Prestwood
                   ` (2 preceding siblings ...)
  2019-10-11 17:24 ` [PATCH 04/11] anqp: " James Prestwood
@ 2019-10-11 17:24 ` James Prestwood
  2019-10-11 18:53   ` Denis Kenzior
  2019-10-11 17:24 ` [PATCH 06/11] manager: " James Prestwood
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 13+ messages in thread
From: James Prestwood @ 2019-10-11 17:24 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 2799 bytes --]

Converts agent into an IWD module. This removes the dbus dependency
on agent. Since dbus is initialized very early we can assume
dbus_get_bus is going to return a valid object.
---
 src/agent.c | 19 ++++++++++++-------
 src/agent.h |  2 --
 src/dbus.c  |  3 +--
 3 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/src/agent.c b/src/agent.c
index 2c04c546..3a266746 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -29,6 +29,7 @@
 #include <ell/ell.h>
 #include "src/dbus.h"
 #include "src/agent.h"
+#include "src/iwd.h"
 
 static unsigned int next_request_id = 0;
 
@@ -619,8 +620,10 @@ static bool release_agent(void *data, void *user_data)
 	return true;
 }
 
-bool agent_init(struct l_dbus *dbus)
+static int agent_init(void)
 {
+	struct l_dbus *dbus = dbus_get_bus();
+
 	agents = l_queue_new();
 
 	if (!l_dbus_register_interface(dbus, IWD_AGENT_MANAGER_INTERFACE,
@@ -628,7 +631,7 @@ bool agent_init(struct l_dbus *dbus)
 						NULL, false)) {
 		l_info("Unable to register %s interface",
 				IWD_AGENT_MANAGER_INTERFACE);
-		return false;
+		return -EIO;
 	}
 
 	if (!l_dbus_object_add_interface(dbus, IWD_AGENT_MANAGER_PATH,
@@ -637,24 +640,26 @@ bool agent_init(struct l_dbus *dbus)
 		l_info("Unable to register the agent manager object on '%s'",
 				IWD_AGENT_MANAGER_PATH);
 		l_dbus_unregister_interface(dbus, IWD_AGENT_MANAGER_INTERFACE);
-		return false;
+		return -EIO;
 	}
 
-	return true;
+	return 0;
 }
 
-bool agent_exit(struct l_dbus *dbus)
+static void agent_exit(void)
 {
+	struct l_dbus *dbus = dbus_get_bus();
+
 	l_dbus_unregister_object(dbus, IWD_AGENT_MANAGER_PATH);
 	l_dbus_unregister_interface(dbus, IWD_AGENT_MANAGER_INTERFACE);
 
 	l_queue_destroy(agents, agent_free);
 	agents = NULL;
-
-	return true;
 }
 
 void agent_shutdown(void)
 {
 	l_queue_foreach_remove(agents, release_agent, NULL);
 }
+
+IWD_MODULE(agent, agent_init, agent_exit);
diff --git a/src/agent.h b/src/agent.h
index f4dcd46b..e9f78c39 100644
--- a/src/agent.h
+++ b/src/agent.h
@@ -37,8 +37,6 @@ typedef void (*agent_request_user_name_passwd_func_t) (enum agent_result result,
 					void *user_data);
 typedef void (*agent_request_destroy_func_t)(void *user_data);
 
-bool agent_init(struct l_dbus *dbus);
-bool agent_exit(struct l_dbus *dbus);
 void agent_shutdown(void);
 
 unsigned int agent_request_passphrase(const char *path,
diff --git a/src/dbus.c b/src/dbus.c
index 5bc32c26..43dfb567 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -210,12 +210,11 @@ struct l_dbus *dbus_get_bus(void)
 bool dbus_init(struct l_dbus *dbus)
 {
 	g_dbus = dbus;
-	return agent_init(dbus);
+	return true;
 }
 
 void dbus_exit(void)
 {
-	agent_exit(g_dbus);
 	g_dbus = NULL;
 }
 
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 06/11] manager: utilize IWD_MODULE
  2019-10-11 17:24 [PATCH 01/11] main: move module init into nl80211_appeared James Prestwood
                   ` (3 preceding siblings ...)
  2019-10-11 17:24 ` [PATCH 05/11] agent: " James Prestwood
@ 2019-10-11 17:24 ` James Prestwood
  2019-10-11 18:57   ` Denis Kenzior
  2019-10-11 17:24 ` [PATCH 07/11] wiphy: " James Prestwood
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 13+ messages in thread
From: James Prestwood @ 2019-10-11 17:24 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 3980 bytes --]

Converts manager into an IWD module. Two getters needed to be added so
manager can get the white/black list of interfaces.
---
 src/iwd.h     |  5 ++---
 src/main.c    | 13 ++++++++++---
 src/manager.c | 26 ++++++++++++++++++--------
 3 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/src/iwd.h b/src/iwd.h
index 7ae7e4b4..8814c244 100644
--- a/src/iwd.h
+++ b/src/iwd.h
@@ -30,9 +30,8 @@ struct l_genl *iwd_get_genl(void);
 
 void netdev_shutdown(void);
 
-bool manager_init(struct l_genl_family *in,
-			const char *if_whitelist, const char *if_blacklist);
-void manager_exit(void);
+const char *iwd_get_iface_whitelist(void);
+const char *iwd_get_iface_blacklist(void);
 
 struct iwd_module_desc {
 	const char *name;
diff --git a/src/main.c b/src/main.c
index 4619a84c..4b114efd 100644
--- a/src/main.c
+++ b/src/main.c
@@ -102,6 +102,16 @@ struct l_genl *iwd_get_genl(void)
 	return genl;
 }
 
+const char *iwd_get_iface_whitelist(void)
+{
+	return interfaces;
+}
+
+const char *iwd_get_iface_blacklist(void)
+{
+	return nointerfaces;
+}
+
 static void usage(void)
 {
 	printf("iwd - Wireless daemon\n"
@@ -152,8 +162,6 @@ static void nl80211_appeared(const struct l_genl_family_info *info,
 		return;
 	}
 
-	manager_init(nl80211, interfaces, nointerfaces);
-
 	if (!wiphy_init(nl80211, phys, nophys))
 		l_error("Unable to init wiphy functionality");
 }
@@ -489,7 +497,6 @@ int main(int argc, char *argv[])
 	eap_exit();
 
 	if (nl80211) {
-		manager_exit();
 		wiphy_exit();
 		l_genl_family_free(nl80211);
 	}
diff --git a/src/manager.c b/src/manager.c
index 1a04b071..d0edbb5a 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -584,16 +584,18 @@ static void manager_config_notify(struct l_genl_msg *msg, void *user_data)
 	}
 }
 
-bool manager_init(struct l_genl_family *in,
-			const char *if_whitelist, const char *if_blacklist)
+static int manager_init(void)
 {
+	struct l_genl *genl = iwd_get_genl();
 	const struct l_settings *config = iwd_get_config();
 	struct l_genl_msg *msg;
 	unsigned int wiphy_dump;
 	unsigned int interface_dump;
 	const char *randomize_str;
+	const char *if_whitelist = iwd_get_iface_whitelist();
+	const char *if_blacklist = iwd_get_iface_blacklist();
 
-	nl80211 = in;
+	nl80211 = l_genl_family_new(genl, NL80211_GENL_NAME);
 
 	if (if_whitelist)
 		whitelist_filter = l_strsplit(if_whitelist, ',');
@@ -606,7 +608,7 @@ bool manager_init(struct l_genl_family *in,
 	if (!l_genl_family_register(nl80211, "config", manager_config_notify,
 					NULL, NULL)) {
 		l_error("Registering for config notifications failed");
-		return false;
+		goto error;
 	}
 
 	msg = l_genl_msg_new_sized(NL80211_CMD_GET_WIPHY, 128);
@@ -617,7 +619,7 @@ bool manager_init(struct l_genl_family *in,
 	if (!wiphy_dump) {
 		l_error("Initial wiphy information dump failed");
 		l_genl_msg_unref(msg);
-		return false;
+		goto error;
 	}
 
 	msg = l_genl_msg_new(NL80211_CMD_GET_INTERFACE);
@@ -629,7 +631,7 @@ bool manager_init(struct l_genl_family *in,
 		l_error("Initial interface information dump failed");
 		l_genl_msg_unref(msg);
 		l_genl_family_cancel(nl80211, wiphy_dump);
-		return false;
+		goto error;
 	}
 
 	randomize_str =
@@ -637,10 +639,15 @@ bool manager_init(struct l_genl_family *in,
 	if (randomize_str && !strcmp(randomize_str, "once"))
 		randomize = true;
 
-	return true;
+	return 0;
+
+error:
+	l_queue_destroy(pending_wiphys, NULL);
+	l_genl_family_free(nl80211);
+	return -EIO;
 }
 
-void manager_exit(void)
+static void manager_exit(void)
 {
 	l_strfreev(whitelist_filter);
 	l_strfreev(blacklist_filter);
@@ -648,6 +655,9 @@ void manager_exit(void)
 	l_queue_destroy(pending_wiphys, wiphy_setup_state_free);
 	pending_wiphys = NULL;
 
+	l_genl_family_free(nl80211);
 	nl80211 = NULL;
 	randomize = false;
 }
+
+IWD_MODULE(manager, manager_init, manager_exit);
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 07/11] wiphy: utilize IWD_MODULE
  2019-10-11 17:24 [PATCH 01/11] main: move module init into nl80211_appeared James Prestwood
                   ` (4 preceding siblings ...)
  2019-10-11 17:24 ` [PATCH 06/11] manager: " James Prestwood
@ 2019-10-11 17:24 ` James Prestwood
  2019-10-11 17:24 ` [PATCH 08/11] eap: remove mtu argument from eap_init James Prestwood
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: James Prestwood @ 2019-10-11 17:24 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 4683 bytes --]

This converts wiphy into an IWD module. nl80211 was completely removed
from main.c as it is no longer passed with manager or wiphy.
---
 src/iwd.h   |  2 ++
 src/main.c  | 25 ++++++++++++++-----------
 src/wiphy.c | 20 ++++++++++++--------
 src/wiphy.h |  4 ----
 4 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/src/iwd.h b/src/iwd.h
index 8814c244..1b64e5a7 100644
--- a/src/iwd.h
+++ b/src/iwd.h
@@ -32,6 +32,8 @@ void netdev_shutdown(void);
 
 const char *iwd_get_iface_whitelist(void);
 const char *iwd_get_iface_blacklist(void);
+const char *iwd_get_phy_whitelist(void);
+const char *iwd_get_phy_blacklist(void);
 
 struct iwd_module_desc {
 	const char *name;
diff --git a/src/main.c b/src/main.c
index 4b114efd..9d0da143 100644
--- a/src/main.c
+++ b/src/main.c
@@ -46,7 +46,6 @@
 #include "src/backtrace.h"
 
 static struct l_genl *genl;
-static struct l_genl_family *nl80211;
 static struct l_settings *iwd_config;
 static struct l_timeout *timeout;
 static const char *interfaces;
@@ -57,6 +56,7 @@ static const char *plugins;
 static const char *noplugins;
 static const char *debugopt;
 static bool terminating;
+static bool nl80211_complete;
 
 static void main_loop_quit(struct l_timeout *timeout, void *user_data)
 {
@@ -70,7 +70,7 @@ static void iwd_shutdown(void)
 
 	terminating = true;
 
-	if (!nl80211) {
+	if (!nl80211_complete) {
 		l_main_quit();
 		return;
 	}
@@ -112,6 +112,16 @@ const char *iwd_get_iface_blacklist(void)
 	return nointerfaces;
 }
 
+const char *iwd_get_phy_whitelist(void)
+{
+	return phys;
+}
+
+const char *iwd_get_phy_blacklist(void)
+{
+	return nophys;
+}
+
 static void usage(void)
 {
 	printf("iwd - Wireless daemon\n"
@@ -155,15 +165,13 @@ static void nl80211_appeared(const struct l_genl_family_info *info,
 							void *user_data)
 {
 	l_debug("Found nl80211 interface");
-	nl80211 = l_genl_family_new(genl, NL80211_GENL_NAME);
+
+	nl80211_complete = true;
 
 	if (iwd_modules_init() < 0) {
 		l_main_quit();
 		return;
 	}
-
-	if (!wiphy_init(nl80211, phys, nophys))
-		l_error("Unable to init wiphy functionality");
 }
 
 static void request_name_callback(struct l_dbus *dbus, bool success,
@@ -496,11 +504,6 @@ int main(int argc, char *argv[])
 
 	eap_exit();
 
-	if (nl80211) {
-		wiphy_exit();
-		l_genl_family_free(nl80211);
-	}
-
 	dbus_exit();
 	l_dbus_destroy(dbus);
 	storage_cleanup_dirs();
diff --git a/src/wiphy.c b/src/wiphy.c
index b672afd4..169631af 100644
--- a/src/wiphy.c
+++ b/src/wiphy.c
@@ -1150,12 +1150,16 @@ static void setup_wiphy_interface(struct l_dbus_interface *interface)
 					NULL);
 }
 
-bool wiphy_init(struct l_genl_family *in, const char *whitelist,
-							const char *blacklist)
+static int wiphy_init(void)
 {
+	struct l_genl *genl = iwd_get_genl();
 	const struct l_settings *config = iwd_get_config();
 	const char *s = l_settings_get_value(config, "General",
 							"mac_randomize_bytes");
+	const char *whitelist = iwd_get_phy_whitelist();
+	const char *blacklist = iwd_get_phy_blacklist();
+
+	nl80211 = l_genl_family_new(genl, NL80211_GENL_NAME);
 
 	if (s && !strcmp(s, "nic"))
 		mac_randomize_bytes = 3;
@@ -1169,8 +1173,6 @@ bool wiphy_init(struct l_genl_family *in, const char *whitelist,
 		l_queue_destroy(wiphy_list, NULL);
 	}
 
-	nl80211 = in;
-
 	wiphy_list = l_queue_new();
 
 	rfkill_watch_add(wiphy_rfkill_cb, NULL);
@@ -1190,10 +1192,10 @@ bool wiphy_init(struct l_genl_family *in, const char *whitelist,
 	if (blacklist)
 		blacklist_filter = l_strsplit(blacklist, ',');
 
-	return true;
+	return 0;
 }
 
-bool wiphy_exit(void)
+static void wiphy_exit(void)
 {
 	l_strfreev(whitelist_filter);
 	l_strfreev(blacklist_filter);
@@ -1201,12 +1203,14 @@ bool wiphy_exit(void)
 	l_queue_destroy(wiphy_list, wiphy_free);
 	wiphy_list = NULL;
 
+	l_genl_family_free(nl80211);
 	nl80211 = NULL;
 	mac_randomize_bytes = 6;
 
 	l_dbus_unregister_interface(dbus_get_bus(), IWD_WIPHY_INTERFACE);
 
 	l_hwdb_unref(hwdb);
-
-	return true;
 }
+
+IWD_MODULE(wiphy, wiphy_init, wiphy_exit);
+IWD_MODULE_DEPENDS(wiphy, rfkill);
diff --git a/src/wiphy.h b/src/wiphy.h
index 10cf5373..61e1caf8 100644
--- a/src/wiphy.h
+++ b/src/wiphy.h
@@ -81,7 +81,3 @@ uint32_t wiphy_state_watch_add(struct wiphy *wiphy,
 				wiphy_state_watch_func_t func, void *user_data,
 				wiphy_destroy_func_t destroy);
 bool wiphy_state_watch_remove(struct wiphy *wiphy, uint32_t id);
-
-bool wiphy_init(struct l_genl_family *in, const char *whitelist,
-							const char *blacklist);
-bool wiphy_exit(void);
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 08/11] eap: remove mtu argument from eap_init
  2019-10-11 17:24 [PATCH 01/11] main: move module init into nl80211_appeared James Prestwood
                   ` (5 preceding siblings ...)
  2019-10-11 17:24 ` [PATCH 07/11] wiphy: " James Prestwood
@ 2019-10-11 17:24 ` James Prestwood
  2019-10-11 17:24 ` [PATCH 09/11] wired: update with new eap_init James Prestwood
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: James Prestwood @ 2019-10-11 17:24 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 2875 bytes --]

This was refactored to set the mtu via __eap_set_config rather than
passing the MTU into eap_init. This makes eap work in a similar fashion
as eapol (i.e. __eapol_set_config).

If __eap_set_config is not used, the MTU will be set to 1020, which is
the same as previously passing 0 to eap_init.
---
 src/eap.c  | 12 ++++++++----
 src/eap.h  |  4 +++-
 src/main.c |  7 ++-----
 3 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/src/eap.c b/src/eap.c
index f605f432..b0fa72cf 100644
--- a/src/eap.c
+++ b/src/eap.c
@@ -676,6 +676,12 @@ int eap_unregister_method(struct eap_method *method)
 	return -ENOENT;
 }
 
+void __eap_set_config(struct l_settings *config)
+{
+	if (!l_settings_get_uint(config, "EAP", "mtu", &default_mtu))
+		default_mtu = 1400; /* on WiFi the real MTU is around 2304 */
+}
+
 static void __eap_method_enable(struct eap_method_desc *start,
 					struct eap_method_desc *stop)
 {
@@ -715,7 +721,7 @@ static void __eap_method_disable(struct eap_method_desc *start,
 extern struct eap_method_desc __start___eap[];
 extern struct eap_method_desc __stop___eap[];
 
-void eap_init(uint32_t mtu)
+void eap_init(void)
 {
 	eap_methods = l_queue_new();
 	__eap_method_enable(__start___eap, __stop___eap);
@@ -725,10 +731,8 @@ void eap_init(uint32_t mtu)
 	 * EAP is capable of functioning on lower layers that
 	 *        provide an EAP MTU size of 1020 octets or greater.
 	 */
-	if (mtu == 0)
+	if (default_mtu == 0)
 		default_mtu = 1020;
-	else
-		default_mtu = mtu;
 }
 
 void eap_exit(void)
diff --git a/src/eap.h b/src/eap.h
index de939cdc..8f128304 100644
--- a/src/eap.h
+++ b/src/eap.h
@@ -93,5 +93,7 @@ const char *eap_get_identity(struct eap_state *eap);
 
 void eap_rx_packet(struct eap_state *eap, const uint8_t *pkt, size_t len);
 
-void eap_init(uint32_t default_mtu);
+void __eap_set_config(struct l_settings *config);
+
+void eap_init(void);
 void eap_exit(void);
diff --git a/src/main.c b/src/main.c
index 9d0da143..7123f7a9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -365,7 +365,6 @@ int main(int argc, char *argv[])
 	struct l_dbus *dbus;
 	const char *config_dir;
 	char **config_dirs;
-	uint32_t eap_mtu;
 	int i;
 
 	for (;;) {
@@ -463,9 +462,7 @@ int main(int argc, char *argv[])
 	l_strv_free(config_dirs);
 
 	__eapol_set_config(iwd_config);
-
-	if (!l_settings_get_uint(iwd_config, "EAP", "mtu", &eap_mtu))
-		eap_mtu = 1400; /* on WiFi the real MTU is around 2304 */
+	__eap_set_config(iwd_config);
 
 	exit_status = EXIT_FAILURE;
 
@@ -494,7 +491,7 @@ int main(int argc, char *argv[])
 	l_dbus_set_disconnect_handler(dbus, dbus_disconnected, NULL, NULL);
 	dbus_init(dbus);
 
-	eap_init(eap_mtu);
+	eap_init();
 
 	plugin_init(plugins, noplugins);
 	exit_status = l_main_run_with_signal(signal_handler, NULL);
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 09/11] wired: update with new eap_init
  2019-10-11 17:24 [PATCH 01/11] main: move module init into nl80211_appeared James Prestwood
                   ` (6 preceding siblings ...)
  2019-10-11 17:24 ` [PATCH 08/11] eap: remove mtu argument from eap_init James Prestwood
@ 2019-10-11 17:24 ` James Prestwood
  2019-10-11 17:24 ` [PATCH 10/11] unit: update wsc/eapol " James Prestwood
  2019-10-11 17:24 ` [PATCH 11/11] eap: utilize IWD_MODULE James Prestwood
  9 siblings, 0 replies; 13+ messages in thread
From: James Prestwood @ 2019-10-11 17:24 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 426 bytes --]

---
 wired/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/wired/main.c b/wired/main.c
index 7e6d26dd..09dbb72d 100644
--- a/wired/main.c
+++ b/wired/main.c
@@ -46,7 +46,7 @@ static void dbus_ready(struct l_dbus *dbus, void *user_data)
 
 	l_info("System ready");
 
-	eap_init(0);
+	eap_init();
 	network_init();
 	ethdev_init(opts->interfaces, opts->nointerfaces);
 }
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 10/11] unit: update wsc/eapol with new eap_init
  2019-10-11 17:24 [PATCH 01/11] main: move module init into nl80211_appeared James Prestwood
                   ` (7 preceding siblings ...)
  2019-10-11 17:24 ` [PATCH 09/11] wired: update with new eap_init James Prestwood
@ 2019-10-11 17:24 ` James Prestwood
  2019-10-11 17:24 ` [PATCH 11/11] eap: utilize IWD_MODULE James Prestwood
  9 siblings, 0 replies; 13+ messages in thread
From: James Prestwood @ 2019-10-11 17:24 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 2919 bytes --]

test-eapol was passing zero as the MTU, so this simply needed to be
updated to remove that parameter.

test-wsc was actually setting a MTU value so when building the
settings we now add the proper value so the MTU can be set with
__eap_set_config.
---
 unit/test-eapol.c | 4 ++--
 unit/test-wsc.c   | 8 ++++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/unit/test-eapol.c b/unit/test-eapol.c
index 177b2577..f7099e6d 100644
--- a/unit/test-eapol.c
+++ b/unit/test-eapol.c
@@ -2912,7 +2912,7 @@ static void eapol_sm_test_tls(struct eapol_8021x_tls_test_state *s,
 	aa = ap_address;
 	spa = sta_address;
 
-	eap_init(0);
+	eap_init();
 	eapol_init();
 	__handshake_set_get_nonce_func(test_nonce);
 
@@ -3375,7 +3375,7 @@ static void eapol_sm_test_eap_nak(const void *data)
 	aa = ap_address;
 	spa = sta_address;
 
-	eap_init(0);
+	eap_init();
 	eapol_init();
 	__handshake_set_get_nonce_func(test_nonce);
 
diff --git a/unit/test-wsc.c b/unit/test-wsc.c
index b1a6d786..b4814622 100644
--- a/unit/test-wsc.c
+++ b/unit/test-wsc.c
@@ -1989,7 +1989,7 @@ static void wsc_test_pbc_handshake(const void *data)
 	char *hex;
 	struct l_settings *settings;
 
-	eap_init(1400);
+	eap_init();
 	eapol_init();
 
 	hs = test_handshake_state_new(1);
@@ -2006,6 +2006,7 @@ static void wsc_test_pbc_handshake(const void *data)
 	eapol_sm_set_event_func(sm, verify_credential);
 
 	settings = l_settings_new();
+	l_settings_set_uint(settings, "EAP", "mtu", 1400);
 	l_settings_set_string(settings, "Security", "EAP-Identity",
 					"WFA-SimpleConfig-Enrollee-1-0");
 	l_settings_set_string(settings, "Security", "EAP-Method", "WSC");
@@ -2039,6 +2040,7 @@ static void wsc_test_pbc_handshake(const void *data)
 	l_settings_set_string(settings, "WSC", "IV2",
 					"4e3a4cf088176989e148d4c10b96e8fd");
 
+	__eap_set_config(settings);
 	handshake_state_set_8021x_config(hs, settings);
 	eapol_start(sm);
 
@@ -2097,7 +2099,7 @@ static void wsc_test_retransmission_no_fragmentation(const void *data)
 	char *hex;
 	struct l_settings *settings;
 
-	eap_init(1400);
+	eap_init();
 	eapol_init();
 
 	hs = test_handshake_state_new(1);
@@ -2114,6 +2116,7 @@ static void wsc_test_retransmission_no_fragmentation(const void *data)
 	eapol_sm_set_event_func(sm, verify_credential);
 
 	settings = l_settings_new();
+	l_settings_set_uint(settings, "EAP", "mtu", 1400);
 	l_settings_set_string(settings, "Security", "EAP-Identity",
 					"WFA-SimpleConfig-Enrollee-1-0");
 	l_settings_set_string(settings, "Security", "EAP-Method", "WSC");
@@ -2147,6 +2150,7 @@ static void wsc_test_retransmission_no_fragmentation(const void *data)
 	l_settings_set_string(settings, "WSC", "IV2",
 					"4e3a4cf088176989e148d4c10b96e8fd");
 
+	__eap_set_config(settings);
 	handshake_state_set_8021x_config(hs, settings);
 	eapol_start(sm);
 
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 11/11] eap: utilize IWD_MODULE
  2019-10-11 17:24 [PATCH 01/11] main: move module init into nl80211_appeared James Prestwood
                   ` (8 preceding siblings ...)
  2019-10-11 17:24 ` [PATCH 10/11] unit: update wsc/eapol " James Prestwood
@ 2019-10-11 17:24 ` James Prestwood
  9 siblings, 0 replies; 13+ messages in thread
From: James Prestwood @ 2019-10-11 17:24 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 1939 bytes --]

Converts eap into an IWD module.
---
 src/eap.c  | 7 ++++++-
 src/eap.h  | 2 +-
 src/main.c | 4 ----
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/eap.c b/src/eap.c
index b0fa72cf..23868811 100644
--- a/src/eap.c
+++ b/src/eap.c
@@ -33,6 +33,7 @@
 #include "src/missing.h"
 #include "src/eap.h"
 #include "src/eap-private.h"
+#include "src/iwd.h"
 
 static uint32_t default_mtu;
 static struct l_queue *eap_methods;
@@ -721,7 +722,7 @@ static void __eap_method_disable(struct eap_method_desc *start,
 extern struct eap_method_desc __start___eap[];
 extern struct eap_method_desc __stop___eap[];
 
-void eap_init(void)
+int eap_init(void)
 {
 	eap_methods = l_queue_new();
 	__eap_method_enable(__start___eap, __stop___eap);
@@ -733,6 +734,8 @@ void eap_init(void)
 	 */
 	if (default_mtu == 0)
 		default_mtu = 1020;
+
+	return 0;
 }
 
 void eap_exit(void)
@@ -740,3 +743,5 @@ void eap_exit(void)
 	__eap_method_disable(__start___eap, __stop___eap);
 	l_queue_destroy(eap_methods, NULL);
 }
+
+IWD_MODULE(eap, eap_init, eap_exit);
diff --git a/src/eap.h b/src/eap.h
index 8f128304..8b2de8c9 100644
--- a/src/eap.h
+++ b/src/eap.h
@@ -95,5 +95,5 @@ void eap_rx_packet(struct eap_state *eap, const uint8_t *pkt, size_t len);
 
 void __eap_set_config(struct l_settings *config);
 
-void eap_init(void);
+int eap_init(void);
 void eap_exit(void);
diff --git a/src/main.c b/src/main.c
index 7123f7a9..9c5ab9ac 100644
--- a/src/main.c
+++ b/src/main.c
@@ -491,16 +491,12 @@ int main(int argc, char *argv[])
 	l_dbus_set_disconnect_handler(dbus, dbus_disconnected, NULL, NULL);
 	dbus_init(dbus);
 
-	eap_init();
-
 	plugin_init(plugins, noplugins);
 	exit_status = l_main_run_with_signal(signal_handler, NULL);
 	plugin_exit();
 
 	iwd_modules_exit();
 
-	eap_exit();
-
 	dbus_exit();
 	l_dbus_destroy(dbus);
 	storage_cleanup_dirs();
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 05/11] agent: utilize IWD_MODULE
  2019-10-11 17:24 ` [PATCH 05/11] agent: " James Prestwood
@ 2019-10-11 18:53   ` Denis Kenzior
  0 siblings, 0 replies; 13+ messages in thread
From: Denis Kenzior @ 2019-10-11 18:53 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 443 bytes --]

Hi James,

On 10/11/19 12:24 PM, James Prestwood wrote:
> Converts agent into an IWD module. This removes the dbus dependency
> on agent. Since dbus is initialized very early we can assume
> dbus_get_bus is going to return a valid object.
> ---
>   src/agent.c | 19 ++++++++++++-------
>   src/agent.h |  2 --
>   src/dbus.c  |  3 +--
>   3 files changed, 13 insertions(+), 11 deletions(-)
> 

Applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 06/11] manager: utilize IWD_MODULE
  2019-10-11 17:24 ` [PATCH 06/11] manager: " James Prestwood
@ 2019-10-11 18:57   ` Denis Kenzior
  0 siblings, 0 replies; 13+ messages in thread
From: Denis Kenzior @ 2019-10-11 18:57 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 1630 bytes --]

Hi James,

On 10/11/19 12:24 PM, James Prestwood wrote:
> Converts manager into an IWD module. Two getters needed to be added so
> manager can get the white/black list of interfaces.

Can we split this up into two commits please.  One for the getter 
refactoring and one for the module migration.

> ---
>   src/iwd.h     |  5 ++---
>   src/main.c    | 13 ++++++++++---
>   src/manager.c | 26 ++++++++++++++++++--------
>   3 files changed, 30 insertions(+), 14 deletions(-)
> 
> diff --git a/src/iwd.h b/src/iwd.h
> index 7ae7e4b4..8814c244 100644
> --- a/src/iwd.h
> +++ b/src/iwd.h
> @@ -30,9 +30,8 @@ struct l_genl *iwd_get_genl(void);
>   
>   void netdev_shutdown(void);
>   
> -bool manager_init(struct l_genl_family *in,
> -			const char *if_whitelist, const char *if_blacklist);
> -void manager_exit(void);
> +const char *iwd_get_iface_whitelist(void);
> +const char *iwd_get_iface_blacklist(void);

Don't we also have phy lists?  Ah I guess you take care of this in the 
next patch...

>   
>   struct iwd_module_desc {
>   	const char *name;

<snip>

> @@ -637,10 +639,15 @@ bool manager_init(struct l_genl_family *in,
>   	if (randomize_str && !strcmp(randomize_str, "once"))
>   		randomize = true;
>   
> -	return true;
> +	return 0;
> +
> +error:
> +	l_queue_destroy(pending_wiphys, NULL);
> +	l_genl_family_free(nl80211);

Maybe reset nl80211 to NULL just to be pedantic

> +	return -EIO;
>   }
>   
> -void manager_exit(void)
> +static void manager_exit(void)
>   {
>   	l_strfreev(whitelist_filter);
>   	l_strfreev(blacklist_filter);

Regards,
-Denis

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2019-10-11 18:57 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-11 17:24 [PATCH 01/11] main: move module init into nl80211_appeared James Prestwood
2019-10-11 17:24 ` [PATCH 02/11] netdev: utilize IWD_MODULE James Prestwood
2019-10-11 17:24 ` [PATCH 03/11] eapol: " James Prestwood
2019-10-11 17:24 ` [PATCH 04/11] anqp: " James Prestwood
2019-10-11 17:24 ` [PATCH 05/11] agent: " James Prestwood
2019-10-11 18:53   ` Denis Kenzior
2019-10-11 17:24 ` [PATCH 06/11] manager: " James Prestwood
2019-10-11 18:57   ` Denis Kenzior
2019-10-11 17:24 ` [PATCH 07/11] wiphy: " James Prestwood
2019-10-11 17:24 ` [PATCH 08/11] eap: remove mtu argument from eap_init James Prestwood
2019-10-11 17:24 ` [PATCH 09/11] wired: update with new eap_init James Prestwood
2019-10-11 17:24 ` [PATCH 10/11] unit: update wsc/eapol " James Prestwood
2019-10-11 17:24 ` [PATCH 11/11] eap: utilize IWD_MODULE James Prestwood

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox