summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancesco Giudici <fgiudici@redhat.com>2018-03-15 18:30:55 +0100
committerFrancesco Giudici <fgiudici@redhat.com>2018-03-23 19:07:41 +0100
commit6026203874231598769b91d7e8e55a63faec9414 (patch)
tree85e4d828a23b40604f2fa414655b2efdc0aaa260
parent177c26d41d987e53759bf477bcccb05bf80dc787 (diff)
downloadNetworkManager-fg/global_DUID-rh1414093.tar.gz
dhcp: introduce global duid filefg/global_DUID-rh1414093
Now it is possible to specify a global DUID file that will be used for all network connections. If the file is not present, a type 4 DUID will be generated as before.
-rw-r--r--src/dhcp/nm-dhcp-client.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/dhcp/nm-dhcp-client.c b/src/dhcp/nm-dhcp-client.c
index 96c0265388..ae69ae6fc0 100644
--- a/src/dhcp/nm-dhcp-client.c
+++ b/src/dhcp/nm-dhcp-client.c
@@ -568,7 +568,31 @@ static GBytes *
get_duid (NMDhcpClient *self)
{
static GBytes *duid = NULL;
+ const char *global_duid_file = NMSTATEDIR "/duid";
+ GBytes *global_duid = NULL;
+ gs_free char *contents = NULL;
+ gs_strfreev char **split = NULL;
+
+ /* First check if a global duid file exists */
+ if ( g_file_test (global_duid_file, G_FILE_TEST_EXISTS)
+ && g_file_get_contents (global_duid_file, &contents, NULL, NULL)) {
+ split = g_strsplit_set (contents, "\n\r", -1);
+ if (!split[0] || (split[1] != NULL))
+ goto generate;
+
+ global_duid = nm_utils_hexstr2bin (g_strdup (split[0]));
+ if (!global_duid)
+ goto generate;
+
+ if (g_bytes_equal (global_duid, duid)) {
+ g_bytes_unref (global_duid);
+ goto generate;
+ }
+ g_bytes_unref (duid);
+ duid = global_duid;
+ }
+generate:
if (G_UNLIKELY (!duid))
duid = generate_duid_from_machine_id ();