Forum Discussion
myocella
Nimbostratus
Jan 22, 2009iRule to inspect MySQL statements
Greeting,
I would like to create iRule to apply a VS to redirect MySQL traffic
to a pool based on the SQL statement. Here is my iRule:
---------------8<------------------------------
when CLIENT_ACCEPTED {
if { ( [IP::addr [IP::client_addr] equals a.a.b.b] ) or ( [IP::addr [IP::client_addr] equals c.c.d.d] ) } {
log local0.none "true"
snat xx.xx.xx.xx
log local0.none "SNAT completed"
TCP::collect
log local0.none "Data collected"
}
}
when CLIENT_DATA {
log local0.none "CLIENT_DATA"
if { [TCP::payload] contains "select" } {
pool mysql_read_pool
} else {
pool mysql_write_pool
}
TCP::release
}
-------------->8-----------------------------------
The CLIENT_ACCEPTED works as it is instructed. However, I couldn't
see the source IP was SNAT(ed) to xx.xx.xx.xx, and CLIENT_DATA
wasn't executed at all.
This VS is for accepting MySQL connections from 2 web servers (a.a.b.b and
c.c.d.d).
Can anyone shed some light on this?
Thanks
myOcella
- myocella
Nimbostratus
I've tried to put any number in TCP::collect but it still doesn't work. However when I removed TCP::collect, SNAT works fine. - hoolio
Cirrostratus
If you capture a tcpdump, do you see the client sending any data? I'm not sure about mysql, but maybe the client establishes the connection and then waits for the server to send data first? That's just a stab in the dark though. If this is the case, take a look at the TCP::collect wiki page's section on skip bytes (TCP::collect Click here). - ryanc_76025
Altocumulus
This, unfortunately, isn't going to work so easily...I really wish it did, but it won't. - hoolio
Cirrostratus
Thanks for the information rcorder. - are you going to use this to send reads to different server than writes?
- Mario_Apitz___u
Nimbostratus
Hello, - L4L7_53191
Nimbostratus
Gang: I think that this is a *very* tricky problem to solve correctly. It's already been noted that we're really talking about implementing a full-blown mysql proxy in iRules, and it gets worse (depending upon your implementation, of course) - imagine a statement like (taken from a random search on google for "mysql update based on select":
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects