5 * Copyright (C) 2007-2008 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #include <connman/plugin.h>
30 #include <connman/driver.h>
31 #include <connman/log.h>
35 #define RESOLVCONF "/sbin/resolvconf"
37 static int resolvconf_probe(struct connman_element *element)
39 const char *nameserver = NULL;
40 struct connman_element *internet;
44 DBG("element %p name %s", element, element->name);
46 if (access(RESOLVCONF, X_OK) < 0)
49 connman_element_get_value(element,
50 CONNMAN_PROPERTY_ID_IPV4_NAMESERVER, &nameserver);
52 if (nameserver == NULL)
55 name = inet_index2name(element->index);
57 cmd = g_strdup_printf("echo \"nameserver %s\" | %s -a %s",
58 nameserver, RESOLVCONF, name);
69 internet = connman_element_create(NULL);
71 internet->type = CONNMAN_ELEMENT_TYPE_INTERNET;
73 connman_element_register(internet, element);
78 static void resolvconf_remove(struct connman_element *element)
83 DBG("element %p name %s", element, element->name);
85 name = inet_index2name(element->index);
87 cmd = g_strdup_printf("%s -d %s", RESOLVCONF, name);
99 static struct connman_driver resolvconf_driver = {
100 .name = "resolvconf",
101 .type = CONNMAN_ELEMENT_TYPE_RESOLVER,
102 .priority = CONNMAN_DRIVER_PRIORITY_HIGH,
103 .probe = resolvconf_probe,
104 .remove = resolvconf_remove,
107 static int resolvconf_init(void)
109 return connman_driver_register(&resolvconf_driver);
112 static void resolvconf_exit(void)
114 connman_driver_unregister(&resolvconf_driver);
117 CONNMAN_PLUGIN_DEFINE("resolvconf", "Name resolver plugin", VERSION,
118 resolvconf_init, resolvconf_exit)