OpenWrt Forum Archive

Topic: vpnc-0.3.3 script issues

The content of this topic has been archived on 7 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

hi...

the vpnc-0.3.3 comes with a script that handles the routing when connecting/disconnecting the vpn connection...

when calling vpnc so that the vpn client connects, i get the following error:

/etc/vpnc/vpnc-script: 222: Syntax error: Bad for loop variable

a look in the script shows this line:

for ((i = 0 ; i < CISCO_SPLIT_INC ; i++ )) ; do

the interpreter for this script is #!/bin/sh, and with busybox this is the ash.

what's the right syntax for the 'for'-statement, couldn't find answers via goole...


greetz
badboy

(Last edited by BadBoyForLife81 on 7 Feb 2006, 17:16)

ok, after rewriting the critical statement and replacing it with 'while ... do' the script works for me.

this is the diff-file:

--- vpnc-0.3.3/vpnc-script      2005-05-05 19:05:18.000000000 +0200
+++ vpnc-0.3.3-PATCHED/vpnc-script      2006-02-07 17:35:24.000000000 +0100
@@ -219,11 +219,13 @@
        do_ifconfig
        set_vpngateway_route
        if [ -n "$CISCO_SPLIT_INC" ]; then
-               for ((i = 0 ; i < CISCO_SPLIT_INC ; i++ )) ; do
+               i=0
+               while i < CISCO_SPLIT_INC ; do
                        eval NETWORK="\${CISCO_SPLIT_INC_${i}_ADDR}"
                        eval NETMASK="\${CISCO_SPLIT_INC_${i}_MASK}"
                        eval NETMASKLEN="\${CISCO_SPLIT_INC_${i}_MASKLEN}"
                        set_network_route "$NETWORK" "$NETMASK" "$NETMASKLEN"
+                       i++
                done
                for i in $INTERNAL_IP4_DNS ; do
                        set_network_route "$i" "255.255.255.255" "32"
@@ -239,11 +241,13 @@
 
 do_disconnect() {
        if [ -n "$CISCO_SPLIT_INC" ]; then
-               for ((i = 0 ; i < CISCO_SPLIT_INC ; i++ )) ; do
+               i=0                                                                          
+               while i < CISCO_SPLIT_INC ; do    
                        eval NETWORK="\${CISCO_SPLIT_INC_${i}_ADDR}"
                        eval NETMASK="\${CISCO_SPLIT_INC_${i}_MASK}"
                        eval NETMASKLEN="\${CISCO_SPLIT_INC_${i}_MASKLEN}"
                        del_network_route "$NETWORK" "$NETMASK" "$NETMASKLEN"
+                       i++
                done
                for i in $INTERNAL_IP4_DNS ; do
                        del_network_route "$i" "255.255.255.255" "32"

how can i get this patch into the trac subversion directory?

anyone who can review it?

This syntax is the bash-3.0 new syntax for "for loops", as the CISCO_SPLIT_INC variable may be big, I recommend you replace your for by a while.

while (i < CISCO_SPLIT_INC)
do
    i=$(($i+1));
    things ...
done

@ritalman:

sorry, don't see where the main difference between the two solutions is...
cause the i=$(($i+1)); is the same as i++


greets badboy

The discussion might have continued from here.