summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPatrik Flykt <patrik.flykt@linux.intel.com>2013-12-09 23:43:23 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-12-12 11:43:34 -0500
commitbbdf06d9f242e2c5a699c3c5820bf6e09e8d174d (patch)
treef8de966f501f8faab6c47f241360ae8a20fe0a78 /src
parentf5a70de7a9a9e8a37ba96f89ad75fcc31336bfa3 (diff)
dhcp: Add function to stop the DHCP client
The client is stopped and brought back to its initial state.
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd-dhcp/dhcp-client.c32
-rw-r--r--src/systemd/sd-dhcp-client.h1
2 files changed, 33 insertions, 0 deletions
diff --git a/src/libsystemd-dhcp/dhcp-client.c b/src/libsystemd-dhcp/dhcp-client.c
index 181c6f8348..bd2882476e 100644
--- a/src/libsystemd-dhcp/dhcp-client.c
+++ b/src/libsystemd-dhcp/dhcp-client.c
@@ -119,6 +119,33 @@ int sd_dhcp_client_set_mac(sd_dhcp_client *client,
return 0;
}
+static int client_stop(sd_dhcp_client *client, int error)
+{
+ assert_return(client, -EINVAL);
+ assert_return(client->state != DHCP_STATE_INIT &&
+ client->state != DHCP_STATE_INIT_REBOOT, -EALREADY);
+
+ switch (client->state) {
+
+ case DHCP_STATE_INIT:
+ case DHCP_STATE_SELECTING:
+
+ client->state = DHCP_STATE_INIT;
+ break;
+
+ case DHCP_STATE_INIT_REBOOT:
+ case DHCP_STATE_REBOOTING:
+ case DHCP_STATE_REQUESTING:
+ case DHCP_STATE_BOUND:
+ case DHCP_STATE_RENEWING:
+ case DHCP_STATE_REBINDING:
+
+ break;
+ }
+
+ return 0;
+}
+
static int client_packet_init(sd_dhcp_client *client, uint8_t type,
DHCPMessage *message, uint16_t secs,
uint8_t **opt, size_t *optlen)
@@ -263,6 +290,11 @@ int sd_dhcp_client_start(sd_dhcp_client *client)
return client_send_discover(client, 0);
}
+int sd_dhcp_client_stop(sd_dhcp_client *client)
+{
+ return client_stop(client, 0);
+}
+
sd_dhcp_client *sd_dhcp_client_new(void)
{
sd_dhcp_client *client;
diff --git a/src/systemd/sd-dhcp-client.h b/src/systemd/sd-dhcp-client.h
index acfa3fac24..2d2fdffd13 100644
--- a/src/systemd/sd-dhcp-client.h
+++ b/src/systemd/sd-dhcp-client.h
@@ -34,6 +34,7 @@ int sd_dhcp_client_set_index(sd_dhcp_client *client, int interface_index);
int sd_dhcp_client_set_mac(sd_dhcp_client *client,
const struct ether_addr *addr);
+int sd_dhcp_client_stop(sd_dhcp_client *client);
int sd_dhcp_client_start(sd_dhcp_client *client);
sd_dhcp_client *sd_dhcp_client_new(void);