Handshake information is sent by the server to the client after
the initial connection (through
connect_server()
) has been made. The
handshake information contains details about the MySQL version,
the ID of the thread that will handle the connection
information, and the IP address of the client and server. This
information is exposed through the
proxy.connection
structure.
proxy.connection.server.mysqld_version
— the version of the MySQL server.
proxy.connection.server.thread_id
—
the thread ID.
proxy.connection.server.scramble_buffer
— the password scramble buffer.
proxy.connection.server.dst.name
—
the IP address of the server.
proxy.connection.client.src.name
—
the IP address of the client.
For example, you can print out the handshake data and refuse clients by IP address with the following function:
function read_handshake() print("<-- let's send him some information about us") print(" mysqld-version: " .. proxy.connection.server.mysqld_version) print(" thread-id : " .. proxy.connection.server.thread_id) print(" scramble-buf : " .. string.format("%q",proxy.connection.server.scramble_buffer)) print(" server-addr : " .. proxy.connection.server.dst.name) print(" client-addr : " .. proxy.connection.client.dst.name) if not proxy.connection.client.src.name:match("^127.0.0.1:") then proxy.response.type = proxy.MYSQLD_PACKET_ERR proxy.response.errmsg = "only local connects are allowed" print("we don't like this client"); return proxy.PROXY_SEND_RESULT end end
Note that you have to return an error packet to the client by
using proxy.PROXY_SEND_RESULT
.