Add chrony from (#1388)

git-svn-id: svn://svn.openwrt.org/openwrt/packages@6593 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
florian 2007-03-17 11:34:51 +00:00
parent 7742429af9
commit f052574592
8 changed files with 230 additions and 0 deletions

71
net/chrony/Makefile Normal file
View File

@ -0,0 +1,71 @@
#
# Copyright (C) 2006 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
# $Id: $
include $(TOPDIR)/rules.mk
PKG_NAME:=chrony
PKG_VERSION:=1.21
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:= ftp://chrony.sunsite.dk/projects/chrony/ \
http://chrony.sunsite.dk/download/
PKG_MD5SUM:=84f76a73dff5a3c9e9f11f3c29a4e93b
PKG_CAT:=zcat
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
include $(INCLUDE_DIR)/package.mk
define Package/chrony
SECTION:=net
CATEGORY:=Network
TITLE:=NTP client/server for on-demand connections
DESCRIPTION:=\
A NTP implementation that has been specifically written to work well in the case of an intermittent \
(e.g. dial-on-demand) connection to the network where your NTP servers are.
URL:=http://chrony.sunsite.dk/
MAINTAINER:=Richard Kunze <kunze-openwrt-chrony@tivano.de>
DEPENDS:=uclibc libreadline libncurses
endef
define Package/chrony/conffiles
/etc/chrony/chrony.conf
endef
define Build/Configure
$(call Build/Configure/Default, \
--target=$(GNU_TARGET_NAME) \
--prefix=/usr \
--with-readline-includes=$(STAGING_DIR)/usr/include \
--with-readline-library=$(STAGING_DIR)/usr/lib \ )
endef
define Build/Compile
$(MAKE) -C $(PKG_BUILD_DIR) \
$(TARGET_CONFIGURE_OPTS) \
prefix="$(PKG_INSTALL_DIR)/usr"
endef
define Package/chrony/install
$(INSTALL_DIR) $(1)/usr/bin/
$(INSTALL_DIR) $(1)/usr/sbin/
$(INSTALL_BIN) $(PKG_BUILD_DIR)/chronyd $(1)$(PKG_INSTALL_DIR)/usr/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/chronyc $(1)$(PKG_INSTALL_DIR)/usr/bin
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_DIR) $(1)/etc/chrony
$(INSTALL_DIR) $(1)/etc/hotplug.d/iface
$(INSTALL_BIN) ./files/ntpd.hotplug $(1)/etc/hotplug.d/iface/20-ntpd
$(INSTALL_BIN) ./files/ntpd.init $(1)/etc/init.d/ntpd
$(INSTALL_CONF) ./files/ntpd.config $(1)/etc/config/ntpd
$(INSTALL_CONF) ./files/chrony.conf $(1)/etc/chrony/chrony.conf
$(INSTALL_CONF) ./files/chrony.keys $(1)/etc/chrony/chrony.keys
endef
$(eval $(call BuildPackage,chrony))

View File

@ -0,0 +1,17 @@
# Chrony configuration
# Note: time servers and ntp client access is configured in /etc/config/ntpd
# and automatically set at startup
# Log clock errors above 0.5 seconds
logchange 0.5
# Allow command access only from localhost
cmdallow localhost
cmddeny
# Password config for chronyc
# Note: Using a command key other than "1" will break
# /etc/init.d/ntpd and /etc/hotplug.d/iface/20-ntpd
keyfile /etc/chrony/chrony.keys
commandkey 1

View File

@ -0,0 +1 @@
1 chronyc

View File

@ -0,0 +1,6 @@
# Generic NTP configuration
# Time servers and network(s) that may access the time service
config ntpd
option TimeServers "0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org 3.pool.ntp.org"
option ClientAccessFrom "lan"

View File

@ -0,0 +1,21 @@
COMMAND=/usr/bin/chronyc
CHRONY_KEY=$(awk '/^1 / { print $2; }' /etc/chrony/chrony.keys)
chrony_control() {
$COMMAND << EOF
password $CHRONY_KEY
$1
EOF
}
[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
[ -x $COMMAND ] && [ -n "$CHRONY_KEY" ] &&{
chrony_control online
}
}
[ "$ACTION" = "ifdown" -a "$INTERFACE" = "wan" ] && {
[ -x $COMMAND ] && [ -n "$CHRONY_KEY" ] &&{
chrony_control offline
}
}

