[Home]

Summary:ASTERISK-00844: [patch] sip debug [peername]
Reporter:Brian West (bkw918)Labels:
Date Opened:2004-01-14 19:59:14.000-0600Date Closed:2008-01-15 14:53:00.000-0600
Priority:MajorRegression?No
Status:Closed/CompleteComponents:Core/General
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) ast_debug.txt
( 1) ast_debug2.txt
( 2) ast_debug3.txt
( 3) ast_debug4.txt
( 4) ast_debug5.txt
( 5) ast_debug6.txt
( 6) ast_debug7.txt
( 7) ast_debug8.txt
( 8) sip_debug_peer1_diff.txt
( 9) sip_debug_peer2_diff.txt
Description:I would like the ability to debug messages to and from a specific peer.  On a busy system this would be more than handy to trouble shoot something.
Comments:By: z_smurf (z_smurf) 2004-01-18 19:31:15.000-0600

I am working on this and will post a patch soon.
Also there till be three levels of debugging.

By: z_smurf (z_smurf) 2004-01-19 08:28:59.000-0600

Please try my patch against the latest cvs.

New features:

* Three levels of SIP-debugging:
a) Show only sip-headers, Direction (to or from asterisk), and IP/Port/extension
b) Same as A but full SIP-packet
c) Same as B but allso old sipdebug-comments

* Debug filter list:
A list with IP/Port pairs, which affects from/to which hosts the sipdebug will write out. Four new commands to edit/view this list is implemented. It is possible to filter for an IP and port, or only an IP.

* sip show peer:
Gives detailed information about a peer.

I am not too familiar with asterisk, and maybe there should be some locks on the filter-list? I did not implement that.

Please try this out, and if there is no big problems, add it to CVS.

//Andreas

By: z_smurf (z_smurf) 2004-01-19 09:43:41.000-0600

There is a bug: if debug is enabled while a peer registers, asterisks hangs.

By: Brian West (bkw918) 2004-01-19 12:57:44.000-0600

chan_sip.c:4255:1: warning: "FORMAT2" redefined
chan_sip.c:437:1: warning: this is the location of the previous definition


Fix that also :)

By: Olle Johansson (oej) 2004-01-19 15:11:01.000-0600

I've implemented a similar solution without the CLI commands in chan_sip2. From reading your text, this seems better. The only difference I had, which you could easily add, is adding an option to avoid "OPTIONS" and "NOTIFY" messages, if you only want to see REGISTERs and INVITES. This was needed in my own installation to be able to see anything interesting. All those OPTIONS messages for qualify= and NOTIFY for voicemail was not very irritating...

By: Olle Johansson (oej) 2004-01-19 15:18:13.000-0600

Really good stuff, now I've read the code. While coding my dirty hack compared to this, I was wondering if we could reuse the ha structure used for permit-deny. Seems like you are implementing something similar here for filtering on ip/port and it would be better for the overall code to reuse those functions that already exist. You'll find them in acl.c. With them one could add filters on network level, like 192.168.0.0/16

I'll be testing this patch during the weekend, will be gone for a conference for a couple of days.

By: z_smurf (z_smurf) 2004-01-19 15:35:30.000-0600

ast_debug2.txt is the same patch as before, added are two bugfixes:
1) Does not lock asterisk when debugging a "REGISTER" event
2) Fixed bkw918´s compilation warnings.

By: z_smurf (z_smurf) 2004-01-19 15:48:16.000-0600

oej: Yes, a filter on networklevel would be better.
And yes, the code would be much better if it could reuse existing functions in acl.s. I am not familiar with those functions, and I dont think I'll be able to rewrite nicer code by using those functions, so I leave this to someone else.

Your idea to filter certain SIP-events is a good idea and would'nt be too hard to implement in my patch.

But before I am trying to do that, I would like to know how to disable the annoying asterisk-output that comes in the middle of my debugging-output... For example "Extension xxx is ringing...", "Trying Native bridge... " ... That stuff does not come from chan_sip.c.

//Andreas

By: Brian West (bkw918) 2004-01-19 22:26:41.000-0600

This is nice but it changes the sip debug output a bit.. can you add some extra line feeds between packets.

By: z_smurf (z_smurf) 2004-01-20 01:41:57.000-0600

Right now every empty line is stripped, maybe that is not what we want when debugging the full sip-packets.
I personally dont see any need of seeing theese blank lines, we can sure put them back if they are any use :)
I'll do that later.

By: Brian West (bkw918) 2004-01-21 01:14:08.000-0600

also have you ran this under valgrind yet?

By: z_smurf (z_smurf) 2004-01-21 04:10:21.000-0600

Sorry, what is valgrind?

By: z_smurf (z_smurf) 2004-01-24 20:33:20.000-0600

ast_debug4.txt:
* Fixed output-formatting to not strip any empty lines
* Fixed seg-fault when trying filter non existing peer
* Fixed read of unallocated memory (found via valgrind)

By: z_smurf (z_smurf) 2004-01-25 19:49:25.000-0600

ast_debug5.txt
* Updated against latest CVS
* Changed output to not show the PORT if 5060
* Changed output to show CSeq in all debugginglevels
* Removed "sip show peer [peer]". This has nothing to do with this patch.

By: z_smurf (z_smurf) 2004-02-24 20:24:37.000-0600

ast_debug6.txt
* Added support for mysql_friends
* Renamed debugging-commands:

sip dfilter add peer <peername>
sip dfilter add ip <host[:port]>
sip dfilter clear
sip show dfilter
sip debug <level 1-3>
sip no debug

By: Matteo Brancaleoni (mbrancaleoni) 2004-02-25 06:26:01.000-0600

mmh, seems that sip dfilter add peer <peername> when peername is a mysql one
doesn't work (ie. I can set the dfilter,  but no output is given)

dfilter by ip works ok for me.

*news*
after further investigation I noticed that the peer is used if I enable also ip filter, so doing:
sip dfilter add ip <ipaddr>
and then
sip dfilter add peer <peername>

reading better the code, I noticed that the func. filter_sip_debug
first matches the ipaddr, THEN the peer.
Since specifyng only a peer , the filter addr is set to 0.0.0.0 then
x.x.x.x is != from 0.0.0.0, so peer checking is never reached.

edited on: 02-25-04 06:17

By: z_smurf (z_smurf) 2004-02-25 10:36:32.000-0600

"sip dfilter add peer <peername>" copies the IP/port from peername.
If peername is not registered, the IP will be 0.0.0.0, and then the debug will not work. It does not matter if peername is a mysql-peer or a static peer.

Maybe a warning in "sip dfilter add peer <peername>" about this would be helpful.

By: zoa (zoa) 2004-02-25 11:27:08.000-0600

z_smurf, could you add this?, i want a lot if people to test this and get it into cvs

By: z_smurf (z_smurf) 2004-02-26 16:35:25.000-0600

ast_debug7.txt
* Added warning if adding unregistered peer.

By: scaredycat (scaredycat) 2004-03-16 08:57:03.000-0600

Has this made it into cvs yet?

By: zoa (zoa) 2004-03-16 10:59:42.000-0600

nopez, but its in chan_sip2

Try it, if its stable and we find enough people that use it without problems, we might put this in cvs.

By: Brian West (bkw918) 2004-04-18 02:01:46

lets get this updated for cvs-head if we can... and get the kram stamp of approval on it.

bkw

By: twisted (twisted) 2004-04-19 22:53:05

I second that.

By: z_smurf (z_smurf) 2004-04-20 20:47:58

Updated to latest CVS.

News:
Added bit-wise selection of what to debug.
sip debug 1: will show SIP-headers (IP, peername, SEQ)
sip debug 2: will show full SIP-packet (old style)
sip debug 4: comments about RTP and codecs
sip debug 8: comments about authentication
sip debug 128: All other comments used in old "sip debug"
You may use them together;
sip debug 3 (1+2): will show full sip-packet with nice header
sip debug 255 will show all at once

Summary of modified CLI commands:
sip dfilter add peer <peername>
sip dfilter add ip <host[:port]>
sip dfilter clear
sip show dfilter
sip debug <level 1-255>
sip no debug

