all: add hostname setting

Add a new setting that contains properties related to how NM should
get the hostname from the connection.
This commit is contained in:
Beniamino Galvani 2020-10-31 10:50:56 +01:00
parent adf63c8875
commit abd002642f
20 changed files with 549 additions and 15 deletions

View file

@ -943,6 +943,7 @@ libnm_core_lib_h_pub_real = \
libnm-core/nm-setting-ethtool.h \
libnm-core/nm-setting-generic.h \
libnm-core/nm-setting-gsm.h \
libnm-core/nm-setting-hostname.h \
libnm-core/nm-setting-infiniband.h \
libnm-core/nm-setting-ip-config.h \
libnm-core/nm-setting-ip-tunnel.h \
@ -1017,6 +1018,7 @@ libnm_core_lib_c_settings_real = \
libnm-core/nm-setting-ethtool.c \
libnm-core/nm-setting-generic.c \
libnm-core/nm-setting-gsm.c \
libnm-core/nm-setting-hostname.c \
libnm-core/nm-setting-infiniband.c \
libnm-core/nm-setting-ip-config.c \
libnm-core/nm-setting-ip-tunnel.c \

View file

@ -881,7 +881,8 @@ const NmcMetaGenericInfo
"," NM_SETTING_6LOWPAN_SETTING_NAME "," NM_SETTING_WIREGUARD_SETTING_NAME \
"," NM_SETTING_PROXY_SETTING_NAME "," NM_SETTING_TC_CONFIG_SETTING_NAME \
"," NM_SETTING_SRIOV_SETTING_NAME "," NM_SETTING_ETHTOOL_SETTING_NAME \
"," NM_SETTING_OVS_DPDK_SETTING_NAME /* NM_SETTING_DUMMY_SETTING_NAME NM_SETTING_WIMAX_SETTING_NAME */
"," NM_SETTING_OVS_DPDK_SETTING_NAME \
"," NM_SETTING_HOSTNAME_SETTING_NAME /* NM_SETTING_DUMMY_SETTING_NAME NM_SETTING_WIMAX_SETTING_NAME */
const NmcMetaGenericInfo *const nmc_fields_con_active_details_groups[] = {
NMC_META_GENERIC_WITH_NESTED("GENERAL", metagen_con_active_general), /* 0 */

View file

@ -564,6 +564,16 @@
<property name="mtu"
description="If non-zero, only transmit packets of the specified size or smaller, breaking larger packets up into multiple frames." />
</setting>
<setting name="hostname" >
<property name="priority"
description="The relative priority of this connection to determine the system hostname. A lower numerical value is better (higher priority). A connection with higher priority is considered before connections with lower priority. If the value is zero, it can be overridden by a global value from NetworkManager configuration. If the property doesn&apos;t have a value in the global configuration, the value is assumed to be 100. Negative values have the special effect of excluding other connections with a greater numerical priority value; so in presence of at least one negative priority, only connections with the lowest priority value will be used to determine the hostname." />
<property name="from-dhcp"
description="Whether the system hostname can be determined from DHCP on this connection. When set to NM_TERNARY_DEFAULT (-1), the value from global configuration is used. If the property doesn&apos;t have a value in the global configuration, NetworkManager assumes the value to be NM_TERNARY_TRUE (1)." />
<property name="from-dns-lookup"
description="Whether the system hostname can be determined from reverse DNS lookup of addresses on this device. When set to NM_TERNARY_DEFAULT (-1), the value from global configuration is used. If the property doesn&apos;t have a value in the global configuration, NetworkManager assumes the value to be NM_TERNARY_TRUE (1)." />
<property name="only-from-default"
description="If set to NM_TERNARY_TRUE (1), NetworkManager attempts to get the hostname via DHCPv4/DHCPv6 or reverse DNS lookup on this device only when the device has the default route for the given address family (IPv4/IPv6). If set to NM_TERNARY_FALSE (0), the hostname can be set from this device even if it doesn&apos;t have the default route. When set to NM_TERNARY_DEFAULT (-1), the value from global configuration is used. If the property doesn&apos;t have a value in the global configuration, NetworkManager assumes the value to be NM_TERNARY_TRUE (1)." />
</setting>
<setting name="infiniband" >
<property name="mac-address"
alias="mac"

View file

@ -5633,6 +5633,24 @@ static const NMMetaPropertyInfo *const property_infos_GSM[] = {
NULL
};
#undef _CURRENT_NM_META_SETTING_TYPE
#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_HOSTNAME
static const NMMetaPropertyInfo *const property_infos_HOSTNAME[] = {
PROPERTY_INFO (NM_SETTING_HOSTNAME_PRIORITY, DESCRIBE_DOC_NM_SETTING_HOSTNAME_PRIORITY,
.property_type = &_pt_gobject_int,
),
PROPERTY_INFO (NM_SETTING_HOSTNAME_FROM_DHCP, DESCRIBE_DOC_NM_SETTING_HOSTNAME_FROM_DHCP,
.property_type = &_pt_gobject_enum,
),
PROPERTY_INFO (NM_SETTING_HOSTNAME_FROM_DNS_LOOKUP, DESCRIBE_DOC_NM_SETTING_HOSTNAME_FROM_DNS_LOOKUP,
.property_type = &_pt_gobject_enum,
),
PROPERTY_INFO (NM_SETTING_HOSTNAME_ONLY_FROM_DEFAULT, DESCRIBE_DOC_NM_SETTING_HOSTNAME_ONLY_FROM_DEFAULT,
.property_type = &_pt_gobject_enum,
),
NULL
};
#undef _CURRENT_NM_META_SETTING_TYPE
#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_INFINIBAND
static const NMMetaPropertyInfo *const property_infos_INFINIBAND[] = {
@ -7936,6 +7954,7 @@ _setting_init_fcn_wireless (ARGS_SETTING_INIT_FCN)
#define SETTING_PRETTY_NAME_ETHTOOL N_("Ethtool settings")
#define SETTING_PRETTY_NAME_GENERIC N_("Generic settings")
#define SETTING_PRETTY_NAME_GSM N_("GSM mobile broadband connection")
#define SETTING_PRETTY_NAME_HOSTNAME N_("Hostname settings")
#define SETTING_PRETTY_NAME_INFINIBAND N_("InfiniBand connection")
#define SETTING_PRETTY_NAME_IP4_CONFIG N_("IPv4 protocol")
#define SETTING_PRETTY_NAME_IP6_CONFIG N_("IPv6 protocol")
@ -8073,6 +8092,7 @@ const NMMetaSettingInfoEditor nm_meta_setting_infos_editor[] = {
),
.setting_init_fcn = _setting_init_fcn_gsm,
),
SETTING_INFO (HOSTNAME),
SETTING_INFO (INFINIBAND,
.valid_parts = NM_META_SETTING_VALID_PARTS (
NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE),
@ -8284,6 +8304,7 @@ static const NMMetaSettingValidPartItem *const valid_settings_noslave[] = {
NM_META_SETTING_VALID_PART_ITEM(MATCH, FALSE),
NM_META_SETTING_VALID_PART_ITEM(IP4_CONFIG, FALSE),
NM_META_SETTING_VALID_PART_ITEM(IP6_CONFIG, FALSE),
NM_META_SETTING_VALID_PART_ITEM(HOSTNAME, FALSE),
NM_META_SETTING_VALID_PART_ITEM(TC_CONFIG, FALSE),
NM_META_SETTING_VALID_PART_ITEM(PROXY, FALSE),
NULL,

View file

@ -203,6 +203,10 @@
#define DESCRIBE_DOC_NM_SETTING_GSM_SIM_ID N_("The SIM card unique identifier (as given by the WWAN management service) which this connection applies to. If given, the connection will apply to any device also allowed by \"device-id\" which contains a SIM card matching the given identifier.")
#define DESCRIBE_DOC_NM_SETTING_GSM_SIM_OPERATOR_ID N_("A MCC/MNC string like \"310260\" or \"21601\" identifying the specific mobile network operator which this connection applies to. If given, the connection will apply to any device also allowed by \"device-id\" and \"sim-id\" which contains a SIM card provisioned by the given operator.")
#define DESCRIBE_DOC_NM_SETTING_GSM_USERNAME N_("The username used to authenticate with the network, if required. Many providers do not require a username, or accept any username. But if a username is required, it is specified here.")
#define DESCRIBE_DOC_NM_SETTING_HOSTNAME_FROM_DHCP N_("Whether the system hostname can be determined from DHCP on this connection. When set to NM_TERNARY_DEFAULT (-1), the value from global configuration is used. If the property doesn't have a value in the global configuration, NetworkManager assumes the value to be NM_TERNARY_TRUE (1).")
#define DESCRIBE_DOC_NM_SETTING_HOSTNAME_FROM_DNS_LOOKUP N_("Whether the system hostname can be determined from reverse DNS lookup of addresses on this device. When set to NM_TERNARY_DEFAULT (-1), the value from global configuration is used. If the property doesn't have a value in the global configuration, NetworkManager assumes the value to be NM_TERNARY_TRUE (1).")
#define DESCRIBE_DOC_NM_SETTING_HOSTNAME_ONLY_FROM_DEFAULT N_("If set to NM_TERNARY_TRUE (1), NetworkManager attempts to get the hostname via DHCPv4/DHCPv6 or reverse DNS lookup on this device only when the device has the default route for the given address family (IPv4/IPv6). If set to NM_TERNARY_FALSE (0), the hostname can be set from this device even if it doesn't have the default route. When set to NM_TERNARY_DEFAULT (-1), the value from global configuration is used. If the property doesn't have a value in the global configuration, NetworkManager assumes the value to be NM_TERNARY_TRUE (1).")
#define DESCRIBE_DOC_NM_SETTING_HOSTNAME_PRIORITY N_("The relative priority of this connection to determine the system hostname. A lower numerical value is better (higher priority). A connection with higher priority is considered before connections with lower priority. If the value is zero, it can be overridden by a global value from NetworkManager configuration. If the property doesn't have a value in the global configuration, the value is assumed to be 100. Negative values have the special effect of excluding other connections with a greater numerical priority value; so in presence of at least one negative priority, only connections with the lowest priority value will be used to determine the hostname.")
#define DESCRIBE_DOC_NM_SETTING_INFINIBAND_MAC_ADDRESS N_("If specified, this connection will only apply to the IPoIB device whose permanent MAC address matches. This property does not change the MAC address of the device (i.e. MAC spoofing).")
#define DESCRIBE_DOC_NM_SETTING_INFINIBAND_MTU N_("If non-zero, only transmit packets of the specified size or smaller, breaking larger packets up into multiple frames.")
#define DESCRIBE_DOC_NM_SETTING_INFINIBAND_P_KEY N_("The InfiniBand P_Key to use for this device. A value of -1 means to use the default P_Key (aka \"the P_Key at index 0\"). Otherwise, it is a 16-bit unsigned integer, whose high bit is set if it is a \"full membership\" P_Key.")

View file

@ -324,6 +324,7 @@ print ("NetworkManager version " + client.get_version())]]></programlisting></in
<xi:include href="xml/nm-setting-ethtool.xml"/>
<xi:include href="xml/nm-setting-generic.xml"/>
<xi:include href="xml/nm-setting-gsm.xml"/>
<xi:include href="xml/nm-setting-hostname.xml"/>
<xi:include href="xml/nm-setting-infiniband.xml"/>
<xi:include href="xml/nm-setting-ip4-config.xml"/>
<xi:include href="xml/nm-setting-ip6-config.xml"/>

View file

@ -33,6 +33,7 @@ libnm_core_headers = files(
'nm-setting-ethtool.h',
'nm-setting-generic.h',
'nm-setting-gsm.h',
'nm-setting-hostname.h',
'nm-setting-infiniband.h',
'nm-setting-ip-config.h',
'nm-setting-ip-tunnel.h',
@ -134,6 +135,7 @@ libnm_core_settings_sources = files(
'nm-setting-ethtool.c',
'nm-setting-generic.c',
'nm-setting-gsm.c',
'nm-setting-hostname.c',
'nm-setting-infiniband.c',
'nm-setting-ip-config.c',
'nm-setting-ip-tunnel.c',

View file

@ -37,6 +37,7 @@
#include "nm-setting-dummy.h"
#include "nm-setting-generic.h"
#include "nm-setting-gsm.h"
#include "nm-setting-hostname.h"
#include "nm-setting-infiniband.h"
#include "nm-setting-ip-tunnel.h"
#include "nm-setting-ip4-config.h"

View file

@ -28,6 +28,7 @@ typedef struct _NMSettingDummy NMSettingDummy;
typedef struct _NMSettingEthtool NMSettingEthtool;
typedef struct _NMSettingGeneric NMSettingGeneric;
typedef struct _NMSettingGsm NMSettingGsm;
typedef struct _NMSettingHostname NMSettingHostname;
typedef struct _NMSettingIP4Config NMSettingIP4Config;
typedef struct _NMSettingIP6Config NMSettingIP6Config;
typedef struct _NMSettingIPConfig NMSettingIPConfig;

View file

@ -0,0 +1,339 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
/*
* Copyright (C) 2020 Red Hat, Inc.
*/
#include "nm-default.h"
#include "nm-setting-hostname.h"
#include "nm-setting-private.h"
#include "nm-utils-private.h"
/**
* SECTION:nm-setting-hostname
* @short_description: Contains properties related to the hostname
* @include: nm-setting-hostname.h
**/
/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE(NMSettingHostname,
PROP_PRIORITY,
PROP_FROM_DHCP,
PROP_FROM_DNS_LOOKUP,
PROP_ONLY_FROM_DEFAULT, );
/**
* NMSettingHostname:
*
* Hostname settings
*
* Since: 1.30
*/
struct _NMSettingHostname {
NMSetting parent;
int priority;
NMTernary from_dhcp;
NMTernary from_dns_lookup;
NMTernary only_from_default;
};
struct _NMSettingHostnameClass {
NMSettingClass parent;
};
G_DEFINE_TYPE(NMSettingHostname, nm_setting_hostname, NM_TYPE_SETTING)
/**
* nm_setting_hostname_get_priority:
* @setting: the #NMSettingHostname
*
* Returns the value contained in the #NMSettingHostname:priority
* property.
*
* Returns: the 'priority' property value
*
* Since: 1.30
**/
int
nm_setting_hostname_get_priority(NMSettingHostname *setting)
{
g_return_val_if_fail(NM_IS_SETTING_HOSTNAME(setting), 0);
return setting->priority;
}
/**
* nm_setting_hostname_get_from_dhcp:
* @setting: the #NMSettingHostname
*
* Returns the value contained in the #NMSettingHostname:from-dhcp
* property.
*
* Returns: the 'from-dhcp' property value
*
* Since: 1.30
**/
NMTernary
nm_setting_hostname_get_from_dhcp(NMSettingHostname *setting)
{
g_return_val_if_fail(NM_IS_SETTING_HOSTNAME(setting), NM_TERNARY_DEFAULT);
return setting->from_dhcp;
}
/**
* nm_setting_hostname_get_from_dns_lookup:
* @setting: the #NMSettingHostname
*
* Returns the value contained in the #NMSettingHostname:from-dns-lookup
* property.
*
* Returns: the 'from-dns-lookup' property value
*
* Since: 1.30
**/
NMTernary
nm_setting_hostname_get_from_dns_lookup(NMSettingHostname *setting)
{
g_return_val_if_fail(NM_IS_SETTING_HOSTNAME(setting), NM_TERNARY_DEFAULT);
return setting->from_dns_lookup;
}
/**
* nm_setting_hostname_get_only_from_default:
* @setting: the #NMSettingHostname
*
* Returns the value contained in the #NMSettingHostname:only-from-default
* property.
*
* Returns: the 'only-from-default' property value
*
* Since: 1.30
**/
NMTernary
nm_setting_hostname_get_only_from_default(NMSettingHostname *setting)
{
g_return_val_if_fail(NM_IS_SETTING_HOSTNAME(setting), NM_TERNARY_DEFAULT);
return setting->only_from_default;
}
/*****************************************************************************/
static void
get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
NMSettingHostname *self = NM_SETTING_HOSTNAME(object);
switch (prop_id) {
case PROP_PRIORITY:
g_value_set_int(value, self->priority);
break;
case PROP_FROM_DHCP:
g_value_set_enum(value, self->from_dhcp);
break;
case PROP_FROM_DNS_LOOKUP:
g_value_set_enum(value, self->from_dns_lookup);
break;
case PROP_ONLY_FROM_DEFAULT:
g_value_set_enum(value, self->only_from_default);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
static void
set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
NMSettingHostname *self = NM_SETTING_HOSTNAME(object);
switch (prop_id) {
case PROP_PRIORITY:
self->priority = g_value_get_int(value);
break;
case PROP_FROM_DHCP:
self->from_dhcp = g_value_get_enum(value);
break;
case PROP_FROM_DNS_LOOKUP:
self->from_dns_lookup = g_value_get_enum(value);
break;
case PROP_ONLY_FROM_DEFAULT:
self->only_from_default = g_value_get_enum(value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
/*****************************************************************************/
static void
nm_setting_hostname_init(NMSettingHostname *setting)
{
setting->from_dhcp = NM_TERNARY_DEFAULT;
setting->from_dns_lookup = NM_TERNARY_DEFAULT;
setting->only_from_default = NM_TERNARY_DEFAULT;
}
/**
* nm_setting_hostname_new:
*
* Creates a new #NMSettingHostname object with default values.
*
* Returns: (transfer full): the new empty #NMSettingHostname object
*
* Since: 1.30
**/
NMSetting *
nm_setting_hostname_new(void)
{
return g_object_new(NM_TYPE_SETTING_HOSTNAME, NULL);
}
static void
nm_setting_hostname_class_init(NMSettingHostnameClass *klass)
{
GObjectClass * object_class = G_OBJECT_CLASS(klass);
NMSettingClass *setting_class = NM_SETTING_CLASS(klass);
object_class->get_property = get_property;
object_class->set_property = set_property;
/**
* NMSettingHostname:priority
*
* The relative priority of this connection to determine the
* system hostname. A lower numerical value is better (higher
* priority). A connection with higher priority is considered
* before connections with lower priority.
*
* If the value is zero, it can be overridden by a global value
* from NetworkManager configuration. If the property doesn't have
* a value in the global configuration, the value is assumed to be
* 100.
*
* Negative values have the special effect of excluding other
* connections with a greater numerical priority value; so in
* presence of at least one negative priority, only connections
* with the lowest priority value will be used to determine the
* hostname.
*
* Since: 1.30
**/
/* ---ifcfg-rh---
* property: priority
* variable: HOSTNAME_PRIORITY(+)
* default: missing variable means global value or 100
* description: hostname priority
* example: HOSTNAME_PRIORITY=50
* ---end---
*/
obj_properties[PROP_PRIORITY] = g_param_spec_int(NM_SETTING_HOSTNAME_PRIORITY,
"",
"",
G_MININT32,
G_MAXINT32,
0,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
/**
* NMSettingHostname:from-dhcp
*
* Whether the system hostname can be determined from DHCP on
* this connection.
*
* When set to %NM_TERNARY_DEFAULT, the value from global configuration
* is used. If the property doesn't have a value in the global
* configuration, NetworkManager assumes the value to be %NM_TERNARY_TRUE.
*
* Since: 1.30
**/
/* ---ifcfg-rh---
* property: from-dhcp
* variable: HOSTNAME_FROM_DHCP(+)
* default: missing variable means global default or 1
* description: whether the system hostname can be determined from DHCP
* example: HOSTNAME_FROM_DHCP=0,1
* ---end---
*/
obj_properties[PROP_FROM_DHCP] = g_param_spec_enum(
NM_SETTING_HOSTNAME_FROM_DHCP,
"",
"",
NM_TYPE_TERNARY,
NM_TERNARY_DEFAULT,
NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
/**
* NMSettingHostname:from-dns-lookup
*
* Whether the system hostname can be determined from reverse
* DNS lookup of addresses on this device.
*
* When set to %NM_TERNARY_DEFAULT, the value from global configuration
* is used. If the property doesn't have a value in the global
* configuration, NetworkManager assumes the value to be %NM_TERNARY_TRUE.
*
* Since: 1.30
**/
/* ---ifcfg-rh---
* property: from-dhcp
* variable: HOSTNAME_FROM_DNS_LOOKUP(+)
* default: missing variable means global default or 1
* description: whether the system hostname can be determined from reverse
* DNS lookup
* example: HOSTNAME_FROM_DNS_LOOKUP=0,1
* ---end---
*/
obj_properties[PROP_FROM_DNS_LOOKUP] = g_param_spec_enum(
NM_SETTING_HOSTNAME_FROM_DNS_LOOKUP,
"",
"",
NM_TYPE_TERNARY,
NM_TERNARY_DEFAULT,
NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
/**
* NMSettingHostname:only-from-default
*
* If set to %NM_TERNARY_TRUE, NetworkManager attempts to get
* the hostname via DHCPv4/DHCPv6 or reverse DNS lookup on this
* device only when the device has the default route for the given
* address family (IPv4/IPv6).
*
* If set to %NM_TERNARY_FALSE, the hostname can be set from this
* device even if it doesn't have the default route.
*
* When set to %NM_TERNARY_DEFAULT, the value from global configuration
* is used. If the property doesn't have a value in the global
* configuration, NetworkManager assumes the value to be %NM_TERNARY_TRUE.
*
* Since: 1.30
**/
/* ---ifcfg-rh---
* property: only-best-device
* variable: HOSTNAME_ONLY_FROM_DEFAULT(+)
* default: missing variable means global default or 1
* description: whether the hostname can be determined only from
* devices with the default route
* example: HOSTNAME_ONLY_FROM_DEFAULT=0,1
* ---end---
*/
obj_properties[PROP_ONLY_FROM_DEFAULT] = g_param_spec_enum(
NM_SETTING_HOSTNAME_ONLY_FROM_DEFAULT,
"",
"",
NM_TYPE_TERNARY,
NM_TERNARY_DEFAULT,
NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_HOSTNAME);
}

View file

@ -0,0 +1,53 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
/*
* Copyright (C) 2020 Red Hat, Inc.
*/
#ifndef NM_SETTING_HOSTNAME_H
#define NM_SETTING_HOSTNAME_H
#if !defined(__NETWORKMANAGER_H_INSIDE__) && !defined(NETWORKMANAGER_COMPILATION)
#error "Only <NetworkManager.h> can be included directly."
#endif
#include "nm-setting.h"
G_BEGIN_DECLS
#define NM_TYPE_SETTING_HOSTNAME (nm_setting_hostname_get_type())
#define NM_SETTING_HOSTNAME(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_SETTING_HOSTNAME, NMSettingHostname))
#define NM_SETTING_HOSTNAME_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), NM_TYPE_SETTING_HOSTNAME, NMSettingHostnameClass))
#define NM_IS_SETTING_HOSTNAME(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NM_TYPE_SETTING_HOSTNAME))
#define NM_IS_SETTING_HOSTNAME_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), NM_TYPE_SETTING_HOSTNAME))
#define NM_SETTING_HOSTNAME_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_SETTING_HOSTNAME, NMSettingHostnameClass))
#define NM_SETTING_HOSTNAME_SETTING_NAME "hostname"
#define NM_SETTING_HOSTNAME_PRIORITY "priority"
#define NM_SETTING_HOSTNAME_FROM_DHCP "from-dhcp"
#define NM_SETTING_HOSTNAME_FROM_DNS_LOOKUP "from-dns-lookup"
#define NM_SETTING_HOSTNAME_ONLY_FROM_DEFAULT "only-from-default"
typedef struct _NMSettingHostnameClass NMSettingHostnameClass;
NM_AVAILABLE_IN_1_30
GType nm_setting_hostname_get_type(void);
NM_AVAILABLE_IN_1_30
NMSetting *nm_setting_hostname_new(void);
NM_AVAILABLE_IN_1_30
int nm_setting_hostname_get_priority(NMSettingHostname *setting);
NM_AVAILABLE_IN_1_30
NMTernary nm_setting_hostname_get_from_dhcp(NMSettingHostname *setting);
NM_AVAILABLE_IN_1_30
NMTernary nm_setting_hostname_get_from_dns_lookup(NMSettingHostname *setting);
NM_AVAILABLE_IN_1_30
NMTernary nm_setting_hostname_get_only_from_default(NMSettingHostname *setting);
G_END_DECLS
#endif /* NM_SETTING_HOSTNAME_H */

View file

@ -62,6 +62,7 @@
#include "nm-setting-ethtool.h"
#include "nm-setting-generic.h"
#include "nm-setting-gsm.h"
#include "nm-setting-hostname.h"
#include "nm-setting-infiniband.h"
#include "nm-setting-ip4-config.h"
#include "nm-setting-ip6-config.h"

View file

@ -1766,6 +1766,11 @@ global:
nm_keyfile_read;
nm_keyfile_warn_severity_get_type;
nm_keyfile_write;
nm_setting_hostname_get_from_dhcp;
nm_setting_hostname_get_from_dns_lookup;
nm_setting_hostname_get_only_from_default;
nm_setting_hostname_get_priority;
nm_setting_hostname_get_type;
nm_setting_ovs_external_ids_check_key;
nm_setting_ovs_external_ids_check_val;
nm_setting_ovs_external_ids_get_data;

View file

@ -278,18 +278,24 @@ no-auto-default=*
this option. An hostname empty or equal to 'localhost', 'localhost6',
'localhost.localdomain' or 'localhost6.localdomain' is considered invalid.
</para>
<para><literal>default</literal>: NetworkManager will update the hostname
with the one provided via DHCP on the main connection (the one with a default
route). If not present, the hostname will be updated to the last one set
outside NetworkManager. If it is not valid, NetworkManager will try to recover
the hostname from the reverse lookup of the IP address of the main connection.
If this fails too, the hostname will be set to 'localhost.localdomain'.
<para><literal>default</literal>: NetworkManager will update the
hostname with the one provided via DHCP or reverse DNS lookup of the
IP address on the connection with the default route or on any
connection with the property hostname.only-from-default set to
'<literal>false</literal>'. Connections are considered in order of
increasing value of the <literal>hostname.priority</literal>
property. In case multiple connections have the same priority,
connections activated earlier are considered first. If no hostname can
be determined in such way, the hostname will be updated to the last
one set outside NetworkManager or to 'localhost.localdomain'.
</para>
<para><literal>dhcp</literal>: NetworkManager will update the transient hostname
only with information coming from DHCP. No fallback nor reverse lookup will be
performed, but when the dhcp connection providing the hostname is deactivated,
the hostname is reset to the last hostname set outside NetworkManager or
'localhost' if none valid is there.
<para><literal>dhcp</literal>: this is similar to
'<literal>default</literal>', with the difference that after trying to
get the DHCP hostname, reverse DNS lookup is not done. Note that
selecting this option is equivalent to setting the property
'<literal>hostname.from-dns-lookup</literal>' to
'<literal>false</literal>' globally for all connections in
NetworkManager.conf.
</para>
<para><literal>none</literal>: NetworkManager will not manage the transient
hostname and will never set it.
@ -734,6 +740,18 @@ ipv6.ip6-privacy=0
<varlistentry>
<term><varname>gsm.mtu</varname></term>
</varlistentry>
<varlistentry>
<term><varname>hostname.from-dhcp</varname></term>
</varlistentry>
<varlistentry>
<term><varname>hostname.from-dns-lookup</varname></term>
</varlistentry>
<varlistentry>
<term><varname>hostname.only-from-default</varname></term>
</varlistentry>
<varlistentry>
<term><varname>hostname.priority</varname></term>
</varlistentry>
<varlistentry>
<term><varname>infiniband.mtu</varname></term>
<listitem><para>If configured explicitly to 0, the MTU is not reconfigured during device activation unless it is required due to IPv6 constraints. If left unspecified, a DHCP/IPv6 SLAAC provided value is used or the MTU is left unspecified on activation.</para></listitem>

View file

@ -21,6 +21,7 @@
#include "nm-setting-ethtool.h"
#include "nm-setting-generic.h"
#include "nm-setting-gsm.h"
#include "nm-setting-hostname.h"
#include "nm-setting-infiniband.h"
#include "nm-setting-ip-config.h"
#include "nm-setting-ip-tunnel.h"
@ -243,6 +244,13 @@ const NMMetaSettingInfo nm_meta_setting_infos[] = {
.setting_name = NM_SETTING_GSM_SETTING_NAME,
.get_setting_gtype = nm_setting_gsm_get_type,
},
[NM_META_SETTING_TYPE_HOSTNAME] =
{
.meta_type = NM_META_SETTING_TYPE_HOSTNAME,
.setting_priority = NM_SETTING_PRIORITY_IP,
.setting_name = NM_SETTING_HOSTNAME_SETTING_NAME,
.get_setting_gtype = nm_setting_hostname_get_type,
},
[NM_META_SETTING_TYPE_INFINIBAND] =
{
.meta_type = NM_META_SETTING_TYPE_INFINIBAND,

View file

@ -119,6 +119,7 @@ typedef enum {
NM_META_SETTING_TYPE_ETHTOOL,
NM_META_SETTING_TYPE_GENERIC,
NM_META_SETTING_TYPE_GSM,
NM_META_SETTING_TYPE_HOSTNAME,
NM_META_SETTING_TYPE_INFINIBAND,
NM_META_SETTING_TYPE_IP_TUNNEL,
NM_META_SETTING_TYPE_IP4_CONFIG,

View file

@ -2546,6 +2546,42 @@ make_ip6_setting(shvarFile *ifcfg, shvarFile *network_ifcfg, gboolean routes_rea
return NM_SETTING(g_steal_pointer(&s_ip6));
}
static NMSetting *
make_hostname_setting(shvarFile *ifcfg)
{
NMSetting *setting;
NMTernary from_dhcp;
NMTernary from_dns_lookup;
NMTernary only_from_default;
int priority;
priority = svGetValueInt64(ifcfg, "HOSTNAME_PRIORITY", 10, G_MININT32, G_MAXINT32, 0);
from_dhcp = svGetValueTernary(ifcfg, "HOSTNAME_FROM_DHCP");
from_dns_lookup = svGetValueTernary(ifcfg, "HOSTNAME_FROM_DNS_LOOKUP");
only_from_default = svGetValueTernary(ifcfg, "HOSTNAME_ONLY_FROM_DEFAULT");
/* Create the setting when at least one key is not default*/
if (priority == 0 && from_dhcp == NM_TERNARY_DEFAULT && from_dns_lookup == NM_TERNARY_DEFAULT
&& only_from_default == NM_TERNARY_DEFAULT)
return NULL;
setting = nm_setting_hostname_new();
g_object_set(setting,
NM_SETTING_HOSTNAME_PRIORITY,
priority,
NM_SETTING_HOSTNAME_FROM_DHCP,
from_dhcp,
NM_SETTING_HOSTNAME_FROM_DNS_LOOKUP,
from_dns_lookup,
NM_SETTING_HOSTNAME_ONLY_FROM_DEFAULT,
only_from_default,
NULL);
return setting;
}
static NMSetting *
make_sriov_setting(shvarFile *ifcfg)
{
@ -2951,7 +2987,7 @@ make_dcb_setting(shvarFile *ifcfg, NMSetting **out_setting, GError **error)
gboolean dcb_on;
NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE;
g_return_val_if_fail(out_setting != NULL, FALSE);
g_return_val_if_fail(out_setting, FALSE);
*out_setting = NULL;
dcb_on = !!svGetValueBoolean(ifcfg, "DCB", FALSE);
@ -6552,6 +6588,10 @@ connection_from_file_full(const char *filename,
if (setting)
nm_connection_add_setting(connection, setting);
setting = make_hostname_setting(main_ifcfg);
if (setting)
nm_connection_add_setting(connection, setting);
setting = make_user_setting(main_ifcfg);
if (setting)
nm_connection_add_setting(connection, setting);

View file

@ -873,6 +873,10 @@ const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[] = {
_KEY_TYPE("GATEWAY_PING_TIMEOUT", NMS_IFCFG_KEY_TYPE_IS_PLAIN),
_KEY_TYPE("GENERATE_MAC_ADDRESS_MASK", NMS_IFCFG_KEY_TYPE_IS_PLAIN),
_KEY_TYPE("GVRP", NMS_IFCFG_KEY_TYPE_IS_PLAIN),
_KEY_TYPE("HOSTNAME_FROM_DHCP", NMS_IFCFG_KEY_TYPE_IS_PLAIN),
_KEY_TYPE("HOSTNAME_FROM_DNS_LOOKUP", NMS_IFCFG_KEY_TYPE_IS_PLAIN),
_KEY_TYPE("HOSTNAME_ONLY_FROM_DEFAULT", NMS_IFCFG_KEY_TYPE_IS_PLAIN),
_KEY_TYPE("HOSTNAME_PRIORITY", NMS_IFCFG_KEY_TYPE_IS_PLAIN),
_KEY_TYPE("HWADDR", NMS_IFCFG_KEY_TYPE_IS_PLAIN),
_KEY_TYPE("HWADDR_BLACKLIST", NMS_IFCFG_KEY_TYPE_IS_PLAIN),
_KEY_TYPE("IEEE_8021X_ALTSUBJECT_MATCHES", NMS_IFCFG_KEY_TYPE_IS_PLAIN),

View file

@ -33,7 +33,7 @@ typedef struct {
NMSIfcfgKeyTypeFlags key_flags;
} NMSIfcfgKeyTypeInfo;
extern const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[243];
extern const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[247];
const NMSIfcfgKeyTypeInfo *nms_ifcfg_well_known_key_find_info(const char *key, gssize *out_idx);

View file

@ -1051,6 +1051,28 @@ write_infiniband_setting(NMConnection *connection, shvarFile *ifcfg, GError **er
return TRUE;
}
static void
write_hostname_setting(NMConnection *connection, shvarFile *ifcfg)
{
NMSettingHostname *s_hostname;
NMTernary t;
s_hostname = _nm_connection_get_setting(connection, NM_TYPE_SETTING_HOSTNAME);
if (!s_hostname)
return;
svSetValueInt64(ifcfg, "HOSTNAME_PRIORITY", nm_setting_hostname_get_priority(s_hostname));
t = nm_setting_hostname_get_from_dhcp(s_hostname);
svSetValueInt64_cond(ifcfg, "HOSTNAME_FROM_DHCP", t != NM_TERNARY_DEFAULT, t);
t = nm_setting_hostname_get_from_dns_lookup(s_hostname);
svSetValueInt64_cond(ifcfg, "HOSTNAME_FROM_DNS_LOOKUP", t != NM_TERNARY_DEFAULT, t);
t = nm_setting_hostname_get_only_from_default(s_hostname);
svSetValueInt64_cond(ifcfg, "HOSTNAME_ONLY_FROM_DEFAULT", t != NM_TERNARY_DEFAULT, t);
}
static gboolean
write_wired_setting(NMConnection *connection, shvarFile *ifcfg, GError **error)
{
@ -3347,7 +3369,7 @@ do_write_construct(NMConnection * connection,
return FALSE;
write_match_setting(connection, ifcfg);
write_hostname_setting(connection, ifcfg);
write_sriov_setting(connection, ifcfg);
if (!write_tc_setting(connection, ifcfg, error))