Help with recompling chan_sip

Hi All,

So I have been trying to make a change to my chan_sip.so I can get my MWI working with all my Avaya phones. I have it working with two of them and the other two not so much. Anyways here is the rundown:

FreePBX 12.0.76.2
Asterisk 13.5.0

I need to perform the following as per this blog:

change this:

if (!sip_standard_port(p->socket.type, ourport)) {
if (p->socket.type == SIP_TRANSPORT_UDP) {
ast_str_append(&out, 0, "Message-Account: sip:%s@%s:%d\r\n", exten, domain, ourport);
} else {
ast_str_append(&out, 0, "Message-Account: sip:%s@%s:%d;transport=%s\r\n", exten, domain, ourport, sip_get_transport(p->socket.type));
}
} else {
if (p->socket.type == SIP_TRANSPORT_UDP) {
ast_str_append(&out, 0, "Message-Account: sip:%s@%s\r\n", exten, domain);
} else {
ast_str_append(&out, 0, "Message-Account: sip:%s@%s:%d;transport=%s\r\n", exten, domain, ourport, sip_get_transport(p->socket.type));
}
}

To This:

if (!sip_standard_port(p->socket.type, ourport)) {
if (p->socket.type == SIP_TRANSPORT_UDP) {
ast_str_append(&out, 0, "Message-Account: sip:%s@%s:%d\r\n", exten, domain, ourport);
} else {
ast_str_append(&out, 0, "Message-Account: sip:%s@%s:%d\r\n", exten, domain, ourport);
}
} else {
if (p->socket.type == SIP_TRANSPORT_UDP) {
ast_str_append(&out, 0, "Message-Account: sip:%s@%s\r\n", exten, domain);
} else {
ast_str_append(&out, 0, "Message-Account: sip:%s@%s\r\n", exten, domain);
}
}

Now here is what I have tried. I followed the guide to manually installing freepbx for cent OS etc. I have downloaded the source files for my version of asterisk 13.0.5 and made the changes to the chan_sip file and was able to recompile the code.

The big problem is that when I look at the chan_sip.so compiled file sizes they are way off. So the existing one that comes with the distro I have is only 941Kb very small. The complied one that I end up with is 4.5Mb which I figured was weird. I SSH’d into freepbx copied the newly compiled file over and then performed an amportal restart.

Well that didn’t work because although I could still get access to the admin webpage I could see that the phone link was down hence asterisk was not starting.

Can someone provide some help on how I can achieve this, I think it’s the key to getting these Avaya phones (at least the newer firmwares) to be able to speak nicely with SIP notify tag.

Thanks very much!

I would follow an OS appropriate “build from scratch” recipe in the wiki , unless you compile with the same flags then the modules likely won’t load on another build, apply your patches before the ./configure stage (not too important) and use the “install_prereq” and “make menuselect” options for simplicity

Thanks dicko, I appreciate the help. Any reason why the compiled Chan_sip file is so small compared to the one you compile regularly in asterisk?

Regards

It’s all about the flags you used and what ./configure came up with, presumably you have various debug symbology compiled in, or not availing shared libraries.

okay so i tried what you suggested and the only difference being that i used ubuntu as the operating system to build from scratch instead of Cent OS. But the file size for chan_sip is still 3.9Mb. So still not sure what needs to be done. I am not sure exactly if building in cent OS would make a difference.

Also not sure if this makes a difference but for my version of FreePBX 12.0.76.2 you can switch between versions of asterisk and I am using 13. I can only find one chan_sip when I search the directories. So I am assuming that if it is using asterisk 13 that’s the only place is referencing the chan_sip. I thought if there are multiple locations since it supports multiple versions of asterisk then there would be a possibility of a few different sized chan_sip files in different locations. No such luck.

Thanks

