IPv6 SmartGW doesn't require IPv6 NAT support
[feed/routing.git] / olsrd / files / olsrd.init
index 1172623023adf60a01fb3412152d9fa02c369e83..c8f1df566c1b1b975fbf717d3d6f615c3444709b 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/sh /etc/rc.common
-# Copyright (C) 2008-2012 OpenWrt.org
+# Copyright (C) 2008-2013 OpenWrt.org
 
 START=65
 
@@ -13,16 +13,19 @@ PID6=/var/run/olsrd.ipv6.pid
 OLSRD_OLSRD_SCHEMA='ignore:internal config_file:internal DebugLevel=0 AllowNoInt=yes'
 OLSRD_IPCCONNECT_SCHEMA='ignore:internal Host:list Net:list2'
 OLSRD_LOADPLUGIN_SCHEMA='ignore:internal library:internal Host4:list Net4:list2 Host:list Net:list2 Host6:list Net6:list2 Ping:list redistribute:list NonOlsrIf:list name:list lat lon latlon_infile HNA:list2 hosts:list2'
-OLSRD_INTERFACE_SCHEMA='ignore:internal interface:internal AutoDetectChanges:bool'
+OLSRD_INTERFACE_SCHEMA='ignore:internal interface:internal AutoDetectChanges:bool LinkQualityMult:list2'
 OLSRD_INTERFACE_DEFAULTS_SCHEMA='AutoDetectChanges:bool'
 
 T='    '
 N='
 '
 
-log()
-{
-       logger -t olsrd -p daemon.info -s "$1"
+log() {
+       logger -t olsrd -p daemon.info -s "${initscript}: $@"
+}
+
+error() {
+       log "ERROR: $@"
 }
 
 validate_varname() {
@@ -39,9 +42,7 @@ validate_olsrd_option() {
 
 system_config() {
        local cfg="$1"
-       local cfgt
-       local hostname
-       local latlon
+       local cfgt hostname latlon oldIFS
 
        config_get cfgt "$cfg" TYPE
 
@@ -53,9 +54,7 @@ system_config() {
 
        if [ -z "$SYSTEM_LAT" -o -z "$SYSTEM_LON" ]; then
                config_get latlon "$cfg" latlon
-               IFS=" ${T}${N},"
-               set -- $latlon
-               unset IFS
+               oldIFS="$IFS"; IFS=" ${T}${N},"; set -- $latlon; IFS="$oldIFS"
                SYSTEM_LAT="$1"
                SYSTEM_LON="$2"
        fi
@@ -139,7 +138,7 @@ olsrd_write_plparam() {
        validate_varname "$option" || return 1
        local value="$4"
        local option_type="$5"
-       local _option
+       local _option oldIFS
 
        if [ "$option_type" = bool ]; then
                case "$value" in
@@ -154,17 +153,20 @@ olsrd_write_plparam() {
                return 1
        fi
 
+       oldIFS="$IFS"
        IFS='-_'
        set -- $option
        option="$*"
-       unset IFS
+       IFS="$oldIFS"
        _option="$option"
+
        if [ "$option" = 'hosts' ]; then
                set -- $value
                option="$1"
                shift
                value="$*"
        fi
+
        if [ "$option" = 'NonOlsrIf' ]; then
                if validate_varname "$value"; then
                        if network_get_device ifname "$value"; then
@@ -184,7 +186,6 @@ olsrd_write_plparam() {
 }
 
 config_update_schema() {
-       unset IFS
        local schema_varname="$1"
        validate_varname "$schema_varname" || return 1
        local command="$2"
@@ -226,7 +227,6 @@ config_update_schema() {
 
 config_write_options() {
        local funcname="config_write_options"
-       unset IFS
        local schema="$1"
        local cfg="$2"
        validate_varname "$cfg" || return 1
@@ -234,18 +234,7 @@ config_write_options() {
        [ -z "$write_func" ] && output_func=echo
        local write_param="$4"
 
-       local schema_entry
-       local option
-       local option_length
-       local option_type
-       local default
-       local value
-       local list_size
-       local list_item
-       local list_value
-       local i
-       local position
-       local speed
+       local schema_entry option option_length option_type default value list_size list_item list_value i position speed oldIFS
        local list_speed_vars="HelloInterval HelloValidityTime TcInterval TcValidityTime MidInterval MidValidityTime HnaInterval HnaValidityTime"
 
        get_value_for_entry()
@@ -256,7 +245,7 @@ config_write_options() {
                [ "$default" = "$schema_entry" ] && default=
                option="${schema_entry%%[=]*}"
 
-               IFS=':'; set -- $option; unset IFS
+               oldIFS="$IFS"; IFS=':'; set -- $option; IFS="$oldIFS"
                option="$1"
                option_type="$2"
 
@@ -349,9 +338,7 @@ config_write_options() {
                fi
 
                if [ -z "$value" ]; then
-                       IFS='+'
-                       set -- $default
-                       unset IFS
+                       oldIFS="$IFS"; IFS='+'; set -- $default; IFS="$oldIFS"
                        value=$*
                elif [ "$value" = '-' -a -n "$default" ]; then
                        continue
@@ -577,6 +564,12 @@ olsrd_write_interface() {
                        if network_get_device IFNAME "$interface"; then
                                ifnames="$ifnames \"$IFNAME\""
                                ifsglobal="$ifsglobal $IFNAME"
+                       elif network_get_physdev IFNAME "$interface"; then
+                               local proto="$(uci -q get network.${interface}.proto)"
+                               if [ "$proto" = "static" -o "$proto" = "none" ]; then
+                                       ifnames="$ifnames \"$IFNAME\""
+                                       ifsglobal="$ifsglobal $IFNAME"
+                               fi
                        else
                                log "$funcname() Warning: Interface '$interface' not found, skipped"
                        fi
@@ -739,9 +732,9 @@ olsrd_setup_smartgw_rules() {
                                        $IP6T -I input_rule -i $IFACE -p 4 -j ACCEPT
                                done
                        else
+                               $IP4T -t nat -I postrouting_rule -o tnl_+ -j MASQUERADE
                                for IPT in $IP4T $IP6T; do
                                        $IPT -I forwarding_rule -o tnl_+ -j ACCEPT
-                                       $IPT -t nat -I postrouting_rule -o tnl_+ -j MASQUERADE
                                        if [ "$nowan"="0" ]; then
                                                for IFACE in $wanifnames; do
                                                        $IPT -A forwarding_rule -i tunl0 -o $IFACE -j ACCEPT
@@ -756,10 +749,6 @@ olsrd_setup_smartgw_rules() {
        fi
 }
 
-error() {
-       log "error() ${initscript}: $@"
-}
-
 start() {
        SYSTEM_HOSTNAME=
        SYSTEM_LAT=
@@ -836,8 +825,12 @@ start() {
                        return 1
                else
                        service_start /usr/sbin/olsrd -f "$OLSRD_CONFIG_FILE" -nofork
+                       service_check /usr/sbin/olsrd || {
+                               log "startup-error: check via: '/usr/sbin/olsrd -f \"$OLSRD_CONFIG_FILE\" -nofork'"
+                       }
                fi
        fi
+
        olsrd_setup_smartgw_rules
 }