First step towards a generic IP configuration infrastructure
authorMarcel Holtmann <marcel@holtmann.org>
Mon, 29 Jun 2009 18:32:55 +0000 (20:32 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Mon, 29 Jun 2009 18:32:55 +0000 (20:32 +0200)
include/Makefile.am
include/element.h
include/ipconfig.h
include/ipv4.h [deleted file]
src/connman.h
src/device.c
src/element.c
src/ipconfig.c
src/ipv4.c

index b887c7c..160ae60 100644 (file)
@@ -6,7 +6,7 @@ include_HEADERS = types.h log.h plugin.h security.h notifier.h \
 
 nodist_include_HEADERS = version.h
 
-noinst_HEADERS = driver.h element.h property.h ipv4.h rtnl.h dbus.h \
+noinst_HEADERS = driver.h element.h property.h rtnl.h dbus.h \
                        rfkill.h resolver.h ipconfig.h service.h option.h
 
 MAINTAINERCLEANFILES = Makefile.in
index bc6a2a9..5e0b28b 100644 (file)
@@ -31,7 +31,7 @@ extern "C" {
 
 #include <connman/property.h>
 #include <connman/types.h>
-#include <connman/ipv4.h>
+#include <connman/ipconfig.h>
 
 /**
  * SECTION:element
@@ -99,7 +99,7 @@ struct connman_element {
        GHashTable *properties;
 
        struct {
-               enum connman_ipv4_method method;
+               enum connman_ipconfig_method method;
                gchar *address;
                gchar *netmask;
                gchar *gateway;
index 9e92c69..e40981f 100644 (file)
@@ -32,20 +32,40 @@ extern "C" {
  * @short_description: Functions for registering IP configuration modules
  */
 
+enum connman_ipconfig_type {
+       CONNMAN_IPCONFIG_TYPE_UNKNOWN = 0,
+       CONNMAN_IPCONFIG_TYPE_IPV4    = 1,
+       CONNMAN_IPCONFIG_TYPE_IPV6    = 2,
+};
+
+enum connman_ipconfig_method {
+       CONNMAN_IPCONFIG_METHOD_UNKNOWN = 0,
+       CONNMAN_IPCONFIG_METHOD_OFF     = 1,
+       CONNMAN_IPCONFIG_METHOD_STATIC  = 2,
+       CONNMAN_IPCONFIG_METHOD_DHCP    = 3,
+};
+
+struct connman_ipconfig;
+
+extern struct connman_ipconfig *connman_ipconfig_create(void);
+extern struct connman_ipconfig *connman_ipconfig_ref(struct connman_ipconfig *ipconfig);
+extern void connman_ipconfig_unref(struct connman_ipconfig *ipconfig);
+
 #define CONNMAN_IPCONFIG_PRIORITY_LOW      -100
 #define CONNMAN_IPCONFIG_PRIORITY_DEFAULT     0
 #define CONNMAN_IPCONFIG_PRIORITY_HIGH      100
 
-struct connman_ipconfig {
+struct connman_ipconfig_driver {
        const char *name;
+       enum connman_ipconfig_type type;
        int priority;
        int (*request) (const char *interface);
        int (*release) (const char *interface);
        int (*renew) (const char *interface);
 };
 
-extern int connman_ipconfig_register(struct connman_ipconfig *ipconfig);
-extern void connman_ipconfig_unregister(struct connman_ipconfig *ipconfig);
+extern int connman_ipconfig_driver_register(struct connman_ipconfig_driver *driver);
+extern void connman_ipconfig_driver_unregister(struct connman_ipconfig_driver *driver);
 
 #ifdef __cplusplus
 }
diff --git a/include/ipv4.h b/include/ipv4.h
deleted file mode 100644 (file)
index 2f57d0c..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- *
- *  Connection Manager
- *
- *  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
- *  published by the Free Software Foundation.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- */
-
-#ifndef __CONNMAN_IPV4_H
-#define __CONNMAN_IPV4_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * SECTION:ipv4
- * @title: IPv4 premitives
- * @short_description: Functions for handling IPv4
- */
-
-enum connman_ipv4_method {
-       CONNMAN_IPV4_METHOD_UNKNOWN = 0,
-       CONNMAN_IPV4_METHOD_OFF     = 1,
-       CONNMAN_IPV4_METHOD_STATIC  = 2,
-       CONNMAN_IPV4_METHOD_DHCP    = 3,
-};
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __CONNMAN_IPV4_H */
index 0f09e43..b558638 100644 (file)
@@ -85,10 +85,10 @@ void __connman_plugin_cleanup(void);
 int __connman_security_check_privilege(DBusMessage *message,
                                enum connman_security_privilege privilege);
 
-#include <connman/ipv4.h>
+#include <connman/ipconfig.h>
 
-const char *__connman_ipv4_method2string(enum connman_ipv4_method method);
-enum connman_ipv4_method __connman_ipv4_string2method(const char *method);
+const char *__connman_ipconfig_method2string(enum connman_ipconfig_method method);
+enum connman_ipconfig_method __connman_ipconfig_string2method(const char *method);
 
 #include <connman/inet.h>
 
@@ -97,8 +97,6 @@ enum connman_ipv4_method __connman_ipv4_string2method(const char *method);
 int __connman_rfkill_init(void);
 void __connman_rfkill_cleanup(void);
 
-#include <connman/ipconfig.h>
-
 #include <connman/resolver.h>
 
 int __connman_resolver_init(void);
index f3dcce1..c6f89fc 100644 (file)
@@ -146,13 +146,13 @@ static int set_carrier(struct connman_device *device, connman_bool_t carrier)
                device->disconnected = TRUE;
 
                switch (device->element.ipv4.method) {
-               case CONNMAN_IPV4_METHOD_UNKNOWN:
-               case CONNMAN_IPV4_METHOD_OFF:
+               case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+               case CONNMAN_IPCONFIG_METHOD_OFF:
                        return 0;
-               case CONNMAN_IPV4_METHOD_STATIC:
+               case CONNMAN_IPCONFIG_METHOD_STATIC:
                        type = CONNMAN_ELEMENT_TYPE_IPV4;
                        break;
-               case CONNMAN_IPV4_METHOD_DHCP:
+               case CONNMAN_IPCONFIG_METHOD_DHCP:
                        type = CONNMAN_ELEMENT_TYPE_DHCP;
                        break;
                }
@@ -909,7 +909,7 @@ struct connman_device *connman_device_create(const char *node,
                connman_element_set_string(&device->element,
                                        CONNMAN_PROPERTY_ID_TYPE, str);
 
-       device->element.ipv4.method = CONNMAN_IPV4_METHOD_DHCP;
+       device->element.ipv4.method = CONNMAN_IPCONFIG_METHOD_DHCP;
 
        device->type      = type;
        device->name      = g_strdup(type2description(device->type));
index 53ec106..33f84f5 100644 (file)
@@ -76,32 +76,32 @@ static const char *type2string(enum connman_element_type type)
        return NULL;
 }
 
-const char *__connman_ipv4_method2string(enum connman_ipv4_method method)
+const char *__connman_ipconfig_method2string(enum connman_ipconfig_method method)
 {
        switch (method) {
-       case CONNMAN_IPV4_METHOD_UNKNOWN:
+       case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
                return "unknown";
-       case CONNMAN_IPV4_METHOD_OFF:
+       case CONNMAN_IPCONFIG_METHOD_OFF:
                return "off";
-       case CONNMAN_IPV4_METHOD_STATIC:
+       case CONNMAN_IPCONFIG_METHOD_STATIC:
                return "static";
-       case CONNMAN_IPV4_METHOD_DHCP:
+       case CONNMAN_IPCONFIG_METHOD_DHCP:
                return "dhcp";
        }
 
        return "unknown";
 }
 
-enum connman_ipv4_method __connman_ipv4_string2method(const char *method)
+enum connman_ipconfig_method __connman_ipconfig_string2method(const char *method)
 {
        if (strcasecmp(method, "off") == 0)
-               return CONNMAN_IPV4_METHOD_OFF;
+               return CONNMAN_IPCONFIG_METHOD_OFF;
        else if (strcasecmp(method, "static") == 0)
-               return CONNMAN_IPV4_METHOD_STATIC;
+               return CONNMAN_IPCONFIG_METHOD_STATIC;
        else if (strcasecmp(method, "dhcp") == 0)
-               return CONNMAN_IPV4_METHOD_DHCP;
+               return CONNMAN_IPCONFIG_METHOD_DHCP;
        else
-               return CONNMAN_IPV4_METHOD_UNKNOWN;
+               return CONNMAN_IPCONFIG_METHOD_UNKNOWN;
 }
 
 static void emit_element_signal(DBusConnection *conn, const char *member,
@@ -703,11 +703,11 @@ int connman_element_get_value(struct connman_element *element,
 
        switch (id) {
        case CONNMAN_PROPERTY_ID_IPV4_METHOD:
-               if (element->ipv4.method == CONNMAN_IPV4_METHOD_UNKNOWN)
+               if (element->ipv4.method == CONNMAN_IPCONFIG_METHOD_UNKNOWN)
                        return connman_element_get_value(element->parent,
                                                                id, value);
                __connman_element_lock(element);
-               *((const char **) value) = __connman_ipv4_method2string(element->ipv4.method);
+               *((const char **) value) = __connman_ipconfig_method2string(element->ipv4.method);
                __connman_element_unlock(element);
                break;
        case CONNMAN_PROPERTY_ID_IPV4_ADDRESS:
@@ -990,15 +990,15 @@ int __connman_element_set_ipv4(struct connman_element *element,
        type = dbus_message_iter_get_arg_type(value);
 
        if (g_str_equal(name, "IPv4.Method") == TRUE) {
-               enum connman_ipv4_method method;
+               enum connman_ipconfig_method method;
                const char *str;
 
                if (type != DBUS_TYPE_STRING)
                        return -EINVAL;
 
                dbus_message_iter_get_basic(value, &str);
-               method = __connman_ipv4_string2method(str);
-               if (method == CONNMAN_IPV4_METHOD_UNKNOWN)
+               method = __connman_ipconfig_string2method(str);
+               if (method == CONNMAN_IPCONFIG_METHOD_UNKNOWN)
                        return -EINVAL;
 
                if (method == element->ipv4.method)
@@ -1240,7 +1240,7 @@ int connman_element_register(struct connman_element *element,
        }
 
        if (element->type == CONNMAN_ELEMENT_TYPE_DHCP)
-               element->ipv4.method = CONNMAN_IPV4_METHOD_DHCP;
+               element->ipv4.method = CONNMAN_IPCONFIG_METHOD_DHCP;
 
        element->parent = parent;
 
index d369296..7368be0 100644 (file)
 
 #include "connman.h"
 
-static GSList *ipconfig_list = NULL;
+struct connman_ipconfig {
+       gint refcount;
+       enum connman_ipconfig_method method;
+};
+
+/**
+ * connman_ipconfig_create:
+ *
+ * Allocate a new ipconfig structure.
+ *
+ * Returns: a newly-allocated #connman_ipconfig structure
+ */
+struct connman_ipconfig *connman_ipconfig_create(void)
+{
+       struct connman_ipconfig *ipconfig;
+
+       DBG("");
+
+       ipconfig = g_try_new0(struct connman_ipconfig, 1);
+       if (ipconfig == NULL)
+               return NULL;
+
+       DBG("ipconfig %p", ipconfig);
+
+       return ipconfig;
+}
+
+/**
+ * connman_ipconfig_ref:
+ * @ipconfig: ipconfig structure
+ *
+ * Increase reference counter of ipconfig
+ */
+struct connman_ipconfig *connman_ipconfig_ref(struct connman_ipconfig *ipconfig)
+{
+       g_atomic_int_inc(&ipconfig->refcount);
+
+       return ipconfig;
+}
+
+/**
+ * connman_ipconfig_unref:
+ * @ipconfig: ipconfig structure
+ *
+ * Decrease reference counter of ipconfig
+ */
+void connman_ipconfig_unref(struct connman_ipconfig *ipconfig)
+{
+       if (g_atomic_int_dec_and_test(&ipconfig->refcount) == TRUE) {
+               g_free(ipconfig);
+       }
+}
+
+static GSList *driver_list = NULL;
 
 static gint compare_priority(gconstpointer a, gconstpointer b)
 {
-       const struct connman_ipconfig *ipconfig1 = a;
-       const struct connman_ipconfig *ipconfig2 = b;
+       const struct connman_ipconfig_driver *driver1 = a;
+       const struct connman_ipconfig_driver *driver2 = b;
 
-       return ipconfig2->priority - ipconfig1->priority;
+       return driver2->priority - driver1->priority;
 }
 
 /**
- * connman_ipconfig_register:
- * @ipconfig: IP configuration module
+ * connman_ipconfig_driver_register:
+ * @driver: IP configuration driver
  *
- * Register a new IP configuration module
+ * Register a new IP configuration driver
  *
  * Returns: %0 on success
  */
-int connman_ipconfig_register(struct connman_ipconfig *ipconfig)
+int connman_ipconfig_driver_register(struct connman_ipconfig_driver *driver)
 {
-       DBG("ipconfig %p name %s", ipconfig, ipconfig->name);
+       DBG("driver %p name %s", driver, driver->name);
 
-       ipconfig_list = g_slist_insert_sorted(ipconfig_list, ipconfig,
+       driver_list = g_slist_insert_sorted(driver_list, driver,
                                                        compare_priority);
 
        return 0;
 }
 
 /**
- * connman_ipconfig_unregister:
- * @ipconfig: IP configuration module
+ * connman_ipconfig_driver_unregister:
+ * @driver: IP configuration driver
  *
- * Remove a previously registered IP configuration module.
+ * Remove a previously registered IP configuration driver.
  */
-void connman_ipconfig_unregister(struct connman_ipconfig *ipconfig)
+void connman_ipconfig_driver_unregister(struct connman_ipconfig_driver *driver)
 {
-       DBG("ipconfig %p name %s", ipconfig, ipconfig->name);
+       DBG("driver %p name %s", driver, driver->name);
 
-       ipconfig_list = g_slist_remove(ipconfig_list, ipconfig);
+       driver_list = g_slist_remove(driver_list, driver);
 }
index b670cfd..25882ba 100644 (file)
@@ -34,7 +34,7 @@
 #include "connman.h"
 
 struct connman_ipv4 {
-       enum connman_ipv4_method method;
+       enum connman_ipconfig_method method;
        struct in_addr address;
        struct in_addr netmask;
        struct in_addr broadcast;