summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-02-14 17:01:56 +0100
committerThomas Haller <thaller@redhat.com>2018-02-15 11:31:14 +0100
commitfd366bcc46e7de289f9370738713f705431c76b7 (patch)
treef3ac20dc6c6517387b11a030825b267c61d94058
parentbc3a756a4fab94ab181d1f338c8fa76bf263117c (diff)
downloadNetworkManager-th/dhcp-client-id-bgo790660.tar.gz
dhcp: add support for special ipv4.dhcp-client-id types "mac", "perm-mac", and "stable"th/dhcp-client-id-bgo790660
-rw-r--r--clients/common/settings-docs.h.in4
-rw-r--r--libnm-core/nm-setting-connection.c10
-rw-r--r--libnm-core/nm-setting-ip4-config.c7
-rw-r--r--src/devices/nm-device.c72
4 files changed, 84 insertions, 9 deletions
diff --git a/clients/common/settings-docs.h.in b/clients/common/settings-docs.h.in
index 4a295a4877..98db0e72a7 100644
--- a/clients/common/settings-docs.h.in
+++ b/clients/common/settings-docs.h.in
@@ -152,7 +152,7 @@
#define DESCRIBE_DOC_NM_SETTING_CONNECTION_READ_ONLY N_("FALSE if the connection can be modified using the provided settings service's D-Bus interface with the right privileges, or TRUE if the connection is read-only and cannot be modified.")
#define DESCRIBE_DOC_NM_SETTING_CONNECTION_SECONDARIES N_("List of connection UUIDs that should be activated when the base connection itself is activated. Currently only VPN connections are supported.")
#define DESCRIBE_DOC_NM_SETTING_CONNECTION_SLAVE_TYPE N_("Setting name of the device type of this slave's master connection (eg, \"bond\"), or NULL if this connection is not a slave.")
-#define DESCRIBE_DOC_NM_SETTING_CONNECTION_STABLE_ID N_("Token to generate stable IDs for the connection. The stable-id is used for generating IPv6 stable private addresses with ipv6.addr-gen-mode=stable-privacy. It is also used to seed the generated cloned MAC address for ethernet.cloned-mac-address=stable and wifi.cloned-mac-address=stable. Note that also the interface name of the activating connection and a per-host secret key is included into the address generation so that the same stable-id on different hosts/devices yields different addresses. If the value is unset, an ID unique for the connection is used. Specifying a stable-id allows multiple connections to generate the same addresses. Another use is to generate IDs at runtime via dynamic substitutions. The '$' character is treated special to perform dynamic substitutions at runtime. Currently supported are \"${CONNECTION}\", \"${BOOT}\", \"${RANDOM}\". These effectively create unique IDs per-connection, per-boot, or every time. Any unrecognized patterns following '$' are treated verbatim, however are reserved for future use. You are thus advised to avoid '$' or escape it as \"$$\". For example, set it to \"${CONNECTION}/${BOOT}\" to create a unique id for this connection that changes with every reboot. Note that two connections only use the same effective id if their stable-id is also identical before performing dynamic substitutions.")
+#define DESCRIBE_DOC_NM_SETTING_CONNECTION_STABLE_ID N_("Token to generate stable IDs for the connection. The stable-id is used for generating IPv6 stable private addresses with ipv6.addr-gen-mode=stable-privacy. It is also used to seed the generated cloned MAC address for ethernet.cloned-mac-address=stable and wifi.cloned-mac-address=stable. It is also used as DHCP client identifier with ipv4.dhcp-client-id=stable. Note that also the interface name of the activating connection and a per-host secret key is included into the address generation so that the same stable-id on different hosts/devices yields different addresses. If the value is unset, an ID unique for the connection is used. Specifying a stable-id allows multiple connections to generate the same addresses. Another use is to generate IDs at runtime via dynamic substitutions. The '$' character is treated special to perform dynamic substitutions at runtime. Currently supported are \"${CONNECTION}\", \"${BOOT}\", \"${RANDOM}\". These effectively create unique IDs per-connection, per-boot, or every time. Any unrecognized patterns following '$' are treated verbatim, however are reserved for future use. You are thus advised to avoid '$' or escape it as \"$$\". For example, set it to \"${CONNECTION}/${BOOT}\" to create a unique id for this connection that changes with every reboot. Note that two connections only use the same effective id if their stable-id is also identical before performing dynamic substitutions.")
#define DESCRIBE_DOC_NM_SETTING_CONNECTION_TIMESTAMP N_("The time, in seconds since the Unix Epoch, that the connection was last _successfully_ fully activated. NetworkManager updates the connection timestamp periodically when the connection is active to ensure that an active connection has the latest timestamp. The property is only meant for reading (changes to this property will not be preserved).")
#define DESCRIBE_DOC_NM_SETTING_CONNECTION_TYPE N_("Base type of the connection. For hardware-dependent connections, should contain the setting name of the hardware-type specific setting (ie, \"802-3-ethernet\" or \"802-11-wireless\" or \"bluetooth\", etc), and for non-hardware dependent connections like VPN or otherwise, should contain the setting name of that setting type (ie, \"vpn\" or \"bridge\", etc).")
#define DESCRIBE_DOC_NM_SETTING_CONNECTION_UUID N_("A universally unique identifier for the connection, for example generated with libuuid. It should be assigned when the connection is created, and never changed as long as the connection still applies to the same network. For example, it should not be changed when the \"id\" property or NMSettingIP4Config changes, but might need to be re-created when the Wi-Fi SSID, mobile broadband network provider, or \"type\" property changes. The UUID must be in the format \"2815492f-7e56-435e-b2e9-246bd7cdc664\" (ie, contains only hexadecimal characters and \"-\").")
@@ -211,7 +211,7 @@
#define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_TTL N_("The TTL to assign to tunneled packets. 0 is a special value meaning that packets inherit the TTL value.")
#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ADDRESSES N_("Array of IP addresses.")
#define DESCRIBE_DOC_NM_SETTING_IP4_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 3 seconds). A value greater than zero is a timeout in milliseconds.")
-#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.")
+#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 01. Currently, only ethernet is supported. The special value \"stable\" is supported to generate a type 00 client identifier based on the stable-id (see connection.stable-id). If unset, a globally configure default is used. If still unset, the client-id from the last lease is reused.")
#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_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.")
diff --git a/libnm-core/nm-setting-connection.c b/libnm-core/nm-setting-connection.c
index 470209a176..e02fad35a1 100644
--- a/libnm-core/nm-setting-connection.c
+++ b/libnm-core/nm-setting-connection.c
@@ -1541,10 +1541,12 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class)
* The stable-id is used for generating IPv6 stable private addresses
* with ipv6.addr-gen-mode=stable-privacy. It is also used to seed the
* generated cloned MAC address for ethernet.cloned-mac-address=stable
- * and wifi.cloned-mac-address=stable. Note that also the interface name
- * of the activating connection and a per-host secret key is included
- * into the address generation so that the same stable-id on different
- * hosts/devices yields different addresses.
+ * and wifi.cloned-mac-address=stable. It is also used as DHCP client
+ * identifier with ipv4.dhcp-client-id=stable.
+ *
+ * Note that also the interface name of the activating connection and a
+ * per-host secret key is included into the address generation so that the
+ * same stable-id on different hosts/devices yields different addresses.
*
* If the value is unset, an ID unique for the connection is used.
* Specifying a stable-id allows multiple connections to generate the
diff --git a/libnm-core/nm-setting-ip4-config.c b/libnm-core/nm-setting-ip4-config.c
index 87dbd489ea..ebbecd8685 100644
--- a/libnm-core/nm-setting-ip4-config.c
+++ b/libnm-core/nm-setting-ip4-config.c
@@ -720,6 +720,13 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *ip4_class)
* 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 01. Currently, only ethernet is supported.
+ *
+ * The special value "stable" is supported to generate a type 00 client identifier based
+ * on the stable-id (see connection.stable-id).
+ *
* If unset, a globally configure default is used. If still unset, the
* client-id from the last lease is reused.
**/
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 7cdc0d4427..2276e2f6c6 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -34,6 +34,7 @@
#include <arpa/inet.h>
#include <fcntl.h>
#include <linux/if_addr.h>
+#include <linux/if_arp.h>
#include <linux/rtnetlink.h>
#include <linux/pkt_sched.h>
@@ -6399,6 +6400,8 @@ dhcp4_get_client_id (NMDevice *self, NMConnection *connection)
NMSettingIPConfig *s_ip4;
const char *client_id;
gs_free char *client_id_default = NULL;
+ guint8 *client_id_buf;
+ gboolean is_mac;
s_ip4 = nm_connection_get_setting_ip4_config (connection);
client_id = nm_setting_ip4_config_get_dhcp_client_id (NM_SETTING_IP4_CONFIG (s_ip4));
@@ -6410,9 +6413,72 @@ dhcp4_get_client_id (NMDevice *self, NMConnection *connection)
client_id = client_id_default;
}
- return client_id
- ? nm_dhcp_utils_client_id_string_to_bytes (client_id)
- : NULL;
+ if (!client_id)
+ return NULL;
+
+ if ( (is_mac = nm_streq (client_id, "mac"))
+ || nm_streq (client_id, "perm-mac")) {
+ const char *hwaddr;
+ char addr_buf[NM_UTILS_HWADDR_LEN_MAX];
+ gsize addr_len;
+ guint8 addr_type;
+
+ hwaddr = is_mac
+ ? nm_device_get_hw_address (self)
+ : nm_device_get_permanent_hw_address (self);
+ if (!hwaddr)
+ return NULL;
+
+ if (!_nm_utils_hwaddr_aton (hwaddr, addr_buf, sizeof (addr_buf), &addr_len))
+ g_return_val_if_reached (NULL);
+
+ switch (addr_len) {
+ case ETH_ALEN:
+ addr_type = ARPHRD_ETHER;
+ break;
+ default:
+ /* unsupported type. */
+ return NULL;
+ }
+
+ client_id_buf = g_malloc (addr_len + 1);
+ client_id_buf[0] = addr_type;
+ memcpy (&client_id_buf[1], addr_buf, addr_len);
+ return g_bytes_new_take (client_id_buf, addr_len + 1);
+ }
+
+ if (nm_streq (client_id, "stable")) {
+ const guint SALT = 2011610591;
+ NMUtilsStableType stable_type;
+ guchar stable_type_uchar;
+ const char *stable_id;
+ GChecksum *sum;
+ guint8 buf[20];
+ gsize buf_size;
+
+ stable_id = _get_stable_id (self, connection, &stable_type);
+ if (!stable_id)
+ g_return_val_if_reached (NULL);
+
+ stable_type_uchar = (guint8) stable_type;
+
+ sum = g_checksum_new (G_CHECKSUM_SHA1);
+ g_checksum_update (sum, (const guchar *) &SALT, sizeof (SALT));
+ g_checksum_update (sum, &stable_type_uchar, sizeof (stable_type_uchar));
+ g_checksum_update (sum, (const guchar *) stable_id, strlen (stable_id) + 1);
+ buf_size = sizeof (buf);
+ g_checksum_get_digest (sum, buf, &buf_size);
+ nm_assert (buf_size == sizeof (buf));
+
+ g_checksum_free (sum);
+
+ client_id_buf = g_malloc (1 + 15);
+ client_id_buf[0] = 0;
+ memcpy (&client_id_buf[0], buf, 15);
+ return g_bytes_new_take (client_id_buf, 1 + 15);
+ }
+
+ return nm_dhcp_utils_client_id_string_to_bytes (client_id);
}
static NMActStageReturn