Persist_Cookie_Logger rule updates

The Persist_Cookie_Logger iRule does not account for the cookie format associated with traffic on non-default route domains. I think this rule on codeshare should be updated. I’ve taken a stab at it below and it seems to work. I’m not an iRule ninja, so I’m sure there is some cleanup that needs to be done. It may be best to have a single rule that checks for route domain - and then applies the appropriate logic. Any thoughts, help are welcome.

when RULE_INIT {

see AskF5 SOL6917 for cookie encoding details:

my persist cookie = VPersist

set ::myCookieName VPersist

set ::debug 0

}

when HTTP_REQUEST {

grab encoded cookie value & parse into relevant pieces

if {[HTTP::cookie exists $::myCookieName]}{

This is the algorithm for default route domain

scan [HTTP::cookie $::myCookieName] {%[^\.].%d.%d} myIpE myPortE unused

this is my first try with scan - so be gentle

scan [HTTP::cookie $::myCookieName] {%[^o]o%24x%xo%d} myRD junk myIpE myPort

if {$::debug != 0}{log local0. “myRD=$myRD junk=$junk myIpD=$myIpE myPort=$myPort”}

not really sure this is necessary, but I left it alone since it’s working. I had to reverse order.

calculate IP

%08x format strings forces padding w/leading 0’s to 8 char string

set myIpH [format %08x $myIpE]

if {$::debug != 0}{log local0. “myIpH=$myIpH”}

set myIpD1 [expr 0x[substr $myIpH 6 2]]

set myIpD2 [expr 0x[substr $myIpH 4 2]]

set myIpD3 [expr 0x[substr $myIpH 2 2]]

set myIpD4 [expr 0x[substr $myIpH 0 2]]

set myIpD “$myIpD4.$myIpD3.$myIpD2.$myIpD1”

if {$::debug != 0}{log local0. “myIpD=$myIpD”}

log results

log local0. "Request from client: \

[IP::remote_addr]:[TCP::remote_port] contains persistence cookie \

referencing pool member $myIpD:$myPort"

} else {

log local0. "Request from client: [IP::remote_addr]:[TCP::remote_port] \

contains NO persistence cookie"

}

}