Blame SOURCES/bind99-automatic-interface-scanning-rh1294506.patch

310562
From 5013230b31da1d94ce5682e5c5c38011da744971 Mon Sep 17 00:00:00 2001
310562
From: Tomas Hozza <thozza@redhat.com>
310562
Date: Wed, 11 May 2016 15:17:55 +0200
310562
Subject: [PATCH] Added support for automatic interface scan when new address
310562
 is assigned to any interface
310562
310562
Signed-off-by: Tomas Hozza <thozza@redhat.com>
310562
---
310562
 bin/named/config.c                |   1 +
310562
 bin/named/control.c               |   3 +
310562
 bin/named/include/named/control.h |   1 +
310562
 bin/named/include/named/server.h  |   8 +++
310562
 bin/named/interfacemgr.c          | 144 ++++++++++++++++++++++++++++++++++++++
310562
 bin/named/named.conf.docbook      |   1 +
310562
 bin/named/server.c                |  31 +++++++-
310562
 bin/named/statschannel.c          |   5 ++
310562
 bin/rndc/rndc.c                   |   1 +
310562
 bin/rndc/rndc.docbook             |  12 ++++
310562
 config.h.in                       |  12 ++++
310562
 configure.in                      |   5 +-
310562
 doc/arm/Bv9ARM-book.xml           |  22 +++++-
310562
 lib/isc/include/isc/socket.h      |  10 ++-
310562
 lib/isc/unix/socket.c             |  59 ++++++++++++++++
310562
 lib/isccfg/namedconf.c            |   1 +
310562
 16 files changed, 310 insertions(+), 6 deletions(-)
310562
310562
diff --git a/bin/named/config.c b/bin/named/config.c
310562
index f6d0263..b43c0fc 100644
310562
--- a/bin/named/config.c
310562
+++ b/bin/named/config.c
310562
@@ -52,6 +52,7 @@
310562
 /*% default configuration */
310562
 static char defaultconf[] = "\
310562
 options {\n\
310562
+	automatic-interface-scan yes;\n\
310562
 #	blackhole {none;};\n"
310562
 #ifndef WIN32
310562
 "	coresize default;\n\
310562
diff --git a/bin/named/control.c b/bin/named/control.c
310562
index 06eadce..86fa691 100644
310562
--- a/bin/named/control.c
310562
+++ b/bin/named/control.c
310562
@@ -185,6 +185,9 @@ ns_control_docommand(isccc_sexpr_t *message, isc_buffer_t *text) {
310562
 		   command_compare(command, NS_COMMAND_THAW)) {
310562
 		result = ns_server_freeze(ns_g_server, ISC_FALSE, command,
310562
 					  text);
310562
+	} else if (command_compare(command, NS_COMMAND_SCAN)) {
310562
+		result = ISC_R_SUCCESS;
310562
+		ns_server_scan_interfaces(ns_g_server);
310562
 	} else if (command_compare(command, NS_COMMAND_SYNC)) {
310562
 		result = ns_server_sync(ns_g_server, command, text);
310562
 	} else if (command_compare(command, NS_COMMAND_RECURSING)) {
310562
diff --git a/bin/named/include/named/control.h b/bin/named/include/named/control.h
310562
index d730a83..52ed583 100644
310562
--- a/bin/named/include/named/control.h
310562
+++ b/bin/named/include/named/control.h
310562
@@ -59,6 +59,7 @@
310562
 #define NS_COMMAND_NULL		"null"
310562
 #define NS_COMMAND_NOTIFY	"notify"
310562
 #define NS_COMMAND_VALIDATION	"validation"
310562
+#define NS_COMMAND_SCAN 	"scan"
310562
 #define NS_COMMAND_SIGN 	"sign"
310562
 #define NS_COMMAND_LOADKEYS 	"loadkeys"
310562
 #define NS_COMMAND_ADDZONE	"addzone"
310562
diff --git a/bin/named/include/named/server.h b/bin/named/include/named/server.h
310562
index ff0bfd3..83622f4 100644
310562
--- a/bin/named/include/named/server.h
310562
+++ b/bin/named/include/named/server.h
310562
@@ -37,6 +37,7 @@
310562
 #define NS_EVENTCLASS		ISC_EVENTCLASS(0x4E43)
310562
 #define NS_EVENT_RELOAD		(NS_EVENTCLASS + 0)
310562
 #define NS_EVENT_CLIENTCONTROL	(NS_EVENTCLASS + 1)
310562
+#define NS_EVENT_IFSCAN		(NS_EVENTCLASS + 2)
310562
 
310562
 /*%
310562
  * Name server state.  Better here than in lots of separate global variables.
310562
@@ -114,6 +115,7 @@ struct ns_server {
310562
 	dns_name_t		*session_keyname;
310562
 	unsigned int		session_keyalg;
310562
 	isc_uint16_t		session_keybits;
310562
+	isc_boolean_t		interface_auto;
310562
 };
310562
 
310562
 #define NS_SERVER_MAGIC			ISC_MAGIC('S','V','E','R')
310562
@@ -201,6 +203,12 @@ ns_server_reloadwanted(ns_server_t *server);
310562
  */
310562
 
310562
 void
310562
+ns_server_scan_interfaces(ns_server_t *server);
310562
+/*%<
310562
+ * Trigger a interface scan.
310562
+ */
310562
+
310562
+void
310562
 ns_server_flushonshutdown(ns_server_t *server, isc_boolean_t flush);
310562
 /*%<
310562
  * Inform the server that the zones should be flushed to disk on shutdown.
310562
diff --git a/bin/named/interfacemgr.c b/bin/named/interfacemgr.c
310562
index 4f6b0f3..a9aa4a4 100644
310562
--- a/bin/named/interfacemgr.c
310562
+++ b/bin/named/interfacemgr.c
310562
@@ -33,6 +33,28 @@
310562
 #include <named/client.h>
310562
 #include <named/log.h>
310562
 #include <named/interfacemgr.h>
310562
+#include <named/server.h>
310562
+
310562
+#ifdef HAVE_NET_ROUTE_H
310562
+#include <net/route.h>
310562
+#if defined(RTM_VERSION) && defined(RTM_NEWADDR) && defined(RTM_DELADDR)
310562
+#define USE_ROUTE_SOCKET 1
310562
+#define ROUTE_SOCKET_PROTOCOL PF_ROUTE
310562
+#define MSGHDR rt_msghdr
310562
+#define MSGTYPE rtm_type
310562
+#endif
310562
+#endif
310562
+
310562
+#if defined(HAVE_LINUX_NETLINK_H) && defined(HAVE_LINUX_RTNETLINK_H)
310562
+#include <linux/netlink.h>
310562
+#include <linux/rtnetlink.h>
310562
+#if defined(RTM_NEWADDR) && defined(RTM_DELADDR)
310562
+#define USE_ROUTE_SOCKET 1
310562
+#define ROUTE_SOCKET_PROTOCOL PF_NETLINK
310562
+#define MSGHDR nlmsghdr
310562
+#define MSGTYPE nlmsg_type
310562
+#endif
310562
+#endif
310562
 
310562
 #define IFMGR_MAGIC			ISC_MAGIC('I', 'F', 'M', 'G')
310562
 #define NS_INTERFACEMGR_VALID(t)	ISC_MAGIC_VALID(t, IFMGR_MAGIC)
310562
@@ -55,6 +77,11 @@ struct ns_interfacemgr {
310562
 	dns_aclenv_t		aclenv;		/*%< Localhost/localnets ACLs */
310562
 	ISC_LIST(ns_interface_t) interfaces;	/*%< List of interfaces. */
310562
 	ISC_LIST(isc_sockaddr_t) listenon;
310562
+#ifdef USE_ROUTE_SOCKET
310562
+	isc_task_t *		task;
310562
+	isc_socket_t *		route;
310562
+	unsigned char		buf[2048];
310562
+#endif
310562
 };
310562
 
310562
 static void
310562
@@ -63,6 +90,71 @@ purge_old_interfaces(ns_interfacemgr_t *mgr);
310562
 static void
310562
 clearlistenon(ns_interfacemgr_t *mgr);
310562
 
310562
+#ifdef USE_ROUTE_SOCKET
310562
+static void
310562
+route_event(isc_task_t *task, isc_event_t *event) {
310562
+	isc_socketevent_t *sevent = NULL;
310562
+	ns_interfacemgr_t *mgr = NULL;
310562
+	isc_region_t r;
310562
+	isc_result_t result;
310562
+	struct MSGHDR *rtm;
310562
+
310562
+	UNUSED(task);
310562
+
310562
+	REQUIRE(event->ev_type == ISC_SOCKEVENT_RECVDONE);
310562
+	mgr = event->ev_arg;
310562
+	sevent = (isc_socketevent_t *)event;
310562
+
310562
+	if (sevent->result != ISC_R_SUCCESS) {
310562
+		if (sevent->result != ISC_R_CANCELED)
310562
+			isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_ERROR,
310562
+				      "automatic interface scanning "
310562
+				      "terminated: %s",
310562
+				      isc_result_totext(sevent->result));
310562
+		ns_interfacemgr_detach(&mgr);
310562
+		isc_event_free(&event);
310562
+		return;
310562
+	}
310562
+
310562
+	rtm = (struct MSGHDR *)mgr->buf;
310562
+#ifdef RTM_VERSION
310562
+	if (rtm->rtm_version != RTM_VERSION) {
310562
+		isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_ERROR,
310562
+			      "automatic interface rescanning disabled: "
310562
+			      "rtm->rtm_version mismatch (%u != %u) "
310562
+			      "recompile required", rtm->rtm_version,
310562
+			      RTM_VERSION);
310562
+		isc_task_detach(&mgr->task);
310562
+		isc_socket_detach(&mgr->route);
310562
+		ns_interfacemgr_detach(&mgr);
310562
+		isc_event_free(&event);
310562
+		return;
310562
+	}
310562
+#endif
310562
+
310562
+	switch (rtm->MSGTYPE) {
310562
+	case RTM_NEWADDR:
310562
+	case RTM_DELADDR:
310562
+		if (ns_g_server->interface_auto)
310562
+			ns_server_scan_interfaces(ns_g_server);
310562
+		break;
310562
+	default:
310562
+		break;
310562
+	}
310562
+
310562
+	/*
310562
+	 * Look for next route event.
310562
+	 */
310562
+	r.base = mgr->buf;
310562
+	r.length = sizeof(mgr->buf);
310562
+	result = isc_socket_recv(mgr->route, &r, 1, mgr->task,
310562
+				 route_event, mgr);
310562
+	if (result != ISC_R_SUCCESS)
310562
+		ns_interfacemgr_detach(&mgr);
310562
+	isc_event_free(&event);
310562
+}
310562
+#endif
310562
+
310562
 isc_result_t
310562
 ns_interfacemgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
310562
 		       isc_socketmgr_t *socketmgr,
310562
@@ -112,11 +204,52 @@ ns_interfacemgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
310562
 	mgr->aclenv.geoip = ns_g_geoip;
310562
 #endif
310562
 
310562
+#ifdef USE_ROUTE_SOCKET
310562
+	mgr->route = NULL;
310562
+	result = isc_socket_create(mgr->socketmgr, ROUTE_SOCKET_PROTOCOL,
310562
+				   isc_sockettype_raw, &mgr->route);
310562
+	switch (result) {
310562
+	case ISC_R_NOPERM:
310562
+	case ISC_R_SUCCESS:
310562
+	case ISC_R_NOTIMPLEMENTED:
310562
+	case ISC_R_FAMILYNOSUPPORT:
310562
+	    break;
310562
+	default:
310562
+		goto cleanup_aclenv;
310562
+	}
310562
+
310562
+	mgr->task = NULL;
310562
+	if (mgr->route != NULL) {
310562
+		result = isc_task_create(taskmgr, 0, &mgr->task);
310562
+		if (result != ISC_R_SUCCESS)
310562
+			goto cleanup_route;
310562
+	}
310562
+	mgr->references = (mgr->route != NULL) ? 2 : 1;
310562
+#else
310562
 	mgr->references = 1;
310562
+#endif
310562
 	mgr->magic = IFMGR_MAGIC;
310562
 	*mgrp = mgr;
310562
+
310562
+#ifdef USE_ROUTE_SOCKET
310562
+	if (mgr->route != NULL) {
310562
+		isc_region_t r = { mgr->buf, sizeof(mgr->buf) };
310562
+
310562
+		result = isc_socket_recv(mgr->route, &r, 1, mgr->task,
310562
+					 route_event, mgr);
310562
+		if (result != ISC_R_SUCCESS)
310562
+			ns_interfacemgr_detach(&mgr);
310562
+	}
310562
+#endif
310562
 	return (ISC_R_SUCCESS);
310562
 
310562
+#ifdef USE_ROUTE_SOCKET
310562
+ cleanup_route:
310562
+	if (mgr->route != NULL)
310562
+		isc_socket_detach(&mgr->route);
310562
+ cleanup_aclenv:
310562
+	dns_aclenv_destroy(&mgr->aclenv);
310562
+#endif
310562
  cleanup_listenon:
310562
 	ns_listenlist_detach(&mgr->listenon4);
310562
 	ns_listenlist_detach(&mgr->listenon6);
310562
@@ -128,6 +261,13 @@ ns_interfacemgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
310562
 static void
