# SIP via header modification

**URL:** <https://community.f5.com/t/sip-via-header-modification/23962>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [September 4, 2008, 5:36am UTC](https://community.f5.com/t/sip-via-header-modification/23962 "2008-09-04T05:36:35Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ken\_Wong\_48678](https://avatars.discourse-cdn.com/v4/letter/k/ce7236/32.png) [@Ken\_Wong\_48678](https://community.f5.com/u/Ken_Wong_48678)\
**Post date:** [September 4, 2008, 5:36am UTC](https://community.f5.com/t/sip-via-header-modification/23962/1 "2008-09-04T05:36:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [September 4, 2008, 7:45am UTC](https://community.f5.com/t/sip-via-header-modification/23962/2 "2008-09-04T07:45:58Z")

</div>

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](http://devcentral.f5.com/wiki/default.aspx/iRules/sip_request_send) for more info on the SIP\_REQUEST\_SEND event and [Click here](http://devcentral.f5.com/wiki/default.aspx/iRules/clientside) for the clientside command.

```tcl
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 
 }

```

```tcl
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

---

<div class="post-metadata">

**Author:** ![Ken\_Wong\_48678](https://avatars.discourse-cdn.com/v4/letter/k/ce7236/32.png) [@Ken\_Wong\_48678](https://community.f5.com/u/Ken_Wong_48678)\
**Post date:** [September 4, 2008, 9:12am UTC](https://community.f5.com/t/sip-via-header-modification/23962/3 "2008-09-04T09:12:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nicolas\_Menant\_1](https://avatars.discourse-cdn.com/v4/letter/n/f19dbf/32.png) [@Nicolas\_Menant\_1](https://community.f5.com/u/Nicolas_Menant_1)\
**Post date:** [September 4, 2008, 9:26am UTC](https://community.f5.com/t/sip-via-header-modification/23962/4 "2008-09-04T09:26:59Z")

</div>

You have this error message even if you use this part :

```tcl
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

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [September 4, 2008, 10:45am UTC](https://community.f5.com/t/sip-via-header-modification/23962/5 "2008-09-04T10:45:05Z")

</div>

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?

```tcl
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

---

<div class="post-metadata">

**Author:** ![Ken\_Wong\_48678](https://avatars.discourse-cdn.com/v4/letter/k/ce7236/32.png) [@Ken\_Wong\_48678](https://community.f5.com/u/Ken_Wong_48678)\
**Post date:** [September 4, 2008, 10:45am UTC](https://community.f5.com/t/sip-via-header-modification/23962/6 "2008-09-04T10:45:37Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![Ken\_Wong\_48678](https://avatars.discourse-cdn.com/v4/letter/k/ce7236/32.png) [@Ken\_Wong\_48678](https://community.f5.com/u/Ken_Wong_48678)\
**Post date:** [September 4, 2008, 10:52am UTC](https://community.f5.com/t/sip-via-header-modification/23962/7 "2008-09-04T10:52:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [September 4, 2008, 11:31am UTC](https://community.f5.com/t/sip-via-header-modification/23962/8 "2008-09-04T11:31:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ken\_Wong\_48678](https://avatars.discourse-cdn.com/v4/letter/k/ce7236/32.png) [@Ken\_Wong\_48678](https://community.f5.com/u/Ken_Wong_48678)\
**Post date:** [September 4, 2008, 12:10pm UTC](https://community.f5.com/t/sip-via-header-modification/23962/9 "2008-09-04T12:10:54Z")

</div>

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

}

---

<div class="post-metadata">

**Author:** ![Nicolas\_Menant\_1](https://avatars.discourse-cdn.com/v4/letter/n/f19dbf/32.png) [@Nicolas\_Menant\_1](https://community.f5.com/u/Nicolas_Menant_1)\
**Post date:** [September 4, 2008, 12:14pm UTC](https://community.f5.com/t/sip-via-header-modification/23962/10 "2008-09-04T12:14:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ken\_Wong\_48678](https://avatars.discourse-cdn.com/v4/letter/k/ce7236/32.png) [@Ken\_Wong\_48678](https://community.f5.com/u/Ken_Wong_48678)\
**Post date:** [September 4, 2008, 12:20pm UTC](https://community.f5.com/t/sip-via-header-modification/23962/11 "2008-09-04T12:20:10Z")

</div>

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

}

---

<div class="post-metadata">

**Author:** ![Nicolas\_Menant\_1](https://avatars.discourse-cdn.com/v4/letter/n/f19dbf/32.png) [@Nicolas\_Menant\_1](https://community.f5.com/u/Nicolas_Menant_1)\
**Post date:** [September 4, 2008, 12:50pm UTC](https://community.f5.com/t/sip-via-header-modification/23962/12 "2008-09-04T12:50:44Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [September 4, 2008, 1:12pm UTC](https://community.f5.com/t/sip-via-header-modification/23962/13 "2008-09-04T13:12:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [September 4, 2008, 2:02pm UTC](https://community.f5.com/t/sip-via-header-modification/23962/14 "2008-09-04T14:02:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![spark\_86682](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@spark\_86682](https://community.f5.com/u/spark_86682)\
**Post date:** [September 4, 2008, 5:47pm UTC](https://community.f5.com/t/sip-via-header-modification/23962/15 "2008-09-04T17:47:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ken\_Wong\_48678](https://avatars.discourse-cdn.com/v4/letter/k/ce7236/32.png) [@Ken\_Wong\_48678](https://community.f5.com/u/Ken_Wong_48678)\
**Post date:** [September 5, 2008, 4:25pm UTC](https://community.f5.com/t/sip-via-header-modification/23962/16 "2008-09-05T16:25:07Z")

</div>

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

}

---

<div class="post-metadata">

**Author:** ![Nicolas\_Menant\_1](https://avatars.discourse-cdn.com/v4/letter/n/f19dbf/32.png) [@Nicolas\_Menant\_1](https://community.f5.com/u/Nicolas_Menant_1)\
**Post date:** [September 5, 2008, 4:26pm UTC](https://community.f5.com/t/sip-via-header-modification/23962/17 "2008-09-05T16:26:22Z")

</div>

Glad it works fine !

---

<div class="post-metadata">

**Author:** ![Jeeth\_42181](https://avatars.discourse-cdn.com/v4/letter/j/ce73a5/32.png) [@Jeeth\_42181](https://community.f5.com/u/Jeeth_42181)\
**Post date:** [November 24, 2008, 9:28pm UTC](https://community.f5.com/t/sip-via-header-modification/23962/18 "2008-11-24T21:28:56Z")

</div>

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

}]

---

<div class="post-metadata">

**Author:** ![JRahm](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/jrahm/32/3327_2.png) [@JRahm](https://community.f5.com/u/JRahm)\
**Post date:** [November 24, 2008, 9:59pm UTC](https://community.f5.com/t/sip-via-header-modification/23962/19 "2008-11-24T21:59:00Z")

</div>

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.
