82 Commits

Author SHA1 Message Date
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
Markus Mäkelä
d4a06c61de Move reauthentication to authenticators
Currently the only situation where a user needs to be authenticated after
the initial authentication is when a COM_CHANGE_USER is being
executed. This was previously handled by directly calling a function in
the MySQLAuth authenticator.

The new entry in the API of the authenticators is very specific to MySQL
and should be reviewed once other protocols are added.
2017-03-13 10:45:51 +02:00
Markus Mäkelä
e1a1959bc2 Replace strerror_r with mxs_strerror
The mxs_strerror function requires no local buffer, thus making it simpler
and cleaner to use.
2017-03-09 09:36:57 +02:00
Markus Mäkelä
29ece502f5 Minor refactoring of error handling
Refactored common code into a reusable function. Now all of the backend
error handling uses the same function.

Moved responsibility of the DCB error handling tracking to the backend
protocol. The routers no longer need to manage the
`dcb->dcb_errhandle_called` variable of the failed DCB.

Removed calls to handleError with client DCBs as parameters. All of the
routers close the DCB given to handleError if it is a client DCB. The only
time the error handler would be called is when the routeQuery function
fails. The handleError call is redundant as the router already knows that
the session should be closed when it returns from routeQuery.
2017-03-07 11:12:56 +02:00
Johan Wikman
b3e8ea9b5a Merge branch '2.1' into develop 2017-03-03 13:37:14 +02:00
Markus Mäkelä
644b139b00 Add support for 10.2 server capabilities
Added support for 10.2 server capabilities and cleaned up the server
capability flags.
2017-02-21 11:27:03 +02:00
Johan Wikman
71707c8505 Merge branch '2.1' into develop 2017-02-15 08:48:36 +02:00
Johan Wikman
49cc2b52e3 Merge branch '2.1.0' into 2.1 2017-02-15 08:44:55 +02:00
Johan Wikman
5648f708af Update license to BSL 1.1 2017-02-14 21:42:28 +02:00
Johan Wikman
54d4a562ce Merge branch '2.1' into develop 2017-02-09 15:07:13 +02:00
Markus Mäkelä
ce5cd69eb3 Remove unused locks and variables
Removed unused spinlocks from DCBs, sessions and the MySQL protocol
structs. They were used in a context where only one thread has access to
the structure.

Removed unused member variables from DCBs.
2017-02-08 15:31:17 +02:00
Markus Mäkelä
fe1a49f4e9 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-02-07 10:03:57 +02:00
Markus Mäkelä
ce5e429ad3 Move reauthentication to authenticators
Currently the only situation where a user needs to be authenticated after
the initial authentication is when a COM_CHANGE_USER is being
executed. This was previously handled by directly calling a function in
the MySQLAuth authenticator.

The new entry in the API of the authenticators is very specific to MySQL
and should be reviewed once other protocols are added.
2017-02-07 10:03:57 +02:00
Esa Korhonen
8b83bf834e Clean up router.h
Nothing moved to core, just rename and cleanup.
2017-01-26 16:14:17 +02:00
Esa Korhonen
fe1863bb49 Remove bitmask.h & .c, since the container is no longer used 2017-01-24 14:28:28 +02:00
Esa Korhonen
fb771c8a2e Rename public types and constants in session.h
Preparing to split session.h into module and core sections.
2017-01-17 16:30:14 +02:00
Markus Mäkelä
1766e3a06b Format protocol modules
Formatted protocol modules with Astyle.
2017-01-17 14:47:50 +02:00
Markus Mäkelä
2cabcea211 Add definitions of MXS_MODULE_NAME to all modules
All modules now declare a name for the module. This is name is added as a
prefix to all messages logged by a module. The prefix should help
determine which part of the system logs a message.
2017-01-16 11:28:34 +02:00
Johan Wikman
2fa12f796b Rename MYSQL_GET_PACKET_LEN to MYSQL_GET_PAYLOAD_LEN
The function returns the length of the payload, not the length of
the entire packet.
2017-01-12 14:24:14 +02:00
Johan Wikman
a2a38f952a Add [process|thread] [init|finish] functions to modules
The MXS_MODULDE object now contains optinal pointers for functions
to be called att process and thread startup and shutdown. Since the
functions were added to the end, strictly speaking, all structures
would not have needed to have been modified, but better to be
explicit. In a subsequent change, these will be called.

C++ does not support flexible arrays, so for the time being C++
modules are restricted to 10 parameters. Better approach is to
factor out the parameters to a separate array and then just store
a pointer to that array in MXS_MODULE.
2017-01-05 14:44:02 +02:00
Johan Wikman
2abe956056 Rename GWPROTOCOL to MXS_PROTOCOL 2017-01-05 14:36:44 +02:00
Johan Wikman
19ce28a43a Rename gw_protocol.h to protocol.h 2017-01-05 14:36:44 +02:00
Markus Mäkelä
c96bd64aa8 Rename MODULE_INFO to MXS_MODULE
The MODULE_INFO is now the main object which is used by modules to convey
information to the MaxScale core. The MXS_MODULE name is more apt as it
now contains the actual module definition.

The old MODULES structure was moved into load_utils.c as an internal
implementation and was renamed so that it is not confused with the new
MODULE structure.
2017-01-03 18:01:14 +02:00