Fully integrate the usage of resolver element
authorMarcel Holtmann <marcel@holtmann.org>
Thu, 3 Jul 2008 08:15:27 +0000 (10:15 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 3 Jul 2008 08:15:27 +0000 (10:15 +0200)
include/property.h
plugins/dhclient.c
plugins/ipv4.c
plugins/resolvconf.c
src/element.c

index 76ff04e8de564d268cef0389be7ae4ee8488e7cc..20d525a0d0bb3ec0396e671a71fe21d32d78d896 100644 (file)
@@ -32,6 +32,7 @@ enum connman_property_type {
        CONNMAN_PROPERTY_TYPE_IPV4_ADDRESS,
        CONNMAN_PROPERTY_TYPE_IPV4_NETMASK,
        CONNMAN_PROPERTY_TYPE_IPV4_GATEWAY,
+       CONNMAN_PROPERTY_TYPE_IPV4_NAMESERVER,
 };
 
 enum connman_property_flags {
index 3a06e3ea680ce8c46e35c060feca43ed7ac34f70..6bffa8f8fd8787d5ccf35a7699adedf66fa06f8a 100644 (file)
@@ -311,6 +311,7 @@ static DBusHandlerResult dhclient_filter(DBusConnection *conn,
                task->child = connman_element_create();
                task->child->type = CONNMAN_ELEMENT_TYPE_IPV4;
                task->child->netdev.index = task->ifindex;
+               task->child->netdev.name = g_strdup(task->ifname);
                connman_element_update(task->element);
                connman_element_register(task->child, task->element);
        } else if (g_ascii_strcasecmp(text, "RENEW") == 0 ||
index 93706449bdd360c28defff69d291e68e2534f999..8b3457b01f426f6c23e1b548c14f630659aea070 100644 (file)
@@ -29,6 +29,7 @@
 
 static int ipv4_probe(struct connman_element *element)
 {
+       struct connman_element *resolver;
        const char *address = NULL, *netmask = NULL, *gateway = NULL;
 
        DBG("element %p name %s", element, element->name);
@@ -44,12 +45,29 @@ static int ipv4_probe(struct connman_element *element)
        DBG("netmask %s", netmask);
        DBG("gateway %s", gateway);
 
+       resolver = connman_element_create();
+
+       resolver->type = CONNMAN_ELEMENT_TYPE_RESOLVER;
+       resolver->netdev.name = g_strdup(element->netdev.name);
+
+       connman_element_register(resolver, element);
+
+       connman_element_set_data(element, resolver);
+
        return 0;
 }
 
 static void ipv4_remove(struct connman_element *element)
 {
+       struct connman_element *resolver = connman_element_get_data(element);
+
        DBG("element %p name %s", element, element->name);
+
+       connman_element_set_data(element, NULL);
+
+       connman_element_unregister(resolver);
+
+       connman_element_unref(resolver);
 }
 
 static struct connman_driver ipv4_driver = {
index 6f30f8b5b004d9143fc154b0535f65b13785c292..45d15c378e6df1943b4483b0e6aabbea44a68fb7 100644 (file)
 
 static int resolvconf_probe(struct connman_element *element)
 {
+       const char *nameserver = NULL;
        gchar *cmd;
        //int err;
 
        DBG("element %p name %s", element, element->name);
 
+       connman_element_get_value(element,
+                       CONNMAN_PROPERTY_TYPE_IPV4_NAMESERVER, &nameserver);
+
+       if (nameserver == NULL)
+               return -EINVAL;
+
        cmd = g_strdup_printf("echo \"nameserver %s\" | resolvconf -a %s",
-                                       "127.0.0.1", element->netdev.name);
+                                       nameserver, element->netdev.name);
 
        DBG("%s", cmd);
 
index 6305adc50f602ced1771a9a3336d8830d89f3470..55fa6cbaba93df700d4840a2e4856a2de3e42192 100644 (file)
@@ -406,6 +406,10 @@ int connman_element_set_property(struct connman_element *element,
                g_free(element->ipv4.gateway);
                element->ipv4.gateway = g_strdup(*((const char **) value));
                break;
+       case CONNMAN_PROPERTY_TYPE_IPV4_NAMESERVER:
+               g_free(element->ipv4.nameserver);
+               element->ipv4.nameserver = g_strdup(*((const char **) value));
+               break;
        }
 
        g_dbus_emit_signal(connection, CONNMAN_MANAGER_PATH,
@@ -443,6 +447,12 @@ int connman_element_get_value(struct connman_element *element,
                                                                type, value);
                *((char **) value) = element->ipv4.gateway;
                break;
+       case CONNMAN_PROPERTY_TYPE_IPV4_NAMESERVER:
+               if (element->ipv4.nameserver == NULL)
+                       return connman_element_get_value(element->parent,
+                                                               type, value);
+               *((char **) value) = element->ipv4.nameserver;
+               break;
        }
 
        return 0;
@@ -492,6 +502,9 @@ int connman_element_register(struct connman_element *element,
                case CONNMAN_ELEMENT_TYPE_ZEROCONF:
                        element->name = g_strdup("zeroconf");
                        break;
+               case CONNMAN_ELEMENT_TYPE_RESOLVER:
+                       element->name = g_strdup("resolver");
+                       break;
                default:
                        break;
                }