N='
'
+log()
+{
+ logger -t olsrd -p daemon.info -s "$1"
+}
+
validate_varname() {
local varname="$1"
[ -z "$varname" -o "$varname" != "${varname%%[!A-Za-z0-9_]*}" ] && return 1
}
warning_invalid_value() {
+ local funcname="warning_invalid_value"
local package="$1"
validate_varname "$package" || package=
local config="$2"
local option="$3"
validate_varname "$option" || option=
- echo -n "Warning: Invalid value" 1>&2
-
if [ -n "$package" -a -n "$config" ]; then
- echo -n " in option '$package.$config${option:+.}$option'" 1>&2
+ log "$funcname() in option '$package.$config${option:+.}$option', skipped"
+ else
+ log "$funcname() skipped"
fi
- echo ", skipped" 1>&2
-
return 0
}
}
olsrd_write_plparam() {
+ local funcname="olsrd_write_plparam"
local param="$1"
local cfg="$2"
validate_varname "$cfg" || return 1
if [ "$option" = 'NonOlsrIf' ]; then
if validate_varname "$value"; then
if network_get_device ifname "$value"; then
- echo "Info: mdns Interface '$value' ifname '$ifname' found" 1>&2
+ log "$funcname() Info: mdns Interface '$value' ifname '$ifname' found"
else
- echo "Warning: mdns Interface '$value' not found, skipped" 1>&2
+ log "$funcname() Warning: mdns Interface '$value' not found, skipped"
fi
else
warning_invalid_value olsrd "$cfg" "NonOlsrIf"
local write_func="$3"
[ -z "$write_func" ] && output_func=echo
local write_param="$4"
+
local schema_entry
local option
local option_length
local i
local position
- for schema_entry in $schema; do
+ get_value_for_entry()
+ {
+ local schema_entry="$1"
+
default="${schema_entry#*[=]}"
[ "$default" = "$schema_entry" ] && default=
option="${schema_entry%%[=]*}"
- IFS=':'
- set -- $option
- unset IFS
+
+ IFS=':'; set -- $option; unset IFS
option="$1"
option_type="$2"
- validate_varname "$option" || continue
- [ -z "$option_type" ] || validate_varname "$option_type" || continue
- [ "$option_type" = internal ] && continue
+
+ validate_varname "$option" || return 1
+ [ -z "$option_type" ] || validate_varname "$option_type" || return 1
+ [ "$option_type" = internal ] && return 1
+
config_get value "$cfg" "$option"
+ return 0
+ }
+
+ for schema_entry in $schema; do
+ get_value_for_entry "$schema_entry" || continue
+
if [ -z "$value" ]; then
IFS='+'
set -- $default
}
olsrd_write_loadplugin() {
+ local funcname="olsrd_write_loadplugin"
local cfg="$1"
validate_varname "$cfg" || return 0
local ignore
return 0
fi
if ! [ -x "/lib/$library" -o -x "/usr/lib/$library" -o -x "/usr/local/lib/$library" ]; then
- echo "Warning: Plugin library '$library' not found, skipped" 1>&2
+ log "$funcname() Warning: Plugin library '$library' not found, skipped"
return 0
fi
}
olsrd_write_interface() {
+ local funcname="olsrd_write_interface"
local cfg="$1"
validate_varname "$cfg" || return 0
local ignore
ifnames=
config_get interfaces "$cfg" interface
+
for interface in $interfaces; do
if validate_varname "$interface"; then
if network_get_device IFNAME "$interface"; then
ifnames="$ifnames \"$IFNAME\""
ifsglobal="$ifsglobal $IFNAME"
else
- echo "Warning: Interface '$interface' not found, skipped" 1>&2
+ log "$funcname() Warning: Interface '$interface' not found, skipped"
fi
else
warning_invalid_value olsrd "$cfg" "interface"
return 0
}
+get_wan_ifnames()
+{
+ local wanifnames word catch_next
+
+ which ip >/dev/null || return 1
+
+ set -- $( ip route list exact 0.0.0.0/0 table all )
+ for word in $*; do
+ case "$word" in
+ dev)
+ catch_next="true"
+ ;;
+ *)
+ [ -n "$catch_next" ] && {
+ case "$wanifnames" in
+ *" $word "*)
+ ;;
+ *)
+ wanifnames="$wanifnames $word "
+ ;;
+ esac
+
+ catch_next=
+ }
+ ;;
+ esac
+ done
+
+ echo "$wanifnames"
+}
+
olsrd_setup_smartgw_rules() {
+ local funcname="olsrd_setup_smartgw_rules"
# Check if ipip is installed
- [ ! -e /etc/modules.d/[0-9]*-ipip ] && echo "Warning: kmod-ipip is missing. SmartGateway will not work until you install it."
+ [ -e /etc/modules.d/[0-9]*-ipip ] || {
+ log "$funcname() Warning: kmod-ipip is missing. SmartGateway will not work until you install it."
+ return 1
+ }
+
+ local wanifnames="$( get_wan_ifnames )"
- wanifnames=$(ip r l e 0/0 t all | sed -e 's/^.* dev //' |cut -d " " -f 1 | sort | uniq)
- nowan=0
if [ -z "$wanifnames" ]; then
nowan=1
+ else
+ nowan=0
fi
IP4T=$(which iptables)
while $IP4T -t nat -D postrouting_rule -o tnl_+ -j MASQUERADE 2> /dev/null; do :;done
if [ "$smartgateway" == "yes" ]; then
- echo "Notice: Inserting firewall rules for SmartGateway"
+ log "$funcname() Notice: Inserting firewall rules for SmartGateway"
if [ ! "$smartgatewayuplink" == "none" ]; then
if [ "$smartgatewayuplink" == "ipv4" ]; then
# Allow everything to be forwarded to tnl_+ and use NAT for it
}
error() {
- echo "${initscript}:" "$@" 1>&2
+ log "error() ${initscript}: $@"
}
start() {
SERVICE_PID_FILE="$PID6"
if service_check /usr/sbin/olsrd; then
- error "there already is an IPv6 instance of olsrd running ($(cat $PID6)), not starting."
+ error "there is already an IPv6 instance of olsrd running (pid: '$(cat $PID6)'), not starting."
else
service_start /usr/sbin/olsrd -f /var/etc/olsrd.conf.ipv6 -nofork
fi
SERVICE_PID_FILE="$PID"
if service_check /usr/sbin/olsrd; then
- error "there already is an IPv4 instance of olsrd running ($(cat $PID)), not starting."
+ error "there is already an IPv4 instance of olsrd running (pid: '$(cat $PID)'), not starting."
else
service_start /usr/sbin/olsrd -f /var/etc/olsrd.conf.ipv4 -nofork
fi
SERVICE_PID_FILE="$PID"
if service_check /usr/sbin/olsrd; then
- error "there already is an IPv4 instance of olsrd running ($(cat $PID)), not starting."
+ error "there is already an IPv4 instance of olsrd running (pid: '$(cat $PID)'), not starting."
return 1
else
service_start /usr/sbin/olsrd -f "$OLSRD_CONFIG_FILE" -nofork