Forum Discussion
Ken_Wong_48678
Sep 04, 2008Historic F5 Account
SIP via header modification
Hi,
my customers have a requirement to modify SIP via header, they want to insert the SIP client ip and port into the via header.
when CLIENT_ACCEPTED {
set ::clientip [IP::client_addr]
set ::clientport [UDP::remote_port]
}
when SIP_REQUEST_SEND {
SIP::header insert "Via" "[lindex [split [SIP::via 1] ";"] 0];received=$::clientip;rport=$::clientport;[lindex [split [SIP::via 1] ";"] 2]" 1
SIP::header remove "Via" 2
}
The above irule seems work but finally I find out the variable cannot be updated even another client ip connect to the virtual. I think it may be related to the variable but it cannot be retrieved in SIP_REQUEST_SEND event if I don't use global variable.
Is there any idea that I can get the client ip and port but don’t need to use global variable? Thanks!
Regards,
Ken
18 Replies
- hoolio
Cirrostratus
Hi Ken,
If you change the variables to local (remove the :: in the var name), does the rule work? Or are you saying that the local variable value set in CLIENT_ACCEPTED isn't available in SIP_REQUEST_SEND?
Also, I think IP::client_addr and UDP::client_port should work in any context (client or serverside event). So I don't think you should have to save any variables in CLIENT_ACCEPTED if you're only tring to get the client IP address and port.
Finally, if you do want to retrieve other clientside values in SIP_REQUEST_SEND, you can do so using 'clientside {COMMAND}'. Click here for more info on the SIP_REQUEST_SEND event and Click here for the clientside command.Test whether a local variable from CLIENT_ACCEPTED is accessible from SIP_REQUEST_SEND when CLIENT_ACCEPTED { Save the client IP and port to local variables (specific to this connection only) set clientip [IP::client_addr] set clientport [UDP::remote_port] } when SIP_REQUEST_SEND { Test whether the local variable set in CLIENT_ACCEPTED is available in this event log local0. "\$clientip: $clientip, \$clientport: $clientport" SIP::header insert "Via" "[lindex [split [SIP::via 1] ";"] 0]received=$clientip;rport=$clientport;[lindex [split [SIP::via 1] ";"] 2]" 1 SIP::header remove "Via" 2 }when SIP_REQUEST_SEND { log local0. "\[IP::client_addr\]:\[UDP::client_port\]: [IP::client_addr]:[UDP::client_port]" SIP::header insert "Via" "[lindex [split [SIP::via 1] ";"] 0]received=[IP::client_addr];rport=[UDP::client_port];[lindex [split [SIP::via 1] ";"] 2]" 1 SIP::header remove "Via" 2 }
Aaron - Ken_Wong_48678Historic F5 AccountHi Aaron,
I tested before but the there is an error shows no such variable...
TCL error: new_rule - can't read "clientip": no such variable while executing "log local0. "client ip is $clientip" "
TCL error: new_rule - can't read "clientip": no such variable while executing "log local0. "client ip is $clientip" "
regards,
Ken - Nicolas_Menant
Employee
You have this error message even if you use this part :when SIP_REQUEST_SEND { log local0. "[IP::client_addr]:[UDP::client_port]: [IP::client_addr]:[UDP::client_port]" SIP::header insert "Via" "[lindex [split [SIP::via 1] ";"] 0]received=[IP::client_addr]rport=[UDP::client_port][lindex [split [SIP::via 1] ";"] 2]" 1 SIP::header remove "Via" 2 }
?
The problem is you may have issue to retrieve variable value in this event, so you should try to call directly [IP::client_addr] instead of $clientip - hoolio
Cirrostratus
The local variable should be available in any event on the same TCP connection. Can you try testing with the following and open a case with F5 Support if the CLIENT_ACCEPTED event is triggered and you still see a TCL error in a subsequent event when trying to access the local variable?when CLIENT_ACCEPTED { set local_var "test" log local0. "[IP::client_addr]: \$local_var: $local_var" } when SIP_REQUEST_SEND { log local0. "[IP::client_addr]: \$local_var: $local_var" }
Aaron - Ken_Wong_48678Historic F5 Accountwhen SIP_REQUEST_SEND {
log local0. "[IP::client_addr]:[UDP::client_port]"
}
I tried it but still fails and the error shown below
Sep 5 09:36:54 tmm tmm[12136]: 01220001:3: TCL error: new_rule - Error: No clientside connection established (line 1) invoked from within "IP::client_addr"
Sep 5 09:36:55 tmm tmm[12136]: 01220001:3: TCL error: new_rule - Error: No clientside connection established (line 1) invoked from within "IP::client_addr" - Ken_Wong_48678Historic F5 AccountHi hoolio,
Yes, I think for TCP it may works. But SIP we are using is UDP so may be there is some tricky. thanks!
Regards,
Ken - hoolio
Cirrostratus
Ken,
Can you post your VIP, profile and rule config from the bigip.conf by running 'b virtual VIP_NAME list', 'b profile UDP_PROFILE_NAME list', and 'b rule RULE_NAME list'? I'm curious to see what's going on with this.
Thanks,
Aaron - Ken_Wong_48678Historic F5 Accountthe info shown below, thanks!
Ken
virtual VS-SIP-5060 {
snat automap
pool SIP_pool
destination a.b.c.d:5060
ip protocol udp
rules new_rule
profiles
sip_profile
sip_udp
}
profile sip sip_profile {
defaults from sip
insert via enable
}
profile udp sip_udp {
defaults from udp
idle timeout 1800
} - Nicolas_Menant
Employee
i'm wondering if it may not be due to MBLB, what is your BIGIP version ken ? - Ken_Wong_48678Historic F5 AccountI think it is not related to MBLB, do you think I need to reset the variable after inserted the modified header? my testing version is already 9.4.5. thanks!
when CLIENT_ACCEPTED {
set ::clientip [IP::client_addr]
set ::clientport [UDP::remote_port]
}
when SIP_REQUEST_SEND {
SIP::header insert "Via" "[lindex [split [SIP::via 1] ";"] 0]received=$::clientip;rport=$::clientport;[lindex [split [SIP::via 1] ";"] 2]" 1
SIP::header remove "Via" 2
}
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
