all: add ipvX.dhcp-iaid properties

Add new ipv4.dhcp-iaid and ipv6.dhcp-iaid properties to specify a DHCP
IAID.
This commit is contained in:
Beniamino Galvani
2019-10-15 10:27:10 +02:00
parent 6ff333e242
commit 56a1a5426a
13 changed files with 1032 additions and 632 deletions

View File

@@ -5639,6 +5639,9 @@ static const NMMetaPropertyInfo *const property_infos_IP4_CONFIG[] = {
PROPERTY_INFO_WITH_DESC (NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID,
.property_type = &_pt_gobject_string,
),
PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_IAID, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_IAID,
.property_type = &_pt_gobject_string,
),
PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_TIMEOUT, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_TIMEOUT,
.property_type = &_pt_gobject_int,
.property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int,
@@ -5884,6 +5887,9 @@ static const NMMetaPropertyInfo *const property_infos_IP6_CONFIG[] = {
PROPERTY_INFO (NM_SETTING_IP6_CONFIG_DHCP_DUID, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_DUID,
.property_type = &_pt_gobject_string,
),
PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_IAID, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_IAID,
.property_type = &_pt_gobject_string,
),
PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_SEND_HOSTNAME,
.property_type = &_pt_gobject_bool,
),

View File

@@ -207,6 +207,7 @@
#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID N_("A string sent to the DHCP server to identify the local machine which the DHCP server may use to customize the DHCP lease and options. When the property is a hex string ('aa:bb:cc') it is interpreted as a binary client ID, in which case the first byte is assumed to be the 'type' field as per RFC 2132 section 9.14 and the remaining bytes may be an hardware address (e.g. '01:xx:xx:xx:xx:xx:xx' where 1 is the Ethernet ARP type and the rest is a MAC address). If the property is not a hex string it is considered as a non-hardware-address client ID and the 'type' field is set to 0. The special values \"mac\" and \"perm-mac\" are supported, which use the current or permanent MAC address of the device to generate a client identifier with type ethernet (01). Currently, these options only work for ethernet type of links. The special value \"duid\" generates a RFC4361-compliant client identifier based on a hash of the interface name as IAID and /etc/machine-id. The special value \"stable\" is supported to generate a type 0 client identifier based on the stable-id (see connection.stable-id) and a per-host key. If you set the stable-id, you may want to include the \"${DEVICE}\" or \"${MAC}\" specifier to get a per-device key. If unset, a globally configured default is used. If still unset, the default depends on the DHCP plugin.")
#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_FQDN N_("If the \"dhcp-send-hostname\" property is TRUE, then the specified FQDN will be sent to the DHCP server when acquiring a lease. This property and \"dhcp-hostname\" are mutually exclusive and cannot be set at the same time.")
#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME N_("If the \"dhcp-send-hostname\" property is TRUE, then the specified name will be sent to the DHCP server when acquiring a lease. This property and \"dhcp-fqdn\" are mutually exclusive and cannot be set at the same time.")
#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_IAID N_("A string containing the \"Identity Association Identifier\" (IAID) used by the DHCP client. The property is a 32-bit decimal value or a special value among \"mac\", \"perm-mac\" and \"ifname\". When set to \"mac\" (or \"perm-mac\"), the last 4 bytes of the current (or permanent) MAC address are used as IAID. When set to \"ifname\", the IAID is computed by hashing the interface name. When unset, the value from global configuration is used; if no global default is set then the IAID is assumed to be \"ifname\". Note that at the moment this property is ignored for IPv6 by dhclient, which always derives the IAID from the MAC address.")
#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME N_("If TRUE, a hostname is sent to the DHCP server when acquiring a lease. Some DHCP servers use this hostname to update DNS databases, essentially providing a static hostname for the computer. If the \"dhcp-hostname\" property is NULL and this property is TRUE, the current persistent hostname of the computer is sent.")
#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_TIMEOUT N_("A timeout for a DHCP transaction in seconds.")
#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS N_("Array of IP addresses of DNS servers.")
@@ -227,6 +228,7 @@
#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DAD_TIMEOUT N_("Timeout in milliseconds used to check for the presence of duplicate IP addresses on the network. If an address conflict is detected, the activation will fail. A zero value means that no duplicate address detection is performed, -1 means the default value (either configuration ipvx.dad-timeout override or zero). A value greater than zero is a timeout in milliseconds. The property is currently implemented only for IPv4.")
#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_DUID N_("A string containing the DHCPv6 Unique Identifier (DUID) used by the dhcp client to identify itself to DHCPv6 servers (RFC 3315). The DUID is carried in the Client Identifier option. If the property is a hex string ('aa:bb:cc') it is interpreted as a binary DUID and filled as an opaque value in the Client Identifier option. The special value \"lease\" will retrieve the DUID previously used from the lease file belonging to the connection. If no DUID is found and \"dhclient\" is the configured dhcp client, the DUID is searched in the system-wide dhclient lease file. If still no DUID is found, or another dhcp client is used, a global and permanent DUID-UUID (RFC 6355) will be generated based on the machine-id. The special values \"llt\" and \"ll\" will generate a DUID of type LLT or LL (see RFC 3315) based on the current MAC address of the device. In order to try providing a stable DUID-LLT, the time field will contain a constant timestamp that is used globally (for all profiles) and persisted to disk. The special values \"stable-llt\", \"stable-ll\" and \"stable-uuid\" will generate a DUID of the corresponding type, derived from the connection's stable-id and a per-host unique key. You may want to include the \"${DEVICE}\" or \"${MAC}\" specifier in the stable-id, in case this profile gets activated on multiple devices. So, the link-layer address of \"stable-ll\" and \"stable-llt\" will be a generated address derived from the stable id. The DUID-LLT time value in the \"stable-llt\" option will be picked among a static timespan of three years (the upper bound of the interval is the same constant timestamp used in \"llt\"). When the property is unset, the global value provided for \"ipv6.dhcp-duid\" is used. If no global value is provided, the default \"lease\" value is assumed.")
#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME N_("If the \"dhcp-send-hostname\" property is TRUE, then the specified name will be sent to the DHCP server when acquiring a lease. This property and \"dhcp-fqdn\" are mutually exclusive and cannot be set at the same time.")
#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_IAID N_("A string containing the \"Identity Association Identifier\" (IAID) used by the DHCP client. The property is a 32-bit decimal value or a special value among \"mac\", \"perm-mac\" and \"ifname\". When set to \"mac\" (or \"perm-mac\"), the last 4 bytes of the current (or permanent) MAC address are used as IAID. When set to \"ifname\", the IAID is computed by hashing the interface name. When unset, the value from global configuration is used; if no global default is set then the IAID is assumed to be \"ifname\". Note that at the moment this property is ignored for IPv6 by dhclient, which always derives the IAID from the MAC address.")
#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_SEND_HOSTNAME N_("If TRUE, a hostname is sent to the DHCP server when acquiring a lease. Some DHCP servers use this hostname to update DNS databases, essentially providing a static hostname for the computer. If the \"dhcp-hostname\" property is NULL and this property is TRUE, the current persistent hostname of the computer is sent.")
#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_TIMEOUT N_("A timeout for a DHCP transaction in seconds.")
#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS N_("Array of IP addresses of DNS servers.")

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -872,4 +872,6 @@ gboolean nm_utils_connection_is_adhoc_wpa (NMConnection *connection);
const char *nm_utils_wifi_freq_to_band (guint32 freq);
gboolean _nm_utils_iaid_verify (const char *str, gint64 *out_value);
#endif

View File

@@ -3584,6 +3584,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMSettingIPConfig,
PROP_MAY_FAIL,
PROP_DAD_TIMEOUT,
PROP_DHCP_TIMEOUT,
PROP_DHCP_IAID,
);
typedef struct {
@@ -3606,6 +3607,7 @@ typedef struct {
gboolean may_fail;
int dad_timeout;
int dhcp_timeout;
char *dhcp_iaid;
} NMSettingIPConfigPrivate;
G_DEFINE_ABSTRACT_TYPE (NMSettingIPConfig, nm_setting_ip_config, NM_TYPE_SETTING)
@@ -4860,6 +4862,25 @@ nm_setting_ip_config_get_dhcp_timeout (NMSettingIPConfig *setting)
return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->dhcp_timeout;
}
/**
* nm_setting_ip_config_get_dhcp_iaid:
* @setting: the #NMSettingIPConfig
*
* Returns the value contained in the #NMSettingIPConfig:dhcp-iaid
* property.
*
* Returns: the configured DHCP IAID (Identity Association Identifier)
*
* Since: 1.22
**/
const char *
nm_setting_ip_config_get_dhcp_iaid (NMSettingIPConfig *setting)
{
g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), NULL);
return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->dhcp_iaid;
}
static gboolean
verify_label (const char *label)
{
@@ -5020,6 +5041,19 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
}
}
if ( priv->dhcp_iaid
&& !_nm_utils_iaid_verify (priv->dhcp_iaid, NULL)) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("'%s' is not a valid IAID"),
priv->dhcp_iaid);
g_prefix_error (error, "%s.%s: ",
nm_setting_get_name (setting),
NM_SETTING_IP_CONFIG_DHCP_IAID);
return FALSE;
}
if (priv->gateway && priv->never_default) {
g_set_error (error,
NM_CONNECTION_ERROR,
@@ -5286,6 +5320,9 @@ get_property (GObject *object, guint prop_id,
case PROP_DHCP_TIMEOUT:
g_value_set_int (value, nm_setting_ip_config_get_dhcp_timeout (setting));
break;
case PROP_DHCP_IAID:
g_value_set_string (value, nm_setting_ip_config_get_dhcp_iaid (setting));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -5386,6 +5423,9 @@ set_property (GObject *object, guint prop_id,
case PROP_DHCP_TIMEOUT:
priv->dhcp_timeout = g_value_get_int (value);
break;
case PROP_DHCP_IAID:
priv->dhcp_iaid = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -5415,6 +5455,7 @@ finalize (GObject *object)
g_free (priv->method);
g_free (priv->gateway);
g_free (priv->dhcp_hostname);
g_free (priv->dhcp_iaid);
g_ptr_array_unref (priv->dns);
g_ptr_array_unref (priv->dns_search);
@@ -5777,5 +5818,27 @@ nm_setting_ip_config_class_init (NMSettingIPConfigClass *klass)
NM_SETTING_PARAM_FUZZY_IGNORE |
G_PARAM_STATIC_STRINGS);
/**
* NMSettingIPConfig:dhcp-iaid:
*
* A string containing the "Identity Association Identifier" (IAID) used
* by the DHCP client. The property is a 32-bit decimal value or a
* special value among "mac", "perm-mac" and "ifname". When set to "mac"
* (or "perm-mac"), the last 4 bytes of the current (or permanent) MAC
* address are used as IAID. When set to "ifname", the IAID is computed
* by hashing the interface name. When unset, the value from global
* configuration is used; if no global default is set then the IAID is
* assumed to be "ifname". Note that at the moment this property is
* ignored for IPv6 by dhclient, which always derives the IAID from
* the MAC address.
*
* Since: 1.22
**/
obj_properties[PROP_DHCP_IAID] =
g_param_spec_string (NM_SETTING_IP_CONFIG_DHCP_IAID, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
}

View File

@@ -324,6 +324,7 @@ char *nm_ip_routing_rule_to_string (const NMIPRoutingRule *self,
#define NM_SETTING_IP_CONFIG_MAY_FAIL "may-fail"
#define NM_SETTING_IP_CONFIG_DAD_TIMEOUT "dad-timeout"
#define NM_SETTING_IP_CONFIG_DHCP_TIMEOUT "dhcp-timeout"
#define NM_SETTING_IP_CONFIG_DHCP_IAID "dhcp-iaid"
/* these are not real GObject properties. */
#define NM_SETTING_IP_CONFIG_ROUTING_RULES "routing-rules"
@@ -456,6 +457,8 @@ NM_AVAILABLE_IN_1_2
int nm_setting_ip_config_get_dad_timeout (NMSettingIPConfig *setting);
NM_AVAILABLE_IN_1_2
int nm_setting_ip_config_get_dhcp_timeout (NMSettingIPConfig *setting);
NM_AVAILABLE_IN_1_22
const char *nm_setting_ip_config_get_dhcp_iaid (NMSettingIPConfig *setting);
G_END_DECLS

View File

@@ -6120,3 +6120,25 @@ _nm_utils_bridge_vlan_verify_list (GPtrArray *vlans,
return TRUE;
}
gboolean
_nm_utils_iaid_verify (const char *str, gint64 *out_value)
{
gint64 iaid;
NM_SET_OUT (out_value, -1);
if (!str || !str[0])
return FALSE;
if (NM_IAID_IS_SPECIAL (str))
return TRUE;
if ( NM_STRCHAR_ALL (str, ch, ch >= '0' && ch <= '9')
&& (str[0] != '0' || str[1] == '\0')
&& (iaid = _nm_utils_ascii_str_to_int64 (str, 10, 0, G_MAXUINT32, -1)) != -1) {
NM_SET_OUT (out_value, iaid);
return TRUE;
}
return FALSE;
}

View File

@@ -3051,6 +3051,7 @@ test_connection_diff_a_only (void)
{ NM_SETTING_IP_CONFIG_MAY_FAIL, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP_CONFIG_DAD_TIMEOUT, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP_CONFIG_DNS_PRIORITY, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP_CONFIG_DHCP_IAID, NM_SETTING_DIFF_RESULT_IN_A },
{ NULL, NM_SETTING_DIFF_RESULT_UNKNOWN },
} },
};

View File

@@ -41,6 +41,18 @@ NM_CLONED_MAC_IS_SPECIAL (const char *str)
NM_CLONED_MAC_STABLE);
}
#define NM_IAID_MAC "mac"
#define NM_IAID_PERM_MAC "perm-mac"
#define NM_IAID_IFNAME "ifname"
static inline gboolean
NM_IAID_IS_SPECIAL (const char *str)
{
return NM_IN_STRSET (str,
NM_IAID_MAC,
NM_IAID_PERM_MAC,
NM_IAID_IFNAME);
}
/*****************************************************************************/
#endif /* __NM_COMMON_MACROS_H__ */

