[systemd-devel] [PATCH 18/28] dhcp: Add function to stop the DHCP client

Patrik Flykt patrik.flykt at linux.intel.com
Wed Nov 13 13:22:46 PST 2013


The client is stopped and brought back to its initial state.
---
 src/dhcp/client.c |   35 +++++++++++++++++++++++++++++++++++
 src/dhcp/client.h |    1 +
 2 files changed, 36 insertions(+)

diff --git a/src/dhcp/client.c b/src/dhcp/client.c
index dc92880..79ac93b 100644
--- a/src/dhcp/client.c
+++ b/src/dhcp/client.c
@@ -133,6 +133,36 @@ int dhcp_client_set_mac(DHCPClient *client, struct ether_addr *addr)
         return 0;
 }
 
+static int client_stop(DHCPClient *client, int error)
+{
+        if (!client)
+                return -EINVAL;
+
+        if (client->state == DHCP_STATE_INIT ||
+            client->state == DHCP_STATE_INIT_REBOOT)
+                return -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(DHCPClient *client, uint8_t type,
                               DHCPMessage *message, uint16_t secs,
                               uint8_t **opt, int *optlen)
@@ -278,6 +308,11 @@ int dhcp_client_start(DHCPClient *client)
         return client_send_discover(client, 0);
 }
 
+int dhcp_client_stop(DHCPClient *client)
+{
+        return client_stop(client, 0);
+}
+
 DHCPClient *dhcp_client_new(void)
 {
         DHCPClient *client;
diff --git a/src/dhcp/client.h b/src/dhcp/client.h
index fb7682a..71fdbe3 100644
--- a/src/dhcp/client.h
+++ b/src/dhcp/client.h
@@ -34,4 +34,5 @@ int dhcp_client_set_index(DHCPClient *client, int interface_index);
 int dhcp_client_set_mac(DHCPClient *client, struct ether_addr *addr);
 
 int dhcp_client_start(DHCPClient *client);
+int dhcp_client_stop(DHCPClient *client);
 DHCPClient *dhcp_client_new(void);
-- 
1.7.10.4



More information about the systemd-devel mailing list