View Single Post
Posts: 306 | Thanked: 106 times | Joined on Feb 2010
#1
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
__________________
------------------------------------------------------------------
Voice choppy on sip calls
Please vote for bug number 10388

Last edited by rajil.s; 2010-07-16 at 22:23. Reason: Fixed dnsmasq in the router
 

The Following 5 Users Say Thank You to rajil.s For This Useful Post: