Forum Discussion
Dave_Wiley
Nimbostratus
Feb 20, 2006SIP Rule to Insert Data into method CANCEL
Greetings! I wrote the following iRule in order to overcome a very specific problem with a SoftSwitch that's handling SIP signaling. The problem only occurs when someone enters *67 before they dial to make themselves anonymous and then they hang-up before the signaling connects to the remote endpoint. I was wondering if there was a better way to handle the mush at the end of the iRule where I'm having to insert a double 0d0a to end the payload. Read below and you'll see what I mean.
Thanks!
Dave
-------------------------------------------
rule invite_and_cancel
when RULE_INIT {
array set ::callidtable{ }
}
when CLIENT_DATA {
Get the UDP Header, Payload, and Call-ID info
set header [UDP::payload 48]
set fullpacket [UDP::payload [UDP::payload length]]
set callid [findstr $fullpacket "Call-ID:" 9 "
" ]
Check if this is a SIP Method INVITE and the FROM field is "anonymous"
if { $header contains "INVITE" } {
if { $fullpacket contains "From: " } {
Find the P-Asserted-Identity field and insert it into the array
This next command MUST have the carriage return in it to pick up the right amount of data.
set ::callidtable($callid) [findstr $fullpacket "P-Asserted-Identity:" 0 "
" ]
return
}
return
}
Check if we've previously stored this Call-ID and this is a CANCEL
if { [info exists ::callidtable($callid)] } {
if { $header contains "CANCEL"} {
Make the P-Asserted-Identity header insert at the right place
set newlength [UDP::payload length]
incr newlength -2
UDP::payload replace $newlength 0 $::callidtable($callid)
Insert a double "0d0a" to end the payload correctly
set newlength [UDP::payload length]
incr newlength -2
UDP::payload replace $newlength 0 "\n"
Clear the array for this callerid
unset ::callidtable($callid)
return
}
else {
If we're here, we're seeing a different message than INVITE or CANCEL
log "Message other than INVITE / CANCEL for CALL-ID $callid"
}
}
}4 Replies
- unRuleY_95363Historic F5 AccountI'm a little concerned that you don't have a way to unset the array if the call ends normally. This will potentially fill up your memory. You should look into using the session add/lookup commands instead as these can use a timeout to remove stale data. Basically, you'd want to use:
instead of:session add uie $callid [findstr $fullpacket "P-Asserted-Identity:" 0 "\r"]
and then use:set ::callidtable($callid) [findstr $fullpacket "P-Asserted-Identity:" 0 " " ]
instead of:id = [session lookup uie $callid] if { $id ne "" } { ...if {[info exists ::callidtable($callid)} {...
You could thereafter simply refer to $id and to then also you can use:
in place of the unset.session delete uie $callid
I am a little puzzled by the -2 stuff since \n is actually only 1 character (a linefeed). Perhaps you really want "\r\n" there.
Hope that helps. It it looking like a pretty cool rule. - Dave_Wiley
Nimbostratus
Thanks for the input!
The problem with the implementation of the iRule is that only the INVITE and CANCEL SIP methods are routed through the BIG-IP; no other SIP methods will ever be seen.
I couldn't find any documentation on the "session" command. Can you tell me where it is or provide a link? How would you go about expiring the data with a timeout?
Each header in the SIP payload is seperated by an x0a0d and a double x0a0d ends the payload. Do they translate to /r/n? ( Sorry, but I haven't had to program in over 15 years. The last language I worked on was Fortran77 and Assembler! ) When I inserted the additional header, I needed to add another x0a0d and I kludged my way through it at the end there. Not very elegant, but it got the job done. - JRahm
Admin
The wiki entry has not been updated yet, but there are plenty of examples in the forum on how to use it. Here's one:
http://devcentral.f5.com/Default.aspx?tabid=28&view=topic&forumid=5&postid=5869 - Dave_Wiley
Nimbostratus
This is excellent! Thank you.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
