MXS-2196: Take Listener into use
This commit is contained in:
@ -3863,13 +3863,13 @@ int create_new_listener(CONFIG_CONTEXT* obj)
|
||||
address = "";
|
||||
}
|
||||
|
||||
if (auto l = service_find_listener(service, socket, address, socket ? 0 : atoi(port)))
|
||||
if (auto l = service_find_listener(service, socket ? socket : "", address, socket ? 0 : atoi(port)))
|
||||
{
|
||||
MXS_ERROR("Creation of listener '%s' for service '%s' failed, because "
|
||||
"listener '%s' already listens on the %s %s.",
|
||||
obj->object,
|
||||
service->name,
|
||||
l->name.c_str(),
|
||||
l->name(),
|
||||
socket ? "socket" : "port",
|
||||
socket ? socket : port);
|
||||
return 1;
|
||||
|
@ -978,16 +978,16 @@ bool runtime_create_listener(Service* service,
|
||||
proto = "mariadbclient";
|
||||
}
|
||||
|
||||
if (auth && strcasecmp(auth, CN_DEFAULT) == 0)
|
||||
if (!auth || strcasecmp(auth, CN_DEFAULT) == 0)
|
||||
{
|
||||
/** Set auth to NULL so the protocol default authenticator is used */
|
||||
auth = NULL;
|
||||
/** Use protocol default authenticator*/
|
||||
auth = "";
|
||||
}
|
||||
|
||||
if (auth_opt && strcasecmp(auth_opt, CN_DEFAULT) == 0)
|
||||
if (!auth_opt || strcasecmp(auth_opt, CN_DEFAULT) == 0)
|
||||
{
|
||||
/** Don't pass options to the authenticator */
|
||||
auth_opt = NULL;
|
||||
auth_opt = "";
|
||||
}
|
||||
|
||||
unsigned short u_port = atoi(port);
|
||||
@ -995,7 +995,7 @@ bool runtime_create_listener(Service* service,
|
||||
|
||||
std::lock_guard<std::mutex> guard(crt_lock);
|
||||
|
||||
if (!serviceHasListener(service, name, proto, addr, u_port))
|
||||
if (!listener_find(name) && !service_find_listener(service, "", addr, u_port))
|
||||
{
|
||||
SSL_LISTENER* ssl = NULL;
|
||||
|
||||
|
@ -2230,8 +2230,8 @@ static int dcb_create_SSL(DCB* dcb, SSL_LISTENER* ssl)
|
||||
*/
|
||||
int dcb_accept_SSL(DCB* dcb)
|
||||
{
|
||||
if ((NULL == dcb->listener || NULL == dcb->listener->ssl)
|
||||
|| (NULL == dcb->ssl && dcb_create_SSL(dcb, dcb->listener->ssl) != 0))
|
||||
if ((NULL == dcb->listener || NULL == dcb->listener->ssl())
|
||||
|| (NULL == dcb->ssl && dcb_create_SSL(dcb, dcb->listener->ssl()) != 0))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@ -2451,10 +2451,11 @@ DCB* dcb_accept(DCB* dcb)
|
||||
INET6_ADDRSTRLEN);
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(&client_dcb->func, protocol_funcs, sizeof(MXS_PROTOCOL));
|
||||
if (!dcb->listener->authenticator.empty())
|
||||
if (*dcb->listener->authenticator())
|
||||
{
|
||||
authenticator_name = dcb->listener->authenticator.c_str();
|
||||
authenticator_name = dcb->listener->authenticator();
|
||||
}
|
||||
else if (client_dcb->func.auth_default != NULL)
|
||||
{
|
||||
@ -2476,7 +2477,7 @@ DCB* dcb_accept(DCB* dcb)
|
||||
/** Allocate DCB specific authentication data */
|
||||
if (client_dcb->authfunc.create
|
||||
&& (client_dcb->authenticator_data =
|
||||
client_dcb->authfunc.create(client_dcb->listener->auth_instance)) == NULL)
|
||||
client_dcb->authfunc.create(client_dcb->listener->auth_instance())) == NULL)
|
||||
{
|
||||
MXS_ERROR("Failed to create authenticator for client DCB");
|
||||
dcb_close(client_dcb);
|
||||
@ -2908,7 +2909,7 @@ void dcb_process_idle_sessions(int thr)
|
||||
if (dcb->dcb_role == DCB_ROLE_CLIENT_HANDLER)
|
||||
{
|
||||
mxb_assert(dcb->listener);
|
||||
SERVICE* service = dcb->listener->service;
|
||||
SERVICE* service = dcb->listener->service();
|
||||
|
||||
if (service->conn_idle_timeout && dcb->state == DCB_STATE_POLLING)
|
||||
{
|
||||
|
@ -347,25 +347,10 @@ bool serviceLaunchListener(Service* service, const SListener& port);
|
||||
* @return True if service has the listener
|
||||
*/
|
||||
SListener service_find_listener(Service* service,
|
||||
const char* socket,
|
||||
const char* address,
|
||||
const std::string& socket,
|
||||
const std::string& address,
|
||||
unsigned short port);
|
||||
|
||||
/**
|
||||
* @brief Check if a service has a listener
|
||||
*
|
||||
* @param service Service to check
|
||||
* @param protocol Listener protocol
|
||||
* @param address Listener address
|
||||
* @param port Listener port
|
||||
* @return True if service has the listener
|
||||
*/
|
||||
bool serviceHasListener(Service* service,
|
||||
const char* name,
|
||||
const char* protocol,
|
||||
const char* address,
|
||||
unsigned short port);
|
||||
|
||||
/**
|
||||
* @brief Check if a MaxScale service listens on a port
|
||||
*
|
||||
|
@ -238,8 +238,8 @@ Service::~Service()
|
||||
|
||||
for (const auto& tmp : listener_find_by_service(this))
|
||||
{
|
||||
mxb_assert(!tmp->active || maxscale_teardown_in_progress());
|
||||
listener_free(listener_find(tmp->name));
|
||||
mxb_assert(!tmp->is_active() || maxscale_teardown_in_progress());
|
||||
listener_free(listener_find(tmp->name()));
|
||||
}
|
||||
|
||||
if (router && router_instance && router->destroyInstance)
|
||||
@ -546,58 +546,28 @@ bool service_remove_listener(Service* service, const char* target)
|
||||
}
|
||||
|
||||
SListener service_find_listener(Service* service,
|
||||
const char* socket,
|
||||
const char* address,
|
||||
const std::string& socket,
|
||||
const std::string& address,
|
||||
unsigned short port)
|
||||
{
|
||||
SListener rval;
|
||||
|
||||
for (const auto& listener : listener_find_by_service(service))
|
||||
{
|
||||
if (port == listener->port)
|
||||
if (port == listener->port() && (listener->address() == address || listener->address() == socket))
|
||||
{
|
||||
if ((!address && listener->address.empty()) || listener->address == address
|
||||
|| (!socket && listener->address.empty()) || listener->address == socket)
|
||||
{
|
||||
return listener;
|
||||
}
|
||||
rval = listener;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a protocol/port pair is part of the service
|
||||
*
|
||||
* @param service The service
|
||||
* @param protocol The name of the protocol module
|
||||
* @param address The address to listen on
|
||||
* @param port The port to listen on
|
||||
* @return True if the protocol/port is already part of the service
|
||||
*/
|
||||
bool serviceHasListener(Service* service,
|
||||
const char* name,
|
||||
const char* protocol,
|
||||
const char* address,
|
||||
unsigned short port)
|
||||
{
|
||||
for (const auto& listener : listener_find_by_service(service))
|
||||
{
|
||||
if (listener->port == port)
|
||||
{
|
||||
if ((!address && listener->address.empty()) || listener->address == address)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return rval;
|
||||
}
|
||||
|
||||
bool service_has_named_listener(Service* service, const char* name)
|
||||
{
|
||||
auto listener = listener_find(name);
|
||||
return listener && listener->service == service;
|
||||
return listener && listener->service() == service;
|
||||
}
|
||||
|
||||
bool service_can_be_destroyed(Service* service)
|
||||
@ -1094,12 +1064,12 @@ void dListListeners(DCB* dcb)
|
||||
{
|
||||
dcb_printf(dcb,
|
||||
"%-20s | %-19s | %-18s | %-15s | %5d | %s\n",
|
||||
listener->name.c_str(),
|
||||
listener->name(),
|
||||
service->name,
|
||||
listener->protocol.c_str(),
|
||||
(listener && !listener->address.empty()) ? listener->address.c_str() : "*",
|
||||
listener->port,
|
||||
listener_state_to_string(listener));
|
||||
listener->protocol(),
|
||||
(listener && *listener->address()) ? listener->address() : "*",
|
||||
listener->port(),
|
||||
listener->state());
|
||||
}
|
||||
}
|
||||
if (!this_unit.services.empty())
|
||||
@ -1316,8 +1286,8 @@ std::unique_ptr<ResultSet> serviceGetListenerList()
|
||||
{
|
||||
for (const auto& listener : listener_find_by_service(service))
|
||||
{
|
||||
set->add_row({service->name, listener->protocol, listener->address,
|
||||
std::to_string(listener->port), listener_state_to_string(listener)});
|
||||
set->add_row({service->name, listener->protocol(), listener->address(),
|
||||
std::to_string(listener->port()), listener->state()});
|
||||
}
|
||||
}
|
||||
|
||||
@ -1623,7 +1593,7 @@ bool service_port_is_used(unsigned short port)
|
||||
{
|
||||
for (const auto& listener : listener_find_by_service(service))
|
||||
{
|
||||
if (listener->port == port)
|
||||
if (listener->port() == port)
|
||||
{
|
||||
rval = true;
|
||||
break;
|
||||
@ -1694,7 +1664,7 @@ static json_t* service_all_listeners_json_data(const SERVICE* service)
|
||||
|
||||
for (const auto& listener : listener_find_by_service(service))
|
||||
{
|
||||
json_array_append_new(arr, listener_to_json(listener));
|
||||
json_array_append_new(arr, listener->to_json());
|
||||
}
|
||||
|
||||
return arr;
|
||||
@ -1704,9 +1674,9 @@ static json_t* service_listener_json_data(const SERVICE* service, const char* na
|
||||
{
|
||||
auto listener = listener_find(name);
|
||||
|
||||
if (listener && listener->service == service)
|
||||
if (listener && listener->service() == service)
|
||||
{
|
||||
return listener_to_json(listener);
|
||||
return listener->to_json();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -54,7 +54,7 @@ int ssl_authenticate_client(DCB* dcb, bool is_capable)
|
||||
const char* remote = dcb->remote ? dcb->remote : "";
|
||||
const char* service = (dcb->service && dcb->service->name) ? dcb->service->name : "";
|
||||
|
||||
if (NULL == dcb->listener || NULL == dcb->listener->ssl)
|
||||
if (NULL == dcb->listener || NULL == dcb->listener->ssl())
|
||||
{
|
||||
/* Not an SSL connection on account of listener configuration */
|
||||
return SSL_AUTH_CHECKS_OK;
|
||||
@ -134,7 +134,7 @@ bool ssl_is_connection_healthy(DCB* dcb)
|
||||
* more to be done.
|
||||
*/
|
||||
return NULL == dcb->listener
|
||||
|| NULL == dcb->listener->ssl
|
||||
|| NULL == dcb->listener->ssl()
|
||||
|| dcb->ssl_state == SSL_ESTABLISHED;
|
||||
}
|
||||
|
||||
@ -171,7 +171,7 @@ bool ssl_check_data_to_process(DCB* dcb)
|
||||
*/
|
||||
bool ssl_required_by_dcb(DCB* dcb)
|
||||
{
|
||||
return NULL != dcb->listener && NULL != dcb->listener->ssl;
|
||||
return NULL != dcb->listener && NULL != dcb->listener->ssl();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -187,7 +187,7 @@ bool ssl_required_by_dcb(DCB* dcb)
|
||||
bool ssl_required_but_not_negotiated(DCB* dcb)
|
||||
{
|
||||
return NULL != dcb->listener
|
||||
&& NULL != dcb->listener->ssl
|
||||
&& NULL != dcb->listener->ssl()
|
||||
&& SSL_HANDSHAKE_UNKNOWN == dcb->ssl_state;
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ static int test1()
|
||||
NULL,
|
||||
NULL),
|
||||
"Add Protocol should succeed");
|
||||
mxb_assert_message(0 != serviceHasListener(service, "TestProtocol", "mariadbclient", "localhost", 9876),
|
||||
mxb_assert_message(service_find_listener(service, "", "localhost", 9876),
|
||||
"Service should have new protocol as requested");
|
||||
|
||||
return 0;
|
||||
|
@ -328,21 +328,21 @@ json_t* users_diagnostic_json(USERS* users)
|
||||
|
||||
void users_default_diagnostic(DCB* dcb, Listener* port)
|
||||
{
|
||||
if (port->users)
|
||||
if (port->users())
|
||||
{
|
||||
users_diagnostic(dcb, port->users);
|
||||
users_diagnostic(dcb, port->users());
|
||||
}
|
||||
}
|
||||
|
||||
json_t* users_default_diagnostic_json(const Listener* port)
|
||||
{
|
||||
return port->users ? users_diagnostic_json(port->users) : json_array();
|
||||
return port->users() ? users_diagnostic_json(port->users()) : json_array();
|
||||
}
|
||||
|
||||
int users_default_loadusers(Listener* port)
|
||||
{
|
||||
users_free(port->users);
|
||||
port->users = users_alloc();
|
||||
users_free(port->users());
|
||||
port->set_users(users_alloc());
|
||||
return MXS_AUTH_LOADUSERS_OK;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user