Forum Discussion

Nick_Matthews's avatar
Mar 15, 2013

iRule Universal Persistence

Hi,

 

I am hoping someone can help with this issue, or at least point me in the right direction.

 

I have 2 VS using the same VIP running on port 80 and 443.

 

I have no default pool selected on these VS, as I am using iRules to do this as shown below:

 

when HTTP_REQUEST {

 

Check the URI, set to lowercase

 

switch -glob [string tolower [HTTP::uri]] {

 

"/Folder1/*" -

 

"/Folder2/*" -

 

"/Folder3/*" {pool HTTP-ThirdParty}

 

default {pool HTTP-MainSite}

 

 

}

 

}

 

and

 

when HTTP_REQUEST {

 

switch -glob [string tolower [HTTP::uri]] {

 

"/Folder1/*" -

 

"/Folder2/*" -

 

"/Folder3/*" pool HTTPS-ThirdParty}

 

default { pool HTTPS-MainSite }

 

}

 

}

 

This works fine.

 

I am then using Universal Match Across Services persistence profile from this example:

 

https://devcentral.f5.com/wiki/iRul...tence.ashx

 

So the match across services for HTTP and HTTPS works fine because the pool has the same member ip's. But anything that goes to the pool HTTPS-ThirdParty and HTTP-ThirdParty doesn't set its own persistence.

 

We require persistence across our third party apps as well, so I attempted to modify the iRule to add persistence using a differently named cookie for the other pool like this:

 

when HTTP_REQUEST {

 

if { ([LB::server pool] eq "/Common/HTTP-MainSite") } {

 

if { [HTTP::cookie value "cookieMainWebsite"] ne "" } {

 

persist uie [HTTP::cookie value "cookieMainWebsite"]

 

set need_cookie 0

 

} else {

 

set need_cookie 1

 

}

 

}

 

if { ([LB::server pool] eq "/Common/HTTP-ThirdParty") } {

 

if { [HTTP::cookie value "cookieThirdParty"] ne "" } {

 

persist uie [HTTP::cookie value "cookieThirdParty"]

 

set need_cookie 0

 

} else {

 

set need_cookie 1

 

}

 

}

 

}

 

when PERSIST_DOWN {

 

set need_cookie 1

 

}

 

 

when HTTP_RESPONSE {

 

if { $need_cookie } {

 

if { ([LB::server pool] eq "/Common/HTTP-MainSite") } {

 

HTTP::cookie insert name "cookieMainWebsite" value [IP::server_addr] path "/"

 

persist add uie [HTTP::cookie value "cookieMainWebsite"]

 

}

 

if { ([LB::server pool] eq "/Common/HTTP-ThirdParty") } {

 

HTTP::cookie insert name "cookieThirdParty" value [IP::server_addr] path "/"

 

persist add uie [HTTP::cookie value "cookieThirdParty"]

 

}

 

}

 

 

}

 

I suspect my expression when I attempt to check the current pool isn't quite right. Hopefully you can understand what I am trying to achieve, but please ask for clarification on any bits that are unclear.

 

  • in HTTP To HTTPS Cookie Persistence irule, can you try to append "priority 600" to HTTP_REQUEST event?

     

     

    from

     

    when HTTP_REQUEST {

     

     

    to

     

    when HTTP_REQUEST priority 600 {
  • when HTTP_REQUEST {

     

    Check the URI, set to lowercase

     

    switch -glob [string tolower [HTTP::uri]] {

     

    "/Folder1/*" -

     

    "/Folder2/*" -

     

    "/Folder3/*" {pool HTTP-ThirdParty}

     

    default {pool HTTP-MainSite}

     

     

    }

     

    }

     

    by the way, in production irule, F is actually in lower case, isn't it?
  • Hi Nitass,

     

    Thanks for your posts.

     

    I will give the priority 600 a try. What exact does that do?

     

     

    Yes, you are correct, the actual URL redirection locations are in lower case.
  • Sorry Nitass,

     

    I have searched and found out what Priorty does. I will give that a try in a moment.
  • Hi Nitass,

     

     

    adding priority 600 has fixed the problem,

     

     

    Thank you very much for your help.