[CFR] reflect resolv.conf update to running application

Matthew N. Dodd mdodd at FreeBSD.ORG
Wed Sep 14 06:20:50 PDT 2005


On Thu, 8 Sep 2005, Brooks Davis wrote:
> I've looked this over and while I like the concept, I think the
> implementation could be improved.  First, it looks like named.conf has
> an include directive what is conveniently undocumented in the manpage,
> but in the BIND 9 Administrator Reference Manual at:
>
> http://www.bind9.net/manual/bind/9.3.1/Bv9ARM.ch06.html#AEN1534
>
> so if it actually works, we should use that instead of rebuiling the
> config file each time.  Second, the forwarders file should default to
> living in the /var/run of the named chroot since we default to chrooted
> operation these day.  Third, I think we need to kick the server with
> "rndc reconfig" once the file is updated.

Attached.

-- 
10 40 80 C0 00 FF FF FF FF C0 00 00 00 00 10 AA AA 03 00 00 00 08 00
-------------- next part --------------
Index: etc/defaults/rc.conf
===================================================================
RCS file: /home/cvs/src/etc/defaults/rc.conf,v
retrieving revision 1.259
diff -u -u -r1.259 rc.conf
--- etc/defaults/rc.conf	24 Aug 2005 16:25:47 -0000	1.259
+++ etc/defaults/rc.conf	14 Sep 2005 12:59:22 -0000
@@ -93,6 +93,10 @@
 nisdomainname="NO"		# Set to NIS domain if using NIS (or NO).
 dhclient_program="/sbin/dhclient"	# Path to dhcp client program.
 dhclient_flags=""		# Additional flags to pass to dhcp client.
+dhclient_script_resolv_conf="YES"	# Update /etc/resolv.conf
+dhclient_script_forwarders_file="/var/named/var/run/named/forwarders"
+dhclient_script_named_forwarders="NO"	# Update /var/named/var/run/named/forwarders
+					# and reload the nameserver
 background_dhclient="NO"	# Start dhcp client in the background.
 firewall_enable="NO"		# Set to YES to enable firewall functionality
 firewall_script="/etc/rc.firewall" # Which script to run to set up the firewall
Index: etc/namedb/named.conf
===================================================================
RCS file: /home/cvs/src/etc/namedb/named.conf,v
retrieving revision 1.22
diff -u -u -r1.22 named.conf
--- etc/namedb/named.conf	5 Sep 2005 13:42:22 -0000	1.22
+++ etc/namedb/named.conf	14 Sep 2005 13:14:49 -0000
@@ -30,6 +30,14 @@
 //
 //      forward only;
 
+//
+// If you wish to run a local caching nameserver and direct queries to
+// the nameservers configured by dhclient(8), see the 
+// dhclient_script_resolv_conf and dhclient_script_named_forwarders 
+// settings in rc.conf and uncomment the following line.
+//
+//	include "/var/run/named/forwarders";
+
 // If you've got a DNS server around at your upstream provider, enter
 // its IP address here, and enable the line below.  This will make you
 // benefit from its cache, thus reduce overall DNS traffic in the Internet.
Index: sbin/dhclient/dhclient-script
===================================================================
RCS file: /home/cvs/src/sbin/dhclient/dhclient-script,v
retrieving revision 1.10
diff -u -u -r1.10 dhclient-script
--- sbin/dhclient/dhclient-script	8 Sep 2005 22:49:17 -0000	1.10
+++ sbin/dhclient/dhclient-script	14 Sep 2005 13:15:31 -0000
@@ -19,6 +19,9 @@
 #
 #
 
+. /etc/rc.subr
+load_rc_config dhclient-script
+
 NETSTAT=/usr/bin/netstat
 AWK=/usr/bin/awk
 HOSTNAME=/bin/hostname
@@ -127,6 +130,26 @@
 	fi
 }
 
+make_named_forwarders() {
+	if [ -z "$new_domain_name_servers" ]; then
+		return 1
+	fi
+
+	rm -f ${dhclient_script_forwarders_file}.$$
+	echo "	forward only;" > ${dhclient_script_forwarders_file}.$$
+	echo "	forwarders {" > ${dhclient_script_forwarders_file}.$$
+	for nameserver in $new_domain_name_servers; do
+		echo "		$nameserver;" >> ${dhclient_script_forwarders_file}.$$
+	done
+	echo "	};" >> ${dhclient_script_forwarders_file}.$$
+
+	mv ${dhclient_script_forwarders_file}.$$ ${dhclient_script_forwarders_file}
+
+	/usr/sbin/rndc reconfig
+
+	return 0
+}
+
 add_new_resolv_conf() {
 	# XXX Old code did not create/update resolv.conf unless both
 	# $new_domain_name and $new_domain_name_servers were provided.  PR
@@ -248,7 +271,12 @@
 	if [ "$new_ip_address" != "$alias_ip_address" ]; then
 		add_new_alias
 	fi
-	add_new_resolv_conf
+	if checkyesno dhclient_script_resolv_conf; then
+		add_new_resolv_conf
+	fi
+	if checkyesno dhclient_script_named_forwarders; then
+		make_named_forwarders
+	fi
 	;;
 
 EXPIRE|FAIL)
@@ -277,8 +305,13 @@
 				add_new_alias
 			fi
 			add_new_routes
-			if add_new_resolv_conf; then
-				exit_with_hooks 0
+			if checkyesno dhclient_script_named_forwarders; then
+				make_named_forwarders
+			fi
+			if checkyesno dhclient_script_resolv_conf; then
+				if add_new_resolv_conf; then
+					exit_with_hooks 0
+				fi
 			fi
 		fi
 	fi


More information about the freebsd-arch mailing list