From 71adbcbb20d685aca4c0de67f0c0c13cd9f5fe00 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Wed, 5 Jan 2011 15:38:03 -0600 Subject: [PATCH] Revert "wimax: if the device is connected at startup, force it to disconnect" This reverts commit 9c99066d6caab46deba26d39df9a01b4dd7476d2. Yay for finger-memory of git commit -a... --- src/dhcp-manager/nm-dhcp-client.c | 16 +++--- src/dhcp-manager/nm-dhcp-client.h | 25 ++++----- src/dhcp-manager/nm-dhcp-dhclient.c | 79 +++++++++-------------------- src/dhcp-manager/nm-dhcp-dhcpcd.c | 6 +-- src/dhcp-manager/nm-dhcp-manager.c | 2 +- src/nm-device.c | 55 ++++++-------------- src/nm-device.h | 2 - src/wimax/nm-device-wimax.c | 46 ++++++----------- 8 files changed, 78 insertions(+), 153 deletions(-) diff --git a/src/dhcp-manager/nm-dhcp-client.c b/src/dhcp-manager/nm-dhcp-client.c index c4dfec64d7..3a8b194081 100644 --- a/src/dhcp-manager/nm-dhcp-client.c +++ b/src/dhcp-manager/nm-dhcp-client.c @@ -136,10 +136,10 @@ watch_cleanup (NMDHCPClient *self) } } -void -nm_dhcp_client_stop_pid (GPid pid, const char *iface, guint timeout_secs) +static void +stop_process (GPid pid, const char *iface) { - int i = (timeout_secs ? timeout_secs : 3) * 5; /* default 3 seconds */ + int i = 15; /* 3 seconds */ g_return_if_fail (pid > 0); @@ -183,7 +183,7 @@ nm_dhcp_client_stop_pid (GPid pid, const char *iface, guint timeout_secs) } static void -real_stop (NMDHCPClient *self, gboolean release) +real_stop (NMDHCPClient *self) { NMDHCPClientPrivate *priv; @@ -196,7 +196,7 @@ real_stop (NMDHCPClient *self, gboolean release) /* Clean up the watch handler since we're explicitly killing the daemon */ watch_cleanup (self); - nm_dhcp_client_stop_pid (priv->pid, priv->iface, 0); + stop_process (priv->pid, priv->iface); priv->info_only = FALSE; } @@ -376,7 +376,7 @@ nm_dhcp_client_stop_existing (const char *pid_file, const char *binary_name) exe = proc_contents; if (!strcmp (exe, binary_name)) - nm_dhcp_client_stop_pid ((GPid) tmp, NULL, 0); + stop_process ((GPid) tmp, NULL); } } @@ -387,7 +387,7 @@ nm_dhcp_client_stop_existing (const char *pid_file, const char *binary_name) } void -nm_dhcp_client_stop (NMDHCPClient *self, gboolean release) +nm_dhcp_client_stop (NMDHCPClient *self) { NMDHCPClientPrivate *priv; @@ -398,7 +398,7 @@ nm_dhcp_client_stop (NMDHCPClient *self, gboolean release) /* Kill the DHCP client */ if (!priv->dead) { - NM_DHCP_CLIENT_GET_CLASS (self)->stop (self, release); + NM_DHCP_CLIENT_GET_CLASS (self)->stop (self); priv->dead = TRUE; nm_log_info (LOGD_DHCP, "(%s): canceled DHCP transaction, DHCP client pid %d", diff --git a/src/dhcp-manager/nm-dhcp-client.h b/src/dhcp-manager/nm-dhcp-client.h index 19c7365edc..f357170b9c 100644 --- a/src/dhcp-manager/nm-dhcp-client.h +++ b/src/dhcp-manager/nm-dhcp-client.h @@ -76,19 +76,18 @@ typedef struct { /* Methods */ - GPid (*ip4_start) (NMDHCPClient *self, - NMSettingIP4Config *s_ip4, - guint8 *anycast_addr, - const char *hostname); + GPid (*ip4_start) (NMDHCPClient *self, + NMSettingIP4Config *s_ip4, + guint8 *anycast_addr, + const char *hostname); - GPid (*ip6_start) (NMDHCPClient *self, - NMSettingIP6Config *s_ip6, - guint8 *anycast_addr, - const char *hostname, - gboolean info_only); + GPid (*ip6_start) (NMDHCPClient *self, + NMSettingIP6Config *s_ip6, + guint8 *anycast_addr, + const char *hostname, + gboolean info_only); - void (*stop) (NMDHCPClient *self, - gboolean release); + void (*stop) (NMDHCPClient *self); /* Signals */ void (*state_changed) (NMDHCPClient *self, NMDHCPState state); @@ -117,7 +116,7 @@ gboolean nm_dhcp_client_start_ip6 (NMDHCPClient *self, const char *hostname, gboolean info_only); -void nm_dhcp_client_stop (NMDHCPClient *self, gboolean release); +void nm_dhcp_client_stop (NMDHCPClient *self); void nm_dhcp_client_new_options (NMDHCPClient *self, GHashTable *options, @@ -134,7 +133,5 @@ NMIP6Config *nm_dhcp_client_get_ip6_config (NMDHCPClient *self, gboolean test) /* Backend helpers */ void nm_dhcp_client_stop_existing (const char *pid_file, const char *binary_name); -void nm_dhcp_client_stop_pid (GPid pid, const char *iface, guint timeout_secs); - #endif /* NM_DHCP_CLIENT_H */ diff --git a/src/dhcp-manager/nm-dhcp-dhclient.c b/src/dhcp-manager/nm-dhcp-dhclient.c index 75684459f6..f6f2a540dc 100644 --- a/src/dhcp-manager/nm-dhcp-dhclient.c +++ b/src/dhcp-manager/nm-dhcp-dhclient.c @@ -411,15 +411,15 @@ dhclient_child_setup (gpointer user_data G_GNUC_UNUSED) static GPid dhclient_start (NMDHCPClient *client, - const char *mode_opt, - gboolean release) + const char *ip_opt, + const char *mode_opt) { NMDHCPDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE (client); GPtrArray *argv = NULL; GPid pid = -1; GError *error = NULL; const char *iface, *uuid; - char *binary_name, *cmd_str, *pid_file = NULL; + char *binary_name, *cmd_str; gboolean ipv6; guint log_domain; @@ -436,33 +436,28 @@ dhclient_start (NMDHCPClient *client, nm_log_warn (log_domain, "(%s): ISC dhcp3 does not support IPv6", iface); return -1; } +#else + g_return_val_if_fail (ip_opt != NULL, -1); #endif + priv->pid_file = g_strdup_printf (LOCALSTATEDIR "/run/dhclient%s-%s.pid", + ipv6 ? "6" : "", + iface); + if (!priv->pid_file) { + nm_log_warn (log_domain, "(%s): not enough memory for dhcpcd options.", iface); + return -1; + } + if (!g_file_test (priv->path, G_FILE_TEST_EXISTS)) { nm_log_warn (log_domain, "%s does not exist.", priv->path); return -1; } - pid_file = g_strdup_printf (LOCALSTATEDIR "/run/dhclient%s-%s.pid", - ipv6 ? "6" : "", - iface); - if (!pid_file) { - nm_log_warn (log_domain, "(%s): not enough memory for dhcpcd options.", iface); - return -1; - } - /* Kill any existing dhclient from the pidfile */ binary_name = g_path_get_basename (priv->path); - nm_dhcp_client_stop_existing (pid_file, binary_name); + nm_dhcp_client_stop_existing (priv->pid_file, binary_name); g_free (binary_name); - if (release) { - /* release doesn't use the pidfile after killing an old client */ - g_free (pid_file); - pid_file = NULL; - } - - g_free (priv->lease_file); priv->lease_file = get_leasefile_for_iface (iface, uuid, ipv6); if (!priv->lease_file) { nm_log_warn (log_domain, "(%s): not enough memory for dhclient options.", iface); @@ -474,26 +469,17 @@ dhclient_start (NMDHCPClient *client, g_ptr_array_add (argv, (gpointer) "-d"); - if (release) - g_ptr_array_add (argv, (gpointer) "-r"); - #if !defined(DHCLIENT_V3) - if (ipv6) { - g_ptr_array_add (argv, (gpointer) "-6"); - if (mode_opt) - g_ptr_array_add (argv, (gpointer) mode_opt); - } else { - g_ptr_array_add (argv, (gpointer) "-4"); - } + g_ptr_array_add (argv, (gpointer) ip_opt); + if (mode_opt) + g_ptr_array_add (argv, (gpointer) mode_opt); #endif g_ptr_array_add (argv, (gpointer) "-sf"); /* Set script file */ g_ptr_array_add (argv, (gpointer) ACTION_SCRIPT_PATH ); - if (pid_file) { - g_ptr_array_add (argv, (gpointer) "-pf"); /* Set pid file */ - g_ptr_array_add (argv, (gpointer) pid_file); - } + g_ptr_array_add (argv, (gpointer) "-pf"); /* Set pid file */ + g_ptr_array_add (argv, (gpointer) priv->pid_file); g_ptr_array_add (argv, (gpointer) "-lf"); /* Set lease file */ g_ptr_array_add (argv, (gpointer) priv->lease_file); @@ -515,10 +501,8 @@ dhclient_start (NMDHCPClient *client, nm_log_warn (log_domain, "dhclient failed to start: '%s'", error->message); g_error_free (error); pid = -1; - } else { + } else nm_log_info (log_domain, "dhclient started with pid %d", pid); - priv->pid_file = pid_file; - } g_ptr_array_free (argv, TRUE); return pid; @@ -541,7 +525,7 @@ real_ip4_start (NMDHCPClient *client, return -1; } - return dhclient_start (client, NULL, FALSE); + return dhclient_start (client, "-4", NULL); } static GPid @@ -551,34 +535,21 @@ real_ip6_start (NMDHCPClient *client, const char *hostname, gboolean info_only) { - return dhclient_start (client, info_only ? "-S" : "-N", FALSE); + return dhclient_start (client, "-6", info_only ? "-S" : "-N"); } static void -real_stop (NMDHCPClient *client, gboolean release) +real_stop (NMDHCPClient *client) { NMDHCPDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE (client); /* Chain up to parent */ - NM_DHCP_CLIENT_CLASS (nm_dhcp_dhclient_parent_class)->stop (client, release); + NM_DHCP_CLIENT_CLASS (nm_dhcp_dhclient_parent_class)->stop (client); if (priv->conf_file) remove (priv->conf_file); - if (priv->pid_file) { + if (priv->pid_file) remove (priv->pid_file); - g_free (priv->pid_file); - priv->pid_file = NULL; - } - - if (release) { - GPid rpid; - - rpid = dhclient_start (client, NULL, TRUE); - if (rpid > 0) { - /* Wait a few seconds for the release to happen */ - nm_dhcp_client_stop_pid (rpid, nm_dhcp_client_get_iface (client), 5); - } - } } /***************************************************/ diff --git a/src/dhcp-manager/nm-dhcp-dhcpcd.c b/src/dhcp-manager/nm-dhcp-dhcpcd.c index 237661fe47..4fb703c480 100644 --- a/src/dhcp-manager/nm-dhcp-dhcpcd.c +++ b/src/dhcp-manager/nm-dhcp-dhcpcd.c @@ -170,17 +170,15 @@ real_ip6_start (NMDHCPClient *client, } static void -real_stop (NMDHCPClient *client, gboolean release) +real_stop (NMDHCPClient *client) { NMDHCPDhcpcdPrivate *priv = NM_DHCP_DHCPCD_GET_PRIVATE (client); /* Chain up to parent */ - NM_DHCP_CLIENT_CLASS (nm_dhcp_dhcpcd_parent_class)->stop (client, release); + NM_DHCP_CLIENT_CLASS (nm_dhcp_dhcpcd_parent_class)->stop (client); if (priv->pid_file) remove (priv->pid_file); - - /* FIXME: implement release... */ } /***************************************************/ diff --git a/src/dhcp-manager/nm-dhcp-manager.c b/src/dhcp-manager/nm-dhcp-manager.c index d3c064199c..a1e3e5e24d 100644 --- a/src/dhcp-manager/nm-dhcp-manager.c +++ b/src/dhcp-manager/nm-dhcp-manager.c @@ -429,7 +429,7 @@ client_start (NMDHCPManager *self, /* Kill any old client instance */ client = get_client_for_iface (self, iface, ipv6); if (client) { - nm_dhcp_client_stop (client, FALSE); + nm_dhcp_client_stop (client); remove_client (self, client); } diff --git a/src/nm-device.c b/src/nm-device.c index b9701a399e..34a9c23a2f 100644 --- a/src/nm-device.c +++ b/src/nm-device.c @@ -184,8 +184,8 @@ static NMActStageReturn dhcp6_start (NMDevice *self, NMDeviceStateReason *reason); static void addrconf6_cleanup (NMDevice *self); -static void dhcp6_cleanup (NMDevice *self, gboolean stop, gboolean release); -static void dhcp4_cleanup (NMDevice *self, gboolean stop, gboolean release); +static void dhcp6_cleanup (NMDevice *self, gboolean stop); +static void dhcp4_cleanup (NMDevice *self, gboolean stop); static void @@ -1467,7 +1467,7 @@ dhcp_timeout (NMDHCPClient *client, gpointer user_data) if (!nm_device_get_act_request (device)) return; - nm_dhcp_client_stop (client, FALSE); + nm_dhcp_client_stop (client); if (nm_device_get_state (device) == NM_DEVICE_STATE_IP_CONFIG) { if (nm_dhcp_client_get_ipv6 (client)) @@ -1480,16 +1480,17 @@ dhcp_timeout (NMDHCPClient *client, gpointer user_data) static NMActStageReturn dhcp4_start (NMDevice *self, NMConnection *connection, + NMSettingIP4Config *s_ip4, NMDeviceStateReason *reason) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMSettingConnection *s_con; - NMSettingIP4Config *s_ip4; guint8 *anycast = NULL; s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION); g_assert (s_con); - s_ip4 = (NMSettingIP4Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG); + + /* Begin a DHCP transaction on the interface */ if (priv->dhcp_anycast_address) anycast = priv->dhcp_anycast_address->data; @@ -1499,7 +1500,6 @@ dhcp4_start (NMDevice *self, g_object_unref (priv->dhcp4_config); priv->dhcp4_config = nm_dhcp4_config_new (); - /* Begin DHCP on the interface */ g_warn_if_fail (priv->dhcp4_client == NULL); priv->dhcp4_client = nm_dhcp_manager_start_ip4 (priv->dhcp_manager, nm_device_get_ip_iface (self), @@ -1525,31 +1525,6 @@ dhcp4_start (NMDevice *self, return NM_ACT_STAGE_RETURN_POSTPONE; } -gboolean -nm_device_dhcp4_renew (NMDevice *self, gboolean release) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - NMActStageReturn ret; - NMDeviceStateReason reason; - NMActRequest *req; - NMConnection *connection; - - g_return_val_if_fail (priv->dhcp4_client != NULL, FALSE); - - /* Terminate old DHCP instance and release the old lease */ - dhcp4_cleanup (self, TRUE, TRUE); - - req = nm_device_get_act_request (self); - g_assert (req); - connection = nm_act_request_get_connection (req); - g_assert (connection); - - /* Start DHCP again on the interface */ - ret = dhcp4_start (self, connection, &reason); - - return (ret != NM_ACT_STAGE_RETURN_FAILURE); -} - static NMActStageReturn real_act_stage3_ip4_config_start (NMDevice *self, NMDeviceStateReason *reason) { @@ -1579,7 +1554,7 @@ real_act_stage3_ip4_config_start (NMDevice *self, NMDeviceStateReason *reason) method = nm_setting_ip4_config_get_method (s_ip4); if (!s_ip4 || !method || !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) { - ret = dhcp4_start (self, connection, reason); + ret = dhcp4_start (self, connection, s_ip4, reason); } else if (s_ip4 && !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)) { GError *error = NULL; const char *iface = nm_device_get_iface (self); @@ -2700,7 +2675,7 @@ delayed_transitions_clear (NMDevice *self) } static void -dhcp4_cleanup (NMDevice *self, gboolean stop, gboolean release) +dhcp4_cleanup (NMDevice *self, gboolean stop) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); @@ -2723,7 +2698,7 @@ dhcp4_cleanup (NMDevice *self, gboolean stop, gboolean release) } if (stop) - nm_dhcp_client_stop (priv->dhcp4_client, release); + nm_dhcp_client_stop (priv->dhcp4_client); g_object_unref (priv->dhcp4_client); priv->dhcp4_client = NULL; @@ -2731,7 +2706,7 @@ dhcp4_cleanup (NMDevice *self, gboolean stop, gboolean release) } static void -dhcp6_cleanup (NMDevice *self, gboolean stop, gboolean release) +dhcp6_cleanup (NMDevice *self, gboolean stop) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); @@ -2755,7 +2730,7 @@ dhcp6_cleanup (NMDevice *self, gboolean stop, gboolean release) } if (stop) - nm_dhcp_client_stop (priv->dhcp6_client, release); + nm_dhcp_client_stop (priv->dhcp6_client); g_object_unref (priv->dhcp6_client); priv->dhcp6_client = NULL; @@ -2804,8 +2779,8 @@ nm_device_deactivate_quickly (NMDevice *self) /* Clear any delayed transitions */ delayed_transitions_clear (self); - dhcp4_cleanup (self, TRUE, FALSE); - dhcp6_cleanup (self, TRUE, FALSE); + dhcp4_cleanup (self, TRUE); + dhcp6_cleanup (self, TRUE); addrconf6_cleanup (self); dnsmasq_cleanup (self); aipd_cleanup (self); @@ -3382,8 +3357,8 @@ dispose (GObject *object) delayed_transitions_clear (self); /* Clean up and stop DHCP */ - dhcp4_cleanup (self, take_down, FALSE); - dhcp6_cleanup (self, take_down, FALSE); + dhcp4_cleanup (self, take_down); + dhcp6_cleanup (self, take_down); addrconf6_cleanup (self); dnsmasq_cleanup (self); diff --git a/src/nm-device.h b/src/nm-device.h index bd400fd6bf..db2b1b7db0 100644 --- a/src/nm-device.h +++ b/src/nm-device.h @@ -185,8 +185,6 @@ void nm_device_set_dhcp_anycast_address (NMDevice *device, guint8 *addr); void nm_device_clear_autoconnect_inhibit (NMDevice *device); -gboolean nm_device_dhcp4_renew (NMDevice *device, gboolean release); - G_END_DECLS #endif /* NM_DEVICE_H */ diff --git a/src/wimax/nm-device-wimax.c b/src/wimax/nm-device-wimax.c index 870759e333..bbb14718f2 100644 --- a/src/wimax/nm-device-wimax.c +++ b/src/wimax/nm-device-wimax.c @@ -587,33 +587,12 @@ real_act_stage2_config (NMDevice *device, NMDeviceStateReason *reason) return NM_ACT_STAGE_RETURN_POSTPONE; } -static void -force_disconnect (struct wmxsdk *sdk) -{ - WIMAX_API_DEVICE_STATUS status; - int ret; - - g_return_if_fail (sdk != NULL); - - status = iwmxsdk_status_get (sdk); - if ((int) status < 0) { - nm_log_err (LOGD_WIMAX, "Failed to read WiMAX device status: %d", status); - return; - } - - if ( status == WIMAX_API_DEVICE_STATUS_Connecting - || status == WIMAX_API_DEVICE_STATUS_Data_Connected) { - ret = iwmx_sdk_disconnect (sdk); - if (ret < 0 && ret != -EINPROGRESS) { - nm_log_err (LOGD_WIMAX, "Failed to disconnect WiMAX device: %d", ret); - } - } -} - static void real_deactivate_quickly (NMDevice *device) { NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (device); + WIMAX_API_DEVICE_STATUS status; + int ret; clear_activation_timeout (NM_DEVICE_WIMAX (device)); clear_link_timeout (NM_DEVICE_WIMAX (device)); @@ -624,7 +603,18 @@ real_deactivate_quickly (NMDevice *device) /* Read explicit status here just to make sure we have the most * up-to-date status and to ensure we disconnect if needed. */ - force_disconnect (priv->sdk); + status = iwmxsdk_status_get (priv->sdk); + if ((int) status < 0) { + nm_log_err (LOGD_WIMAX, "Failed to read WiMAX device status: %d", status); + } else { + if ( status == WIMAX_API_DEVICE_STATUS_Connecting + || status == WIMAX_API_DEVICE_STATUS_Data_Connected) { + ret = iwmx_sdk_disconnect (priv->sdk); + if (ret < 0 && ret != -EINPROGRESS) { + nm_log_err (LOGD_WIMAX, "Failed to disconnect WiMAX device: %d", ret); + } + } + } } } @@ -672,14 +662,10 @@ wmx_state_change_cb (struct wmxsdk *wmxsdk, return; } break; - case WIMAX_API_DEVICE_STATUS_Connecting: - case WIMAX_API_DEVICE_STATUS_Data_Connected: - /* If for some reason we're initially connected, force a disconnect here */ - if (state < NM_DEVICE_STATE_DISCONNECTED) - force_disconnect (wmxsdk); - /* Fall through */ case WIMAX_API_DEVICE_STATUS_Ready: case WIMAX_API_DEVICE_STATUS_Scanning: + case WIMAX_API_DEVICE_STATUS_Connecting: + case WIMAX_API_DEVICE_STATUS_Data_Connected: if (priv->wimaxd_enabled == FALSE) { priv->wimaxd_enabled = TRUE; if (update_availability (self, old_available))