dhcp: (dhclient) use per-connection leasefiles and don't delete on deactivate

So that leases are actually useful...
This commit is contained in:
Dan Williams 2009-05-03 00:51:09 -04:00
parent 8613f66f3f
commit 756bc70402
5 changed files with 27 additions and 13 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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;
}

View file

@ -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,

View file

@ -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) {