From f6242bdf77b5258d607899a67f6558c73fe47399 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Caletka?= Date: Sun, 30 Nov 2014 18:46:01 +0100 Subject: [PATCH 1/4] aiccu: Minor whitespace fix Signed-off-by: Ondrej Caletka --- ipv6/aiccu/files/aiccu.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ipv6/aiccu/files/aiccu.sh b/ipv6/aiccu/files/aiccu.sh index 669e0e257..f38a75c74 100755 --- a/ipv6/aiccu/files/aiccu.sh +++ b/ipv6/aiccu/files/aiccu.sh @@ -31,17 +31,18 @@ proto_aiccu_setup() { echo "username $username" > "$CFGFILE" echo "password $password" >> "$CFGFILE" - echo "ipv6_interface $link" >> "$CFGFILE" + echo "ipv6_interface $link" >> "$CFGFILE" [ -n "$server" ] && echo "server $server" >> "$CFGFILE" [ -n "$protocol" ] && echo "protocol $protocol" >> "$CFGFILE" - [ -n "$tunnelid" ] && echo "tunnel_id $tunnelid" >> "$CFGFILE" - [ -n "$requiretls" ] && echo "requiretls $requiretls" >> "$CFGFILE" - [ "$nat" == 1 ] && echo "behindnat true" >> "$CFGFILE" - [ "$heartbeat" == 1 ] && echo "makebeats true" >> "$CFGFILE" + [ -n "$tunnelid" ] && echo "tunnel_id $tunnelid" >> "$CFGFILE" + [ -n "$requiretls" ] && echo "requiretls $requiretls" >> "$CFGFILE" + [ "$nat" == 1 ] && echo "behindnat true" >> "$CFGFILE" + [ "$heartbeat" == 1 ] && echo "makebeats true" >> "$CFGFILE" [ "$verbose" == 1 ] && echo "verbose true" >> "$CFGFILE" echo "defaultroute false" >> "$CFGFILE" - echo "daemonize true" >> "$CFGFILE" - echo "pidfile $PIDFILE" >> "$CFGFILE" + echo "daemonize true" >> "$CFGFILE" + echo "pidfile $PIDFILE" >> "$CFGFILE" + aiccu start "$CFGFILE" From 4f7b0213d9d75391cc34636a2bcf302164aa410f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Caletka?= Date: Sun, 30 Nov 2014 18:47:58 +0100 Subject: [PATCH 2/4] aiccu: add NTP sync check This check tries to wait for NTP daemon to synchronise clock to lower stratum than 16 before running the aiccu binary. In case timeout (configurable in new option ntpsynctimeout; default is 90 seconds) is reached, the AICCU is run neverrtheless. This makes the new script compliant with some corner case scenarios like not using Busybox NTPd or not using NTPd at all, maintaining maximum out-of-the box functionality. Signed-off-by: Ondrej Caletka --- ipv6/aiccu/files/aiccu.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ipv6/aiccu/files/aiccu.sh b/ipv6/aiccu/files/aiccu.sh index f38a75c74..89c812219 100755 --- a/ipv6/aiccu/files/aiccu.sh +++ b/ipv6/aiccu/files/aiccu.sh @@ -14,8 +14,8 @@ proto_aiccu_setup() { local iface="$2" local link="aiccu-$cfg" - local username password protocol server ip6prefix tunnelid requiretls defaultroute nat heartbeat verbose sourcerouting ip6addr - json_get_vars username password protocol server ip6prefix tunnelid requiretls defaultroute nat heartbeat verbose sourcerouting ip6addr + local username password protocol server ip6prefix tunnelid requiretls defaultroute nat heartbeat verbose sourcerouting ip6addr ntpsynctimeout + json_get_vars username password protocol server ip6prefix tunnelid requiretls defaultroute nat heartbeat verbose sourcerouting ip6addr ntpsynctimeout [ -z "$username" -o -z "$password" ] && { proto_notify_error "$cfg" "MISSING_USERNAME_OR_PASSWORD" @@ -27,6 +27,7 @@ proto_aiccu_setup() { CFGFILE="/var/etc/${link}.conf" PIDFILE="/var/run/${link}.pid" + NTPSTRATUMFILE="/var/run/aiccu_ntp_stratum" mkdir -p /var/run /var/etc echo "username $username" > "$CFGFILE" @@ -43,6 +44,15 @@ proto_aiccu_setup() { echo "daemonize true" >> "$CFGFILE" echo "pidfile $PIDFILE" >> "$CFGFILE" + # By default, wait at most 90 seconds for NTP sync + [ -z "$ntpsynctimeout" ] && ntpsynctimeout=90 + for i in $(seq 1 $ntpsynctimeout); do + [ -f "$NTPSTRATUMFILE" ] && \ + [ "$(cat $NTPSTRATUMFILE)" -lt 16 ] && \ + echo "NTP synced, stratum $(cat $NTPSTRATUMFILE)" && break + [ "$(( $i % 10 ))" -eq 0 ] && echo "Waiting ${i} secs for NTP sync..." + sleep 1 + done aiccu start "$CFGFILE" @@ -99,6 +109,7 @@ proto_aiccu_init_config() { proto_config_add_boolean "nat" proto_config_add_boolean "heartbeat" proto_config_add_boolean "verbose" + proto_config_add_int "ntpsynctimeout" } [ -n "$INCLUDE_ONLY" ] || { From 7c9b5198cdcce3a79d389451206326eacdfc7f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Caletka?= Date: Sun, 30 Nov 2014 18:55:28 +0100 Subject: [PATCH 3/4] aiccu: Issue aiccu stop only when aiccu is running When AICCU is not running, running 'aiccu stop' results in unnecessary communications with SixXS servers. Signed-off-by: Ondrej Caletka --- ipv6/aiccu/files/aiccu.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ipv6/aiccu/files/aiccu.sh b/ipv6/aiccu/files/aiccu.sh index 89c812219..38d8191f5 100755 --- a/ipv6/aiccu/files/aiccu.sh +++ b/ipv6/aiccu/files/aiccu.sh @@ -89,8 +89,12 @@ proto_aiccu_teardown() { local cfg="$1" local link="aiccu-$cfg" CFGFILE="/var/etc/${link}.conf" - - aiccu stop "$CFGFILE" + PIDFILE="/var/run/${link}.pid" + [ -f "$CFGFILE" -a -f "$PIDFILE" ] && { + local pid="$(cat "$PIDFILE")" + [ -d /proc/$pid -a $(cat /proc/$pid/comm) = "aiccu" ] && \ + aiccu stop "$CFGFILE" + } } proto_aiccu_init_config() { From 6f704629524bc32f263b8440d80bbd1b13e3da71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Caletka?= Date: Sun, 30 Nov 2014 18:57:28 +0100 Subject: [PATCH 4/4] aiccu: Add NTP hotplug hook This hook simply writes current stratum to /var/run/aiccu_ntp_stratum, from where it is read by aiccu proto script. Signed-off-by: Ondrej Caletka --- ipv6/aiccu/Makefile | 5 +++-- ipv6/aiccu/files/aiccu.hotplug | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 ipv6/aiccu/files/aiccu.hotplug diff --git a/ipv6/aiccu/Makefile b/ipv6/aiccu/Makefile index bfa8a8320..50839f359 100644 --- a/ipv6/aiccu/Makefile +++ b/ipv6/aiccu/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=aiccu PKG_VERSION:=20070115 -PKG_RELEASE:=11 +PKG_RELEASE:=12 PKG_SOURCE:=$(PKG_NAME)_$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=http://www.sixxs.net/archive/sixxs/aiccu/unix @@ -47,9 +47,10 @@ define Package/aiccu/conffiles endef define Package/aiccu/install - $(INSTALL_DIR) $(1)/usr/sbin $(1)/lib/netifd/proto + $(INSTALL_DIR) $(1)/usr/sbin $(1)/lib/netifd/proto $(1)/etc/hotplug.d/ntp $(INSTALL_BIN) $(PKG_BUILD_DIR)/unix-console/$(PKG_NAME) $(1)/usr/sbin/ $(INSTALL_BIN) ./files/aiccu.sh $(1)/lib/netifd/proto/aiccu.sh + $(INSTALL_DATA) ./files/aiccu.hotplug $(1)/etc/hotplug.d/ntp/10-aiccu endef $(eval $(call BuildPackage,aiccu)) diff --git a/ipv6/aiccu/files/aiccu.hotplug b/ipv6/aiccu/files/aiccu.hotplug new file mode 100644 index 000000000..b52137170 --- /dev/null +++ b/ipv6/aiccu/files/aiccu.hotplug @@ -0,0 +1,3 @@ +#!/bin/sh +NTPSTRATUMFILE="/var/run/aiccu_ntp_stratum" +echo $stratum > "$NTPSTRATUMFILE"