issue with cookie persist irule

Hey guys, I am having an issue with an irule that I got from code share that is shown below. This irule is used on 2 virtual servers (using the same nodes, but different ports) and should be persistent between virtual servers. The user logs into the website, which is vs 1, and clicks a link that sends them to vs 2 (the same node). This works only sometimes for the users. The HTTP::response event in this irule always works, but the HTTP::request event gets numerous errors.

Here’s the error:

Aug 19 16:18:57 local/tmm err tmm[13657]: 01220001:3: TCL error: cookie - no such pool Failed Tcl_pool_GetFromObj: pool (line 6) invoked from within “active_members -list [LB::server pool]”

IRule:

when HTTP_REQUEST {

if { [HTTP::cookie exists “cookie”] } {

set decrypted [HTTP::cookie decrypt “cookie” “passcode”]

if { ($decrypted ne “”) }

{ set persist_node [HTTP::cookie “cookie”]

foreach member [active_members -list [LB::server pool]] { <--Line that fails

set node [lindex $member 0]

if { $node eq $persist_node }

{ node $persist_node [lindex $member 1] } } }

log local0. [LB::server] } } <-- Doesn’t return anything

when LB_FAILED { LB::reselect }

when HTTP_RESPONSE {

HTTP::cookie insert name “cookie” value [IP::remote_addr] path /

HTTP::cookie encrypt “cookie” “passcode” }

Thanks for your help,

Mike

I’m not sure I see how your iRule would work… However, a couple of things I notice…

1. The cookie is encrypted, yet you use the actual cookie value directly in

set persist_node [HTTP::cookie "cookie"]

which means the node $persist_node […] is going to fail too…

shouldn’t that be

set persist_node decrypted

or simply replace ‘decrypted’ with ‘persist_node’…

2. Why are you looping through the poolmembers?

3. What happens if the cookie exists already but wasn’t actually set by the iRule HTTP_RESPONSE?

I think you need to catch {} any errors from the decrypting too… Otherwise bad cookies will kill your connection… Are there any other errors (Sorry, I don’t have my stuff with me to actually test your iRule on an LTM).

H

1. So the line: set decrypted [HTTP::cookie decrypt “cookie” “passcode”]

should look like: set persist_node [HTTP::cookie “cookie_name”] ?

2. I don’t know. Doesn’t seem like I need to. Can I just delete the “foreach” line?

3. The cookie shouldn’t exist unless assigned by the HTTP_RESPONSE

I actually don’t need an encrypted cookie.

does f5 professional services do irule creation? customer is coming up on a deadline, and we can’t seem to get things working for them.

Posted By Mike on 08/24/2010 08:47 AM

does f5 professional services do irule creation? customer is coming up on a deadline, and we can’t seem to get things working for them.

By the way, since you’re calling LB::server pool from HTTP_REQUEST, it should be checking against your default pool.

It looks like this is the codeshare you’re using:

http://devcentral.f5.com/wiki/default.aspx/iRules/Cookie\_Encryption\_across\_pools\_and\_services.html

What’s your default pool called? Your TCL error leads me to believe the rule is somehow looking for a pool called “cookie”

What version are you running?

The reason you aren’t seeing anything for logging LB::server is because you haven’t chosen a server which makes me think your default pool isn’t specified.

Hi Chris, thanks for the link.

I am using this irule for 3 different virtual servers. Each vs has a default pool defined (same nodes, but different ports). We are running version 10.0.1.

I don’t really have the need for an encrypted cookie, but this is the closest codeshare example I could find to what I wanted to do.

Posted By Mike on 08/24/2010 10:42 AM

Hi Chris, thanks for the link.

I am using this irule for 3 different virtual servers. Each vs has a default pool defined (same nodes, but different ports). We are running version 10.0.1.

I don’t really have the need for an encrypted cookie, but this is the closest codeshare example I could find to what I wanted to do.

May I ask what the name of the default pool is for the VS that is giving you this error?

This might be worth a read.

http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/109/Persisting-Across-Virtual-Servers.aspx

there would be 2 default pools, p_lum_test and p_lum_resource_test. one pool is used by one virtual server and one pool is used by 2 other virtual servers. i want to persist across all 3 virtual servers.

according to the article, i would have to be using the same pool for all 3 virtual servers?

We can get the original one working.

Can you add this to the bottom of your HTTP_RESPONSE event?

log local0. “cookie value set to [IP::remote_addr]”

Let’s kill the encrypt/decrypt logic and make the rule look like this:

when HTTP_REQUEST {
         If the cookie exists, connect to the IP specified in the cookie
        if { [HTTP::cookie exists "cookie"] } {
                if { ([HTTP::cookie "cookie"] ne "") } {
                        set persist_node [HTTP::cookie "cookie"]
                        foreach member [active_members -list [LB::server pool]] {
                                set node [lindex $member 0]
                                if { $node eq $persist_node } {
                                        node $persist_node [lindex $member 1]
                                }
                        }
                }
        }
}

when LB_FAILED {
        LB::reselect
}

when HTTP_RESPONSE {
   HTTP::cookie insert name "cookie" value [IP::remote_addr] path /
    Optionally comment out the above line and use the following line
    instead while specifying a domain
    HTTP::cookie insert name "cookie" value [IP::remote_addr] path / domain abc.com
}

Ok, I tried the rule you have above. The user can log into the web portal fine, there is a link on the portal that sends the user to the port 8008 virtual server. Sometimes it works, and sometimes it just hangs. The virtual servers are listed below, and the 2 physical servers are 10.10.11.252 and 10.10.11.253.

