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

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

Hi 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

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

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

when 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”

Hi 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

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

the 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

}

i’m wondering if it may not be due to MBLB, what is your BIGIP version ken ?

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!

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

}

Hi,

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.

Aaron

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.

Aaron

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.

finally it seems work and I will pass to customer for further tests. Thanks for all who response…

Ken

when SIP_REQUEST {

log local0. “client info is [IP::client_addr]:[UDP::client_port]”

SIP::header insert “Via” “[lindex [split [SIP::via 0] “;”] 0];received=[IP::client_addr];rport=[UDP::client_port];[lindex [split [SIP::via 0] “;”] 1]”

SIP::header remove “Via” 1

}

Glad it works fine !

When I try to apply this rule, I am getting following error.

Btw I am using 9.2.5

01070151:3: Rule [sip-request] error:

line 1: [unknown event (SIP_REQUEST)] [when SIP_REQUEST {

log local0. “client info is [IP::client_addr]:[UDP::client_port]”

SIP::header insert “Via” “[lindex [split [SIP::via 0] “;”] 0];received=[IP::client_addr];rport=[UDP::client_port];[lindex [split [SIP::via 0] “;”] 1]”

SIP::header remove “Via” 1

}]

For versions before 9.4 that support the SIP events (and 9.2.x is included), you must have an Early Access license in order for the features to work.