[patch] Out of the box NTP support (on FreeBSD)
Roderick van Domburg
r.s.a.vandomburg at student.utwente.nl
Mon Aug 4 23:29:37 UTC 2003
Hello there,
The attached patches bring better NTP support to FreeBSD. Porting it to
other platforms would be a simple matter of editing the relevant client
scripts.
It also fixes an existing typo in the the dhcp-options man page, and
updates it to document the new behavior.
What it does:
* Query for NTP servers by default
* If returned, write out an appropriate /etc/ntp.conf
This is the same behavior as exhibited by the PhysTech dhcpcd.
This patch is appropriate for FreeBSD as it comes with ntpd by default;
so these patches make its use more seamless. Even on other platforms
that might not carry it by default, the feature is helpful still should
the administrator choose to install ntpd.
Thanks in advance for considering these patches. I attached them so they
would not get truncated.
Regards,
Roderick
-- Attached file included as plaintext by Ecartis --
-- File: freebsd-ntp-patches
diff -r -u /usr/src/contrib/isc-dhcp/client/clparse.c isc-dhcp/client/clparse.c
--- /usr/src/contrib/isc-dhcp/client/clparse.c Tue May 6 00:49:22 2003
+++ isc-dhcp/client/clparse.c Tue Aug 5 00:48:52 2003
@@ -63,6 +63,7 @@
DHO_DOMAIN_NAME,
DHO_DOMAIN_NAME_SERVERS,
DHO_HOST_NAME,
+ DHO_NTP_SERVERS,
0
};
diff -r -u /usr/src/contrib/isc-dhcp/client/dhclient.conf.5 isc-dhcp/client/dhclient.conf.5
--- /usr/src/contrib/isc-dhcp/client/dhclient.conf.5 Thu Jan 16 08:31:49 2003
+++ isc-dhcp/client/dhclient.conf.5 Tue Aug 5 01:03:49 2003
@@ -193,9 +193,9 @@
The request statement causes the client to request that any server
responding to the client send the client its values for the specified
options. Only the option names should be specified in the request
-statement - not option parameters. By default, the DHCP server
+statement - not option parameters. By default, the DHCP client
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 -r -u /usr/src/contrib/isc-dhcp/client/scripts/freebsd isc-dhcp/client/scripts/freebsd
--- /usr/src/contrib/isc-dhcp/client/scripts/freebsd Tue Jul 29 00:25:20 2003
+++ isc-dhcp/client/scripts/freebsd Tue Aug 5 00:48:52 2003
@@ -29,6 +29,30 @@
fi
}
+make_ntp_conf() {
+ if [ x"$new_ntp_servers" != x ]; then
+ ( echo restrict default noquery notrust nomodify >/etc/ntp.conf )
+ exit_status=$?
+ else
+ ( rm /etc/ntp.conf )
+ exit_status=$?
+ fi
+ if [ $exit_status -ne 0 ]; then
+ $LOGGER "WARNING: Unable to update ntp.conf: Error $exit_status"
+ else
+ if [ x$new_ntp_servers != x ]; then
+ ( echo restrict 127.0.0.1 >>/etc/ntp.conf )
+ for ntpserver in $new_ntp_servers; do
+ ( echo restrict $ntpserver >>/etc/ntp.conf )
+ done
+ for ntpserver in $new_ntp_servers; do
+ ( echo server $ntpserver >>/etc/ntp.conf )
+ done
+ ( echo driftfile /var/db/ntp.drift >>/etc/ntp.conf )
+ fi
+ fi
+}
+
# Must be used on exit. Invokes the local dhcp client exit hooks, if any.
exit_with_hooks() {
exit_status=$1
@@ -153,6 +177,7 @@
route add $alias_ip_address 127.0.0.1
fi
make_resolv_conf
+ make_ntp_conf
exit_with_hooks 0
fi
@@ -215,6 +240,7 @@
shift; shift
done
make_resolv_conf
+ make_ntp_conf
exit_with_hooks 0
fi
fi
More information about the dhcp-hackers
mailing list