Forum Discussion
jminfused
Nimbostratus
Feb 03, 2016How do I configure a simple TCP proxy that can rewrite SQL from a client to a MySQL server?
I would like to know how to configure a Virtual Server on the F5 BigIP (version 11.5) that would do nothing more than proxy TCP connections to a MySQL server, with the ability to match and rewrite sp...
jminfused
Nimbostratus
Feb 05, 2016Ok, I was able to get it working using the information provided here. First I had to create a Standard Virtual Server with a TCP protocol and profile, with Source Address Translation set to Auto Map. Then I added a pool with the MySQL server in it and gave it a TCP monitor and attached them together with the Virtual Server.
Next comes the iRule, which is below and is correctly adding an index hint to the SQL "on the wire." The code is still a bit ugly with magic numbers and strings, but it works:
when CLIENT_ACCEPTED {
TCP::release
TCP::collect
}
when CLIENT_DATA {
binary scan [TCP::payload] ica* length cmd sql
set cmd [expr { $cmd & 0xff }]
if { $cmd eq 3 } {
set length [expr { $length & 0xffffffff }]
if { $sql contains "WHERE Contact.IsUser <=> '0' AND `ContactGroupAssign`.`DateCreated`" } {
set location [string first "FROM ContactGroupAssign INNER" $sql]
if { $location > 5 } {
TCP::payload replace [expr $location + 29] 0 "use index (DateCreated) "
set newLen [expr $length + 24]
set replacement [binary format i $newLen]
TCP::payload replace 0 4 $replacement
log local0.alert "MySQL rewrite: added \"use index (DateCreated) \""
}
}
}
TCP::release
TCP::collect
}Kai_Wilke
MVP
Feb 05, 2016Your first iRule? Nice job! ;-)
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