It could be due to debug symbols being embedded into the binary after compilation; This space is too small to explain this, but either there would/should be a ./configure flag that tells the build system to build it with debug symbols, or a step that invokes the ‘strip’ program somehow, or a compiler/linker flag that would tell it to build with debug info ‘external’ (to create a separate symbol file). Debug symbols are usually large, because they contain names (in human-readable form) of every function, variable and whatnot. They are needed if you need to actually debug the program for gdb (or your choice of debugger) to show you pretty names rather than addresses in the binary. Some /not all/ are needed if the program is a dynamically loadable module, so that the dynamic linker can actually have a clue what to call is where in the binary. Therefore the step to strip the built binary is usually performed by the build system, because calling ‘strip’ on a ready binary can damage it beyond repair. So much for theory :wink:

el_es

Thanks for the explanation, makes sense to me and I appreciate you taking the time to break it down for me. Here is the section from the freepbx manual build documentation:

cd /usr/srctar
xvfz asterisk-13-current.tar.gz
rm -f asterisk-13-current.tar.gz
cd asterisk-*
contrib/scripts/install_prereq install
./configure --libdir=/usr/lib64
contrib/scripts/get_mp3_source.sh
make menuselect

I am assuming that this is where the configure part would have some extra details to strip out debugging etc. But not much stated there unless there are other things in the process that I am missing. What I focused on were all the steps prior to the installation of asterisk and once I had run the make command I didn’t bother with the actuall install of freepbx etc because I figured the chan_sip was already compiled. Am I correct in my logic?

http://wiki.freepbx.org/display/FOP/Installing+FreePBX+12+on+CentOS+6.5

Thanks very much, I’m excited to get this working I just know this is the issue to fix my problems albeit very small with these phones.

Thanks!

You need to follow the correct recipe, if you are in fact using a modern Debian based OS then --libdir=/usr/lib64 will spoil your whole day, if you don’t do the “make install” and any clean-ups necessary then all bets are off.

okay gotcha! see freepbx that I am running is on centOS so what I am thinking is i have to follow that guide and get a VM running with centos and go through the whole process because I have been doing this in a ubuntu VM which now after reading what you posted sounds like the best approach.

What do you think?

It’s just four basic commands needed:-

./configure
make menuconfig
make
make install

fix any problems as you encounter them, follow the tried and proven recipes specific to your particular OS and there will be few if any problems. It is “possible” to cross-compile for Centos on Debian, but I don’t suggest it for a newbie.

OK, so,
first I have to say, I never compiled Asterisk or chan_sip myself; what I’m saying is from previous experience compiling other stuff that usually follows the ./configure; make [multiple invocations of]; make install;

  • the size of executable may not only be coming from debug symbols; there is also ‘a thing’ called static linking, where the final stage of linking takes ALL the code from various libraries and embeds it into the executable; in that case, you don’t need to worry about the size; but the executable could then be using old/outdated versions of system libraries [the ones found at the time of linking] - which isn’t very ‘cool’ in Linux world :wink: This however works another way in favor too, if you find that a system library update has gone AWOL with an incompatible [with your program] change, the dynamically linked ones /could/ stop working properly;It’s probably unlikely to happen in a stable distribution though, in this day and age ;). This aspect is also controlled usually by flags given to ./configure and/or in make menuconfig;
  • If you don’t know what’s going on, the ./configure is usually a shell script; so a good text editor runnable in console with syntax highlighting [e.g. Midnight Commanders’ mcedit] can do wonders; there is usually a very established pattern to that file, and some of them have good embedded comments too. Sometimes even respond to ./configure --help to give you the possible choices.
  • Makefiles can be difficult to follow however not impossible.

Hi el_es, wow thanks for explaining this all. It’s definitely a great read for a newbie in linux, I tried the whole process for what was outlined in the ubuntu instructions and after following it to a tee and correcting any errors I got the same file size as before 4Mb after the make install. So I think I have to spool up a VM of centOS and follow the instructions for that one. I’m not sure what they are doing for the distro to get that size as 941Kb. It seems to me the correct route to go because the freepbx distro is based on just that centOS.

