commit 756bc704029050af94ef678bb4c0bdc02da14034 Author: Dan Williams Date: Sun May 3 00:51:09 2009 -0400 dhcp: (dhclient) use per-connection leasefiles and don't delete on deactivate So that leases are actually useful... diff --git a/src/dhcp-manager/nm-dhcp-dhclient.c b/src/dhcp-manager/nm-dhcp-dhclient.c index a4d2a88..28b5a23 100644 --- a/src/dhcp-manager/nm-dhcp-dhclient.c +++ b/src/dhcp-manager/nm-dhcp-dhclient.c @@ -63,11 +63,12 @@ get_pidfile_for_iface (const char * iface) static char * -get_leasefile_for_iface (const char * iface) +get_leasefile_for_iface (const char * iface, const char *uuid) { - return g_strdup_printf ("%s/%s-%s.%s", + return g_strdup_printf ("%s/%s-%s-%s.%s", NM_DHCP_MANAGER_LEASE_DIR, NM_DHCP_MANAGER_LEASE_FILENAME, + uuid, iface, NM_DHCP_MANAGER_LEASE_FILE_EXT); } @@ -220,7 +221,9 @@ dhclient_child_setup (gpointer user_data G_GNUC_UNUSED) GPid -nm_dhcp_client_start (NMDHCPDevice *device, NMSettingIP4Config *s_ip4) +nm_dhcp_client_start (NMDHCPDevice *device, + const char *uuid, + NMSettingIP4Config *s_ip4) { GPtrArray *dhclient_argv = NULL; GPid pid = 0; @@ -238,7 +241,7 @@ nm_dhcp_client_start (NMDHCPDevice *device, NMSettingIP4Config *s_ip4) goto out; } - device->lease_file = get_leasefile_for_iface (device->iface); + device->lease_file = get_leasefile_for_iface (device->iface, uuid); if (!device->lease_file) { nm_warning ("%s: not enough memory for dhclient options.", device->iface); goto out; diff --git a/src/dhcp-manager/nm-dhcp-dhcpcd.c b/src/dhcp-manager/nm-dhcp-dhcpcd.c index bc04c5f..05db9dd 100644 --- a/src/dhcp-manager/nm-dhcp-dhcpcd.c +++ b/src/dhcp-manager/nm-dhcp-dhcpcd.c @@ -60,7 +60,9 @@ dhcpcd_child_setup (gpointer user_data G_GNUC_UNUSED) GPid -nm_dhcp_client_start (NMDHCPDevice *device, NMSettingIP4Config *s_ip4) +nm_dhcp_client_start (NMDHCPDevice *device, + const char *uuid, + NMSettingIP4Config *s_ip4) { GPtrArray *argv = NULL; GPid pid = 0; diff --git a/src/dhcp-manager/nm-dhcp-manager.c b/src/dhcp-manager/nm-dhcp-manager.c index a2350e7..afab9a7 100644 --- a/src/dhcp-manager/nm-dhcp-manager.c +++ b/src/dhcp-manager/nm-dhcp-manager.c @@ -586,6 +586,7 @@ static void dhcp_watch_cb (GPid pid, gint status, gpointer user_data) gboolean nm_dhcp_manager_begin_transaction (NMDHCPManager *manager, const char *iface, + const char *uuid, NMSettingIP4Config *s_ip4, guint32 timeout) { @@ -625,7 +626,7 @@ nm_dhcp_manager_begin_transaction (NMDHCPManager *manager, } nm_info ("Activation (%s) Beginning DHCP transaction.", iface); - device->pid = nm_dhcp_client_start (device, setting); + device->pid = nm_dhcp_client_start (device, uuid, setting); if (setting) g_object_unref (setting); @@ -711,9 +712,8 @@ nm_dhcp_manager_cancel_transaction_real (NMDHCPDevice *device) device->pid_file = NULL; } - /* Clean up the leasefile if it got left around */ + /* Free leasefile (but don't delete) */ if (device->lease_file) { - remove (device->lease_file); g_free (device->lease_file); device->lease_file = NULL; } diff --git a/src/dhcp-manager/nm-dhcp-manager.h b/src/dhcp-manager/nm-dhcp-manager.h index f91a8ee..f8737cb 100644 --- a/src/dhcp-manager/nm-dhcp-manager.h +++ b/src/dhcp-manager/nm-dhcp-manager.h @@ -93,6 +93,7 @@ void nm_dhcp_manager_set_hostname_provider(NMDHCPManager *manager, gboolean nm_dhcp_manager_begin_transaction (NMDHCPManager *manager, const char *iface, + const char *uuid, NMSettingIP4Config *s_ip4, guint32 timeout); void nm_dhcp_manager_cancel_transaction (NMDHCPManager *manager, @@ -106,7 +107,9 @@ gboolean nm_dhcp_manager_foreach_dhcp4_option (NMDHCPManager *self, gpointer user_data); /* The following are implemented by the DHCP client backends */ -GPid nm_dhcp_client_start (NMDHCPDevice *device, NMSettingIP4Config *s_ip4); +GPid nm_dhcp_client_start (NMDHCPDevice *device, + const char *uuid, + NMSettingIP4Config *s_ip4); void nm_dhcp_client_stop (NMDHCPDevice *device, pid_t pid); gboolean nm_dhcp_client_process_classless_routes (GHashTable *options, diff --git a/src/nm-device.c b/src/nm-device.c index 1ea77b2..cdbc85c 100644 --- a/src/nm-device.c +++ b/src/nm-device.c @@ -862,10 +862,12 @@ aipd_exec (NMDevice *self, GError **error) static NMActStageReturn real_act_stage3_ip_config_start (NMDevice *self, NMDeviceStateReason *reason) { + NMConnection *connection; + NMSettingConnection *s_con; NMSettingIP4Config *s_ip4; NMActRequest *req; NMActStageReturn ret = NM_ACT_STAGE_RETURN_SUCCESS; - const char *ip_iface, *method = NULL; + const char *ip_iface, *method = NULL, *uuid; g_return_val_if_fail (reason != NULL, NM_ACT_STAGE_RETURN_FAILURE); @@ -873,8 +875,12 @@ real_act_stage3_ip_config_start (NMDevice *self, NMDeviceStateReason *reason) ip_iface = nm_device_get_ip_iface (self); req = nm_device_get_act_request (self); - s_ip4 = (NMSettingIP4Config *) nm_connection_get_setting (nm_act_request_get_connection (req), - NM_TYPE_SETTING_IP4_CONFIG); + connection = nm_act_request_get_connection (req); + s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION); + g_assert (s_con); + uuid = nm_setting_connection_get_uuid (s_con); + + s_ip4 = (NMSettingIP4Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG); /* If we did not receive IP4 configuration information, default to DHCP */ if (s_ip4) @@ -890,7 +896,7 @@ real_act_stage3_ip_config_start (NMDevice *self, NMDeviceStateReason *reason) /* DHCP manager will cancel any transaction already in progress and we do not want to cancel this activation if we get "down" state from that. */ g_signal_handler_block (priv->dhcp_manager, priv->dhcp_state_sigid); - success = nm_dhcp_manager_begin_transaction (priv->dhcp_manager, ip_iface, s_ip4, 45); + success = nm_dhcp_manager_begin_transaction (priv->dhcp_manager, ip_iface, uuid, s_ip4, 45); g_signal_handler_unblock (priv->dhcp_manager, priv->dhcp_state_sigid); if (success) {