104 Commits

Author SHA1 Message Date
Markus Mäkelä
45e0e8bb59 Introduce internal protocol command enum
The enums exposed by the connector are not intended to be used by the
users of the library. The fact that the protocol, and other, modules used
it was in violation of how the library is intended to be used.

Adding an internal mapping into MaxScale also removes some of the
dependencies that the core has on the connector.
2017-09-14 15:30:43 +03:00
Markus Mäkelä
3676dcebb1 MXS-1398: Clean up mysql.h header
Cleaned up the MaxScale version of the mysql.h header by removing all
unused includes. This revealed a large amount of dependencies on these
removed includes in other files which needed to be fixed.

Also sorted all includes in changed files by type and alphabetical
order. Removed explicit revision history from modified files.
2017-09-14 15:30:43 +03:00
Markus Mäkelä
16d3eab59f Merge branch '2.1' into develop 2017-09-12 22:42:11 +03:00
Johan Wikman
02b9e0a01d Merge branch '2.1.7' into develop-2.1-merge 2017-09-12 11:08:02 +03:00
Markus Mäkelä
9ceb23dd65 MXS-1396: Fix persistent connection hangs
When a COM_CHANGE_USER was executed, it is possible that the server
responds with a AuthSwitchRequest packet instead of an OK packet. In this
case, the server sends a new scramble which must be used to create the 20
byte hash that is expected as the response.
2017-09-11 12:50:24 +03:00
Markus Mäkelä
e0c2af45c7 Handle AuthSwitchRequest responses to COM_CHANGE_USER
The COM_CHANGE_USER that is sent as a part of the reset process for a
persistent connection did not expect a AuthSwitchRequest packet to be sent
as that implies that the server did not take the authentication fast
path. In this case, an error message needs to be logged stating that the
server requested a different authentication plugin than was expected.
2017-09-07 09:51:23 +03:00
Johan Wikman
84300c6d97 Do not manipulate read queue directly
Protocol modules should not manupulate the read queue directly,
but always access it via the functions created for that purpose.
2017-09-06 11:21:47 +03:00
Markus Mäkelä
642232e26b Fix COM_CHANGE_USER unknown response handling
The response handling logic did not always take the last packet for
inspection when a COM_CHANGE_USER was executed. The OK packet will always
be the last one since the COM_CHANGE_USER is the last command that was
sent.
2017-09-04 17:45:30 +03:00
Markus Mäkelä
7cef722282 Handle unexpected responses to COM_CHANGE_USER
When an unexpected response to a COM_CHANGE_USER is received, it is now
processes and discarded instead of treated as an error. This will allow
further analysis of the situation in addition to possibly solving some of
the problems that the persistent connections have.

Added extra info level logging to relevant parts of the code that deal
with the COM_CHANGE_USER reply processing. This information should allow
tracking of the response state for debugging purposes.
2017-09-01 11:28:21 +03:00
Markus Mäkelä
c5581faae7 Always collect contiguous results for COM_CHANGE_USER
The response to the COM_CHANGE_USER should always be turned into a
contiguous buffer of complete packets. This guarantees that the code that
processes it functions properly.
2017-08-29 22:24:00 +03:00
Markus Mäkelä
866a15dafa Skip COM_CHANGE_USER for COM_QUIT
As COM_QUIT would terminate the connection, there's no need to initiate
the session reset process. Also make sure all buffers are empty before
putting the DCB into the pool.

Added extra debug assertions for parts of the code that are related to the
COM_CHANGE_USER processing.
2017-08-29 11:15:06 +03:00
Markus Mäkelä
13f7015e7b Fix EOF packet calculation for large rows
The EOF packet calculation function in modutil.cc didn't handle the case
where the payload exceeded maximum packet size and could mistake binary
data for a ERR packet.

The state of a multi-packet payload is now exposed by the
modutil_count_signal_packets function. This allows proper handling of
large multi-packet payloads.

Added minor improvements to mxs1110_16mb to handle testing of this change.
2017-08-25 17:00:42 +03:00
Johan Wikman
9c25e6d995 MXS-1376 All zombie related code removed
As dcbs are now closed when dcb_close() is called and there is
no zombie queue, the zombie state can also be removed.
2017-08-25 14:48:16 +03:00
Markus Mäkelä
bc889b1b41 MXS-1375: Fix double response to COM_CHANGE_USER
When a persistent connection is reused, a COM_CHANGE_USER command is
executed to reset the session state. If the reused connection was closed
before the response to the COM_CHANGE_USER was received and taken into use
by another connection, another COM_CHANGE_USER would be sent to, again,
reset the session state. Due to the fact that the first response is still
on its way, it will appear as if two responses are generated for a single
COM_CHANGE_USER.

The way to fix this is to avoid putting connections that haven't been
successfully reset into the connection pool.
2017-08-24 09:30:08 +03:00
Markus Mäkelä
55c704a3dd Ignore repeated errors
Only the first error for each DCB should invoke the error handler
routine. All other errors for the same DCB should be ignored.