View File

@@ -1628,6 +1628,11 @@ make_ip4_setting (shvarFile *ifcfg,
if (v)
g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, v, NULL);
nm_clear_g_free (&value);
v = svGetValueStr (ifcfg, "DHCP_IAID", &value);
if (v)
g_object_set (s_ip4, NM_SETTING_IP_CONFIG_DHCP_IAID, v, NULL);
/* Read static IP addresses.
* Read them even for AUTO method - in this case the addresses are
* added to the automatic ones. Note that this is not currently supported by
@@ -2061,6 +2066,11 @@ make_ip6_setting (shvarFile *ifcfg,
if (v)
g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_DHCP_DUID, v, NULL);
nm_clear_g_free (&value);
v = svGetValueStr (ifcfg, "DHCPV6_IAID", &value);
if (v)
g_object_set (s_ip6, NM_SETTING_IP_CONFIG_DHCP_IAID, v, NULL);
nm_clear_g_free (&value);
v = svGetValueStr (ifcfg, "DHCPV6_HOSTNAME", &value);
/* Use DHCP_HOSTNAME as fallback if it is in FQDN format and ipv6.method is

View File

@@ -2604,6 +2604,9 @@ write_ip4_setting (NMConnection *connection,
value = nm_setting_ip4_config_get_dhcp_client_id (NM_SETTING_IP4_CONFIG (s_ip4));
svSetValueStr (ifcfg, "DHCP_CLIENT_ID", value);
value = nm_setting_ip_config_get_dhcp_iaid (s_ip4);
svSetValueStr (ifcfg, "DHCP_IAID", value);
timeout = nm_setting_ip_config_get_dhcp_timeout (s_ip4);
svSetValueInt64_cond (ifcfg,
"IPV4_DHCP_TIMEOUT",
@@ -2782,6 +2785,7 @@ write_ip6_setting (NMConnection *connection,
svUnsetValue (ifcfg, "IPV6_AUTOCONF");
svUnsetValue (ifcfg, "DHCPV6C");
svUnsetValue (ifcfg, "DHCPv6_DUID");
svUnsetValue (ifcfg, "DHCPv6_IAID");
svUnsetValue (ifcfg, "DHCPV6_HOSTNAME");
svUnsetValue (ifcfg, "DHCPV6_SEND_HOSTNAME");
svUnsetValue (ifcfg, "IPV6_DEFROUTE");
@@ -2831,6 +2835,8 @@ write_ip6_setting (NMConnection *connection,
svSetValueStr (ifcfg, "DHCPV6_DUID",
nm_setting_ip6_config_get_dhcp_duid (NM_SETTING_IP6_CONFIG (s_ip6)));
svSetValueStr (ifcfg, "DHCPV6_IAID",
nm_setting_ip_config_get_dhcp_iaid (s_ip6));
write_ip6_setting_dhcp_hostname (s_ip6, ifcfg);

View File

@@ -4458,6 +4458,7 @@ test_write_wired_dhcp (void)
NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, "awesome-hostname",
NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, TRUE,
NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, TRUE,
NM_SETTING_IP_CONFIG_DHCP_IAID, "2864434397",
NULL);
nmtst_assert_connection_verifies (connection);