SERVICE_DAEMONIZE=1
SERVICE_WRITE_PID=1
-CONF=/var/etc/olsrd.conf
-PID=/var/run/olsrd.pid
-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_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 ipv6only:bool'
+OLSRD_INTERFACE_SCHEMA='ignore:internal interface:internal AutoDetectChanges:bool LinkQualityMult:list2'
OLSRD_INTERFACE_DEFAULTS_SCHEMA='AutoDetectChanges:bool'
T=' '
N='
'
+#6and4: backward compatibility - it MUST be different from /etc/init.d/olsrd6 PID variable
+PID6=/var/run/olsrd6and4.pid
log() {
logger -t olsrd -p daemon.info -s "${initscript}: $@"
}
error() {
- log "ERROR: $@"
+ logger -t olsrd -p daemon.err -s "${initscript}: ERROR: $@"
+}
+
+warn() {
+ logger -t olsrd -p daemon.warn -s "${initscript}: WARNING: $@"
}
validate_varname() {
validate_olsrd_option() {
local str="$1"
- [ -z "$str" -o "$str" != "${str%%[! 0-9A-Za-z./|:_-]*}" ] && return 1
+ [ -z "$str" -o "$str" != "${str%%[! 0-9A-Za-z.%/|:_-]*}" ] && return 1
return 0
}
return 1
fi
- oldIFS="$IFS"; IFS='-_'; set -- $option; IFS="$oldIFS"
+ oldIFS="$IFS"
+ IFS='-_'
+ set -- $option
option="$*"
+ IFS="$oldIFS"
_option="$option"
if [ "$option" = 'hosts' ]; then
[ "$OLSRD_COUNT" -gt 0 ] && return 0
config_get ipversion "$cfg" IpVersion
- if [ "$ipversion" = "6and4" ]; then
- OLSRD_IPVERSION_6AND4=1
- config_set "$cfg" IpVersion '6'
+ if [ "$UCI_CONF_NAME" == "olsrd6" ]; then
+ OLSRD_OLSRD_SCHEMA="$OLSRD_OLSRD_SCHEMA IpVersion=6"
+ if [ "$ipversion" = "6and4" ]; then
+ error "IpVersion 6and4 not supported in olsrd6"
+ return 1
+ fi
+ else
+ if [ "$ipversion" = "6and4" ]; then
+ OLSRD_IPVERSION_6AND4=1
+ config_set "$cfg" IpVersion '6'
+ fi
fi
config_get smartgateway "$cfg" SmartGateway
config_get smartgatewayuplink "$cfg" SmartGatewayUplink
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
IP6T=$(which ip6tables)
# Delete smartgw firewall rules first
- for IPT in $IP4T $IP6T; do
- while $IPT -D forwarding_rule -o tnl_+ -j ACCEPT 2> /dev/null; do :;done
+ if [ "$UCI_CONF_NAME" == "olsrd6" ]; then
+ while $IP6T -D forwarding_rule -o tnl_+ -j ACCEPT 2> /dev/null; do :;done
for IFACE in $wanifnames; do
- while $IPT -D forwarding_rule -i tunl0 -o $IFACE -j ACCEPT 2> /dev/null; do :; done
+ while $IP6T -D forwarding_rule -i tunl0 -o $IFACE -j ACCEPT 2> /dev/null; do :; done
done
for IFACE in $ifsglobal; do
- while $IPT -D input_rule -i $IFACE -p 4 -j ACCEPT 2> /dev/null; do :; done
+ while $IP6T -D input_rule -i $IFACE -p 4 -j ACCEPT 2> /dev/null; do :; done
done
- done
- while $IP4T -t nat -D postrouting_rule -o tnl_+ -j MASQUERADE 2> /dev/null; do :;done
+ else
+ while $IP4T -D forwarding_rule -o tnl_+ -j ACCEPT 2> /dev/null; do :;done
+ for IFACE in $wanifnames; do
+ while $IP4T -D forwarding_rule -i tunl0 -o $IFACE -j ACCEPT 2> /dev/null; do :; done
+ done
+ for IFACE in $ifsglobal; do
+ while $IP4T -D input_rule -i $IFACE -p 4 -j ACCEPT 2> /dev/null; do :; done
+ done
+ while $IP4T -t nat -D postrouting_rule -o tnl_+ -j MASQUERADE 2> /dev/null; do :;done
+ fi
if [ "$smartgateway" == "yes" ]; then
log "$funcname() Notice: Inserting firewall rules for SmartGateway"
$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
. /lib/functions/network.sh
- config_load olsrd
+ config_load $UCI_CONF_NAME
reset_cb
OLSRD_CONFIG_FILE=
if [ -z "$OLSRD_CONFIG_FILE" ]; then
mkdir -p -- /var/etc/
- olsrd_write_config > /var/etc/olsrd.conf
+ olsrd_write_config > /var/etc/$UCI_CONF_NAME.conf || return 1
if [ "$INTERFACES_COUNT" -gt 0 -a "$OLSRD_COUNT" -gt 0 ]; then
- OLSRD_CONFIG_FILE=/var/etc/olsrd.conf
+ OLSRD_CONFIG_FILE=/var/etc/$UCI_CONF_NAME.conf
fi
fi
[ -z "$OLSRD_CONFIG_FILE" ] && return 1
+ #6and4: backward compatibility
local bindv6only='0'
if [ "$OLSRD_IPVERSION_6AND4" -ne 0 ]; then
+ warn "IpVersion 6and4 is deprecated and will be removed in future!"
+ warn "You must use /etc/config/olsrd and /etc/init.d/olsrd for IPv4"
+ warn " /etc/config/olsrd6 and /etc/init.d/olsrd6 for IPv6"
+
bindv6only="$(sysctl -n net.ipv6.bindv6only)"
sysctl -w net.ipv6.bindv6only=1 > /dev/null
sed -e '/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/d' < "$OLSRD_CONFIG_FILE" > /var/etc/olsrd.conf.ipv6
sleep 3
sysctl -w net.ipv6.bindv6only="$bindv6only" > /dev/null
-
else
-
- if [ "$ipversion" = "6" ]; then
- sed -i '/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/d' "$OLSRD_CONFIG_FILE"
- fi
-
SERVICE_PID_FILE="$PID"
if service_check /usr/sbin/olsrd; then
- error "there is already an IPv4 instance of olsrd running (pid: '$(cat $PID)'), not starting."
+ error "there is already an instance of $UCI_CONF_NAME running (pid: '$(cat $PID)'), not starting."
return 1
else
service_start /usr/sbin/olsrd -f "$OLSRD_CONFIG_FILE" -nofork
+ sleep 1
service_check /usr/sbin/olsrd || {
log "startup-error: check via: '/usr/sbin/olsrd -f \"$OLSRD_CONFIG_FILE\" -nofork'"
}
SERVICE_PID_FILE="$PID"
service_stop /usr/sbin/olsrd
+ #6and4: backward compatibility
SERVICE_PID_FILE="$PID6"
service_stop /usr/sbin/olsrd
}