View File

@ -0,0 +1,69 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org
START=60
start() {
[ ! -f /var/run/chronyd.pid ] && (
/usr/sbin/chronyd -f /etc/chrony/chrony.conf
local NTP_SERVERS
local NTP_SERVER
local CLIENT_NETWORKS
local NETNAME
config_load ntpd
config_get NTP_SERVERS cfg1 TimeServers
config_get CLIENT_NETWORKS cfg1 ClientAccessFrom
CHRONY_KEY=$(awk '/^1 / { print $2; }' /etc/chrony/chrony.keys)
include /lib/network
scan_interfaces
# Define servers and do a rapid series of time measurements
# to get up to date
(
echo password $CHRONY_KEY
for NTP_SERVER in $NTP_SERVERS; do
echo add server $NTP_SERVER
done
echo burst 5/5
) | chronyc > /dev/null 2>&1
# ... wait until a reference ID is found ...
while chronyc tracking | grep 'Reference ID.*0.0.0.0' >/dev/null ; do sleep 1; done
# ... and finally, adjust the time in a single step
# and allow clients to access the server
(
echo password $CHRONY_KEY
echo makestep
for NETNAME in $CLIENT_NETWORKS; do
local INTERFACE
local IP
local NETMASK
local BROADCAST
local NETWORK
local PREFIX
config_get INTERFACE "$NETNAME" ifname
if [ -n "$INTERFACE" ] ; then
eval $(ifconfig $INTERFACE | grep inet | sed -e 's/.*addr:/IP=/' -e 's/ .*Mask:/; NETMASK=/')
eval $(ipcalc $IP $NETMASK)
echo allow $NETWORK/$PREFIX
fi
done
) | chronyc > /dev/null 2>&1
)
}
stop() {
[ -r /var/run/chronyd.pid ] && PID=$(cat /var/run/chronyd.pid)
[ -n "$PID" ] && kill $PID
}
restart() {
stop
while [ -r /var/run/chronyd.pid ] ; do sleep 1; done
start
}

View File

@ -0,0 +1,26 @@
diff -ru chrony-1.21.orig/configure chrony-1.21/configure
--- chrony-1.21.orig/configure 2005-08-11 22:32:54.000000000 +0200
+++ chrony-1.21/configure 2006-08-08 22:24:39.000000000 +0200
@@ -185,6 +185,13 @@
--prefix=* | --install_prefix=* )
INSTALL_PREFIX=`echo $option | sed -e 's/[^=]*=//;'`
;;
+ --target=* )
+ TARGET=`echo $option | sed -e 's/[^=]*=//;'`
+ OPERATINGSYSTEM=`echo $TARGET | sed -e 's/.*-//;'`
+ MACHINE=`echo $TARGET | sed -e 's/-.*//;'`
+ VERSION=""
+ SYSTEM=${OPERATINGSYSTEM}-${MACHINE}
+ ;;
--trace )
EXTRA_DEFS="-DTRACEON"
;;
@@ -237,7 +244,7 @@
;;
esac
;;
- Linux* )
+ Linux* | linux* )
EXTRA_OBJECTS="sys_linux.o wrap_adjtimex.o rtc_linux.o"
SYSDEFS="-DLINUX"
echo "Configuring for " $SYSTEM

View File

@ -0,0 +1,19 @@
diff -ru chrony-1.21.orig/io_linux.h chrony-1.21/io_linux.h
--- chrony-1.21.orig/io_linux.h 2005-08-11 22:32:54.000000000 +0200
+++ chrony-1.21/io_linux.h 2006-08-08 22:24:43.000000000 +0200
@@ -24,6 +24,15 @@
#define CHRONY_IOC_NONE 1U
#define CHRONY_IOC_READ 2U
#define CHRONY_IOC_WRITE 4U
+#elif defined(__mips__)
+#define CHRONY_IOC_NRBITS 8
+#define CHRONY_IOC_TYPEBITS 8
+#define CHRONY_IOC_SIZEBITS 13
+#define CHRONY_IOC_DIRBITS 3
+
+#define CHRONY_IOC_NONE 1U
+#define CHRONY_IOC_READ 2U
+#define CHRONY_IOC_WRITE 4U
#else
#error "I don't know the values of the _IOC_* constants for your architecture"
#endif