mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-08 10:08:05 +02:00
policy: add support to configurable hostname mode
This commit is contained in:
parent
e22af1aa9e
commit
2eba42b4ab
3 changed files with 38 additions and 0 deletions
|
|
@ -62,6 +62,7 @@
|
||||||
#define NM_CONFIG_KEYFILE_KEY_MAIN_AUTH_POLKIT "auth-polkit"
|
#define NM_CONFIG_KEYFILE_KEY_MAIN_AUTH_POLKIT "auth-polkit"
|
||||||
#define NM_CONFIG_KEYFILE_KEY_MAIN_DHCP "dhcp"
|
#define NM_CONFIG_KEYFILE_KEY_MAIN_DHCP "dhcp"
|
||||||
#define NM_CONFIG_KEYFILE_KEY_MAIN_DEBUG "debug"
|
#define NM_CONFIG_KEYFILE_KEY_MAIN_DEBUG "debug"
|
||||||
|
#define NM_CONFIG_KEYFILE_KEY_MAIN_HOSTNAME_MODE "hostname-mode"
|
||||||
#define NM_CONFIG_KEYFILE_KEY_LOGGING_BACKEND "backend"
|
#define NM_CONFIG_KEYFILE_KEY_LOGGING_BACKEND "backend"
|
||||||
#define NM_CONFIG_KEYFILE_KEY_CONFIG_ENABLE "enable"
|
#define NM_CONFIG_KEYFILE_KEY_CONFIG_ENABLE "enable"
|
||||||
#define NM_CONFIG_KEYFILE_KEY_ATOMIC_SECTION_WAS ".was"
|
#define NM_CONFIG_KEYFILE_KEY_ATOMIC_SECTION_WAS ".was"
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@
|
||||||
#include "settings/nm-settings-connection.h"
|
#include "settings/nm-settings-connection.h"
|
||||||
#include "nm-dhcp4-config.h"
|
#include "nm-dhcp4-config.h"
|
||||||
#include "nm-dhcp6-config.h"
|
#include "nm-dhcp6-config.h"
|
||||||
|
#include "nm-config.h"
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
@ -85,6 +86,7 @@ typedef struct {
|
||||||
|
|
||||||
guint schedule_activate_all_id; /* idle handler for schedule_activate_all(). */
|
guint schedule_activate_all_id; /* idle handler for schedule_activate_all(). */
|
||||||
|
|
||||||
|
NMPolicyHostnameMode hostname_mode;
|
||||||
char *orig_hostname; /* hostname at NM start time */
|
char *orig_hostname; /* hostname at NM start time */
|
||||||
char *cur_hostname; /* hostname we want to assign */
|
char *cur_hostname; /* hostname we want to assign */
|
||||||
char *last_hostname; /* last hostname NM set (to detect if someone else changed it in the meanwhile) */
|
char *last_hostname; /* last hostname NM set (to detect if someone else changed it in the meanwhile) */
|
||||||
|
|
@ -591,6 +593,9 @@ update_system_hostname (NMPolicy *self, NMDevice *best4, NMDevice *best6)
|
||||||
|
|
||||||
g_return_if_fail (self != NULL);
|
g_return_if_fail (self != NULL);
|
||||||
|
|
||||||
|
if (priv->hostname_mode == NM_POLICY_HOSTNAME_MODE_NONE)
|
||||||
|
return;
|
||||||
|
|
||||||
nm_clear_g_cancellable (&priv->lookup_cancellable);
|
nm_clear_g_cancellable (&priv->lookup_cancellable);
|
||||||
|
|
||||||
/* Check if the hostname was set externally to NM, so that in that case
|
/* Check if the hostname was set externally to NM, so that in that case
|
||||||
|
|
@ -683,6 +688,9 @@ update_system_hostname (NMPolicy *self, NMDevice *best4, NMDevice *best6)
|
||||||
if (external_hostname)
|
if (external_hostname)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (priv->hostname_mode == NM_POLICY_HOSTNAME_MODE_DHCP)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!best4 && !best6) {
|
if (!best4 && !best6) {
|
||||||
/* No best device; fall back to the last hostname set externally
|
/* No best device; fall back to the last hostname set externally
|
||||||
* to NM or if there wasn't one, 'localhost.localdomain'
|
* to NM or if there wasn't one, 'localhost.localdomain'
|
||||||
|
|
@ -2257,6 +2265,18 @@ static void
|
||||||
nm_policy_init (NMPolicy *self)
|
nm_policy_init (NMPolicy *self)
|
||||||
{
|
{
|
||||||
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
|
||||||
|
const char *hostname_mode;
|
||||||
|
|
||||||
|
hostname_mode = nm_config_data_get_value (NM_CONFIG_GET_DATA_ORIG,
|
||||||
|
NM_CONFIG_KEYFILE_GROUP_MAIN,
|
||||||
|
NM_CONFIG_KEYFILE_KEY_MAIN_HOSTNAME_MODE,
|
||||||
|
NM_CONFIG_GET_VALUE_STRIP | NM_CONFIG_GET_VALUE_NO_EMPTY);
|
||||||
|
if (nm_streq0 (hostname_mode, "none"))
|
||||||
|
priv->hostname_mode = NM_POLICY_HOSTNAME_MODE_NONE;
|
||||||
|
else if (nm_streq0 (hostname_mode, "dhcp"))
|
||||||
|
priv->hostname_mode = NM_POLICY_HOSTNAME_MODE_DHCP;
|
||||||
|
else /* default - full mode */
|
||||||
|
priv->hostname_mode = NM_POLICY_HOSTNAME_MODE_FULL;
|
||||||
|
|
||||||
priv->devices = g_hash_table_new (NULL, NULL);
|
priv->devices = g_hash_table_new (NULL, NULL);
|
||||||
priv->ip6_prefix_delegations = g_array_new (FALSE, FALSE, sizeof (IP6PrefixDelegation));
|
priv->ip6_prefix_delegations = g_array_new (FALSE, FALSE, sizeof (IP6PrefixDelegation));
|
||||||
|
|
|
||||||
|
|
@ -47,4 +47,21 @@ NMDevice *nm_policy_get_default_ip6_device (NMPolicy *policy);
|
||||||
NMDevice *nm_policy_get_activating_ip4_device (NMPolicy *policy);
|
NMDevice *nm_policy_get_activating_ip4_device (NMPolicy *policy);
|
||||||
NMDevice *nm_policy_get_activating_ip6_device (NMPolicy *policy);
|
NMDevice *nm_policy_get_activating_ip6_device (NMPolicy *policy);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NMPolicyHostnameMode
|
||||||
|
* @NM_POLICY_HOSTNAME_MODE_NONE: never update the transient hostname.
|
||||||
|
* @NM_POLICY_HOSTNAME_MODE_DHCP: only hostname from DHCP hostname
|
||||||
|
* options are eligible to be set as transient hostname.
|
||||||
|
* @NM_POLICY_HOSTNAME_MODE_FULL: NM will try to update the hostname looking
|
||||||
|
* to current static hostname, DHCP options, reverse IP lookup and externally
|
||||||
|
* set hostnames.
|
||||||
|
*
|
||||||
|
* NMPolicy's hostname update policy
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
NM_POLICY_HOSTNAME_MODE_NONE,
|
||||||
|
NM_POLICY_HOSTNAME_MODE_DHCP,
|
||||||
|
NM_POLICY_HOSTNAME_MODE_FULL,
|
||||||
|
} NMPolicyHostnameMode;
|
||||||
|
|
||||||
#endif /* __NETWORKMANAGER_POLICY_H__ */
|
#endif /* __NETWORKMANAGER_POLICY_H__ */
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue