Date: Tue, 30 Sep 2003 18:16:17 +0200 (CEST) From: Roderick van Domburg <roderick@stud187236.mobiel.utwente.nl> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/57407: [patch] Better NTP support for dhclient(8) and friends Message-ID: <200309301616.h8UGGHHr001069@stud187236.mobiel.utwente.nl> Resent-Message-ID: <200309301620.h8UGKCBO026538@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 57407 >Category: bin >Synopsis: [patch] Better NTP support for dhclient(8) and friends >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Tue Sep 30 09:20:12 PDT 2003 >Closed-Date: >Last-Modified: >Originator: Roderick van Domburg >Release: FreeBSD 5.1-CURRENT sparc64 >Organization: University of Twente >Environment: System: FreeBSD stud187236.mobiel.utwente.nl 5.1-CURRENT FreeBSD 5.1-CURRENT #0: Tue Sep 30 16:56:52 CEST 2003 roderick@stud187236.mobiel.utwente.nl:/usr/obj/usr/src/sys/E250 sparc64 >Description: This patch adds support to dhclient(8) and friends to automatically write out an appropriate /etc/ntp.conf if a NTP server was supplied by the DHCP server, querying for NTP servers by default. The changes in functionality are fully reflected in the man pages. I believe these feature changes to be justified, since ntpd is an integral part of the FreeBSD base system. The changes are transparent to nearly all users. It eases the task of configuration and better suits FreeBSD to NTP-enabled environments. This behavior already is exhibited by the PhysTech DHCP client that is the default client on many Linux distributions. I have contacted the ISC DHCP development team asking them to include this functionality upstream. Without commenting on the quality of this patch, however, they preferred a far more complex and extensible system rather than including operating system-dependent implementations. So far, no one at ISC has taken this task upon himself and it is unlikely that it will appear anytime soon if at all. I would be more than happy to maintain this patch for future ISC DHCP imports. >How-To-Repeat: >Fix: --- isc-dhcp-ntp.patch begins here --- diff -ru /usr/src/contrib/isc-dhcp/client/clparse.c /home/roderick/src/contrib/isc-dhcp/client/clparse.c --- /usr/src/contrib/isc-dhcp/client/clparse.c Sat Sep 6 11:17:42 2003 +++ /home/roderick/src/contrib/isc-dhcp/client/clparse.c Tue Sep 30 17:37:01 2003 @@ -63,6 +63,7 @@ DHO_DOMAIN_NAME, DHO_DOMAIN_NAME_SERVERS, DHO_HOST_NAME, + DHO_NTP_SERVERS, 0 }; diff -ru /usr/src/contrib/isc-dhcp/client/dhclient-script.8 /home/roderick/src/contrib/isc-dhcp/client/dhclient-script.8 --- /usr/src/contrib/isc-dhcp/client/dhclient-script.8 Thu Jan 16 08:23:57 2003 +++ /home/roderick/src/contrib/isc-dhcp/client/dhclient-script.8 Tue Sep 30 18:03:36 2003 @@ -53,9 +53,11 @@ This script is not meant to be customized by the end user. If local customizations are needed, they should be possible using the enter and exit hooks provided (see HOOKS for details). These hooks will allow the -user to override the default behaviour of the client in creating a +user to override the default behaviour of the client in creating .B /etc/resolv.conf -file. +and +.B /etc/ntp.conf +files. .PP No standard client script exists for some operating systems, even though the actual client may work, so a pioneering user may well need to create @@ -67,15 +69,19 @@ .B ETCDIR/dhclient.conf or using the enter and exit hooks, please submit a bug report. .SH HOOKS -When it starts, the client script first defines a shell function, -.B make_resolv_conf , -which is later used to create the +When it starts, the client script first defines two shell functions - +.B make_resolv_conf +and +.B make_ntp_conf +- which are later used to create the .B /etc/resolv.conf -file. To override the default behaviour, redefine this function in -the enter hook script. +and +.B /etc/ntp.conf +files respectively. To override the default behaviour, redefine this +function in the enter hook script. .PP -On after defining the make_resolv_conf function, the client script checks -for the presence of an executable +On after defining the make_resolv_conf and make_ntp_conf functions, the +client script checks for the presence of an executable .B ETCDIR/dhclient-enter-hooks script, and if present, it invokes the script inline, using the Bourne shell '.' command. The entire environment documented under OPERATION @@ -147,7 +153,8 @@ $new_domain_name_servers (which may list more than one server, separated by spaces). A default route should be set using $new_routers, and static routes may need to be set up using -$new_static_routes. +$new_static_routes. In addition, a new /etc/ntp.conf is written out +if $new_ntp_servers contains one or more server entries. .PP If an IP alias has been declared, it must be set up here. The alias IP address will be written as $alias_ip_address, and other DHCP @@ -213,7 +220,7 @@ repeatedly initialized to the values provided by one server, and then the other. Assuming the information provided by both servers is valid, this shouldn't cause any real problems, but it could be -confusing. +confusing. The same goes for /etc/ntp.conf. .SH SEE ALSO dhclient.conf(5), dhclient.leases(5), dhclient(8). .SH AUTHOR diff -ru /usr/src/contrib/isc-dhcp/client/dhclient.conf.5 /home/roderick/src/contrib/isc-dhcp/client/dhclient.conf.5 --- /usr/src/contrib/isc-dhcp/client/dhclient.conf.5 Sat Sep 6 11:17:42 2003 +++ /home/roderick/src/contrib/isc-dhcp/client/dhclient.conf.5 Tue Sep 30 17:37:01 2003 @@ -195,7 +195,7 @@ options. Only the option names should be specified in the request statement - not option parameters. By default, the DHCP server requests the subnet-mask, broadcast-address, time-offset, routers, -domain-name, domain-name-servers and host-name options. +domain-name, domain-name-servers, host-name and ntp-servers options. .PP In some cases, it may be desirable to send no parameter request list at all. To do this, simply write the request statement but specify diff -ru /usr/src/contrib/isc-dhcp/client/scripts/freebsd /home/roderick/src/contrib/isc-dhcp/client/scripts/freebsd --- /usr/src/contrib/isc-dhcp/client/scripts/freebsd Tue Sep 16 03:44:08 2003 +++ /home/roderick/src/contrib/isc-dhcp/client/scripts/freebsd Tue Sep 30 17:37:01 2003 @@ -29,6 +29,25 @@ fi } +make_ntp_conf() { + if [ x"$new_ntp_servers" != x ]; then + ( echo restrict default noquery notrust nomodify >/etc/ntp.conf ) + exit_status=$? + if [ $exit_status -ne 0 ]; then + $LOGGER "WARNING: Unable to update ntp.conf: Error $exit_status" + else + ( echo restrict 127.0.0.1 >>/etc/ntp.conf ) + for ntpserver in $new_ntp_servers; do + ( echo restrict $ntpserver >>/etc/resolv.conf ) + done + for ntpserver in $new_ntp_servers; do + ( echo server $ntpserver >>/etc/resolv.conf ) + done + ( echo driftfile /etc/ntp.drift >>/etc/resolv.conf ) + fi + fi +} + # Must be used on exit. Invokes the local dhcp client exit hooks, if any. exit_with_hooks() { exit_status=$1 @@ -157,6 +176,7 @@ route add $alias_ip_address 127.0.0.1 fi make_resolv_conf + make_ntp_conf exit_with_hooks 0 fi @@ -221,6 +241,7 @@ shift; shift done make_resolv_conf + make_ntp_conf exit_with_hooks 0 fi fi --- isc-dhcp-ntp.patch ends here --- >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200309301616.h8UGGHHr001069>