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"
}
}
}
- 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)} {...
in place of the unset.session delete uie $callid
- Dave_Wiley
Nimbostratus
Thanks for the input! - 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: - Dave_Wiley
Nimbostratus
This is excellent! Thank you.
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