In practice this appears to happen when epoll return two different types
of error events for the same DCB.
2017-08-18 10:27:28 +03:00
Markus Mäkelä
6c5ae24dff Fix out-of-bounds reads with LOAD DATA LOCAL INFILE
When a LOAD DATA LOCAL INFILE is done, the last packet is an empty packet
which does not contain the command byte. Some parts of the MySQL protocol
modules expected that a command is always present. The proper way to
handle this is to use the mxs_mysql_get_command function which does bounds
checking.
2017-08-18 10:27:28 +03:00
Esa Korhonen
7ba0533cc8 Authenticator API extract-entrypoint returns bool
Extraction either succeeds or fails, it does not need to return
defined integer values.
2017-08-09 17:28:58 +03:00
Markus Mäkelä
35de0c392f Only store established connections in the pool
If a connection has not been fully established (i.e. authentication has
been completed) then it should not be considered as a connection pool
candidate.
2017-08-09 09:22:57 +03:00
Esa Korhonen
8e9c943d48 Proxy protocol setting error detection + documentation
The setting parsing is now similar to the other server settings.
The header is printed if log_info is on.
Changed the setting name to simply "proxy_protocol".
Updated documentation.
2017-08-04 11:43:29 +03:00
MassimilianoPinto
cb57e10761 Develop merge
Develop merge
2017-06-29 15:34:22 +02:00
Markus Mäkelä
705d29ea41 MXS-852: Fix prepared statement collection
If a prepared statement response was collected into one buffer, it doesn't
need to be processed again. By jumping directly to the routing of the
collected result, we prevent the unnecessary splitting of buffers that
appears to happend with continuous preparations of prepared statements.
2017-06-22 10:40:19 +03:00
Markus Mäkelä
d59e98e238 MXS-1267: Remove DCB cloning
The DCB cloning is no longer needed as the tee filter now does the session
branching by simulating a local client connection.
2017-06-02 13:07:02 +03:00
Markus Mäkelä
e43cdcf741 MXS-1267: Expose MySQL backend authentication
Refactored the backend authentication functions so that they can be
exposed to the tee filter. This allows the tee filter to use the same
functions as the protocol modules use without having to reimplement them
inside the tee filter.
2017-06-02 13:07:02 +03:00
Johan Wikman
f546a17e77 Update change date of 2.2 2017-06-01 10:24:20 +03:00
Markus Mäkelä
4117dcf410 Only store established connections in the pool
If a connection has not been fully established (i.e. authentication has
been completed) then it should not be considered as a connection pool
candidate.
2017-05-15 19:32:02 +03:00
Esa Korhonen
8f50269338 Add proxy protocol support
Adds a server-specific parameter, "use_proxy_protocol". If enabled,
a header string is sent to the backend when a routing session connection
changes state to MXS_AUTH_STATE_CONNECTED. The string contains the real
client IP and port.
2017-04-27 12:29:46 +03:00
Markus Mäkelä
36d06960bf Combine query preparation into one function
The same operations of protocol state and inspections of the buffer were
done in multiple places. Combining these into one function removes the
duplicated code.
2017-04-20 14:22:55 +03:00
Markus Mäkelä
73dd9bd025 Allow collection of prepared statement responses
The backend MySQL protocol can now collect prepared statement preparation
responses as well as result sets. This removes the need to parse and
collect the preparation responses at the router level.
2017-04-20 14:22:55 +03:00
Markus Mäkelä
a88e98035f Clean up MySQL protocol debug logging
Removed pthread_self calls from the backend modules. This makes the debug
logging easier to parse when the messages aren't prefixed with the verbose
thread ID.
2017-04-20 14:22:55 +03:00
Markus Mäkelä
8fe31f360d Remove multi-packet additions to response parsing
The additions to the packet parsing code weren't necessary once the
statement output change was reverted.
2017-04-20 14:18:40 +03:00
Markus Mäkelä
d7258fffd0 MXS-1203: Improve resultset processing functions
The functions used to track the resultset EOF packets now expose the
position of the end of the result set. This allows the modules that use
them to check if more results exist in the same buffer.

Added the status bits for OK and EOF packets to the mysql.h protocol
header. This can be used to check for various state changes that happen in
the session. Currently the status bits are only used to detect if more
results are expected.
2017-04-20 14:18:40 +03:00
Markus Mäkelä
66cf571412 MXS-1203: Better handling of batch queries
When batched queries are done through readwritesplit, it will now handle
them one by one. This allows batched queries to be used with
readwritesplit but it does impose a performance penalty when compared to
direct execution on the backend.
2017-04-20 14:18:39 +03:00
Markus Mäkelä
ad1c05b015 Merge branch '2.1' into develop 2017-04-05 11:35:13 +03:00
Markus Mäkelä
1ff83150f0 Revert "Route statements in larger batches"
This reverts commit f3c83770903151a0a3b53593c3e05fa0af94cd5f. The
functionality was used implicitly by modules that declare the
RCAP_TYPE_CONTIGUOUS_OUTPUT capability.
2017-04-04 09:56:51 +03:00
Markus Mäkelä
f3c8377090 Route statements in larger batches
The RCAP_TYPE_STMT_OUTPUT is not used in its previous form. It can be
altered to route only complete packets back to the client. This allows
routers to do safer parsing on the results.
2017-04-03 12:07:45 +03:00
Markus Mäkelä
cbc1e864d9 Use RFC 3986 compliant addresses in log messages
When log messages are written with both address and port information, IPv6
addresses can cause confusion if the normal address:port formatting is
used. The RFC 3986 suggests that all IPv6 addresses are expressed as a
bracket enclosed address optionally followed by the port that is separate
from the address by a colon.

