From cd1c9108cc51ab550b616beff06e6f07f34eb467 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Wed, 4 Jul 2018 17:29:33 +0200 Subject: [PATCH] devices: make sure the generated connections are normalized Using these unormalized was wrong all along, but by chance didn't hit paths that needed normalized connections. This may change if we actually write in memory connections to /run with the keyfile plugin, because that one wants them normalized. This also saves some work, because normalization does boring things for us, such as adding default ipv4/ipv6/proxy settings everywhere. (cherry picked from commit 89d1c9fb302e84b92d0be415f0bb4bdca34ae74c) --- src/devices/bluetooth/nm-bluez-device.c | 21 ++++++--------------- src/devices/nm-device.c | 22 ++++++++++++++++++---- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/devices/bluetooth/nm-bluez-device.c b/src/devices/bluetooth/nm-bluez-device.c index b69b432039..b722f692ce 100644 --- a/src/devices/bluetooth/nm-bluez-device.c +++ b/src/devices/bluetooth/nm-bluez-device.c @@ -227,21 +227,12 @@ pan_connection_check_create (NMBluezDevice *self) NULL); nm_connection_add_setting (connection, setting); - /* Setting: IPv4 */ - setting = nm_setting_ip4_config_new (); - g_object_set (G_OBJECT (setting), - NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, - NM_SETTING_IP_CONFIG_MAY_FAIL, FALSE, - NULL); - nm_connection_add_setting (connection, setting); - - /* Setting: IPv6 */ - setting = nm_setting_ip6_config_new (); - g_object_set (G_OBJECT (setting), - NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, - NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, - NULL); - nm_connection_add_setting (connection, setting); + if (!nm_connection_normalize (connection, NULL, NULL, &error)) { + nm_log_err (LOGD_BT, "bluez[%s] couldn't generate a connection for NAP device: %s", + priv->path, error->message); + g_error_free (error); + g_return_if_reached (); + } /* Adding a new connection raises a signal which eventually calls check_emit_usable (again) * which then already finds the suitable connection in priv->connections. This is confusing, diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 31d6dcea2f..26ea06bda9 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -4599,9 +4599,23 @@ nm_device_owns_iface (NMDevice *self, const char *iface) NMConnection * nm_device_new_default_connection (NMDevice *self) { - if (NM_DEVICE_GET_CLASS (self)->new_default_connection) - return NM_DEVICE_GET_CLASS (self)->new_default_connection (self); - return NULL; + NMConnection *connection; + GError *error = NULL; + + if (!NM_DEVICE_GET_CLASS (self)->new_default_connection) + return NULL; + + connection = NM_DEVICE_GET_CLASS (self)->new_default_connection (self); + if (!connection) + return NULL; + + if (!nm_connection_normalize (connection, NULL, NULL, &error)) { + _LOGD (LOGD_DEVICE, "device generated an invalid default connection: %s", error->message); + g_error_free (error); + g_return_val_if_reached (NULL); + } + + return connection; } static void @@ -5472,7 +5486,7 @@ nm_device_generate_connection (NMDevice *self, klass->update_connection (self, connection); - if (!nm_connection_verify (connection, &local)) { + if (!nm_connection_normalize (connection, NULL, NULL, error)) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, "generated connection does not verify: %s", local->message);