Forum Discussion
symtex_22198
Nimbostratus
Jul 23, 2009modify SIP contact header param
Hi,
we are using a location server which basically gets SIP invites from a SIP proxy then sends 302 redirect messages.
I have been trying to modify the IP address parameter in the Contact header which is in the 302 message. this IP address will vary, but I want to set it statically
the contact header will have a URI in the format of number xxxxxxxxxxxxx@172.24.103.10. since this is my first irule. I'm struggling.
here is what I've been trying with no success.
when SIP_RESPONSE {
set contact [ SIP::header Contact ]
set telephone 0
set bind 0
regexp {[0-9]{13}} $contact telephone
regexp {[0-9]{8}} $contact bind
SIP::header insert [format \"$bind\"
the header just returns a 0 or a 1... maybe I should try the -inline switch with regexp???
15 Replies
- hoolio
Cirrostratus
Hi,
What's the name and format of the value of the header you want to insert? Or do you just want to insert the 5060 port in the existing Contact header?
I imagine you can check for the 302 response using 'SIP::response code' (Click here) and then use getfield (Click here) or scan (Click here) to parse the string without depending on the more resource intensive regexp command.
Aaron - symtex_22198
Nimbostratus
within a 302 SIP message is a "Contact" field
The contact field will contain the redirected telephone in the format of a uri like this
Contact: "16601003"
I only need to replace the IP address, which will vary with every 302 from the server. I want to set it statically to an IP address I want.
at first I tried to use UDP::payload and replace the hex values using the offset, but the offset varies too... so now I'm trying it this way... let me repost the the irule there are some small details missing...
when SIP_RESPONSE {
set contact [ SIP::header Contact ]
set telephone 0
set bind 0
regexp {[0-9]{13}} $contact telephone
regexp {[0-9]{8}} $contact bind
SIP::header remove Contact
SIP::header insert [format \"$bind\"
} - symtex_22198
Nimbostratus
oops, reposted the irule incorrectly again
when SIP_RESPONSE {
set contact [ SIP::header Contact ]
set telephone 0
set bind 0
regexp {[0-9]{13}} $contact telephone
regexp {[0-9]{8}} $contact bind
SIP::header remove Contact
SIP::header insert [format \"$bind\"
} - symtex_22198
Nimbostratus
BTW I want to add this is my first irule and I'm fairly excited. I worked with other ADCs and was always curious about F5 and iRules. I could see myself really getting into this, iRules rule!! - symtex_22198
Nimbostratus
i was looking into getfield but I was unsure if it would copy everything before the "@" character. I used a regexp to just concentrate on the lengh of the number from the field. I think it would work if I could somehow get regexp to get the regexp result and put it into a variable that I can later outupt in SIP::header - symtex_22198
Nimbostratus
the amount of traffic is minimal and it doesn't seem like a very resource intensive regexp operation. is regexp known to be very resource intensive on TMOS? - hoolio
Cirrostratus
Here is what I was thinking might work. I tested the scan command, but not the iRule.when SIP_RESPONSE { Check for 302 responses if {[SIP::response code] == 302}{ Parse the Contact header value "16601003" using scan http://www.tcl.tk/man/tcl8.4/TclCmd/scan.htm start reading everything not a @ into 'a' then read everything not a : into 'b' finally read the rest into 'c' Example using tclsh: % scan {"16601003"} {%[^@]@%[^:]:%s} a b c 3 % puts "$a $b $c" "16601003" if {[scan [SIP::header value "Contact"] {%[^@]@%[^:]:%s} a b c] == 3}{ We parsed three strings into a b c log local0. "Parsed [SIP::header value "Contact"] into $a, $b, $c" Remove existing Contact header SIP::header remove "Contact" Insert new Contact header with 1.1.1.1 set as a static IP address SIP::header insert "Contact" "${a}@1.1.1.1:${c}" log local0. "Inserting new Contact header: ${a}@1.1.1.1:${c}" } } }
Aaron - symtex_22198
Nimbostratus
that worked!!!! except there is a problem, the telephony people told me this is what they needed. now they're telling me it's ok but erase the first part of the field so
modify
Contact: "16601003"
to
Contact:
how can I modify the scan command to do this? - symtex_22198
Nimbostratus
BTW thanks
this is awesome - symtex_22198
Nimbostratus
NEVERMIND I GOT IT I GOT IT!!!! i got the scan command
just modified
scan {"16601003"} {%[^<]%[^@]@%[^:]:%s} a b c d
I was a perl/sh programmer, this tcl stuff is awesome
AWESOME
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
