mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-10-15 12:34:55 +00:00
merge: branch 'dns_checkpoint'
Allow rollback on internal global DNS https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1875
This commit is contained in:
commit
f805114a91
|
@ -13,6 +13,7 @@
|
||||||
#include "nm-core-utils.h"
|
#include "nm-core-utils.h"
|
||||||
#include "nm-dbus-interface.h"
|
#include "nm-dbus-interface.h"
|
||||||
#include "devices/nm-device.h"
|
#include "devices/nm-device.h"
|
||||||
|
#include "nm-config.h"
|
||||||
#include "nm-manager.h"
|
#include "nm-manager.h"
|
||||||
#include "settings/nm-settings.h"
|
#include "settings/nm-settings.h"
|
||||||
#include "settings/nm-settings-connection.h"
|
#include "settings/nm-settings-connection.h"
|
||||||
|
@ -55,6 +56,8 @@ struct _NMCheckpointPrivate {
|
||||||
|
|
||||||
NMCheckpointTimeoutCallback timeout_cb;
|
NMCheckpointTimeoutCallback timeout_cb;
|
||||||
gpointer timeout_data;
|
gpointer timeout_data;
|
||||||
|
|
||||||
|
NMGlobalDnsConfig *global_dns_config;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _NMCheckpointClass {
|
struct _NMCheckpointClass {
|
||||||
|
@ -491,6 +494,17 @@ next_dev:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (NM_FLAGS_HAS(priv->flags, NM_CHECKPOINT_CREATE_FLAG_TRACK_INTERNAL_GLOBAL_DNS)
|
||||||
|
&& priv->global_dns_config) {
|
||||||
|
gs_free_error GError *error = NULL;
|
||||||
|
NMConfig *config;
|
||||||
|
|
||||||
|
config = nm_manager_get_config(priv->manager);
|
||||||
|
nm_assert(config);
|
||||||
|
if (!nm_config_set_global_dns(config, priv->global_dns_config, &error)) {
|
||||||
|
_LOGE("set global DNS failed with error: %s", error->message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return g_variant_new("(a{su})", &builder);
|
return g_variant_new("(a{su})", &builder);
|
||||||
}
|
}
|
||||||
|
@ -742,6 +756,19 @@ nm_checkpoint_new(NMManager *manager,
|
||||||
NM_MANAGER_DEVICE_REMOVED,
|
NM_MANAGER_DEVICE_REMOVED,
|
||||||
G_CALLBACK(_device_removed),
|
G_CALLBACK(_device_removed),
|
||||||
self);
|
self);
|
||||||
|
if (NM_FLAGS_HAS(flags, NM_CHECKPOINT_CREATE_FLAG_TRACK_INTERNAL_GLOBAL_DNS)) {
|
||||||
|
NMConfigData *config_data;
|
||||||
|
NMGlobalDnsConfig *dns_config = NULL;
|
||||||
|
|
||||||
|
config_data = nm_config_get_data(nm_manager_get_config(manager));
|
||||||
|
if (config_data) {
|
||||||
|
dns_config = nm_config_data_get_global_dns_config(config_data);
|
||||||
|
if (!dns_config || nm_global_dns_config_is_internal(dns_config)) {
|
||||||
|
priv->global_dns_config = nm_global_dns_config_clone(dns_config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -756,6 +783,7 @@ dispose(GObject *object)
|
||||||
nm_clear_pointer(&priv->devices, g_hash_table_unref);
|
nm_clear_pointer(&priv->devices, g_hash_table_unref);
|
||||||
nm_clear_pointer(&priv->connection_uuids, g_hash_table_unref);
|
nm_clear_pointer(&priv->connection_uuids, g_hash_table_unref);
|
||||||
nm_clear_pointer(&priv->removed_devices, g_ptr_array_unref);
|
nm_clear_pointer(&priv->removed_devices, g_ptr_array_unref);
|
||||||
|
nm_global_dns_config_free(priv->global_dns_config);
|
||||||
|
|
||||||
nm_clear_g_signal_handler(priv->manager, &priv->dev_removed_id);
|
nm_clear_g_signal_handler(priv->manager, &priv->dev_removed_id);
|
||||||
g_clear_object(&priv->manager);
|
g_clear_object(&priv->manager);
|
||||||
|
|
|
@ -2436,3 +2436,50 @@ nm_config_data_class_init(NMConfigDataClass *config_class)
|
||||||
|
|
||||||
g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties);
|
g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static NMGlobalDnsDomain *
|
||||||
|
nm_global_dns_domain_clone(NMGlobalDnsDomain *old_domain)
|
||||||
|
{
|
||||||
|
if (old_domain) {
|
||||||
|
NMGlobalDnsDomain *new_domain = g_malloc0(sizeof(NMGlobalDnsDomain));
|
||||||
|
new_domain->name = g_strdup(old_domain->name);
|
||||||
|
new_domain->servers = (char **) nm_strv_dup(old_domain->servers, -1, TRUE);
|
||||||
|
new_domain->options = (char **) nm_strv_dup(old_domain->options, -1, TRUE);
|
||||||
|
return new_domain;
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NMGlobalDnsConfig *
|
||||||
|
nm_global_dns_config_clone(NMGlobalDnsConfig *old_dns_config)
|
||||||
|
{
|
||||||
|
NMGlobalDnsConfig *new_dns_config;
|
||||||
|
gpointer key, value;
|
||||||
|
NMGlobalDnsDomain *old_domain;
|
||||||
|
GHashTableIter iter;
|
||||||
|
|
||||||
|
new_dns_config = g_malloc0(sizeof(NMGlobalDnsConfig));
|
||||||
|
new_dns_config->internal = TRUE;
|
||||||
|
|
||||||
|
if (old_dns_config) {
|
||||||
|
new_dns_config->internal = old_dns_config->internal;
|
||||||
|
new_dns_config->searches = nm_strv_dup(old_dns_config->searches, -1, TRUE);
|
||||||
|
new_dns_config->options = nm_strv_dup(old_dns_config->options, -1, TRUE);
|
||||||
|
new_dns_config->domains = g_hash_table_new_full(nm_str_hash,
|
||||||
|
g_str_equal,
|
||||||
|
g_free,
|
||||||
|
(GDestroyNotify) global_dns_domain_free);
|
||||||
|
if (old_dns_config->domains) {
|
||||||
|
g_hash_table_iter_init(&iter, old_dns_config->domains);
|
||||||
|
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||||
|
old_domain = value;
|
||||||
|
g_hash_table_insert(new_dns_config->domains,
|
||||||
|
g_strdup(key),
|
||||||
|
nm_global_dns_domain_clone(old_domain));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
global_dns_config_seal_domains(new_dns_config);
|
||||||
|
}
|
||||||
|
return new_dns_config;
|
||||||
|
}
|
||||||
|
|
|
@ -280,7 +280,8 @@ int nm_global_dns_config_cmp(const NMGlobalDnsConfig *a,
|
||||||
const NMGlobalDnsConfig *b,
|
const NMGlobalDnsConfig *b,
|
||||||
gboolean check_internal);
|
gboolean check_internal);
|
||||||
void nm_global_dns_config_update_checksum(const NMGlobalDnsConfig *dns_config, GChecksum *sum);
|
void nm_global_dns_config_update_checksum(const NMGlobalDnsConfig *dns_config, GChecksum *sum);
|
||||||
void nm_global_dns_config_free(NMGlobalDnsConfig *dns_config);
|
NMGlobalDnsConfig *nm_global_dns_config_clone(NMGlobalDnsConfig *dns_config);
|
||||||
|
void nm_global_dns_config_free(NMGlobalDnsConfig *dns_config);
|
||||||
|
|
||||||
NMGlobalDnsConfig *nm_global_dns_config_from_dbus(const GValue *value, GError **error);
|
NMGlobalDnsConfig *nm_global_dns_config_from_dbus(const GValue *value, GError **error);
|
||||||
void nm_global_dns_config_to_dbus(const NMGlobalDnsConfig *dns_config, GValue *value);
|
void nm_global_dns_config_to_dbus(const NMGlobalDnsConfig *dns_config, GValue *value);
|
||||||
|
|
|
@ -8503,7 +8503,8 @@ impl_manager_checkpoint_create(NMDBusObject *obj,
|
||||||
| NM_CHECKPOINT_CREATE_FLAG_DELETE_NEW_CONNECTIONS
|
| NM_CHECKPOINT_CREATE_FLAG_DELETE_NEW_CONNECTIONS
|
||||||
| NM_CHECKPOINT_CREATE_FLAG_DISCONNECT_NEW_DEVICES
|
| NM_CHECKPOINT_CREATE_FLAG_DISCONNECT_NEW_DEVICES
|
||||||
| NM_CHECKPOINT_CREATE_FLAG_ALLOW_OVERLAPPING
|
| NM_CHECKPOINT_CREATE_FLAG_ALLOW_OVERLAPPING
|
||||||
| NM_CHECKPOINT_CREATE_FLAG_NO_PRESERVE_EXTERNAL_PORTS)))) {
|
| NM_CHECKPOINT_CREATE_FLAG_NO_PRESERVE_EXTERNAL_PORTS
|
||||||
|
| NM_CHECKPOINT_CREATE_FLAG_TRACK_INTERNAL_GLOBAL_DNS)))) {
|
||||||
g_dbus_method_invocation_return_error_literal(invocation,
|
g_dbus_method_invocation_return_error_literal(invocation,
|
||||||
NM_MANAGER_ERROR,
|
NM_MANAGER_ERROR,
|
||||||
NM_MANAGER_ERROR_INVALID_ARGUMENTS,
|
NM_MANAGER_ERROR_INVALID_ARGUMENTS,
|
||||||
|
@ -9811,3 +9812,11 @@ nm_manager_class_init(NMManagerClass *manager_class)
|
||||||
1,
|
1,
|
||||||
NM_TYPE_DEVICE);
|
NM_TYPE_DEVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NMConfig *
|
||||||
|
nm_manager_get_config(NMManager *self)
|
||||||
|
{
|
||||||
|
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self);
|
||||||
|
|
||||||
|
return priv->config;
|
||||||
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "settings/nm-settings-connection.h"
|
#include "settings/nm-settings-connection.h"
|
||||||
#include "c-list/src/c-list.h"
|
#include "c-list/src/c-list.h"
|
||||||
#include "nm-dbus-manager.h"
|
#include "nm-dbus-manager.h"
|
||||||
|
#include "nm-config-data.h"
|
||||||
|
|
||||||
#define NM_TYPE_MANAGER (nm_manager_get_type())
|
#define NM_TYPE_MANAGER (nm_manager_get_type())
|
||||||
#define NM_MANAGER(obj) (_NM_G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_MANAGER, NMManager))
|
#define NM_MANAGER(obj) (_NM_G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_MANAGER, NMManager))
|
||||||
|
@ -266,4 +267,6 @@ gboolean nm_manager_devcon_autoconnect_blocked_reason_set(NMManager *
|
||||||
NMSettingsAutoconnectBlockedReason value,
|
NMSettingsAutoconnectBlockedReason value,
|
||||||
gboolean set);
|
gboolean set);
|
||||||
|
|
||||||
|
NMConfig *nm_manager_get_config(NMManager *self);
|
||||||
|
|
||||||
#endif /* __NETWORKMANAGER_MANAGER_H__ */
|
#endif /* __NETWORKMANAGER_MANAGER_H__ */
|
||||||
|
|
|
@ -991,6 +991,11 @@ typedef enum {
|
||||||
* With this flag, the rollback detaches all external ports.
|
* With this flag, the rollback detaches all external ports.
|
||||||
* This only has an effect for bridge ports. Before 1.38, this was the default
|
* This only has an effect for bridge ports. Before 1.38, this was the default
|
||||||
* behavior. Since: 1.38.
|
* behavior. Since: 1.38.
|
||||||
|
* @NM_CHECKPOINT_CREATE_FLAG_TRACK_INTERNAL_GLOBAL_DNS: during rollback,
|
||||||
|
* by default changes to global DNS via D-BUS interface are preserved.
|
||||||
|
* With this flag, the rollback reverts the global DNS changes made via D-Bus
|
||||||
|
* interface. Global DNS defined in [global-dns] section of
|
||||||
|
* NetworkManager.conf is not impacted by this flag. Since: 1.48.
|
||||||
*
|
*
|
||||||
* The flags for CheckpointCreate call
|
* The flags for CheckpointCreate call
|
||||||
*
|
*
|
||||||
|
@ -1003,6 +1008,7 @@ typedef enum /*< flags >*/ {
|
||||||
NM_CHECKPOINT_CREATE_FLAG_DISCONNECT_NEW_DEVICES = 0x04,
|
NM_CHECKPOINT_CREATE_FLAG_DISCONNECT_NEW_DEVICES = 0x04,
|
||||||
NM_CHECKPOINT_CREATE_FLAG_ALLOW_OVERLAPPING = 0x08,
|
NM_CHECKPOINT_CREATE_FLAG_ALLOW_OVERLAPPING = 0x08,
|
||||||
NM_CHECKPOINT_CREATE_FLAG_NO_PRESERVE_EXTERNAL_PORTS = 0x10,
|
NM_CHECKPOINT_CREATE_FLAG_NO_PRESERVE_EXTERNAL_PORTS = 0x10,
|
||||||
|
NM_CHECKPOINT_CREATE_FLAG_TRACK_INTERNAL_GLOBAL_DNS = 0x20,
|
||||||
} NMCheckpointCreateFlags;
|
} NMCheckpointCreateFlags;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue