// OnStop script

$LogD OnStop script


// INTERFACE
//--------------------------

// reset interface ip (delete default gateway)
if $myInterface = tun0
   $LogD interface is tun0. don't shutdown interface 
else
   $LogD busybox ifconfig $myInterface down
   $busybox ifconfig $myInterface down
   //$busybox ifconfig $myInterface 0.0.0.0 up
fi

// ROUTE : revert to old route
//--------------------------------------

//$busybox route add default gateway "$firstdefaultroute" 
if "$firstdefaultroute" = "" then
   $LogD no default route to restore
else
   // route add default gateway ip interface
   $LogD route add default gateway $firstdefaultroute
   $busybox route add default gateway $firstdefaultroute

   if $lastResultSuccess = false then
      $LogE route add default gateway $firstdefaultroute : nok
      $LogE lastResultStdErr   : "$lastResultStdErr"
   else
      $LogD restore default gateway : OK
   fi
fi

//$busybox ifconfig $myInterface down

// reset IPTABLES     
//-------------------------  

//$iptables         -D INPUT    -p icmp -j LOG --log-uid --log-level debug --log-prefix "MYPREROUTING " --log-ip-options
//$iptables         -D OUTPUT -p icmp -j LOG --log-uid --log-level debug --log-prefix "MYPREROUTING " --log-ip-options
//$iptables -t nat -D INPUT    -p icmp -j LOG --log-uid --log-level debug --log-prefix "MYPREROUTING " --log-ip-options
//$iptables -t nat -D OUTPUT -p icmp -j LOG --log-uid --log-level debug --log-prefix "MYPREROUTING " --log-ip-options
//$iptables -t nat -D TETHER  -p icmp -j LOG --log-uid --log-level debug --log-prefix "MYPREROUTING " --log-ip-options

$LogI clean iptables 

$iptables -t nat -D OUTPUT -j TETHER
$iptables -t nat -F TETHER
$iptables -t nat -F
$iptables -t filter -F
$iptables -F
$iptables -t nat --delete-chain TETHER
