summary refs log tree commit diff
path: root/src/dnsmasq-manager
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2014-07-06 02:16:10 +0200
committerMichael Biebl <biebl@debian.org>2014-07-06 02:16:10 +0200
commit33491bc4279481db8ae47213e34a6d695a0e8830 (patch)
tree097d2b0fdff3fae6885381ae5e57a182cd8cbbba /src/dnsmasq-manager
parent59c3714a494c3b3765657c0551ad82842d98a7d2 (diff)
Imported Upstream version 0.9.10.0 upstream/0.9.10.0
Diffstat (limited to 'src/dnsmasq-manager')
-rw-r--r--src/dnsmasq-manager/Makefile.am19
-rw-r--r--src/dnsmasq-manager/nm-dnsmasq-manager.c59
-rw-r--r--src/dnsmasq-manager/nm-dnsmasq-utils.c77
-rw-r--r--src/dnsmasq-manager/nm-dnsmasq-utils.h32
-rw-r--r--src/dnsmasq-manager/tests/Makefile.am23
-rw-r--r--src/dnsmasq-manager/tests/Makefile.in (renamed from src/dnsmasq-manager/Makefile.in)235
-rw-r--r--src/dnsmasq-manager/tests/test-dnsmasq-utils.c115
7 files changed, 444 insertions, 116 deletions
diff --git a/src/dnsmasq-manager/Makefile.am b/src/dnsmasq-manager/Makefile.am
deleted file mode 100644
index 42706cc2..00000000
--- a/src/dnsmasq-manager/Makefile.am
+++ /dev/null
@@ -1,19 +0,0 @@
-noinst_LTLIBRARIES = libdnsmasq-manager.la
-
-libdnsmasq_manager_la_CPPFLAGS = \
-	-I${top_srcdir}/libnm-util \
-	-I${top_srcdir}/src/logging \
-	-I${top_srcdir}/src/posix-signals \
-	-I${top_srcdir}/src \
-	-I${top_srcdir}/include \
-	$(GLIB_CFLAGS) \
-	-DLOCALSTATEDIR=\"$(localstatedir)\"
-
-libdnsmasq_manager_la_SOURCES = \
-	nm-dnsmasq-manager.h \
-	nm-dnsmasq-manager.c
-
-libdnsmasq_manager_la_LIBADD = \
-	$(top_builddir)/src/logging/libnm-logging.la \
-	$(top_builddir)/src/posix-signals/libnm-posix-signals.la \
-	$(GLIB_LIBS)
diff --git a/src/dnsmasq-manager/nm-dnsmasq-manager.c b/src/dnsmasq-manager/nm-dnsmasq-manager.c
index 083fb533..21bbd23a 100644
--- a/src/dnsmasq-manager/nm-dnsmasq-manager.c
+++ b/src/dnsmasq-manager/nm-dnsmasq-manager.c
@@ -28,9 +28,11 @@
 #include <stdlib.h>
 
 #include "nm-dnsmasq-manager.h"
+#include "nm-dnsmasq-utils.h"
 #include "nm-logging.h"
 #include "nm-glib-compat.h"
 #include "nm-posix-signals.h"
