340 Commits

Author SHA1 Message Date
Markus Makela
eaddc4ea9d Fixed dbfwfilter build failure on Ubuntu
The bison executable didn't generate the headers even though it was instructed
to generate them. This was caused by an older CMake version.
2016-02-09 16:35:51 +02:00
Markus Makela
9e33f300b0 Added flex/bison based parsing of rules to dbfwfilter
The dbfwfilter now uses flex to tokenize the rules and bison to process those
tokens into a language. This will make the syntax checks more robust and
the rule language easier to maintain. It also makes the processing of rules
easier to understand and removes most of the C language side checks for
correctness.

The old rule processing functions are still left intact and will be removed
at a later point.
2016-02-09 11:00:27 +02:00
Markus Makela
6055ba25bf Added logging of matching and non-matching queries to dbfwfilter
When configured to log matching queries, the dbfwfilter will log all queries
that match a rule. The rule name, user name and the query itself are logged.

It is also possible to match all queries that do not match a rule. Only the user
name and query is logged in this mode.
2016-02-09 11:00:27 +02:00
Markus Makela
5efd5d8927 Added user configurable actions to dbfwfilter
The dbfwfilter can now either allow, block or ignore queries that match the
configured rules.
2016-02-09 11:00:27 +02:00
Johan Wikman
4a4f22c9a7 Make query_classifier part of core.
The query classifier interface is now built as an integral
part of MaxScale core.
2016-02-08 11:44:07 +02:00
Johan Wikman
834d04ed6c Merge branch 'MXS-517' into develop 2016-02-08 11:03:31 +02:00
Markus Makela
0d51f78a2a Dbfwfilter now uses PCRE2 regular expressions
Switched from the POSIX regex implementation to PCRE2. This should improve the
filter's performance as well as make the code more manageable.
2016-02-02 12:38:44 +02:00
Markus Makela
7bac2f8fab Moved the applying of rules to users to its own function
This makes the function easier to understand as a whole.
2016-02-02 12:38:44 +02:00
Johan Wikman
fc6f49fe8a Link against Connector-C.
Now, qc_mysqlembedded is linked against MySQL's embedded library,
and MaxScale itself against Connector-C.

So, in order to build MaxScale, Connector-C must be installed.
This has been tested with Connector-C 2.2.1.

The build variable MYSQLCLIENT_LIBRARIES is no longer used.
2016-02-01 15:43:05 +02:00
Johan Wikman
42b1722e49 Make query classifier self-contained.
Only the query classifier needs the functionality of the embedded
server, while the rest of MaxScale is content with the client
library or Connector/C.

This have now been rearranged so that query-classifier links with
the embedded static library and then explicitly exports its own
functions using the query_classifier.map linker script. That way
query classifier will use the embedded library, while the rest of
maxscale use the client library, and this without conflicts.

Currently, query_classifier is not linked to maxscale-common,
but executables must link to maxscale-common and query_classifier.
2016-01-25 21:43:49 +02:00
Johan Wikman
1f241a5ed1 Rearrange libraries and build files.
This is the first change in an attempt to arrange the linking so that
more errors are detected at link-time.

- All files in server/core but for gateway.c are linked to one shared
  library called maxscale-common.
- The files log_manager/log_manager.cc and utils/skygw_utils.cc are
  built into maxscale-common as well.
- MaxScale itself consists now only of gateway.c and is linked with
  maxscale-common.
- All plugins link with maxscale-common.
- All executables link in addition with {EMBEDDED_LIB}.

After this change, the change (MXS-517) where query_classifier is the
only component that uses ${EMBEDDED_LIB} and the rest mysqlclient can
be made much cleaner.