310562
 ns_interfacemgr_destroy(ns_interfacemgr_t *mgr) {
310562
 	REQUIRE(NS_INTERFACEMGR_VALID(mgr));
310562
+
310562
+#ifdef USE_ROUTE_SOCKET
310562
+	if (mgr->route != NULL)
310562
+		isc_socket_detach(&mgr->route);
310562
+	if (mgr->task != NULL)
310562
+		isc_task_detach(&mgr->task);
310562
+#endif
310562
 	dns_aclenv_destroy(&mgr->aclenv);
310562
 	ns_listenlist_detach(&mgr->listenon4);
310562
 	ns_listenlist_detach(&mgr->listenon6);
310562
@@ -179,6 +319,10 @@ ns_interfacemgr_shutdown(ns_interfacemgr_t *mgr) {
310562
 	 * consider all interfaces "old".
310562
 	 */
310562
 	mgr->generation++;
310562
+#ifdef USE_ROUTE_SOCKET
310562
+	if (mgr->route != NULL)
310562
+		isc_socket_cancel(mgr->route, mgr->task, ISC_SOCKCANCEL_RECV);
310562
+#endif
310562
 	purge_old_interfaces(mgr);
310562
 }
310562
 
310562
diff --git a/bin/named/named.conf.docbook b/bin/named/named.conf.docbook
310562
index 8c23e52..a8cd31e 100644
310562
--- a/bin/named/named.conf.docbook
310562
+++ b/bin/named/named.conf.docbook
310562
@@ -373,6 +373,7 @@ options {
310562
 	zero-no-soa-ttl <replaceable>boolean</replaceable>;
310562
 	zero-no-soa-ttl-cache <replaceable>boolean</replaceable>;
310562
 	dnssec-secure-to-insecure <replaceable>boolean</replaceable>;
310562
+	automatic-interface-scan <replaceable>boolean</replaceable>;
310562
 	deny-answer-addresses {
310562
 		<replaceable>address_match_list</replaceable>
310562
 	} <optional> except-from { <replaceable>namelist</replaceable> } </optional>;
310562
diff --git a/bin/named/server.c b/bin/named/server.c
310562
index 24b31c3..942bab6 100644
310562
--- a/bin/named/server.c
310562
+++ b/bin/named/server.c
310562
@@ -4485,8 +4485,9 @@ adjust_interfaces(ns_server_t *server, isc_mem_t *mctx) {
310562
 }
310562
 
310562
 /*
310562
- * This event callback is invoked to do periodic network
310562
- * interface scanning.
310562
+ * This event callback is invoked to do periodic network interface
310562
+ * scanning.  It is also called by ns_server_scan_interfaces(),
310562
+ * invoked by "rndc scan"
310562
  */
310562
 static void
310562
 interface_timer_tick(isc_task_t *task, isc_event_t *event) {
310562
@@ -4494,7 +4495,14 @@ interface_timer_tick(isc_task_t *task, isc_event_t *event) {
310562
 	ns_server_t *server = (ns_server_t *) event->ev_arg;
310562
 	INSIST(task == server->task);
310562
 	UNUSED(task);
310562
+
310562
+	if (event->ev_type == NS_EVENT_IFSCAN)
310562
+		isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
310562
+			      NS_LOGMODULE_SERVER, ISC_LOG_DEBUG(1),
310562
+			      "automatic interface rescan");
310562
+
310562
 	isc_event_free(&event);
310562
+
310562
 	/*
310562
 	 * XXX should scan interfaces unlocked and get exclusive access
310562
 	 * only to replace ACLs.
310562
@@ -5419,6 +5427,14 @@ load_configuration(const char *filename, ns_server_t *server,
310562
 	server->interface_interval = interface_interval;
310562
 
310562
 	/*
310562
+	 * Enable automatic interface scans.
310562
+	 */
310562
+	obj = NULL;
310562
+	result = ns_config_get(maps, "automatic-interface-scan", &obj);
310562
+	INSIST(result == ISC_R_SUCCESS);
310562
+	server->interface_auto = cfg_obj_asboolean(obj);
310562
+
310562
+	/*
310562
 	 * Configure the dialup heartbeat timer.
310562
 	 */
310562
 	obj = NULL;
310562
@@ -6637,6 +6653,17 @@ ns_server_reloadwanted(ns_server_t *server) {
310562
 	UNLOCK(&server->reload_event_lock);
310562
 }
310562
 
310562
+void
310562
+ns_server_scan_interfaces(ns_server_t *server) {
310562
+	isc_event_t *event;
310562
+
310562
+	event = isc_event_allocate(ns_g_mctx, server, NS_EVENT_IFSCAN,
310562
+				   interface_timer_tick, server,
310562
+				   sizeof(isc_event_t));
310562
+	if (event != NULL)
310562
+		isc_task_send(server->task, &event);
310562
+}
310562
+
310562
 static char *
310562
 next_token(char **stringp, const char *delim) {
310562
 	char *res;
310562
diff --git a/bin/named/statschannel.c b/bin/named/statschannel.c
310562
index 37e98a8..b985f62 100644
310562
--- a/bin/named/statschannel.c
310562
+++ b/bin/named/statschannel.c
310562
@@ -341,6 +341,7 @@ init_desc(void) {
310562
 	SET_SOCKSTATDESC(tcp4open, "TCP/IPv4 sockets opened", "TCP4Open");
310562
 	SET_SOCKSTATDESC(tcp6open, "TCP/IPv6 sockets opened", "TCP6Open");
310562
 	SET_SOCKSTATDESC(unixopen, "Unix domain sockets opened", "UnixOpen");
310562
+	SET_SOCKSTATDESC(rawopen, "Raw sockets opened", "RawOpen");
310562
 	SET_SOCKSTATDESC(udp4openfail, "UDP/IPv4 socket open failures",
310562
 			 "UDP4OpenFail");
310562
 	SET_SOCKSTATDESC(udp6openfail, "UDP/IPv6 socket open failures",
310562
@@ -351,6 +352,8 @@ init_desc(void) {
310562
 			 "TCP6OpenFail");
310562
 	SET_SOCKSTATDESC(unixopenfail, "Unix domain socket open failures",
310562
 			 "UnixOpenFail");
310562
+	SET_SOCKSTATDESC(rawopenfail, "Raw socket open failures",
310562
+			 "RawOpenFail");
310562
 	SET_SOCKSTATDESC(udp4close, "UDP/IPv4 sockets closed", "UDP4Close");
310562
 	SET_SOCKSTATDESC(udp6close, "UDP/IPv6 sockets closed", "UDP6Close");
310562
 	SET_SOCKSTATDESC(tcp4close, "TCP/IPv4 sockets closed", "TCP4Close");
310562
@@ -358,6 +361,7 @@ init_desc(void) {
310562
 	SET_SOCKSTATDESC(unixclose, "Unix domain sockets closed", "UnixClose");
310562
 	SET_SOCKSTATDESC(fdwatchclose, "FDwatch sockets closed",
310562
 			 "FDWatchClose");
310562
+	SET_SOCKSTATDESC(rawclose, "Raw sockets closed", "RawClose");
310562
 	SET_SOCKSTATDESC(udp4bindfail, "UDP/IPv4 socket bind failures",
310562
 			 "UDP4BindFail");
310562
 	SET_SOCKSTATDESC(udp6bindfail, "UDP/IPv6 socket bind failures",
310562
@@ -424,6 +428,7 @@ init_desc(void) {
310562
 			 "UnixRecvErr");
310562
 	SET_SOCKSTATDESC(fdwatchrecvfail, "FDwatch recv errors",
310562
 			 "FDwatchRecvErr");
310562
+	SET_SOCKSTATDESC(rawrecvfail, "Raw recv errors", "RawRecvErr");
310562
 	INSIST(i == isc_sockstatscounter_max);
310562
 
310562
 	/* Initialize DNSSEC statistics */
310562
diff --git a/bin/rndc/rndc.c b/bin/rndc/rndc.c
310562
index 9a007e2..be198b1 100644
310562
--- a/bin/rndc/rndc.c
310562
+++ b/bin/rndc/rndc.c
310562
@@ -160,6 +160,7 @@ command is one of the following:\n\
310562
 		Add zone to given view. Requires new-zone-file option.\n\
310562
   delzone [\"file\"] zone [class [view]]\n\
310562
 		Removes zone from given view. Requires new-zone-file option.\n\
310562
+  scan		Scan available network interfaces for changes.\n\
310562
   signing -list zone [class [view]]\n\
310562
 		List the private records showing the state of DNSSEC\n\
310562
 		signing in the given zone.\n\
310562
diff --git a/bin/rndc/rndc.docbook b/bin/rndc/rndc.docbook
310562
index 1789aaa..5b37b7f 100644
310562
--- a/bin/rndc/rndc.docbook
310562
+++ b/bin/rndc/rndc.docbook
310562
@@ -330,6 +330,18 @@
310562
       </varlistentry>
310562
 
310562
       <varlistentry>
310562
+        <term><userinput>scan</userinput></term>
310562
+        <listitem>
310562
+          <para>
310562
+             Scan the list of available network interfaces
310562
+             for changes, without performing a full
310562
+             <command>reconfig</command> or waiting for the
310562
+             <command>interface-interval</command> timer.
310562
+          </para>
310562
+        </listitem>
310562
+      </varlistentry>
310562
+
310562
+      <varlistentry>
310562
         <term><userinput>sync <optional>-clean</optional> <optional><replaceable>zone</replaceable> <optional><replaceable>class</replaceable> <optional><replaceable>view</replaceable></optional></optional></optional></userinput></term>
310562
         <listitem>
310562
           <para>
310562
diff --git a/config.h.in b/config.h.in
310562
index 6ed8381..3515f69 100644
310562
--- a/config.h.in
310562
+++ b/config.h.in
310562
@@ -280,6 +280,12 @@ int sigwait(const unsigned int *set, int *sig);
310562
 /* Define to 1 if you have the <linux/capability.h> header file. */
310562
 #undef HAVE_LINUX_CAPABILITY_H
310562
 
310562
+/* Define to 1 if you have the <linux/netlink.h> header file. */
310562
+#undef HAVE_LINUX_NETLINK_H
310562
+
310562
+/* Define to 1 if you have the <linux/rtnetlink.h> header file. */
310562
+#undef HAVE_LINUX_RTNETLINK_H
310562
+
310562
 /* Define to 1 if you have the <linux/types.h> header file. */
310562
 #undef HAVE_LINUX_TYPES_H
310562
 
310562
@@ -295,6 +301,9 @@ int sigwait(const unsigned int *set, int *sig);
310562
 /* Define to 1 if you have the <net/if6.h> header file. */
310562
 #undef HAVE_NET_IF6_H
310562
 
310562
+/* Define to 1 if you have the <net/route.h> header file. */
310562
+#undef HAVE_NET_ROUTE_H
310562
+
310562
 /* Define if your OpenSSL version supports ECDSA. */
310562
 #undef HAVE_OPENSSL_ECDSA
310562
 
310562
@@ -358,6 +367,9 @@ int sigwait(const unsigned int *set, int *sig);
310562
 /* Define to 1 if you have the <sys/select.h> header file. */
310562
 #undef HAVE_SYS_SELECT_H
310562
 
310562
+/* Define to 1 if you have the <sys/socket.h> header file. */
310562
+#undef HAVE_SYS_SOCKET_H
310562
+
310562
 /* Define to 1 if you have the <sys/sockio.h> header file. */
310562
 #undef HAVE_SYS_SOCKIO_H
310562
 
310562
diff --git a/configure.in b/configure.in
310562
index d72093f..38e626d 100644
310562
--- a/configure.in
310562
+++ b/configure.in
310562
@@ -375,11 +375,14 @@ fi
310562
 
310562
 AC_HEADER_STDC
310562
 
310562
-AC_CHECK_HEADERS(fcntl.h regex.h sys/time.h unistd.h sys/sockio.h sys/select.h sys/param.h sys/sysctl.h net/if6.h,,,
310562
+AC_CHECK_HEADERS(fcntl.h regex.h sys/time.h unistd.h sys/sockio.h sys/select.h sys/param.h sys/sysctl.h net/if6.h sys/socket.h net/route.h linux/netlink.h linux/rtnetlink.h,,,
310562
 [$ac_includes_default
310562
 #ifdef HAVE_SYS_PARAM_H
310562
 # include <sys/param.h>
310562
 #endif
310562
+#ifdef HAVE_SYS_SOCKET_H
310562
+# include <sys/socket.h>
310562
+#endif
310562
 ])
310562
 
310562
 AC_C_CONST
310562
diff --git a/doc/arm/Bv9ARM-book.xml b/doc/arm/Bv9ARM-book.xml
310562
index 92c7b72..4c47d92 100644
310562
--- a/doc/arm/Bv9ARM-book.xml
310562
+++ b/doc/arm/Bv9ARM-book.xml
310562
@@ -4964,7 +4964,9 @@ badresp:1,adberr:0,findfail:0,valfail:0]
310562
 	<optional> policy given | disabled | passthru | nxdomain | nodata | cname <replaceable>domain</replaceable> </optional>
310562
 	<optional> recursive-only <replaceable>yes_or_no</replaceable> </optional> <optional> max-policy-ttl <replaceable>number</replaceable> </optional> ;
310562
     } <optional> recursive-only <replaceable>yes_or_no</replaceable> </optional> <optional> max-policy-ttl <replaceable>number</replaceable> </optional>
310562
-	<optional> break-dnssec <replaceable>yes_or_no</replaceable> </optional> <optional> min-ns-dots <replaceable>number</replaceable> </optional> ; </optional>
310562
+    <optional> break-dnssec <replaceable>yes_or_no</replaceable> </optional> <optional> min-ns-dots <replaceable>number</replaceable> </optional>
310562
+      <optional> automatic-interface-scan <replaceable>yes_or_no</replaceable> </optional>
310562
+    ; </optional>
310562
 };
310562
 </programlisting>
310562
 
310562
@@ -5726,6 +5728,23 @@ options {
310562
           <variablelist>
310562
 
310562
             <varlistentry>
310562
+	      <term><command>automatic-interface-scan</command></term>
310562
+	      <listitem>
310562
+		<para>
310562
+		  If <userinput>yes</userinput> and supported by the OS,
310562
+		  automatically rescan network interfaces when the interface
310562
+		  addresses are added or removed.  The default is
310562
+		  <userinput>yes</userinput>.
310562
+		</para>
310562
+		<para>
310562
+		  Currently the OS needs to support routing sockets for
310562
+		  <command>automatic-interface-scan</command> to be
310562
+		  supported.
310562
+		</para>
310562
+	      </listitem>
310562
+	    </varlistentry>
310562
+
310562
+	    <varlistentry>
310562
               <term><command>allow-new-zones</command></term>
310562
               <listitem>
310562
                 <para>
310562
@@ -10494,6 +10513,7 @@ zone <replaceable>zone_name</replaceable> <optional><replaceable>class
310562
     <optional> allow-query-on { <replaceable>address_match_list</replaceable> }; </optional>
310562
     <optional> allow-transfer { <replaceable>address_match_list</replaceable> }; </optional>
310562
     <optional> allow-update-forwarding { <replaceable>address_match_list</replaceable> }; </optional>
310562
+    <optional> automatic-interface-scan { <replaceable>yes_or_no</replaceable> }; </optional>
310562
     <optional> dnssec-update-mode ( <replaceable>maintain</replaceable> | <replaceable>no-resign</replaceable> ); </optional>
310562
     <optional> update-check-ksk <replaceable>yes_or_no</replaceable>; </optional>
310562
     <optional> dnssec-dnskey-kskonly <replaceable>yes_or_no</replaceable>; </optional>
310562
diff --git a/lib/isc/include/isc/socket.h b/lib/isc/include/isc/socket.h
310562
index c5a753a..1cd90bb 100644
310562
--- a/lib/isc/include/isc/socket.h
310562
+++ b/lib/isc/include/isc/socket.h
310562
@@ -150,7 +150,12 @@ enum {
310562
 	isc_sockstatscounter_unixrecvfail = 50,
310562
 	isc_sockstatscounter_fdwatchrecvfail = 51,
310562
 
310562
-	isc_sockstatscounter_max = 52
310562
+	isc_sockstatscounter_rawopen = 52,
310562
+	isc_sockstatscounter_rawopenfail = 53,
310562
+	isc_sockstatscounter_rawclose = 54,
310562
+	isc_sockstatscounter_rawrecvfail = 55,
310562
+
310562
+	isc_sockstatscounter_max = 56
310562
 };
310562
 
310562
 /***
310562
@@ -221,7 +226,8 @@ typedef enum {
310562
 	isc_sockettype_udp = 1,
310562
 	isc_sockettype_tcp = 2,
310562
 	isc_sockettype_unix = 3,
310562
-	isc_sockettype_fdwatch = 4
310562
+	isc_sockettype_fdwatch = 4,
310562
+	isc_sockettype_raw = 5
310562
 } isc_sockettype_t;
310562
 
310562
 /*@{*/
310562
diff --git a/lib/isc/unix/socket.c b/lib/isc/unix/socket.c
310562
index 82d0d16..cbc506b 100644
310562
--- a/lib/isc/unix/socket.c
310562
+++ b/lib/isc/unix/socket.c
310562
@@ -28,6 +28,11 @@
310562
 #include <sys/time.h>
310562
 #include <sys/uio.h>
310562
 
310562
+#if defined(HAVE_LINUX_NETLINK_H) && defined(HAVE_LINUX_RTNETLINK_H)
310562
+#include <linux/netlink.h>
310562
+#include <linux/rtnetlink.h>
310562
+#endif
310562
+
310562
 #include <errno.h>
310562
 #include <fcntl.h>
310562
 #include <stddef.h>
310562
@@ -708,6 +713,18 @@ static const isc_statscounter_t fdwatchstatsindex[] = {
310562
 	isc_sockstatscounter_fdwatchsendfail,
310562
 	isc_sockstatscounter_fdwatchrecvfail
310562
 };
310562
+static const isc_statscounter_t rawstatsindex[] = {
310562
+	isc_sockstatscounter_rawopen,
310562
+	isc_sockstatscounter_rawopenfail,
310562
+	isc_sockstatscounter_rawclose,
310562
+	-1,
310562
+	-1,
310562
+	-1,
310562
+	-1,
310562
+	-1,
310562
+	-1,
310562
+	isc_sockstatscounter_rawrecvfail,
310562
+};
310562
 
310562
 #if defined(USE_KQUEUE) || defined(USE_EPOLL) || defined(USE_DEVPOLL) || \
310562
     defined(USE_WATCHER_THREAD)
310562
@@ -1744,6 +1761,7 @@ doio_recv(isc__socket_t *sock, isc_socketevent_t *dev) {
310562
 			return (DOIO_EOF);
310562
 		break;
310562
 	case isc_sockettype_udp:
310562
+	case isc_sockettype_raw:
310562
 		break;
310562
 	case isc_sockettype_fdwatch:
310562
 	default:
310562
@@ -2306,6 +2324,44 @@ opensocket(isc__socketmgr_t *manager, isc__socket_t *sock,
310562
 		case isc_sockettype_unix:
310562
 			sock->fd = socket(sock->pf, SOCK_STREAM, 0);
310562
 			break;
310562
+		case isc_sockettype_raw:
310562
+			errno = EPFNOSUPPORT;
310562
+			/*
310562
+			 * PF_ROUTE is a alias for PF_NETLINK on linux.
310562
+			 */
310562
+#if defined(PF_ROUTE)
310562
+			if (sock->fd == -1 && sock->pf == PF_ROUTE) {
310562
+#ifdef NETLINK_ROUTE
310562
+				sock->fd = socket(sock->pf, SOCK_RAW,
310562
+						  NETLINK_ROUTE);
310562
+#else
310562
+				sock->fd = socket(sock->pf, SOCK_RAW, 0);
310562
+#endif
310562
+				if (sock->fd != -1) {
310562
+#ifdef NETLINK_ROUTE
310562
+					struct sockaddr_nl sa;
310562
+					int n;
310562
+
310562
+					/*
310562
+					 * Do an implicit bind.
310562
+					 */
310562
+					memset(&sa, 0, sizeof(sa));
310562
+					sa.nl_family = AF_NETLINK;
310562
+					sa.nl_groups = RTMGRP_IPV4_IFADDR |
310562
+						       RTMGRP_IPV6_IFADDR;
310562
+					n = bind(sock->fd,
310562
+						 (struct sockaddr *) &sa,
310562
+						 sizeof(sa));
310562
+					if (n < 0) {
310562
+						close(sock->fd);
310562
+						sock->fd = -1;
310562
+					}
310562
+#endif
310562
+					sock->bound = 1;
310562
+				}
310562
+			}
310562
+ #endif
310562
+			break;
310562
 		case isc_sockettype_fdwatch:
310562
 			/*
310562
 			 * We should not be called for isc_sockettype_fdwatch
310562
@@ -2602,6 +2658,9 @@ socket_create(isc_socketmgr_t *manager0, int pf, isc_sockettype_t type,
310562
 	case isc_sockettype_unix:
310562
 		sock->statsindex = unixstatsindex;
310562
 		break;
310562
+	case isc_sockettype_raw:
310562
+		sock->statsindex = rawstatsindex;
310562
+		break;
310562
 	default:
310562
 		INSIST(0);
310562
 	}
310562
diff --git a/lib/isccfg/namedconf.c b/lib/isccfg/namedconf.c
310562
index f5ff8e3..f49ff70 100644
310562
--- a/lib/isccfg/namedconf.c
310562
+++ b/lib/isccfg/namedconf.c
310562
@@ -931,6 +931,7 @@ bindkeys_clauses[] = {
310562
  */
310562
 static cfg_clausedef_t
310562
 options_clauses[] = {
310562
+	{ "automatic-interface-scan", &cfg_type_boolean, 0 },
310562
 	{ "avoid-v4-udp-ports", &cfg_type_bracketed_portlist, 0 },
310562
 	{ "avoid-v6-udp-ports", &cfg_type_bracketed_portlist, 0 },
310562
 	{ "bindkeys-file", &cfg_type_qstring, 0 },
310562
-- 
310562
2.5.5
310562