What's new

How I have installed Asterisk on ASUS router

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

rampitec

Occasional Visitor
This is the small howto install asterisk on the router.

Why? Maybe there are other guides, but I have seen guides involving chrooted Debian which is an overkill to me, and then I have seen a lot of forum posts about problems without any resolution. Maybe I missed something, but that is how I did it.

Result: asterisk running on Asus, available from inet and local network.

Start with Merlin ASUS FW.

Install optware-ng on a USB stick. 2Gb is sufficient. Optware guide is good and everything works. Make sure to format flash drive as a sort of ext filesystem. I'm using ext3.

In optware install asterisk:

Code:
ipkg install asterisk18 asterisk14-core-sounds-en-alaw asterisk14-extra-sounds-en-alaw asterisk14-moh-freeplay-alaw

I have also installed some of its recommended packages. Do not recall the list now, as asterisk is not the only
thing I have installed from optware. Install all it recommends if not sure, it does not harm. Install tz, you will need it. Install xmlrpc-c, libxml2 and libxslt. Not sure if all are needed, but some are. Install sqlite.
You do not need jabberd and net-snmp to to run asterisk, they will sit in memory so do not install them.

Now these are essential files I have modified:

asterisk.conf
cdr.conf
extensions.conf
sip.conf

This will be not a complete config of all clients, but an essential portion needed for this kind of setup.

asterisk.conf
:
add into options section:

Code:
[options]
runuser = nobody
rungroup = nobody
live_dangerously = no

cdr.conf:
Code:
[scv]
usegmtime=no

extensions.conf:
Your extensions go here...

voicemail.conf:
configure your voicemail here...

sip.conf:
Code:
[general]
context=default
allowgest=no
allowoverlap=no
bindport=45060  ; Choose your own ;)
bindaddr=0.0.0.0
srvlookup=yes
disallow=all
allow=ulaw
allow=alaw
alwaysauthreject=yes
nat=comedia
directmedia=no
externhost = my.fdqn.com
externrefresh = 120
session-timers=refuse
localnet=192.168.0.0/255.255.0.0 ; your local subnet, this is mine
rtptimeout=60
rtpkeepalive=60
mwi_from=asterisk
pedantic=no
dtmfmode=auto
registertimeout=120

So in sip.conf you request to bind to both external and internal interface, that is important for router setup.
directmedia is set to no, while could be set to nonat. Too bad I cannot be sure all my peers support that (they do not in fact), so I will have to live with all RTP traffic routed through the router. That is unfortunate, but if you are more lucky with peers you can try nonat setting. Above config will always work however.

What else? You do not need any firewall rules and you do not need to change SIP passthrough in router's setup either. It works with any setting. Unless you have specifically blocked your ports or enabled firewall all traffic on INPUT chain is accepted as well, no need to change anything. You definitely do not need any forwarding rules. Just in case, that is how my INPUT chain looks like:

Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT udp -- anywhere anywhere udp dpt:1194

Nothing specific to asterisk.

Now you need a script to start it, put S71asterisk into /opt/init.d/ (do not forget to chmod +x /opt/init.d/S71asterisk):

#!/bin/sh

prefix="/opt"
PATH=${prefix}/bin:${prefix}/sbin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=asterisk
DAEMON=${prefix}/sbin/${NAME}
DAEMON_OPTS=""

test -x $DAEMON || exit 0

ln -sf /opt/share/zoneinfo/America/Los_Angeles /etc/localtime

if [ -z "$1" ] ; then
case `echo "$0" | sed 's:^.*/\(.*\):\1:g'` in
S??*) rc="start" ;;
K??*) rc="stop" ;;
*) rc="usage" ;;
esac
else
rc="$1"
fi

case "$rc" in
start)
echo "Starting service: $NAME"
$DAEMON $DAEMON_OPTS
;;
stop)
if [ -n "`pidof $NAME`" ]; then
echo "Stopping service: $NAME"
killall $NAME 2> /dev/null
fi
;;
restart)
"$0" stop
sleep 1
"$0" start
;;
*)
echo "Usage: $0 (start|stop|restart|usage)"
;;
esac

exit 0

