Forum Discussion

Stephane_Deshai's avatar
Stephane_Deshai
Icon for Nimbostratus rankNimbostratus
Sep 11, 2012

Change IP in a SIP INVITE

I'm managed to change the IP in a SIP INVITE with this iRule :

 

when SIP_REQUEST {

 

if {[SIP::method] == "INVITE" && [SIP::uri] contains "10.215.186.38" }{

 

eval [LB::select]

 

 

set ipSelected [string map "10.215.186.38 [LB::server addr]" [SIP::uri]]

 

set ipSelected2 [string map {"%10" ""} [SIP::uri]]

 

 

}

 

}

 

 

But the problem that I have is that my LB::server addr is in a specific route domain and the IP finish with %10 so I have to remove the %10 in the SIP::uri. ex.: sip:94167127070@10.215.184.71%10:5060.

 

Can someone hep me ?

 

Thanks

 

3 Replies

  • Hi Stephane,

     

     

    You can use getfield to split off the % and get just the IP:

     

     

    set ip [getfield "1.1.1.1%10" "%" 1]

     

     

    Aaron
  • Thank you ! but something doesnt work here the change I made .. :

     

     

    when SIP_REQUEST {

     

    if {[SIP::method] == "INVITE" && [SIP::uri] contains "10.215.186.38" }{

     

    eval [LB::select]

     

    set ipSelected [string map "10.215.186.38 [LB::server addr]" [SIP::uri]]

     

    set ip [getfield $ipSelected "%10" 1][SIP::uri]

     

     

    I'm not sure about the last [SIP::uri]

     

     

    Also, is it possible that each time a make a change in an iRule that I have remove the iRule from the VS and put it back ?
  • Also, is it possible that each time a make a change in an iRule that I have remove the iRule from the VS and put it back ?

    No, but the iRule won't take effect for existing connections (by design). You could manually clear the connection for your client using 'tmsh delete sys conn cs-client-addr 1.1.1.1'

    If you're trying to replace the IP%RD with the server address in the SIP URI you could try this:

    when SIP_REQUEST {
       if {[SIP::method] eq "INVITE" && [SIP::uri] contains "10.215.186.38" }{
           Force a pool member selection
          eval [LB::select] 
    
           Rewrite the destination to the server IP
           Ex SIP URI: sip:94167127070@10.215.184.71%10:5060 
          SIP::uri [string map "10.215.184.71%10 [LB::server addr]" [SIP::uri]]
       }
    } 

    Aaron