This patch: * Replaces the mess the config file generation was with a bunch of helper routines.
* Makes absent boolean config options use the aiccu internal defaults like for the strings. These options are commented out in the config per default. * Ensures that the generated config file has mode 600. I know that OpenWrt is normally not a multiuser system but we've got passwords in there, better safe than sorry. * Records for each (probably only one) running aiccu the state in /var/state and stops the tunnels based on that. This avoids weird errors when you change your config and then try to restart aiccu. * Replaces config_cb with config_foreach which makes the file a lot better to understand for non-pros like >me. * Adds a name to the section in the default config file so the files in /var/run have a nicer name. Maybe the files should be named based on the interface name instead but I didn't find a clean way to implement this. Signed-off-by: Malte S. Stretz <m...@apache.org> --- ipv6/aiccu/files/aiccu.conf | 10 ++-- ipv6/aiccu/files/aiccu.init | 93 +++++++++++++++++++++++++----------------- 2 files changed, 60 insertions(+), 43 deletions(-) diff --git a/ipv6/aiccu/files/aiccu.conf b/ipv6/aiccu/files/aiccu.conf index 671fd16..b088992 100755 --- a/ipv6/aiccu/files/aiccu.conf +++ b/ipv6/aiccu/files/aiccu.conf @@ -1,11 +1,11 @@ -config aiccu +config aiccu tunnel option username '' option password '' option protocol '' option server '' option interface '' option tunnel_id '' - option requiretls '' - option defaultroute '1' - option nat '1' - option heartbeat '1' +# option requiretls 'true' +# option defaultroute 'true' +# option nat 'true' +# option heartbeat 'true' diff --git a/ipv6/aiccu/files/aiccu.init b/ipv6/aiccu/files/aiccu.init index 56de87d..6567bcd 100644 --- a/ipv6/aiccu/files/aiccu.init +++ b/ipv6/aiccu/files/aiccu.init @@ -1,52 +1,69 @@ #!/bin/sh /etc/rc.common -# Copyright (C) 2006 OpenWrt.org +# Copyright (C) 2006-2009 OpenWrt.org START=50 -config_cb() { - local cfg_type="$1" - local cfg_name="$2" +aiccu_set() { + local config="$1" + local option="$2" + local value="$3" + echo "$option $value" >> /var/run/aiccu-${config}.conf +} + +aiccu_set_string() { + local config="$1" + local option="$2" + local setting="$3" + config_get dummy $config ${setting:-$option} + [ -n "$dummy" ] && aiccu_set $config $option $dummy +} - case "$cfg_type" in - aiccu) - append cfgs_sections "$cfg_name" "$N" - ;; +aiccu_set_bool() { + local config="$1" + local option="$2" + local setting="$3" + config_get_bool dummy $config ${setting:-$option} "undef" + case "$dummy" in + 0) aiccu_set $config $option false ;; + 1) aiccu_set $config $option true ;; esac } start() { config_load aiccu - for cfgs_section in $cfgs_sections; do - config_get username $cfgs_section username - config_get password $cfgs_section password - config_get server $cfgs_section server - config_get protocol $cfgs_section protocol - config_get interface $cfgs_section interface - config_get tunnel_id $cfgs_section tunnel_id - config_get_bool requiretls $cfgs_section requiretls 0 - config_get_bool defaultroute $cfgs_section defaultroute 1 - config_get_bool nat $cfgs_section nat 1 - config_get_bool heartbeat $cfgs_section heartbeat 1 - mkdir -p /tmp/run - echo "username $username" > /tmp/run/aiccu-${cfgs_section}.conf - echo "password $password" >> /tmp/run/aiccu-${cfgs_section}.conf - [ -n "$server" ] && echo "server $server" >> /tmp/run/aiccu-${cfgs_section}.conf - [ -n "$protocol" ] && echo "protocol $protocol" >> /tmp/run/aiccu-${cfgs_section}.conf - [ -n "$interface" ] && echo "ipv6_interface $interface" >> /tmp/run/aiccu-${cfgs_section}.conf - [ -n "$tunnel_id" ] && echo "tunnel_id $tunnel_id" >> /tmp/run/aiccu-${cfgs_section}.conf - [ "$requiretls" = "1" ] && echo "requiretls true" >> /tmp/run/aiccu-${cfgs_section}.conf - [ "$defaultroute" != "1" ] && echo "defaultroute false >> /tmp/run/aiccu-${cfgs_section}.conf - [ "$nat" = "1" ] && echo "behindnat true >> /tmp/run/aiccu-${cfgs_section}.conf - [ "$heartbeat" != "1" ] && echo "makebeats false" >> /tmp/run/aiccu-${cfgs_section}.conf - echo 'daemonize true' >> /tmp/run/aiccu-${cfgs_section}.conf - echo "pidfile /var/run/aiccu-${cfgs_section}.pid" >> /tmp/run/aiccu-${cfgs_section}.conf - - aiccu start /tmp/run/aiccu-$cfgs_section.conf - done + callback() { + local config="$1" + local config_file=/var/run/aiccu-${config}.conf + rm -f $config_file + touch $config_file + chmod 600 $config_file + + aiccu_set_string $config username + aiccu_set_string $config password + aiccu_set_string $config server + aiccu_set_string $config protocol + aiccu_set_string $config ipv6_interface interface + aiccu_set_string $config tunnel_id + aiccu_set_bool $config requiretls + aiccu_set_bool $config defaultroute + aiccu_set_bool $config behindnat nat + aiccu_set_bool $config makebeats heartbeat + aiccu_set $config daemonize "true" + aiccu_set $config pidfile "/var/run/aiccu-${config}.pid" + + aiccu start $config_file + uci_set_state aiccu "$config" conf "$config_file" + } + config_foreach callback aiccu } stop() { config_load aiccu - for cfgs_section in $cfgs_sections; do - aiccu stop /tmp/run/aiccu-$cfgs_section.conf - done + callback() { + local config="$1" + config_get config_file "$config" conf + aiccu stop $config_file + uci_revert_state aiccu "$config" conf + rm -f $config_file + } + config_foreach callback aiccu } -- 1.5.4.3 -- _______________________________________________ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/mailman/listinfo/openwrt-devel