commit da52bcd109061cb4a73f65971f148466e0add030
parent b3e937e11a24fc211b5269af5ffe96ad29ca4ee2
Author: Denis Kenzior <denkenz@gmail.com>
Date: Fri, 17 Aug 2018 23:23:19 -0500
netdev: Rework netdev_init/exit
Diffstat:
4 files changed, 36 insertions(+), 33 deletions(-)
diff --git a/src/iwd.h b/src/iwd.h
@@ -22,6 +22,7 @@
#define uninitialized_var(x) x = x
+struct l_genl_family;
struct device;
typedef void (*iwd_device_foreach_func)(struct device *, void *data);
@@ -32,6 +33,11 @@ const struct l_settings *iwd_get_config(void);
void iwd_shutdown(void);
+bool netdev_init(const char *whitelist, const char *blacklist);
+void netdev_exit(void);
+void netdev_set_nl80211(struct l_genl_family *nl80211);
+void netdev_shutdown(void);
+
void network_init();
void network_exit();
diff --git a/src/main.c b/src/main.c
@@ -34,7 +34,6 @@
#include "linux/nl80211.h"
#include "src/iwd.h"
-#include "src/netdev.h"
#include "src/wiphy.h"
#include "src/dbus.h"
#include "src/eap.h"
@@ -147,8 +146,7 @@ static void nl80211_appeared(void *user_data)
if (!wiphy_init(nl80211, phys, nophys))
l_error("Unable to init wiphy functionality");
- if (!netdev_init(nl80211, interfaces, nointerfaces))
- l_error("Unable to init netdev functionality");
+ netdev_set_nl80211(nl80211);
if (!scan_init(nl80211))
l_error("Unable to init scan functionality");
@@ -162,7 +160,6 @@ static void nl80211_vanished(void *user_data)
ap_exit();
scan_exit();
- netdev_exit();
wiphy_exit();
}
@@ -430,6 +427,9 @@ int main(int argc, char *argv[])
eapol_init();
rfkill_init();
+ if (!netdev_init(interfaces, nointerfaces))
+ goto fail_netdev;
+
if (!device_init())
goto fail_device;
@@ -451,6 +451,8 @@ int main(int argc, char *argv[])
adhoc_exit();
device_exit();
fail_device:
+ netdev_exit();
+fail_netdev:
rfkill_exit();
eapol_exit();
eap_exit();
diff --git a/src/netdev.c b/src/netdev.c
@@ -4552,12 +4552,8 @@ bool netdev_station_watch_remove(struct netdev *netdev, uint32_t id)
return watchlist_remove(&netdev->station_watches, id);
}
-bool netdev_init(struct l_genl_family *in,
- const char *whitelist, const char *blacklist)
+bool netdev_init(const char *whitelist, const char *blacklist)
{
- struct l_genl_msg *msg;
- struct l_genl *genl = l_genl_family_get_genl(in);
-
if (rtnl)
return false;
@@ -4581,6 +4577,27 @@ bool netdev_init(struct l_genl_family *in,
netdev_list = l_queue_new();
+ __handshake_set_install_tk_func(netdev_set_tk);
+ __handshake_set_install_gtk_func(netdev_set_gtk);
+ __handshake_set_install_igtk_func(netdev_set_igtk);
+
+ __eapol_set_rekey_offload_func(netdev_set_rekey_offload);
+ __eapol_set_tx_packet_func(netdev_control_port_frame);
+
+ if (whitelist)
+ whitelist_filter = l_strsplit(whitelist, ',');
+
+ if (blacklist)
+ blacklist_filter = l_strsplit(blacklist, ',');
+
+ return true;
+}
+
+void netdev_set_nl80211(struct l_genl_family *in)
+{
+ struct l_genl_msg *msg;
+ struct l_genl *genl = l_genl_family_get_genl(in);
+
nl80211 = in;
if (!l_genl_family_register(nl80211, "config", netdev_config_notify,
@@ -4599,27 +4616,12 @@ bool netdev_init(struct l_genl_family *in,
if (!l_genl_set_unicast_handler(genl, netdev_unicast_notify,
NULL, NULL))
l_error("Registering for unicast notification failed");
-
- __handshake_set_install_tk_func(netdev_set_tk);
- __handshake_set_install_gtk_func(netdev_set_gtk);
- __handshake_set_install_igtk_func(netdev_set_igtk);
-
- __eapol_set_rekey_offload_func(netdev_set_rekey_offload);
- __eapol_set_tx_packet_func(netdev_control_port_frame);
-
- if (whitelist)
- whitelist_filter = l_strsplit(whitelist, ',');
-
- if (blacklist)
- blacklist_filter = l_strsplit(blacklist, ',');
-
- return true;
}
-bool netdev_exit(void)
+void netdev_exit(void)
{
if (!rtnl)
- return false;
+ return;
l_strfreev(whitelist_filter);
l_strfreev(blacklist_filter);
@@ -4629,8 +4631,6 @@ bool netdev_exit(void)
l_debug("Closing route netlink socket");
l_netlink_destroy(rtnl);
rtnl = NULL;
-
- return true;
}
void netdev_shutdown(void)
diff --git a/src/netdev.h b/src/netdev.h
@@ -175,8 +175,3 @@ uint32_t netdev_station_watch_add(struct netdev *netdev,
netdev_station_watch_func_t func, void *user_data);
bool netdev_station_watch_remove(struct netdev *netdev, uint32_t id);
-
-bool netdev_init(struct l_genl_family *in,
- const char *whitelist, const char *blacklist);
-bool netdev_exit(void);
-void netdev_shutdown(void);