here is the output from the log we put in the HTTP_RESPONSE event:

Aug 26 15:53:29 local/tmm1 info tmm1[13658]: Rule persist_prod : cookie value set to 10.10.11.252

I’m still getting the TCL error in the line: foreach member [active_members -list [LB::server pool]] {

Should/could we include both pools in the LB::server function somehow?

What about an irule that grabs the IP::remote_addr from the http_response when the user hits the vs_HTTPS vs, and apply the rule to the 8008 vs, having them hit the same server thats returned by the IP::remote_addr? Is there a way we could do that?

virtual vs_HTTPS {

snat automap

pool p_Luminus

destination 10.10.11.230:443

ip protocol tcp

rules persist_prod

httpclass web-acc-class

profiles {

http {}

luminus-temp-clientssl {

clientside }

tcp-lan-optimized {}

} }

virtual vs_Resource_Prod {

snat automap

pool p_Resource_8008

destination 10.10.11.230:8008

ip protocol tcp

rules persist_prod

profiles {

http {}

tcp {}

} }

Under this line:

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

Add this line:

log local0. "cookie inserted with value [IP::remote_addr]"

Let me know what log entries you see in the LTM section of logging.

Ug…this is what I get for posting before I’m completely awake…I see you already configured logging and that you’re inserting the cookie properly.

Under this line:

set persist_node [HTTP::cookie "cookie"]

Add:

log local0. "$persist_node set to [HTTP::cookie "cookie"]"

Let me know what that’s giving you…want to make sure the cookie is coming in properly…somehow, the LB::server pool command is having issues. Can you paste the exact TCL error you’re getting now?

log local0. “$persist_node set to [HTTP::cookie “cookie”]” is returning this:

Aug 27 09:39:19 local/tmm1 info tmm1[13658]: Rule persist_prod : 10.10.11.252 set to 10.10.11.252

The TCL error is:

Aug 27 09:37:24 local/tmm err tmm[13657]: 01220001:3: TCL error: persist_prod - no such pool Failed Tcl_pool_GetFromObj: pool (line 1) invoked from within “active_members -list [LB::server pool]”

Something’s definitely amiss with the lb::server pool command.

Please modify the log command as follows:

From this:

log local0. "$persist_node set to [HTTP::cookie "cookie"]"

to

log local0. "persist_node is $persist_node and server pool is [LB::server pool]"

Let me know what you log…

here is what is logging:

Aug 30 09:31:01 local/tmm info tmm[13657]: Rule persist_prod : persist_node is 10.10.11.252 and server pool is p_webpool

when the user initiates connection to the other vs:

Aug 30 09:32:02 local/tmm info tmm[13657]: Rule persist_prod : persist_node is 10.10.11.252 and server pool is p_Resource_8008

it looks like the node is staying persistent between pools, but it is still giving me the TCL error:

Aug 30 09:36:56 local/tmm err tmm[13657]: 01220001:3: TCL error: persist_prod - no such pool Failed Tcl_pool_GetFromObj: pool (line 1) invoked from within “active_members -list [LB::server pool]”

Just for kicks…please change your request event to this:

when HTTP_REQUEST {
         If the cookie exists, connect to the IP specified in the cookie
        if { [HTTP::cookie exists "cookie"] } {
                if { ([HTTP::cookie "cookie"] ne "") } {
                        set persist_node [HTTP::cookie "cookie"]
                       log local0. "persist_node is $persist_node and server pool is [LB::server pool]"
                       set current_pool [LB::server pool]
                        foreach member [active_members -list $current_pool] {
                                set node [lindex $member 0]
                                if { $node eq $persist_node } {
                                        node $persist_node [lindex $member 1]
                                }
                        }
                }
        }
}

This is less efficient as we’re setting a variable for the selected pool, but I’m curious.

I see the same result…it’s logging the same information as my last post, but the TCL error still exists:

Aug 30 15:32:15 local/tmm1 err tmm1[13658]: 01220001:3: TCL error: Luminus_persist_prod - no such pool Failed Tcl_pool_GetFromObj: pool (line 1) invoked from within “active_members -list $current_pool”

one thing i did notice in the log is that both pool members were being used, see below: (these are consecutive lines)

and in the 5th entry shown, LB::server is blank

Aug 30 15:32:14 local/tmm1 info tmm1[13658]: Rule persist_prod : persist_node is 10.10.11.252 and server pool is p_HTTPS

Aug 30 15:32:14 local/tmm1 info tmm1[13658]: Rule persist_prod : cookie value set to 10.10.11.253

Aug 30 15:32:14 local/tmm1 info tmm1[13658]: Rule persist_prod : cookie value set to 10.10.11.253

Aug 30 15:32:14 local/tmm1 info tmm1[13658]: Rule persist_prod : cookie value set to 10.10.11.252

Aug 30 15:32:15 local/tmm1 info tmm1[13658]: Rule persist_prod : persist_node is 10.10.11.252 and server pool is

Aug 30 15:32:15 local/tmm1 err tmm1[13658]: 01220001:3: TCL error: persist_prod - no such pool Failed Tcl_pool_GetFromObj: pool (line 1) invoked from within “active_members -list $current_pool”

Are you using OneConnect on this VS?

Very interesting that we aren’t able to lookup which pool we’re in…which is definitely why the error is getting triggered.