By: Brian West (bkw918) 2004-04-20 21:01:57

z_smurf can you simlify this patch just a bit?  I talked with kram and he said this was "too sophisticated" and that he had no problems with something "sip debug <peername>".

Thanks for all the hard work.

bkw

By: z_smurf (z_smurf) 2004-04-20 21:42:19

You are right about that, this should be separated into smaller patches or other CLI commands really.

It is not easy to do a "sip debug peername" if the peername is not registered, but I will give it a try later on...

What about:

sip debug
sip debug peer <peername>
sip debug ip <ip[:port]>
sip no debug


That will do the same, without any effort to clean out comments which is hard do bind to a specific peername.

By: Brian West (bkw918) 2004-04-20 22:25:08

ya that will make it in.. and be very useful.

By: Olle Johansson (oej) 2004-04-21 02:52:24

I suggest we divide it in two steps.

* The simple patch for current CVS head (1.1).

* The sophisticated patch is still important for those of us that use SIP a lot. I think we'll target this for after 1.1 - the new dev branch, so that we could have extensive testing done. Some changes need time.

What do you think?

By: connor (connor) 2004-04-21 22:04:01

While your at it.. add some extended commands to sip show peer.. example...

sip show peer | include 5060
sip show peer | begin 123
sip show peer | exlclude Unmonitored

Basicly, this would allow you to "grep" out the info you want to see..

By: z_smurf (z_smurf) 2004-04-21 23:36:34

Connor: Several people has been asking about this... but never found that I needed it because it is quite easy to follow the stream when only displaying the headers...

By: z_smurf (z_smurf) 2004-04-21 23:44:54

sip_debug_peer1_diff.txt

I've put a lot of time to check that the internal chatty stupid debug-lines (like "Got DTMF!" or "Read 10 headers, 5 lines") only show up for the peer you actually are debugging.

I personally dont think this is a good way of doing it because the code becomes hard to understand, and really, many of the lines does not help one while debugging.

I think that a way of choosing *what* to debug is just as useful as choosing which peer to debug.

By: Brian West (bkw918) 2004-04-22 01:44:19

fyi gethostbyname isn't reentrant... must use ast_gethostbyname now.  Look at recent changes.

bkw

By: z_smurf (z_smurf) 2004-04-22 12:51:54

sip_debug_peer2_diff.txt uploaded twice... I think I double-clicked the submit-button :-)

I removed even more unnecessary stuff, and changed to use ast_gethostbyname.

By: Brian West (bkw918) 2004-04-22 17:11:26

LOVE It.. but your peer matching needs more work.. example get a 7960 with 6 lines registered and you only wanna debug one of those.. but you get them all... So is it a flaw in the peer match?

By: connor (connor) 2004-04-23 10:59:10

sip_show_peers.diff add ability to "grep" through the output of sip show peers.. examples..

sip show peers include 5060
sip show peers exclude UNKNOWN
sip show peers begin 21

and so on..  Simple patch, please let me know how it works and what you think.

By: twisted (twisted) 2004-04-28 20:06:03

Connor: this is really in a different bug.  Should remain there and not here as this is a completely different thing. As such, i have removed your patch from this bug.

edited on: 04-28-04 19:01

By: connor (connor) 2004-04-28 20:09:35

I asked bkw were to put it, he told me here, that was before 1470 was opened.. after he found that 1470 was opened, he moved it.

By: Brian West (bkw918) 2004-05-01 02:00:46

my bad! :)  Sorry guys!

By: Mark Spencer (markster) 2004-05-01 17:19:38

Updated for latest CVS and committed.  Nicely done.

By: Digium Subversion (svnbot) 2008-01-15 14:53:00.000-0600

Repository: asterisk
Revision: 2845

U   trunk/channels/chan_sip.c

------------------------------------------------------------------------
r2845 | markster | 2008-01-15 14:52:59 -0600 (Tue, 15 Jan 2008) | 2 lines

Allow debug to be enabled on a per-peer or per-IP basis (bug ASTERISK-844)

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=2845