I am hoping that after I try this tonight it should give me the right size unless they have a different method for building the distro version.

Thanks very much!

I however have been compiling asterisk on various OS’s for quite a few years. From the horses mouth :-

https://wiki.asterisk.org/wiki/display/AST/Installing+Asterisk+From+Source

(but don’t do the “make samples” bit :wink: )

However if you looked at the lines below your patch in chan_sip.c you will surely see a comment

/* Cisco has a bug in the SIP stack where it can’t accept the
(0/0) notification. This can temporarily be disabled in
sip.conf with the “buggymwi” option */

then an apparent fix for it. Maybe you should try that first as it might already be covered just do it the FreePBX way and don’t modify sip.conf.

echo ‘buggymwi=yes’ >> /etc/asterisk/sip_general_custom.conf;rasterisk -x “sip reload”

Hi dicko,

Thanks very much for that I appreciate it. I had looked into that but because that is cisco specific it will not work for me. I have some Avaya phones that do work with the default chan_sip but not all of them and also only for a specific firmware then they changed how they handle that SIP NOTIFY.

Okay update time, so I created a VM with CentOS 6.5 and followed that exactly as stated in the wiki. Again the chan_sip.so turned out to be 4Mb. Infact looking at nearly all the modules they are significantly larger in size so they must be doing something to get all those files sizes down.

I’m at a total loss now since I have followed everything. Unless there is another location that I have to look at but so far there are only one modules folder in usr/lib64/asterisk/modules.

Thanks for being patient with me guys, I do appreciate the help. Maybe it’s not even releavant but doing a version switch I notice all the stuff is being downloaded from
jenkins-builder1.schmoozecom.net which is probably already compiled etc, not sure if the instructions they give online will still yield a working freepbx system albiet one that is not quite the same as the distro they provide online. I’ve no idea who compiles those but I’d sure like to figure this out.

Thanks!

There could /still/ be one case I forgot to mention :wink:

Compiler Optimization Flags.
Certain compiler flags (man gcc?) have an effect on trading execution speed/performance for size: because not /all/ machine code duplication is /always/ bad - if all ‘repeatable’ code is split into ‘sub-routines’ you get significantly less machine code to load; but the cost of ‘jumping’ to the repeatable sections can be high, especially in tight loops (jumps can take time especially if cache / tlb is reloaded) but on the other side of the coin is, loading large binary into memory increases cpu cache misses too, which is bad, too (again this place is to small to explain all that) :wink: Proper answer, i guess, usually is: first you try, then you know which is better for you :wink:

Which (again) is (should be) controlled by either the ./configure flags or switches or the make menuconfig step. Or in the code of either script itself.

Other than that, why do you care so much about the size of it? If it works, and doesn’t give ‘odd’ behavior like 100% cpu in normal conditions, based on official description, and is able to verify itself working, I probably wouldn’t care all /that/ much :wink:

Thanks, yes I did try to load just the chan_sip module before although it says asterisk started when I did a amportal restart the server link was down on the phones so I know something was not loading properly. But maybe I just have just copied all the modules over instead of just the one? Not sure I could try a few things. Here is what I am thinking now as you mentioned it only dawned on me at 3am but I should just complete the VM build and just use that freepbx instance and see if it works. As long as it does then I should be fine instead of having to tweak these specific distro’s. I’m going to give it a shot :smile:

Since I built out 90% why not just get the whole thing going. As long as it works i really don’t care too much.

Okay just an update thanks again to you both for helping me with this. So I did compile fully the whole freepbx build on centos7 from start to finish and the compiled chan_sip.c file was still 4Mb in size. So it seems aparent to me that the freepbx distro is compiled a bit different than the manual build but it does build fine. So thanks for all the explanations and help to get that far.

Turns out after all that the patch didn’t seem to work anyways. Any Avaya experts out there that might be able to help?

Thanks again all, great community that we have here! I appreciate the help as always.