After a few additional steps, all shared libraries can be linked with
the linker flags "-Wl,-z,defs", which directs the linker to resolve
all symbols. That will require that all shared libraries list all the
libraries they need, but will at the same time ensure that any
missing symbols are detected at link-time and not at run-time.
2016-01-22 23:26:17 +02:00
Markus Makela
a2bc15c870 Removed obsolete functions from dbfwfilter
The filter defined its own hashing and string comparison functions even though
there are common functions for both.
2016-01-15 16:22:18 +02:00
Markus Makela
0a3e6b4352 MXS-498: Username and source address added to QLA filter output
The filter now logs the username and remote address of each client. This will
make tracking of users and their queries a lot easier.
2016-01-12 09:30:03 +02:00
Johan Wikman
23a7562d3a Replace skygw_ type prefix with qc_.
- skygw_query_type_t renamed to qc_query_type_t.
- skygw_query_op_t renamed to qc_query_op_t.
2016-01-11 12:06:21 +02:00
Johan Wikman
2f42246880 Rename query classifier functions consistently.
All public query classifier functions now have the prefix qc_.
2016-01-11 12:04:52 +02:00
Johan Wikman
ec281849aa Remove explicit calls to parse_query.
Now that all query classifier functions parse the query if it
has not been parsed, there is no reason for any module to call
parse_query explicitly.
2016-01-11 10:15:13 +02:00
Johan Wikman
57b79fc663 Remove unecessary calls to query_is_parsed/parse_query.
query_classifier_get_operation() parsed the query if it has not
yet been parsed. In the other places, the query need not be
parsed.
2016-01-08 11:52:20 +02:00
Johan Wikman
97282fca97 Make lines of mqfilter.c less that 110 characters long.
Untabified as well.
2016-01-08 11:43:05 +02:00
Markus Makela
40cfe1a864 Merge branch 'release-1.3.0' into develop 2016-01-08 11:14:02 +02:00
Johan Wikman
2b83530ae9 Make dbfwfilter.c rows less than 110 character long. 2016-01-08 10:35:53 +02:00
Markus Makela
080a9ebc9d PCRE2 is now statically linked
Since the PCRE2 library was always going to be a part of MaxScale, there was
no real reason to have it as a shared library apart from smaller binaries.
2015-12-29 10:09:38 +02:00
Markus Makela
0cf564aa0d Fix to MXS-508: Fixed username matching in regexfilter
The username matching was working as intended but the session's active value
was ignored when queries were being routed. This meant that both the username
and the IP address of the user were ignored and query replacement was always
done.
2015-12-29 09:57:27 +02:00
Markus Makela
aff3f66fa6 Fixed compilation error for slavelag.c
There was an extra parenthesis left when skygw_log_write was changed to
MXS_ERROR which caused the compilation to fail.
2015-12-23 06:45:28 +02:00
Markus Makela
78b5777d6e Fixes to Coverity defects
Few fixes to possible use of freed memory and resource leaks.
2015-12-15 13:13:53 +02:00
Markus Makela
3d20beef8c Fixed possible memory leaks in dbfwfilter.c
Made some variables stack allocated so there is no change of memory leaking.
There was no real reason to allocate memory from the heap for the variables in
question since they did not need to persist outside the scope of the function.
2015-12-15 13:09:50 +02:00
Markus Makela
992d6fb3bc Fix to MXS-501: Tee filter and USE ... no longer hangs
Some of the data was not reset for the branch session when a query
was not duplicated which could lead to a hang. Also the COM_FIELD_LIST
duplicated to the branch session even though it doesn't change the
session state.
2015-12-10 09:56:06 +02:00
Johan Wikman
5ebdd6f47d Fix signed/unsigned problem in tee.c 2015-12-10 08:41:20 +02:00
Markus Makela
a663a8ec5c Fix to MXS-500: Statement cloning is now properly handled
If a statement wasn't cloned for the Tee filter, the session would be closed
leading to a possible hang. Instead of closing the session when a statement
isn't cloned, it should not expect a response from that server for that statement.
2015-12-09 13:48:20 +02:00
Markus Makela
a829b38873 Fix to MXS-363: Added soname versions to libraries
The soname version numbers were missing from all the library targets
properties which caused ldconfig to warn about non-symlink libraries
being installed.
2015-11-30 10:46:08 +02:00
Markus Makela
f441f72b75 Added support for librabbitmq-c 0.6.0 and newer
The 0.6.0 version of librabbitmq-c added two parameters to amqp_exchange_declare
which allow auto-deleted and internal exchanges. This change requires more
advanced version detection so that code could be conditionally compiled for
newer versions of the library.
2015-11-27 12:21:19 +02:00
Johan Wikman
916ee5ff2a Rename some log concepts
The mxs prefix is now uniformly used with all log components.
2015-11-26 17:34:53 +02:00
Markus Makela
63da12e5b5 Corrected bugs introduced by refactoring of the dbfwfilter
The limit_queries parsing used a bad initial value for the return value
which lead to a guaranteed failure. Other parts of the code used wrong values
for comparisons leading to sporadic parsing errors.
2015-11-26 09:59:39 +02:00
Markus Makela
443bbe73d2 Mqfilter is built if possible
The mqfilter was not built by default even though it should have been. This has
been fixed but the filter is built only if librabbitmq is found. This was done
to avoid having the librabbitmq and its development headers as a hard
dependency.
2015-11-26 09:28:27 +02:00
Markus Makela
b0458b3cc4 Fixed wrong value being used for users rules in dbfwfilter
A parsed, local copy of the string was duplicated instead of the original string
which caused the parsing to always fail.
2015-11-25 17:39:18 +02:00
Markus Makela
038877b8db Fixed minor format errors and resource leaks
Some format strings used integer values for unsigned integers.
Memory and file descriptors leaked in some error conditions.
2015-11-25 12:43:49 +02:00
Markus Makela
59b0555090 Made function parameters const where possible.
Some of the functions for dbfwfilter were taking char* arguments where
const char* was more appropriate.
2015-11-24 13:54:50 +02:00
Markus Makela
cbc1872b2b Refactoring of dbfwfilter limit_queries parsing
Moved parsing of limit_queries into a separate function.
2015-11-24 13:54:50 +02:00
Markus Makela
76dc63efa2 Moved rule definition parsing to its own function
A large part of parse_query was parsing of the actual rule definitions. This made
the function very large and hard to understand. For this reason the definition parsing
was moved to its own function.
2015-11-24 13:54:50 +02:00
Markus Makela
62ca9ab8ec Moved parsing of at_times rules to a separate function
This was done in order to make the parse_rule function smaller and easier to
comprehend.
2015-11-24 13:54:28 +02:00
Johan Wikman
6164b7f301 Fixed unsafe use of localtime
Since localtime is not thread-safe it should not be used in multithreaded
contexts. For this reason all calls to localtime were changed to localtime_r
in code where concurrency issues were possible.