In practice, the "all interfaces" address and port number 3306 can be
written in IPv4 numbers-and-dots notation as 0.0.0.0:3306 and in IPv6
notation as [::]:3306. Using the latter format in log messages keeps the
output consistent with all types of addresses.

The details of the standard can be found at the following addresses:

     https://www.ietf.org/rfc/rfc3986.txt

     https://www.rfc-editor.org/std/std66.txt
2017-03-31 14:12:58 +03:00
Markus Mäkelä
c2857b976a Add collectable resultset buffer type
The new type allows routers to send queries and get complete result sets
as a response. This allows the routers to easily send commands that create
result sets and which are parsed by the router.

Currently only the schemarouter benefits from this new capability as it
generates the database mappings by parsing the output of a SHOW DATABASES
query.
2017-03-31 14:12:02 +03:00
Markus Mäkelä
5c1c89c835 Remove unused buffer types
A part of the buffer types weren't used or provided no real functionality.
2017-03-31 14:12:02 +03:00
Markus Mäkelä
1ba399a62a Use size_t in all functions
Some of the protocol modules use ssize_t instead of size_t.

Split the function that counts the number of response packets a session
command will receive into two parts. This allows it to be reused
elsewhere.
2017-03-31 14:12:00 +03:00
Markus Mäkelä
509a5c6ed3 Fix error handling for binlogrouter
The binlogrouter error handling closed the DCB twice. This was caused by
the change in the way the DCB error handling is done.

The protocol modules now also call the error handling routine even if the
router session is NULL. This enables the binlogrouter to manage
authentication failures correctly instead of trying to reconnect again.
2017-03-31 14:11:46 +03:00
Markus Mäkelä
710012ac5d MXS-827: Add connection keepalive
The readwritesplit now sends COM_PING queries to backend servers that have
been idle for too long. The option is configured with the
`connection_keepalive` parameter.
2017-03-26 13:57:25 +03:00
Markus Mäkelä
1736aca7f7 Add module level static capabilities
The static capabilities declared in getCapabilities allows certain
capabilities to be queried before instances are created. The intended use
of this capability is to remove the need for the `is_internal_service`
function.
2017-03-20 11:10:08 +02:00
Markus Mäkelä
8c7618035b Merge branch '2.1' into develop 2017-03-14 10:45:25 +02:00
Markus Mäkelä
7b3c287ac3 Close sessions in MaxScale core
The core now provides a simple function to close a session. This removes
the need for the modules to directly call the API entry points when the
session should be closed. It is also in line with the style that other
objects, namely the DCBs, use. This makes the new session_close very
similar to dcb_close.
2017-03-14 10:45:10 +02:00
Markus Mäkelä
4d561c5f6a Detect password usage based on token length
The client protocol module can resolve whether a password was used based
on the information the authenticators gather before authentication is
done. It uses the authentication token length as the basis on which it
makes the decision.
2017-03-13 19:42:38 +02:00
Markus Mäkelä
147a1f88eb Merge branch '2.1-ipv6' into develop 2017-03-13 13:18:08 +02:00
Markus Mäkelä
e8ef701409 Combine socket creation code
The client connection and the server listener sockets used largely similar
code. Combining them allows for simpler protocol code.

Cleaned up parts of the DCB listener creation and moved the parsing of the
network binding configuration to a higher level.
2017-03-13 10:45:56 +02:00
Markus Mäkelä
66ba7f3c80 Simplify network socket creation code
The socket creation code in mysql_backend.c wasn't MySQL specific and it
could be used for all non-blocking network connections. Thus, it makes
sense to move it to a common file where other protocol modules can use
it.

The address resolution code now uses `getaddrinfo` to resolve all
addresses instead of manually handling wildcard hosts. This allows the
same code to be used for all addresses.
2017-03-13 10:45:55 +02:00
Markus Mäkelä
37dd561470 Add support for IPv6
Both the listeners and servers now support IPv6 addresses.

The namedserverfilter does not yet use the new structures and needs to be
fixed in a following commit.
2017-03-13 10:45:55 +02:00
Markus Mäkelä
b376d9043a Use new authentication for reauthentication
This fixes the reauthentication of users that was missing from the new
implementation. Now COM_CHANGE_USER should work properly.
2017-03-13 10:45:52 +02:00