summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2018-05-15 20:29:30 +0200
committerLubomir Rintel <lkundrak@v3.sk>2018-06-26 16:21:54 +0200
commit6371f399ae6b69ccc2ca743b77803ba1ffa8d17e (patch)
tree5c1a897f6277fddd5d9f238202505187762fc24d
parent123b79518ce274971e502cd99acc808d3b792842 (diff)
downloadNetworkManager-6371f399ae6b69ccc2ca743b77803ba1ffa8d17e.tar.gz
platform: move the management of the genl socket to linux-platform
We're fine with a single genl socket instead of opening a new one for each WifiData instance.
-rw-r--r--src/platform/nm-linux-platform.c29
-rw-r--r--src/platform/wifi/nm-wifi-utils-nl80211.c16
-rw-r--r--src/platform/wifi/nm-wifi-utils-nl80211.h3
-rw-r--r--src/platform/wifi/nm-wifi-utils.c4
-rw-r--r--src/platform/wifi/nm-wifi-utils.h3
5 files changed, 39 insertions, 16 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index 085abca6a4..56f2cee591 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -317,6 +317,7 @@ static void cache_on_change (NMPlatform *platform,
const NMPObject *obj_new);
static void cache_prune_all (NMPlatform *platform);
static gboolean event_handler_read_netlink (NMPlatform *platform, gboolean wait_for_acks);
+static struct nl_sock *_genl_sock (NMLinuxPlatform *platform);
/*****************************************************************************/
@@ -1936,7 +1937,9 @@ _new_from_nl_link (NMPlatform *platform, const NMPCache *cache, struct nlmsghdr
obj->_link.wifi_data = nm_wifi_utils_wext_new (ifi->ifi_index, FALSE);
#endif
} else {
- obj->_link.wifi_data = nm_wifi_utils_new (ifi->ifi_index, TRUE);
+ obj->_link.wifi_data = nm_wifi_utils_new (ifi->ifi_index,
+ _genl_sock (NM_LINUX_PLATFORM (platform)),
+ TRUE);
}
}
@@ -2994,6 +2997,8 @@ typedef struct {
} DelayedActionWaitForNlResponseData;
typedef struct {
+ struct nl_sock *genl;
+
struct nl_sock *nlh;
guint32 nlh_seq_next;
#ifdef NM_MORE_LOGGING
@@ -3064,6 +3069,14 @@ nm_linux_platform_setup (void)
/*****************************************************************************/
+static struct nl_sock *
+_genl_sock (NMLinuxPlatform *platform)
+{
+ NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
+
+ return priv->genl;
+}
+
#define ASSERT_SYSCTL_ARGS(pathid, dirfd, path) \
G_STMT_START { \
const char *const _pathid = (pathid); \
@@ -7049,6 +7062,18 @@ constructed (GObject *_object)
nmp_netns_get_current () == nmp_netns_get_initial () ? "/main" : "")),
nm_platform_get_use_udev (platform) ? "use" : "no");
+
+ priv->genl = nl_socket_alloc ();
+ g_assert (priv->genl);
+
+ nle = nl_connect (priv->genl, NETLINK_GENERIC);
+ if (nle) {
+ _LOGE ("unable to connect the generic netlink socket \"%s\" (%d)",
+ nl_geterror (nle), -nle);
+ nl_socket_free (priv->genl);
+ priv->genl = NULL;
+ }
+
priv->nlh = nl_socket_alloc ();
g_assert (priv->nlh);
@@ -7167,6 +7192,8 @@ finalize (GObject *object)
g_ptr_array_unref (priv->delayed_action.list_refresh_link);
g_array_unref (priv->delayed_action.list_wait_for_nl_response);
+ nl_socket_free (priv->genl);
+
g_source_remove (priv->event_id);
g_io_channel_unref (priv->event_channel);
nl_socket_free (priv->nlh);
diff --git a/src/platform/wifi/nm-wifi-utils-nl80211.c b/src/platform/wifi/nm-wifi-utils-nl80211.c
index 4965dc3fbc..1728ad1809 100644
--- a/src/platform/wifi/nm-wifi-utils-nl80211.c
+++ b/src/platform/wifi/nm-wifi-utils-nl80211.c
@@ -174,10 +174,6 @@ dispose (GObject *object)
{
NMWifiUtilsNl80211 *nl80211 = NM_WIFI_UTILS_NL80211 (object);
- if (nl80211->nl_sock) {
- nl_socket_free (nl80211->nl_sock);
- nl80211->nl_sock = NULL;
- }
g_clear_pointer (&nl80211->freqs, g_free);
}
@@ -931,13 +927,16 @@ nm_wifi_utils_nl80211_class_init (NMWifiUtilsNl80211Class *klass)
}
NMWifiUtils *
-nm_wifi_utils_nl80211_new (int ifindex)
+nm_wifi_utils_nl80211_new (int ifindex, struct nl_sock *genl)
{
NMWifiUtilsNl80211 *nl80211;
nm_auto_nlmsg struct nl_msg *msg = NULL;
struct nl80211_device_info device_info = {};
char ifname[IFNAMSIZ];
+ if (!genl)
+ return NULL;
+
if (!nmp_utils_if_indextoname (ifindex, ifname)) {
_LOGW (LOGD_PLATFORM | LOGD_WIFI,
"can't determine interface name for ifindex %d", ifindex);
@@ -947,12 +946,7 @@ nm_wifi_utils_nl80211_new (int ifindex)
nl80211 = g_object_new (NM_TYPE_WIFI_UTILS_NL80211, NULL);
nl80211->parent.ifindex = ifindex;
- nl80211->nl_sock = nl_socket_alloc ();
- if (nl80211->nl_sock == NULL)
- goto error;
-
- if (nl_connect (nl80211->nl_sock, NETLINK_GENERIC))
- goto error;
+ nl80211->nl_sock = genl;
nl80211->id = genl_ctrl_resolve (nl80211->nl_sock, "nl80211");
if (nl80211->id < 0) {
diff --git a/src/platform/wifi/nm-wifi-utils-nl80211.h b/src/platform/wifi/nm-wifi-utils-nl80211.h
index caa99b1c4b..27f67697e2 100644
--- a/src/platform/wifi/nm-wifi-utils-nl80211.h
+++ b/src/platform/wifi/nm-wifi-utils-nl80211.h
@@ -23,6 +23,7 @@
#define __WIFI_UTILS_NL80211_H__
#include "nm-wifi-utils.h"
+#include "platform/nm-netlink.h"
#define NM_TYPE_WIFI_UTILS_NL80211 (nm_wifi_utils_nl80211_get_type ())
#define NM_WIFI_UTILS_NL80211(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_WIFI_UTILS_NL80211, NMWifiUtilsNl80211))
@@ -33,6 +34,6 @@
GType nm_wifi_utils_nl80211_get_type (void);
-NMWifiUtils *nm_wifi_utils_nl80211_new (int ifindex);
+NMWifiUtils *nm_wifi_utils_nl80211_new (int ifindex, struct nl_sock *genl);
#endif /* __WIFI_UTILS_NL80211_H__ */
diff --git a/src/platform/wifi/nm-wifi-utils.c b/src/platform/wifi/nm-wifi-utils.c
index be60699e44..25d71c6a88 100644
--- a/src/platform/wifi/nm-wifi-utils.c
+++ b/src/platform/wifi/nm-wifi-utils.c
@@ -52,13 +52,13 @@ nm_wifi_utils_class_init (NMWifiUtilsClass *klass)
}
NMWifiUtils *
-nm_wifi_utils_new (int ifindex, gboolean check_scan)
+nm_wifi_utils_new (int ifindex, struct nl_sock *genl, gboolean check_scan)
{
NMWifiUtils *ret;
g_return_val_if_fail (ifindex > 0, NULL);
- ret = nm_wifi_utils_nl80211_new (ifindex);
+ ret = nm_wifi_utils_nl80211_new (ifindex, genl);
#if HAVE_WEXT
if (ret == NULL)
diff --git a/src/platform/wifi/nm-wifi-utils.h b/src/platform/wifi/nm-wifi-utils.h
index f946f4b9c4..6cd178bd93 100644
--- a/src/platform/wifi/nm-wifi-utils.h
+++ b/src/platform/wifi/nm-wifi-utils.h
@@ -26,6 +26,7 @@
#include "nm-dbus-interface.h"
#include "nm-setting-wireless.h"
+#include "platform/nm-netlink.h"
typedef struct NMWifiUtils NMWifiUtils;
@@ -40,7 +41,7 @@ GType nm_wifi_utils_get_type (void);
gboolean nm_wifi_utils_is_wifi (int dirfd, const char *ifname);
-NMWifiUtils *nm_wifi_utils_new (int ifindex, gboolean check_scan);
+NMWifiUtils *nm_wifi_utils_new (int ifindex, struct nl_sock *genl, gboolean check_scan);
NMDeviceWifiCapabilities nm_wifi_utils_get_caps (NMWifiUtils *data);