maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Nokia N900 (https://talk.maemo.org/forumdisplay.php?f=44)
-   -   [Solved] Sip over Openvpn on 3g and wifi (https://talk.maemo.org/showthread.php?t=58537)

rajil.s 2010-07-15 18:21

[Solved] Sip over Openvpn on 3g and wifi
 
Hi,

I have finally a working sip over openvpn today and wanted to post about it for everybodys benefit. I have tested this both on 3g (using three UK) and wifi. Here are the following files needed. All these files go in /etc/openvpn.

First the client config
Code:

#cat  openvpn_client.conf
client
script-security 2
up /etc/openvpn/nokia.up
down /etc/openvpn/nokia.down
ipchange /etc/openvpn/add_default_route.sh
dev tun
proto udp
remote xx.dyndns.org 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert client.crt
key client.key
comp-lzo
verb 3

nokia.up script
Code:


# cat nokia.up
#!/bin/bash

case $script_type in

up)
    for optionname in ${!foreign_option_*} ; do
        option="${!optionname}"
        echo $option
        part1=$(echo "$option" | cut -d " " -f 1)
        if [ "$part1" == "dhcp-option" ] ; then
            part2=$(echo "$option" | cut -d " " -f 2)
            part3=$(echo "$option" | cut -d " " -f 3)
            if [ "$part2" == "DNS" ] ; then
                IF_DNS_NAMESERVERS="$IF_DNS_NAMESERVERS $part3"
            fi
            if [ "$part2" == "DOMAIN" ] ; then
                IF_DNS_SEARCH="$part3"
            fi
        fi
    done
    R=""
    if [ "$IF_DNS_SEARCH" ] ; then
        R="${R}search $IF_DNS_SEARCH\n"
    fi
    for NS in $IF_DNS_NAMESERVERS ; do
        R="${R}nameserver $NS\n"
    done
    if [ ! -f /etc/resolv.conf.prevpn ] ; then
        mv /etc/resolv.conf /etc/resolv.conf.prevpn
    fi
    echo -e "$R" > /etc/resolv.conf
    ;;

down)
    if [ -f /etc/resolv.conf.prevpn ] ; then
        mv /etc/resolv.conf.prevpn /etc/resolv.conf
    fi
    ;;

esac


source /etc/osso-af-init/af-defines.sh

for acct in `mc-tool list | grep sofiasip/sip`; do
        mc-tool update $acct string:local-ip-address=$4

done

nokia.down script


Code:


#cat nokia.down

#!/bin/bash

case $script_type in

up)
    for optionname in ${!foreign_option_*} ; do
        option="${!optionname}"
        echo $option
        part1=$(echo "$option" | cut -d " " -f 1)
        if [ "$part1" == "dhcp-option" ] ; then
            part2=$(echo "$option" | cut -d " " -f 2)
            part3=$(echo "$option" | cut -d " " -f 3)
            if [ "$part2" == "DNS" ] ; then
                IF_DNS_NAMESERVERS="$IF_DNS_NAMESERVERS $part3"
            fi
            if [ "$part2" == "DOMAIN" ] ; then
                IF_DNS_SEARCH="$part3"
            fi
        fi
    done
    R=""
    if [ "$IF_DNS_SEARCH" ] ; then
        R="${R}search $IF_DNS_SEARCH\n"
    fi
    for NS in $IF_DNS_NAMESERVERS ; do
        R="${R}nameserver $NS\n"
    done
    if [ ! -f /etc/resolv.conf.prevpn ] ; then
        mv /etc/resolv.conf /etc/resolv.conf.prevpn
    fi
    echo -e "$R" > /etc/resolv.conf
    ;;

down)
    if [ -f /etc/resolv.conf.prevpn ] ; then
        mv /etc/resolv.conf.prevpn /etc/resolv.conf
    fi
    ;;

esac


source /etc/osso-af-init/af-defines.sh

for acct in `mc-tool list | grep sofiasip/sip`; do
        mc-tool update $acct clear:local-ip-address
done

andf finally default route script

Code:


#cat add_default_route.sh

#!/bin/sh

#if gprs0 up and no flagged default route ; then create one
#use with ipchange /etc/openvpn/add_default_route.sh in openvpn conf
#after setting script-security 2
gprsroute=`route | grep gprs` ; defroute=`route | grep default | grep G` ; if [ -n "$gprsroute" -a -z "$defroute" ]; then nexthop=`ifconfig gprs0 | grep "inet addr" | cut -d : -f 3 | cut -d " " -f 1` ; route add -host $nexthop dev gprs0 ; route add default gw $nexthop ; fi

Also wanted to add that this method works well if the sip provider is hosted outside the network. However in my case i have an asterisk server running inside my local network at 172.16.1.10. Thus i have to change my sip uri to reflect the internal asterisk server to 50@172.16.1.10 whereas normally i would simply use 50@xx.dyndns.org. This is a big pain because i have to keep switching between the two accounts depending on whether i am usng vpn or not. If somebody has any workaround please let me know.

Ok. The above issue is sorted. I use a Linksys WRT54GL router running dd-wrt. I had to simply add an extra arguement to dnsmasq as

Code:

address=/xx.dyndns.org/172.16.1.10

9000 2010-07-16 04:03

Re: [Solved] Sip over Openvpn on 3g and wifi
 
I don't use it atm but I'll bookmark it for future use. Thank you very much for your sharing.

hellhammer 2010-07-16 04:35

Re: [Solved] Sip over Openvpn on 3g and wifi
 
thank you very much good sir.

mrwhy 2011-01-07 18:08

Re: [Solved] Sip over Openvpn on 3g and wifi
 
Hi Rajil.S

Iīm trying your way, but something wonīt work.

I think i donīt need the way with default route.

The problem is in executing the scripts.

OpenVPN throws an error :

script failed: could not execute external program

in my openvpn config i have also set the script-security to 2 and the rights on the scripts are 755 but i donīt work.

Do you have an idea?

Thanks very much
Greetz

Mr.

rajil.s 2011-01-07 19:11

Re: [Solved] Sip over Openvpn on 3g and wifi
 
do you have mc-tool installed?

praveenchand 2011-01-07 22:06

Re: [Solved] Sip over Openvpn on 3g and wifi
 
rajil, i want to setup sip over openvpn, please let me know step by step procedure. I have dyndns account, have installed mc-tools, but dnt know how to configure that, please explain. thanks.

worldclass85 2011-04-08 15:50

Re: [Solved] Sip over Openvpn on 3g and wifi
 
Hi rajil,

I know this is a dead thread. but any chance you could show the server config file for openvpn? That's were most of the action seems to be taking place. I have windows running openvpn server. I hope it is something that windows can handle without iptables.

I know you used the dev tun and I'd like to know if you think bridging (dev tap) works as well.


All times are GMT. The time now is 14:08.

vBulletin® Version 3.8.8