diff options
| author | Michael Biebl <biebl@debian.org> | 2013-02-20 23:06:55 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2013-02-20 23:06:55 +0100 |
| commit | 6bb18bdca6b7bf811bdd00dbea1b09f3a367d2dc (patch) | |
| tree | 8fec068abdd1bc1ade3839f599e1c18d6c524a6a /src/dhcp-manager | |
| parent | fdcb282bbb150da0049cf2dd5b54e56eb3d0b55f (diff) | |
| parent | 8d275584fc94f398f0a7c990dcd057533d9a5856 (diff) | |
Merge tag 'upstream/0.9.8.0' into experimental
Upstream version 0.9.8.0
Diffstat (limited to 'src/dhcp-manager')
| -rw-r--r-- | src/dhcp-manager/nm-dhcp-client.c | 74 | ||||
| -rw-r--r-- | src/dhcp-manager/nm-dhcp-dhclient.c | 17 |
2 files changed, 70 insertions, 21 deletions
diff --git a/src/dhcp-manager/nm-dhcp-client.c b/src/dhcp-manager/nm-dhcp-client.c index 2cdd304d..7bcf935b 100644 --- a/src/dhcp-manager/nm-dhcp-client.c +++ b/src/dhcp-manager/nm-dhcp-client.c @@ -323,6 +323,32 @@ nm_dhcp_client_start_ip4 (NMDHCPClient *self, return priv->pid ? TRUE : FALSE; } +/* uuid_parse does not work for machine-id, so we use our own converter */ +static gboolean +machine_id_parse (const char *in, uuid_t uu) +{ + const char *cp; + int i; + char buf[3]; + + g_return_val_if_fail (in != NULL, FALSE); + g_return_val_if_fail (strlen (in) == 32, FALSE); + + for (i = 0; i < 32; i++, cp++) { + if (!g_ascii_isxdigit (in[i])) + return FALSE; + } + + buf[2] = 0; + cp = in; + for (i = 0; i < 16; i++) { + buf[0] = *cp++; + buf[1] = *cp++; + uu[i] = ((unsigned char) strtoul (buf, NULL, 16)) & 0xFF; + } + return TRUE; +} + static GByteArray * generate_duid_from_machine_id (void) { @@ -334,7 +360,7 @@ generate_duid_from_machine_id (void) gsize sumlen = sizeof (buffer); const guint16 duid_type = g_htons (4); uuid_t uuid; - int ret; + gboolean success; /* Get the machine ID from /etc/machine-id; it's always in /etc no matter * where our configured SYSCONFDIR is. @@ -348,10 +374,10 @@ generate_duid_from_machine_id (void) } contents = g_strstrip (contents); - ret = uuid_parse (contents, uuid); + success = machine_id_parse (contents, uuid); g_free (contents); - if (ret != 0) { + if (!success) { nm_log_warn (LOGD_DHCP6, "Failed to parse " SYSCONFDIR "/machine-id to generate DHCPv6 DUID."); return NULL; } @@ -379,23 +405,6 @@ generate_duid_from_machine_id (void) return duid; } -static GByteArray * -get_duid (NMDHCPClient *self) -{ - static GByteArray *duid = NULL; - GByteArray *copy = NULL; - - if (G_UNLIKELY (duid == NULL)) - duid = generate_duid_from_machine_id (); - - if (G_LIKELY (duid)) { - copy = g_byte_array_sized_new (duid->len); - g_byte_array_append (copy, duid->data, duid->len); - } - - return copy; -} - static char * escape_duid (const GByteArray *duid) { @@ -413,6 +422,31 @@ escape_duid (const GByteArray *duid) return g_string_free (s, FALSE); } +static GByteArray * +get_duid (NMDHCPClient *self) +{ + static GByteArray *duid = NULL; + GByteArray *copy = NULL; + char *escaped; + + if (G_UNLIKELY (duid == NULL)) { + duid = generate_duid_from_machine_id (); + + if (nm_logging_level_enabled (LOGL_DEBUG)) { + escaped = escape_duid (duid); + nm_log_dbg (LOGD_DHCP6, "Generated DUID from machine-id: %s", escaped); + g_free (escaped); + } + } + + if (G_LIKELY (duid)) { + copy = g_byte_array_sized_new (duid->len); + g_byte_array_append (copy, duid->data, duid->len); + } + + return copy; +} + gboolean nm_dhcp_client_start_ip6 (NMDHCPClient *self, NMSettingIP6Config *s_ip6, diff --git a/src/dhcp-manager/nm-dhcp-dhclient.c b/src/dhcp-manager/nm-dhcp-dhclient.c index d9f51352..c43ecf50 100644 --- a/src/dhcp-manager/nm-dhcp-dhclient.c +++ b/src/dhcp-manager/nm-dhcp-dhclient.c @@ -455,8 +455,9 @@ dhclient_start (NMDHCPClient *client, GError *error = NULL; const char *iface, *uuid, *system_bus_address; char *binary_name, *cmd_str, *pid_file = NULL, *system_bus_address_env = NULL; - gboolean ipv6; + gboolean ipv6, success; guint log_domain; + char *escaped; g_return_val_if_fail (priv->pid_file == NULL, -1); @@ -497,6 +498,20 @@ dhclient_start (NMDHCPClient *client, return -1; } + /* Save the DUID to the leasefile dhclient will actually use */ + if (ipv6) { + escaped = nm_dhcp_dhclient_escape_duid (duid); + success = nm_dhcp_dhclient_save_duid (priv->lease_file, escaped, &error); + g_free (escaped); + if (!success) { + nm_log_warn (log_domain, "(%s): failed to save DUID to %s: (%d) %s.", + iface, priv->lease_file, + error ? error->code : -1, + error && error->message ? error->message : "(unknown)"); + return -1; + } + } + argv = g_ptr_array_new (); g_ptr_array_add (argv, (gpointer) priv->path); |