olsrd: backward compatibility (config and init script) 37/head
authorAlessio Caiazza <nolith@abisso.org>
Thu, 12 Jun 2014 10:57:12 +0000 (12:57 +0200)
committerAlessio Caiazza <nolith@abisso.org>
Thu, 12 Jun 2014 10:57:12 +0000 (12:57 +0200)
olsrd/Makefile
olsrd/files/olsrd.config [new file with mode: 0644]
olsrd/files/olsrd.hotplug.sh
olsrd/files/olsrd.init
olsrd/files/olsrd4.config [deleted file]
olsrd/files/olsrd4.init
olsrd/files/olsrd6.init

index 48dd7d20402914fefd8d3f0cadfd0fcad4854a4f..e2686d08fd6bd0eb835d3cb014beef1a9147b99e 100644 (file)
@@ -37,7 +37,7 @@ define Package/olsrd
 endef
 
 define Package/olsrd/conffiles
-/etc/config/olsrd4
+/etc/config/olsrd
 /etc/config/olsrd6
 endef
 
@@ -173,41 +173,17 @@ define Package/olsrd/install
        $(INSTALL_DIR) $(1)/lib/functions
        $(INSTALL_DATA) ./files/olsrd.init $(1)/lib/functions/olsrd.sh
        $(INSTALL_DIR) $(1)/etc/config
-       $(INSTALL_DATA) ./files/olsrd4.config $(1)/etc/config/olsrd4
+       $(INSTALL_DATA) ./files/olsrd.config $(1)/etc/config/olsrd
        $(INSTALL_DATA) ./files/olsrd6.config $(1)/etc/config/olsrd6
        $(INSTALL_DIR) $(1)/usr/sbin
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/olsrd $(1)/usr/sbin/
        $(INSTALL_DIR) $(1)/etc/init.d
-       $(INSTALL_BIN) ./files/olsrd4.init $(1)/etc/init.d/olsrd4
+       $(INSTALL_BIN) ./files/olsrd4.init $(1)/etc/init.d/olsrd
        $(INSTALL_BIN) ./files/olsrd6.init $(1)/etc/init.d/olsrd6
        $(INSTALL_DIR) $(1)/etc/hotplug.d/iface
        $(INSTALL_BIN) ./files/olsrd.hotplug.sh $(1)/etc/hotplug.d/iface/50-olsrd
 endef
 
-define Package/olsrd/preinst
-#!/bin/sh
-# check if we are on real system
-if [ -z "$${IPKG_INSTROOT}" ]; then
-       [ -f /etc/config/olsrd ] && cp /etc/config/olsrd /etc/config/olsrd.opkg-old
-fi
-exit 0
-endef
-
-define Package/olsrd/postinst
-#!/bin/sh
-# check if we are on real system
-if [ -z "$${IPKG_INSTROOT}" ]; then
-        if [ -f /etc/config/olsrd.opkg-old ]; then
-               mv /etc/config/olsrd.opkg-old /etc/config/olsrd
-               echo "**********  WARNING  ***************"
-               echo "/etc/config/olsrd is no longer used! This will prevent olsrd to start."
-               echo "Please use /etc/config/olsrd4 for IPv4 and /etc/config/olrsd6 for IPv6"
-               echo "Remember to remove option IpVersion from your config file"
-       fi
-fi
-exit 0
-endef
-
 define Package/olsrd-mod-arprefresh/install
        $(INSTALL_DIR) $(1)/usr/lib
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/arprefresh/olsrd_arprefresh.so.* $(1)/usr/lib/
diff --git a/olsrd/files/olsrd.config b/olsrd/files/olsrd.config
new file mode 100644 (file)
index 0000000..f4ddfd0
--- /dev/null
@@ -0,0 +1,24 @@
+config olsrd
+       # uncomment the following line to use a custom config file instead:
+       #option config_file '/etc/olsrd.conf'
+
+config LoadPlugin
+       option library 'olsrd_arprefresh.so.0.1'
+
+config LoadPlugin
+       option library 'olsrd_dyn_gw.so.0.5'
+
+config LoadPlugin
+       option library 'olsrd_httpinfo.so.0.1'
+       option port '1978'
+       list Net '0.0.0.0 0.0.0.0'
+
+config LoadPlugin
+       option library 'olsrd_nameservice.so.0.3'
+
+config LoadPlugin
+       option library 'olsrd_txtinfo.so.0.1'
+       option accept '0.0.0.0'
+
+config Interface
+       list interface 'wlan'
index 9e5f0ca72cff5126dbeff80c1cb99ab92c0daaf3..99e834ea4c622b16e6baaafbbe0152d6b6fc8abc 100755 (executable)
@@ -52,7 +52,7 @@ case "$ACTION" in
        ifup)
                # only work after the first normal startup
                # also: no need to test, if enabled
-               OLSRD=olsrd4
+               OLSRD=olsrd
                [ -e "/var/etc/$OLSRD.conf" ] && {
                        # INTERFACE = e.g. 'wlanadhocRADIO1' or 'cfg144d8f'
                        # DEVICE    = e.g. 'wlan1-1'
index 5864756465a9b2a465650af8698e8df86430e470..887a4a213e60ec39666490974a098215a105358e 100644 (file)
@@ -15,13 +15,19 @@ 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() {
@@ -391,6 +397,18 @@ olsrd_write_olsrd() {
        [ "$OLSRD_COUNT" -gt 0 ] && return 0
 
        config_get ipversion "$cfg" IpVersion
+       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
 
@@ -614,21 +632,9 @@ 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
@@ -754,13 +760,6 @@ 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=
@@ -793,16 +792,53 @@ start() {
 
        [ -z "$OLSRD_CONFIG_FILE" ] && return 1
 
-       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
+       #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
+               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
        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"
+               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
+                       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'"
+                       }
+               fi
        fi
 
        olsrd_setup_smartgw_rules
@@ -811,4 +847,8 @@ start() {
 stop() {
        SERVICE_PID_FILE="$PID"
        service_stop /usr/sbin/olsrd
+
+       #6and4: backward compatibility
+       SERVICE_PID_FILE="$PID6"
+       service_stop /usr/sbin/olsrd
 }
diff --git a/olsrd/files/olsrd4.config b/olsrd/files/olsrd4.config
deleted file mode 100644 (file)
index f4ddfd0..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-config olsrd
-       # uncomment the following line to use a custom config file instead:
-       #option config_file '/etc/olsrd.conf'
-
-config LoadPlugin
-       option library 'olsrd_arprefresh.so.0.1'
-
-config LoadPlugin
-       option library 'olsrd_dyn_gw.so.0.5'
-
-config LoadPlugin
-       option library 'olsrd_httpinfo.so.0.1'
-       option port '1978'
-       list Net '0.0.0.0 0.0.0.0'
-
-config LoadPlugin
-       option library 'olsrd_nameservice.so.0.3'
-
-config LoadPlugin
-       option library 'olsrd_txtinfo.so.0.1'
-       option accept '0.0.0.0'
-
-config Interface
-       list interface 'wlan'
index 9b08f2d306268419c713cc7a9fd7109075d7cc34..09adf6dc533c5c1ce06c86a7a7bd32c08d5aea86 100644 (file)
@@ -8,8 +8,7 @@ START=65
 SERVICE_DAEMONIZE=1
 SERVICE_WRITE_PID=1
 
-CONF=/var/etc/olsrd4.conf
+CONF=/var/etc/olsrd.conf
 PID=/var/run/olsrd4.pid
 
-UCI_CONF_NAME=olsrd4
-OLSRD_OLSRD_SCHEMA="$OLSRD_OLSRD_SCHEMA IpVersion=4"
+UCI_CONF_NAME=olsrd
index c43cc034e2774eedafeafbcddd419e95cfae6cca..1dcc4a0bdd9215ac4c243ccb78234d357436935d 100644 (file)
@@ -12,4 +12,3 @@ CONF=/var/etc/olsrd6.conf
 PID=/var/run/olsrd6.pid
 
 UCI_CONF_NAME=olsrd6
-OLSRD_OLSRD_SCHEMA="$OLSRD_OLSRD_SCHEMA IpVersion=6"