From 449ad56fb5a46aeddbb0dcff7c82e7285cee17e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Caletka?= Date: Mon, 23 Jun 2014 11:05:01 +0200 Subject: [PATCH] aiccu: integrate with netifd This patch integrates AICCU with netifd. Care was taken not to restart aiccu without a reason as it triggers alert on SixXS infrastructure. Example usage: config interface 'wan6' option 'proto' 'aiccu' option 'username' 'HANDLE-SIXXS/TID' option 'password' 'Password' option 'ip6prefix' '2001:db8:aabb::/48' #Delegated subnet option 'ip6addr' '2001:db8:aaaa:aaa::2/64' #Optional option 'verbose' 'true' Tested with current trunk on TL-WR703N. Signed-off-by: Ondrej Caletka --- ipv6/aiccu/Makefile | 5 +- ipv6/aiccu/files/aiccu.sh | 105 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 2 deletions(-) create mode 100755 ipv6/aiccu/files/aiccu.sh diff --git a/ipv6/aiccu/Makefile b/ipv6/aiccu/Makefile index d0ead0317..fe1f162dd 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:=10 +PKG_RELEASE:=11 PKG_SOURCE:=$(PKG_NAME)_$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=http://www.sixxs.net/archive/sixxs/aiccu/unix @@ -45,8 +45,9 @@ define Package/aiccu/conffiles endef define Package/aiccu/install - $(INSTALL_DIR) $(1)/usr/sbin + $(INSTALL_DIR) $(1)/usr/sbin $(1)/lib/netifd/proto $(INSTALL_BIN) $(PKG_BUILD_DIR)/unix-console/$(PKG_NAME) $(1)/usr/sbin/ + $(INSTALL_BIN) ./files/aiccu.sh $(1)/lib/netifd/proto/aiccu.sh endef $(eval $(call BuildPackage,aiccu)) diff --git a/ipv6/aiccu/files/aiccu.sh b/ipv6/aiccu/files/aiccu.sh new file mode 100755 index 000000000..4340b2f4e --- /dev/null +++ b/ipv6/aiccu/files/aiccu.sh @@ -0,0 +1,105 @@ +#!/bin/sh +# aiccu.sh - AICCU proto +# Copyright (c) 2014 OpenWrt.org + +[ -n "$INCLUDE_ONLY" ] || { + . /lib/functions.sh + . /lib/functions/network.sh + . ../netifd-proto.sh + init_proto "$@" +} + +proto_aiccu_setup() { + local cfg="$1" + 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 + + [ -z "$username" -o -z "$password" ] && { + proto_notify_error "$cfg" "MISSING_USERNAME_OR_PASSWORD" + proto_block_restart "$cfg" + return + } + + ( proto_add_host_dependency "$cfg" 0.0.0.0 ) + + CFGFILE="/var/etc/${link}.conf" + PIDFILE="/var/run/${link}.pid" + mkdir -p /var/run /var/etc + + echo "username $username" > "$CFGFILE" + echo "password $password" >> "$CFGFILE" + echo "ipv6_interface $link" >> "$CFGFILE" + [ -n "$server" ] && echo "server $server" >> "$CFGFILE" + [ -n "$protocol" ] && echo "protocol $protocol" >> "$CFGFILE" + [ -n "$tunnel_id" ] && echo "tunnel_id $tunnel_id" >> "$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" + + aiccu start "$CFGFILE" + + [ "$?" -ne 0 ] && { + proto_notify_error "$cfg" "AICCU_FAILED_SEE_LOG" + proto_block_restart "$cfg" + return + } + + proto_init_update "$link" 1 + + local source="" + [ "$sourcerouting" != "0" ] && source="::/128" + [ "$defaultroute" != "0" ] && proto_add_ipv6_route "::" 0 "" "" "" "$source" + + [ -n "$ip6addr" ] && { + local local6="${ip6addr%%/*}" + local mask6="${ip6addr##*/}" + [[ "$local6" = "$mask6" ]] && mask6= + proto_add_ipv6_address "$local6" "$mask6" + [ "$defaultroute" != "0" -a "$sourcerouting" != "0" ] && proto_add_ipv6_route "::" 0 "" "" "" "$local6/$mask6" + } + + [ -n "$ip6prefix" ] && { + proto_add_ipv6_prefix "$ip6prefix" + [ "$defaultroute" != "0" -a "$sourcerouting" != "0" ] && proto_add_ipv6_route "::" 0 "" "" "" "$ip6prefix" + } + + proto_send_update "$cfg" + +} + +proto_aiccu_teardown() { + local cfg="$1" + local link="aiccu-$cfg" + CFGFILE="/var/etc/${link}.conf" + + aiccu stop "$CFGFILE" +} + +proto_aiccu_init_config() { + no_device=1 + available=1 + proto_config_add_string "username" + proto_config_add_string "password" + proto_config_add_string "protocol" + proto_config_add_string "server" + proto_config_add_string "ip6addr:ip6addr" + proto_config_add_string "ip6prefix:ip6addr" + proto_config_add_string "tunnelid" + proto_config_add_boolean "requiretls" + proto_config_add_boolean "defaultroute" + proto_config_add_boolean "sourcerouting" + proto_config_add_boolean "nat" + proto_config_add_boolean "heartbeat" + proto_config_add_boolean "verbose" +} + +[ -n "$INCLUDE_ONLY" ] || { + add_protocol aiccu +}