summary refs log tree commit diff
path: root/src/core/NetworkManagerUtils.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2022-01-13 22:30:39 +0100
committerMichael Biebl <biebl@debian.org>2022-01-13 22:30:39 +0100
commit88c227d90a6b7b388c5c85d72802a0ca8f05ed5c (patch)
tree71f32df6617802270e8a78574bd8e1637dc532f4 /src/core/NetworkManagerUtils.c
parente74c568b07b50b97873fb4ee1d776dedefbd54d6 (diff)
New upstream version 1.34.0 upstream/1.34.0
Diffstat (limited to 'src/core/NetworkManagerUtils.c')
-rw-r--r--src/core/NetworkManagerUtils.c72
1 files changed, 47 insertions, 25 deletions
diff --git a/src/core/NetworkManagerUtils.c b/src/core/NetworkManagerUtils.c
index 7d3e80be..0da8e0a9 100644
--- a/src/core/NetworkManagerUtils.c
+++ b/src/core/NetworkManagerUtils.c
@@ -17,6 +17,7 @@
 #include "libnm-glib-aux/nm-uuid.h"
 #include "libnm-glib-aux/nm-str-buf.h"
 #include "libnm-base/nm-net-aux.h"
+#include "libnm-core-aux-intern/nm-libnm-core-utils.h"
 #include "libnm-core-aux-intern/nm-common-macros.h"
 #include "nm-utils.h"
 #include "nm-setting-connection.h"
@@ -112,7 +113,7 @@ get_new_connection_name(NMConnection *const *existing_connections,
          * connection id. */
         temp = g_strdup_printf(C_("connection id fallback", "%s %u"), fallback_prefix, i);
 
-        if (nm_utils_strv_find_first((char **) existing_names, existing_len, temp) < 0)
+        if (nm_strv_find_first(existing_names, existing_len, temp) < 0)
             return temp;
 
         g_free(temp);
@@ -227,28 +228,28 @@ out:
 /*****************************************************************************/
 
 void
-nm_utils_complete_generic(NMPlatform *         platform,
-                          NMConnection *       connection,
-                          const char *         ctype,
-                          NMConnection *const *existing_connections,
-                          const char *         preferred_id,
-                          const char *         fallback_id_prefix,
-                          const char *         ifname_prefix,
-                          const char *         ifname,
-                          gboolean             default_enable_ipv6)
+_nm_utils_complete_generic_with_params(NMPlatform *         platform,
+                                       NMConnection *       connection,
+                                       const char *         ctype,
+                                       NMConnection *const *existing_connections,
+                                       const char *         preferred_id,
+                                       const char *         fallback_id_prefix,
+                                       const char *         ifname_prefix,
+                                       const char *         ifname,
+                                       ...)
 {
     NMSettingConnection *s_con;
-    char *               id, *generated_ifname;
-    GHashTable *         parameters;
+    char *               id;
+    char *               generated_ifname;
+    gs_unref_hashtable GHashTable *parameters = NULL;
+    va_list                        ap;
+    const char *                   p_val;
+    const char *                   p_key;
 
     g_assert(fallback_id_prefix);
     g_return_if_fail(ifname_prefix == NULL || ifname == NULL);
 
-    s_con = nm_connection_get_setting_connection(connection);
-    if (!s_con) {
-        s_con = (NMSettingConnection *) nm_setting_connection_new();
-        nm_connection_add_setting(connection, NM_SETTING(s_con));
-    }
+    s_con = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_CONNECTION);
     g_object_set(G_OBJECT(s_con), NM_SETTING_CONNECTION_TYPE, ctype, NULL);
 
     if (!nm_setting_connection_get_uuid(s_con)) {
@@ -268,7 +269,9 @@ nm_utils_complete_generic(NMPlatform *         platform,
     }
 
     /* Add an interface name, if requested */
-    if (ifname) {
+    if (nm_setting_connection_get_interface_name(s_con)) {
+        /* pass */
+    } else if (ifname) {
         g_object_set(G_OBJECT(s_con), NM_SETTING_CONNECTION_INTERFACE_NAME, ifname, NULL);
     } else if (ifname_prefix && !nm_setting_connection_get_interface_name(s_con)) {
         generated_ifname = get_new_connection_ifname(platform, existing_connections, ifname_prefix);
@@ -277,13 +280,20 @@ nm_utils_complete_generic(NMPlatform *         platform,
     }
 
     /* Normalize */
-    parameters = g_hash_table_new(nm_str_hash, g_str_equal);
-    g_hash_table_insert(parameters,
-                        NM_CONNECTION_NORMALIZE_PARAM_IP6_CONFIG_METHOD,
-                        default_enable_ipv6 ? NM_SETTING_IP6_CONFIG_METHOD_AUTO
-                                            : NM_SETTING_IP6_CONFIG_METHOD_IGNORE);
+    va_start(ap, ifname);
+    while ((p_key = va_arg(ap, const char *))) {
+        p_val = va_arg(ap, const char *);
+        if (!p_val) {
+            if (parameters)
+                g_hash_table_remove(parameters, p_key);
+            continue;
+        }
+        if (!parameters)
+            parameters = g_hash_table_new(nm_str_hash, g_str_equal);
+        g_hash_table_insert(parameters, (char *) p_key, (char *) p_val);
+    }
+    va_end(ap);
     nm_connection_normalize(connection, parameters, NULL, NULL);
-    g_hash_table_destroy(parameters);
 }
 
 /*****************************************************************************/
@@ -1051,6 +1061,12 @@ nm_shutdown_wait_obj_register_full(gpointer           watched_obj,
     if (G_UNLIKELY(!_shutdown_waitobj_lst_head.next))
         c_list_init(&_shutdown_waitobj_lst_head);
 
+    /* Beware: there are callers with g_main_context_get_thread_default()
+     * not being g_main_context_get_default(). For example _fw_nft_call().
+     *
+     * If you schedule any sources or async operations, you probably need to
+     * make sure to use the default context. */
+
     handle  = g_slice_new(NMShutdownWaitObjHandle);
     *handle = (NMShutdownWaitObjHandle){
         /* depending on @free_msg_reason, we take ownership of @msg_reason.
@@ -1693,5 +1709,11 @@ nm_platform_get()
 void
 nm_linux_platform_setup(void)
 {
-    nm_platform_setup(nm_linux_platform_new(FALSE, FALSE));
+    nm_platform_setup(nm_linux_platform_new(FALSE, FALSE, FALSE));
+}
+
+void
+nm_linux_platform_setup_with_tc_cache(void)
+{
+    nm_platform_setup(nm_linux_platform_new(FALSE, FALSE, TRUE));
 }