+#include "nm-utils.h"
 
 typedef struct {
 	char *iface;
@@ -53,6 +55,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
 
 typedef enum {
 	NM_DNSMASQ_MANAGER_ERROR_NOT_FOUND,
+	NM_DNSMASQ_MANAGER_ERROR_INVALID_IP_RANGE,
 } NMDnsMasqManagerError;
 
 GQuark
@@ -112,8 +115,6 @@ nm_dnsmasq_manager_new (const char *iface)
 	NMDnsMasqManagerPrivate *priv;
 
 	manager = (NMDnsMasqManager *) g_object_new (NM_TYPE_DNSMASQ_MANAGER, NULL);
-	if (!manager)
-		return NULL;
 
 	priv = NM_DNSMASQ_MANAGER_GET_PRIVATE (manager);
 	priv->iface = g_strdup (iface);
@@ -251,10 +252,11 @@ create_dm_cmd_line (const char *iface,
 	const char *dm_binary;
 	NMCmdLine *cmd;
 	GString *s;
-	NMIP4Address *tmp;
-	struct in_addr addr;
-	char buf[INET_ADDRSTRLEN + 15];
-	char localaddr[INET_ADDRSTRLEN + 1];
+	const NMPlatformIP4Address *tmp;
+	char first[INET_ADDRSTRLEN];
+	char last[INET_ADDRSTRLEN];
+	char localaddr[INET_ADDRSTRLEN];
+	char *error_desc = NULL;
 
 	dm_binary = nm_find_dnsmasq ();
 	if (!dm_binary) {
@@ -296,48 +298,23 @@ create_dm_cmd_line (const char *iface,
 	nm_cmd_line_add_string (cmd, "--strict-order");
 
 	s = g_string_new ("--listen-address=");
-	addr.s_addr = nm_ip4_address_get_address (tmp);
-	if (!inet_ntop (AF_INET, &addr, &localaddr[0], INET_ADDRSTRLEN)) {
-		char *err_msg = g_strdup_printf ("error converting IP4 address 0x%X",
-		                                 ntohl (addr.s_addr));
-		g_set_error_literal (error, NM_DNSMASQ_MANAGER_ERROR, NM_DNSMASQ_MANAGER_ERROR_NOT_FOUND, err_msg);
-		nm_log_warn (LOGD_SHARING, "%s", err_msg);
-		g_free (err_msg);
-		goto error;
-	}
+	nm_utils_inet4_ntop (tmp->address, localaddr);
 	g_string_append (s, localaddr);
 	nm_cmd_line_add_string (cmd, s->str);
 	g_string_free (s, TRUE);
 
-	s = g_string_new ("--dhcp-range=");
-
-	/* Add start of address range */
-	addr.s_addr = nm_ip4_address_get_address (tmp) + htonl (9);
-	if (!inet_ntop (AF_INET, &addr, &buf[0], INET_ADDRSTRLEN)) {
-		char *err_msg = g_strdup_printf ("error converting IP4 address 0x%X",
-		                                 ntohl (addr.s_addr));
-		g_set_error_literal (error, NM_DNSMASQ_MANAGER_ERROR, NM_DNSMASQ_MANAGER_ERROR_NOT_FOUND, err_msg);
-		nm_log_warn (LOGD_SHARING, "%s", err_msg);
-		g_free (err_msg);
-		goto error;
-	}
-	g_string_append (s, buf);
-
-	g_string_append_c (s, ',');
-
-	/* Add end of address range */
-	addr.s_addr = nm_ip4_address_get_address (tmp) + htonl (99);
-	if (!inet_ntop (AF_INET, &addr, &buf[0], INET_ADDRSTRLEN)) {
-		char *err_msg = g_strdup_printf ("error converting IP4 address 0x%X",
-		                                 ntohl (addr.s_addr));
-		g_set_error_literal (error, NM_DNSMASQ_MANAGER_ERROR, NM_DNSMASQ_MANAGER_ERROR_NOT_FOUND, err_msg);
-		nm_log_warn (LOGD_SHARING, "%s", err_msg);
-		g_free (err_msg);
+	if (!nm_dnsmasq_utils_get_range (tmp, first, last, &error_desc)) {
+		g_set_error_literal (error,
+		                     NM_DNSMASQ_MANAGER_ERROR,
+		                     NM_DNSMASQ_MANAGER_ERROR_INVALID_IP_RANGE,
+		                     error_desc);
+		nm_log_warn (LOGD_SHARING, "Failed to find DHCP address ranges: %s", error_desc);
+		g_free (error_desc);
 		goto error;
 	}
-	g_string_append (s, buf);
 
-	g_string_append (s, ",60m");
+	s = g_string_new ("--dhcp-range=");
+	g_string_append_printf (s, "%s,%s,60m", first, last);
 	nm_cmd_line_add_string (cmd, s->str);
 	g_string_free (s, TRUE);
 
diff --git a/src/dnsmasq-manager/nm-dnsmasq-utils.c b/src/dnsmasq-manager/nm-dnsmasq-utils.c
new file mode 100644
index 00000000..7036b409
--- /dev/null
+++ b/src/dnsmasq-manager/nm-dnsmasq-utils.c
@@ -0,0 +1,77 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager -- Network link manager
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2013 Red Hat, Inc.
+ */
+
+#include <config.h>
+#include <string.h>
+#include <arpa/inet.h>
+
+#include "nm-dnsmasq-utils.h"
+#include "nm-platform.h"
+#include "nm-utils.h"
+
+gboolean
+nm_dnsmasq_utils_get_range (const NMPlatformIP4Address *addr,
+                            char *out_first,
+                            char *out_last,
+                            char **out_error_desc)
+{
+	guint32 host = addr->address;
+	guint32 prefix = addr->plen;
+	guint32 netmask = nm_utils_ip4_prefix_to_netmask (prefix);
+	guint32 first, last, reserved;
+
+	g_return_val_if_fail (out_first != NULL, FALSE);
+	g_return_val_if_fail (out_last != NULL, FALSE);
+
+	if (prefix > 30) {
+		if (out_error_desc)
+			*out_error_desc = g_strdup_printf ("Address prefix %d is too small for DHCP.", prefix);
+		return FALSE;
+	}
+
+	/* Find the first available address *after* the local machine's IP */
+	first = (host & netmask) + htonl (1);
+
+	/* Shortcut: allow a max of 253 addresses; the - htonl(1) here is to assure
+	 * that we don't set 'last' to the broadcast address of the network. */
+	if (prefix < 24)
+		last = (host | ~nm_utils_ip4_prefix_to_netmask (24)) - htonl (1);
+	else
+		last = (host | ~netmask) - htonl(1);
+
+	/* Figure out which range (either above the host address or below it)
+	 * has more addresses.  Reserve some addresses for static IPs.
+	 */
+	if (ntohl (host) - ntohl (first) > ntohl (last) - ntohl (host)) {
+		/* Range below the host's IP address */
+		reserved = (guint32) ((ntohl (host) - ntohl (first)) / 10);
+		last = host - htonl (MIN (reserved, 8)) - htonl (1);
+	} else {
+		/* Range above host's IP address */
+		reserved = (guint32) ((ntohl (last) - ntohl (host)) / 10);
+		first = host + htonl (MIN (reserved, 8)) + htonl (1);
+	}
+
+	nm_utils_inet4_ntop (first, out_first);
+	nm_utils_inet4_ntop (last, out_last);
+
+	return TRUE;
+}
+
diff --git a/src/dnsmasq-manager/nm-dnsmasq-utils.h b/src/dnsmasq-manager/nm-dnsmasq-utils.h
new file mode 100644
index 00000000..4534c6ef
--- /dev/null
+++ b/src/dnsmasq-manager/nm-dnsmasq-utils.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager -- Network link manager
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2013 Red Hat, Inc.
+ */
+
+#ifndef NM_DNSMASQ_UTILS_H
+#define NM_DNSMASQ_UTILS_H
+
+#include <glib.h>
+#include "nm-platform.h"
+
+gboolean nm_dnsmasq_utils_get_range (const NMPlatformIP4Address *addr,
+                                     char *out_first,
+                                     char *out_last,
+                                     char **out_error_desc);
+
+#endif /* NM_DNSMASQ_UTILS_H */
diff --git a/src/dnsmasq-manager/tests/Makefile.am b/src/dnsmasq-manager/tests/Makefile.am
new file mode 100644
index 00000000..9c7f4ab5
--- /dev/null
+++ b/src/dnsmasq-manager/tests/Makefile.am
@@ -0,0 +1,23 @@
+AM_CPPFLAGS = \
+	-I$(top_srcdir)/include \
+	-I$(top_builddir)/include \
+	-I${top_srcdir}/libnm-util \
+	-I${top_builddir}/libnm-util \
+	-I$(top_srcdir)/src/dnsmasq-manager \
+	-I$(top_srcdir)/src \
+	-I$(top_srcdir)/src/platform \
+	-DG_LOG_DOMAIN=\""NetworkManager"\" \
+	-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
+	$(GLIB_CFLAGS) \
+	-DTESTDIR="\"$(abs_srcdir)\""
+
+noinst_PROGRAMS = test-dnsmasq-utils
+
+test_dnsmasq_utils_SOURCES = \
+	test-dnsmasq-utils.c
+
+test_dnsmasq_utils_LDADD = \
+	$(top_builddir)/src/libNetworkManager.la
+
+TESTS = test-dnsmasq-utils
+
diff --git a/src/dnsmasq-manager/Makefile.in b/src/dnsmasq-manager/tests/Makefile.in
index 9b20331f..52301e3d 100644
--- a/src/dnsmasq-manager/Makefile.in
+++ b/src/dnsmasq-manager/tests/Makefile.in
@@ -78,11 +78,14 @@ PRE_UNINSTALL = :
 POST_UNINSTALL = :
 build_triplet = @build@
 host_triplet = @host@
-subdir = src/dnsmasq-manager
+noinst_PROGRAMS = test-dnsmasq-utils$(EXEEXT)
+TESTS = test-dnsmasq-utils$(EXEEXT)
+subdir = src/dnsmasq-manager/tests
 DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
 	$(top_srcdir)/build-aux/depcomp
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/compiler_warnings.m4 \
+am__aclocal_m4_deps = $(top_srcdir)/m4/ax_lib_readline.m4 \
+	$(top_srcdir)/m4/compiler_warnings.m4 \
 	$(top_srcdir)/m4/gettext.m4 \
 	$(top_srcdir)/m4/gnome-code-coverage.m4 \
 	$(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/iconv.m4 \
@@ -100,15 +103,11 @@ mkinstalldirs = $(install_sh) -d
 CONFIG_HEADER = $(top_builddir)/config.h
 CONFIG_CLEAN_FILES =
 CONFIG_CLEAN_VPATH_FILES =
-LTLIBRARIES = $(noinst_LTLIBRARIES)
-am__DEPENDENCIES_1 =
-libdnsmasq_manager_la_DEPENDENCIES =  \
-	$(top_builddir)/src/logging/libnm-logging.la \
-	$(top_builddir)/src/posix-signals/libnm-posix-signals.la \
-	$(am__DEPENDENCIES_1)
-am_libdnsmasq_manager_la_OBJECTS =  \
-	libdnsmasq_manager_la-nm-dnsmasq-manager.lo
-libdnsmasq_manager_la_OBJECTS = $(am_libdnsmasq_manager_la_OBJECTS)
+PROGRAMS = $(noinst_PROGRAMS)
+am_test_dnsmasq_utils_OBJECTS = test-dnsmasq-utils.$(OBJEXT)
+test_dnsmasq_utils_OBJECTS = $(am_test_dnsmasq_utils_OBJECTS)
+test_dnsmasq_utils_DEPENDENCIES =  \
+	$(top_builddir)/src/libNetworkManager.la
 AM_V_lt = $(am__v_lt_@AM_V@)
 am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
 am__v_lt_0 = --silent
@@ -147,8 +146,8 @@ AM_V_CCLD = $(am__v_CCLD_@AM_V@)
 am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
 am__v_CCLD_0 = @echo "  CCLD    " $@;
 am__v_CCLD_1 = 
-SOURCES = $(libdnsmasq_manager_la_SOURCES)
-DIST_SOURCES = $(libdnsmasq_manager_la_SOURCES)
+SOURCES = $(test_dnsmasq_utils_SOURCES)
+DIST_SOURCES = $(test_dnsmasq_utils_SOURCES)
 am__can_run_installinfo = \
   case $$AM_UPDATE_INFO_DIR in \
     n|no|NO) false;; \
@@ -173,6 +172,28 @@ am__define_uniq_tagged_files = \
   done | $(am__uniquify_input)`
 ETAGS = etags
 CTAGS = ctags
+am__tty_colors_dummy = \
+  mgn= red= grn= lgn= blu= brg= std=; \
+  am__color_tests=no
+am__tty_colors = { \
+  $(am__tty_colors_dummy); \
+  if test "X$(AM_COLOR_TESTS)" = Xno; then \
+    am__color_tests=no; \
+  elif test "X$(AM_COLOR_TESTS)" = Xalways; then \
+    am__color_tests=yes; \
+  elif test "X$$TERM" != Xdumb && { test -t 1; } 2>/dev/null; then \
+    am__color_tests=yes; \
+  fi; \
+  if test $$am__color_tests = yes; then \
+    red=''; \
+    grn=''; \
+    lgn=''; \
+    blu=''; \
+    mgn=''; \
+    brg=''; \
+    std=''; \
+  fi; \
+}
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = @ACLOCAL@
 ALL_LINGUAS = @ALL_LINGUAS@
@@ -199,12 +220,15 @@ CXXFLAGS = @CXXFLAGS@
 CYGPATH_W = @CYGPATH_W@
 DATADIRNAME = @DATADIRNAME@
 DBUS_CFLAGS = @DBUS_CFLAGS@
+DBUS_GLIB_100_CFLAGS = @DBUS_GLIB_100_CFLAGS@
+DBUS_GLIB_100_LIBS = @DBUS_GLIB_100_LIBS@
 DBUS_LIBS = @DBUS_LIBS@
 DBUS_SYS_DIR = @DBUS_SYS_DIR@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
 DHCLIENT_PATH = @DHCLIENT_PATH@
 DHCPCD_PATH = @DHCPCD_PATH@
+DISTRO_NETWORK_SERVICE = @DISTRO_NETWORK_SERVICE@
 DLLTOOL = @DLLTOOL@
 DNSMASQ_PATH = @DNSMASQ_PATH@
 DSYMUTIL = @DSYMUTIL@
@@ -229,7 +253,6 @@ GNUTLS_CFLAGS = @GNUTLS_CFLAGS@
 GNUTLS_LIBS = @GNUTLS_LIBS@
 GREP = @GREP@
 GTKDOC_CHECK = @GTKDOC_CHECK@
-GTKDOC_CHECK_PATH = @GTKDOC_CHECK_PATH@
 GTKDOC_DEPS_CFLAGS = @GTKDOC_DEPS_CFLAGS@
 GTKDOC_DEPS_LIBS = @GTKDOC_DEPS_LIBS@
 GTKDOC_MKPDF = @GTKDOC_MKPDF@
@@ -274,12 +297,16 @@ LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@
 LIBICONV = @LIBICONV@
 LIBINTL = @LIBINTL@
 LIBM = @LIBM@
+LIBNDP_CFLAGS = @LIBNDP_CFLAGS@
+LIBNDP_LIBS = @LIBNDP_LIBS@
 LIBNL_CFLAGS = @LIBNL_CFLAGS@
 LIBNL_LIBS = @LIBNL_LIBS@
 LIBOBJS = @LIBOBJS@
 LIBS = @LIBS@
 LIBSOUP_CFLAGS = @LIBSOUP_CFLAGS@
 LIBSOUP_LIBS = @LIBSOUP_LIBS@
+LIBTEAMDCTL_CFLAGS = @LIBTEAMDCTL_CFLAGS@
+LIBTEAMDCTL_LIBS = @LIBTEAMDCTL_LIBS@
 LIBTOOL = @LIBTOOL@
 LIPO = @LIPO@
 LN_S = @LN_S@
@@ -296,6 +323,8 @@ MOC = @MOC@
 MSGFMT = @MSGFMT@
 MSGFMT_015 = @MSGFMT_015@
 MSGMERGE = @MSGMERGE@
+NEWT_CFLAGS = @NEWT_CFLAGS@
+NEWT_LIBS = @NEWT_LIBS@
 NM = @NM@
 NMEDIT = @NMEDIT@
 NM_MAJOR_VERSION = @NM_MAJOR_VERSION@
@@ -323,11 +352,16 @@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
 POLKIT_CFLAGS = @POLKIT_CFLAGS@
 POLKIT_LIBS = @POLKIT_LIBS@
 POSUB = @POSUB@
+PPPD_PATH = @PPPD_PATH@
 PPPD_PLUGIN_DIR = @PPPD_PLUGIN_DIR@
+PPPOE_PATH = @PPPOE_PATH@
 QT_CFLAGS = @QT_CFLAGS@
 QT_LIBS = @QT_LIBS@
 RANLIB = @RANLIB@
+READLINE_LIBS = @READLINE_LIBS@
 SED = @SED@
+SELINUX_CFLAGS = @SELINUX_CFLAGS@
+SELINUX_LIBS = @SELINUX_LIBS@
 SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
 STRIP = @STRIP@
@@ -342,6 +376,7 @@ UDEV_BASE_DIR = @UDEV_BASE_DIR@
 USE_NLS = @USE_NLS@
 UUID_CFLAGS = @UUID_CFLAGS@
 UUID_LIBS = @UUID_LIBS@
+VALGRIND_RULES = @VALGRIND_RULES@
 VAPIGEN = @VAPIGEN@
 VAPIGEN_MAKEFILE = @VAPIGEN_MAKEFILE@
 VAPIGEN_VAPIDIR = @VAPIGEN_VAPIDIR@
@@ -404,6 +439,7 @@ psdir = @psdir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
+subdirs = @subdirs@
 sysconfdir = @sysconfdir@
 systemdsystemunitdir = @systemdsystemunitdir@
 target_alias = @target_alias@
@@ -414,24 +450,25 @@ with_dhclient = @with_dhclient@
 with_dhcpcd = @with_dhcpcd@
 with_netconfig = @with_netconfig@
 with_resolvconf = @with_resolvconf@
-noinst_LTLIBRARIES = libdnsmasq-manager.la
-libdnsmasq_manager_la_CPPFLAGS = \
+with_valgrind = @with_valgrind@
+AM_CPPFLAGS = \
+	-I$(top_srcdir)/include \
+	-I$(top_builddir)/include \
 	-I${top_srcdir}/libnm-util \
-	-I${top_srcdir}/src/logging \
-	-I${top_srcdir}/src/posix-signals \
-	-I${top_srcdir}/src \
-	-I${top_srcdir}/include \
+	-I${top_builddir}/libnm-util \
+	-I$(top_srcdir)/src/dnsmasq-manager \
+	-I$(top_srcdir)/src \
+	-I$(top_srcdir)/src/platform \
+	-DG_LOG_DOMAIN=\""NetworkManager"\" \
+	-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
 	$(GLIB_CFLAGS) \
-	-DLOCALSTATEDIR=\"$(localstatedir)\"
+	-DTESTDIR="\"$(abs_srcdir)\""
 
-libdnsmasq_manager_la_SOURCES = \
-	nm-dnsmasq-manager.h \
-	nm-dnsmasq-manager.c
+test_dnsmasq_utils_SOURCES = \
+	test-dnsmasq-utils.c
 
-libdnsmasq_manager_la_LIBADD = \
-	$(top_builddir)/src/logging/libnm-logging.la \
-	$(top_builddir)/src/posix-signals/libnm-posix-signals.la \
-	$(GLIB_LIBS)
+test_dnsmasq_utils_LDADD = \
+	$(top_builddir)/src/libNetworkManager.la
 
 all: all-am
 
@@ -446,9 +483,9 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__confi
 	      exit 1;; \
 	  esac; \
 	done; \
-	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/dnsmasq-manager/Makefile'; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/dnsmasq-manager/tests/Makefile'; \
 	$(am__cd) $(top_srcdir) && \
-	  $(AUTOMAKE) --gnu src/dnsmasq-manager/Makefile
+	  $(AUTOMAKE) --gnu src/dnsmasq-manager/tests/Makefile
 .PRECIOUS: Makefile
 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
 	@case '$?' in \
@@ -468,19 +505,18 @@ $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
 	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
 $(am__aclocal_m4_deps):
 
-clean-noinstLTLIBRARIES:
-	-test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
-	@list='$(noinst_LTLIBRARIES)'; \
-	locs=`for p in $$list; do echo $$p; done | \
-	      sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
-	      sort -u`; \
-	test -z "$$locs" || { \
-	  echo rm -f $${locs}; \
-	  rm -f $${locs}; \
-	}
+clean-noinstPROGRAMS:
+	@list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \
+	echo " rm -f" $$list; \
+	rm -f $$list || exit $$?; \
+	test -n "$(EXEEXT)" || exit 0; \
+	list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+	echo " rm -f" $$list; \
+	rm -f $$list
 
-libdnsmasq-manager.la: $(libdnsmasq_manager_la_OBJECTS) $(libdnsmasq_manager_la_DEPENDENCIES) $(EXTRA_libdnsmasq_manager_la_DEPENDENCIES) 
-	$(AM_V_CCLD)$(LINK)  $(libdnsmasq_manager_la_OBJECTS) $(libdnsmasq_manager_la_LIBADD) $(LIBS)
+test-dnsmasq-utils$(EXEEXT): $(test_dnsmasq_utils_OBJECTS) $(test_dnsmasq_utils_DEPENDENCIES) $(EXTRA_test_dnsmasq_utils_DEPENDENCIES) 
+	@rm -f test-dnsmasq-utils$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(test_dnsmasq_utils_OBJECTS) $(test_dnsmasq_utils_LDADD) $(LIBS)
 
 mostlyclean-compile:
 	-rm -f *.$(OBJEXT)
@@ -488,7 +524,7 @@ mostlyclean-compile:
 distclean-compile:
 	-rm -f *.tab.c
 
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libdnsmasq_manager_la-nm-dnsmasq-manager.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-dnsmasq-utils.Po@am__quote@
 
 .c.o:
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@@ -511,13 +547,6 @@ distclean-compile:
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
 
-libdnsmasq_manager_la-nm-dnsmasq-manager.lo: nm-dnsmasq-manager.c
-@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libdnsmasq_manager_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libdnsmasq_manager_la-nm-dnsmasq-manager.lo -MD -MP -MF $(DEPDIR)/libdnsmasq_manager_la-nm-dnsmasq-manager.Tpo -c -o libdnsmasq_manager_la-nm-dnsmasq-manager.lo `test -f 'nm-dnsmasq-manager.c' || echo '$(srcdir)/'`nm-dnsmasq-manager.c
-@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libdnsmasq_manager_la-nm-dnsmasq-manager.Tpo $(DEPDIR)/libdnsmasq_manager_la-nm-dnsmasq-manager.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='nm-dnsmasq-manager.c' object='libdnsmasq_manager_la-nm-dnsmasq-manager.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libdnsmasq_manager_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libdnsmasq_manager_la-nm-dnsmasq-manager.lo `test -f 'nm-dnsmasq-manager.c' || echo '$(srcdir)/'`nm-dnsmasq-manager.c
-
 mostlyclean-libtool:
 	-rm -f *.lo
 
@@ -576,6 +605,99 @@ cscopelist-am: $(am__tagged_files)
 distclean-tags:
 	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
 
+check-TESTS: $(TESTS)
+	@failed=0; all=0; xfail=0; xpass=0; skip=0; \
+	srcdir=$(srcdir); export srcdir; \
+	list=' $(TESTS) '; \
+	$(am__tty_colors); \
+	if test -n "$$list"; then \
+	  for tst in $$list; do \
+	    if test -f ./$$tst; then dir=./; \
+	    elif test -f $$tst; then dir=; \
+	    else dir="$(srcdir)/"; fi; \
+	    if $(TESTS_ENVIRONMENT) $${dir}$$tst $(AM_TESTS_FD_REDIRECT); then \
+	      all=`expr $$all + 1`; \
+	      case " $(XFAIL_TESTS) " in \
+	      *[\ \	]$$tst[\ \	]*) \
+		xpass=`expr $$xpass + 1`; \
+		failed=`expr $$failed + 1`; \
+		col=$$red; res=XPASS; \
+	      ;; \
+	      *) \
+		col=$$grn; res=PASS; \
+	      ;; \
+	      esac; \
+	    elif test $$? -ne 77; then \
+	      all=`expr $$all + 1`; \
+	      case " $(XFAIL_TESTS) " in \
+	      *[\ \	]$$tst[\ \	]*) \
+		xfail=`expr $$xfail + 1`; \
+		col=$$lgn; res=XFAIL; \
+	      ;; \
+	      *) \
+		failed=`expr $$failed + 1`; \
+		col=$$red; res=FAIL; \
+	      ;; \
+	      esac; \
+	    else \
+	      skip=`expr $$skip + 1`; \
+	      col=$$blu; res=SKIP; \
+	    fi; \
+	    echo "$${col}$$res$${std}: $$tst"; \
+	  done; \
+	  if test "$$all" -eq 1; then \
+	    tests="test"; \
+	    All=""; \
+	  else \
+	    tests="tests"; \
+	    All="All "; \
+	  fi; \
+	  if test "$$failed" -eq 0; then \
+	    if test "$$xfail" -eq 0; then \
+	      banner="$$All$$all $$tests passed"; \
+	    else \
+	      if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \
+	      banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \
+	    fi; \
+	  else \
+	    if test "$$xpass" -eq 0; then \
+	      banner="$$failed of $$all $$tests failed"; \
+	    else \
+	      if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \
+	      banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \
+	    fi; \
+	  fi; \
+	  dashes="$$banner"; \
+	  skipped=""; \
+	  if test "$$skip" -ne 0; then \
+	    if test "$$skip" -eq 1; then \
+	      skipped="($$skip test was not run)"; \
+	    else \
+	      skipped="($$skip tests were not run)"; \
+	    fi; \
+	    test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \
+	      dashes="$$skipped"; \
+	  fi; \
+	  report=""; \
+	  if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \
+	    report="Please report to $(PACKAGE_BUGREPORT)"; \
+	    test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \
+	      dashes="$$report"; \
+	  fi; \
+	  dashes=`echo "$$dashes" | sed s/./=/g`; \
+	  if test "$$failed" -eq 0; then \
+	    col="$$grn"; \
+	  else \
+	    col="$$red"; \
+	  fi; \
+	  echo "$${col}$$dashes$${std}"; \
+	  echo "$${col}$$banner$${std}"; \
+	  test -z "$$skipped" || echo "$${col}$$skipped$${std}"; \
+	  test -z "$$report" || echo "$${col}$$report$${std}"; \
+	  echo "$${col}$$dashes$${std}"; \
+	  test "$$failed" -eq 0; \
+	else :; fi
+
 distdir: $(DISTFILES)
 	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
 	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
@@ -607,8 +729,9 @@ distdir: $(DISTFILES)
 	  fi; \
 	done
 check-am: all-am
+	$(MAKE) $(AM_MAKEFLAGS) check-TESTS
 check: check-am
-all-am: Makefile $(LTLIBRARIES)
+all-am: Makefile $(PROGRAMS)
 installdirs:
 install: install-am
 install-exec: install-exec-am
@@ -642,7 +765,7 @@ maintainer-clean-generic:
 	@echo "it deletes files that may require special tools to rebuild."
 clean: clean-am
 
-clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \
+clean-am: clean-generic clean-libtool clean-noinstPROGRAMS \
 	mostlyclean-am
 
 distclean: distclean-am
@@ -711,11 +834,11 @@ ps-am:
 
 uninstall-am:
 
-.MAKE: install-am install-strip
+.MAKE: check-am install-am install-strip
 
-.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \
-	clean-libtool clean-noinstLTLIBRARIES cscopelist-am ctags \
-	ctags-am distclean distclean-compile distclean-generic \
+.PHONY: CTAGS GTAGS TAGS all all-am check check-TESTS check-am clean \
+	clean-generic clean-libtool clean-noinstPROGRAMS cscopelist-am \
+	ctags ctags-am distclean distclean-compile distclean-generic \
 	distclean-libtool distclean-tags distdir dvi dvi-am html \
 	html-am info info-am install install-am install-data \
 	install-data-am install-dvi install-dvi-am install-exec \
diff --git a/src/dnsmasq-manager/tests/test-dnsmasq-utils.c b/src/dnsmasq-manager/tests/test-dnsmasq-utils.c
new file mode 100644
index 00000000..07dbc0f7
--- /dev/null
+++ b/src/dnsmasq-manager/tests/test-dnsmasq-utils.c
@@ -0,0 +1,115 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ */
+
+#include <glib.h>
+#include <arpa/inet.h>
+
+#include "nm-dnsmasq-utils.h"
+
+static guint32
+addr_to_num (const char *addr)
+{
+	guint n;
+
+	g_assert (inet_pton (AF_INET, addr, (void *) &n) == 1);
+	return n;
+}
+
+static void
+test_address_ranges (void)
+{
+	NMPlatformIP4Address addr;
+	char first[INET_ADDRSTRLEN];
+	char last[INET_ADDRSTRLEN];
+	char *error_desc = NULL;
+
+	addr.address = addr_to_num ("192.168.0.1");
+	addr.plen = 24;
+	g_assert (nm_dnsmasq_utils_get_range (&addr, first, last, &error_desc));
+	g_assert (error_desc == NULL);
+	g_assert_cmpstr (first, ==, "192.168.0.10");
+	g_assert_cmpstr (last, ==, "192.168.0.254");
+
+	addr.address = addr_to_num ("192.168.0.99");
+	addr.plen = 24;
+	g_assert (nm_dnsmasq_utils_get_range (&addr, first, last, &error_desc));
+	g_assert (error_desc == NULL);
+	g_assert_cmpstr (first, ==, "192.168.0.108");
+	g_assert_cmpstr (last, ==, "192.168.0.254");
+
+	addr.address = addr_to_num ("192.168.0.254");
+	addr.plen = 24;
+	g_assert (nm_dnsmasq_utils_get_range (&addr, first, last, &error_desc));
+	g_assert (error_desc == NULL);
+	g_assert_cmpstr (first, ==, "192.168.0.1");
+	g_assert_cmpstr (last, ==, "192.168.0.245");
+
+	/* Smaller networks */
+	addr.address = addr_to_num ("1.2.3.1");
+	addr.plen = 30;
+	g_assert (nm_dnsmasq_utils_get_range (&addr, first, last, &error_desc));
+	g_assert (error_desc == NULL);
+	g_assert_cmpstr (first, ==, "1.2.3.2");
+	g_assert_cmpstr (last, ==, "1.2.3.2");
+
+	addr.address = addr_to_num ("1.2.3.1");
+	addr.plen = 29;
+	g_assert (nm_dnsmasq_utils_get_range (&addr, first, last, &error_desc));
+	g_assert (error_desc == NULL);
+	g_assert_cmpstr (first, ==, "1.2.3.2");
+	g_assert_cmpstr (last, ==, "1.2.3.6");
+
+	addr.address = addr_to_num ("1.2.3.1");
+	addr.plen = 28;
+	g_assert (nm_dnsmasq_utils_get_range (&addr, first, last, &error_desc));
+	g_assert (error_desc == NULL);
+	g_assert_cmpstr (first, ==, "1.2.3.3");
+	g_assert_cmpstr (last, ==, "1.2.3.14");
+
+	addr.address = addr_to_num ("1.2.3.1");
+	addr.plen = 26;
+	g_assert (nm_dnsmasq_utils_get_range (&addr, first, last, &error_desc));
+	g_assert (error_desc == NULL);
+	g_assert_cmpstr (first, ==, "1.2.3.8");
+	g_assert_cmpstr (last, ==, "1.2.3.62");
+
+	addr.address = addr_to_num ("1.2.3.1");
+	addr.plen = 31;
+	g_assert (nm_dnsmasq_utils_get_range (&addr, first, last, &error_desc) == FALSE);
+	g_assert (error_desc);
+	g_free (error_desc);
+}
+
+/*******************************************/
+
+int
+main (int argc, char **argv)
+{
+	g_test_init (&argc, &argv, NULL);
+
+#if !GLIB_CHECK_VERSION (2, 35, 0)
+	g_type_init ();
+#endif
+
+	g_test_add_func ("/dnsmasq-manager/address-ranges", test_address_ranges);
+
+	return g_test_run ();
+}
+