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!
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
}
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"
}
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.
I 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!
I did some testing in my lab and reproduce your error. It definitely seems like SIP_REQUEST_SEND doesn’t share data with the other event including clientside data …
Anyway it works fine with SIP_REQUEST, cannot you do everything within this event ?
I think the reason it’s failing is that there isn’t a client side “connection” once the server side connection is established. I would have thought LTM would maintain a connection table entry until the response was sent. I also expected that LTM would preserve any variables set in a client side event for the duration of the server side connection. Both of these points seem odd, even for UDP. I’d be curious to see what F5 dev has to say about this.
I’m guessing the issue is specific to UDP and it’s because the client side connection doesn’t exist by the time the server side context is started. It’s still very odd that the IP::client_addr and UDP::client_port values aren’t stored like they are in TCP-based rules. It’s even more strange that explicitly set local variables aren’t preserved.
I agree that this is very strange behavior. It’s almost like the serverside connection doesn’t have a link back to the clientside, which would explain both the local variables not working and the clientside commands not working.
The suggestion to use SIP_REQUEST is a good one; see if that solves the problem.
In any case, I would strongly recommend opening a case with F5 support.