Commit d695e2de authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

MDEV-33506 Show original IP in the "aborted" message.

Add "real ip:<ip_or_localhost>" part to the aborted message
Only for proxy-protocoled connection, so it does not  not to cause
confusion to normal users.
parent ed027d65
......@@ -456,6 +456,7 @@ typedef struct st_net {
my_bool thread_specific_malloc;
unsigned char compress;
my_bool unused3; /* Please remove with the next incompatible ABI change. */
my_bool using_proxy_protocol;
/*
Pointer to query object in query cache, do not equal NULL (0) for
queries in cache that have not stored its results yet
......
......@@ -261,3 +261,4 @@ SET @@global.character_set_server= @save_character_set_server;
SET @@global.collation_server= @save_collation_server;
SET @@global.character_set_client= @save_character_set_client;
SET @@global.collation_connection= @save_collation_connection;
FOUND 1 /Aborted connection.*'u' host: '192.0.2.1' real ip: '(localhost|::1)'/ in mysqld.1.err
......@@ -59,3 +59,9 @@ SET @@global.character_set_server= @save_character_set_server;
SET @@global.collation_server= @save_collation_server;
SET @@global.character_set_client= @save_character_set_client;
SET @@global.collation_connection= @save_collation_connection;
# Search for "real ip" in Aborted message
# This is indicator for abort of the proxied connections.
let SEARCH_FILE=$MYSQLTEST_VARDIR/log/mysqld.1.err;
let SEARCH_PATTERN= Aborted connection.*'u' host: '192.0.2.1' real ip: '(localhost|::1)';
source include/search_pattern_in_file.inc;
......@@ -151,6 +151,7 @@ my_bool my_net_init(NET *net, Vio *vio, void *thd, uint my_flags)
net->where_b = net->remain_in_buf=0;
net->net_skip_rest_factor= 0;
net->last_errno=0;
net->using_proxy_protocol= 0;
net->thread_specific_malloc= MY_TEST(my_flags & MY_THREAD_SPECIFIC);
net->thd= 0;
#ifdef MYSQL_SERVER
......@@ -192,6 +193,7 @@ void net_end(NET *net)
DBUG_ENTER("net_end");
my_free(net->buff);
net->buff=0;
net->using_proxy_protocol= 0;
DBUG_VOID_RETURN;
}
......@@ -908,6 +910,7 @@ static handle_proxy_header_result handle_proxy_header(NET *net)
return RETRY;
/* Change peer address in THD and ACL structures.*/
uint host_errors;
net->using_proxy_protocol= 1;
return (handle_proxy_header_result)thd_set_peer_addr(thd,
&(peer_info.peer_addr), NULL, peer_info.port,
false, &host_errors);
......
......@@ -4252,22 +4252,22 @@ ER_ERROR_DURING_CHECKPOINT
swe "Fick fel %M vid CHECKPOINT"
ukr "Отримано помилку %M під час CHECKPOINT"
ER_NEW_ABORTING_CONNECTION 08S01
chi "终止的连接 %lld 到数据库: '%-.192s' 用户: '%-.48s' 主机: '%-.64s' (%-.64s)"
cze "Spojení %lld do databáze: '%-.192s' uživatel: '%-.48s' stroj: '%-.64s' (%-.64s) bylo přerušeno"
dan "Afbrød forbindelsen %lld til databasen '%-.192s' bruger: '%-.48s' vært: '%-.64s' (%-.64s)"
eng "Aborted connection %lld to db: '%-.192s' user: '%-.48s' host: '%-.64s' (%-.64s)"
est "Ühendus katkestatud %lld andmebaas: '%-.192s' kasutaja: '%-.48s' masin: '%-.64s' (%-.64s)"
fre "Connection %lld avortée vers la bd: '%-.192s' utilisateur: '%-.48s' hôte: '%-.64s' (%-.64s)"
ger "Abbruch der Verbindung %lld zur Datenbank '%-.192s'. Benutzer: '%-.48s', Host: '%-.64s' (%-.64s)"
ita "Interrotta la connessione %lld al db: ''%-.192s' utente: '%-.48s' host: '%-.64s' (%-.64s)"
jpn "接続 %lld が中断されました。データベース: '%-.192s' ユーザー: '%-.48s' ホスト: '%-.64s' (%-.64s)"
nla "Afgebroken verbinding %lld naar db: '%-.192s' gebruiker: '%-.48s' host: '%-.64s' (%-.64s)"
por "Conexão %lld abortada para banco de dados '%-.192s' - usuário '%-.48s' - 'host' '%-.64s' ('%-.64s')"
rus "Прервано соединение %lld к базе данных '%-.192s' пользователя '%-.48s' с хоста '%-.64s' (%-.64s)"
serbian "Prekinuta konekcija broj %lld ka bazi: '%-.192s' korisnik je bio: '%-.48s' a host: '%-.64s' (%-.64s)"
spa "Abortada conexión %lld para db: '%-.192s' usuario: '%-.48s' servidor: '%-.64s' (%-.64s)"
swe "Avbröt länken för tråd %lld till db '%-.192s', användare '%-.48s', host '%-.64s' (%-.64s)"
ukr "Перервано з'єднання %lld до бази данних: '%-.192s' користувач: '%-.48s' хост: '%-.64s' (%-.64s)"
chi "终止的连接 %lld 到数据库: '%-.192s' 用户: '%-.48s' 主机: '%-.64s'%-.64s (%-.64s)"
cze "Spojení %lld do databáze: '%-.192s' uživatel: '%-.48s' stroj: '%-.64s'%-.64s (%-.64s) bylo přerušeno"
dan "Afbrød forbindelsen %lld til databasen '%-.192s' bruger: '%-.48s' vært: '%-.64s'%-.64s (%-.64s)"
eng "Aborted connection %lld to db: '%-.192s' user: '%-.48s' host: '%-.64s'%-.64s (%-.64s)"
est "Ühendus katkestatud %lld andmebaas: '%-.192s' kasutaja: '%-.48s' masin: '%-.64s'%-.64s (%-.64s)"
fre "Connection %lld avortée vers la bd: '%-.192s' utilisateur: '%-.48s' hôte: '%-.64s'%-.64s (%-.64s)"
ger "Abbruch der Verbindung %lld zur Datenbank '%-.192s'. Benutzer: '%-.48s', Host: '%-.64s'%-.64s (%-.64s)"
ita "Interrotta la connessione %lld al db: ''%-.192s' utente: '%-.48s' host: '%-.64s'%-.64s (%-.64s)"
jpn "接続 %lld が中断されました。データベース: '%-.192s' ユーザー: '%-.48s' ホスト: '%-.64s'%-.64s (%-.64s)"
nla "Afgebroken verbinding %lld naar db: '%-.192s' gebruiker: '%-.48s' host: '%-.64s'%-.64s (%-.64s)"
por "Conexão %lld abortada para banco de dados '%-.192s' - usuário '%-.48s' - 'host' '%-.64s'%-.64s ('%-.64s')"
rus "Прервано соединение %lld к базе данных '%-.192s' пользователя '%-.48s' с хоста '%-.64s'%-.64s (%-.64s)"
serbian "Prekinuta konekcija broj %lld ka bazi: '%-.192s' korisnik je bio: '%-.48s' a host: '%-.64s'%-.64s (%-.64s)"
spa "Abortada conexión %lld a la base de datos: '%-.192s' usuario: '%-.48s' equipo: '%-.64s'%-.64s (%-.64s)"
swe "Avbröt länken för tråd %lld till db '%-.192s', användare '%-.48s', host '%-.64s'%-.64s (%-.64s)"
ukr "Перервано з'єднання %lld до бази данних: '%-.192s' користувач: '%-.48s' хост: '%-.64s'%-.64s (%-.64s)"
ER_UNUSED_10
eng "You should never see it"
ER_FLUSH_MASTER_BINLOG_CLOSED
......
......@@ -4773,11 +4773,29 @@ class THD: public THD_count, /* this must be first */
{
if (global_system_variables.log_warnings > threshold)
{
char real_ip_str[64];
real_ip_str[0]= 0;
/* For proxied connections, add the real IP to the warning message */
if (net.using_proxy_protocol && net.vio)
{
if(net.vio->localhost)
snprintf(real_ip_str, sizeof(real_ip_str), " real ip: 'localhost'");
else
{
char buf[INET6_ADDRSTRLEN];
if (!vio_getnameinfo((sockaddr *)&(net.vio->remote), buf,
sizeof(buf),NULL, 0, NI_NUMERICHOST))
{
snprintf(real_ip_str, sizeof(real_ip_str), " real ip: '%s'",buf);
}
}
}
Security_context *sctx= &main_security_ctx;
sql_print_warning(ER_THD(this, ER_NEW_ABORTING_CONNECTION),
thread_id, (db.str ? db.str : "unconnected"),
sctx->user ? sctx->user : "unauthenticated",
sctx->host_or_ip, reason);
sctx->host_or_ip, real_ip_str, reason);
}
}
......
......@@ -1282,7 +1282,7 @@ void prepare_new_connection_state(THD* thd)
thd->thread_id,
thd->db.str ? thd->db.str : "unconnected",
sctx->user ? sctx->user : "unauthenticated",
sctx->host_or_ip, "init_connect command failed");
sctx->host_or_ip, "", "init_connect command failed");
thd->server_status&= ~SERVER_STATUS_CLEAR_SET;
thd->protocol->end_statement();
thd->killed = KILL_CONNECTION;
......
......@@ -20546,7 +20546,6 @@ typedef struct {
#ifndef EMBEDDED_LIBRARY
static void test_proxy_header_tcp(const char *ipaddr, int port)
{
int rc;
MYSQL_RES *result;
int family = (strchr(ipaddr,':') == NULL)?AF_INET:AF_INET6;
......@@ -20621,6 +20620,11 @@ static void test_proxy_header_tcp(const char *ipaddr, int port)
DIE_UNLESS(strncmp(row[0], normalized_addr, addrlen) == 0);
DIE_UNLESS(atoi(row[0] + addrlen+1) == port);
mysql_free_result(result);
if (i == 0 && !strcmp(ipaddr,"192.0.2.1"))
{
/* do "dirty" close, to get aborted message in error log.*/
mariadb_cancel(m);
}
mysql_close(m);
}
sprintf(query,"DROP USER 'u'@'%s'",normalized_addr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment