config,dns: support Reload flags to specify that only parts should be reloaded
Support 3 new flags for Reload: - 0x01 (CONF): reload the configuration from disk - 0x02 (DNS_RC): write DNS configuration to resolv.conf - 0x04 (DNS_FULL): restart DNS plugin Omitting all flags is the same as reloading everything, thus SIGHUP.
This commit is contained in:
@@ -5,8 +5,27 @@
|
||||
|
||||
<!--
|
||||
Reload:
|
||||
@flags: optional flags to specify which parts shall be reloaded. A default of zero
|
||||
means to reload everything.
|
||||
@flags: optional flags to specify which parts shall be reloaded.
|
||||
|
||||
Reload NetworkManager's configuration and perform certain updates, like flushing a cache or
|
||||
rewriting external state to disk. This is similar to sending SIGHUP to NetworkManager but it
|
||||
allows for more fine-grained control over what to reload (see @flags). It also allows
|
||||
non-root access via PolicyKit and contrary to signals it is synchronous.
|
||||
|
||||
No flags (0x00) means to reload everything that is supported which is identical to
|
||||
sending a SIGHUP.
|
||||
(0x01) means to reload the NetworkManager.conf configuration from disk. Note that this
|
||||
does not include connections, which can be reloaded via Setting's ReloadConnections.
|
||||
(0x02) means to update DNS configuration, which usually involves writing /etc/resolv.conf
|
||||
anew.
|
||||
(0x04) means to restart the DNS plugin. This is for example useful when using
|
||||
dnsmasq plugin, which uses additional configuration in /etc/NetworkManager/dnsmasq.d.
|
||||
If you edit those files, you can restart the DNS plugin. This action shortly interrupts
|
||||
rename resolution.
|
||||
Note that flags may affect each other. For example, restarting the DNS plugin (0x04)
|
||||
implicitly updates DNS too (0x02). Or when reloading the configuration (0x01), changes
|
||||
to DNS setting also cause a DNS update (0x02). However, (0x01) does not involve restarting
|
||||
the DNS plugin (0x02), unless an entirely different plugin is selected.
|
||||
-->
|
||||
<method name="Reload">
|
||||
<arg name="flags" type="u" direction="in"/>
|
||||
|
@@ -78,6 +78,10 @@
|
||||
This file is not intended to be modified by the user, but it is read last and can shadow
|
||||
user configuration from <literal>NetworkManager.conf</literal>.
|
||||
</para>
|
||||
<para>
|
||||
Certain settings from the configuration can be reloaded at runtime either by sending SIGHUP signal or via
|
||||
D-Bus' Reload call.
|
||||
</para>
|
||||
|
||||
</refsect1>
|
||||
|
||||
|
@@ -462,6 +462,11 @@
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</para>
|
||||
<para>
|
||||
An alternative to a signal to reload configuration is the Reload D-Bus call.
|
||||
It allows for more fine-grained selection of what to reload, it only returns
|
||||
after the reload is complete, and it is guarded by PolicyKit.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
|
@@ -1610,17 +1610,21 @@ config_changed_cb (NMConfig *config,
|
||||
|
||||
if (NM_FLAGS_ANY (changes, NM_CONFIG_CHANGE_DNS_MODE |
|
||||
NM_CONFIG_CHANGE_RC_MANAGER |
|
||||
NM_CONFIG_CHANGE_CAUSE_SIGHUP)) {
|
||||
NM_CONFIG_CHANGE_CAUSE_SIGHUP |
|
||||
NM_CONFIG_CHANGE_CAUSE_DNS_FULL)) {
|
||||
/* reload the resolv-conf mode also on SIGHUP (when DNS_MODE didn't change).
|
||||
* The reason is, that the configuration also depends on whether resolv.conf
|
||||
* is immutable, thus, without the configuration changing, we always want to
|
||||
* re-configure the mode. */
|
||||
init_resolv_conf_mode (self,
|
||||
NM_FLAGS_HAS (changes, NM_CONFIG_CHANGE_CAUSE_SIGHUP));
|
||||
NM_FLAGS_ANY (changes, NM_CONFIG_CHANGE_CAUSE_SIGHUP
|
||||
| NM_CONFIG_CHANGE_CAUSE_DNS_FULL));
|
||||
}
|
||||
|
||||
if (NM_FLAGS_ANY (changes, NM_CONFIG_CHANGE_CAUSE_SIGHUP |
|
||||
NM_CONFIG_CHANGE_CAUSE_SIGUSR1 |
|
||||
NM_CONFIG_CHANGE_CAUSE_DNS_RC |
|
||||
NM_CONFIG_CHANGE_CAUSE_DNS_FULL |
|
||||
NM_CONFIG_CHANGE_DNS_MODE |
|
||||
NM_CONFIG_CHANGE_RC_MANAGER |
|
||||
NM_CONFIG_CHANGE_GLOBAL_DNS_CONFIG)) {
|
||||
|
@@ -44,6 +44,25 @@ G_BEGIN_DECLS
|
||||
#define NM_CONFIG_DATA_NO_AUTO_DEFAULT "no-auto-default"
|
||||
#define NM_CONFIG_DATA_DNS_MODE "dns"
|
||||
|
||||
/* The flags for Reload. Currently these are internal defines,
|
||||
* only their numeric value matters and must be stable as
|
||||
* they are public API! Also, the enum must fit in uint32. */
|
||||
enum { /*< skip >*/
|
||||
NM_MANAGER_RELOAD_FLAGS_NONE = 0,
|
||||
|
||||
/* reload the configuration from disk */
|
||||
NM_MANAGER_RELOAD_FLAGS_CONF = (1LL << 0),
|
||||
|
||||
/* write DNS configuration to resolv.conf */
|
||||
NM_MANAGER_RELOAD_FLAGS_DNS_RC = (1LL << 1),
|
||||
|
||||
/* restart the DNS plugin (includes DNS_RC) */
|
||||
NM_MANAGER_RELOAD_FLAGS_DNS_FULL = (1LL << 2),
|
||||
|
||||
_NM_MANAGER_RELOAD_FLAGS_ALL,
|
||||
NM_MANAGER_RELOAD_FLAGS_ALL = ((_NM_MANAGER_RELOAD_FLAGS_ALL - 1) << 1) - 1,
|
||||
};
|
||||
|
||||
typedef enum { /*< flags >*/
|
||||
NM_CONFIG_GET_VALUE_NONE = 0,
|
||||
|
||||
@@ -73,8 +92,11 @@ typedef enum { /*< flags >*/
|
||||
NM_CONFIG_CHANGE_CAUSE_SIGUSR2 = (1L << 2),
|
||||
NM_CONFIG_CHANGE_CAUSE_NO_AUTO_DEFAULT = (1L << 3),
|
||||
NM_CONFIG_CHANGE_CAUSE_SET_VALUES = (1L << 4),
|
||||
NM_CONFIG_CHANGE_CAUSE_CONF = (1L << 5),
|
||||
NM_CONFIG_CHANGE_CAUSE_DNS_RC = (1L << 6),
|
||||
NM_CONFIG_CHANGE_CAUSE_DNS_FULL = (1L << 7),
|
||||
|
||||
NM_CONFIG_CHANGE_CAUSES = ((1L << 5) - 1),
|
||||
NM_CONFIG_CHANGE_CAUSES = ((1L << 8) - 1),
|
||||
|
||||
/**************************************************************************
|
||||
* Following flags describe which property of the configuration changed:
|
||||
|
@@ -1884,7 +1884,7 @@ nm_config_reload (NMConfig *self, NMConfigChangeFlags reload_flags)
|
||||
|
||||
priv = NM_CONFIG_GET_PRIVATE (self);
|
||||
|
||||
if (reload_flags != NM_CONFIG_CHANGE_CAUSE_SIGHUP) {
|
||||
if (!NM_FLAGS_ANY (reload_flags, NM_CONFIG_CHANGE_CAUSE_SIGHUP | NM_CONFIG_CHANGE_CAUSE_CONF)) {
|
||||
/* unless SIGHUP is specified, we don't reload the configuration from disc. */
|
||||
_set_config_data (self, NULL, reload_flags);
|
||||
return;
|
||||
@@ -1930,6 +1930,9 @@ nm_config_reload (NMConfig *self, NMConfigChangeFlags reload_flags)
|
||||
|
||||
NM_UTILS_FLAGS2STR_DEFINE (nm_config_change_flags_to_string, NMConfigChangeFlags,
|
||||
|
||||
NM_UTILS_FLAGS2STR (NM_CONFIG_CHANGE_CAUSE_CONF, "CONF"),
|
||||
NM_UTILS_FLAGS2STR (NM_CONFIG_CHANGE_CAUSE_DNS_RC, "DNS_RC"),
|
||||
NM_UTILS_FLAGS2STR (NM_CONFIG_CHANGE_CAUSE_DNS_FULL, "DNS_FULL"),
|
||||
NM_UTILS_FLAGS2STR (NM_CONFIG_CHANGE_CAUSE_SIGHUP, "SIGHUP"),
|
||||
NM_UTILS_FLAGS2STR (NM_CONFIG_CHANGE_CAUSE_SIGUSR1, "SIGUSR1"),
|
||||
NM_UTILS_FLAGS2STR (NM_CONFIG_CHANGE_CAUSE_SIGUSR2, "SIGUSR2"),
|
||||
@@ -1970,7 +1973,10 @@ _set_config_data (NMConfig *self, NMConfigData *new_data, NMConfigChangeFlags re
|
||||
changes |= changes_diff;
|
||||
}
|
||||
|
||||
if ( NM_IN_SET (reload_flags, NM_CONFIG_CHANGE_CAUSE_NO_AUTO_DEFAULT, NM_CONFIG_CHANGE_CAUSE_SET_VALUES)
|
||||
if ( NM_IN_SET (reload_flags,
|
||||
NM_CONFIG_CHANGE_CAUSE_NO_AUTO_DEFAULT,
|
||||
NM_CONFIG_CHANGE_CAUSE_SET_VALUES,
|
||||
NM_CONFIG_CHANGE_CAUSE_CONF)
|
||||
&& !new_data) {
|
||||
/* no relevant changes that should be propagated. Return silently. */
|
||||
return;
|
||||
|
@@ -477,6 +477,7 @@ _reload_auth_cb (NMAuthChain *chain,
|
||||
guint32 flags;
|
||||
NMAuthSubject *subject;
|
||||
char s_buf[60];
|
||||
NMConfigChangeFlags reload_type = NM_CONFIG_CHANGE_NONE;
|
||||
|
||||
g_assert (context);
|
||||
|
||||
@@ -496,11 +497,26 @@ _reload_auth_cb (NMAuthChain *chain,
|
||||
ret_error = g_error_new_literal (NM_MANAGER_ERROR,
|
||||
NM_MANAGER_ERROR_PERMISSION_DENIED,
|
||||
"Not authorized to reload configuration");
|
||||
} else if (flags != 0) {
|
||||
} else {
|
||||
if (NM_FLAGS_ANY (flags, ~NM_MANAGER_RELOAD_FLAGS_ALL)) {
|
||||
/* invalid flags */
|
||||
} else if (flags == 0)
|
||||
reload_type = NM_CONFIG_CHANGE_CAUSE_SIGHUP;
|
||||
else {
|
||||
if (NM_FLAGS_HAS (flags, NM_MANAGER_RELOAD_FLAGS_CONF))
|
||||
reload_type |= NM_CONFIG_CHANGE_CAUSE_CONF;
|
||||
if (NM_FLAGS_HAS (flags, NM_MANAGER_RELOAD_FLAGS_DNS_RC))
|
||||
reload_type |= NM_CONFIG_CHANGE_CAUSE_DNS_RC;
|
||||
if (NM_FLAGS_HAS (flags, NM_MANAGER_RELOAD_FLAGS_DNS_FULL))
|
||||
reload_type |= NM_CONFIG_CHANGE_CAUSE_DNS_FULL;
|
||||
}
|
||||
|
||||
if (reload_type == NM_CONFIG_CHANGE_NONE) {
|
||||
ret_error = g_error_new_literal (NM_MANAGER_ERROR,
|
||||
NM_MANAGER_ERROR_INVALID_ARGUMENTS,
|
||||
"Invalid flags for reload");
|
||||
}
|
||||
}
|
||||
|
||||
nm_audit_log_control_op (NM_AUDIT_OP_RELOAD,
|
||||
nm_sprintf_buf (s_buf, "%u", flags),
|
||||
@@ -512,8 +528,7 @@ _reload_auth_cb (NMAuthChain *chain,
|
||||
goto out;
|
||||
}
|
||||
|
||||
nm_config_reload (priv->config, NM_CONFIG_CHANGE_CAUSE_SIGHUP);
|
||||
|
||||
nm_config_reload (priv->config, reload_type);
|
||||
g_dbus_method_invocation_return_value (context, NULL);
|
||||
|
||||
out:
|
||||
|
Reference in New Issue
Block a user