From 3813c728b1dd75026c5fcaa5d0eaf070ef0e7eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 8 May 2019 09:39:19 +0300 Subject: [PATCH] Move listener parameter handling into Listener::create The Listener::create method now takes a set of configuration parameters from which it constructs a listener. This removes the duplicated code and makes the behavior of listener creation similar to other objects in MaxScale. It also allows the configuration parameters to be stored in the listener object itself. --- include/maxscale/listener.hh | 52 +++++----- server/core/config.cc | 97 ++----------------- server/core/config_runtime.cc | 96 ++++++++---------- server/core/internal/config.hh | 8 +- server/core/listener.cc | 94 +++++++++++++++--- server/core/server.cc | 2 +- server/core/test/test_dcb.cc | 10 +- server/core/test/test_poll.cc | 10 +- server/core/test/test_service.cc | 16 +-- .../filter/cache/test/test_cacheoptions.cc | 12 ++- .../filter/dbfwfilter/test/test_dbfwfilter.cc | 13 ++- .../routing/binlogrouter/blr_master.cc | 11 ++- 12 files changed, 214 insertions(+), 207 deletions(-) diff --git a/include/maxscale/listener.hh b/include/maxscale/listener.hh index 2d1b43554..1960ff009 100644 --- a/include/maxscale/listener.hh +++ b/include/maxscale/listener.hh @@ -52,25 +52,15 @@ public: /** * Create a new listener * - * @param service Service where the listener points to - * @param name Name of the listener - * @param protocol Protocol module to use - * @param address The address to listen with - * @param port The port to listen on - * @param authenticator Name of the authenticator to be used - * @param auth_options Authenticator options - * @param ssl SSL configuration + * @param name Name of the listener + * @param protocol Protocol module to use + * @param params Parameters for the listener * * @return New listener or nullptr on error */ - static SListener create(SERVICE* service, - const std::string& name, + static SListener create(const std::string& name, const std::string& protocol, - const std::string& address, - unsigned short port, - const std::string& authenticator, - const std::string& auth_options, - SSL_LISTENER* ssl); + const MXS_CONFIG_PARAMETER& params); /** * Destroy a listener @@ -211,20 +201,21 @@ private: DESTROYED }; - std::string m_name; /**< Name of the listener */ - State m_state; /**< Listener state */ - std::string m_protocol; /**< Protocol module to load */ - uint16_t m_port; /**< Port to listen on */ - std::string m_address; /**< Address to listen with */ - std::string m_authenticator; /**< Name of authenticator */ - std::string m_auth_options; /**< Authenticator options */ - void* m_auth_instance; /**< Authenticator instance */ - SSL_LISTENER* m_ssl; /**< Structure of SSL data or NULL */ - struct users* m_users; /**< The user data for this listener */ - SERVICE* m_service; /**< The service which used by this listener */ - std::atomic m_active; /**< True if the port has not been deleted */ - MXS_PROTOCOL m_proto_func; /**< Preloaded protocol functions */ - MXS_AUTHENTICATOR m_auth_func; /**< Preloaded authenticator functions */ + std::string m_name; /**< Name of the listener */ + State m_state; /**< Listener state */ + std::string m_protocol; /**< Protocol module to load */ + uint16_t m_port; /**< Port to listen on */ + std::string m_address; /**< Address to listen with */ + std::string m_authenticator; /**< Name of authenticator */ + std::string m_auth_options; /**< Authenticator options */ + void* m_auth_instance; /**< Authenticator instance */ + SSL_LISTENER* m_ssl; /**< Structure of SSL data or NULL */ + struct users* m_users; /**< The user data for this listener */ + SERVICE* m_service; /**< The service which used by this listener */ + std::atomic m_active; /**< True if the port has not been deleted */ + MXS_PROTOCOL m_proto_func; /**< Preloaded protocol functions */ + MXS_AUTHENTICATOR m_auth_func; /**< Preloaded authenticator functions */ + MXS_CONFIG_PARAMETER m_params; /**< Configuration parameters */ Type m_type; /**< The type of the listener */ @@ -258,7 +249,8 @@ private: */ Listener(SERVICE* service, const std::string& name, const std::string& address, uint16_t port, const std::string& protocol, const std::string& authenticator, - const std::string& auth_opts, void* auth_instance, SSL_LISTENER* ssl); + const std::string& auth_opts, void* auth_instance, SSL_LISTENER* ssl, + const MXS_CONFIG_PARAMETER& params); /** * Listen on a file descriptor shared between all workers diff --git a/server/core/config.cc b/server/core/config.cc index a22a3fd8a..983bcbfd5 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -2887,22 +2887,22 @@ static void free_ssl_structure(SSL_LISTENER* ssl) } bool config_create_ssl(const char* name, - MXS_CONFIG_PARAMETER* params, + const MXS_CONFIG_PARAMETER& params, bool require_cert, SSL_LISTENER** dest) { SSL_LISTENER* ssl = NULL; // The enum values convert to bool - int value = params->get_enum(CN_SSL, ssl_values); + int value = params.get_enum(CN_SSL, ssl_values); mxb_assert(value != -1); if (value) { bool error = false; - string ssl_cert = params->get_string(CN_SSL_CERT); - string ssl_key = params->get_string(CN_SSL_KEY); - string ssl_ca_cert = params->get_string(CN_SSL_CA_CERT); + string ssl_cert = params.get_string(CN_SSL_CERT); + string ssl_key = params.get_string(CN_SSL_KEY); + string ssl_ca_cert = params.get_string(CN_SSL_CA_CERT); if (ssl_ca_cert.empty()) { @@ -2942,12 +2942,12 @@ bool config_create_ssl(const char* name, ssl = (SSL_LISTENER*)MXS_CALLOC(1, sizeof(SSL_LISTENER)); MXS_ABORT_IF_NULL(ssl); - int ssl_version = params->get_enum(CN_SSL_VERSION, ssl_version_values); + int ssl_version = params.get_enum(CN_SSL_VERSION, ssl_version_values); ssl->ssl_method_type = (ssl_method_type_t)ssl_version; ssl->ssl_init_done = false; - ssl->ssl_cert_verify_depth = params->get_integer(CN_SSL_CERT_VERIFY_DEPTH); - ssl->ssl_verify_peer_certificate = params->get_bool(CN_SSL_VERIFY_PEER_CERTIFICATE); + ssl->ssl_cert_verify_depth = params.get_integer(CN_SSL_CERT_VERIFY_DEPTH); + ssl->ssl_verify_peer_certificate = params.get_bool(CN_SSL_VERIFY_PEER_CERTIFICATE); listener_set_certificates(ssl, ssl_cert, ssl_key, ssl_ca_cert); @@ -4130,86 +4130,7 @@ int create_new_listener(CONFIG_CONTEXT* obj) return 1; } - int error_count = 0; - - bool port_defined = obj->m_parameters.contains(CN_PORT); - bool socket_defined = obj->m_parameters.contains(CN_SOCKET); - - if (port_defined && socket_defined) - { - MXS_ERROR("Creation of listener '%s' failed because both 'socket' and 'port' " - "are defined. Only one of them is allowed.", - obj->name()); - error_count++; - } - else if (!port_defined && !socket_defined) - { - MXS_ERROR("Listener '%s' is missing a required parameter. A Listener " - "must have a service, protocol and port (or socket) defined.", - obj->name()); - error_count++; - } - else - { - auto address = obj->m_parameters.get_string(CN_ADDRESS); - Service* service = static_cast(obj->m_parameters.get_service(CN_SERVICE)); - mxb_assert(service); - - // The conditionals just enforce defaults expected in the function. - auto port = port_defined ? obj->m_parameters.get_integer(CN_PORT) : 0; - auto socket = socket_defined ? obj->m_parameters.get_string(CN_SOCKET) : ""; - - // Remove this once maxadmin is removed - if (strcasecmp(protocol.c_str(), "maxscaled") == 0 && socket_defined - && socket == MAXADMIN_CONFIG_DEFAULT_SOCKET_TAG) - { - socket = MAXADMIN_DEFAULT_SOCKET; - address = ""; - } - - if (socket_defined) - { - if (auto l = listener_find_by_socket(socket)) - { - MXS_ERROR("Creation of listener '%s' for service '%s' failed, because " - "listener '%s' already listens on socket %s.", - obj->name(), service->name(), l->name(), socket.c_str()); - return 1; - } - } - else if (auto l = listener_find_by_address(address, port)) - { - MXS_ERROR("Creation of listener '%s' for service '%s' failed, because " - "listener '%s' already listens on port %s.", - obj->name(), service->name(), l->name(), - obj->m_parameters.get_string(CN_PORT).c_str()); - return 1; - } - - auto protocol = obj->m_parameters.get_string(CN_PROTOCOL); - SSL_LISTENER* ssl_info = NULL; - - if (!config_create_ssl(obj->name(), &obj->m_parameters, true, &ssl_info)) - { - return 1; - } - - // These two values being NULL trigger the loading of the default - // authenticators that are specific to each protocol module - auto authenticator = obj->m_parameters.get_string(CN_AUTHENTICATOR); - auto authenticator_options = obj->m_parameters.get_string(CN_AUTHENTICATOR_OPTIONS); - int net_port = socket_defined ? 0 : port; - - auto listener = Listener::create(service, obj->name(), protocol, socket_defined ? socket : address, - net_port, authenticator, authenticator_options, ssl_info); - - if (!listener) - { - ++error_count; - } - } - - return error_count; + return Listener::create(obj->name(), protocol, obj->m_parameters) ? 0 : 1; } /** diff --git a/server/core/config_runtime.cc b/server/core/config_runtime.cc index 08862403c..8e6fe0d56 100644 --- a/server/core/config_runtime.cc +++ b/server/core/config_runtime.cc @@ -470,7 +470,7 @@ static SSL_LISTENER* create_ssl(const char* name, && (!depth || config_add_param(obj, CN_SSL_CERT_VERIFY_DEPTH, depth)) && (!verify || config_add_param(obj, CN_SSL_VERIFY_PEER_CERTIFICATE, verify))) { - config_create_ssl(name, &obj->m_parameters, true, &rval); + config_create_ssl(name, obj->m_parameters, true, &rval); } config_context_free(obj); @@ -1155,31 +1155,14 @@ bool runtime_create_listener(Service* service, const char* ssl_depth, const char* verify_ssl) { - - if (addr == NULL || strcasecmp(addr, CN_DEFAULT) == 0) - { - addr = "::"; - } - if (port == NULL || strcasecmp(port, CN_DEFAULT) == 0) - { - port = "3306"; - } if (proto == NULL || strcasecmp(proto, CN_DEFAULT) == 0) { proto = "mariadbclient"; } - if (!auth || strcasecmp(auth, CN_DEFAULT) == 0) - { - /** Use protocol default authenticator*/ - auth = ""; - } - - if (!auth_opt || strcasecmp(auth_opt, CN_DEFAULT) == 0) - { - /** Don't pass options to the authenticator */ - auth_opt = ""; - } + MXS_CONFIG_PARAMETER params; + bool ok; + tie(ok, params) = load_defaults(proto, MODULE_PROTOCOL, CN_LISTENER); unsigned short u_port = atoi(port); bool rval = false; @@ -1187,7 +1170,11 @@ bool runtime_create_listener(Service* service, std::lock_guard guard(crt_lock); std::string reason; - if (listener_find(name)) + if (!ok) + { + config_runtime_error("Failed to load module '%s'", proto); + } + else if (listener_find(name)) { config_runtime_error("Listener '%s' already exists", name); } @@ -1197,49 +1184,50 @@ bool runtime_create_listener(Service* service, } else if (config_is_valid_name(name, &reason)) { - SSL_LISTENER* ssl = NULL; - - if (ssl_key && ssl_cert && ssl_ca - && (ssl = - create_ssl(name, - ssl_key, - ssl_cert, - ssl_ca, - ssl_version, - ssl_depth, - verify_ssl)) == NULL) + if (addr == NULL || strcasecmp(addr, CN_DEFAULT) == 0) { - MXS_ERROR("SSL initialization for listener '%s' failed.", name); - config_runtime_error("SSL initialization for listener '%s' failed.", name); + params.set(CN_ADDRESS, "::"); } - else + + if (port == NULL || strcasecmp(port, CN_DEFAULT) == 0) { - const char* print_addr = addr ? addr : "::"; - auto listener = Listener::create(service, name, proto, addr, u_port, auth, auth_opt, ssl); + params.set(CN_PORT, "3306"); + } - if (listener && listener_serialize(listener)) + if (auth && strcasecmp(auth, CN_DEFAULT) != 0) + { + params.set(CN_AUTHENTICATOR, auth); + } + + if (auth_opt && strcasecmp(auth_opt, CN_DEFAULT) != 0) + { + params.set(CN_AUTHENTICATOR_OPTIONS, auth_opt); + } + + const char* print_addr = addr ? addr : "::"; + auto listener = Listener::create(name, proto, params); + + if (listener && listener_serialize(listener)) + { + if (listener->listen()) { - MXS_NOTICE("Created %slistener '%s' at %s:%s for service '%s'", - ssl ? "TLS encrypted " : "", name, print_addr, port, service->name()); + MXS_NOTICE("Created listener '%s' at %s:%u for service '%s'", + name, listener->address(), listener->port(), service->name()); - if (listener->listen()) - { - rval = true; - } - else - { - MXS_ERROR("Listener '%s' was created but failed to start it.", name); - config_runtime_error("Listener '%s' was created but failed to start it.", name); - Listener::destroy(listener); - mxb_assert(!listener_find(name)); - } + rval = true; } else { - MXS_ERROR("Failed to create listener '%s' at %s:%s.", name, print_addr, port); - config_runtime_error("Failed to create listener '%s' at %s:%s.", name, print_addr, port); + config_runtime_error("Listener '%s' was created but failed to start it.", name); + Listener::destroy(listener); + mxb_assert(!listener_find(name)); } } + else + { + MXS_ERROR("Failed to create listener '%s' at %s:%s.", name, print_addr, port); + config_runtime_error("Failed to create listener '%s' at %s:%s.", name, print_addr, port); + } } else { diff --git a/server/core/internal/config.hh b/server/core/internal/config.hh index c25c60d7f..de2f8b25e 100644 --- a/server/core/internal/config.hh +++ b/server/core/internal/config.hh @@ -70,9 +70,9 @@ void config_set_global_defaults(); */ void config_add_defaults(CONFIG_CONTEXT* ctx, const MXS_MODULE_PARAM* params); -char* config_clean_string_list(const char* str); -bool config_load(const char*); -bool config_load_global(const char* filename); +char* config_clean_string_list(const char* str); +bool config_load(const char*); +bool config_load_global(const char* filename); /** * @brief Creates an empty configuration context @@ -140,7 +140,7 @@ void config_remove_param(CONFIG_CONTEXT* obj, const char* name); * @return True on success, false on error */ bool config_create_ssl(const char* name, - MXS_CONFIG_PARAMETER* params, + const MXS_CONFIG_PARAMETER& params, bool require_cert, SSL_LISTENER** dest); diff --git a/server/core/listener.cc b/server/core/listener.cc index 1f310a953..0f15c62a2 100644 --- a/server/core/listener.cc +++ b/server/core/listener.cc @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -40,6 +41,7 @@ #include "internal/modules.hh" #include "internal/session.hh" +#include "internal/config.hh" using Clock = std::chrono::steady_clock; using std::chrono::seconds; @@ -99,9 +101,16 @@ private: thread_local RateLimit rate_limit; } -Listener::Listener(SERVICE* service, const std::string& name, const std::string& address, - uint16_t port, const std::string& protocol, const std::string& authenticator, - const std::string& auth_opts, void* auth_instance, SSL_LISTENER* ssl) +Listener::Listener(SERVICE* service, + const std::string& name, + const std::string& address, + uint16_t port, + const std::string& protocol, + const std::string& authenticator, + const std::string& auth_opts, + void* auth_instance, + SSL_LISTENER* ssl, + const MXS_CONFIG_PARAMETER& params) : MXB_POLL_DATA{Listener::poll_handler} , m_name(name) , m_state(CREATED) @@ -116,6 +125,7 @@ Listener::Listener(SERVICE* service, const std::string& name, const std::string& , m_service(service) , m_proto_func(*(MXS_PROTOCOL*)load_module(protocol.c_str(), MODULE_PROTOCOL)) , m_auth_func(*(MXS_AUTHENTICATOR*)load_module(authenticator.c_str(), MODULE_AUTHENTICATOR)) + , m_params(params) { if (strcasecmp(service->router_name(), "cli") == 0 || strcasecmp(service->router_name(), "maxinfo") == 0) { @@ -145,15 +155,75 @@ Listener::~Listener() SSL_LISTENER_free(m_ssl); } -SListener Listener::create(SERVICE* service, - const std::string& name, +SListener Listener::create(const std::string& name, const std::string& protocol, - const std::string& address, - unsigned short port, - const std::string& authenticator, - const std::string& auth_options, - SSL_LISTENER* ssl) + const MXS_CONFIG_PARAMETER& params) { + bool port_defined = params.contains(CN_PORT); + bool socket_defined = params.contains(CN_SOCKET); + Service* service = static_cast(params.get_service(CN_SERVICE)); + + if (port_defined && socket_defined) + { + MXS_ERROR("Creation of listener '%s' failed because both 'socket' and 'port' " + "are defined. Only one of them is allowed.", + name.c_str()); + return nullptr; + } + else if ((!port_defined && !socket_defined) || !service) + { + MXS_ERROR("Listener '%s' is missing a required parameter. A Listener " + "must have a service, protocol and port (or socket) defined.", + name.c_str()); + return nullptr; + } + + // The conditionals just enforce defaults expected in the function. + auto port = port_defined ? params.get_integer(CN_PORT) : 0; + auto socket = socket_defined ? params.get_string(CN_SOCKET) : ""; + auto address = socket_defined ? params.get_string(CN_SOCKET) : params.get_string(CN_ADDRESS); + + // Remove this once maxadmin is removed + if (strcasecmp(protocol.c_str(), "maxscaled") == 0 && socket_defined + && socket == MAXADMIN_CONFIG_DEFAULT_SOCKET_TAG) + { + socket = MAXADMIN_DEFAULT_SOCKET; + address = ""; + } + + if (socket_defined) + { + if (auto l = listener_find_by_socket(socket)) + { + MXS_ERROR("Creation of listener '%s' for service '%s' failed, because " + "listener '%s' already listens on socket %s.", + name.c_str(), service->name(), l->name(), socket.c_str()); + return nullptr; + } + } + else if (auto l = listener_find_by_address(address, port)) + { + MXS_ERROR("Creation of listener '%s' for service '%s' failed, because " + "listener '%s' already listens on port %s.", + name.c_str(), service->name(), l->name(), + params.get_string(CN_PORT).c_str()); + return nullptr; + } + + SSL_LISTENER* ssl_info = NULL; + + if (!config_create_ssl(name.c_str(), params, true, &ssl_info)) + { + return nullptr; + } + + // These two values being NULL trigger the loading of the default + // authenticators that are specific to each protocol module + auto authenticator = params.get_string(CN_AUTHENTICATOR); + auto authenticator_options = params.get_string(CN_AUTHENTICATOR_OPTIONS); + int net_port = socket_defined ? 0 : port; + + const char* auth = !authenticator.empty() ? authenticator.c_str() : get_default_authenticator(protocol.c_str()); @@ -166,7 +236,7 @@ SListener Listener::create(SERVICE* service, void* auth_instance = NULL; - if (!authenticator_init(&auth_instance, auth, auth_options.c_str())) + if (!authenticator_init(&auth_instance, auth, authenticator_options.c_str())) { MXS_ERROR("Failed to initialize authenticator module '%s' for listener '%s'.", auth, name.c_str()); @@ -179,7 +249,7 @@ SListener Listener::create(SERVICE* service, mxb_assert(proto_mod && auth_mod); SListener listener(new(std::nothrow) Listener(service, name, address, port, protocol, auth, - auth_options, auth_instance, ssl)); + authenticator_options, auth_instance, ssl_info, params)); if (listener) { diff --git a/server/core/server.cc b/server/core/server.cc index 94246a14e..22372995c 100644 --- a/server/core/server.cc +++ b/server/core/server.cc @@ -197,7 +197,7 @@ Server* Server::server_alloc(const char* name, MXS_CONFIG_PARAMETER* params) SSL_LISTENER* ssl = NULL; - if (!config_create_ssl(name, params, false, &ssl)) + if (!config_create_ssl(name, *params, false, &ssl)) { MXS_ERROR("Unable to initialize SSL for server '%s'", name); return NULL; diff --git a/server/core/test/test_dcb.cc b/server/core/test/test_dcb.cc index e0264c9d7..81aef9c02 100644 --- a/server/core/test/test_dcb.cc +++ b/server/core/test/test_dcb.cc @@ -54,7 +54,15 @@ static int test1() parameters.set("max_retry_interval", "10s"); parameters.set("connection_timeout", "10s"); auto service = service_alloc("service", "readconnroute", ¶meters); - auto listener = Listener::create(service, "listener", "mariadbclient", "0.0.0.0", 3306, "", "", nullptr); + + MXS_CONFIG_PARAMETER listener_params; + listener_params.set(CN_ADDRESS, "0.0.0.0"); + listener_params.set(CN_PORT, "3306"); + listener_params.set(CN_PROTOCOL, "mariadbclient"); + listener_params.set(CN_SERVICE, service->name()); + + auto listener = Listener::create("listener", "mariadbclient", listener_params); + auto session = new mxs::Session(listener); dcb = dcb_alloc(DCB::Role::INTERNAL, session); printDCB(dcb); diff --git a/server/core/test/test_poll.cc b/server/core/test/test_poll.cc index 2a9911e70..4fd6574c4 100644 --- a/server/core/test/test_poll.cc +++ b/server/core/test/test_poll.cc @@ -60,7 +60,15 @@ static int test1() parameters.set(CN_MAX_RETRY_INTERVAL, "10s"); parameters.set(CN_CONNECTION_TIMEOUT, "10s"); auto service = service_alloc("service", "readconnroute", ¶meters); - auto listener = Listener::create(service, "listener", "mariadbclient", "0.0.0.0", 3306, "", "", nullptr); + + MXS_CONFIG_PARAMETER listener_params; + listener_params.set(CN_ADDRESS, "0.0.0.0"); + listener_params.set(CN_PORT, "3306"); + listener_params.set(CN_PROTOCOL, "mariadbclient"); + listener_params.set(CN_SERVICE, service->name()); + + auto listener = Listener::create("listener", "mariadbclient", listener_params); + auto session = new mxs::Session(listener); dcb = dcb_alloc(DCB::Role::CLIENT, session); diff --git a/server/core/test/test_service.cc b/server/core/test/test_service.cc index 21eaaccf1..fc7bbe3cb 100644 --- a/server/core/test/test_service.cc +++ b/server/core/test/test_service.cc @@ -78,14 +78,14 @@ static int test1() mxb_assert_message(0 != service_isvalid(service), "Service must be valid after creation"); mxb_assert_message(0 == strcmp("MyService", service->name()), "Service must have given name"); fprintf(stderr, "\t..done\nAdding protocol testprotocol."); - mxb_assert_message(Listener::create(service, - "TestProtocol", - "mariadbclient", - "localhost", - 9876, - "MySQLAuth", - "", - NULL), + + MXS_CONFIG_PARAMETER listener_params; + listener_params.set(CN_ADDRESS, "localhost"); + listener_params.set(CN_PORT, "9876"); + listener_params.set(CN_PROTOCOL, "mariadbclient"); + listener_params.set(CN_SERVICE, service->name()); + + mxb_assert_message(Listener::create("TestProtocol", "mariadbclient", listener_params), "Add Protocol should succeed"); mxb_assert_message(service_find_listener(service, "", "localhost", 9876), "Service should have new protocol as requested"); diff --git a/server/modules/filter/cache/test/test_cacheoptions.cc b/server/modules/filter/cache/test/test_cacheoptions.cc index b322b2f82..bb3c9736a 100644 --- a/server/modules/filter/cache/test/test_cacheoptions.cc +++ b/server/modules/filter/cache/test/test_cacheoptions.cc @@ -141,7 +141,7 @@ string create_unique_select() int test(mock::Session& session, FilterModule::Session& filter_session, - mock::RouterSession& router_session, + mock::RouterSession& router_session, const TEST_CASE& tc) { int rv = 0; @@ -293,7 +293,15 @@ int test(FilterModule::Instance& filter_instance, const TEST_CASE& tc) parameters.set("connection_timeout", "10s"); auto service = service_alloc("service", "readconnroute", ¶meters); - auto listener = Listener::create(service, "listener", "mariadbclient", "0.0.0.0", 3306, "", "", nullptr); + + MXS_CONFIG_PARAMETER listener_params; + listener_params.set(CN_ADDRESS, "0.0.0.0"); + listener_params.set(CN_PORT, "3306"); + listener_params.set(CN_PROTOCOL, "mariadbclient"); + listener_params.set(CN_SERVICE, service->name()); + + auto listener = Listener::create("listener", "mariadbclient", listener_params); + mock::Client client("bob", "127.0.0.1"); mock::Session session(&client, listener); mock::ResultSetBackend backend; diff --git a/server/modules/filter/dbfwfilter/test/test_dbfwfilter.cc b/server/modules/filter/dbfwfilter/test/test_dbfwfilter.cc index b721e5dd8..da99088e8 100644 --- a/server/modules/filter/dbfwfilter/test/test_dbfwfilter.cc +++ b/server/modules/filter/dbfwfilter/test/test_dbfwfilter.cc @@ -708,7 +708,7 @@ void log_error(const FW_TEST_CASE& c) int test(mock::Client& client, FilterModule::Session& filter_session, - mock::RouterSession& router_session, + mock::RouterSession& router_session, const FW_TEST_CASE& c) { int rv = 0; @@ -772,8 +772,15 @@ int test(FilterModule::Instance& filter_instance, const FW_TEST& t) parameters.set("max_retry_interval", "10s"); parameters.set("connection_timeout", "10s"); auto service = service_alloc("service", "readconnroute", ¶meters); - auto listener = Listener::create(service, "listener", "mariadbclient", "0.0.0.0", 3306, - "", "", nullptr); + + MXS_CONFIG_PARAMETER listener_params; + listener_params.set(CN_ADDRESS, "0.0.0.0"); + listener_params.set(CN_PORT, "3306"); + listener_params.set(CN_PROTOCOL, "mariadbclient"); + listener_params.set(CN_SERVICE, service->name()); + + auto listener = Listener::create("listener", "mariadbclient", listener_params); + mock::Session session(&client, listener); mock::OkBackend backend; mock::RouterSession router_session(&backend, &session); diff --git a/server/modules/routing/binlogrouter/blr_master.cc b/server/modules/routing/binlogrouter/blr_master.cc index 3560c22a6..4c63af3e6 100644 --- a/server/modules/routing/binlogrouter/blr_master.cc +++ b/server/modules/routing/binlogrouter/blr_master.cc @@ -188,8 +188,13 @@ static void blr_start_master(void* data) pthread_mutex_unlock(&router->lock); // Create a temporary listener so we can create a session originating from it - auto listener = Listener::create(router->service, "binlogrouter_listener", "mariadbclient", - "127.0.0.1", 9999, "", "", nullptr); + MXS_CONFIG_PARAMETER listener_params; + listener_params.set(CN_ADDRESS, "127.0.0.1"); + listener_params.set(CN_PORT, "9999"); + listener_params.set(CN_PROTOCOL, "mariadbclient"); + listener_params.set(CN_SERVICE, router->service->name()); + + auto listener = Listener::create("binlogrouter_listener", "mariadbclient", listener_params); mxb_assert(listener); // Load users now so that authentication will work for the fake client @@ -1708,7 +1713,7 @@ bool blr_send_event(blr_thread_role_t role, const char* binlog_name, uint32_t binlog_pos, ROUTER_SLAVE* slave, - REP_HEADER* hdr, + REP_HEADER* hdr, uint8_t* buf) { bool rval = true;