Export and use more generic INET helpers
[connman] / plugins / dhclient.c
index 04787d1..432878a 100644 (file)
@@ -2,7 +2,7 @@
  *
  *  Connection Manager
  *
- *  Copyright (C) 2007-2008  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2007-2009  Intel Corporation. All rights reserved.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 2 as
 #include <sys/wait.h>
 #include <glib/gstdio.h>
 
+#define CONNMAN_API_SUBJECT_TO_CHANGE
 #include <connman/plugin.h>
 #include <connman/driver.h>
+#include <connman/inet.h>
 #include <connman/dbus.h>
 #include <connman/log.h>
 
-#include "inet.h"
-
 #define DHCLIENT_INTF "org.isc.dhclient"
 #define DHCLIENT_PATH "/org/isc/dhclient"
 
@@ -144,7 +144,7 @@ static int dhclient_probe(struct connman_element *element)
                return -ENOMEM;
 
        task->ifindex = element->index;
-       task->ifname = inet_index2name(element->index);
+       task->ifname = connman_inet_ifname(element->index);
        task->element = element;
 
        if (task->ifname == NULL) {
@@ -214,11 +214,21 @@ static void dhclient_remove(struct connman_element *element)
        kill_task(task);
 }
 
+static void dhclient_change(struct connman_element *element)
+{
+       DBG("element %p name %s", element, element->name);
+
+       if (element->state == CONNMAN_ELEMENT_STATE_ERROR)
+               connman_element_set_error(element->parent,
+                                       CONNMAN_ELEMENT_ERROR_DHCP_FAILED);
+}
+
 static struct connman_driver dhclient_driver = {
        .name           = "dhclient",
        .type           = CONNMAN_ELEMENT_TYPE_DHCP,
        .probe          = dhclient_probe,
        .remove         = dhclient_remove,
+       .change         = dhclient_change,
 };
 
 static DBusHandlerResult dhclient_filter(DBusConnection *conn,
@@ -305,6 +315,9 @@ static DBusHandlerResult dhclient_filter(DBusConnection *conn,
        } else if (g_ascii_strcasecmp(text, "RENEW") == 0 ||
                                g_ascii_strcasecmp(text, "REBIND") == 0) {
                connman_element_update(task->element);
+       } else if (g_ascii_strcasecmp(text, "FAIL") == 0) {
+               connman_element_set_error(task->element,
+                                               CONNMAN_ELEMENT_ERROR_FAILED);
        } else {
        }
 
@@ -363,4 +376,4 @@ static void dhclient_exit(void)
 }
 
 CONNMAN_PLUGIN_DEFINE(dhclient, "ISC DHCP client plugin", VERSION,
-                                               dhclient_init, dhclient_exit)
+               CONNMAN_PLUGIN_PRIORITY_DEFAULT, dhclient_init, dhclient_exit)