From e773dbb260068f85ed291972daccc684bc8173ff Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 17 Jan 2020 16:21:46 +0500 Subject: [PATCH] Add application_name_add_host setting --- odyssey.conf | 8 +++++++- sources/config_reader.c | 7 +++++++ sources/frontend.c | 16 ++++++++++++++++ sources/rules.h | 1 + third_party/kiwi/kiwi/var.h | 4 +++- 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/odyssey.conf b/odyssey.conf index ed3b7360c..25a5264d5 100644 --- a/odyssey.conf +++ b/odyssey.conf @@ -435,7 +435,7 @@ database default { # "session" - assign server connection to a client until it disconnects # "transaction" - assign server connection to a client during a transaction lifetime # - pool "session" + pool "transaction" # # Server pool size. @@ -495,6 +495,12 @@ database default { # client_fwd_error yes +# +# Add client host name to application_name parameter +# + + application_name_add_host yes + # # Enable verbose mode for a specific route only. # diff --git a/sources/config_reader.c b/sources/config_reader.c index 757f32200..162e44bdf 100644 --- a/sources/config_reader.c +++ b/sources/config_reader.c @@ -67,6 +67,7 @@ enum OD_LCLIENT_MAX_ROUTING, OD_LCLIENT_LOGIN_TIMEOUT, OD_LCLIENT_FWD_ERROR, + OD_LAPPLICATION_NAME_ADD_HOST, OD_LTLS, OD_LTLS_CA_FILE, OD_LTLS_KEY_FILE, @@ -153,6 +154,7 @@ od_config_keywords[] = od_keyword("client_max_routing", OD_LCLIENT_MAX_ROUTING), od_keyword("client_login_timeout", OD_LCLIENT_LOGIN_TIMEOUT), od_keyword("client_fwd_error", OD_LCLIENT_FWD_ERROR), + od_keyword("application_name_add_host", OD_LAPPLICATION_NAME_ADD_HOST), od_keyword("tls", OD_LTLS), od_keyword("tls_ca_file", OD_LTLS_CA_FILE), od_keyword("tls_key_file", OD_LTLS_KEY_FILE), @@ -693,6 +695,11 @@ od_config_reader_route(od_config_reader_t *reader, char *db_name, int db_name_le if (! od_config_reader_yes_no(reader, &route->client_fwd_error)) return -1; continue; + /* application_name_add_host */ + case OD_LAPPLICATION_NAME_ADD_HOST: + if (! od_config_reader_yes_no(reader, &route->application_name_add_host)) + return -1; + continue; /* pool */ case OD_LPOOL: if (! od_config_reader_string(reader, &route->pool_sz)) diff --git a/sources/frontend.c b/sources/frontend.c index 968334e2c..7852c9392 100644 --- a/sources/frontend.c +++ b/sources/frontend.c @@ -876,6 +876,20 @@ od_frontend_cleanup(od_client_t *client, char *context, } } +static void od_application_name_add_host(od_client_t *client) { + if (client == NULL || client->io.io == NULL) + return; + char app_name[KIWI_MAX_VAR_SIZE]; + char peer_name[KIWI_MAX_VAR_SIZE]; + kiwi_var_t *app_name_var = kiwi_vars_get(&client->vars, KIWI_VAR_APPLICATION_NAME); + if (app_name_var == NULL) + return; + od_getpeername(client->io.io, peer_name, sizeof(peer_name), 1, 0); //return code ignored + + int length = od_snprintf(app_name, 256, "%.*s - %s", app_name_var->value_len, app_name_var->value, peer_name); + kiwi_var_set(app_name_var, KIWI_VAR_APPLICATION_NAME, app_name, length + 1); //return code ignored +} + void od_frontend(void *arg) { @@ -1005,6 +1019,8 @@ od_frontend(void *arg) case OD_ROUTER_OK: { od_route_t *route = client->route; + if (route->rule->application_name_add_host) + od_application_name_add_host(client); if (instance->config.log_session) { od_log(&instance->logger, "startup", client, NULL, "route '%s.%s' to '%s.%s'", diff --git a/sources/rules.h b/sources/rules.h index 42437c708..44e4cc538 100644 --- a/sources/rules.h +++ b/sources/rules.h @@ -113,6 +113,7 @@ struct od_rule int pool_rollback; /* misc */ int client_fwd_error; + int application_name_add_host; int client_max_set; int client_max; int log_debug; diff --git a/third_party/kiwi/kiwi/var.h b/third_party/kiwi/kiwi/var.h index c80e96152..6cc6a6ed3 100644 --- a/third_party/kiwi/kiwi/var.h +++ b/third_party/kiwi/kiwi/var.h @@ -7,6 +7,8 @@ * postgreSQL protocol interaction library. */ +#define KIWI_MAX_VAR_SIZE 128 + typedef struct kiwi_var kiwi_var_t; typedef struct kiwi_vars kiwi_vars_t; @@ -25,7 +27,7 @@ struct kiwi_var kiwi_var_type_t type; char *name; int name_len; - char value[128]; + char value[KIWI_MAX_VAR_SIZE]; int value_len; };