#!/bin/sh /etc/rc.common
# Copyright (C) 2008 Alina Friedrichsen <x-alina@gmx.net>
# Special thanks to bittorf wireless ))
-START=50
+START=65
-OLSRD_OLSRD_SCHEMA='ignore:internal config_file:internal DebugLevel=0 IpVersion=4 AllowNoInt:bool=1 Pollrate=0.025 TcRedundancy=2 MprCoverage=3 LinkQualityFishEye=1 LinkQualityWinSize=100 LinkQualityDijkstraLimit=0+9.0 LinkQualityLevel=2 UseHysteresis:bool=0 FIBMetric=flat ClearScreen:bool=1 Willingness=3 LinkQualityAging=0.1 LinkQualityAlgorithm=etx_fpm'
+OLSRD_OLSRD_SCHEMA='ignore:internal config_file:internal DebugLevel=0'
OLSRD_IPCCONNECT_SCHEMA='ignore:internal Host:list Net:list2'
-OLSRD_LOADPLUGIN_SCHEMA='ignore:internal library:internal Host:list Net: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 Ip4Broadcast=255.255.255.255 HelloInterval=2.0 HelloValidityTime=40.0 TcInterval=5.0 TcValidityTime=100.0 MidInterval=18.0 MidValidityTime=324.0 HnaInterval=18.0 HnaValidityTime=108.0'
+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'
T=' '
N='
'
validate_varname() {
- local varname=$1
+ local varname="$1"
[ -z "$varname" -o "$varname" != "${varname%%[!A-Za-z0-9_]*}" ] && return 1
return 0
}
validate_ifname() {
- local ifname=$1
+ local ifname="$1"
[ -z "$ifname" -o "$ifname" != "${ifname%%[!A-Za-z0-9.:_-]*}" ] && return 1
return 0
}
validate_olsrd_option() {
- local str=$1
- [ -z "$str" -o "$str" != "${str%%[! 0-9A-Za-z./:_-]*}" ] && return 1
+ local str="$1"
+ [ -z "$str" -o "$str" != "${str%%[! 0-9A-Za-z./|:_-]*}" ] && return 1
return 0
}
get_ifname() {
IFNAME=
- local interface=$1
+ local interface="$1"
validate_varname "$interface" || return 1
local ifname
config_get ifname "$interface" ifname
validate_ifname "$ifname" || return 1
- IFNAME=$ifname
+ IFNAME="$ifname"
return 0
}
system_config() {
- local cfg=$1
+ local cfg="$1"
local cfgt
local hostname
local latlon
if [ "$cfgt" = "system" ]; then
config_get hostname "$cfg" hostname
- hostname=${hostname:-OpenWrt}
- SYSTEM_HOSTNAME=$hostname
+ hostname="${hostname:-OpenWrt}"
+ SYSTEM_HOSTNAME="$hostname"
fi
if [ -z "$SYSTEM_LAT" -o -z "$SYSTEM_LON" ]; then
IFS=" ${T}${N},"
set -- $latlon
unset IFS
- SYSTEM_LAT=$1
- SYSTEM_LON=$2
+ SYSTEM_LAT="$1"
+ SYSTEM_LON="$2"
+ fi
+
+ if [ -z "$SYSTEM_LAT" -o -z "$SYSTEM_LON" ]; then
+ config_get latlon "$cfg" latitude
+ SYSTEM_LAT="$latlon"
+ config_get latlon "$cfg" longitude
+ SYSTEM_LON="$latlon"
fi
}
olsrd_find_config_file() {
- local cfg=$1
+ local cfg="$1"
validate_varname "$cfg" || return 0
config_get_bool ignore "$cfg" ignore 0
}
warning_invalid_value() {
- local package=$1
+ local package="$1"
validate_varname "$package" || package=
- local config=$2
+ local config="$2"
validate_varname "$config" || config=
- local option=$3
+ local option="$3"
validate_varname "$option" || option=
echo -n "Warning: Invalid value" 1>&2
}
olsrd_write_option() {
- local param=$1
- local cfg=$2
+ local param="$1"
+ local cfg="$2"
validate_varname "$cfg" || return 1
- local option=$3
+ local option="$3"
validate_varname "$option" || return 1
- local value=$4
- local option_type=$5
+ local value="$4"
+ local option_type="$5"
if [ "$option_type" = bool ]; then
case "$value" in
fi
if [ "$value" != "${value%%[G-Zg-z_-]*}" ]; then
- if [ "$value" != "yes" -a "$value" != "no" ]; then
+ if [ "$option" != "Ip6AddrType" -a "$value" != "yes" -a "$value" != "no" ]; then
value="\"$value\""
fi
fi
}
olsrd_write_plparam() {
- local param=$1
- local cfg=$2
+ local param="$1"
+ local cfg="$2"
validate_varname "$cfg" || return 1
- local option=$3
+ local option="$3"
validate_varname "$option" || return 1
- local value=$4
- local option_type=$5
+ local value="$4"
+ local option_type="$5"
local _option
if [ "$option_type" = bool ]; then
_option="$option"
if [ "$option" = 'hosts' ]; then
set -- $value
- option=$1
+ option="$1"
shift
value="$*"
fi
config_update_schema() {
unset IFS
- local schema_varname=$1
+ local schema_varname="$1"
validate_varname "$schema_varname" || return 1
- local command=$2
+ local command="$2"
validate_varname "$command" || return 1
- local option=$3
+ local option="$3"
validate_varname "$option" || return 1
- local value=$4
+ local value="$4"
local schema
local cur_option
config_write_options() {
unset IFS
- local schema=$1
- local cfg=$2
+ local schema="$1"
+ local cfg="$2"
validate_varname "$cfg" || return 1
- local write_func=$3
+ local write_func="$3"
[ -z "$write_func" ] && output_func=echo
- local write_param=$4
+ local write_param="$4"
local schema_entry
local option
local option_length
local position
for schema_entry in $schema; do
- default=${schema_entry#*[=]}
+ default="${schema_entry#*[=]}"
[ "$default" = "$schema_entry" ] && default=
- option=${schema_entry%%[=]*}
+ option="${schema_entry%%[=]*}"
IFS=':'
set -- $option
unset IFS
- option=$1
- option_type=$2
+ option="$1"
+ option_type="$2"
validate_varname "$option" || continue
[ -z "$option_type" ] || validate_varname "$option_type" || continue
[ "$option_type" = internal ] && continue
}
olsrd_write_olsrd() {
- local cfg=$1
+ local cfg="$1"
validate_varname "$cfg" || return 0
local ignore
+ local ipversion
config_get_bool ignore "$cfg" ignore 0
[ "$ignore" -ne 0 ] && return 0
[ "$OLSRD_COUNT" -gt 0 ] && return 0
+ config_get ipversion "$cfg" IpVersion
+ if [ "$ipversion" = "6and4" ]; then
+ OLSRD_IPVERSION_6AND4=1
+ config_set "$cfg" IpVersion '6'
+ fi
+
config_write_options "$OLSRD_OLSRD_SCHEMA" "$cfg" olsrd_write_option
echo
OLSRD_COUNT=$((OLSRD_COUNT + 1))
}
olsrd_write_ipcconnect() {
- local cfg=$1
+ local cfg="$1"
validate_varname "$cfg" || return 0
local ignore
}
olsrd_write_hna4() {
- local cfg=$1
+ local cfg="$1"
validate_varname "$cfg" || return 0
local ignore
fi
[ "$HNA4_COUNT" -le 0 ] && echo -n "${N}Hna4${N}{"
- echo -n "${N}${T}$netaddr $netmask"
+ echo -n "${N}${T}${T}$netaddr $netmask"
HNA4_COUNT=$((HNA4_COUNT + 1))
return 0
}
olsrd_write_hna6() {
- local cfg=$1
+ local cfg="$1"
validate_varname "$cfg" || return 0
local ignore
fi
[ "$HNA6_COUNT" -le 0 ] && echo -n "${N}Hna6${N}{"
- echo -n "${N}${T}$netaddr $prefix"
+ echo -n "${N}${T}${T}$netaddr $prefix"
HNA6_COUNT=$((HNA6_COUNT + 1))
return 0
}
olsrd_write_loadplugin() {
- local cfg=$1
+ local cfg="$1"
validate_varname "$cfg" || return 0
local ignore
local name
}
olsrd_write_interface() {
- local cfg=$1
+ local cfg="$1"
validate_varname "$cfg" || return 0
local ignore
local interfaces
}
olsrd_write_config() {
+ OLSRD_IPVERSION_6AND4=0
OLSRD_COUNT=0
config_foreach olsrd_write_olsrd olsrd
IPCCONNECT_COUNT=0
[ -z "$OLSRD_CONFIG_FILE" ] && return 1
- olsrd -f "$OLSRD_CONFIG_FILE" -nofork < /dev/null > /dev/null &
+ local bindv6only='0'
+ if [ "$OLSRD_IPVERSION_6AND4" -ne 0 ]; then
+ bindv6only="$(sysctl -n net.ipv6.bindv6only)"
+ sysctl -w net.ipv6.bindv6only=1
+ sed -e 's/^\t\t[0-9.]*[ ][0-9.]*$//' < "$OLSRD_CONFIG_FILE" > /var/etc/olsrd.conf.ipv6
+ olsrd -f /var/etc/olsrd.conf.ipv6 -nofork < /dev/null > /dev/null &
+
+ sed -e 's/^IpVersion[ ][ ]*6$/IpVersion 4/' -e 's/^\t\t[A-Fa-f0-9.:]*[:][A-Fa-f0-9.:]*[ ][0-9]*$//' < "$OLSRD_CONFIG_FILE" > /var/etc/olsrd.conf.ipv4
+ olsrd -f /var/etc/olsrd.conf.ipv4 -nofork < /dev/null > /dev/null &
+ sleep 3
+ sysctl -w net.ipv6.bindv6only="$bindv6only"
+ else
+ olsrd -f "$OLSRD_CONFIG_FILE" -nofork < /dev/null > /dev/null &
+ fi
}
stop() {