Add resolver plugin using resolvconf helper tool
authorMarcel Holtmann <marcel@holtmann.org>
Mon, 24 Mar 2008 10:02:49 +0000 (11:02 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Mon, 24 Mar 2008 10:02:49 +0000 (11:02 +0100)
plugins/Makefile.am
plugins/resolvconf.c [new file with mode: 0644]

index 2f789ec..87464b0 100644 (file)
@@ -2,7 +2,7 @@
 plugindir = $(libdir)/connman/plugins
 
 plugin_LTLIBRARIES = libconnman-80203.la libconnman-80211.la \
-                       libconnman-dhclient.la
+                       libconnman-dhclient.la libconnman-resolvconf.la
 
 libconnman_80203_la_SOURCES = 80203.c
 
@@ -11,6 +11,8 @@ libconnman_80211_la_SOURCES = 80211.c supplicant.h supplicant.c
 libconnman_dhclient_la_SOURCES = dhclient.c
 libconnman_dhclient_la_LIBADD = @GDBUS_LIBS@
 
+libconnman_resolvconf_la_SOURCES = resolvconf.c
+
 AM_LDFLAGS = -module -avoid-version -export-symbols-regex connman_plugin_desc
 
 statedir = $(localstatedir)/run/connman
diff --git a/plugins/resolvconf.c b/plugins/resolvconf.c
new file mode 100644 (file)
index 0000000..732db4f
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007  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
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <net/if.h>
+
+#include <connman/plugin.h>
+#include <connman/resolver.h>
+#include <connman/log.h>
+
+static int resolvconf_append(struct connman_iface *iface, const char *nameserver)
+{
+       struct ifreq ifr;
+       char cmd[128];
+       int sk, err;
+
+       sk = socket(PF_INET, SOCK_DGRAM, 0);
+       if (sk < 0)
+               return -1;
+
+       memset(&ifr, 0, sizeof(ifr));
+       ifr.ifr_ifindex = iface->index;
+
+       err = ioctl(sk, SIOCGIFNAME, &ifr);
+
+       close(sk);
+
+       if (err < 0)
+               return -1;
+
+       DBG("ifname %s", ifr.ifr_name);
+
+       snprintf(cmd, sizeof(cmd), "echo \"nameserver %s\" | resolvconf -a %s",
+                                               nameserver, ifr.ifr_name);
+
+       DBG("%s", cmd);
+
+       err = system(cmd);
+
+       return 0;
+}
+
+static int resolvconf_remove(struct connman_iface *iface)
+{
+       struct ifreq ifr;
+       char cmd[128];
+       int sk, err;
+
+       sk = socket(PF_INET, SOCK_DGRAM, 0);
+       if (sk < 0)
+               return -1;
+
+       memset(&ifr, 0, sizeof(ifr));
+       ifr.ifr_ifindex = iface->index;
+
+       err = ioctl(sk, SIOCGIFNAME, &ifr);
+
+       close(sk);
+
+       if (err < 0)
+               return -1;
+
+       DBG("ifname %s", ifr.ifr_name);
+
+       snprintf(cmd, sizeof(cmd), "resolvconf -d %s", ifr.ifr_name);
+
+       DBG("%s", cmd);
+
+       err = system(cmd);
+
+       return 0;
+}
+
+static struct connman_resolver_driver resolvconf_driver = {
+       .name           = "resolvconf",
+       .append         = resolvconf_append,
+       .remove         = resolvconf_remove,
+};
+
+static int resolvconf_init(void)
+{
+       return connman_resolver_register(&resolvconf_driver);
+}
+
+static void resolvconf_exit(void)
+{
+       connman_resolver_unregister(&resolvconf_driver);
+}
+
+CONNMAN_PLUGIN_DEFINE("resolvconf", "Name resolver plugin", VERSION,
+                                       resolvconf_init, resolvconf_exit)