Internal tests were left unchanged because they aren't multithreaded.
2015-11-19 17:17:16 +02:00
Markus Makela
84d2c72db2 Formatted mqfilter
Mqfilter formatted according to the style guide.
2015-11-19 12:16:47 +02:00
Markus Makela
cbeead7c43 Formatted namedserverfilter
Namedserverfilter formatted according to the style guide.
2015-11-18 14:44:05 +02:00
Markus Makela
036fd6f16c Formatted qlafilter
Qlafilter formatted according to the style guide.
2015-11-18 14:31:02 +02:00
Markus Makela
a7c0952e66 Formatted tee filter
Tee filter formatted according to the style guide.
2015-11-18 14:18:00 +02:00
Markus Makela
e24504c427 Formatted topfilter
Topfilter is now formatted according to the style guide.
2015-11-18 13:46:23 +02:00
Markus Makela
7d9324ee12 Formatted regexfilter
Formatted regexfilter according to the style guide and removed trailing whitespace.
2015-11-18 13:35:04 +02:00
Markus Makela
da74bb7c3f Formatted dbfwfilter according to the style guide
Fixed indentation, bracket alignment and other minor things.
2015-11-18 10:12:04 +02:00
Johan Wikman
1bfe85099f server/module/filters: All LOGIF and skygw_log_write calls removed.
All LOGIF and skygw_log_write calls have been replaced with the
equivalent MXS_[ERROR|WARNING|NOTICE|INFO|DEBUG] calls.
2015-11-16 14:25:02 +02:00
Markus Makela
b22d40b06b Fixed PCRE2 beng built when CMake is configured
The bundled PCRE2 library will be built as a separate target and configuring
CMake no longer builds it. Instead, it will only be built when it is out of date.
This requires all targets to declare that they depend on the pcre2 target in
order for it to be built.
2015-11-16 13:59:47 +02:00
Johan Wikman
a355e1beef Printf format checking added to logging function.
Printf format checking added to logging function and all
issues that were revealed by that fixed.
2015-11-16 12:40:49 +02:00