Problems:

  1. Log will use wrong time and GotoIfTime will not work unless you install tz data and link /opt/share/zoneinfo/America/Los_Angeles to /etc/localtime at asterisk start. That is included in the above script.

    Change
    America/Los_Angeles to your own timezone!

  2. Your log will be flooded with warning messages about missing xmldoc.

    This is bad because it obscures real errors in the /opt/var/log/asterisk/messages, but that also results in that file growing too big too fast. You will run out of space on the flash pretty soon unless you use a good logrotate. These are tons of warnings like this:

    [Jan 18 21:06:00] WARNING[12089] xmldoc.c: Couldn't find manager DataGet in XML documentation

    The proper solution is to rebuild asterisk yourself with --disable-xmldoc. I do not think I want a fun of crosscompilng for ARM or building on a router. So I decided to look, what's the problem. Documentation is actually installed into /opt/var/lib/asterisk/documentation, but asterisk uses glob() function to search for it. Unfortunately router's library does not support the mighty syntax asterisk uses, see its sources (xmldoc.c):

    if (ast_asprintf(&xmlpattern, "%s/documentation{/thirdparty/,/}*-{%s,%.2s_??,%s}.xml", ast_config_AST_DATA_DIR,
    ...
    globret = glob(xmlpattern, MY_GLOB_FLAGS, NULL, &globbuf);

    As a result glob returns just what it got, and asterisk tries to open file which does not exist:
    open("/opt/var/lib/asterisk/documentation{/thirdparty/,", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = -1 ENOENT (No such file or directory)

    I have just opened /opt/sbin/asterisk in the editor and replaced above string with simple:
    Code:
    %s/documentation/core-en_US.xml
    If you do it yourself do not forget to place terminating 0 after ".xml". You can try to apply my patch.
    Comparing files asterisk.bak and ASTERISK-PATCHED
    001B2938: 7B 2F
    001B2939: 2F 63
    001B293A: 74 6F
    001B293B: 68 72
    001B293C: 69 65
    001B293D: 72 2D
    001B293E: 64 65
    001B293F: 70 6E
    001B2940: 61 5F
    001B2941: 72 55
    001B2942: 74 53
    001B2943: 79 2E
    001B2944: 2F 78
    001B2945: 2C 6D
    001B2946: 2F 6C
    001B2947: 7D 00
    001B2948: 2A 20
    001B2949: 2D 20
    001B294A: 7B 20
    001B294B: 25 20
    001B294C: 73 20
    001B294D: 2C 20
    001B294E: 25 20
    001B294F: 2E 20
    001B2950: 32 20
    001B2951: 73 20
    001B2952: 5F 20
    001B2953: 3F 20
    001B2954: 3F 20
    001B2955: 2C 20
    001B2956: 25 20
    001B2957: 73 20
    001B2958: 7D 20
    001B2959: 2E 20
    001B295A: 78 20
    001B295B: 6D 20
    001B295C: 6C 20
    001B295D: 00 20

    MD5 sums of original and patched files:
    6839c93c53956dca3b7c78177f9f79fa *asterisk-patched
    4ec68737cfefb0db02ddb067d63fda1d *asterisk.bak

    Of course everything after 001B2948 is just not needed, you can omit it if you wish.

  3. So far it works good. However, router sometimes becomes unresponsive.
    It still routes, but ssh session freezes and disconnects. That is not the issue specific to asterisk, but can affect you. One way to achieve that with asterisk is to connect two asterisk clients with the same number from different devices, call your own number on one of them and pick the call on another. It will kill the router ;) Otherwise when I just use it normally it seems to live so far.

  4. I would like a watchdog to restart died service. Not that it died as long as I run it, but it can.
A final word, this is the load from `top' when asterisk is idle:

Mem: 78136K used, 177564K free, 6376K shrd, 636K buff, 19940K cached
CPU: 0.0% usr 0.1% sys 0.0% nic 99.6% idle 0.0% io 0.0% irq 0.0% sirq
Load average: 0.00 0.02 0.05 1/113 28708
PID PPID USER STAT VSZ %VSZ CPU %CPU COMMAND
920 1 nobody S 33828 13.2 1 0.0 /opt/sbin/asterisk

It consumes some memory, but not CPU.

I hope this will help at least somebody.
 
This is awesome!

I'm a telecoms consultant and had been pondering doing this since I got the router but not tried. Given how simple it appears I'll be sure to have a play.

Many Thanks, and I'll report back with any findings of interest.


Sent from my iPhone using Tapatalk
 
Spectacular! Could you please recall and approximate amount of storage it required? Have you face any special difficulties?
 
Spectacular! Could you please recall and approximate amount of storage it required? Have you face any special difficulties?

Code:
# df -h /tmp/mnt/OPTWARE
Filesystem                Size      Used Available Use% Mounted on
/dev/sda1                 1.8G    949.3M    835.1M  53% /tmp/mnt/OPTWARE

For the special difficulties specific to the router setup of Asterisk, I have attempted to describe them all in the post.

I can also tell that I'm still running that setup without any issues our downtimes other than because of internet downtime itself. The router also has several Merlin FW upgrades since then and setup has survived them all so far.
 
Cool. Have you tried to attach GSM USB dongles to this setup?
Now I am running my FreeBPX on the Raspberry PI and considering moving all this stuff to router for better integrity.
 
Well, I can add that dongle runs excellent too, though I used Entware, not Optware. Asterisk just added a couple of supplementary packages and that's it! Work like "out-of-the-box".
 
I also spent last night getting Asterisk installed via Entware. It was fairly straight forward. Running a conference bridge on it now for my business :)

I actually didn't need to do much of the above (mainly the running as nobody actually breaks permissions). Main change I made was [directories] section was set as a template (!) so it wasn't finding the default sounds dir until I removed the (!) flag.
 

Similar threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top