summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2014-07-01 12:39:28 -0500
committerDan Williams <dcbw@redhat.com>2014-07-18 17:03:29 -0500
commitdb12693f77c4208fa6e0736ece1ba0080d4e014d (patch)
tree3236f2b69b18ac5fcc86aee3f8b0cd2516e83f03
parent6b445fa030b4d2ff75b192e87f0b412ab4ccdddc (diff)
downloadNetworkManager-db12693f77c4208fa6e0736ece1ba0080d4e014d.tar.gz
dhcp: consolidate more state logic in nm_dhcp_client_set_state()
The goal is to remove generic logic from nm_dhcp_client_new_options(), since library-ized DHCP clients won't ever call that function since their native data format isn't a hash table of strings.
-rw-r--r--src/dhcp-manager/nm-dhcp-client.c48
-rw-r--r--src/dhcp-manager/nm-dhcp-client.h2
2 files changed, 23 insertions, 27 deletions
diff --git a/src/dhcp-manager/nm-dhcp-client.c b/src/dhcp-manager/nm-dhcp-client.c
index a448ab5a73..eff16cc83c 100644
--- a/src/dhcp-manager/nm-dhcp-client.c
+++ b/src/dhcp-manager/nm-dhcp-client.c
@@ -215,16 +215,18 @@ stop (NMDHCPClient *self, gboolean release, const GByteArray *duid)
void
nm_dhcp_client_set_state (NMDHCPClient *self,
- NMDhcpState state,
+ NMDhcpState new_state,
GObject *ip_config,
GHashTable *options)
{
NMDHCPClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE (self);
- if (state == NM_DHCP_STATE_BOUND) {
- /* Cancel the timeout if the DHCP client is now bound */
+ if (new_state >= NM_DHCP_STATE_BOUND)
timeout_cleanup (self);
+ if (new_state >= NM_DHCP_STATE_TIMEOUT)
+ watch_cleanup (self);
+ if (new_state == NM_DHCP_STATE_BOUND) {
g_assert ( (priv->ipv6 && NM_IS_IP6_CONFIG (ip_config))
|| (!priv->ipv6 && NM_IS_IP4_CONFIG (ip_config)));
g_assert (options);
@@ -234,10 +236,25 @@ nm_dhcp_client_set_state (NMDHCPClient *self,
g_assert (options == NULL);
}
- priv->state = state;
+ /* The client may send same-state transitions for RENEW/REBIND events and
+ * the lease may have changed, so handle same-state transitions for the
+ * BOUND state. Ignore same-state transitions for other events since
+ * the lease won't have changed and the state was already handled.
+ */
+ if ((priv->state == new_state) && (new_state != NM_DHCP_STATE_BOUND))
+ return;
+
+ nm_log_info (priv->ipv6 ? LOGD_DHCP6 : LOGD_DHCP4,
+ "(%s): DHCPv%c state changed %s -> %s",
+ priv->iface,
+ priv->ipv6 ? '6' : '4',
+ state_to_string (priv->state),
+ state_to_string (new_state));
+
+ priv->state = new_state;
g_signal_emit (G_OBJECT (self),
signals[SIGNAL_STATE_CHANGED], 0,
- state,
+ new_state,
ip_config,
options);
}
@@ -280,8 +297,6 @@ daemon_watch_cb (GPid pid, gint status, gpointer user_data)
} else
new_state = NM_DHCP_STATE_DONE;
- watch_cleanup (self);
- timeout_cleanup (self);
priv->pid = -1;
nm_dhcp_client_set_state (self, new_state, NULL, NULL);
@@ -550,10 +565,6 @@ nm_dhcp_client_stop (NMDHCPClient *self, gboolean release)
}
g_assert (priv->pid == -1);
- /* And clean stuff up */
- timeout_cleanup (self);
- watch_cleanup (self);
-
nm_dhcp_client_set_state (self, NM_DHCP_STATE_DONE, NULL, NULL);
}
@@ -654,21 +665,6 @@ nm_dhcp_client_new_options (NMDHCPClient *self,
old_state = priv->state;
new_state = reason_to_state (priv->iface, reason);
- /* dhclient sends same-state transitions for RENEW/REBIND events, but
- * the lease may have changed, so handle same-state transitions for
- * these events. Ignore same-state transitions for other events since
- * the lease won't have changed and the state was already handled.
- */
- if ((old_state == new_state) && (new_state != NM_DHCP_STATE_BOUND))
- return;
-
- nm_log_info (priv->ipv6 ? LOGD_DHCP6 : LOGD_DHCP4,
- "(%s): DHCPv%c state changed %s -> %s",
- priv->iface,
- priv->ipv6 ? '6' : '4',
- state_to_string (old_state),
- state_to_string (new_state));
-
if (new_state == NM_DHCP_STATE_BOUND) {
/* Copy options */
str_options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
diff --git a/src/dhcp-manager/nm-dhcp-client.h b/src/dhcp-manager/nm-dhcp-client.h
index 8ab99dbd4a..1712144721 100644
--- a/src/dhcp-manager/nm-dhcp-client.h
+++ b/src/dhcp-manager/nm-dhcp-client.h
@@ -132,7 +132,7 @@ void nm_dhcp_client_stop_pid (pid_t pid, const char *iface);
void nm_dhcp_client_watch_child (NMDHCPClient *self, pid_t pid);
void nm_dhcp_client_set_state (NMDHCPClient *self,
- NMDhcpState state,
+ NMDhcpState new_state,
GObject *ip_config, /* NMIP4Config or NMIP6Config */
GHashTable *options); /* str:str hash */