diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2018-05-15 16:47:13 +0200 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2018-06-26 16:21:54 +0200 |
commit | 123b79518ce274971e502cd99acc808d3b792842 (patch) | |
tree | 0b50e08c919d233219d41e9f8876e2b556ce4b58 | |
parent | 0b4010d740d27c65e4790ec5709d55655ddc0749 (diff) | |
download | NetworkManager-123b79518ce274971e502cd99acc808d3b792842.tar.gz |
platform: attach WifiData to NMPObject
This fixes leakage of the WifiData structures.
-rw-r--r-- | src/platform/nm-linux-platform.c | 64 | ||||
-rw-r--r-- | src/platform/nmp-object.c | 12 | ||||
-rw-r--r-- | src/platform/nmp-object.h | 4 | ||||
-rw-r--r-- | src/platform/tests/test-general.c | 4 |
4 files changed, 50 insertions, 34 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 60ffd6df6e..085abca6a4 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -1714,6 +1714,7 @@ _new_from_nl_link (NMPlatform *platform, const NMPCache *cache, struct nlmsghdr NMPObject *lnk_data = NULL; gboolean address_complete_from_cache = TRUE; gboolean lnk_data_complete_from_cache = TRUE; + gboolean need_wifi_data = FALSE; gboolean af_inet6_token_valid = FALSE; gboolean af_inet6_addr_gen_mode_valid = FALSE; @@ -1868,6 +1869,11 @@ _new_from_nl_link (NMPlatform *platform, const NMPCache *cache, struct nlmsghdr case NM_LINK_TYPE_VXLAN: lnk_data = _parse_lnk_vxlan (nl_info_kind, nl_info_data); break; + case NM_LINK_TYPE_WIFI: + case NM_LINK_TYPE_OLPC_MESH: + need_wifi_data = TRUE; + lnk_data_complete_from_cache = FALSE; + break; default: lnk_data_complete_from_cache = FALSE; break; @@ -1895,6 +1901,14 @@ _new_from_nl_link (NMPlatform *platform, const NMPCache *cache, struct nlmsghdr nmp_object_unref (lnk_data); lnk_data = (NMPObject *) nmp_object_ref (link_cached->_link.netlink.lnk); } + + if ( need_wifi_data + && link_cached->link.type == obj->link.type + && link_cached->_link.wifi_data) { + /* Prefer reuse of existing wifi_data object */ + obj->_link.wifi_data = g_object_ref (link_cached->_link.wifi_data); + } + if (address_complete_from_cache) obj->link.addr = link_cached->link.addr; if (!af_inet6_token_valid) @@ -1912,6 +1926,20 @@ _new_from_nl_link (NMPlatform *platform, const NMPCache *cache, struct nlmsghdr obj->_link.netlink.lnk = lnk_data; + if (need_wifi_data && obj->_link.wifi_data == NULL) { + if (obj->link.type == NM_LINK_TYPE_OLPC_MESH) { +#if HAVE_WEXT + /* The kernel driver now uses nl80211, but we force use of WEXT because + * the cfg80211 interactions are not quite ready to support access to + * mesh control through nl80211 just yet. + */ + 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.netlink.is_in_netlink = TRUE; id_only_handled: obj_result = obj; @@ -2997,8 +3025,6 @@ typedef struct { gint is_handling; } delayed_action; - - GHashTable *wifi_data; } NMLinuxPlatformPrivate; struct _NMLinuxPlatform { @@ -5983,34 +6009,15 @@ infiniband_partition_delete (NMPlatform *platform, int parent, int p_key) static NMWifiUtils * wifi_get_wifi_data (NMPlatform *platform, int ifindex) { - NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform); - const NMPlatformLink *pllink; - NMWifiUtils *wifi_data; - - wifi_data = g_hash_table_lookup (priv->wifi_data, GINT_TO_POINTER (ifindex)); - - if (!wifi_data) { - pllink = nm_platform_link_get (platform, ifindex); - if (pllink) { - if (pllink->type == NM_LINK_TYPE_WIFI) - wifi_data = nm_wifi_utils_new (ifindex, TRUE); - else if (pllink->type == NM_LINK_TYPE_OLPC_MESH) { - /* The kernel driver now uses nl80211, but we force use of WEXT because - * the cfg80211 interactions are not quite ready to support access to - * mesh control through nl80211 just yet. - */ -#if HAVE_WEXT - wifi_data = nm_wifi_utils_wext_new (ifindex, FALSE); -#endif - } + const NMPObject *obj; - if (wifi_data) - g_hash_table_insert (priv->wifi_data, GINT_TO_POINTER (ifindex), wifi_data); - } - } + obj = nmp_cache_lookup_link (nm_platform_get_cache (platform), ifindex); + if (!obj) + return NULL; - return wifi_data; + return obj->_link.wifi_data; } + #define WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, retval) \ nm_auto_pop_netns NMPNetns *netns = NULL; \ NMWifiUtils *wifi_data; \ @@ -7013,7 +7020,6 @@ nm_linux_platform_init (NMLinuxPlatform *self) priv->delayed_action.list_master_connected = g_ptr_array_new (); priv->delayed_action.list_refresh_link = g_ptr_array_new (); priv->delayed_action.list_wait_for_nl_response = g_array_new (FALSE, TRUE, sizeof (DelayedActionWaitForNlResponseData)); - priv->wifi_data = g_hash_table_new_full (nm_direct_hash, NULL, NULL, g_object_unref); } static void @@ -7165,8 +7171,6 @@ finalize (GObject *object) g_io_channel_unref (priv->event_channel); nl_socket_free (priv->nlh); - g_hash_table_unref (priv->wifi_data); - if (priv->sysctl_get_prev_values) { sysctl_clear_cache_list = g_slist_remove (sysctl_clear_cache_list, object); g_hash_table_destroy (priv->sysctl_get_prev_values); diff --git a/src/platform/nmp-object.c b/src/platform/nmp-object.c index 50e6825bf9..55d7a29d37 100644 --- a/src/platform/nmp-object.c +++ b/src/platform/nmp-object.c @@ -15,7 +15,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright (C) 2015 - 2017 Red Hat, Inc. + * Copyright (C) 2015 - 2018 Red Hat, Inc. */ #include "nm-default.h" @@ -31,6 +31,8 @@ #include "nm-core-utils.h" #include "nm-platform-utils.h" +#include "wifi/nm-wifi-utils.h" + /*****************************************************************************/ #define _NMLOG_DOMAIN LOGD_PLATFORM @@ -456,6 +458,8 @@ _vt_cmd_obj_dispose_link (NMPObject *obj) udev_device_unref (obj->_link.udev.device); obj->_link.udev.device = NULL; } + if (obj->_link.wifi_data) + g_clear_object (&obj->_link.wifi_data); nmp_object_unref (obj->_link.netlink.lnk); } @@ -908,6 +912,12 @@ _vt_cmd_obj_copy_link (NMPObject *dst, const NMPObject *src) nmp_object_unref (dst->_link.netlink.lnk); dst->_link.netlink.lnk = src->_link.netlink.lnk; } + if (dst->_link.wifi_data != src->_link.wifi_data) { + if (dst->_link.wifi_data) + g_clear_object (&dst->_link.wifi_data); + if (src->_link.wifi_data) + dst->_link.wifi_data = g_object_ref (src->_link.wifi_data); + } dst->_link = src->_link; } diff --git a/src/platform/nmp-object.h b/src/platform/nmp-object.h index f473f4628f..9489453195 100644 --- a/src/platform/nmp-object.h +++ b/src/platform/nmp-object.h @@ -15,7 +15,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright (C) 2015 - 2017 Red Hat, Inc. + * Copyright (C) 2015 - 2018 Red Hat, Inc. */ #ifndef __NMP_OBJECT_H__ @@ -164,6 +164,8 @@ typedef struct { */ struct udev_device *device; } udev; + + struct NMWifiUtils *wifi_data; } NMPObjectLink; typedef struct { diff --git a/src/platform/tests/test-general.c b/src/platform/tests/test-general.c index 8708c80f72..eebc15d80d 100644 --- a/src/platform/tests/test-general.c +++ b/src/platform/tests/test-general.c @@ -15,7 +15,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright (C) 2015 Red Hat, Inc. + * Copyright (C) 2015 - 2018 Red Hat, Inc. */ #include "nm-default.h" @@ -57,7 +57,7 @@ NMTST_DEFINE (); int main (int argc, char **argv) { - nmtst_init_assert_logging (&argc, &argv, "INFO", "DEFAULT"); + nmtst_init_assert_logging (&argc, &argv, "WARN", "DEFAULT"); g_test_add_func ("/general/init_linux_platform", test_init_linux_platform); g_test_add_func ("/general/link_get_all", test_link_get_all); |