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.
This commit is contained in:
Lubomir Rintel 2018-05-15 20:29:30 +02:00
parent 123b79518c
commit 6371f399ae
5 changed files with 39 additions and 16 deletions

View file

@ -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);

View file

@ -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) {

View file

@ -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__ */

View file

@ -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)

View file

@ -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);