olsrd: configuration sanity checks
authorAlessio Caiazza <nolith@abisso.org>
Wed, 28 May 2014 14:43:59 +0000 (16:43 +0200)
committerAlessio Caiazza <nolith@abisso.org>
Wed, 28 May 2014 14:55:55 +0000 (16:55 +0200)
* do not start in presence of the old /etc/config/olsrd
* use always use the appropriate IpVersion.

olsrd/files/olsrd.init
olsrd/files/olsrd4.config
olsrd/files/olsrd4.init
olsrd/files/olsrd6.config
olsrd/files/olsrd6.init

index d0c4e0035262db8c0250e8425fd6a0749ab6dc80..4da101cad239cfda4eb59f5494119df14712d879 100644 (file)
@@ -391,10 +391,6 @@ olsrd_write_olsrd() {
        [ "$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_get smartgateway "$cfg" SmartGateway
        config_get smartgatewayuplink "$cfg" SmartGatewayUplink
 
@@ -618,9 +614,21 @@ olsrd_update_schema() {
 }
 
 olsrd_write_config() {
-       OLSRD_IPVERSION_6AND4=0
        OLSRD_COUNT=0
        config_foreach olsrd_write_olsrd olsrd
+
+       if [ ! -z "$ipversion" ]; then
+               if [ "$ipversion" = "6and4" ]; then
+                       error "IpVersion 6and4 is no longer supported!"
+                       error "You must use /etc/config/olsrd4 for IPv4 and /etc/config/olsrd6 for IPv4"
+               else
+                       error "Option IpVersion is no longer supported!"
+                       error "Please remove it from /etc/config/$UCI_CONF_NAME"
+               fi
+
+               return 1
+       fi
+
        IPCCONNECT_COUNT=0
        config_foreach olsrd_write_ipcconnect IpcConnect
        HNA4_COUNT=0
@@ -746,6 +754,13 @@ olsrd_setup_smartgw_rules() {
 }
 
 start() {
+        if [ -f /etc/config/olsrd ]; then
+              error "/etc/config/olsrd no longer supported!"
+              error "please move your config file to /etc/config/olsrd4 and/or /etc/config/olsrd6"
+
+              return 1
+       fi
+
        SYSTEM_HOSTNAME=
        SYSTEM_LAT=
        SYSTEM_LON=
@@ -770,7 +785,7 @@ start() {
 
        if [ -z "$OLSRD_CONFIG_FILE" ]; then
                mkdir -p -- /var/etc/
-               olsrd_write_config > /var/etc/$UCI_CONF_NAME.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/$UCI_CONF_NAME.conf
                fi
@@ -778,53 +793,15 @@ start() {
 
        [ -z "$OLSRD_CONFIG_FILE" ] && return 1
 
-       local bindv6only='0'
-       if [ "$OLSRD_IPVERSION_6AND4" -ne 0 ]; then
-               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
-               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
-               rm $OLSRD_CONFIG_FILE
-
-               # some filenames should get the suffix .ipv6
-               for file in $latlon_file $hosts_file $services_file $resolv_file $macs_file $wd_file;do
-                       f=$(echo $file|sed 's/\//\\\//g')
-                       sed -i "s/$f/$f.ipv6/g" /var/etc/olsrd.conf.ipv6
-               done
-
-               SERVICE_PID_FILE="$PID6"
-               if service_check /usr/sbin/olsrd; then
-                       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 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
-
-               sleep 3
-               sysctl -w net.ipv6.bindv6only="$bindv6only" > /dev/null
-
+       SERVICE_PID_FILE="$PID"
+       if service_check /usr/sbin/olsrd; then
+               error "there is already an instance of $UCI_CONF_NAME running (pid: '$(cat $PID)'), not starting."
+               return 1
        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."
-                       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
+               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
 
        olsrd_setup_smartgw_rules
index 9a19eb98c861b1c5ed3e6b0fa3ae1aa13558c011..f4ddfd0d06322345cb8c51931857951a058f0695 100644 (file)
@@ -2,8 +2,6 @@ config olsrd
        # uncomment the following line to use a custom config file instead:
        #option config_file '/etc/olsrd.conf'
 
-       option IpVersion '4'
-
 config LoadPlugin
        option library 'olsrd_arprefresh.so.0.1'
 
index eb13eeeff158afcbb117bfc2351449ff10cb43fb..2afa434874050447f381f917c42a37ffcc6c718e 100644 (file)
@@ -12,3 +12,4 @@ CONF=/var/etc/olsrd4.conf
 PID=/var/run/olsrd4.pid
 
 UCI_CONF_NAME=olsrd4
+OLSRD_OLSRD_SCHEMA="$OLSRD_OLSRD_SCHEMA IpVersion=4"
index a71a2dcb0c672ac58dee7af81cf102d0fe8542c2..37349e4e1173e1ed7addb22a8542144f86908614 100644 (file)
@@ -2,8 +2,6 @@ config olsrd
        # uncomment the following line to use a custom config file instead:
        #option config_file '/etc/olsrd6.conf'
 
-       option IpVersion '6'
-
 config LoadPlugin
        option library 'olsrd_txtinfo.so.0.1'
        option accept '::'
index 71d5dbdfcbdc1724a3cfcdf41024833b28410493..35fba5b4ebb3bfb32b564bbe28697796898ec1a0 100644 (file)
@@ -12,3 +12,4 @@ CONF=/var/etc/olsrd6.conf
 PID=/var/run/olsrd6.pid
 
 UCI_CONF_NAME=olsrd6
+OLSRD_OLSRD_SCHEMA="$OLSRD_OLSRD_SCHEMA IpVersion=6"