Examining the Handshake with read_handshake()
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 MariaDB 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 MariaDB 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 must return an error packet to the client by using proxy.PROXY_SEND_RESULT
.